From 7ceb9b642fc01412fc4fe3e1a44f55cc79c10c88 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期一, 15 七月 2024 17:00:31 +0800
Subject: [PATCH] Merge branch 'hwh'

---
 Wms/WMS.BLL/SysServer/UnitServer.cs |  172 +++++++++++++++++++++++---------------------------------
 1 files changed, 71 insertions(+), 101 deletions(-)

diff --git a/Wms/WMS.BLL/SysServer/UnitServer.cs b/Wms/WMS.BLL/SysServer/UnitServer.cs
index a406675..47838d7 100644
--- a/Wms/WMS.BLL/SysServer/UnitServer.cs
+++ b/Wms/WMS.BLL/SysServer/UnitServer.cs
@@ -33,55 +33,39 @@
         /// <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)
+        public async Task<List<UnitDto>> GetUnitList(string unitNo, string unitName, int page, int limit, RefAsync<int> count)
         {
-            try
+            Expression<Func<SysUnit, bool>> item = Expressionable.Create<SysUnit>() //鍒涘缓琛ㄨ揪寮�
+                .AndIF(!string.IsNullOrWhiteSpace(unitNo), it => it.UnitNo.Contains(unitNo.Trim()))
+                .AndIF(!string.IsNullOrWhiteSpace(unitName), it => it.UnitName.Contains(unitName.Trim()))
+                .ToExpression();//娉ㄦ剰 杩欎竴鍙� 涓嶈兘灏�
+
+
+            var data = await UnitRst.GetAllByOrderPage(item, limit, page, out int counts)
+                .Includes(x => x.CreateUserInfo)
+                .Includes(x => x.UpdateUserInfo).ToListAsync();
+            count = counts;
+            return data.Select(m => new UnitDto()
             {
-                Expression<Func<SysUnit, bool>> item = Expressionable.Create<SysUnit>() //鍒涘缓琛ㄨ揪寮�
-                    .AndIF(!string.IsNullOrWhiteSpace(unitNo), it => it.UnitNo.Contains(unitNo.Trim()))
-                    .AndIF(!string.IsNullOrWhiteSpace(unitName), it => it.UnitName.Contains(unitName.Trim()))
-                    .ToExpression();//娉ㄦ剰 杩欎竴鍙� 涓嶈兘灏�
-
-
-                var data = UnitRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
-                    .Includes(x => x.CreateUserInfo)
-                    .Includes(x => x.UpdateUserInfo).ToList();
-                count = counts;
-                return data.Select(m => new UnitDto()
-                {
-                    Id = m.Id,
-                    UnitNo = m.UnitNo,
-                    UnitName = m.UnitName,
-                    Abbrev = m.Abbrev,
-                    CreateTime = m.CreateTime,
-                    CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName,
-                    UpdateTime = m.UpdateTime,
-                    UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName
-                }).ToList();
-
-
-            }
-            catch (Exception e)
-            {
-                throw new Exception(e.Message);
-            }
+                Id = m.Id,
+                UnitNo = m.UnitNo,
+                UnitName = m.UnitName,
+                Abbrev = m.Abbrev,
+                CreateTime = m.CreateTime,
+                CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName,
+                UpdateTime = m.UpdateTime,
+                UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName
+            }).ToList();
         }
         /// <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);
-                return data;
-            }
-            catch (Exception e)
-            {
-                throw new Exception(e.Message);
-            }
+            var data = await UnitRst.GetOneByIdAsync(id);
+            return data;
         }
         /// <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,9 +96,9 @@
                 }
 
                 //鑷姩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)
