Exemplo n.º 1
0
        /// <summary>
        /// 注销用户登录状态
        /// <para>清除用户的缓存状态</para>
        /// <para>记录退出日志</para>
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <Result> LoginOut(DtoSave <SysLoginHistoryEntity> inEnt)
        {
            Result reObj = new Result();

            #region 记录登出历史

            //正常退出,修改退出日志
            DapperHelper <SysLoginEntity> dbHelper = new DapperHelper <SysLoginEntity>();

            reObj.success = await dbHelper.Update(new DtoSave <SysLoginEntity>
            {
                data = new SysLoginEntity {
                    id = inEnt.data.USER_ID.Value, lastActiveTime = Helper.DataTimeHelper.getDateLong(DateTime.Now), lastLogoutTime = Helper.DataTimeHelper.getDateLong(DateTime.Now)
                },
                saveFieldListExp = x => new object[] { x.lastActiveTime, x.lastLogoutTime }
            }) > 0;

            if (!reObj.success)
            {
                return(reObj);
            }
            if (inEnt.data.ID == 0)
            {
                inEnt.data.ID = await SequenceRepository.GetNextID <SysLoginHistoryEntity>();
            }
            //记录登录日志
            await new LoginHistoryRepository().Save(inEnt);

            #endregion

            reObj.success = RedisRepository.UserTokenDelete(inEnt.data.USER_ID.Value);
            return(reObj);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public async Task <int> Save(DtoSave <SysQueryEntity> inEnt)
 {
     if (inEnt.data.id == 0)
     {
         inEnt.data.id = await SequenceRepository.GetNextID <SysQueryEntity>();
     }
     return(await dal.Save(inEnt));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <ResultObj <int> > Save(DtoSave <PsAdminEntity> inEnt)
        {
            var reObj = new ResultObj <int>();

            inEnt.data.createTime = Helper.DataTimeHelper.getDateLong(DateTime.Now);
            inEnt.data.id         = await SequenceRepository.GetNextID <PsAdminEntity>();

            reObj.data = await dbHelper.Save(inEnt);

            reObj.success = reObj.data > 0;
            return(reObj);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 检测货物
        /// </summary>
        /// <param name="inLog"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <ResultObj <PsGoodsEntity> > GoodsCheck(PsGoodsLogEntity inLog, string code)
        {
            var reObj = new ResultObj <PsGoodsEntity>();
            var goods = await dbHelperGoods.Single(x => x.id == inLog.goodsGuid);

            if (goods == null || !goods.code.Equals(code))
            {
                reObj.success = false;
                reObj.msg     = "产品有误";
            }
            else
            {
                inLog.id = await SequenceRepository.GetNextID <PsGoodsLogEntity>();

                inLog.createTime = Helper.DataTimeHelper.getDateLong(DateTime.Now);
                dbHelperGoods.TranscationBegin();
                try
                {
                    DapperHelper <PsGoodsLogEntity> dbHelperGoodsLog = new DapperHelper <PsGoodsLogEntity>(dbHelperGoods.GetConnection(), dbHelperGoods.GetTransaction());
                    var opNum = await dbHelperGoodsLog.Save(new DtoSave <PsGoodsLogEntity> {
                        data = inLog
                    });

                    if (opNum < 1)
                    {
                        throw new Exception("保存日志失败");
                    }
                    goods.confirmTime = inLog.createTime;
                    goods.openid      = inLog.openid;
                    opNum             = await dbHelperGoods.Update(new DtoSave <PsGoodsEntity> {
                        data = goods, saveFieldListExp = x => new object[] { x.confirmTime, x.openid }, whereListExp = x => new object[] { x.id }
                    });

                    if (opNum < 1)
                    {
                        throw new Exception("更新检测失败");
                    }
                    dbHelperGoods.TranscationCommit();
                    reObj.success = true;
                    reObj.data    = goods;
                }
                catch (Exception e)
                {
                    dbHelperGoods.TranscationRollback();
                    reObj.success = false;
                    reObj.msg     = e.Message;
                }
            }
            return(reObj);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 保存日志
        /// </summary>
        /// <param name="inObj"></param>
        /// <returns></returns>
        public async Task <ResultObj <int> > saveLog(WxQuestLogEntity inObj)
        {
            ResultObj <int> resultObj = new ResultObj <int>();
            var             saveEnt   = new DtoSave <WxQuestLogEntity>()
            {
                data = inObj
            };

            saveEnt.data.id = await SequenceRepository.GetNextID <WxQuestLogEntity>();

            resultObj.data = await dbHelper.Save(saveEnt);

            resultObj.success = resultObj.data > 0;
            return(resultObj);
        }
Exemplo n.º 7
0
        public async Task <ResultObj <int> > Save(DtoSave <SysModuleEntity> inEnt)
        {
            ResultObj <int> reObj = new ResultObj <int>();

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

                reObj.data = await dbHelper.Save(inEnt);
            }
            else
            {
                reObj.data = await dbHelper.Update(inEnt);
            }

            reObj.success = reObj.data > 0;
            return(reObj);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }