Selaa lähdekoodia

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

leiy 1 vuosi sitten
vanhempi
commit
d6842ea869

+ 3 - 11
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -562,26 +562,18 @@ namespace OASystem.API.Controllers
                     diId = groupData.Data;
                     GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
                 }
-
-                diId = dto.Id;
+               
 
                 if (dto.Status == 2)
                 {
+                    diId = dto.Id;
                     if (diId == 0)
                     {
                         return Ok(JsonView(false, "修改失败! 未添加团组id" + groupData.Msg));
                     }
                 }
 
-                var viewData = await _tourClientListRep._AddMultiple(new
-     TourClientListAddMultipleDto
-                {
-                    DiId = diId,
-                    PageId = 104,
-                    PortType = dto.PortType,
-                    UserId = dto.UserId,
-                    TourClientListInfos = dto.TourClientListInfos
-                });
+                var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
 
                 if (viewData.Code != 0)
                 {

+ 1 - 1
OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

@@ -502,7 +502,7 @@ namespace OASystem.Domain.Dtos.Groups
         /// 接团客户名单
         /// AddMultiple Infos
         /// </summary>
-        public List<TourClientListInfo>? TourClientListInfos { get; set; }
+        public List<TourClientListProcessInfo> TourClientListInfos { get; set; }
     }
 
 }

+ 5 - 0
OASystem/OASystem.Domain/Dtos/Groups/TourClientListDto.cs

@@ -227,6 +227,11 @@ namespace OASystem.Domain.Dtos.Groups
         public string? Remark { get; set; }
     }
 
+    public class TourClientListProcessInfo : TourClientListInfo
+    {
+        public int Id { get; set; } 
+    }
+
     // <summary>
     /// 接团客户名单
     /// AddMultiple Info

+ 7 - 6
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -281,11 +281,11 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
                         List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
                         List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
-                        var TourClientListInfoArr = new List<TourClientListInfo>();
+                        var TourClientListInfoArr = new List<TourClientListProcessInfo>();
 
                         foreach (var item in _DeleClients)
                         {
-                            var param = new TourClientListInfo();
+                            var param = new TourClientListProcessInfo();
                             var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
                             if (clientInfo == null) clientInfo = new Crm_DeleClient(); 
                             var clientIDInfo = _CustomerCerts.FirstOrDefault(x=>x.DcId == item.ClientId); //身份证信息
@@ -295,7 +295,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                             param.IDCardNo = clientIDInfo.CertNo;
                             param.Remark = item.Remark;
-                            param.BirthDay = clientInfo.BirthDay;
+                            param.BirthDay = clientInfo.BirthDay.Length > 10 ? clientInfo.BirthDay.Substring(0, 10).Replace("/", "-").Trim() : "";
                             param.FirstName = clientInfo.FirstName;
                             param.LastName = clientInfo.LastName;
                             param.CompanyFullName = Company.CompanyFullName;
@@ -307,14 +307,15 @@ namespace OASystem.Infrastructure.Repositories.Groups
                             param.MealSpecialNeeds = item.MealSpecialNeeds;
                             param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
                             param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
+                            param.Id = clientInfo.Id;
 
                             TourClientListInfoArr.Add(param);
                         }
 
                         GroupProcessOperationDtoParam.PortType = dto.PortType;
                         GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
-                        GroupProcessOperationDtoParam.VisitDate = GroupProcessOperationDtoParam.VisitDate.Length > 10 ? GroupProcessOperationDtoParam.VisitDate.Substring(0, 10) : "";
-                        GroupProcessOperationDtoParam.TontractTime = GroupProcessOperationDtoParam.TontractTime.Length > 10 ? GroupProcessOperationDtoParam.TontractTime.Substring(0, 10) : "";
+                        GroupProcessOperationDtoParam.VisitDate = GroupProcessOperationDtoParam.VisitDate.Length > 10 ? GroupProcessOperationDtoParam.VisitDate.Substring(0, 10).Replace("/","-").Trim() : "";
+                        GroupProcessOperationDtoParam.TontractTime = GroupProcessOperationDtoParam.TontractTime.Length > 10 ? GroupProcessOperationDtoParam.TontractTime.Substring(0, 10).Replace("/","-").Trim() : "";
 
                         result.Data = GroupProcessOperationDtoParam;
                     }
@@ -512,7 +513,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         SpecialNeeds = dto.SpecialNeeds,
                         OtherNeeds = dto.OtherNeeds,
                         Remark = dto.Remark,
-                        JietuanOperator = dto.UserId,
+                        JietuanOperator = dto.JietuanOperator,
                         TellPhone = dto.TellPhone,
                         CGRWSPBMMC = dto.CGRWSPBMMC,
                         CGRWSPWH = dto.CGRWSPWH,