+                if (unitList != null && unitList.Count() > 0)
                 {
                     var unitCode = unitList.First().UnitNo;
                     var str = unitCode.Substring(0, 1);
@@ -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,83 +132,69 @@
         /// <param name="abbrev">缂╁啓</param>
         /// <param name="userId">鎿嶄綔浜�</param>
         /// <returns></returns>
-        public bool EditUnit(int id, string unitName, string abbrev, int userId)
+        public async Task<bool> EditUnit(int id, string unitName, string abbrev, int userId)
         {
-            try
+            if (string.IsNullOrEmpty(abbrev))
             {
-                if (string.IsNullOrEmpty(abbrev))
+                var date = await UnitRst.GetAllWhere(m => m.Id != id && m.UnitName == unitName).CountAsync();
+                if (date > 0)
                 {
-                    var date = UnitRst.GetAllWhereAsync(m => m.Id != id && m.UnitName == unitName).Count();
-                    if (date > 0)
-                    {
-                        throw new Exception("鍗曚綅鍚嶇О閲嶅");
-                    }
+                    throw new Exception("鍗曚綅鍚嶇О閲嶅");
                 }
-                else
-                {
-                    var date = UnitRst.GetAllWhereAsync(m => m.Id != id && (m.UnitName == unitName || m.Abbrev == abbrev)).Count();
-                    if (date > 0)
-                    {
-                        throw new Exception("鍗曚綅鍚嶇О鎴栬嫳鏂囩缉鍐欓噸澶�");
-                    }
-                }
-
-                //鑷姩UnitCode澶勭悊
-                var unit = UnitRst.GetOneById(id);
-                if (unit == null)
-                {
-                    throw new Exception("鏈煡璇㈠埌鍗曚綅淇℃伅");
-                }
-                unit.UnitName = unitName;
-                unit.Abbrev = abbrev;
-                unit.UpdateUser = userId;
-                unit.UpdateTime = DateTime.Now;
-
-                var num = UnitRst.Edit(unit);
-                return num > 0;
             }
-            catch (Exception e)
+            else
             {
-                throw new Exception(e.Message);
+                var date = await UnitRst.GetAllWhere(m => m.Id != id && (m.UnitName == unitName || m.Abbrev == abbrev)).CountAsync();
+                if (date > 0)
+                {
+                    throw new Exception("鍗曚綅鍚嶇О鎴栬嫳鏂囩缉鍐欓噸澶�");
+                }
             }
+
+            //鑷姩UnitCode澶勭悊
+            var unit = UnitRst.GetOneById(id);
+            if (unit == null)
+            {
+                throw new Exception("鏈煡璇㈠埌鍗曚綅淇℃伅");
+            }
+            unit.UnitName = unitName;
+            unit.Abbrev = abbrev;
+            unit.UpdateUser = userId;
+            unit.UpdateTime = DateTime.Now;
+
+            var num = await UnitRst.EditAsync(unit);
+            return num > 0;
         }
 
-        public bool DelUnit(int id, int userId)
+        public async Task<bool> DelUnit(int id, int userId)
         {
-            try
+            var unit = UnitRst.GetOneById(id);
+            if (unit == null)
             {
-                var unit = UnitRst.GetOneById(id);
-                if (unit == null)
-                {
-                    throw new Exception("鏈煡璇㈠埌鍗曚綅淇℃伅");
-                }
-                int num = UnitRst.Remove(id, userId);
-                if (num > 0)
-                {
-                    _operation.InsertOperation("鍩虹淇℃伅", "璁¢噺鍗曚綅", unit.UnitNo, "鍒犻櫎", "鍒犻櫎璁¢噺鍗曚綅 鍗曚綅鍙凤細" + unit.UnitNo, Convert.ToInt32(userId));
-                }
+                throw new Exception("鏈煡璇㈠埌鍗曚綅淇℃伅");
+            }
+            int num = await UnitRst.RemoveAsync(id, userId);
+            if (num > 0)
+            {
+                await _operation.InsertOperation("鍩虹淇℃伅", "璁¢噺鍗曚綅", unit.UnitNo, "鍒犻櫎", "鍒犻櫎璁¢噺鍗曚綅 鍗曚綅鍙凤細" + unit.UnitNo, Convert.ToInt32(userId));
+            }
 
-                return num > 0;
-            }
-            catch (Exception e)
-            {
-                throw new Exception(e.Message);
-            }
+            return num > 0;
         }
 
-        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)

--
Gitblit v1.8.0