payne
2024-04-25 bf915c71f7ab3fcd9a7f81ed18f3a10c68d50dc0
iWare_RawMaterialWarehouse_Wms/Admin.NET.Application/Service/WmsBase/BaseCustomer/BaseCustomerService.cs
@@ -51,11 +51,10 @@
        {
            var baseCustomers = await _baseCustomerRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.CustCode), u => u.CustCode == input.CustCode)
                                     .Where(!string.IsNullOrEmpty(input.CustChinaName), u => EF.Functions.Like(u.CustChinaName, $"%{input.CustChinaName.Trim()}%"))
                                     .Where(!string.IsNullOrEmpty(input.CustChinaName), u => u.CustChinaName == input.CustChinaName)
                                     .Where(!string.IsNullOrEmpty(input.CustEnglishName), u => u.CustEnglishName == input.CustEnglishName)
                                     .Where(!string.IsNullOrEmpty(input.MnemonicCode), u => u.MnemonicCode == input.MnemonicCode)
                                     .Where(input.CustType != null, u => u.CustType == input.CustType)
                                     .Where(!string.IsNullOrEmpty(input.CustTypeName), u => u.CustTypeName == input.CustTypeName)
                                     .Where(!string.IsNullOrEmpty(input.LinkMan), u => u.LinkMan == input.LinkMan)
                                     .Where(!string.IsNullOrEmpty(input.Phone), u => u.Phone == input.Phone)
                                     .Where(!string.IsNullOrEmpty(input.Email), u => u.Email == input.Email)
@@ -87,7 +86,6 @@
            var pCustEnglishName = input.CustEnglishName?.Trim() ?? "";
            var pMnemonicCode = input.MnemonicCode?.Trim() ?? "";
            var pCustType = input.CustType;
            var pCustTypeName = input.CustTypeName?.Trim() ?? "";
            var pLinkMan = input.LinkMan?.Trim() ?? "";
            var pPhone = input.Phone?.Trim() ?? "";
            var pEmail = input.Email?.Trim() ?? "";
@@ -102,11 +100,10 @@
            var pUpdatedUserName = input.UpdatedUserName?.Trim() ?? "";
            var baseCustomers = await _baseCustomerRep.DetachedEntities
                .Where(!string.IsNullOrEmpty(pCustCode), u => u.CustCode == pCustCode)
                .Where(!string.IsNullOrEmpty(pCustChinaName), u => EF.Functions.Like(u.CustChinaName, $"%{pCustChinaName}%"))
                .Where(!string.IsNullOrEmpty(pCustChinaName), u => u.CustChinaName == pCustChinaName)
                .Where(!string.IsNullOrEmpty(pCustEnglishName), u => u.CustEnglishName == pCustEnglishName)
                .Where(!string.IsNullOrEmpty(pMnemonicCode), u => u.MnemonicCode == pMnemonicCode)
                .Where(pCustType != null, u => u.CustType == pCustType)
                .Where(!string.IsNullOrEmpty(pCustTypeName), u => u.CustTypeName == pCustTypeName)
                .Where(!string.IsNullOrEmpty(pLinkMan), u => u.LinkMan == pLinkMan)
                .Where(!string.IsNullOrEmpty(pPhone), u => u.Phone == pPhone)
                .Where(!string.IsNullOrEmpty(pEmail), u => u.Email == pEmail)
