Пример #1
0
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <returns></returns>
        public bool CreateSqliteDb()
        {
            if (!File.Exists(_filePath))
            {
                SQLiteConnection.CreateFile(_filePath);
            }
            var connection = new SQLiteConnection(ConnectionString);

            using (connection)
            {
                connection.Open();
                var tableCount = connection.ExecuteScalar(
                    " SELECT COUNT(*) FROM sqlite_master where type='table' and name='DataBaseLinkConfigModel' ");
                if (DataTypeConvertHelper.ToInt(tableCount) == 1)
                {
                    return(true);
                }
                connection.Execute(@" CREATE TABLE DataBaseLinkConfigModel (
                                            Id  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                                            DbType  INTEGER,
                                            LinkName  TEXT,
                                            LinkConnectionString  TEXT,
                                            IsEnable INTEGER
                                            ); ");
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Get collection of int.
        /// </summary>
        /// <param name="context">request context</param>
        /// <param name="key">params key</param>
        /// <param name="separator">split char</param>
        /// <returns></returns>
        public static List <int> GetListIntFromParameters(this HttpContext context, string key, char separator)
        {
            var strList = context.GetStringFromParameters(key);

            if (string.IsNullOrEmpty(strList))
            {
                return(null);
            }
            var list = new List <int>();

            foreach (var item in strList.Split(separator))
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }
                var id = DataTypeConvertHelper.ToInt(item);
                if (list.Contains(id))
                {
                    continue;
                }
                list.Add(id);
            }
            return(list);
        }
Пример #3
0
        /// <summary>
        /// GetKeys
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="sqlCmd"></param>
        /// <returns></returns>
        private Columns GetKeys(string connectionString, string sqlCmd)
        {
            Columns columns = new Columns(5);

            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.Oracle);
            using (var conn = SqlConnectionHelper.GetOpenConnection(connectionString))
            {
                var dr = conn.ExecuteReader(sqlCmd);
                while (dr.Read())
                {
                    string id           = dr.IsDBNull(3) ? string.Empty : dr.GetValue(3).ToString();
                    string displayName  = dr.IsDBNull(3) ? string.Empty : dr.GetValue(3).ToString();
                    string name         = dr.IsDBNull(3) ? string.Empty : dr.GetValue(3).ToString();
                    string dataType     = "";
                    string defaultValue = "";
                    string isNullable   = "Y";
                    string length       = "";
                    string identity     = string.Empty;
                    string comment      = "主键";

                    Column column = new Column(id, displayName, name, dataType, comment);
                    column.Length            = DataTypeConvertHelper.ToInt(length);
                    column.IsAutoIncremented = false;
                    column.IsNullable        = isNullable.Equals("Y");
                    column.DefaultValue      = defaultValue.ToEmpty();
                    column.DataType          = dataType;
                    column.OriginalName      = name;
                    columns.Add(id, column);
                }
                dr.Close();

                return(columns);
            }
        }
