From 4a7b0fda2e0659982239020c005615758a3acbee Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期五, 12 十二月 2025 10:20:23 +0800
Subject: [PATCH] 采购员编码转ID
---
MES.Service/service/BasicData/MesDepotsManager.cs | 119 +++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 99 insertions(+), 20 deletions(-)
diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs
index 1a6bee0..2e5830f 100644
--- a/MES.Service/service/BasicData/MesDepotsManager.cs
+++ b/MES.Service/service/BasicData/MesDepotsManager.cs
@@ -4,7 +4,9 @@
using SqlSugar;
namespace MES.Service.service.BasicData;
-
+/// <summary>
+/// 浠撳簱淇℃伅
+/// </summary>
public class MesDepotsManager : Repository<MesDepots>
{
// Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜浠撳簱璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔
@@ -76,41 +78,121 @@
throw new NotImplementedException("鍙嶅鏍稿け璐�");
}
- // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
+ /// <summary>
+ /// 鍚屾浠撳簱淇℃伅new_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity)
{
- db.Deleteable<MesDepots>()
- .Where(s => s.DepotId == entity.DepotId)
- .ExecuteCommand();
- var insert = db.Insertable(entity).ExecuteCommand();
- return insert > 0;
+ if (entity.DepotId == 0)
+ {
+ // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏�
+ var newId = GenerateNewId();
+ entity.DepotId = newId;
+ entity.Guid = newId.ToString();
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
+ else
+ {
+ // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ var originalId = entity.DepotId;
+
+ // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+ db.Deleteable<MesDepots>().Where(s => s.DepotId == originalId).ExecuteCommand();
+
+ // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ entity.DepotId = originalId;
+ entity.Guid = originalId.ToString();
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
+ }
+
+ // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
+ //private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity)
+ //{
+ // db.Deleteable<MesDepots>()
+ // .Where(s => s.DepotId == entity.DepotId)
+ // .ExecuteCommand();
+ // var insert = db.Insertable(entity).ExecuteCommand();
+ // return insert > 0;
+ //}
+
+ /// <summary>
+ /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+ /// </summary>
+ private decimal GenerateNewId()
+ {
+ // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+ var maxId = Db.Queryable<MesDepots>().Max(x => (decimal?)x.DepotId) ?? 0;
+ var newId = maxId + 1;
+
+ // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+ while (Db.Queryable<MesDepots>().Where(x => x.DepotId == newId).Any())
+ {
+ newId++;
+ }
+
+ return newId;
}
// 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉�
private MesDepots GetMesDepots(ErpDepots depots)
{
- return new MesDepots
+ // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚岀紪鐮佺殑璁板綍銆�
+ var existingCustomer = Db.Queryable<MesDepots>()
+ .Where(s => s.DepotCode == depots.FNumber)
+ .First();
+
+ var entity = new MesDepots
{
- Guid = depots.Id,
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+ DepotId = existingCustomer?.DepotId ?? 0,
+ //DepotId = Convert.ToDecimal(depots.Id),
+ Guid = existingCustomer?.Guid ?? string.Empty,
DepotCode = depots.FNumber,
DepotName = depots.FName,
- DepotId = Convert.ToDecimal(depots.Id),
IsFkc = depots.FAllowMinusQty,
CreateBy = depots.FPrincipal,
Depottype = depots.FStockProperty,
IsNg = depots.FForbidStatus,
Zuid = depots.FGroup,
- FSubsidiary = depots.FUseOrgId,
- Fumbrella = depots.FCreateOrgId,
- CreateDate = DateTime.Now,
+ //FSubsidiary = depots.FUseOrgId,
+ //Fumbrella = depots.FCreateOrgId,
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+ CreateDate = existingCustomer?.CreateDate ?? DateTime.Now,
LastupdateDate = DateTime.Now,
SupplierId = depots.FSUPPLIERID,
ClientId = depots.ClientId,
Department = depots.Fdeptid,
Phone = depots.Phone,
Company = "1000",
- Factory = "1000"
+ Factory = depots.Factory,
+ factory_name = depots.factory_name,
+ Remark4 = depots.remark4,
+ Remark5 = depots.remark5,
+ FSubsidiary = string.IsNullOrEmpty(depots.FUseOrgId) ? "1" : depots.FUseOrgId,
+ Fumbrella = string.IsNullOrEmpty(depots.FCreateOrgId) ? "1" : depots.FCreateOrgId,
};
+ // ERP: 0=鏈鐢�, 1=绂佺敤
+ // MES: A=鏈鐢�, B=绂佺敤
+ //浼犲叆0銆�1鎴栬�匒銆丅鏃堕兘浼氳浆涓篈銆丅锛屽叾浠栨儏鍐典负A
+ if (string.IsNullOrEmpty(depots.FForbidStatus))
+ {
+ entity.IsNg = "A";
+ }
+ else
+ {
+ // 鍥炰紶B鎴�1鏃跺啓鍏锛屽叾瀹冨啓A
+ entity.IsNg = (depots.FForbidStatus == "1" || depots.FForbidStatus == "B")
+ ? "B"
+ : "A";
+ }
+
+ return entity;
}
// SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜浠撳簱璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔
@@ -162,8 +244,7 @@
}
// 鎵归噺鏇存柊浠撳簱鐘舵�佺殑鏂规硶
- private bool UpdateDepotStatusBatch(SqlSugarScope db,
- List<MesDepots> depotList, string status)
+ private bool UpdateDepotStatusBatch(SqlSugarScope db,List<MesDepots> depotList, string status)
{
var ids = depotList.Select(it => it.DepotId).ToArray();
var result = db.Updateable<MesDepots>()
@@ -177,8 +258,7 @@
}
// 鎵归噺鎻掑叆浠撳簱鐨勬柟娉�
- private bool InsertDepotBatch(SqlSugarScope db,
- List<MesDepots> depotList)
+ private bool InsertDepotBatch(SqlSugarScope db,List<MesDepots> depotList)
{
var insertRange = db.Insertable(depotList).ExecuteCommand();
if (insertRange > 0)
@@ -202,8 +282,7 @@
}
// 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
- private bool InsertOrUpdateBatch(SqlSugarScope db,
- List<MesDepots> depotList)
+ private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesDepots> depotList)
{
return depotList.All(entity => InsertOrUpdate(db, entity));
}
--
Gitblit v1.9.3