From dabfdd9dbf0364b1134daaad86af7e13f6437295 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期四, 30 十月 2025 12:40:30 +0800
Subject: [PATCH] XJ,SJ,RKJ检验项目序号,LLJ单个检验项目FTP附件信息

---
 StandardInterface/MES.Service/service/QC/LljService.cs |  591 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 480 insertions(+), 111 deletions(-)

diff --git a/StandardInterface/MES.Service/service/QC/LljService.cs b/StandardInterface/MES.Service/service/QC/LljService.cs
index c84c883..71d481a 100644
--- a/StandardInterface/MES.Service/service/QC/LljService.cs
+++ b/StandardInterface/MES.Service/service/QC/LljService.cs
@@ -26,78 +26,157 @@
         var totalCount = 0;
 
         // 浣跨敤鏁版嵁搴撳垎椤垫煡璇紝涓�娆℃煡璇�50鏉★紝鎻愬崌鎬ц兘
-        var pageList = db.Queryable<LtsLlj, V_LljUser>((a, v) =>
-                new JoinQueryInfos(JoinType.Left, a.ItemNo == v.ItemNo))
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                "鏈畬鎴�".Equals(queryObj.result),
-                (a, v) => a.FcheckResu == null)
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                !"鏈畬鎴�".Equals(queryObj.result),
-                (a, v) => a.FcheckResu != null)
-            .WhereIF(id > 0, (a, v) => a.Id == id)
-            // 鏉冮檺鎺у埗锛歅L017銆丠MLYY銆丠MCS 鍙互鐪嬪埌鎵�鏈夊崟鎹紝鍏朵粬鐢ㄦ埛闇�瑕佹牴鎹墿鏂欑淮鎶ゆ儏鍐靛垽鏂�
-            .WhereIF(queryObj.createUser != "PL017" && queryObj.createUser != "HMLYY" && queryObj.createUser != "HMCS" && queryObj.UserIndex == "0", 
-                (a, v) => 
-                    // 濡傛灉鐗╂枡琚淮鎶わ紝鍙湁缁存姢浜哄憳鍙互鐪嬪埌
-                    (v.Fcode != null && v.Fcode == queryObj.createUser) ||
-                    // 濡傛灉鐗╂枡鏈缁存姢锛屾墍鏈変汉閮藉彲浠ョ湅鍒�
-                    (v.Fcode == null))
-
-            //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
-                (a, v) => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
-                (a, v) => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
-                (a, v) => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
-                (a, v) => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
-                (a, v) => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
-                (a, v) => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .Select((a, v) => new LtsLlj
-            {
-                Id = a.Id,
-                ItemNo = a.ItemNo,
-                ItemId = a.ItemId,
-                ItemName = a.ItemName,
-                ItemModel = a.ItemModel,
-                SuppName = a.SuppName,
-                LotNo = a.LotNo,
-                ReleaseNo = a.ReleaseNo,
-                FcheckResu = a.FcheckResu,
-                CreateDate = a.CreateDate,
-                FcovertQty = a.FcovertQty,
-                DEPARTMENTNAME = a.DEPARTMENTNAME,
-                FngDesc = a.FngDesc,
-                UrgentFlag = a.UrgentFlag,
-                Ftype = a.Ftype,
-                LotNo1 = a.LotNo1,
-                EMERGENCY = a.EMERGENCY,
-                Status = a.Status,
-                IqcDate = a.IqcDate,
-                // 娣诲姞缁存姢浜哄憳淇℃伅
-                Fcode = v.Fcode,
-                // 娣诲姞鐮村潖瀹為獙鏁伴噺
-                PHSY = a.PHSY,
-                // 娣诲姞涓嶈壇鍘熷洜
-                BLYY = a.BLYY,
-                // 娣诲姞鎵�灞炶溅闂�
-                SSCJ = a.SSCJ,
-                // 娣诲姞璇勫鐘舵��
-                PSZT = a.PSZT,
-                // 娣诲姞妫�楠岄」鐩淮鎶ょ姸鎬�
-                Jyxm = a.Jyxm
-            })
-            .OrderBy("CASE WHEN EMERGENCY = 1 THEN 0 ELSE 1 END")
-            .OrderBy("CASE WHEN JYXM = 0 THEN 0 ELSE 1 END")
-            .OrderBy("CASE WHEN STATUS = '宸叉彁浜�' THEN 1 ELSE 0 END")
-            .OrderBy("IQC_DATE DESC")
-            .OrderBy("CREATE_DATE")
-            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+        // 鍒ゆ柇鏄惁涓虹鐞嗗憳璐﹀彿
+        bool isAdmin = queryObj.createUser == "PL017" || queryObj.createUser == "HMLYY" || queryObj.createUser == "HMCS";
+        
+        List<LtsLlj> pageList;
+        
+        if (isAdmin)
+        {
+            // 绠$悊鍛樿处鍙凤細鐩存帴鏌ヨ涓昏〃锛岄伩鍏岼OIN瀵艰嚧鐨勯噸澶嶈褰�
+            pageList = db.Queryable<LtsLlj>()
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    "鏈畬鎴�".Equals(queryObj.result),
+                    a => a.FcheckResu == null)
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    !"鏈畬鎴�".Equals(queryObj.result),
+                    a => a.FcheckResu != null)
+                .WhereIF(id > 0, a => a.Id == id)
+                //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
+                    a => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
+                    a => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
+                    a => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
+                    a => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
+                    a => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
+                    a => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .Select(a => new LtsLlj
+                {
+                    Id = a.Id,
+                    ItemNo = a.ItemNo,
+                    ItemId = a.ItemId,
+                    ItemName = a.ItemName,
+                    ItemModel = a.ItemModel,
+                    SuppName = a.SuppName,
+                    LotNo = a.LotNo,
+                    ReleaseNo = a.ReleaseNo,
+                    FcheckResu = a.FcheckResu,
+                    CreateDate = a.CreateDate,
+                    FcovertQty = a.FcovertQty,
+                    DEPARTMENTNAME = a.DEPARTMENTNAME,
+                    FngDesc = a.FngDesc,
+                    UrgentFlag = a.UrgentFlag,
+                    Ftype = a.Ftype,
+                    LotNo1 = a.LotNo1,
+                    EMERGENCY = a.EMERGENCY,
+                    Status = a.Status,
+                    IqcDate = a.IqcDate,
+                    // 娣诲姞缁存姢浜哄憳淇℃伅锛堢鐞嗗憳涓嶉渶瑕佹瀛楁锛�
+                    Fcode = null,
+                    // 娣诲姞鐮村潖瀹為獙鏁伴噺
+                    PHSY = a.PHSY,
+                    // 娣诲姞涓嶈壇鍘熷洜
+                    BLYY = a.BLYY,
+                    // 娣诲姞鎵�灞炶溅闂�
+                    SSCJ = a.SSCJ,
+                    // 娣诲姞璇勫鐘舵��
+                    PSZT = a.PSZT,
+                    // 娣诲姞妫�楠岄」鐩淮鎶ょ姸鎬�
+                    Jyxm = a.Jyxm,
+                    // 娣诲姞鐗堟湰鍙凤紙鐢ㄤ簬FTP璺緞锛�
+                    Fversion = a.Fversion
+                })
+                .OrderBy("IQC_DATE DESC")
+                .OrderBy("CASE WHEN EMERGENCY = 1 THEN 0 ELSE 1 END")
+                .OrderBy("CASE WHEN JYXM = 0 THEN 0 ELSE 1 END")
+                .OrderBy("CASE WHEN STATUS = '宸叉彁浜�' THEN 1 ELSE 0 END")
+                .OrderBy("CREATE_DATE")
+                .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+        }
+        else
+        {
+            // 鏅�氱敤鎴凤細浣跨敤JOIN鏌ヨ锛屾牴鎹淮鎶ゆ儏鍐靛垽鏂潈闄�
+            pageList = db.Queryable<LtsLlj, V_LljUser>((a, v) =>
+                    new JoinQueryInfos(JoinType.Left, a.ItemNo == v.ItemNo))
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    "鏈畬鎴�".Equals(queryObj.result),
+                    (a, v) => a.FcheckResu == null)
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    !"鏈畬鎴�".Equals(queryObj.result),
+                    (a, v) => a.FcheckResu != null)
+                .WhereIF(id > 0, (a, v) => a.Id == id)
+                // 鏉冮檺鎺у埗锛氭櫘閫氱敤鎴烽渶瑕佹牴鎹墿鏂欑淮鎶ゆ儏鍐靛垽鏂�
+                .WhereIF(queryObj.UserIndex == "0", 
+                    (a, v) => 
+                        // 濡傛灉鐗╂枡琚淮鎶わ紝鍙湁缁存姢浜哄憳鍙互鐪嬪埌
+                        (v.Fcode != null && v.Fcode == queryObj.createUser) ||
+                        // 濡傛灉鐗╂枡鏈缁存姢锛屾墍鏈変汉閮藉彲浠ョ湅鍒�
+                        (v.Fcode == null))
+                //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
+                    (a, v) => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
+                    (a, v) => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
+                    (a, v) => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
+                    (a, v) => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
+                    (a, v) => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
+                    (a, v) => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .Select((a, v) => new LtsLlj
+                {
+                    Id = a.Id,
+                    ItemNo = a.ItemNo,
+                    ItemId = a.ItemId,
+                    ItemName = a.ItemName,
+                    ItemModel = a.ItemModel,
+                    SuppName = a.SuppName,
+                    LotNo = a.LotNo,
+                    ReleaseNo = a.ReleaseNo,
+                    FcheckResu = a.FcheckResu,
+                    CreateDate = a.CreateDate,
+                    FcovertQty = a.FcovertQty,
+                    DEPARTMENTNAME = a.DEPARTMENTNAME,
+                    FngDesc = a.FngDesc,
+                    UrgentFlag = a.UrgentFlag,
+                    Ftype = a.Ftype,
+                    LotNo1 = a.LotNo1,
+                    EMERGENCY = a.EMERGENCY,
+                    Status = a.Status,
+                    IqcDate = a.IqcDate,
+                    // 娣诲姞缁存姢浜哄憳淇℃伅
+                    Fcode = v.Fcode,
+                    // 娣诲姞鐮村潖瀹為獙鏁伴噺
+                    PHSY = a.PHSY,
+                    // 娣诲姞涓嶈壇鍘熷洜
+                    BLYY = a.BLYY,
+                    // 娣诲姞鎵�灞炶溅闂�
+                    SSCJ = a.SSCJ,
+                    // 娣诲姞璇勫鐘舵��
+                    PSZT = a.PSZT,
+                    // 娣诲姞妫�楠岄」鐩淮鎶ょ姸鎬�
+                    Jyxm = a.Jyxm,
+                    // 娣诲姞鐗堟湰鍙凤紙鐢ㄤ簬FTP璺緞锛�
+                    Fversion = a.Fversion
+                })
+                .OrderBy("IQC_DATE DESC")
+                .OrderBy("CASE WHEN EMERGENCY = 1 THEN 0 ELSE 1 END")
+                .OrderBy("CASE WHEN JYXM = 0 THEN 0 ELSE 1 END")
+                .OrderBy("CASE WHEN STATUS = '宸叉彁浜�' THEN 1 ELSE 0 END")
+                .OrderBy("CREATE_DATE")
+                .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+        }
 
         // 鎵归噺鑾峰彇妫�楠岄」鐩暟閲忥紝閬垮厤N+1鏌ヨ闂
         if (pageList.Any())