@@ -158,9 +155,11 @@
        public async Task Add(AddBaseCustomerInput input)
        {
            var baseCustomer = input.Adapt<BaseCustomer>();
                        //验证
            await CheckExisit(baseCustomer);
            baseCustomer.CustCode = Yitter.IdGenerator.YitIdHelper.NextId().ToString();//TODO 要调用生成 编号的方法 先用雪花ID
            baseCustomer.CustTypeName = baseCustomer.CustType.ToString();
            //验证
            await CheckExisit(baseCustomer);
            baseCustomer.CreatedUserId = baseCustomer.UpdatedUserId = SysHelper.GetUserId();
            baseCustomer.CreatedUserName = baseCustomer.UpdatedUserName = SysHelper.GetUserName();
            baseCustomer.CreatedTime = baseCustomer.UpdatedTime = SysHelper.GetNowTime();
@@ -247,20 +246,20 @@
                                          
                           var addItem = new BaseCustomer()
                            {
                               CustCode = Yitter.IdGenerator.YitIdHelper.NextId().ToString(),//TODO 要调用生成 编号的方法 先用雪花ID
                               CreatedTime = SysHelper.GetNowTime(),
                               CreatedUserId = SysHelper.GetUserId(),
                               CreatedUserName = SysHelper.GetUserName(),
                               UpdatedTime = SysHelper.GetNowTime(),
                               UpdatedUserId = SysHelper.GetUserId(),
                               UpdatedUserName = SysHelper.GetUserName()
                             };
                          #region 定义变量
                           var _CustCode = "";//客户编号
                           var _CustChinaName = "";//客户中文名称
                           var _CustEnglishName = "";//客户英文名称
                           var _MnemonicCode = "";//助记码
                           var _CustType = "";//类型
                           var _CustTypeName = "";//类型名称
                           var _LinkMan = "";//联系人
                           var _Phone = "";//电话
                           var _Email = "";//电子邮件
@@ -269,17 +268,14 @@
                           var _City = "";//城市
                           var _Address = "";//地址
                           var _IsDisabled = "";//是否禁用
                           var _Id = "";//Id主键
                          #endregion
                          
                          
                          #region 取值
                           _CustCode = row["客户编号"]?.ToString() ;
                           _CustChinaName = row["客户中文名称"]?.ToString() ;
                           _CustEnglishName = row["客户英文名称"]?.ToString() ;
                           _MnemonicCode = row["助记码"]?.ToString() ;
                           _CustType = row["类型"]?.ToString() ;
                           _CustTypeName = row["类型名称"]?.ToString() ;
                           _LinkMan = row["联系人"]?.ToString() ;
                           _Phone = row["电话"]?.ToString() ;
                           _Email = row["电子邮件"]?.ToString() ;
@@ -287,22 +283,11 @@
                           _Province = row["省份"]?.ToString() ;
                           _City = row["城市"]?.ToString() ;
                           _Address = row["地址"]?.ToString() ;
                           _IsDisabled = row["是否禁用"]?.ToString() ;
                           _Id = row["Id主键"]?.ToString() ;
                          #endregion
                          
                          
                          #region 验证
                          if (string.IsNullOrEmpty(_CustCode))
                          {
                            throw Oops.Oh($"第{index}行[客户编号]{_CustCode}不能为空!");
                          }
                          if(!string.IsNullOrEmpty(_CustCode))
                          {
                                addItem.CustCode = (string)_CustCode;
                           }
                          
                          if (string.IsNullOrEmpty(_CustChinaName))
                          {
@@ -329,23 +314,18 @@
                          
                          if(!string.IsNullOrEmpty(_CustType))
                          {
                              if (!int.TryParse(_CustType, out int outCustType)&&!string.IsNullOrEmpty(_CustType))
                          Admin.NET.Core.BaseCustomerTypeEnum  enumCustType = default(Admin.NET.Core.BaseCustomerTypeEnum);
                             if(!Enum.TryParse<Admin.NET.Core.BaseCustomerTypeEnum>(_CustType, out enumCustType)&&!string.IsNullOrEmpty(_CustType))
                              {
                                 throw Oops.Oh($"第{index}行[类型]{_CustType}值不正确!");
                              }
                              if (outCustType <= 0&&!string.IsNullOrEmpty(_CustType))
                              {
                                 throw Oops.Oh($"第{index}行[类型]{_CustType}值不能小于等于0!");
                                throw Oops.Oh($"第{index}行[类型]{_CustType}值不正确!");
                              }
                              else
                              {
                                 addItem.CustType = outCustType;
                                 addItem.CustType = enumCustType;
                                 addItem.CustTypeName = addItem.CustType.ToString();
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_CustTypeName))
                          {
                                addItem.CustTypeName = (string)_CustTypeName;
                           }
                          if(!string.IsNullOrEmpty(_LinkMan))
                          {
@@ -386,24 +366,9 @@
                               bool outIsDisabled = _IsDisabled.Equals("是") ? true : false;
                               addItem.IsDisabled = outIsDisabled;
                             }
                             }
                           }
                          
                          if(!string.IsNullOrEmpty(_Id))
                          {
                              if (!long.TryParse(_Id, out long outId)&&!string.IsNullOrEmpty(_Id))
                              {
                                 throw Oops.Oh($"第{index}行[Id主键]{_Id}值不正确!");
                              }
                              if (outId <= 0&&!string.IsNullOrEmpty(_Id))
                              {
                                 throw Oops.Oh($"第{index}行[Id主键]{_Id}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.Id = outId;
                              }
                          }
                          #endregion
                          
@@ -449,7 +414,7 @@
           {
                   //数据是否存在重复
                   isExist = await _baseCustomerRep.AnyAsync(u =>
                                   u.CustCode.Equals(input.CustCode)
                                   u.CustChinaName.Equals(input.CustChinaName)
                   ,false);
          }
           else//编辑 
@@ -460,7 +425,7 @@
                 //当前编辑数据以外是否存在重复
                  isExist = await _baseCustomerRep.AnyAsync(u => 
                                    u.Id != input.Id
                                    &&u.CustCode.Equals(input.CustCode)
                                    &&u.CustChinaName.Equals(input.CustChinaName)
                    ,false);
               }
               
@@ -483,17 +448,16 @@
                 }
                 //数据是否重复
                 var existExcelItem = inputs.GroupBy(g => new {
                                               g.CustCode
                                               g.CustChinaName
                                               })
                                               .Where(g => g.Count() > 1)
                                               .Select(s => new {
                                               s.Key.CustCode
                                               s.Key.CustChinaName
                                               }).FirstOrDefault();
                 if (existExcelItem != null)
                 {
                   var baseCustomer = existExcelItem.Adapt<BaseCustomer>();
                   var item= existExcelItem.Adapt<BaseCustomer>();
                   throw Oops.Oh($"导入的表格中,客户编号[{item.CustCode}]已存在");
                   throw Oops.Oh($"导入的表格中,客户中文名称[{item.CustChinaName}]已存在");
                 }
                      
@@ -502,16 +466,15 @@
    //根据联合主键验证数据库中是否已存在相同数据
                 var existDBItem = await _baseCustomerRep.DetachedEntities.FirstOrDefaultAsync(w=> 
                                                                         inputs.Select(s=>""
                                                                           +s.CustCode
                                                                           +s.CustChinaName
                                                                        )
                                                                        .Contains(""
                                                                         +w.CustCode
                                                                         +w.CustChinaName
                  ));
                  if (existDBItem != null)
                 {
                   var baseCustomer = existExcelItem.Adapt<BaseCustomer>();
                   var item= existExcelItem.Adapt<BaseCustomer>();
                   throw Oops.Oh($"系统中,客户编号[{item.CustCode}]已存在");
                   var item= existDBItem.Adapt<BaseCustomer>();
                   throw Oops.Oh($"系统中,客户中文名称[{item.CustChinaName}]已存在");
                 }
        }