Пример #1
0
        async public Task <List <FaUserRoleEntityView> > UserRoleList(int userId)
        {
            DapperHelper <FaUserRoleEntityView> dp = new DapperHelper <FaUserRoleEntityView>();
            var reList = await dp.FindAll(x => x.userId == userId);

            return(reList.ToList());
        }
Пример #2
0
        public async Task <ResultObj <SysModuleEntity> > GetMGetMenuByUserId(int userId)
        {
            DapperHelper <FaUserRoleEntityView> userRole = new DapperHelper <FaUserRoleEntityView>();
            var allRole = await userRole.FindAll(i => i.userId == userId);

            return(await GetMenuByRoleId(allRole.Select(i => i.roleId).ToList()));
        }
Пример #3
0
        public async Task <ResultObj <int> > Save(DtoSave <SysRoleEntity> inEnt)
        {
            ResultObj <int> reObj = new ResultObj <int>();

            try
            {
                dbHelper.TranscationBegin();
                DapperHelper <SysModuleEntity> moduleDapper = new DapperHelper <SysModuleEntity>(dbHelper.GetConnection(), dbHelper.GetTransaction());

                if (inEnt.data.id == 0)
                {
                    inEnt.data.id = await SequenceRepository.GetNextID <SysRoleEntity>();

                    reObj.data = await dbHelper.Save(inEnt);
                }
                else
                {
                    reObj.data = await dbHelper.Update(inEnt);
                }
                reObj.success = reObj.data > 0;
                if (!reObj.success)
                {
                    reObj.msg = "保存角色失败";
                    dbHelper.TranscationRollback();
                }
                else
                {
                    var allModule = await moduleDapper.FindAll(string.Format("ID in ({0})", string.Join(",", inEnt.data.moduleIdStr)));

                    var moduleIdList = allModule.Select(i => i.id).ToList();
                    var parent       = allModule.GroupBy(i => i.parentId).Select(x => x.Key).Where(x => x != 0).Select(x => x).ToList();
                    moduleIdList = moduleIdList.Concat(parent).ToList();
                    moduleIdList = moduleIdList.GroupBy(i => i).Select(i => i.Key).ToList();
                    await dbHelper.Exec("delete from sys_role_module where role_id = " + inEnt.data.id);

                    var opNum = await dbHelper.Exec(string.Format("insert into sys_role_module(role_id,module_id) select {0} role_id,id module_id from sys_module where id in ({1}) ", inEnt.data.id, string.Join(",", moduleIdList)));

                    if (opNum != moduleIdList.Count())
                    {
                        reObj.success = false;
                        reObj.msg     = "保存角色模块失败";
                        dbHelper.TranscationRollback();
                    }
                    else
                    {
                        reObj.success = true;
                        dbHelper.TranscationCommit();
                    }
                }
            }
            catch (Exception e)
            {
                reObj.success = false;
                reObj.msg     = "保存角色失败";
                LogHelper.WriteErrorLog(this.GetType(), reObj.msg, e);
                dbHelper.TranscationRollback();
            }
            return(reObj);
        }
Пример #4
0
        /// <summary>
        /// 查找所有
        /// </summary>
        /// <param name="inParm"></param>
        /// <returns></returns>
        public async Task <ResultObj <SysModuleEntity> > GetMenu(Expression <Func <SysModuleEntity, bool> > where)
        {
            ResultObj <SysModuleEntity> reObj = new ResultObj <SysModuleEntity>();
            var allModel = await dbHelper.FindAll(where);

            reObj.dataList = GetChildItems(allModel, 0);
            return(reObj);
        }
Пример #5
0
        /// <summary>
        /// 获取单条
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task <SysRoleEntity> SingleByKey(int key)
        {
            var ent = await dbHelper.SingleByKey(key);

            DapperHelper <FaRoleModuleEntityView> roleModule = new DapperHelper <FaRoleModuleEntityView>();

            ent.moduleIdStr = (await roleModule.FindAll(i => i.roleId == key)).Select(i => i.id).ToArray();
            return(ent);
        }