+ 254 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/TourClientListRepository.cs

@@ -1,4 +1,5 @@
 using AutoMapper;
+using MathNet.Numerics.Distributions;
 using OASystem.Domain;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Dtos.Groups;
@@ -9,6 +10,7 @@ using OASystem.Infrastructure.Tools;
 using Org.BouncyCastle.Utilities.Encoders;
 using StackExchange.Redis;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
@@ -618,6 +620,258 @@ namespace OASystem.Infrastructure.Repositories.Groups
         }
 
 
+        public async Task<Result> OperMultiple(List<TourClientListProcessInfo> _TourClientListInfos , int diid,int userId)
+        {
+            if (diid < 0)
+            {
+                _result.Msg = string.Format(@"请传入有效的团组Id参数!");
+                return _result;
+            }
+            if (_TourClientListInfos == null || _TourClientListInfos.Count < 0)
+            {
+                _result.Msg = string.Format(@"接团客户名单信息集合为空,不执行批量添加!");
+                return _result;
+            }
+
+            _sqlSugar.BeginTran();
+            try
+            {
+                _sqlSugar.Updateable<Grp_TourClientList>().SetColumns(x=> new Grp_TourClientList { IsDel = 1 } ).Where(x=>x.DiId == diid).ExecuteCommand();
+
+                foreach (var item in _TourClientListInfos)
+                {
+                    //客户信息
+                    var clientInfo = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 &&
+                                                                             it.LastName.Equals(item.LastName) &&
+                                                                             it.FirstName.Equals(item.FirstName) &&
+                                                                             it.Phone.Equals(item.Phone)
+                                                                       ).FirstAsync();
+
+
+                    Crm_CustomerCompany _CustomerCompany = new Crm_CustomerCompany()
+                    {
+                        CompanyFullName = item.CompanyFullName,
+                        LastedOpUserId = userId,
+                        CreateUserId = userId
+                    };
+
+                    Crm_CustomerCert _CustomerCert = new Crm_CustomerCert()
+                    {
+                        SdId = 773,
+                        CertNo = item.IDCardNo,
+                        CreateUserId = userId
+                    };
+
+                    Crm_DeleClient _DeleClient = new Crm_DeleClient()
+                    {
+                        LastName = item.LastName,
+                        FirstName = item.FirstName,
+                        Pinyin = item.Pinyin,
+                        Phone = item.Phone,
+                        Sex = item.Sex,
+                        BirthDay = item.BirthDay,
+                        Job = item.Job,
+                        CreateUserId = userId
+                    };
+
+                    int clientId = -1;
+                    int crmCompanyId = -1;
+
+                    //客户单位/公司 操作
+                    //1.添加 or 修改 公司基本信息
+                    if (clientInfo == null)
+                    {
+                        var companyInfo = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0 &&
+                                                                                                       it.CompanyFullName.Equals(item.CompanyFullName)
+                                                                                                 ).FirstAsync();
+                        if (companyInfo != null) crmCompanyId = companyInfo.Id;
+                        else
+                        {
+                            var companyAdd = await _sqlSugar.Insertable(_CustomerCompany).ExecuteReturnIdentityAsync();
+                            if (companyAdd < 0)
+                            {
+                                _result.Msg = "客户公司信息添加失败!";
+                                _sqlSugar.RollbackTran();
+                                return _result;
+                            }
+                            crmCompanyId = companyAdd;
+                        }
+                    }
+                    else
+                    {
+                        var companyInfo = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0 &&
+                                                                                                       it.Id == clientInfo.CrmCompanyId
+                                                                                                 ).FirstAsync();
+                        if (companyInfo != null)
+                        {
+                            crmCompanyId = companyInfo.Id;
+                            if (!companyInfo.CompanyFullName.Equals(item.CompanyFullName))
+                            {
+                                companyInfo.CompanyFullName = item.CompanyFullName;
+                                var companyEdit = await _sqlSugar.Updateable(companyInfo).UpdateColumns(it =>
+                                                                                     new
+                                                                                     {
+                                                                                         it.CompanyFullName,
+                                                                                     }
+                                                                                 )
+                                                                                .Where(it => it.Id == companyInfo.Id)
+                                                                                .ExecuteCommandAsync();
+                                if (companyEdit < 0)
+                                {
+                                    _result.Msg = "客户公司信息修改失败!";
+                                    _sqlSugar.RollbackTran();
+                                    return _result;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            var companyAdd = await _sqlSugar.Insertable(_CustomerCompany).ExecuteReturnIdentityAsync();
+                            if (companyAdd < 0)
+                            {
+                                _result.Msg = "客户公司信息添加失败!";
+                                _sqlSugar.RollbackTran();
+                                return _result;
+                            }
+                            crmCompanyId = companyAdd;
+                        }
+                    }
+
+                    //客户人员 操作
+                    //2.添加 or 修改 客户基本信息
+                    if (clientInfo != null)  //该客户存在 修改信息 
+                    {
+                        clientId = clientInfo.Id;
+                        var clientEdit = await _sqlSugar.Updateable(_DeleClient).UpdateColumns(it =>
+                                                                                     new
+                                                                                     {
+                                                                                         it.LastName,
+                                                                                         it.FirstName,
+                                                                                         it.Pinyin,
+                                                                                         it.Sex,
+                                                                                         it.Phone,
+                                                                                         it.BirthDay
+                                                                                     }
+                                                                                 )
+                                                                                .Where(it => it.Id == clientId)
+                                                                                .ExecuteCommandAsync();
+                        if (clientEdit < 0)
+                        {
+                            _result.Msg = "客户基础信息修改失败!";
+                            _sqlSugar.RollbackTran();
+                            return _result;
+                        }
+                    }
+                    else //不存在添加 客户信息
+                    {
+                        _DeleClient.CrmCompanyId = crmCompanyId;
+                        var clientAdd = await _sqlSugar.Insertable(_DeleClient).ExecuteReturnIdentityAsync();
+                        if (clientAdd < 0)
+                        {
+                            _result.Msg = "客户基本信息添加失败!";
+                            _sqlSugar.RollbackTran();
+                            return _result;
+                        }
+                        clientId = clientAdd;
+
+                    }
+
+                    //客户身份证操作
+                    //3.添加 or 修改 身份证信息
+                    _CustomerCert.DcId = clientId;
+                    if (clientInfo == null)
+                    {
+                        var certInfo = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 &&
+                                                                                                 it.SdId == 773 &&      //卡类型 身份证
+                                                                                                 it.CertNo == item.IDCardNo    //人员Id
+                                                                                           ).FirstAsync();
+                        if (certInfo == null)
+                        {
+                            var certAdd = await _sqlSugar.Insertable(_CustomerCert).ExecuteReturnIdentityAsync();
+                            if (certAdd < 0)
+                            {
+                                _result.Msg = "客户身份证添加失败!";
+                                _sqlSugar.RollbackTran();
+                                return _result;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        var certInfo = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 &&
+                                                                                                 it.SdId == 773 &&      //卡类型 身份证
+                                                                                                 it.DcId == clientInfo.Id    //人员Id
+                                                                                           ).FirstAsync();
+                        if (certInfo == null)
+                        {
+
+                            var certAdd = await _sqlSugar.Insertable(_CustomerCert).ExecuteReturnIdentityAsync();
+                            if (certAdd < 0)
+                            {
+                                _result.Msg = "客户身份证添加失败!";
+                                _sqlSugar.RollbackTran();
+                                return _result;
+                            }
+                        }
+                        else
+                        {
+                            var certEdit = await _sqlSugar.Updateable(_CustomerCert).UpdateColumns(it =>
+                                                                                     new
+                                                                                     {
+                                                                                         it.CertNo,
+                                                                                     }
+                                                                                 )
+                                                                                .Where(it => it.Id == certInfo.Id)
+                                                                                .ExecuteCommandAsync();
+                            if (certEdit < 0)
+                            {
+                                _result.Msg = "客户身份证修改失败!";
+                                _sqlSugar.RollbackTran();
+                                return _result;
+                            }
+                        }
+                    }
+
+
+                    //团组客户信息名单操作
+                    Grp_TourClientList _TourClientList = new Grp_TourClientList()
+                    {
+                        DiId = diid,
+                        ClientId = clientId,
+                        ShippingSpaceTypeId = item.ShippingSpaceTypeId,
+                        ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds,
+                        HotelSpecialNeeds = item.HotelSpecialNeeds,
+                        MealSpecialNeeds = item.MealSpecialNeeds,
+                        Remark = item.Remark,
+                        CreateUserId = userId,
+                    };
+
+                    var tourClientAdd = await _sqlSugar.Insertable(_TourClientList).ExecuteReturnIdentityAsync();
+                    if (tourClientAdd < 0)
+                    {
+                        _result.Msg = "接团客户名单添加失败!";
+                        _sqlSugar.RollbackTran();
+                        return _result;
+                    }
+                    
+                }
+
+                _result.Code = 0;
+                _sqlSugar.CommitTran();
+
+            }
+            catch (Exception ex)
+            {
+
+                _sqlSugar.RollbackTran();
+                _result.Msg = "程序异常 -- " + ex.Message;
+            }
+
+
+            return _result;
+        }
+
+
         /// <summary>
         /// Del
         /// </summary>