From 99cb010209a7b7e464ef5c13bd24c9a37fd82cce Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期三, 26 十一月 2025 09:44:37 +0800
Subject: [PATCH] 供应商信息
---
MES.Service/service/BasicData/MesSupplierManager.cs | 106 ++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 93 insertions(+), 13 deletions(-)
diff --git a/MES.Service/service/BasicData/MesSupplierManager.cs b/MES.Service/service/BasicData/MesSupplierManager.cs
index ee14371..63ad3f4 100644
--- a/MES.Service/service/BasicData/MesSupplierManager.cs
+++ b/MES.Service/service/BasicData/MesSupplierManager.cs
@@ -1,7 +1,10 @@
-锘縰sing MES.Service.DB;
+锘縰sing AngleSharp.Dom;
+using Castle.Core.Resource;
+using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
+using Masuit.Tools;
namespace MES.Service.service.BasicData;
@@ -114,24 +117,66 @@
private MesSupplier GetMesSupplier(ErpSupplier supplier)
{
- return new MesSupplier
+ // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚屽鎴风紪鐮佺殑璁板綍銆侷D銆乧reate_date
+ var existingCustomer = Db.Queryable<MesSupplier>()
+ .Where(s => s.SuppNo == supplier.FNumber)
+ .First();
+
+ var entity = new MesSupplier
{
- Id = Convert.ToDecimal(supplier.Id),
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+ Id = existingCustomer?.Id ?? 0,
SuppNo = supplier.FNumber,
SuppSname = supplier.FShortName,
SuppName = supplier.FName,
Lxr = supplier.FTContact,
Telf1 = supplier.Fmobilephone,
Fstaffid = supplier.FStaffId,
- Fforbidstatus = supplier.FForbidStatus,
+ //Fforbidstatus = supplier.FForbidStatus,
Type = supplier.Type,
- FSubsidiary = supplier.FUseOrgId,
- Fumbrella = supplier.FCreateOrgId,
- CreateDate = DateTime.Now,
+ FSubsidiary = "1",
+ Fumbrella = "1",
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+ CreateDate = existingCustomer?.CreateDate ?? DateTime.Now,
LastupdateDate = DateTime.Now,
Company = "1000",
Factory = "1000"
};
+
+ // ERP: 0=鏈鐢�, 1=绂佺敤
+ // MES: A=鏈鐢�, B=绂佺敤
+ if (supplier.FForbidStatus.IsNullOrEmpty())
+ {
+ entity.Fforbidstatus = "A";
+ }
+ else
+ {
+ //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+ //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+ entity.Fforbidstatus = supplier.FForbidStatus == "1" ? "B" : "A";
+ }
+
+ return entity;
+ }
+
+ /// <summary>
+ /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+ /// </summary>
+ private decimal GenerateNewId()
+ {
+ // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+ var maxId = Db.Queryable<MesSupplier>().Max(x => (decimal?)x.Id) ?? 0;
+ var newId = maxId + 1;
+
+ // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+ while (Db.Queryable<MesSupplier>().Where(x => x.Id == newId).Any())
+ {
+ newId++;
+ }
+
+ return newId;
}
private bool UpdateSupplierStatusBatch(SqlSugarScope db,
@@ -170,18 +215,53 @@
throw new NotImplementedException("鍒犻櫎澶辫触");
}
+ /// <summary>
+ /// 鍚屾渚涘簲鍟嗕俊鎭痭ew_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity)
{
- db.Deleteable<MesSupplier>().Where(s => s.Id == entity.Id)
- .ExecuteCommand();
+ if (entity.Id == 0)
+ {
+ // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏�
+ var newId = GenerateNewId();
+ entity.Id = newId;
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
+ else
+ {
+ // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ var originalId = entity.Id;
- var insert = db.Insertable(entity).ExecuteCommand();
- if (insert > 0)
- return true;
+ // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+ db.Deleteable<MesSupplier>().Where(s => s.Id == originalId).ExecuteCommand();
- return false;
+ // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ entity.Id = originalId;
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
}
+ /// <summary>
+ /// 鍚屾渚涘簲鍟嗕俊鎭痮ld_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="supplierList"></param>
+ /// <returns></returns>
+ //private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity)
+ //{
+ // db.Deleteable<MesSupplier>().Where(s => s.Id == entity.Id)
+ // .ExecuteCommand();
+
+ // var insert = db.Insertable(entity).ExecuteCommand();
+ // if (insert > 0)
+ // return true;
+
+ // return false;
+ //}
+
private bool InsertOrUpdateBatch(SqlSugarScope db,
List<MesSupplier> supplierList)
{
--
Gitblit v1.9.3