@@ -117,40 +196,76 @@
         }
         
         // 璁$畻鎵�鏈夋暟鎹殑鍘婚噸鎬绘暟锛堜笉鏄綋鍓嶉〉鐨勫幓閲嶆暟锛�
-        var allDataQuery = db.Queryable<LtsLlj, V_LljUser>((a, v) =>
-                new JoinQueryInfos(JoinType.Left, a.ItemNo == v.ItemNo))
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                "鏈畬鎴�".Equals(queryObj.result),
-                (a, v) => a.FcheckResu == null)
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                !"鏈畬鎴�".Equals(queryObj.result),
-                (a, v) => a.FcheckResu != null)
-            .WhereIF(id > 0, (a, v) => a.Id == id)
-            // 鏉冮檺鎺у埗锛歅L017銆丠MLYY銆丠MCS 鍙互鐪嬪埌鎵�鏈夊崟鎹紝鍏朵粬鐢ㄦ埛闇�瑕佹牴鎹墿鏂欑淮鎶ゆ儏鍐靛垽鏂�
-            .WhereIF(queryObj.createUser != "PL017" && queryObj.createUser != "HMLYY" && queryObj.createUser != "HMCS" && queryObj.UserIndex == "0", 
-                (a, v) => 
-                    // 濡傛灉鐗╂枡琚淮鎶わ紝鍙湁缁存姢浜哄憳鍙互鐪嬪埌
-                    (v.Fcode != null && v.Fcode == queryObj.createUser) ||
-                    // 濡傛灉鐗╂枡鏈缁存姢锛屾墍鏈変汉閮藉彲浠ョ湅鍒�
-                    (v.Fcode == null))
-            //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
-                (a, v) => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
-                (a, v) => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
-                (a, v) => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
-                (a, v) => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
-                (a, v) => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
-                (a, v) => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
-            .Select((a, v) => a.ReleaseNo)
-            .Distinct()
-            .Count();
+        int allDataQuery;
+        
+        if (isAdmin)
+        {
+            // 绠$悊鍛樿处鍙凤細鐩存帴鏌ヨ涓昏〃
+            allDataQuery = db.Queryable<LtsLlj>()
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    "鏈畬鎴�".Equals(queryObj.result),
+                    a => a.FcheckResu == null)
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    !"鏈畬鎴�".Equals(queryObj.result),
+                    a => a.FcheckResu != null)
+                .WhereIF(id > 0, a => a.Id == id)
+                //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
+                    a => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
+                    a => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
+                    a => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
+                    a => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
+                    a => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
+                    a => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .Select(a => a.ReleaseNo)
+                .Distinct()
+                .Count();
+        }
+        else
+        {
+            // 鏅�氱敤鎴凤細浣跨敤JOIN鏌ヨ
+            allDataQuery = db.Queryable<LtsLlj, V_LljUser>((a, v) =>
+                    new JoinQueryInfos(JoinType.Left, a.ItemNo == v.ItemNo))
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    "鏈畬鎴�".Equals(queryObj.result),
+                    (a, v) => a.FcheckResu == null)
+                .WhereIF(
+                    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                    !"鏈畬鎴�".Equals(queryObj.result),
+                    (a, v) => a.FcheckResu != null)
+                .WhereIF(id > 0, (a, v) => a.Id == id)
+                // 鏉冮檺鎺у埗锛氭櫘閫氱敤鎴烽渶瑕佹牴鎹墿鏂欑淮鎶ゆ儏鍐靛垽鏂�
+                .WhereIF(queryObj.UserIndex == "0", 
+                    (a, v) => 
+                        // 濡傛灉鐗╂枡琚淮鎶わ紝鍙湁缁存姢浜哄憳鍙互鐪嬪埌
+                        (v.Fcode != null && v.Fcode == queryObj.createUser) ||
+                        // 濡傛灉鐗╂枡鏈缁存姢锛屾墍鏈変汉閮藉彲浠ョ湅鍒�
+                        (v.Fcode == null))
+                //鍔犵瓫閫夋潯浠�,鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 1, // 鐗╂枡缂栧彿鎼滅储
+                    (a, v) => a.ItemNo != null && a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 2, // 鐗╂枡鍚嶇О鎼滅储
+                    (a, v) => a.ItemName != null && a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 3, // 渚涘簲鍟嗘悳绱�
+                    (a, v) => a.SuppName != null && a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 4, // 鍒拌揣鍗曞彿鎼滅储
+                    (a, v) => a.LotNo != null && a.LotNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 5, // 妫�楠屽崟鍙锋悳绱�
+                    (a, v) => a.ReleaseNo != null && a.ReleaseNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && queryObj.selectedIndex == 6, // 鐗╂枡瑙勬牸鎼滅储
+                    (a, v) => a.ItemModel != null && a.ItemModel.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                .Select((a, v) => a.ReleaseNo)
+                .Distinct()
+                .Count();
+        }
         
         var emergencyValues = pageList.Select(item => item.EMERGENCY).ToList(); 
         return (pageList, allDataQuery);