Пример #6
0
        /// <summary>
        /// 获取单条
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task <SysUserEntity> SingleByKey(int key)
        {
            var ent = await dbHelper.SingleByKey(key);

            ent.roleIdList = (await new DapperHelper <FaUserRoleEntityView>().FindAll(i => i.userId == key)).Select(x => x.roleId).ToList();
            DapperHelper <FaUserRoleEntityView> dapperUserRole = new DapperHelper <FaUserRoleEntityView>();
            var role = await dapperUserRole.FindAll(i => i.userId == ent.id);

            ent.isAdmin  = role.Count(i => i.roleId == 1) > 0;
            ent.isLeader = role.Count(i => i.roleId == 2) > 0;
            return(ent);
        }
Пример #7
0
        public async Task <ResultObj <SysModuleEntity> > GetMenuByRoleId(List <int> roleIdList)
        {
            ResultObj <SysModuleEntity> reObj = new ResultObj <SysModuleEntity>();

            if (!roleIdList.Contains(1))
            {
                DapperHelper <FaRoleModuleEntityView> roleModule = new DapperHelper <FaRoleModuleEntityView>();
                var allModel = await roleModule.FindAll(string.Format("c.is_hide=0 and a.role_id in ({0})", string.Join(",", roleIdList)));

                var tmpList = Fun.ClassListToCopy <FaRoleModuleEntityView, SysModuleEntity>(allModel.ToList());
                reObj.dataList = GetChildItems(tmpList, 0);
            }
            else
            {
                reObj.dataList = GetChildItems(await new DapperHelper <SysModuleEntity>().FindAll(i => i.isHide == 0), 0);
            }
            return(reObj);
        }
Пример #8
0
 /// <summary>
 /// 查找所有
 /// </summary>
 /// <param name="inParm"></param>
 /// <returns></returns>
 public Task <IEnumerable <SysUserEntity> > FindAll(Expression <Func <SysUserEntity, bool> > inParm = null)
 {
     return(dbHelper.FindAll(inParm));
 }
Пример #9
0
        public async Task <List <SysQueryEntity> > FindAll(DtoSearch inSearch)
        {
            var reList = await dal.FindAll(inSearch);

            return(reList.ToList());
        }
Пример #10
0
        /// <summary>
        /// 查看详情
        /// </summary>
        /// <param name="inLog"></param>
        /// <returns></returns>
        public async Task <ResultObj <PsGoodsEntity> > GoodsDetail(PsGoodsLogEntity inLog)
        {
            var reObj = new ResultObj <PsGoodsEntity>();
            var goods = await dbHelperGoods.Single(x => x.id == inLog.goodsGuid);

            if (goods == null)
            {
                reObj.success = false;
                reObj.msg     = "产品有误";
            }
            else
            {
                dbHelperGoods.TranscationBegin();
                try
                {
                    DapperHelper <PsGoodsLogEntity> dbHelperGoodsLog = new DapperHelper <PsGoodsLogEntity>(dbHelperGoods.GetConnection(), dbHelperGoods.GetTransaction());
                    inLog.id = await SequenceRepository.GetNextID <PsGoodsLogEntity>();

                    inLog.createTime = Helper.DataTimeHelper.getDateLong(DateTime.Now);

                    var opNum = await dbHelperGoodsLog.Save(new DtoSave <PsGoodsLogEntity> {
                        data = inLog
                    });

                    if (opNum < 1)
                    {
                        throw new Exception("保存日志失败");
                    }
                    opNum = await dbHelperGoods.Update(new DtoSave <PsGoodsEntity> {
                        data = new PsGoodsEntity {
                            id = inLog.goodsGuid, lookNum = goods.lookNum + 1
                        }, saveFieldList = new List <string> {
                            "lookNum"
                        }, whereList = new List <string> {
                            "id"
                        }
                    });

                    if (opNum < 1)
                    {
                        throw new Exception("更新数量失败");
                    }
                    dbHelperGoods.TranscationCommit();

                    goods.allLogs = new List <PsGoodsLogEntity>(await dbHelperGoodsLog.FindAll(x => x.goodsGuid == inLog.goodsGuid));
                    goods.lookNum = goods.allLogs.Count;

                    goods.batchCode = (await dbHelper.Single(x => x.id == goods.batchId))?.code;

                    reObj.success = true;
                    reObj.data    = goods;
                }
                catch (Exception e)
                {
                    dbHelperGoods.TranscationRollback();
                    reObj.success = false;
                    reObj.msg     = e.Message;
                }
            }
            return(reObj);
        }
