From dd8907e99aeb468ab535800183de60c1410f92e3 Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期四, 27 十一月 2025 16:32:58 +0800
Subject: [PATCH] 员工信息
---
MES.Service/service/BasicData/MesStaffManager.cs | 112 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 96 insertions(+), 16 deletions(-)
diff --git a/MES.Service/service/BasicData/MesStaffManager.cs b/MES.Service/service/BasicData/MesStaffManager.cs
index 1f435af..f83112e 100644
--- a/MES.Service/service/BasicData/MesStaffManager.cs
+++ b/MES.Service/service/BasicData/MesStaffManager.cs
@@ -57,11 +57,15 @@
throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
}
- // 鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶
- private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,
- MesStaff entity)
+ /// <summary>
+ /// 鍚屾鐗╂枡淇℃伅new_0/4
+ /// </summary>
+ /// <param name="db"></param>
+ /// <param name="entity"></param>
+ /// <returns></returns>
+ private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser, MesStaff entity)
{
-
+ // 鍏堢‘淇濈敤鎴疯处鍙峰瓨鍦�
var exists = db.Queryable<SysUser>().Any(u => u.Account == sysUser.Account);
if (!exists)
{
@@ -69,17 +73,49 @@
if (insertUser <= 0) return false;
}
- //db.Deleteable<SysUser>()
- // .Where(s => s.Account == sysUser.Account).ExecuteCommand();
+ if (entity.Id == 0)
+ {
+ // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏�
+ var newId = GenerateNewId();
+ entity.Id = newId;
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
+ else
+ {
+ // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ var originalId = entity.Id;
- db.Deleteable<MesStaff>()
- .Where(s => s.Id == entity.Id).ExecuteCommand();
+ // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+ db.Deleteable<MesStaff>().Where(s => s.Id == originalId).ExecuteCommand();
-
-
- var insertStaff = db.Insertable(entity).ExecuteCommand();
- return insertStaff > 0;
+ // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+ entity.Id = originalId;
+ return db.Insertable(entity).ExecuteCommand() > 0;
+ }
}
+
+ // 鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶
+ //private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,MesStaff entity)
+ //{
+
+ // var exists = db.Queryable<SysUser>().Any(u => u.Account == sysUser.Account);
+ // if (!exists)
+ // {
+ // var insertUser = db.Insertable(sysUser).ExecuteCommand();
+ // if (insertUser <= 0) return false;
+ // }
+
+ // //db.Deleteable<SysUser>()
+ // // .Where(s => s.Account == sysUser.Account).ExecuteCommand();
+
+ // db.Deleteable<MesStaff>()
+ // .Where(s => s.Id == entity.Id).ExecuteCommand();
+
+
+
+ // var insertStaff = db.Insertable(entity).ExecuteCommand();
+ // return insertStaff > 0;
+ //}
// 鍒犻櫎鍛樺伐鐨勬柟娉�
private bool DeleteStaff(SqlSugarScope db, SysUser sysUser, decimal staffId)
@@ -96,22 +132,53 @@
throw new NotImplementedException("鍙嶅鏍稿け璐�");
}
+ /// <summary>
+ /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+ /// </summary>
+ private decimal GenerateNewId()
+ {
+ // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+ var maxId = Db.Queryable<MesStaff>().Max(x => (decimal?)x.Id) ?? 0;
+ var newId = maxId + 1;
+
+ // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+ while (Db.Queryable<MesStaff>().Where(x => x.Id == newId).Any())
+ {
+ newId++;
+ }
+
+ return newId;
+ }
+
// 灏� ErpStaff 瀵硅薄杞崲涓� MesStaff 瀵硅薄鐨勬柟娉�
private MesStaff GetMesStaff(ErpStaff staff)
{
+ // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚岀紪鐮佺殑璁板綍銆�
+ var existingCustomer = Db.Queryable<MesStaff>()
+ .Where(s => s.StaffNo == staff.FStaffNumber)
+ .First();
+
var entity = new MesStaff
{
- Id = Convert.ToDecimal(staff.Id),
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+ Id = existingCustomer?.Id ?? 0,
+ //Id = Convert.ToDecimal(staff.Id),
StaffNo = staff.FStaffNumber,
StaffName = staff.FName,
- DepartmentName = staff.FPostDept,
- PositionCode = staff.FPostId,
+ DepartmentNo = staff.FPostDeptNo,//閮ㄩ棬缂栫爜
+ DepartmentName = staff.FPostDept,//閮ㄩ棬鍚嶇О
+ PositionCode = staff.FPost,//宀椾綅缂栫爜
+ PositionName = staff.FPostId,//宀椾綅鍚嶇О
PhoneNumber = staff.FMobile,
Remark = staff.FDescription,
FforbidStatus = staff.FForbidStatus,
FSubsidiary = staff.FUseOrgId,
Fumbrella = staff.FCreateOrgId,
- CreateDate = DateTime.Now,
+ // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+ // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+ CreateDate = existingCustomer?.CreateDate ?? DateTime.Now,
+ //CreateDate = DateTime.Now,
LastupdateDate = DateTime.Now,
Type = staff.Type
};
@@ -120,6 +187,19 @@
entity.StartDate = DateTime.ParseExact(staff.FStaffStartDate,
"yyyy-MM-dd HH:mm:ss", null);
+ // ERP: 0=鏈鐢�, 1=绂佺敤
+ // MES: A=鏈鐢�, B=绂佺敤
+ if (string.IsNullOrEmpty(staff.FForbidStatus))
+ {
+ entity.FforbidStatus = "A";
+ }
+ else
+ {
+ //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+ //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+ entity.FforbidStatus = staff.FForbidStatus == "1" ? "B" : "A";
+ }
+
return entity;
}
--
Gitblit v1.9.3