@@ -393,7 +508,13 @@
         return input.Substring(startIndex + 1, length);
     }
 
-    public List<QamftpDto> GetAttachments(string ItemNo)
+    /// <summary>
+    /// 鑾峰彇闄勪欢淇℃伅
+    /// </summary>
+    /// <param name="ItemNo">鐗╂枡缂栫爜</param>
+    /// <param name="fversion">鐗堟湰鍙凤紙鍙�夛紝鐢ㄤ簬杩囨护锛�</param>
+    /// <returns>闄勪欢鍒楄〃</returns>
+    public List<QamftpDto> GetAttachments(string ItemNo, string fversion = null)
     {
         //if (string.IsNullOrEmpty(ItemNo))
         //{
@@ -403,8 +524,17 @@
         var db = SqlSugarHelper.GetInstance();
         try
         {
-            return db.Queryable<MesQamftp>()
+            var query = db.Queryable<MesQamftp>()
                 .Where(x => x.ItemNo == ItemNo)
+                .Where(x => x.Ftype == "鏉ユ枡妫�");  // 娣诲姞FTYPE = '鏉ユ枡妫�'鐨勯檺鍒�
+            
+            // 濡傛灉浼犲叆浜唂version锛屽垯鎸塅version杩囨护
+            if (!string.IsNullOrEmpty(fversion))
+            {
+                query = query.Where(x => x.Fversion == fversion);
+            }
+            
+            return query
                 .OrderBy(x => x.Fdate, OrderByType.Desc)
                 // .ThenBy(x => x.CreateDate, OrderByType.Desc)
                 .Select(x => new QamftpDto
@@ -432,7 +562,7 @@
         }
     }
 
-    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer)
+    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer, string fversion = null)
     {
         // 鍙傛暟楠岃瘉
         if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
@@ -446,8 +576,16 @@
         // 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧�
         string normalizedServer = NormalizeFtpServer(ftpServer);
         
-        // 鏋勫缓FTP鏂囦欢璺緞
-        string ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fileName}";
+        // 鏋勫缓FTP鏂囦欢璺緞 - 鏉ユ枡妫�浣跨敤IQC鐩綍锛屼娇鐢╢version浣滀负瀛愮洰褰�
+        string ftpPath;
+        if (!string.IsNullOrEmpty(fversion))
+        {
+            ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fversion}/{fileName}";
+        }
+        else
+        {
+            ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fileName}";
+        }
         
         try
         {
@@ -1153,4 +1291,235 @@
 
     }
 
