wangxinhui
昨天 9ce6731460179c71f0f2c636b2a1598324d5194e
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_BasicService/SupplierInfoService.cs
@@ -39,19 +39,71 @@
            try
            {
                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)
                //新增
                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)
                {
                    return content.Error($"物料Id{nameof(BSTSupplierDTO.VendId)}:{ExistSupplier.SupplierSourceId}已存在");
                    //判断重复插入
                    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);
                    }
                }
                List<Dt_SupplierInfo> supplierInfos = new List<Dt_SupplierInfo>();
                foreach (var item in bSTSupplierDTOs)
                //更新
                if (bSTSupplierDTOsUpdate.Count > 0)
                {
                    Dt_SupplierInfo supplierInfo = _mapper.Map<Dt_SupplierInfo>(item);
                    supplierInfos.Add(supplierInfo);
                    //获取已存在的物料
                    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);
                        }
                    }
                }
                BaseDal.AddData(supplierInfos);
                //删除
                if (bSTSupplierDTOsDTODel.Count > 0)
                {
                }
                //更新数据
                _unitOfWorkManage.CommitTran();
                BaseDal.AddData(supplierInfosAdd);
                BaseDal.UpdateData(supplierInfosUpdate);
                _unitOfWorkManage.CommitTran();
                content.OK("接收成功");
            }
            catch (Exception ex)