From b38be3b76d6169692a7907b7f33cd488a5345279 Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期二, 18 三月 2025 16:58:58 +0800
Subject: [PATCH] 单据基础资料优化:器具主档,器具保养规程,器具点检规程,产品器具清单 ,设备档案,设备点检规程,设备保养规程

---
 WebAPI/Controllers/SCGL/日计划管理/JIT_DayPlanPlatFormBillController.cs |  579 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 538 insertions(+), 41 deletions(-)

diff --git "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormBillController.cs" "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormBillController.cs"
index 33442ff..f65d4a8 100644
--- "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormBillController.cs"
+++ "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormBillController.cs"
@@ -9,7 +9,7 @@
 using Newtonsoft.Json.Linq;
 using System.Diagnostics;
 using System.Threading;
-
+using System.Globalization;
 namespace WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�
 {
     public class JIT_DayPlanPlatFormBillController : ApiController
@@ -169,6 +169,9 @@
 
             try
             {
+                Stopwatch sw = new Stopwatch();//璁℃椂鍣�
+                sw.Start();//寮�濮嬭鏃�
+
                 if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user))
                 {
                     objJsonResult.code = "0";
@@ -195,8 +198,11 @@
                 LogService.CustomWriteLog("2:", DateTime.Now.ToString("yyyy-MM-dd"));
                 int TrueCount = 0, SumCount = 0;
                 LogService.CustomWriteLog("list.Count:"+ list.Count, DateTime.Now.ToString("yyyy-MM-dd"));
+
+                string sReturn = "";
+                oSystemParameter.ShowBill(ref sReturn);
                 for (int i = 0; i < list.Count; i++)
-                {
+                {                                     
                     TrueCount = 0;
                     SumCount = 0;
                     long HInterID = 0;
@@ -230,20 +236,26 @@
                         var HMainSourceEntryID = list[i]["婧愬崟瀛愬唴鐮�"].ToString();
                         var HPlanQty = list[i]["璁″垝鏁伴噺"].ToString();
                         var HEmpID = list[i]["HEmpID"].ToString();
+                        var HWorkQty = list[i]["灏忔椂浜ц兘"].ToString();
+                        var HSourceName = list[i]["鐢熶骇璧勬簮"].ToString();
+                        var HWorkQty_ProdLine = list[i]["浜х嚎鎬讳骇鑳�"].ToString();
 
                         LogService.CustomWriteLog("2.05:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
 
-                        if (HSourceID == ""|| HSourceID == "0")
+                        if (oSystemParameter.omodel.WMS_CampanyName != "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
                         {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愪笉鑳戒负绌�!";
-                            objJsonResult.data = null;
-                            return objJsonResult;
+                            if (HSourceID == "" || HSourceID == "0")
+                            {
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愪笉鑳戒负绌�!";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
                         }
-
-                        ds = oCN.RunProcReturn($"select * from Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
+                        ds = oCN.RunProcReturn($"select HInterID,HICMOBillNo from Sc_WorkBillSortBillMain with(nolock) where HMainSourceInterID={HMainSourceInterID}" +
                             $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
+
                         if (ds.Tables[0].Rows.Count > 0)
                         {
                             objJsonResult.code = "0";
@@ -264,7 +276,7 @@
                             " HOrderNeedQty, HSplitQty, HDayPlanSumQty,HPlanBeginDate," +
                             "HSeOrderBillNo,HICMOBillType,HSourceStockInQty,HLeftPlanQty,HOrderLev,HPreparatDate," +
                             "HMainSourceInterID,HMainSourceEntryID,HICMOInterID_Sec,HICMOEntryID_Sec,HPlanQty" +
-                            ",HICMOInterID,HICMOEntryID,HPlanEndDate,HEmpID)values" +
+                            ",HICMOInterID,HICMOEntryID,HPlanEndDate,HEmpID,HWorkQty,HSourceName,HWorkQty_ProdLine)values" +
                             $"({HInterID},'{HBillNo}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
                             $"'{BillType}',GETDATE(),1,'{user}',getdate(),'{HICMOBillNo}','{HOrderType}'," +
                             $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID == "" ? 0.ToString() : HSourceID)}, {(HYX == "" ? 0.ToString() : HYX)}, {(HProdORGID == "" ? 0.ToString() : HProdORGID)}," +
@@ -272,7 +284,7 @@
                             $" 0, {(HSplitQty == "" ? 0.ToString() : HSplitQty)}, {(HDayPlanSumQty == "" ? 0.ToString() : HDayPlanSumQty)},'{HPlanBeginDate}'," +
                             $"'{HSeOrderBillNo}','{HICMOBillType}',{(HSourceStockInQty == "" ? 0.ToString() : HSourceStockInQty)},{(HLeftPlanQty == "" ? 0.ToString() : HLeftPlanQty)},'{HOrderLev}',getdate()," +
                             $"{HMainSourceInterID},{HMainSourceEntryID},{HMainSourceInterID},{HMainSourceEntryID},{HPlanQty}," +
-                            $"{HMainSourceInterID},{HMainSourceEntryID},'{HPlanEndDate}','{HEmpID}')";
+                            $"{HMainSourceInterID},{HMainSourceEntryID},'{HPlanEndDate}','{HEmpID}','{HWorkQty}','{HSourceName}','{HWorkQty_ProdLine}')";
 
                         //LogService.Write("sql:" + sql);
                         //涓昏〃
@@ -298,17 +310,41 @@
                         var HOrderCommitDate = list[i]["璁㈠崟浜よ揣鏈�"].ToString();
                         var HPlanEndDate = list[i]["璁″垝缁撴潫鏃ユ湡"].ToString();
                         var HSplitQty = list[i]["鎷嗗崟鏁伴噺"].ToString();
+                        var HSourceName = list[i]["鐢熶骇璧勬簮"].ToString();
+                        var HWorkQty_ProdLine = list[i]["浜х嚎鎬讳骇鑳�"].ToString();
+
+                        var HOrderType = list[i]["璁㈠崟绫诲瀷"].ToString();
+                        var HWorkShopID = list[i]["HWorkShopID"].ToString();
+                        var HProdORGID = list[i]["HProdORGID"].ToString();
+                        var HMaterID = list[i]["HMaterID"].ToString();
+                        var HMaterName = list[i]["鐗╂枡鍚嶇О"].ToString();
+                        var HMaterModel = list[i]["瑙勬牸鍨嬪彿"].ToString().Replace("'", "''");
+                        var HUnitID = list[i]["HUnitID"].ToString();
+                        var HSeOrderBillQty = list[i]["閿�鍞鍗曟暟閲�"].ToString();
+                        var HDayPlanSumQty = list[i]["鏃ヨ鍒掓暟閲忔�婚噺"].ToString();
+                        var HPlanBeginDate = list[i]["璁″垝寮�濮嬫棩鏈�"].ToString();
+                        var HSeOrderBillNo = list[i]["閿�鍞鍗曞彿"].ToString();
+                        var HICMOBillType = list[i]["鐢熶骇璁㈠崟鍗曟嵁绫诲瀷"].ToString();
+                        var HSourceStockInQty = list[i]["浜х嚎鍏ュ簱鏁伴噺"].ToString();
+                        var HLeftPlanQty = list[i]["鏈帓鏁伴噺"].ToString();
+                        var HOrderLev = list[i]["璁㈠崟绛夌骇"].ToString();
+                        var HPlanQty = list[i]["璁″垝鏁伴噺"].ToString();
+                        var HEmpID = list[i]["HEmpID"].ToString();
 
                         LogService.CustomWriteLog("2.1:"+i, DateTime.Now.ToString("yyyy-MM-dd"));
-
-                        if (HSourceID == "" || HSourceID == "0")
+                        
+                        if (oSystemParameter.omodel.WMS_CampanyName != "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
                         {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愪笉鑳戒负绌�!";
-                            objJsonResult.data = null;
-                            return objJsonResult;
+                            if (HSourceID == "" || HSourceID == "0")
+                            {
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愪笉鑳戒负绌�!";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
                         }
+
                         var str = 0;
                         if (!int.TryParse(HYX, out str))
                         {
@@ -319,31 +355,164 @@
                             return objJsonResult;
                         }
 
-                        ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
-                              $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
-
-                        if (ds.Tables[0].Rows.Count > 1)
+                        if (oSystemParameter.omodel.WMS_CampanyName == "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
                         {
-                            LogService.CustomWriteLog("绗�" + i + 1 + "琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�", DateTime.Now.ToString("yyyy-MM-dd"));
-                            LogService.CustomWriteLog($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
-                              $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", DateTime.Now.ToString("yyyy-MM-dd"));
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�!";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                        LogService.CustomWriteLog("2.2:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
+                            //鐪嬫湁鍑犲彴鐢熶骇璧勬簮鍗忓悓鐢熶骇
+                            string[] HSourceNameArr = HSourceName.Split(new char[]{'&'});
 
-                        oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID == "" ? 0.ToString() : HSourceID)},HYX={HYX}" +
-                            $",HWorkQty={HWorkQty},HProdTimes={HProdTimes},HReadyTimes={HReadyTimes},HLastBeginDate='{HLastBeginDate}'" +
-                            $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}',HPlanEndDate='{HPlanEndDate}',HSplitQty={HSplitQty}" +
-                            $" where HInterID={list[i]["hmainid"].ToString()} and HBillNo='{list[i]["鍗曟嵁鍙�"].ToString()}'");
+                            if (HSourceNameArr.Length >= 2)
+                            {
+                                for (int s = 0; s < HSourceNameArr.Length; s++)
+                                {
+                                    if (s == 0)
+                                    {
+                                        ds = oCN.RunProcReturn("select HItemID from Gy_Source with(nolock) where HName = '" + HSourceNameArr[s] + "'", "Gy_Source");
+
+                                        var HSourceID_Child = ds.Tables[0].Rows[0]["HItemID"];
+
+                                        oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID_Child == "" ? 0.ToString() : HSourceID_Child)}" +
+                                            $",HYX={HYX},HWorkQty={HWorkQty},HProdTimes={HProdTimes},HReadyTimes={HReadyTimes},HLastBeginDate='{HLastBeginDate}'" +
+                                            $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}'" +
+                                            $",HPlanEndDate='{HPlanEndDate}',HSplitQty={HSplitQty},HSourceName='{HSourceName}',HWorkQty_ProdLine={HWorkQty_ProdLine}" +
+                                            $" where HInterID={list[i]["hmainid"].ToString()} and HBillNo='{list[i]["鍗曟嵁鍙�"].ToString()}'");
+                                    }
+                                    else
+                                    {
+                                        ds = oCN.RunProcReturn("select HItemID from Gy_Source with(nolock) where HName = '" + HSourceNameArr[s] + "'", "Gy_Source");
+
+                                        var HSourceID_Child = ds.Tables[0].Rows[0]["HItemID"];
+
+                                        //鏂板鍗忓悓鐢熶骇璧勬簮鐨勬帓浜ц褰�
+                                        ds = oCN.RunProcReturn($"select HInterID,HICMOBillNo from Sc_WorkBillSortBillMain with(nolock) where HMainSourceInterID={HMainSourceInterID}" +
+                           $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID_Child}", "Sc_WorkBillSortBillMain");
+
+                                        if (ds.Tables[0].Rows.Count > 0)
+                                        {
+                                            objJsonResult.code = "0";
+                                            objJsonResult.count = 0;
+                                            objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�!";
+                                            objJsonResult.data = null;
+                                            return objJsonResult;
+                                        }
+
+                                        //鏂板鍗曟嵁鍙� id
+                                        var HBillNo_New = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);//鑾峰緱涓�涓柊鐨勫崟鎹彿
+                                        var HInterID_New = DBUtility.ClsPub.CreateBillID_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo);//鑾峰緱涓�涓柊鐨刬d
+
+                                        string sql = $"insert into Sc_WorkBillSortBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType," +
+                                            "HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HICMOBillNo,HOrderType," +
+                                            "HICMOEntrySEQ,HWorkShopID,HSourceID, HYX, HProdORGID," +
+                                            " HMaterID, HMaterName, HMaterModel, HUnitID, HSeOrderBillQty," +
+                                            " HOrderNeedQty, HSplitQty, HDayPlanSumQty,HPlanBeginDate," +
+                                            "HSeOrderBillNo,HICMOBillType,HSourceStockInQty,HLeftPlanQty,HOrderLev,HPreparatDate," +
+                                            "HMainSourceInterID,HMainSourceEntryID,HICMOInterID_Sec,HICMOEntryID_Sec,HPlanQty" +
+                                            ",HICMOInterID,HICMOEntryID,HPlanEndDate,HEmpID,HWorkQty,HSourceName,HWorkQty_ProdLine,HRemark)values" +
+                                            $"({HInterID_New},'{HBillNo_New}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
+                                            $"'{BillType}',GETDATE(),1,'{user}',getdate(),'{HICMOBillNo}','{HOrderType}'," +
+                                            $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID_Child == "" ? 0.ToString() : HSourceID_Child)}, {(HYX == "" ? 0.ToString() : HYX)}, {(HProdORGID == "" ? 0.ToString() : HProdORGID)}," +
+                                            $" {(HMaterID == "" ? 0.ToString() : HMaterID)}, '{HMaterName}', '{HMaterModel}', {(HUnitID == "" ? 0.ToString() : HUnitID)}, {(HSeOrderBillQty == "" ? 0.ToString() : HSeOrderBillQty)}," +
+                                            $" 0, {(HSplitQty == "" ? 0.ToString() : HSplitQty)}, {(HDayPlanSumQty == "" ? 0.ToString() : HDayPlanSumQty)},'{HPlanBeginDate}'," +
+                                            $"'{HSeOrderBillNo}','{HICMOBillType}',{(HSourceStockInQty == "" ? 0.ToString() : HSourceStockInQty)},{(HLeftPlanQty == "" ? 0.ToString() : HLeftPlanQty)},'{HOrderLev}',getdate()," +
+                                            $"{HMainSourceInterID},{HMainSourceEntryID},{HMainSourceInterID},{HMainSourceEntryID},{HPlanQty}," +
+                                            $"{HMainSourceInterID},{HMainSourceEntryID},'{HPlanEndDate}','{HEmpID}','{HWorkQty}','{HSourceName}','{HWorkQty_ProdLine}','{"鍗忓悓鐢熶骇"}')";
+
+                                        //LogService.Write("sql:" + sql);
+                                        //涓昏〃
+                                        oCN.RunProc(sql);
+
+                                        //鎻掑叆瀛愯〃鏁版嵁
+                                        for (int j = 0; j < 180; j++)
+                                        {                                           
+                                            //涓昏〃鏈夋暟鎹� 瀛愯〃鏃犳暟鎹�
+                                            //if (j == 180 - 1 && SumCount == 0 && HInterID_New != 0 && HBillNo_New != "")
+                                            //{
+                                            //    objJsonResult = AddBillSub(HInterID_New.ToString(), HBillNo_New, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0, list[i]);
+                                            //}
+
+
+                                            if (list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString() != "")
+                                            {
+                                                ////淇濆瓨瀛愯〃
+                                                objJsonResult = AddBillSub(HInterID_New == 0 ? list[i]["hmainid"].ToString() : HInterID_New.ToString()
+                                                    , HBillNo_New == "" ? list[i]["鍗曟嵁鍙�"].ToString() : HBillNo_New
+                                                     , DateTime.Parse(DateTime.Now.AddDays(j).ToString("yyyy-MM-dd").ToString())
+                                                     , 0
+                                                     , list[i]);
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                ds = oCN.RunProcReturn($"select HInterID,HICMOBillNo from Sc_WorkBillSortBillMain with(nolock) where HMainSourceInterID={HMainSourceInterID}" +
+                             $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
+
+                                if (ds.Tables[0].Rows.Count > 1)
+                                {
+                                    LogService.CustomWriteLog("绗�" + i + 1 + "琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�", DateTime.Now.ToString("yyyy-MM-dd"));
+                                    LogService.CustomWriteLog($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
+                                      $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", DateTime.Now.ToString("yyyy-MM-dd"));
+                                    objJsonResult.code = "0";
+                                    objJsonResult.count = 0;
+                                    objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�!";
+                                    objJsonResult.data = null;
+                                    return objJsonResult;
+                                }
+                                LogService.CustomWriteLog("2.2:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
+
+                                oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID == "" ? 0.ToString() : HSourceID)},HYX={HYX}" +
+                                    $",HWorkQty={HWorkQty},HProdTimes={HProdTimes},HReadyTimes={HReadyTimes},HLastBeginDate='{HLastBeginDate}'" +
+                                    $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}',HPlanEndDate='{HPlanEndDate}',HSplitQty={HSplitQty},HSourceName='{HSourceName}',HWorkQty_ProdLine={HWorkQty_ProdLine}" +
+                                    $" where HInterID={list[i]["hmainid"].ToString()} and HBillNo='{list[i]["鍗曟嵁鍙�"].ToString()}'");
+                            }
+                        }
+                        else
+                        {
+                            ds = oCN.RunProcReturn($"select HInterID,HICMOBillNo from Sc_WorkBillSortBillMain with(nolock) where HMainSourceInterID={HMainSourceInterID}" +
+                             $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
+
+                            if (ds.Tables[0].Rows.Count > 1)
+                            {
+                                LogService.CustomWriteLog("绗�" + i + 1 + "琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�", DateTime.Now.ToString("yyyy-MM-dd"));
+                                LogService.CustomWriteLog($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
+                                  $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", DateTime.Now.ToString("yyyy-MM-dd"));
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = $"绗瑊i + 1}琛岀敓浜ц祫婧愭湁閲嶅,璇蜂慨鏀�!";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+                            LogService.CustomWriteLog("2.2:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
+
+                            oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID == "" ? 0.ToString() : HSourceID)},HYX={HYX}" +
+                                $",HWorkQty={HWorkQty},HProdTimes={HProdTimes},HReadyTimes={HReadyTimes},HLastBeginDate='{HLastBeginDate}'" +
+                                $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}',HPlanEndDate='{HPlanEndDate}',HSplitQty={HSplitQty},HSourceName='{HSourceName}',HWorkQty_ProdLine={HWorkQty_ProdLine}" +
+                                $" where HInterID={list[i]["hmainid"].ToString()} and HBillNo='{list[i]["鍗曟嵁鍙�"].ToString()}'");
+                        }                       
                     }
 
                     oCN.RunProc($"update Sc_WorkBillSortBillMain set HDayPlanSumQty={list[i]["鏃ヨ鍒掓暟閲忔�婚噺"].ToString()} where HInterID={(HInterID==0?int.Parse(list[i]["hmainid"].ToString()):HInterID)} and HBillNo='{(HBillNo==""?list[i]["鍗曟嵁鍙�"].ToString(): HBillNo)}'");
 
-                    int SumDay = 31; //鍔ㄦ�佷袱鏈堜箣宸� DateTime.Now.AddMonths(1).AddDays(-1).Subtract(DateTime.Now).Days;
+                    int SumDay = 0; //鍔ㄦ�佷袱鏈堜箣宸� DateTime.Now.AddMonths(1).AddDays(-1).Subtract(DateTime.Now).Days;
+
+                    // 缁熻鎬诲ぉ鏁�
+                    HashSet<DateTime> uniqueDates = new HashSet<DateTime>();
+
+                    foreach (var key in list[i].Keys)
+                    {
+                        if (DateTime.TryParseExact(key, "yyyy-M-d", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
+                        {
+                            uniqueDates.Add(date);
+                        }
+                    }
+
+                    SumDay = uniqueDates.Count;
+
+                    if (oSystemParameter.omodel.WMS_CampanyName == "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
+                    {
+                        SumDay = 180;
+                    }            
 
                     LogService.CustomWriteLog("2.3:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                     for (int j = 0; j < SumDay; j++)
@@ -364,7 +533,7 @@
                             }
                         }
                         //涓昏〃鏈夋暟鎹� 瀛愯〃鏃犳暟鎹�
-                        if (j == 30 && SumCount == 0 && HInterID != 0 && HBillNo != "")
+                        if (j == SumDay-1 && SumCount == 0 && HInterID != 0 && HBillNo != "")
                         {
                             //LogService.CustomWriteLog("3:"+ HInterID+","+ HBillNo, DateTime.Now.ToString("yyyy-MM-dd"));
                             objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0, list[i]);
@@ -381,6 +550,8 @@
                         objJsonResult.data = null;
                         return objJsonResult;
                     }
+
+                   
                 }
 
                 LogService.CustomWriteLog("2.5:", DateTime.Now.ToString("yyyy-MM-dd"));
@@ -389,6 +560,8 @@
                 oCN.RunProc("exec REALESE_SC_ICMOBILLSTATUS_TMP");
 
                 LogService.CustomWriteLog("2.6:", DateTime.Now.ToString("yyyy-MM-dd"));
+                sw.Stop();//缁撴潫璁℃椂
+                LogService.Write($"========================1.鎺掍骇璁㈠崟鎬荤敤鏃讹細" + sw.Elapsed);
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -409,7 +582,7 @@
         public json AddBillSub(string HInterID, string HBillNo, DateTime date, double HQTY, Dictionary<string, string> dic)
         {         
             //鑾峰彇琛ㄦ牸鏁版嵁
-            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where 鍗曟嵁鍙�='{HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
+            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBill_PC where 鍗曟嵁鍙�='{HBillNo}'", "h_v_JIT_Sc_WorkBillSortBill_PC");
             int count = 0;
             if (ds.Tables[0].Rows.Count > 0)
             {
@@ -431,7 +604,16 @@
                 oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HSEQ," +
                     "HMasterDate,HQty,HUseTimes)" +
                             $"values({HInterID}, {(ds.Tables[0].Rows.Count + 1)}," +
-                            $" '{date}', {HQTY},{ ( (dic["灏忔椂浜ц兘"] == "0.0000" ? 0 : HQTY / float.Parse(dic["灏忔椂浜ц兘"].ToString())).ToString()=="闈炴暟瀛�" ? 0 : dic["灏忔椂浜ц兘"] == "0.0000" ? 0 : HQTY / float.Parse(dic["灏忔椂浜ц兘"].ToString())) })");               
+                            $" '{date}', {HQTY},{ ((dic["灏忔椂浜ц兘"] == "0.0000" ? 0 : dic["灏忔椂浜ц兘"] == "0" ? 0 : HQTY / float.Parse(dic["灏忔椂浜ц兘"].ToString())).ToString() == "闈炴暟瀛�" ? 0 : dic["灏忔椂浜ц兘"] == "0.0000" ? 0 : dic["灏忔椂浜ц兘"] == "0" ? 0 : HQTY / float.Parse(dic["灏忔椂浜ц兘"].ToString())) })");               
+            }
+
+            string sReturn = "";
+            oSystemParameter.ShowBill(ref sReturn);
+            if (oSystemParameter.omodel.WMS_CampanyName == "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
+            {
+                //鎶婃帓浜ц鍗曞畬宸ユ棩鏈熷弽鍐欏埌閲戣澏閿�鍞鍗曚笂
+                string sql = "exec h_p_JIT_UpdateEndDateToERP " + HInterID + ",'" + HBillNo + "'";
+                oCN.RunProc(sql);
             }
 
             objJsonResult.code = "1";
@@ -792,6 +974,19 @@
                 //LogService.Write("榻愬鍒嗘瀽sql:" + sql);
                 List<PRD_PPBOM> BomList = new List<PRD_PPBOM>();
                 DataTable resulTable = ds.Tables[0];
+
+                if (ds.Tables[0].Rows.Count < 1 || ds == null)
+                {
+                    //閲婃斁榻愬鎿嶄綔 閬垮厤澶氫汉鍚屾椂杩涜榻愬鍒嗘瀽
+                    oCN.RunProc($"update T_PRD_QTFX set FSTATUS = 0 where FPRDORGID ={omdelMian.HProdORGID} and FSTATUS = 1 ");
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "娌℃湁闇�瑕佽繘琛岄綈濂楀垎鏋愮殑鏁版嵁";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
                 if (resulTable.Rows[0][0].ToString().Contains("澶辫触"))
                 {
                     //閲婃斁榻愬鎿嶄綔 閬垮厤澶氫汉鍚屾椂杩涜榻愬鍒嗘瀽
@@ -1596,11 +1791,16 @@
                     {
                         sqlName = "AIS20240809105013";
                     }
+                    else if (oSystemParameter.omodel.WMS_CampanyName == "瀹濆伐")
+                    {
+                        sqlName = "AIS20250102123554";
+                    }
                     else
                     {
                         sqlName = "AIS20210811135644";
                     }
                 }
+
 
                 if (HTLType == "缂烘枡")
                 {
@@ -2593,6 +2793,58 @@
         }
         #endregion
 
+        #region 鐢熶骇鏃ヨ鍒掑钩鍙� 閿佸畾宸ュ崟
+        [Route("JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHLockedOrder")]
+        [HttpGet]
+        public object JIT_DayPlanPlatFormBillHLockedOrder(string HInterIDs)
+        {
+            try
+            {
+                oCN.RunProc($"update Sc_WorkBillSortBillMain set HLockOrder = 1 where HInterID in ({HInterIDs})");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇鏃ヨ鍒掑钩鍙� 瑙i攣宸ュ崟
+        [Route("JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHUnlockOrder")]
+        [HttpGet]
+        public object JIT_DayPlanPlatFormBillHUnlockOrder(string HInterIDs)
+        {
+            try
+            {
+                oCN.RunProc($"update Sc_WorkBillSortBillMain set HLockOrder = 0 where HInterID in ({HInterIDs})");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
         #region 鐢熶骇鏃ヨ鍒掑钩鍙� 鐢熶骇璁㈠崟鏌ヨ
         [Route("JIT_DayPlanPlatFormBill/JIT_ICMOBillList")]
         [HttpGet]
@@ -2825,5 +3077,250 @@
             }
         }
         #endregion
+
+        #region 鐢熶骇鏃ヨ鍒掑钩鍙� 鏍规嵁杞﹂棿娣诲姞鏈帓浜х敓浜ц鍗�
+        [Route("JIT_DayPlanPlatFormBill/JIT_ICMOBillListByDept")]
+        [HttpGet]
+        public object JIT_ICMOBillListByDept(string HDeptID)
+        {
+            try
+            {
+                //鑾峰彇鏄剧ず绯荤粺鍙傛暟
+                string sReturn = "";
+                oSystemParameter.ShowBill(ref sReturn);
+
+                //鏌ヨ閫夋嫨杞﹂棿涓湭鎺掍骇杩囩殑鐢熶骇璁㈠崟淇℃伅锛堟坊搴风鎶�--鐢熶骇璁㈠崟鐘舵�佷负涓嬭揪锛�
+                ds = oCN.RunProcReturn($"exec h_p_JIT_ICMOBillListByDept '{HDeptID}'", "h_p_JIT_ICMOBillListByDept");
+
+                if (ds.Tables[0].Rows.Count > 0 && ds != null)
+                {
+                    if (oSystemParameter.omodel.WMS_CampanyName == "娣诲悍绉戞妧") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
+                    {
+                        //鏁版嵁琛ㄦ牸娣诲姞鍔ㄦ�佹棩鏈�
+                        for (int j = 1; j <= 180; j++)
+                        {
+                            ds.Tables[0].Columns.Add(DateTime.Now.AddDays(j - 1).ToString("yyyy-MM-dd"), typeof(Int32));
+                        }
+                    }
+                    else
+                    {
+                        //鏁版嵁琛ㄦ牸娣诲姞鍔ㄦ�佹棩鏈�
+                        for (int j = 1; j <= 31; j++)
+                        {
+                            ds.Tables[0].Columns.Add(DateTime.Now.AddDays(j - 1).ToString("yyyy-MM-dd"), typeof(Int32));
+                        }
+                    }                   
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "Sucess锛�";
+                    objJsonResult.data = ds.Tables[0];
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏌ユ棤鏁版嵁锛屽綋鍓嶆墍閫夎溅闂翠笅鏆傛棤鏈帓浜т笖璁㈠崟鐘舵�佷负涓嬭揪鐨勭敓浜ц鍗曚俊鎭紒";
+                    objJsonResult.data = "";
+                    return objJsonResult;
+                }
+               
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇鏃ヨ鍒掑钩鍙� 鑾峰彇瀹屽伐鏃ユ湡
+        [Route("JIT_DayPlanPlatFormBill/GetICMOCompletionDate")]
+        [HttpGet]
+        public object GetICMOCompletionDate(string HDeptID)
+        {
+            try
+            {
+                //鏇存柊鏃ヨ鍒掑伐鍗曠殑瀹屽伐鏃ユ湡
+                oCN.RunProc($"exec h_p_JIT_GetICMOCompletionDate '{HDeptID}'");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鑾峰彇瀹屽伐鏃ユ湡鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇鏃ヨ鍒掑钩鍙� 鑾峰彇鏈�鏃╁紑宸ユ棩鏈�
+        [Route("JIT_DayPlanPlatFormBill/GetICMOEarlyDate")]
+        [HttpGet]
+        public object GetICMOEarlyDate(string HDeptID)
+        {
+            try
+            {
+                //鏇存柊鐢熶骇璁㈠崟鐨勬渶鏃╁紑宸ユ棩鏈�
+                oCN.RunProc($"exec h_p_JIT_GetICMOEarlyDate '{HDeptID}'");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鑾峰彇鏈�鏃╁紑宸ユ棩鏈熸垚鍔燂紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 閫氳繃鐗╂枡鍖归厤浜у搧鍣ㄥ叿娓呭崟
+        [Route("JIT_DayPlanPlatFormBill/GetMouldByMater")]
+        [HttpGet]
+        public object GetMouldByMater(string HMaterID,string HSourceID,string HPCDate)
+        {
+            try
+            {
+                ds = oCN.RunProcReturn("exec h_p_Gy_MaterialMouldByMater " + HMaterID + "," + HSourceID + ",'" + HPCDate + "'", "h_p_Gy_MaterialMouldByMater");               
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 閫氳繃璧勬簮鍖归厤璧勬簮鍣ㄥ叿娓呭崟
+        [Route("JIT_DayPlanPlatFormBill/GetMouldBySource")]
+        [HttpGet]
+        public object GetMouldBySource(string HSourceID, string HMouldID)
+        {
+            try
+            {
+                ds = oCN.RunProcReturn("select * from h_v_Gy_SourceMouldBillMainList where HSourceID = " + HSourceID + " and HMouldID = " + HMouldID, "h_v_Gy_SourceMouldBillMainList");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鎺掍骇鍚庡皢鍣ㄥ叿鍗犵敤鏃堕棿鍐欏叆鏁版嵁搴�
+        [Route("JIT_DayPlanPlatFormBill/AddMouldOccupancyTime")]
+        [HttpGet]
+        public object AddMouldOccupancyTime(string HMouldID, string HSourceID, string HICMOInterID, string HICMOEntryID, string HICMOBillNo, string HMouldPCTime)
+        {
+            try
+            {
+                ds = oCN.RunProcReturn("exec h_p_JIT_AddMouldOccupancyTime " + HMouldID + "," + HSourceID + "," + HICMOInterID + "," + HICMOEntryID + ",'" + HICMOBillNo  + "','" + HMouldPCTime + "'", "h_p_JIT_AddMouldOccupancyTime");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = "";
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 閫氳繃涓昏祫婧愬尮閰嶅瓙璧勬簮
+        [Route("JIT_DayPlanPlatFormBill/GetChildSource")]
+        [HttpGet]
+        public object GetChildSource(string HSourceID)
+        {
+            try
+            {
+                ds = oCN.RunProcReturn("select HItemID 瀛愯祫婧怚D,HNumber 瀛愯祫婧愪唬鐮�,HName 瀛愯祫婧愬悕绉�,HCubicleQty 瀛愯祫婧愬伐浣嶆暟 from Gy_Source with(nolock) where HParentID = " + HSourceID + " order by HName asc", "Gy_Source");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鍒ゆ柇鐗╂枡鏄惁鍙互鏀惧湪鍚屼竴璧勬簮涓婁竴璧风敓浜�
+        [Route("JIT_DayPlanPlatFormBill/GetSourceByMater")]
+        [HttpGet]
+        public object GetSourceByMater(string HMaterID)
+        {
+            try
+            {
+                ds = oCN.RunProcReturn("exec h_p_Sc_ICMOGetWorkSource_TK " + HMaterID + ",'',''", "h_p_Sc_ICMOGetWorkSource_TK");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1