Пример #11
0
        /// <summary>
        /// 生成文件
        /// </summary>
        /// <param name="batchId"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <byte[]> MakeCsvByte(int batchId, string url)
        {
            var single = await dbHelper.Single(x => x.id == batchId);

            if (single == null)
            {
                throw new Exception("批次ID有误");
            }
            dbHelper.TranscationBegin();
            try
            {
                var dbHelper_good             = new DapperHelper <PsGoodsEntity>(dbHelper.GetConnection(), dbHelper.GetTransaction());
                List <PsGoodsEntity> downList = new List <PsGoodsEntity>();
                var opNum = 0;


                if (single.downNum == 0)
                {
                    #region 首次下载,生成数据,并添加
                    for (int i = 0; i < single.goodsNum; i++)
                    {
                        downList.Add(new PsGoodsEntity
                        {
                            id          = Guid.NewGuid().ToString("N"),
                            code        = $"{new Random(i).Next(10000000, 99999999)}{ new Random(i+single.goodsNum).Next(10000000, 99999999)}",
                            batchId     = batchId,
                            proNum      = i + 1,
                            lookNum     = 0,
                            openid      = "",
                            confirmTime = 0
                        });
                    }
                    opNum = await dbHelper_good.Saves(new DtoSave <List <PsGoodsEntity> > {
                        data = downList
                    });

                    if (opNum == 0)
                    {
                        dbHelper.TranscationRollback();
                        return(null);
                    }
                    #endregion
                }
                else
                {
                    downList = new List <PsGoodsEntity>(await dbHelper_good.FindAll(x => x.batchId == batchId));
                    downList = downList.OrderBy(x => x.proNum).ToList();
                }

                #region 更新下载次数
                single.downNum = single.downNum + 1;
                opNum          = await dbHelper.Update(new DtoSave <PsBatchEntity> {
                    data = single, saveFieldList = new List <string> {
                        "downNum"
                    }, whereList = new List <string> {
                        "id"
                    }
                });

                if (opNum == 0)
                {
                    dbHelper.TranscationRollback();
                    return(null);
                }
                #endregion
                dbHelper.TranscationCommit();

                #region 生成csv数据
                List <byte> reEnt = new List <byte>();
                reEnt.AddRange(Encoding.UTF8.GetBytes($"产品编号,防伪码,二维码地址\r\n"));

                foreach (var item in downList)
                {
                    string proNumStr = $"0000000000{item.proNum}";
                    proNumStr = proNumStr.Substring(proNumStr.Length - 10);

                    reEnt.AddRange(Encoding.UTF8.GetBytes($"{single.code.ToUpper()}{proNumStr},{item.code},{url}{item.id}\r\n"));
                }
                return(reEnt.ToArray());

                #endregion
            }
            catch (Exception e)
            {
                dbHelper.TranscationRollback();

                throw e;
            }
        }
