hwh
2024-07-04 2dd922eb3ab68c0314f5828fcae1ed7db0e17d9e
Wms/WMS.BLL/SysServer/UnitServer.cs
@@ -33,9 +33,7 @@
        /// <param name="limit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<UnitDto> GetUnitList(string unitNo, string unitName, int page, int limit, out int count)
        {
            try
        public async Task<List<UnitDto>> GetUnitList(string unitNo, string unitName, int page, int limit, RefAsync<int> count)
            {
                Expression<Func<SysUnit, bool>> item = Expressionable.Create<SysUnit>() //创建表达式
                    .AndIF(!string.IsNullOrWhiteSpace(unitNo), it => it.UnitNo.Contains(unitNo.Trim()))
@@ -43,9 +41,9 @@
                    .ToExpression();//注意 这一句 不能少
                var data = UnitRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
            var data = await UnitRst.GetAllByOrderPage(item, limit, page, out int counts)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToList();
                .Includes(x => x.UpdateUserInfo).ToListAsync();
                count = counts;
                return data.Select(m => new UnitDto()
                {
@@ -58,30 +56,16 @@
                    UpdateTime = m.UpdateTime,
                    UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName
                }).ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 获取单条单位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SysUnit GetUnit(int id)
        public async Task<SysUnit> GetUnit(int id)
        {
            try
            {
                var data = UnitRst.GetOneById(id);
            var data = await UnitRst.GetOneByIdAsync(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 添加单位信息
@@ -90,13 +74,13 @@
        /// <param name="abbrev">缩写</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool AddUnit(string unitName, string abbrev, int userId)
        public async Task<bool> AddUnit(string unitName, string abbrev, int userId)
        {
            try
            {
                if (string.IsNullOrEmpty(abbrev))
                {
                    var date = UnitRst.GetAllWhereAsync(m => m.UnitName == unitName).Count();
                    var date = await UnitRst.GetAllWhere(m => m.UnitName == unitName).CountAsync();
                    if (date > 0)
                    {
                        throw new Exception("单位名称重复");
@@ -104,7 +88,7 @@
                }
                else
                {
                    var date = UnitRst.GetAllWhereAsync(m => m.UnitName == unitName || m.Abbrev == abbrev).Count();
                    var date = await UnitRst.GetAllWhere(m => m.UnitName == unitName || m.Abbrev == abbrev).CountAsync();
                    if (date > 0)
                    {
                        throw new Exception("单位名称或英文缩写重复");
@@ -112,7 +96,7 @@
                }
                //自动UnitCode处理
                var unitList = UnitRst.GetAllAsync().OrderByDescending(m => m.UnitNo);
                var unitList = UnitRst.GetAll().OrderByDescending(m => m.UnitNo);
                var code = "01";
                if (unitList != null && unitList.Count()>0)
                {
@@ -122,7 +106,7 @@
                    code = str == "0" ? (str2 == "9" ? (int.Parse(str2) + 1).ToString() : "0" + (int.Parse(str2) + 1)) : (int.Parse(unitCode) + 1).ToString();
                }
                var num = UnitRst.Add(new SysUnit()
                var num = await UnitRst.AddAsync(new SysUnit()
                {
                    UnitNo = code,
                    UnitName = unitName,
@@ -131,7 +115,7 @@
                });
                if (num > 0)
                {
                    _operation.InsertOperation("基础信息", "计量单位", code, "添加", "添加计量单位 单位号:" + code, Convert.ToInt32(userId));
                    await _operation.InsertOperation("基础信息", "计量单位", code, "添加", "添加计量单位 单位号:" + code, Convert.ToInt32(userId));
                }
                return num > 0;
            }
@@ -148,13 +132,11 @@
        /// <param name="abbrev">缩写</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool EditUnit(int id, string unitName, string abbrev, int userId)
        {
            try
        public async Task<bool> EditUnit(int id, string unitName, string abbrev, int userId)
            {
                if (string.IsNullOrEmpty(abbrev))
                {
                    var date = UnitRst.GetAllWhereAsync(m => m.Id != id && m.UnitName == unitName).Count();
                var date = await UnitRst.GetAllWhere(m => m.Id != id && m.UnitName == unitName).CountAsync();
                    if (date > 0)
                    {
                        throw new Exception("单位名称重复");
@@ -162,7 +144,7 @@
                }
                else
                {
                    var date = UnitRst.GetAllWhereAsync(m => m.Id != id && (m.UnitName == unitName || m.Abbrev == abbrev)).Count();
                var date = await UnitRst.GetAllWhere(m => m.Id != id && (m.UnitName == unitName || m.Abbrev == abbrev)).CountAsync();
                    if (date > 0)
                    {
                        throw new Exception("单位名称或英文缩写重复");
@@ -180,51 +162,39 @@
                unit.UpdateUser = userId;
                unit.UpdateTime = DateTime.Now;
                var num = UnitRst.Edit(unit);
            var num = await UnitRst.EditAsync(unit);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public bool DelUnit(int id, int userId)
        {
            try
        public async Task<bool> DelUnit(int id, int userId)
            {
                var unit = UnitRst.GetOneById(id);
                if (unit == null)
                {
                    throw new Exception("未查询到单位信息");
                }
                int num = UnitRst.Remove(id, userId);
            int num = await UnitRst.RemoveAsync(id, userId);
                if (num > 0)
                {
                    _operation.InsertOperation("基础信息", "计量单位", unit.UnitNo, "删除", "删除计量单位 单位号:" + unit.UnitNo, Convert.ToInt32(userId));
                await _operation.InsertOperation("基础信息", "计量单位", unit.UnitNo, "删除", "删除计量单位 单位号:" + unit.UnitNo, Convert.ToInt32(userId));
                }
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public bool DelsUnit(List<int> ids, int userId)
        public async Task<bool> DelsUnit(List<int> ids, int userId)
        {
            try
            {
                var list = UnitRst.GetAllWhereAsync(m => ids.Contains(m.Id)).ToList();
                var list = await UnitRst.GetAllWhere(m => ids.Contains(m.Id)).ToListAsync();
                if (list.Count > 0)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        _operation.InsertOperation("基础信息", "计量单位", list[i].UnitNo, "删除", "删除计量单位 单位号:" + list[i].UnitNo, Convert.ToInt32(userId));
                        await _operation.InsertOperation("基础信息", "计量单位", list[i].UnitNo, "删除", "删除计量单位 单位号:" + list[i].UnitNo, Convert.ToInt32(userId));
                    }
                }
                var num = UnitRst.RemoveAll(list, userId);
                var num = await UnitRst.RemoveAllAsync(list, userId);
                return num > 0;
            }
            catch (Exception e)