From 9ce6731460179c71f0f2c636b2a1598324d5194e Mon Sep 17 00:00:00 2001 From: wangxinhui <wangxinhui@hnkhzn.com> Date: 星期六, 20 九月 2025 15:16:48 +0800 Subject: [PATCH] 最新代码更新 --- 项目代码/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 116 insertions(+), 0 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" new file mode 100644 index 0000000..02e7383 --- /dev/null +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs" @@ -0,0 +1,116 @@ +锘縰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; +using WIDESEA_IBasicService; +using WIDESEA_Model.Models; + +namespace WIDESEA_BasicService +{ + public class SupplierInfoService : ServiceBase<Dt_SupplierInfo, ISupplierInfoRepository>, ISupplierInfoService + { + public ISupplierInfoRepository Repository => BaseDal; + + 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 + { + List<Dt_SupplierInfo> OldsupplierInfos = BaseDal.QueryData(x => x.InvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt()); + //鏂板 + List<BSTSupplierDTO> bSTSupplierDTOsAdd = bSTSupplierDTOs.Where(x => x.Way == 1).ToList(); + //淇敼 + List<BSTSupplierDTO> bSTSupplierDTOsUpdate = bSTSupplierDTOs.Where(x => x.Way == 2).ToList(); + //鍒犻櫎 + List<BSTSupplierDTO> bSTSupplierDTOsDTODel = bSTSupplierDTOs.Where(x => x.Way == 3).ToList(); + List<Dt_SupplierInfo> supplierInfosAdd = new List<Dt_SupplierInfo>(); + List<Dt_SupplierInfo> supplierInfosUpdate = new List<Dt_SupplierInfo>(); + //鏂板 + if (bSTSupplierDTOsAdd.Count > 0) + { + //鍒ゆ柇閲嶅鎻掑叆 + Dt_SupplierInfo? ExistSupplier = OldsupplierInfos.FirstOrDefault(x => bSTSupplierDTOsAdd.Select(x => x.VendId).Contains(x.SupplierSourceId)); + if (ExistSupplier != null) + { + return content.Error($"渚涘簲鍟唟nameof(BSTSupplierDTO.VendId)}:{ExistSupplier.SupplierSourceId}宸插瓨鍦�"); + } + + foreach (var item in bSTSupplierDTOsAdd) + { + if (bSTSupplierDTOsUpdate.FirstOrDefault(x => x.VendId == item.VendId) != null) + { + continue; + } + Dt_SupplierInfo supplierInfo = _mapper.Map<Dt_SupplierInfo>(item); + supplierInfosAdd.Add(supplierInfo); + } + } + //鏇存柊 + if (bSTSupplierDTOsUpdate.Count > 0) + { + //鑾峰彇宸插瓨鍦ㄧ殑鐗╂枡 + List<Dt_SupplierInfo>? ExistbSTSuppliersUpdate = OldsupplierInfos.Where(x => bSTSupplierDTOsUpdate.Select(x => x.VendId).Contains(x.SupplierSourceId)).ToList(); + foreach (var item in bSTSupplierDTOsUpdate) + { + Dt_SupplierInfo? supplierInfoUpdate = ExistbSTSuppliersUpdate.FirstOrDefault(x => x.SupplierSourceId == item.VendId); + //濡傛灉鐗╂枡宸插瓨鍦ㄥ垯杩涜鏇存敼 + if (supplierInfoUpdate != null) + { + supplierInfoUpdate.SupplierSourceId = item.VendId; + supplierInfoUpdate.SupplierCode = item.VendNo; + supplierInfoUpdate.SupplierShortName = item.ShortName; + supplierInfoUpdate.SupplierName = item.ShortName; + supplierInfoUpdate.Contacts = item.BusinessContact; + supplierInfoUpdate.ContactNumber = item.Tel; + supplierInfoUpdate.ContactAddress = item.Address; + supplierInfosUpdate.Add(supplierInfoUpdate); + } + else//濡傛灉涓嶅瓨鍦ㄥ垯杩涜鏂板 + { + Dt_SupplierInfo supplierInfo = _mapper.Map<Dt_SupplierInfo>(item); + supplierInfosAdd.Add(supplierInfo); + } + } + } + //鍒犻櫎 + if (bSTSupplierDTOsDTODel.Count > 0) + { + + } + //鏇存柊鏁版嵁 + _unitOfWorkManage.CommitTran(); + BaseDal.AddData(supplierInfosAdd); + BaseDal.UpdateData(supplierInfosUpdate); + _unitOfWorkManage.CommitTran(); + content.OK("鎺ユ敹鎴愬姛"); + } + catch (Exception ex) + { + content.Error(ex.Message); + } + return content; + } + } +} -- Gitblit v1.9.3