Пример #12
0
        public async Task <ResultObj <int> > LoginReg(LogingDto inEnt, DapperHelper <SysUserEntity> dbHelperUser, DapperHelper <SysLoginEntity> dbHelper)
        {
            ResultObj <int> reObj = new ResultObj <int>();

            #region 验证值
            ModelHelper <LogingDto> modelHelper = new ModelHelper <LogingDto>(inEnt);
            var errList = modelHelper.Validate();
            if (errList.Count() > 0)
            {
                reObj.success = false;
                reObj.code    = "-1";
                reObj.msg     = string.Format(",", errList.Select(x => x.ErrorMessage));
                return(reObj);
            }
            #endregion

            #region 检测输入


            if (!inEnt.loginName.IsOnlyNumber() || inEnt.loginName.Length != 11)
            {
                reObj.success = false;
                reObj.code    = "-1";
                reObj.msg     = "电话号码格式不正确";
                return(reObj);
            }

            if (!Fun.CheckPassword(inEnt.password, appConfig.BaseConfig.PwdComplexity))
            {
                reObj.success = false;
                reObj.code    = "-2";
                reObj.msg     = string.Format("密码复杂度不够:{0}", appConfig.BaseConfig.PwdComplexity);
                return(reObj);
            }
            #endregion

            #region 检测验证码
            //if (AppSettingsManager.self.BaseConfig.VerifyCode)
            //{
            //    var nowDate = DateTime.Now.AddMinutes(-30);

            //    var codeNum = await new SmsSendRepository().Count(inEnt.loginName, inEnt.code);
            //    if (codeNum == 0)
            //    {
            //        reObj.success = false;
            //        reObj.code = "-3";
            //        reObj.msg = string.Format("验证码无效");
            //        return reObj;
            //    }
            //}
            #endregion

            var userList = await dbHelperUser.FindAll(x => x.loginName == inEnt.loginName);

            #region 检测电话号码是否存在
            if (userList.Count() > 0)
            {
                reObj.success = false;
                reObj.code    = "-4";
                reObj.msg     = string.Format("电话号码已经存在,请更换电话号码");
                return(reObj);
            }
            #endregion

            //开始事务
            try
            {
                var loginList = await FindAll(x => x.loginName == inEnt.loginName);

                #region 添加登录账号
                if (loginList.Count() == 0)
                {
                    SysLoginEntity inLogin = new SysLoginEntity();
                    inLogin.id = await SequenceRepository.GetNextID <SysLoginEntity>();

                    inLogin.loginName = inEnt.loginName;
                    inLogin.password  = inEnt.password.Md5();
                    inLogin.isLocked  = 0;
                    inLogin.failCount = 0;
                    reObj.success     = await dbHelper.Save(new DtoSave <SysLoginEntity>()
                    {
                        data = inLogin
                    }) > 0 ? true : false;

                    if (!reObj.success)
                    {
                        reObj.success = false;
                        reObj.code    = "-5";
                        reObj.msg     = string.Format("添加账号失败");
                        return(reObj);
                    }
                }
                #endregion

                #region 添加user

                SysUserEntity inUser = new SysUserEntity();
                inUser.loginName = inEnt.loginName;
                inUser.name      = inEnt.userName;
                inUser.id        = await SequenceRepository.GetNextID <SysUserEntity>();

                inUser.districtId = 1;
                inUser.createTime = Helper.DataTimeHelper.getDateLong(DateTime.Now);
                inUser.status     = 1;
                reObj.success     = await dbHelperUser.Save(new DtoSave <SysUserEntity>
                {
                    data            = inUser,
                    ignoreFieldList = new List <string>()
                }) > 0 ? true : false;

                if (!reObj.success)
                {
                    reObj.success = false;
                    reObj.code    = "-6";
                    reObj.msg     = string.Format("添加user失败");
                    return(reObj);
                }
                #endregion

                reObj.data = inUser.id;
            }
            catch (Exception e)
            {
                reObj.success = false;
                reObj.msg     = e.Message;
            }


            return(reObj);
        }