Пример #4
0
        /// <summary>
        /// GetColumns
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="sqlCmd"></param>
        /// <returns></returns>
        private Columns GetColumns(string connectionString, string sqlCmd)
        {
            Columns         columns = new Columns(50);
            MySqlDataReader dr      = MySqlHelper.ExecuteReader(connectionString, sqlCmd);

            while (dr.Read())
            {
                string id          = dr.IsDBNull(2) ? string.Empty : dr.GetString(2);
                string displayName = dr.IsDBNull(2) ? string.Empty : dr.GetString(2);
                string name        = dr.IsDBNull(2) ? string.Empty : dr.GetString(2);
                string dataType    = dr.IsDBNull(3) ? string.Empty : dr.GetString(3);
                //string key = dr.IsDBNull(4) ? string.Empty : dr.GetString(4);
                string defaultValue = dr.IsDBNull(5) ? string.Empty : dr.GetString(5);
                string isNullable   = dr.IsDBNull(6) ? string.Empty : dr.GetString(6);
                string length       = dr.IsDBNull(7) ? string.Empty : dr.GetString(7);
                string identity     = dr.IsDBNull(8) ? string.Empty : dr.GetString(8);
                string comment      = dr.IsDBNull(9) ? string.Empty : dr.GetString(9);

                Column column = new Column(id, displayName, name, dataType, comment);
                column.Length            = DataTypeConvertHelper.ToInt(length);
                column.IsAutoIncremented = identity.Equals("auto_increment");
                column.IsNullable        = isNullable.Equals("YES");
                column.DefaultValue      = defaultValue.ToEmpty();
                column.DataType          = dataType;
                column.OriginalName      = name;
                columns.Add(id, column);
            }
            dr.Close();

            return(columns);
        }
        /// <summary>
        /// 获取消费分类记录
        /// </summary>
        /// <param name="starTime"></param>
        /// <param name="endTime"></param>
        /// <param name="userIds"></param>
        /// <param name="inOrOut"></param>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public Dictionary <int, decimal> GetStatisticsCostMonth(DateTime starTime, DateTime endTime, List <long> userIds, CostInOrOutEnum inOrOut, long channelId)
        {
            var select  = @"SELECT
	CostYear,CostMonth,
	sum( cost ) CostCount 
FROM 
	costcontent "    ;
            var groupby = " GROUP BY CostYear,CostMonth ORDER BY CostYear desc,CostMonth desc";

            var where = new StringBuilder("WHERE UserId in @UserIds and IsDel=@IsDel ");
            where.Append(" AND SpendType!=2 ");
            where.Append(" AND CostInOrOut = @CostInOrOut  ");
            if (starTime > new DateTime(1900, 1, 1))
            {
                where.Append(" and  CostTime>@StartTime  ");
            }

            if (endTime > new DateTime(1900, 1, 1))
            {
                where.Append(" and  CostTime<=@EndTime  ");
            }

            if (channelId > 0)
            {
                where.Append(" and  CostChannel=@CostChannel  ");
            }
            var param = new
            {
                UserIds     = userIds.ToArray(),
                CostInOrOut = inOrOut.GetHashCode(),
                StartTime   = starTime,
                EndTime     = endTime,
                CostChannel = channelId,
                IsDel       = FlagEnum.HadZore.GetHashCode()
            };
            var resultMap = new Dictionary <int, decimal>();

            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                IEnumerable <dynamic> query = conn.Query(select + where + groupby, param);
                foreach (var rows in query)
                {
                    if (!(rows is IDictionary <string, object> fields))
                    {
                        continue;
                    }
                    var sum       = fields["CostCount"];
                    var costYear  = fields["CostYear"];
                    var costMonth = fields["CostMonth"];
                    resultMap.Add(DataTypeConvertHelper.ToInt(costYear) * 100 + DataTypeConvertHelper.ToInt(costMonth), DataTypeConvertHelper.ToDecimal(sum));
                }
            }

            return(resultMap);
        }
Пример #6
0
        /// <summary>
        /// To int
        /// </summary>
        public void ToIntTest1()
        {
            var intNumber       = "90";
            var intNumberResult = DataTypeConvertHelper.ToInt(intNumber, 20);

            intNumberResult.IsEqualTo(90);

            var strNoNumber            = "90你好";
            var convertNumberIsDefault = DataTypeConvertHelper.ToInt(strNoNumber, 20);

            convertNumberIsDefault.IsEqualTo(20);
        }
Пример #7
0
        /// <summary>
        /// To int
        /// </summary>
        public void ToIntTest()
        {
            var intNumber       = "90";
            var intNumberResult = DataTypeConvertHelper.ToInt(intNumber);

            intNumberResult.IsEqualTo(90);

            var strNoNumber         = "90你好";
            var convertNumberIsZero = DataTypeConvertHelper.ToInt(strNoNumber);

            convertNumberIsZero.IsEqualTo(0);
        }
