From f8c29731de73b1c05a5336b433ad92d52eb4ee97 Mon Sep 17 00:00:00 2001
From: 如洲 陈 <1278080563@qq.com>
Date: 星期一, 27 十月 2025 08:38:03 +0800
Subject: [PATCH] 人员信息接口,首检巡检入库检优化,变更工单修改

---
 MES.Service/service/BasicData/MesStaffManager.cs |   84 +++++++++++++++++++++++++++++++++++------
 1 files changed, 71 insertions(+), 13 deletions(-)

diff --git a/MES.Service/service/BasicData/MesStaffManager.cs b/MES.Service/service/BasicData/MesStaffManager.cs
index deccb30..a4527d3 100644
--- a/MES.Service/service/BasicData/MesStaffManager.cs
+++ b/MES.Service/service/BasicData/MesStaffManager.cs
@@ -123,14 +123,37 @@
         {
             var insertUser = db.Insertable(sysUser).ExecuteCommand();
         }
+        else
+        {
+            // 濡傛灉SysUser宸插瓨鍦紝鍒欐洿鏂扮浉鍏冲瓧娈�
+            var updateUser = db.Updateable<SysUser>()
+                .SetColumns(s => s.Fcode == sysUser.Fcode)
+                .SetColumns(s => s.Fname == sysUser.Fname)
+                .SetColumns(s => s.fPostid == sysUser.fPostid)
+                .SetColumns(s => s.fPostdeptid == sysUser.fPostdeptid)
+                .SetColumns(s => s.fStaffstartdate == sysUser.fStaffstartdate)
+                .SetColumns(s => s.LastupdateDate == DateTime.Now)
+                .Where(s => s.Sid == sysUser.Sid)
+                .ExecuteCommand();
+        }
 
 
-        db.Deleteable<MesStaff>()
-            .Where(s => s.Id == entity.Id)
-            .ExecuteCommand();
-
-        var insertStaff =
-            db.Insertable(entity).IgnoreColumns(true).ExecuteCommand();
+        // 妫�鏌ES_STAFF璁板綍鏄惁瀛樺湪
+        var staffExists = db.Queryable<MesStaff>().Any(s => s.Id == entity.Id);
+        
+        int insertStaff;
+        if (staffExists)
+        {
+            // 濡傛灉璁板綍瀛樺湪锛屽垯鏇存柊
+            insertStaff = db.Updateable(entity)
+                .Where(s => s.Id == entity.Id)
+                .ExecuteCommand();
+        }
+        else
+        {
+            // 濡傛灉璁板綍涓嶅瓨鍦紝鍒欐彃鍏�
+            insertStaff = db.Insertable(entity).ExecuteCommand();
+        }
 
 
         var insertPosition = 1;
@@ -208,6 +231,22 @@
     // 灏� ErpStaff 瀵硅薄杞崲涓� MesStaff 瀵硅薄鐨勬柟娉�
     private MesStaff GetMesStaff(ErpStaff staff)
     {
+        // 浠嶦rpStaffDetails涓幏鍙栧矖浣嶅拰閮ㄩ棬淇℃伅
+        decimal? postId = null;
+        decimal? postDeptId = null;
+        DateTime? staffStartDate = null;
+        
+        if (staff.ErpStaffDetails != null && staff.ErpStaffDetails.Count > 0)
+        {
+            var firstDetail = staff.ErpStaffDetails.First();
+            if (!string.IsNullOrEmpty(firstDetail.fPostId))
+                postId = Convert.ToDecimal(firstDetail.fPostId);
+            if (!string.IsNullOrEmpty(firstDetail.fPostDeptid))
+                postDeptId = Convert.ToDecimal(firstDetail.fPostDeptid);
+            if (!string.IsNullOrEmpty(firstDetail.fStaffStartDate))
+                staffStartDate = DateTime.ParseExact(firstDetail.fStaffStartDate, "yyyy-MM-dd HH:mm:ss", null);
+        }
+
         var entity = new MesStaff
         {
             Id = Convert.ToDecimal(staff.Id),
@@ -234,13 +273,12 @@
             CreateDate = DateTime.Now,
             Remark = staff.FDescription,
             FDOCUMENTSTATUS = staff.FDocumentStatus,
-            FforbidStatus = staff.FForbidStatus
+            FforbidStatus = staff.FForbidStatus,
+            // 鏂板瀛楁鏄犲皠
+            FPostId = postId,
+            FPostDeptid = postDeptId,
+            FStaffStartDate = staffStartDate
         };
-
-        //鍒犻櫎  2025-01-04  姹犲崡楠�
-        //if (staff.FStaffStartDate != null)
-        //    entity.StartDate = DateTime.ParseExact(staff.FStaffStartDate,
-        //        "yyyy-MM-dd HH:mm:ss", null);
 
         return entity;
     }
@@ -298,6 +336,22 @@
 
         //string organizeName = organize.f;
 
+        // 浠嶦rpStaffDetails涓幏鍙栧矖浣嶅拰閮ㄩ棬淇℃伅
+        decimal? postId = null;
+        decimal? postDeptId = null;
+        DateTime? staffStartDate = null;
+        
+        if (staff.ErpStaffDetails != null && staff.ErpStaffDetails.Count > 0)
+        {
+            var firstDetail = staff.ErpStaffDetails.First();
+            if (!string.IsNullOrEmpty(firstDetail.fPostId))
+                postId = Convert.ToDecimal(firstDetail.fPostId);
+            if (!string.IsNullOrEmpty(firstDetail.fPostDeptid))
+                postDeptId = Convert.ToDecimal(firstDetail.fPostDeptid);
+            if (!string.IsNullOrEmpty(firstDetail.fStaffStartDate))
+                staffStartDate = DateTime.ParseExact(firstDetail.fStaffStartDate, "yyyy-MM-dd HH:mm:ss", null);
+        }
+
         return new SysUser
         {
             Sid = Convert.ToDecimal(staff.Id),
@@ -322,7 +376,11 @@
             ExpFiel12 = 0,
             FirstLogin = 0,
             CreateDate = DateTime.Now,
-            PswEditTime = DateTime.Now
+            PswEditTime = DateTime.Now,
+            // 鏂板瀛楁鏄犲皠
+            fPostid = postId,
+            fPostdeptid = postDeptId,
+            fStaffstartdate = staffStartDate
         };
     }
 

--
Gitblit v1.9.3