+    /// <summary>
+    /// 鏍规嵁浜岀淮鐮佹煡璇㈢墿鏂欎俊鎭�
+    /// </summary>
+    /// <param name="itemBarcode">浜岀淮鐮佸唴瀹�</param>
+    /// <param name="currentBillNo">褰撳墠妫�楠屽崟鐨勫埌璐у崟鍙凤紙宸插簾寮冿紝淇濈暀鍙傛暟鍏煎鎬э級</param>
+    /// <returns>鐗╂枡淇℃伅</returns>
+    public List<MaterialInfoDto> GetMaterialByBarcode(string itemBarcode, string currentBillNo)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        try
+        {
+            // 浣跨敤JOIN鏌ヨMES_INV_ITEM_BARCODES鍜孧ES_ITEMS琛�
+            var materialInfo = db.Queryable<MesInvItemBarcodes>()
+                .LeftJoin<MesItems>((b, m) => b.ItemId == m.Id)
+                .Where((b, m) => b.ItemBarcode == itemBarcode && b.ComeFlg == 1)
+                .Select((b, m) => new MaterialInfoDto
+                {
+                    ItemNo = b.ItemNo,        // 鐗╂枡缂栫爜
+                    OldQty = b.Oldqty,        // 鏁伴噺
+                    ItemId = b.ItemId,        // 鐗╂枡ID
+                    ItemName = m.ItemName,    // 鐗╂枡鍚嶇О
+                    ItemModel = m.ItemModel,  // 瑙勬牸鍨嬪彿
+                    BillNo = b.BillNo         // 鍒拌揣鍗曞彿
+                })
+                .ToList();
+            // 绉婚櫎鍒拌揣鍗曞彿鏍¢獙锛岀洿鎺ヨ繑鍥炴煡璇㈢粨鏋�
+            return materialInfo;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception($"鏌ヨ鐗╂枡淇℃伅澶辫触: {ex.Message}");
+        }
+    }
+    /// <summary>
+    /// 鏌ヨ鐮村潖瀹為獙璁板綍鏄惁瀛樺湪
+    /// </summary>
+    /// <param name="billNo">鍒拌揣鍗曞彿</param>
+    /// <param name="releaseNo">妫�楠屽崟鍙�</param>
+    /// <returns>鏄惁瀛樺湪璁板綍</returns>
+    public bool CheckPhsyRecordExists(string billNo, string releaseNo)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        try
+        {
+            var count = db.Queryable<MesInvPhsy>()
+                .Where(x => x.BillNo == billNo && x.ReleaseNo == releaseNo)
+                .Count();
+
+            return count > 0;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception($"鏌ヨ鐮村潖瀹為獙璁板綍澶辫触: {ex.Message}");
+        }
+    }
+    /// <summary>
+    /// 鑾峰彇鐮村潖瀹為獙璁板綍璇︾粏淇℃伅
+    /// </summary>
+    /// <param name="billNo">鍒拌揣鍗曞彿</param>
+    /// <param name="releaseNo">妫�楠屽崟鍙�</param>
+    /// <returns>鐮村潖瀹為獙璁板綍淇℃伅</returns>
+    public List<PhsyRecordInfoDto> GetPhsyRecordInfo(string billNo, string releaseNo)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        try
+        {
+            // 鍏堟煡璇㈢牬鍧忓疄楠岃褰�
+            var phsyRecords = db.Queryable<MesInvPhsy>()
+                .Where(x => x.BillNo == billNo && x.ReleaseNo == releaseNo)
+                .ToList();
+            var result = new List<PhsyRecordInfoDto>();
+
+            foreach (var record in phsyRecords)
+            {
+                // 灏濊瘯閫氳繃鏉$爜鏌ヨ鐗╂枡淇℃伅
+                var materialInfo = db.Queryable<MesInvItemBarcodes>()
+                    .LeftJoin<MesItems>((b, m) => b.ItemId == m.Id)
+                    .Where((b, m) => b.ItemBarcode == record.ItemBarcode)
+                    .Select((b, m) => new {
+                        ItemNo = b.ItemNo,
+                        ItemName = m.ItemName,
+                        ItemModel = m.ItemModel
+                    })
+                    .First();
+                var dto = new PhsyRecordInfoDto
+                {
+                    ItemBarcode = record.ItemBarcode,
+                    ItemNo = materialInfo?.ItemNo ?? record.ItemBarcode,
+                    ItemName = materialInfo?.ItemName ?? "宸茶褰曠墿鏂�",
+                    ItemModel = materialInfo?.ItemModel ?? "宸茶褰曡鏍�",
+                    BillNo = record.BillNo,
+                    Yqty = record.Yqty,
+                    Cqty = record.Cqty,
+                    CreateDate = record.CreateDate
+                };
+
+                result.Add(dto);
+            }
+
+            return result;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception($"鑾峰彇鐮村潖瀹為獙璁板綍淇℃伅澶辫触: {ex.Message}");
+        }
+    }
+    /// <summary>
+    /// 璋冪敤鐮村潖瀹為獙瀛樺偍杩囩▼
+    /// </summary>
+    /// <param name="itemBarcode">鎵弿鐨勬潯鐮佸��</param>
+    /// <param name="yqty">鎵爜鏌ヨ鍑烘潵鐨勬潯鐮佹暟閲�</param>
+    /// <param name="cqty">濉啓鐨勭牬鍧忓疄楠屾暟閲�</param>
+    /// <param name="billNo">鏌ヨ鍒扮殑鍒拌揣鍗曞彿</param>
+    /// <param name="lx">鎿嶄綔绫诲瀷锛�1鏂板锛�2淇敼锛�3鍒犻櫎</param>
+    /// <param name="releaseNo">妫�楠屽崟鍙�</param>
+    /// <param name="itemId">鐗╂枡ID</param>
+    /// <returns>鎵ц缁撴灉</returns>
+    public (int result, string message) CallPhsyUpdateProcedure(string itemBarcode, decimal yqty, decimal cqty, string billNo, int lx, string releaseNo, decimal? itemId = null)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        try
+        {
+            // 瀹氫箟杈撳叆鍙傛暟
+            var inputParam1 = new SugarParameter("P_ITEM_BARCODE", itemBarcode, DbType.String, ParameterDirection.Input);
+            var inputParam2 = new SugarParameter("P_YQTY", yqty, DbType.Decimal, ParameterDirection.Input);
+            var inputParam3 = new SugarParameter("P_CQTY", cqty, DbType.Decimal, ParameterDirection.Input);
+            var inputParam4 = new SugarParameter("P_BILL_NO", billNo, DbType.String, ParameterDirection.Input);
+            var inputParam5 = new SugarParameter("P_LX", lx, DbType.Int32, ParameterDirection.Input);
+            var inputParam6 = new SugarParameter("ITEM_ID", itemId ?? 0, DbType.Decimal, ParameterDirection.Input);
+            var inputParam7 = new SugarParameter("P_RELEASE_NO", releaseNo, DbType.String, ParameterDirection.Input);
+
+            // 瀹氫箟杈撳嚭鍙傛暟
+            var outputResult = new SugarParameter("PO_RESULT", null, DbType.Int32, ParameterDirection.Output);
+            var outputMessage = new SugarParameter("PO_MSG", null, DbType.String, ParameterDirection.Output, 4000);
+            // 浣跨敤SqlSugar鎵ц瀛樺偍杩囩▼
+            db.Ado.ExecuteCommand("BEGIN PRC_INV_PHSYUPDATE(:P_ITEM_BARCODE, :P_YQTY, :P_CQTY, :P_BILL_NO, :P_LX, :ITEM_ID, :P_RELEASE_NO, :PO_RESULT, :PO_MSG); END;",
+                inputParam1, inputParam2, inputParam3, inputParam4, inputParam5, inputParam6, inputParam7, outputResult, outputMessage);
+            // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+            var result = outputResult.Value == null ? 1 : Convert.ToInt32(outputResult.Value);
+            var message = outputMessage.Value?.ToString() ?? "";
+            return (result, message);
+        }
+        catch (Exception ex)
+        {
+            return (1, $"璋冪敤瀛樺偍杩囩▼澶辫触: {ex.Message}");
+        }
+    }
+    /// <summary>
+    /// 璁剧疆鍫电┐淇℃伅
+    /// </summary>
+    /// <param name="releaseNo">妫�楠屽崟鍙�</param>
+    /// <param name="blockedHoles">鍫电┐淇℃伅锛屾牸寮忓"1,2,3"</param>
+    /// <param name="itemId">妫�楠岄」鐩甀D</param>
+    /// <returns>鎵ц缁撴灉</returns>
+    public (int result, string message) SetBlockedHoles(string releaseNo, string blockedHoles, decimal itemId)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        try
+        {
+            // 瑙f瀽鍫电┐淇℃伅
+            var blockedHolesList = blockedHoles.Split(',', '锛�')
+                .Select(s => s.Trim())
+                .Where(s => !string.IsNullOrEmpty(s))
+                .Select(s => int.Parse(s))
+                .ToList();
+            // 鑾峰彇妫�楠岄」鐩俊鎭�
+            var item = db.Queryable<MesQaItemsDetectDetail5>()
+                .Where(x => x.Id == itemId && x.ReleaseNo == releaseNo)
+                .First();
+            if (item == null)
+            {
+                return (1, "妫�楠岄」鐩笉瀛樺湪");
+            }
+            // 瑙f瀽寮�绌存暟
+            var holeCount = ParseHoleCount(item.FcheckItem);
+            if (holeCount == 0)
+            {
+                return (1, "璇ユ楠岄」鐩病鏈夌┐鏁颁俊鎭�");
+            }
+            // 楠岃瘉鍫电┐鏁伴噺涓嶈兘澶т簬绛変簬寮�绌存暟
+            if (blockedHolesList.Count >= holeCount)
+            {
+                return (1, $"鍫电┐鏁伴噺涓嶈兘澶т簬绛変簬寮�绌存暟锛坽holeCount}锛�");
+            }
+            // 楠岃瘉鍫电┐鍙锋槸鍚﹀湪鏈夋晥鑼冨洿鍐�
+            foreach (var hole in blockedHolesList)
+            {
+                if (hole < 1 || hole > holeCount)
+                {
+                    return (1, $"鍫电┐鍙峰繀椤诲湪1-{holeCount}涔嬮棿");
+                }
+            }
+            // 璁$畻鏂扮殑妫�楠屾暟閲�
+            var newCheckQyt = item.CheckQyt - (item.CheckQyt / holeCount) * blockedHolesList.Count;
+            // 鏇存柊鏁版嵁搴�
+            var result = SqlSugarHelper.UseTransactionWithOracle(db =>
+            {
+                return db.Updateable<MesQaItemsDetectDetail5>()
+                    .SetColumns(x => x.Dnum == blockedHoles)
+                    .SetColumns(x => x.CheckQyt == newCheckQyt)
+                    .Where(x => x.Id == itemId && x.ReleaseNo == releaseNo)
+                    .ExecuteCommand();
+            });
+            if (result > 0)
+            {
+                return (0, "鍫电┐璁剧疆鎴愬姛");
+            }
+            else
+            {
+                return (1, "鍫电┐璁剧疆澶辫触");
+            }
+        }
+        catch (Exception ex)
+        {
+            return (1, $"璁剧疆鍫电┐澶辫触: {ex.Message}");
+        }
+    }
+    /// <summary>
+    /// 瑙f瀽妫�楠岄」鐩悕绉颁腑鐨勭┐鏁�
+    /// </summary>
+    /// <param name="checkItemName">妫�楠岄」鐩悕绉�</param>
+    /// <returns>绌存暟锛屽鏋滄病鏈夌┐鏁颁俊鎭繑鍥�0</returns>
+    private int ParseHoleCount(string checkItemName)
+    {
+        if (string.IsNullOrEmpty(checkItemName))
+            return 0;
+        // 鍖归厤鏍煎紡锛氬昂瀵告鏌ワ紙5绌达級鎴� 灏哄妫�鏌�(5绌�)
+        var match = System.Text.RegularExpressions.Regex.Match(checkItemName, @"[锛�(](\d+)绌碵锛�)]");
+        return match.Success ? int.Parse(match.Groups[1].Value) : 0;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3