Пример #8
0
        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="authorityList"></param>
        /// <returns></returns>
        public List <SysMenuModel> GetMenuList(long userId, ref List <int> authorityList)
        {
            if (userId < 1)
            {
                return(null);
            }

            var sysUserMenus = new List <SysMenuModel>();

            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                var userMenus = conn.GetList <Sysusermenu>(new { IsDel = FlagEnum.HadZore.GetHashCode(), UserId = userId })?.ToList();
                if (userMenus != null && userMenus.Any())
                {
                    sysUserMenus = conn.GetList <SysMenuModel>("where id in @Id and IsDel=@IsDel", new { Id = userMenus.Select(item => item.MenuId).ToArray(), IsDel = FlagEnum.HadZore.GetHashCode() })?.ToList();
                }
            }

            var resultMemuList = new List <SysMenuModel>();

            if (sysUserMenus != null && sysUserMenus.Any())
            {
                var ids         = sysUserMenus.Select(f => f.Id).ToList();
                var dictionMenu = sysUserMenus.ToDictionary(f => f.Id, f => f);
                foreach (var r in sysUserMenus)
                {
                    authorityList.Add(DataTypeConvertHelper.ToInt(r.MenuType));
                    if (r.ParentId < 1)
                    {
                        resultMemuList.Add(r);
                    }

                    else if (ids.Contains(r.ParentId))
                    {
                        if (dictionMenu[r.ParentId].SubMenuModel == null)
                        {
                            dictionMenu[r.ParentId].SubMenuModel = new List <SysMenuModel>();
                        }
                        dictionMenu[r.ParentId].SubMenuModel.Add(r);
                    }
                    else
                    {
                        resultMemuList.Add(r);
                    }
                }
            }
            return(resultMemuList);
        }
        /// <summary>
        /// 获取统计数据
        /// </summary>
        /// <param name="userIds"></param>
        /// <param name="spendType"></param>
        /// <param name="address"></param>
        /// <param name="costThing"></param>
        /// <param name="costType"></param>
        /// <param name="costchannel"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public Dictionary <int, decimal> GetStatisticsCost(List <long> userIds, int spendType, string address, string costThing, int costType, long costchannel, DateTime startTime, DateTime endTime)
        {
            var select = "select CostInOrOut,sum(cost) Sum from costcontent ";

            var where = new StringBuilder(" where UserId in @UserIds and IsDel=@IsDel ");

            if (spendType != -1)
            {
                where.Append(" AND SpendType = @SpendType ");
            }
            if (costType != -1)
            {
                where.Append(" AND CostType = @CostType ");
            }

            if (costchannel != -1)
            {
                where.Append(" and CostChannel=@CostChannel ");
            }

            if (startTime > new DateTime(1900, 1, 1))
            {
                where.Append(" AND CostTime >= @StartTime ");
            }

            if (endTime > new DateTime(1900, 1, 1))
            {
                where.Append(" AND CostTime <= @EndTime ");
            }
            if (!string.IsNullOrEmpty(address))
            {
                where.Append(" AND CostAddress LIKE @CostAddress ");
            }

            if (!string.IsNullOrEmpty(costThing))
            {
                where.Append(" AND CostThing LIKE @CostThing ");
            }

            var groupby = " GROUP BY CostInOrOut ";
            var param   = new
            {
                UserIds     = userIds.ToArray(),
                SpendType   = spendType,
                CostType    = costType,
                CostChannel = costchannel,
                StartTime   = startTime,
                EndTime     = endTime,
                CostAddress = "%" + address + "%",
                CostThing   = "%" + costThing + "%",
                IsDel       = FlagEnum.HadZore.GetHashCode()
            };
            var result = new Dictionary <int, decimal>();

            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                IEnumerable <dynamic> query = conn.Query(select + where + groupby, param);
                foreach (var rows in query)
                {
                    if (!(rows is IDictionary <string, object> fields))
                    {
                        continue;
                    }
                    var sum     = fields["Sum"];
                    var inOrOut = fields["CostInOrOut"];
                    result.Add(DataTypeConvertHelper.ToInt(inOrOut), DataTypeConvertHelper.ToDecimal(sum));
                }
            }

            return(result);
        }
