From cd78554c3da306ed8c866d971bee94457665f80c Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 30 八月 2025 17:35:51 +0800
Subject: [PATCH] ERP一期接口

---
 项目代码/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs |   93 ++++++++++++++++------------------------------
 1 files changed, 32 insertions(+), 61 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs"
index a682d53..b548127 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs"
@@ -1,10 +1,14 @@
-锘縰sing System;
+锘縰sing AutoMapper;
+using SqlSugar.Extensions;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_BasicRepository;
+using WIDESEA_Common.MaterielEnum;
 using WIDESEA_Core;
+using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_DTO.Basic;
 using WIDESEA_IBasicRepository;
@@ -15,79 +19,46 @@
 {
     public class SupplierInfoService : ServiceBase<Dt_SupplierInfo, ISupplierInfoRepository>, ISupplierInfoService
     {
-        public SupplierInfoService(ISupplierInfoRepository BaseDal) : base(BaseDal)
-        {
-        }
-
         public ISupplierInfoRepository Repository => BaseDal;
 
-        public WebResponseContent ReceiveSupplier(SupplierDTO model)
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        private readonly IMapper _mapper;
+        public SupplierInfoService(ISupplierInfoRepository BaseDal,IUnitOfWorkManage unitOfWorkManage,IMapper mapper) : base(BaseDal)
         {
+            _unitOfWorkManage = unitOfWorkManage;
+            _mapper = mapper;
+        }
+        /// <summary>
+        /// 娣诲姞鑰佸巶渚涘簲鍟嗕俊鎭�
+        /// </summary>
+        /// <param name="bSTSupplierDTOs"></param>
+        /// <returns></returns>
+        public WebResponseContent AddSupplier(List<BSTSupplierDTO> bSTSupplierDTOs)
+        {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                if (model.OperateType == "0")
+                List<Dt_SupplierInfo> OldsupplierInfos = BaseDal.QueryData(x => x.InvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt());
+                //鍒ゆ柇閲嶅鎻掑叆
+                Dt_SupplierInfo? ExistSupplier = OldsupplierInfos.FirstOrDefault(x => bSTSupplierDTOs.Where(x => x.Way == 1).Select(x => x.VendId).Contains(x.SupplierSourceId));
+                if (ExistSupplier != null)
                 {
-                    Dt_SupplierInfo supplierInfo = new Dt_SupplierInfo()
-                    {
-                        Status = 1,
-                        SupplierCode = model.Code,
-                        ContactAddress = model.ContactAddress,
-                        ContactNumber = model.ContactNumber,
-                        Contacts = model.Contacts,
-                        Description = model.Description,
-                        Email = model.Email,
-                        InvOrgId = model.InvOrgId,
-                        SupplierName = model.Name,
-                        SupplierShortName = model.ShortName
-                    };
-
-                    BaseDal.AddData(supplierInfo);
+                    return content.Error($"鐗╂枡Id{nameof(BSTSupplierDTO.VendId)}:{ExistSupplier.SupplierSourceId}宸插瓨鍦�");
                 }
-                else if (model.OperateType == "1")
+                List<Dt_SupplierInfo> supplierInfos = new List<Dt_SupplierInfo>();
+                foreach (var item in bSTSupplierDTOs)
                 {
-                    Dt_SupplierInfo supplierInfo = BaseDal.QueryFirst(x => x.SupplierCode == model.Code);
-                    if (supplierInfo == null)
-                    {
-                        Dt_SupplierInfo supplierInfoAddNew = new Dt_SupplierInfo()
-                        {
-                            Status = 1,
-                            SupplierCode = model.Code,
-                            ContactAddress = model.ContactAddress,
-                            ContactNumber = model.ContactNumber,
-                            Contacts = model.Contacts,
-                            Description = model.Description,
-                            Email = model.Email,
-                            InvOrgId = model.InvOrgId,
-                            SupplierName = model.Name,
-                            SupplierShortName = model.ShortName
-                        };
-
-                        BaseDal.AddData(supplierInfoAddNew);
-                    }
-                    else
-                    {
-                        supplierInfo.Status = 1;
-                        supplierInfo.SupplierCode = model.Code;
-                        supplierInfo.SupplierName = model.Name;
-                        supplierInfo.SupplierShortName = model.ShortName;
-                        BaseDal.UpdateData(supplierInfo);
-                    }
+                    Dt_SupplierInfo supplierInfo = _mapper.Map<Dt_SupplierInfo>(item);
+                    supplierInfos.Add(supplierInfo);
                 }
-                else if (model.OperateType == "2")
-                {
-                    Dt_SupplierInfo supplierInfo = BaseDal.QueryFirst(x => x.SupplierCode == model.Code);
-                    if (supplierInfo == null)
-                    {
-                        return WebResponseContent.Instance.Error($"鏈壘鍒拌渚涘簲鍟嗕俊鎭�");
-                    }
-                    BaseDal.DeleteData(supplierInfo);
-                }
-                return WebResponseContent.Instance.OK();
+                BaseDal.AddData(supplierInfos);
+                content.OK("鎺ユ敹鎴愬姛");
             }
             catch (Exception ex)
             {
-                return WebResponseContent.Instance.Error(ex.Message);
+                content.Error(ex.Message);
             }
+            return content;
         }
     }
 }

--
Gitblit v1.9.3