Beispiel #1
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);
        }
Beispiel #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);
        }
        /// <summary>
        /// 注册账号
        /// <para>1、添加登录工号 </para>
        /// <para>2、添加用户</para>
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task <ResultObj <int> > LoginReg(LogingDto inEnt)
        {
            DapperHelper <SysLoginEntity> dbHelper = new DapperHelper <SysLoginEntity>();

            dbHelper.TranscationBegin();
            DapperHelper <SysUserEntity> dbHelperUser = new DapperHelper <SysUserEntity>(dbHelper.GetConnection(), dbHelper.GetTransaction());
            ResultObj <int> reObj = await LoginReg(inEnt, dbHelperUser, dbHelper);

            if (reObj.success)
            {
                dbHelper.TranscationCommit();
            }
            else
            {
                dbHelper.TranscationRollback();
            }
            return(reObj);
        }
        public async Task <ResultObj <int> > Save(DtoSave <SysUserEntity> inEnt)
        {
            ResultObj <int> reObj = new ResultObj <int>();

            try
            {
                if (inEnt.data.roleIdList == null)
                {
                    inEnt.data.roleIdList = new List <int>();
                }
                dbHelper.TranscationBegin();
                if (inEnt.data.id == 0)
                {
                    DapperHelper <SysLoginEntity> dbHelperlog = new DapperHelper <SysLoginEntity>(dbHelper.GetConnection(), dbHelper.GetTransaction());
                    var addResult = await loginRepository.LoginReg(new LogingDto { loginName = inEnt.data.loginName, password = "******", userName = inEnt.data.name }, dbHelper, dbHelperlog);

                    if (!addResult.success)
                    {
                        return(addResult);
                    }
                    inEnt.data.id = addResult.data;
                }
                else
                {
                    reObj.data = await dbHelper.Update(inEnt);

                    reObj.success = reObj.data > 0;
                    if (!reObj.success)
                    {
                        reObj.msg = "保存角色失败";
                        dbHelper.TranscationRollback();
                        return(reObj);
                    }
                }

                int v = await dbHelper.Exec("delete from sys_user_role where user_id = " + inEnt.data.id);

                foreach (var item in inEnt.data.roleIdList)
                {
                    var opNum = await dbHelper.Exec(string.Format("insert into sys_user_role(role_id,user_id) values({0},{1}) ", item, inEnt.data.id));

                    if (opNum != 1)
                    {
                        reObj.success = false;
                        reObj.msg     = "保存用户模块失败";
                        dbHelper.TranscationRollback();
                        return(reObj);
                    }
                }

                reObj.success = true;
                dbHelper.TranscationCommit();
            }
            catch (Exception e)
            {
                reObj.success = false;
                reObj.msg     = "保存用户失败";
                LogHelper.WriteErrorLog(this.GetType(), reObj.msg, e);
                dbHelper.TranscationRollback();
            }
            return(reObj);
        }
Beispiel #5
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;
            }
        }
        /// <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);
        }
        /// <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);
        }