From 52ee0c077127aef8580edbe65d6d48de083e570a Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期二, 25 十一月 2025 16:41:24 +0800
Subject: [PATCH] 客户信息
---
MES.Service/service/BasicData/MesCustomerManager.cs | 151 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 135 insertions(+), 16 deletions(-)
diff --git a/MES.Service/service/BasicData/MesCustomerManager.cs b/MES.Service/service/BasicData/MesCustomerManager.cs
index aeb8abe..86a4fe7 100644
--- a/MES.Service/service/BasicData/MesCustomerManager.cs
+++ b/MES.Service/service/BasicData/MesCustomerManager.cs
@@ -1,7 +1,9 @@
-锘縰sing MES.Service.DB;
+锘縰sing AngleSharp.Dom;
+using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
+using Masuit.Tools;
namespace MES.Service.service.BasicData;
@@ -80,6 +82,14 @@
}) > 0;
}
+ /// <summary>
+ /// 鍚敤涓庣鐢╛0/1
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="customerId"></param>
+ /// <param name="status"></param>
+ /// <returns></returns>
+ /// <exception cref="NotImplementedException"></exception>
private bool UpdateCustomerStatus(SqlSugarScope db, decimal customerId,
string status)
{
@@ -102,6 +112,13 @@
throw new NotImplementedException("鎻掑叆澶辫触");
}
+ /// <summary>
+ /// 鍙嶅鏍竉3
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="customerId"></param>
+ /// <returns></returns>
+ /// <exception cref="NotImplementedException"></exception>
private bool DeleteCustomer(SqlSugarScope db, decimal customerId)
{
var deleteById = db.Deleteable<MesCustomer>()
@@ -114,30 +131,85 @@
private MesCustomer GetSysDepartment(ErpCustomer customer)
{
- //ERP鍌宠几鐨勬帴鍙f暩鎿氳綁鎻涚偤MES鏁告摎搴瓧娈�
+ // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚屽鎴风紪鐮佺殑璁板綍銆侷D銆乧reate_date
+ var existingCustomer = Db.Queryable<MesCustomer>()
+ .Where(s => s.CustNo == customer.FNumber)
+ .First();
- return new MesCustomer
+ //ERP鍌宠几鐨勬帴鍙f暩鎿氳綁鎻涚偤MES鏁告摎搴瓧娈�
+ var entity = new MesCustomer
{
- Id = Convert.ToDecimal(customer.Id),
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+ Id = existingCustomer?.Id ?? 0,
+ //Id = Convert.ToDecimal(customer.Id),
CustNo = customer.FNumber,
CustSname = customer.FShortName,
CustName = customer.FName,
- Anred = customer.FTContact,
+ Anred = customer.Fcontact,
Telf1 = customer.Fmobilephone,
Fseller = customer.Fseller,
- Fforbidstatus = customer.FForbidStatus,
+ //Fforbidstatus = customer.FForbidStatus,
Remark = customer.FDescription,
- FSubsidiary = customer.FUseOrgId,
- Fumbrella = customer.FCreateOrgId,
- CreateDate = DateTime.Now,
+ FSubsidiary = "1",
+ Fumbrella = "1",
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+ CreateDate = existingCustomer?.CreateDate ?? DateTime.Now,
LastupdateDate = DateTime.Now,
Company = "1000",
Factory = "1000",
DataType = customer.FDocumentStatus,
- Type = customer.Type
+ Type = customer.Type,
+ QuickCode=customer.QuickCode,
+ ItemC =null,
+ ItemSap=null,
+ LotFlag=null,
+ Iscommit= null
};
+
+ // ERP: 0=鏈鐢�, 1=绂佺敤
+ // MES: A=鏈鐢�, B=绂佺敤
+ if (customer.FForbidStatus.IsNullOrEmpty())
+ {
+ entity.Fforbidstatus = "A";
+ }
+ else
+ {
+ //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+ //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+ entity.Fforbidstatus = customer.FForbidStatus == "1" ? "B" : "A";
+ }
+
+ return entity;
}
+ /// <summary>
+ /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+ /// </summary>
+ private decimal GenerateNewId()
+ {
+ // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+ var maxId = Db.Queryable<MesCustomer>().Max(x => (decimal?)x.Id) ?? 0;
+ var newId = maxId + 1;
+
+ // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+ while (Db.Queryable<MesCustomer>().Where(x => x.Id == newId).Any())
+ {
+ newId++;
+ }
+
+ return newId;
+ }
+
+ /// <summary>
+ /// 鎵归噺鍚敤涓庣鐢╛0/1
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="customerList"></param>
+ /// <param name="status"></param>
+ /// <returns></returns>
+ /// <exception cref="NotImplementedException"></exception>
private bool UpdateCustomerStatusBatch(SqlSugarScope db,
List<MesCustomer> customerList, string status)
{
@@ -162,6 +234,13 @@
throw new NotImplementedException("鎻掑叆澶辫触");
}
+ /// <summary>
+ /// 鎵归噺鍙嶅鏍竉3
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="customerList"></param>
+ /// <returns></returns>
+ /// <exception cref="NotImplementedException"></exception>
private bool DeleteCustomerBatch(SqlSugarScope db,
List<MesCustomer> customerList)
{
@@ -174,18 +253,58 @@
throw new NotImplementedException("鍒犻櫎澶辫触");
}
+ /// <summary>
+ /// 鍚屾瀹㈡埛淇℃伅new_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
private bool InsertOrUpdate(SqlSugarScope db, MesCustomer entity)
{
- db.Deleteable<MesCustomer>().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();
+ // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+ db.Deleteable<MesCustomer>().Where(s => s.Id == originalId).ExecuteCommand();
- return insert > 0;
+ // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ entity.Id = originalId;
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
}
- private bool InsertOrUpdateBatch(SqlSugarScope db,
- List<MesCustomer> customerList)
+ /// <summary>
+ /// 鍚屾瀹㈡埛淇℃伅old_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
+ //private bool InsertOrUpdate(SqlSugarScope db, MesCustomer entity)
+ //{
+ // db.Deleteable<MesCustomer>().Where(s => s.CustNo == entity.CustNo)
+ // .ExecuteCommand();
+
+ // var insert = db.Insertable(entity).ExecuteCommand();
+
+ // return insert > 0;
+ //}
+
+ /// <summary>
+ /// 鎵归噺_鍚屾瀹㈡埛淇℃伅new_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
+ private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesCustomer> customerList)
{
return customerList.All(entity => InsertOrUpdate(db, entity));
}
--
Gitblit v1.9.3