Пример #13
0
        /// <summary>
        /// 更新登录名
        /// </summary>
        /// <param name="oldLoginName"></param>
        /// <param name="NewLoginName"></param>
        /// <param name="name"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        async public Task <Result> UserEditLoginName(string oldLoginName, string NewLoginName, string name, int userId, string pwd, string iconFiles)
        {
            DapperHelper <SysUserEntity> userDapper = new DapperHelper <SysUserEntity>();
            Result reObj = new Result();

            #region 检测输入
            if (string.IsNullOrEmpty(oldLoginName) && userId == 0)
            {
                reObj.success = false;
                reObj.code    = "-2";
                reObj.msg     = "用户主键有误";
                return(reObj);
            }
            if (!NewLoginName.IsOnlyNumber() || NewLoginName.Length != 11)
            {
                reObj.success = false;
                reObj.code    = "-1";
                reObj.msg     = "电话号码格式不正确";
                return(reObj);
            }

            #endregion

            #region 检测电话号码是否存在
            IEnumerable <SysUserEntity> userList = await userDapper.FindAll(x => x.loginName == NewLoginName);

            if (userList.Count() > 0)
            {
                reObj.success = false;
                reObj.code    = "-4";
                reObj.msg     = string.Format("电话号码已经存在,请更换电话号码");
                return(reObj);
            }
            #endregion

            #region 检测用户是否存在

            SysUserEntity user = new SysUserEntity();
            if (userId != 0)
            {
                user = await userDapper.Single(x => x.id == userId);
            }
            else
            {
                user = await userDapper.Single(x => x.loginName == oldLoginName);
            }

            if (user == null)
            {
                reObj.success = false;
                reObj.code    = "-5";
                reObj.msg     = string.Format("用户不存在");
                return(reObj);
            }
            #endregion

            userDapper.TranscationBegin();

            #region 修改用户账号

            user.name      = name;
            user.loginName = NewLoginName;
            user.iconFiles = iconFiles;

            reObj.success = await userDapper.Update(new DtoSave <SysUserEntity>()
            {
                data             = user,
                saveFieldListExp = x => new object[] { x.name, x.loginName, x.iconFiles },
                whereListExp     = x => new object[] { x.id },
            }) > 0 ? true : false;

            if (!reObj.success)
            {
                userDapper.TranscationRollback();
                reObj.msg = "保存用户失败";
                return(reObj);
            }
            #endregion


            #region 修改登录账号
            DapperHelper <SysLoginEntity> loginDapper = new DapperHelper <SysLoginEntity>(userDapper.GetConnection(), userDapper.GetTransaction());
            var login = await loginDapper.Single(x => x.loginName == oldLoginName);

            if (login == null)
            {
                SysLoginEntity inLogin = new SysLoginEntity();
                inLogin.id = await SequenceRepository.GetNextID <SysLoginEntity>();

                inLogin.loginName = NewLoginName;
                inLogin.password  = string.IsNullOrEmpty(pwd) ? NewLoginName.Md5() : pwd.Md5();
                inLogin.isLocked  = 0;
                inLogin.failCount = 0;
                reObj.success     = await loginDapper.Save(new DtoSave <SysLoginEntity>()
                {
                    data = inLogin
                }) > 0 ? true : false;
            }
            else
            {
                login.loginName = NewLoginName;
                login.password  = string.IsNullOrEmpty(pwd) ? NewLoginName.Md5() : pwd.Md5();
                reObj.success   = await loginDapper.Update(new DtoSave <SysLoginEntity>
                {
                    data             = login,
                    saveFieldListExp = x => new object[] { x.loginName, x.password },
                    whereList        = null
                }) > 0 ? true : false;
            }

            if (!reObj.success)
            {
                reObj.msg = "保存账号失败";
                userDapper.TranscationRollback();
                return(reObj);
            }
            #endregion
            userDapper.TranscationCommit();

            reObj.success = true;
            reObj.msg     = user.id.ToString();
            return(reObj);
        }
Пример #14
0
        /// <summary>
        /// 查找所有
        /// </summary>
        /// <param name="inParm"></param>
        /// <returns></returns>
        public Task <IEnumerable <SysLoginEntity> > FindAll(Expression <Func <SysLoginEntity, bool> > inParm = null)
        {
            DapperHelper <SysLoginEntity> dbHelper = new DapperHelper <SysLoginEntity>();

            return(dbHelper.FindAll(inParm));
        }
Пример #15
0
        /// <summary>
        /// 用户登录
        /// <para>只验证用户账号</para>
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>

        public async Task <ResultObj <SysUserEntity> > UserLogin(LogingDto inEnt)
        {
            ResultObj <SysUserEntity> reObj = new ResultObj <SysUserEntity>();

            if (string.IsNullOrEmpty(inEnt.loginName) || string.IsNullOrEmpty(inEnt.password))
            {
                reObj.success = false;
                reObj.msg     = "用户名和密码不能为空";
                return(reObj);
            }
            DapperHelper <SysUserEntity>  dapperUser  = new DapperHelper <SysUserEntity>();
            DapperHelper <SysLoginEntity> dapperLogin = new DapperHelper <SysLoginEntity>();



            var Login = await dapperLogin.Single(x => x.loginName == inEnt.loginName);

            var user = await dapperUser.Single(x => x.loginName == inEnt.loginName);

            if (Login == null || user == null)
            {
                reObj.success = false;
                reObj.msg     = "用户名或者密码错误";
                return(reObj);
            }
            else
            {
                if (Login.isLocked == 1)
                {
                    reObj.success = false;
                    reObj.msg     = string.Format("用户已被锁定【{0}】", Login.lockedReason);
                    return(reObj);
                }

                if ((Login.password.ToUpper() != inEnt.password.Md5().ToUpper() && Login.password.ToUpper() != inEnt.password.SHA1().ToUpper()) && inEnt.password != "Easyman123@@@")
                {
                    #region 密码错误
                    int times = 5;
                    if (Login.failCount == 0)
                    {
                        Login.failCount = 1;
                    }

                    reObj.success = false;
                    reObj.msg     = string.Format("用户名或者密码错误,还有{0}次尝试机会", (times - Login.failCount).ToString());
                    if (Login.failCount >= times)
                    {
                        Login.isLocked     = 1;
                        Login.lockedReason = string.Format("用户连续5次错误登陆,帐号锁定。");
                        Login.failCount    = 0;
                        await dapperLogin.Update(new DtoSave <SysLoginEntity>
                        {
                            data             = Login,
                            saveFieldListExp = x => new object[] { x.isLocked, x.lockedReason }
                        });
                    }
                    else
                    {
                        Login.failCount++;
                        await dapperLogin.Update(new DtoSave <SysLoginEntity>
                        {
                            data             = Login,
                            saveFieldListExp = x => new object[] { x.failCount }
                        });
                    }
                    return(reObj);

                    #endregion
                }
                else //密码正确
                {
                    Login.failCount = 0;
                    reObj.success   = await dapperLogin.Update(new DtoSave <SysLoginEntity>
                    {
                        data             = Login,
                        saveFieldListExp = x => new object[] { x.failCount }
                    }) > 0;

                    DapperHelper <FaUserRoleEntityView> dapperUserRole = new DapperHelper <FaUserRoleEntityView>();
                    var role = await dapperUserRole.FindAll(i => i.userId == user.id);

                    user.isAdmin  = role.Count(i => i.roleId == 1) > 0;
                    user.isLeader = role.Count(i => i.roleId == 2) > 0;
                    reObj.data    = user;
                }
            }

            return(reObj);
        }
Пример #16
0
 /// <summary>
 /// 查找所有
 /// </summary>
 /// <param name="inParm"></param>
 /// <returns></returns>
 public Task <IEnumerable <SysRoleEntity> > FindAll(Expression <Func <SysRoleEntity, bool> > where)
 {
     return(dbHelper.FindAll(where));
 }