Пример #10
0
        public ResponseBaseModel <WeChatAuthResponseModel> GetUserOpenId([FromBody] WeChatLoginInfo loginInfo)
        {
            var data = RedisCacheHelper.Get <WeChatAuthResponseModel>(RedisCacheKey.AuthInfoKey + loginInfo.code);

            if (data != null)
            {
                return(new ResponseBaseModel <WeChatAuthResponseModel> {
                    ResultCode = ResponceCodeEnum.Success, Message = "微信认证成功", Data = data
                });
            }

            var weChatCheck = new WeChatAppDecrypt(
                string.IsNullOrEmpty(loginInfo.sys)
                    ? AppConfigurationHelper.GetString("XcxAppID", "")
                    : AppConfigurationHelper.GetString("XcxAppID" + loginInfo.sys),
                string.IsNullOrEmpty(loginInfo.sys)
                    ? AppConfigurationHelper.GetString("XcxAppSecrect", "")
                    : AppConfigurationHelper.GetString("XcxAppSecrect" + loginInfo.sys, ""));
            var openIdAndSessionKeyModel = weChatCheck.DecodeOpenIdAndSessionKey(loginInfo);

            if (openIdAndSessionKeyModel == null)
            {
                return(new ResponseBaseModel <WeChatAuthResponseModel> {
                    ResultCode = ResponceCodeEnum.Fail, Message = "微信认证失败"
                });
            }
            var isValidData = weChatCheck.VaildateUserInfo(loginInfo, openIdAndSessionKeyModel);

            if (!isValidData)
            {
                return(new ResponseBaseModel <WeChatAuthResponseModel> {
                    ResultCode = ResponceCodeEnum.Fail, Message = "请求信息验签失败"
                });
            }
            var responseData = weChatCheck.Decrypt(loginInfo.encryptedData, loginInfo.iv, openIdAndSessionKeyModel.session_key);

            if (responseData == null)
            {
                return(new ResponseBaseModel <WeChatAuthResponseModel> {
                    ResultCode = ResponceCodeEnum.Fail, Message = "微信认证失败"
                });
            }
            var server            = new WechatAccountService();
            var searchOpenIdModel = server.GetByOpenId(responseData.openId);

            //TODO:新的访问者
            if (searchOpenIdModel == null)
            {
                var newModel = new WeChatAccountModel
                {
                    AvatarUrl     = responseData.avatarUrl,
                    CreateTime    = DateTime.Now,
                    Gender        = DataTypeConvertHelper.ToInt(responseData.gender, 1),
                    IsDel         = FlagEnum.HadZore.GetHashCode(),
                    NickName      = responseData.nickName,
                    OpenId        = responseData.openId,
                    Remarks       = "新访问用户",
                    FamilyCode    = "",
                    HadBindFamily = FlagEnum.HadZore
                };
                server.SaveModel(newModel);

                var newSysModel = new SysUser
                {
                    Birthday   = "1900-01-01 00:00:00",
                    CreateTime = DateTime.Now,
                    IsDel      = FlagEnum.HadZore,
                    CreateAuth = 1,
                    HeadUrl    = newModel.AvatarUrl,
                    Password   = AesHelper.AesEncrypt("123456"),
                    Sex        = EnumHelper.GetEnumByValue <SexEnum>(newModel.Gender),
                    UpdateAuth = 1,
                    UpdateTime = DateTime.Now,
                    UserType   = UserTypeEnum.Usually,
                    UserName   = Guid.NewGuid().ToString()
                };
                var accountService = new AccountService();
                var resultId       = accountService.InsertWeChatUserAndBind(newSysModel, newModel.OpenId);
                newModel.AccountId = resultId;
                searchOpenIdModel  = newModel;
            }
            //TODO:未绑定用户,自动注册绑定
            else if (searchOpenIdModel.AccountId < 1)
            {
                var newSysModel = new SysUser
                {
                    Birthday   = "1900-01-01 00:00:00",
                    CreateTime = DateTime.Now,
                    IsDel      = FlagEnum.HadZore,
                    CreateAuth = 1,
                    HeadUrl    = searchOpenIdModel.AvatarUrl,
                    Password   = AesHelper.AesEncrypt("123456"),
                    Sex        = EnumHelper.GetEnumByValue <SexEnum>(searchOpenIdModel.Gender),
                    UpdateAuth = 1,
                    UpdateTime = DateTime.Now,
                    UserType   = UserTypeEnum.Usually,
                    UserName   = Guid.NewGuid().ToString()
                };
                var accountService = new AccountService();
                var resultId       = accountService.InsertWeChatUserAndBind(newSysModel, searchOpenIdModel.OpenId);
                searchOpenIdModel.AccountId = resultId;
            }
            //TODO:更新用户的昵称,头像
            else
            {
                searchOpenIdModel.AvatarUrl  = responseData.avatarUrl;
                searchOpenIdModel.NickName   = responseData.nickName;
                searchOpenIdModel.UpDateTime = DateTime.Now;
                server.SaveModel(searchOpenIdModel);
            }

            //TODO:获取家庭成员信息
            var userIds = new List <long>();

            if (searchOpenIdModel.HadBindFamily == FlagEnum.HadOne &&
                !string.IsNullOrEmpty(searchOpenIdModel.FamilyCode))
            {
                var members = _familyServer.GetFamilyMembers(searchOpenIdModel.FamilyCode);
                if (members != null && members.Count > 0)
                {
                    userIds.AddRange(members.Select(f => f.UserId));
                }
            }

            var weChatMemberList = new List <WeChatAuthResponseModel>();

            if (userIds.Count > 0)
            {
                var weChatMembers = server.Get(userIds);
                if (weChatMembers != null && weChatMembers.Count > 0)
                {
                    weChatMemberList = weChatMembers.Select(f => new WeChatAuthResponseModel
                    {
                        AvatarUrl = f.AvatarUrl,
                        AccountId = f.AccountId,
                        NickName  = f.NickName
                    }).ToList();
                }
            }

            var resultModel = new WeChatAuthResponseModel
            {
                Token            = Guid.NewGuid().ToString(),
                CodeTimeSpan     = responseData.watermark?.timestamp,
                AvatarUrl        = responseData.avatarUrl,
                AccountId        = searchOpenIdModel.AccountId,
                NickName         = responseData.nickName,
                WechatMemberList = weChatMemberList
            };

            //TODO:记录Token信息
            RedisCacheHelper.AddSet(RedisCacheKey.AuthInfoKey + loginInfo.code, resultModel, DateTime.Now.AddHours(2));
            RedisCacheHelper.AddSet(RedisCacheKey.AuthTokenKey + resultModel.Token, searchOpenIdModel, DateTime.Now.AddHours(2));
            return(new ResponseBaseModel <WeChatAuthResponseModel> {
                ResultCode = ResponceCodeEnum.Success, Message = "微信认证成功", Data = resultModel
            });
        }