예제 #1
0
        /// <summary>
        /// 获取所有数据
        /// msg为SQL语句
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <ResultObj <Dictionary <string, object> > > QueryExecute(QuerySearchDto inEnt)
        {
            ResultObj <Dictionary <string, object> > reObj = new ResultObj <Dictionary <string, object> >();
            Dictionary <string, object> reEnt = new Dictionary <string, object>();

            SysQueryEntity query = await dal.Single(i => i.code == inEnt.code);

            if (query == null)
            {
                return(reObj);
            }
            IList <QueryCfg> cfg = TypeChange.ToJsonObject <List <QueryCfg> >(query.queryCfgJson);

            string whereStr = "";
            string AllSql   = MakeSql(inEnt, query.queryConf, ref whereStr);

            reObj.msg = AllSql;
            if (string.IsNullOrEmpty(inEnt.orderStr))
            {
                inEnt.orderStr = "(SELECT 0)";
            }
            try
            {
                reObj.dataList = dal.Query(AllSql);
                reObj.total    = reObj.dataList.Count();
            }
            catch
            {
                return(reObj);
            }
            return(reObj);
        }
예제 #2
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);
        }
예제 #3
0
        /// <summary>
        /// 修改用户密码
        /// <para>entity:旧密码</para>
        /// <para>NewPwd:新密码</para>
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        async public Task <ResultObj <bool> > UserEditPwd(EditPwdDto inEnt)
        {
            var reObj = new ResultObj <bool>();

            reObj.data = false;
            if (!inEnt.NewPwd.Equals(inEnt.ReNewPwd))
            {
                reObj.success = false;
                reObj.msg     = "两次密码不一致";
                return(reObj);
            }
            if (!Fun.CheckPassword(inEnt.NewPwd, appConfig.BaseConfig.PwdComplexity))
            {
                reObj.success = false;
                reObj.code    = "-2";
                reObj.msg     = string.Format("密码复杂度不够:{0}", appConfig.BaseConfig.PwdComplexity);
                return(reObj);
            }
            DapperHelper <SysLoginEntity> dapper = new DapperHelper <SysLoginEntity>();
            var single = await dapper.Single(i => i.loginName == inEnt.LoginName);

            if (single == null)
            {
                reObj.success = false;
                reObj.msg     = "账号不存在";
                return(reObj);
            }
            if (single.password != inEnt.OldPwd.Md5())
            {
                reObj.success = false;
                reObj.msg     = "原密码有误";
                return(reObj);
            }

            single.password = inEnt.NewPwd.Md5();
            var upRows = await dapper.Update(new DtoSave <SysLoginEntity>
            {
                data             = single,
                saveFieldListExp = x => new object[] { x.password },
                whereList        = null
            });

            if (upRows < 1)
            {
                reObj.success = false;
                reObj.msg     = "修改密码失败";
                return(reObj);
            }

            reObj.success = true;
            reObj.data    = true;
            return(reObj);
        }
예제 #4
0
        /// <summary>
        /// 重置用户密码
        /// <para>VerifyCode:短信验证码</para>
        /// <para>LoginName:登录名</para>
        /// <para>NewPwd:新密码</para>
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <Result> ResetPassword(ResetPasswordDto inEnt)
        {
            Result reObj = new Result();

            if (string.IsNullOrEmpty(inEnt.VerifyCode) || string.IsNullOrEmpty(inEnt.LoginName) || string.IsNullOrEmpty(inEnt.NewPwd))
            {
                reObj.success = false;
                reObj.msg     = "参数不正确";
                return(reObj);
            }
            var dapper = new DapperHelper <SysLoginEntity>();

            var login = await dapper.Single(x => x.loginName == inEnt.LoginName);

            if (login == null)
            {
                reObj.success = false;
                reObj.msg     = "登录名不存在";
                return(reObj);
            }
            //if (login.verifyCode != inEnt.VerifyCode)
            //{
            //    reObj.success = false;
            //    reObj.msg = "验证码不正确";
            //    return reObj;
            //}
            //检测密码复杂度
            if (!Fun.CheckPassword(inEnt.NewPwd, appConfig.BaseConfig.PwdComplexity))
            {
                reObj.success = false;
                reObj.msg     = "密码复杂度不够:";
                return(reObj);
            }
            login.password = inEnt.NewPwd.Md5();
            await dapper.Update(new DtoSave <SysLoginEntity>()
            {
                data             = login,
                saveFieldListExp = x => new object[] { x.password }
            });

            return(reObj);
        }
예제 #5
0
        public async Task <ResultObj <SysUserEntity> > UserLogin(string username, string password)
        {
            ResultObj <SysUserEntity>     reObj  = new ResultObj <SysUserEntity>();
            DapperHelper <SysLoginEntity> dapper = new DapperHelper <SysLoginEntity>();
            var login = await dapper.Single(x => x.loginName == username);

            if (login != null)
            {
                if (login.password.ToLower().Equals(Fun.Md5Hash(password).ToLower()))
                {
                    reObj.data = await new DapperHelper <SysUserEntity>().Single(x => x.loginName == username);
                }
                else
                {
                    reObj.msg = "密码错误";
                }
            }
            else
            {
                reObj.msg = "用户名不存在";
            }
            return(reObj);
        }
예제 #6
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);
        }
예제 #7
0
        /// <summary>
        /// 替换账号
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <Result> ChangeLoginName(ChangeLoginNameDto inEnt)
        {
            Result reObj = new Result();
            DapperHelper <SysUserEntity> userDapper = new DapperHelper <SysUserEntity>();

            userDapper.TranscationBegin();
            try
            {
                var loginDapper = new DapperHelper <SysLoginEntity>(userDapper.GetConnection(), userDapper.GetTransaction());
                if ((await loginDapper.Count(x => x.loginName == inEnt.newLoginName)) > 0 || (await userDapper.Count(x => x.loginName == inEnt.newLoginName)) > 0)
                {
                    userDapper.TranscationRollback();
                    reObj.success = false;
                    reObj.msg     = string.Format("账号{0}已经存在", inEnt.newLoginName);
                }
                else
                {
                    var pwd   = inEnt.password.Md5();
                    var login = await loginDapper.Single(x => x.loginName == inEnt.oldLoginName && x.password == pwd);

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

                    if (login == null || user == null)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("原账号有误");
                        return(reObj);
                    }

                    user.loginName  = inEnt.newLoginName;
                    login.loginName = inEnt.newLoginName;

                    reObj.success = await loginDapper.Update(new DtoSave <SysLoginEntity>
                    {
                        data             = login,
                        saveFieldListExp = x => new object[] { x.loginName },
                        whereList        = null
                    }) > 0;

                    if (!reObj.success)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("更新账号失败");
                        return(reObj);
                    }

                    reObj.success = await userDapper.Update(new DtoSave <SysUserEntity>
                    {
                        data             = user,
                        saveFieldListExp = x => new object[] { x.loginName },
                        whereList        = null
                    }) > 0;

                    if (!reObj.success)
                    {
                        userDapper.TranscationRollback();
                        reObj.success = false;
                        reObj.msg     = string.Format("更新用户失败");
                        return(reObj);
                    }
                    reObj.success = true;
                    userDapper.TranscationCommit();
                }
            }
            catch (Exception e)
            {
                userDapper.TranscationRollback();
                reObj.success = false;
                reObj.msg     = e.Message;
            }
            return(reObj);
        }
예제 #8
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);
        }
예제 #9
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);
        }