WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/JIT_DayPlanPlatFormBillController.cs
@@ -8,7 +8,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using System.Threading;
using System.Globalization;
namespace WebAPI.Controllers.SCGL.日计划管理
{
    public class JIT_DayPlanPlatFormBillController : ApiController
@@ -42,7 +43,8 @@
                omdelMian = JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(sWhere);
                ds = oCN.RunProcReturn($"exec h_p_JIT_Sc_WorkBillSortBill_Query '{omdelMian.HPlanBeginDate}',{(omdelMian.HProdORGID == null ? 0 : omdelMian.HProdORGID)},'{omdelMian.HSeOrderBillNo}'" +
                    $",'{omdelMian.HPlanEndDate.AddDays(1)}',{omdelMian.HMaterID},'{omdelMian.HICMOBillNo}',{omdelMian.HWorkShopID}", "h_p_JIT_Sc_WorkBillSortBill_Query");
                    $",'{omdelMian.HPlanEndDate.AddDays(1)}',{omdelMian.HMaterID},'{omdelMian.HICMOBillNo}',{omdelMian.HWorkShopID}" +
                    $",'{omdelMian.HMastersDate}','{omdelMian.sWheres}'", "h_p_JIT_Sc_WorkBillSortBill_Query");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -96,6 +98,40 @@
                return objJsonResult;
            }
        }
        /// <summary>
        /// æ ¹æ®ç‚¹å‡»è¡Œæ ‡é¢˜æ—¶é—´æŸ¥è¯¢ç¼ºæ–™åˆ†æž
        /// </summary>
        /// <param name="sWhere"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        [Route("JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHDateTimeList")]
        [HttpGet]
        public object JIT_DayPlanPlatFormBillHDateTimeList(string sWhere)
        {
            try
            {
                MaterialShorAnalysis Report = JsonConvert.DeserializeObject<MaterialShorAnalysis>(sWhere);
                ds = oCN.RunProcReturn($"exec h_p_JIT_MaterialShorAnalysisReportList {Report.HORGID},'{Report.HBEGINDATE}','{Report.HENDDATE}' ", "h_p_JIT_PODemandPlanBill_ReportList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                //objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ç”Ÿäº§æ—¥è®¡åˆ’平台 ä¿å­˜
@@ -127,12 +163,15 @@
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                Stopwatch sw = new Stopwatch();//计时器
                sw.Start();//开始计时
                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
@@ -142,6 +181,7 @@
                    return objJsonResult;
                }
                LogService.CustomWriteLog("1:"+msg2, DateTime.Now.ToString("yyyy-MM-dd"));
                //JSON序列化转换字典集合
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<object> jb = JsonConvert.DeserializeObject<List<object>>(msg2);
@@ -155,16 +195,21 @@
                    list.Add(dic);
                }
                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;
                    var HBillNo = "";
                    if (list[i]["单据号"].ToString() == "" && list[i]["hmainid"].ToString() == "")
                    {
                        LogService.CustomWriteLog("2.01:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        var HICMOBillNo = list[i]["生产订单号"].ToString();
                        var HOrderType = list[i]["订单类型"].ToString();
                        var HICMOEntrySEQ = list[i]["生产订单明细行号"].ToString();
@@ -174,13 +219,14 @@
                        var HProdORGID = list[i]["HProdORGID"].ToString();
                        var HMaterID = list[i]["HMaterID"].ToString();
                        var HMaterName = list[i]["物料名称"].ToString();
                        var HMaterModel = list[i]["规格型号"].ToString();
                        var HMaterModel = list[i]["规格型号"].ToString().Replace("'", "''");
                        var HUnitID = list[i]["HUnitID"].ToString();
                        var HSeOrderBillQty = list[i]["销售订单数量"].ToString();
                        //var HOrderNeedQty = list[i]["订单需求数量"].ToString();
                        var HSplitQty = list[i]["拆单数量"].ToString();
                        var HDayPlanSumQty = list[i]["日计划数量总量"].ToString();
                        var HPlanBeginDate = list[i]["计划开始日期"].ToString();
                        var HPlanEndDate = list[i]["计划结束日期"].ToString();
                        var HSeOrderBillNo = list[i]["销售订单号"].ToString();
                        var HICMOBillType = list[i]["生产订单单据类型"].ToString();
                        var HSourceStockInQty = list[i]["产线入库数量"].ToString();
@@ -189,18 +235,27 @@
                        var HMainSourceInterID = list[i]["源单主内码"].ToString();
                        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();
                        if (HSourceID == ""|| HSourceID == "0")
                        LogService.CustomWriteLog("2.05:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        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";
@@ -220,14 +275,16 @@
                            " HMaterID, HMaterName, HMaterModel, HUnitID, HSeOrderBillQty," +
                            " HOrderNeedQty, HSplitQty, HDayPlanSumQty,HPlanBeginDate," +
                            "HSeOrderBillNo,HICMOBillType,HSourceStockInQty,HLeftPlanQty,HOrderLev,HPreparatDate," +
                            "HMainSourceInterID,HMainSourceEntryID,HICMOInterID_Sec,HICMOEntryID_Sec,HPlanQty)values" +
                            "HMainSourceInterID,HMainSourceEntryID,HICMOInterID_Sec,HICMOEntryID_Sec,HPlanQty" +
                            ",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)}," +
                            $" {(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},{HMainSourceInterID},{HMainSourceEntryID},{HPlanQty}," +
                            $"{HMainSourceInterID},{HMainSourceEntryID},'{HPlanEndDate}','{HEmpID}','{HWorkQty}','{HSourceName}','{HWorkQty_ProdLine}')";
                        //LogService.Write("sql:" + sql);
                        //主表
@@ -235,21 +292,59 @@
                    }
                    else
                    {
                        LogService.CustomWriteLog("2.0:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        HBillNo = list[i]["单据号"].ToString();
                        HInterID = int.Parse(list[i]["hmainid"].ToString());
                        var HMainSourceInterID = list[i]["源单主内码"].ToString();
                        var HMainSourceEntryID = list[i]["源单子内码"].ToString();
                        var HICMOBillNo = list[i]["生产订单号"].ToString();
                        var HICMOEntrySEQ = list[i]["生产订单明细行号"].ToString();
                        var HSourceID = list[i]["HSourceID"].ToString();
                        var HYX = list[i]["优先级"].ToString();
                        var HWorkQty = list[i]["小时产能"].ToString();
                        var HProdTimes = list[i]["生产周期"].ToString();
                        var HReadyTimes = list[i]["开工余量"].ToString();
                        var HLastBeginDate = list[i]["最迟开工日期"].ToString();
                        var HLastEndDate = list[i]["最迟完工日期"].ToString();
                        var HOrderNeedQty = list[i]["订单需求数量"].ToString();
                        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();
                        if (HSourceID == "" || HSourceID == "0")
                        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 (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))
                        {
@@ -260,25 +355,166 @@
                            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 == "添康科技") //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称     ç©ºç™½ä¸ºé€šç”¨
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = $"第{i + 1}行生产资源有重复,请修改!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //看有几台生产资源协同生产
                            string[] HSourceNameArr = HSourceName.Split(new char[]{'&'});
                        oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID == "" ? 0.ToString() : HSourceID)},HYX={HYX} 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);//获得一个新的id
                                        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++)
                    {
                        //主表子表都有数据
@@ -289,32 +525,43 @@
                            objJsonResult = AddBillSub(HInterID == 0 ? list[i]["hmainid"].ToString() : HInterID.ToString()
                                , HBillNo == "" ? list[i]["单据号"].ToString() : HBillNo
                                 , DateTime.Parse(DateTime.Now.AddDays(j).ToString("yyyy-MM-dd").ToString())
                                 , int.Parse(list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString()));
                                 , Math.Round(double.Parse(list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString()),1)
                                 , list[i]);
                            if (objJsonResult.count == 1)
                            {
                                TrueCount += 1;
                            }
                        }
                        //主表有数据 å­è¡¨æ— æ•°æ®
                        if (j == 30 && SumCount == 0 && HInterID != 0 && HBillNo != "")
                        if (j == SumDay-1 && SumCount == 0 && HInterID != 0 && HBillNo != "")
                        {
                            objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0);
                            //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]);
                        }
                    }
                    LogService.CustomWriteLog("2.4:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                    if (TrueCount != SumCount)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (TrueCount != SumCount)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                LogService.CustomWriteLog("2.5:", DateTime.Now.ToString("yyyy-MM-dd"));
                //同步日计划工单
                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;
@@ -332,11 +579,10 @@
            }
        }
        public json AddBillSub(string HInterID, string HBillNo, DateTime date, int HQTY)
        {
        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)
            {
@@ -345,20 +591,29 @@
                {
                    if (DateTime.Parse(ds.Tables[0].Rows[i]["日计划生产日期"].ToString()) == date)
                    {
                        oCN.RunProc($"update Sc_WorkBillSortBillSub set HMasterDate='{date}',HQty={HQTY}" +
                        oCN.RunProc($"update Sc_WorkBillSortBillSub set HMasterDate='{date}',HQty={HQTY},HUseTimes={(dic["小时产能"]=="0"?0: HQTY / float.Parse(dic["小时产能"].ToString()))}" +
                            $"  where HInterID={HInterID} and HEntryID={ds.Tables[0].Rows[i]["hsubid"].ToString()}");
                        count += 1;
                    }
                }
            }
            if (count != 1)
            {
                //插入子表
                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HSEQ," +
                    "HMasterDate,HQty)" +
                    "HMasterDate,HQty,HUseTimes)" +
                            $"values({HInterID}, {(ds.Tables[0].Rows.Count + 1)}," +
                            $" '{date}', {HQTY})");
                            $" '{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";
@@ -716,9 +971,22 @@
                omdelMian = JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(sWhere);
                string sql = $"exec JIT_qtfx {omdelMian.HProdORGID},{omdelMian.HWorkShopID},'{user}' ";
                ds = oCN.RunProcReturn(sql, "JIT_qtfx");
                LogService.Write("齐套分析sql:" + sql);
                //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("失败"))
                {
                    //释放齐套操作 é¿å…å¤šäººåŒæ—¶è¿›è¡Œé½å¥—分析
@@ -755,14 +1023,15 @@
                    fDayPlanFids = string.Join(",", fidList);
                    fDayPlanFEntryids = string.Join(",", fentryidList);
                }
                LogService.Write("日计划工单ids" + fDayPlanFids);
                //LogService.Write("日计划工单ids" + fDayPlanFids);
                sw.Start();//开始计时
                //获取当前即时库存 åº“存数量+库存组织+物料+货主+仓库   
                //原查询即时库存方式:select * from h_v_jit_InventoryList
                ds = oCN.RunProcReturn(@" 
select * from h_v_jit_InventoryList
", "h_v_jit_InventoryList");
exec h_p_jit_Inventory_UsableList
", "h_p_jit_Inventory_UsableList");
                ListInventory = ds.ToModelList<PRD_Inventory>();
                //车间 ä»“库对照列表 
                ds = oCN.RunProcReturn(@" 
@@ -776,18 +1045,24 @@
                //取应发数量 FMustQty ä¸è¦å–值需求数量FNeedQty é¢†æ–™æ•°æ®
                string LLsql = string.Format(@"exec h_p_jit_PPBOMList '{0}'", fDayPlanFids);
                List<DayPlanPickedModel> DayPlanPickedModel = new List<DayPlanPickedModel>();
                //LogService.Write("LLsql:" + LLsql);
                ds = oCN.RunProcReturn(LLsql, "SC_WORKBILLSORTBILLMAIN");
                //LogService.Write(JsonConvert.SerializeObject(ds));
                DayPlanPickedModel = ds.ToModelList<DayPlanPickedModel>();
                //LogService.Write(JsonConvert.SerializeObject(DayPlanPickedModel));
                //CompleteAnalysisTempModel ç”¨äºŽå­˜å‚¨ä¸´æ—¶éœ€è¦æ’入数据
                List<CompleteAnalysisTempModel> completeAnalysisTempModel = new List<CompleteAnalysisTempModel>();
                //创建字典 ç”¨äºŽå‚¨å­˜ç‰©æ–™ + å ç”¨æ•°é‡
                Dictionary<string, decimal> occupyDic = new Dictionary<string, decimal>();
                LogService.Write($"齐套分析,数据准备阶段,用时" + sw.Elapsed + "总行数:" + BomList.Count);
                LogService.Write($"齐套分析,数据准备阶段,用时" + sw.Elapsed + "总需要循环的bom数量:" + DatePlanList.Count);
                //LogService.Write($"齐套分析,数据准备阶段,用时" + sw.Elapsed + "总行数:" + BomList.Count);
                //LogService.Write($"齐套分析,数据准备阶段,用时" + sw.Elapsed + "总需要循环的bom数量:" + DatePlanList.Count);
                //第一个循环 æ—¥è®¡åˆ’工单明细 ä¸€å¤©+一个工单 ä¸€ä¸ªå¾ªçޝ
                int o = 0;
                foreach (var item in DatePlanList)
                {
                    o++;
                    //LogService.Write("循环:" + o);
                    //日计划用料清单明细 æ¯ä¸€å¤©çš„实际用料情况
                    var _BomList = BomList.Where(x => x.HMasterDate == item.HMasterDate && x.HICMOEntryID_Sec == item.HICMOEntryID_Sec).ToList();
                    //每一个物料进行库存计算
@@ -823,8 +1098,9 @@
                        decimal planNeed = _item.PlanCount; //不参与计算 ç”¨äºŽè®°å½•
                        decimal need = _item.PlanCount;//参与计算
                        decimal FOccupyPickedCount = 0;//占用领料单数量
                        //找到领用数量
                                                       //找到领用数量
                        var _DayPlanPickedModel = DayPlanPickedModel.Where(c => c.FPRDMOENTYID == _item.HICMOEntryID_Sec && c.FMATERIALID == _item.FMATERIALID2).FirstOrDefault();
                        if (_DayPlanPickedModel.FRemainPickedQty >= need)
                        {
                            //领料数量满足了当前这个需求量 ç›´æŽ¥é½å¥— ä¸éœ€è¦åŽ»å ç”¨ä»“åº“
@@ -855,19 +1131,24 @@
                            });
                            //扣除剩余可用领料数量
                            _DayPlanPickedModel.FRemainPickedQty -= need;
                            //LogService.Write($"h" + need);
                            //循环下一个物料
                            continue;
                        }
                        else
                        {
                            //LogService.Write($"kxs" + need);
                            need -= _DayPlanPickedModel.FRemainPickedQty; //剩余需求数量
                            //LogService.Write($"i1" + need);
                            FOccupyPickedCount = _DayPlanPickedModel.FRemainPickedQty;
                            _DayPlanPickedModel.FRemainPickedQty = 0;
                            //LogService.Write($"i" + need);
                        }
                        if (_pRD_WorkHouseCompar.Count > 0)
                        {
                            //缺料数量 éœ€æ±‚数量 - å®žé™…库存  >0 ? ä¸€ä¸ªç‰©æ–™ä¸ç®¡å ç”¨å¤šå°‘条 åº“å­˜+货主 æ•°æ® ç¼ºæ–™æ•°é‡æ˜¯åŒä¸€ä¸ªæ•°é‡
                            decimal _fLackCount = need > jskcQty ? (need - jskcQty) : 0;
                            //LogService.Write($"j" + _fLackCount);
                            //LogHelper.Info("组织:" + _item.FStockOrgId + " ,及时库存" + jskcQty);
                            //总库存为0了 ç›´æŽ¥ç»™å‡º ç¼ºæ–™æ•°é‡
                            if (jskcQty == 0)
@@ -900,6 +1181,8 @@
                                //终止该物料计算 è¿›å…¥ä¸‹ä¸€ä¸ª
                                continue;
                            }
                            //LogService.Write($"k" + 2);
                            foreach (var WorkHouse in _pRD_WorkHouseCompar)
                            {
                                //库存数据匹配
@@ -1000,7 +1283,7 @@
                    //Thread.Sleep(6000);
                    i++;
                }
                LogService.Write($"齐套分析,数据准备完成,保存到Model实体,总行数:{completeAnalysisTempModel.Count},耗时:" + sw.Elapsed);
                //LogService.Write($"齐套分析,数据准备完成,保存到Model实体,总行数:{completeAnalysisTempModel.Count},耗时:" + sw.Elapsed);
                List<string> sqlList = new List<string>();
                DataTable insertDT = new DataTable();
                insertDT.TableName = "JIT_MOMaterReadysBill";
@@ -1090,7 +1373,7 @@
                             $", {item["FCOMPLETECOUNT1"].ToString()}, {item["FERPCLSID"].ToString()}, {item["FWORKSHOPID"].ToString()}, {item["FSTOCKID"].ToString()}, {item["FOCCUPYPICKEDCOUNT"].ToString()}, '{item["HMainICMOBillNo"].ToString()}'" +
                             $",{item["HLOT"].ToString()},'{item["HInventoryFID"].ToString()}')");
                }
                LogService.Write("批量插入到数据库用时:" + sw.Elapsed);
                //LogService.Write("批量插入到数据库用时:" + sw.Elapsed);
                //执行完成后 æ›´æ–°æ—¥è®¡åˆ’工单状态
                string updatesql = string.Format(@"
update Sc_WorkBillSortBillSub set HComplete = '未齐套' where HEntryID IN 
@@ -1109,7 +1392,7 @@
                //释放齐套操作 é¿å…å¤šäººåŒæ—¶è¿›è¡Œé½å¥—分析
                oCN.RunProc($"update T_PRD_QTFX set FSTATUS = 0 where FPRDORGID ={omdelMian.HProdORGID} and FSTATUS = 1 ");
                sw.Stop();//结束计时
                LogService.Write("齐套分析运行总时长:" + sw.Elapsed);
                //LogService.Write("齐套分析运行总时长:" + sw.Elapsed);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -1500,11 +1783,24 @@
                    {
                        sqlName = "AIS20230129011339";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "凯贝奈特")
                    {
                        sqlName = "AIS20210820164804";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "添康科技")
                    {
                        sqlName = "AIS20240809105013";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "宝工")
                    {
                        sqlName = "AIS20250102123554";
                    }
                    else
                    {
                        sqlName = "AIS20210811135644";
                    }
                }
                if (HTLType == "缺料")
                {
@@ -1574,7 +1870,9 @@
                List<PODemandPlanTemp> PODemandPlanTemp = new List<PODemandPlanTemp>();
                //sql集合 æ›´æ–°é‡‡è´­è®¢å•占用的提料计划数量
                List<string> sqlList = new List<string>();
                string Error = "运算失败!";
                //LogService.Write("1");
                string Error = "";
                foreach (var item in MaterialIDList)
                {
                    //当前物料没有采购订单时 ç›´æŽ¥è·³å‡º
@@ -1584,6 +1882,9 @@
                        Error+="[提料计划开始]当前物料无采购信息:" + item.FNumber + " åº“存组织:" + item.FStockOrgName + "      ";
                        continue;
                    }
                    //LogService.Write("1.1");
                    ////LogHelper.Info(item.FMATERIALID.ToString());
                    //当前物料和库存组织对应的需进行提料计划的数据    
                    List<DayPlanPpbom> _DayPlanPpbom = DayPlanPpbom.Where(x => x.FMATERIALID == item.FMATERIALID && x.FStockOrgId == item.FStockOrgId).ToList();
@@ -1597,6 +1898,9 @@
                    DateTime DATE = _DayPlanPpbom.FirstOrDefault().FHMASTERDATE;//第一个订货起始日期
                    int i = 0;
                    //记录在最小采购量需求下的日计划明细FentyrID
                    //LogService.Write("1.2");
                    List<int> FEntryIdList = new List<int>();
                    foreach (var _item in _DayPlanPpbom)
                    {
@@ -1607,13 +1911,25 @@
                            break;
                        }
                        //LogService.Write("1.2.1");
                        if (NeedQty == 0)
                        {
                            DATE = Convert.ToDateTime(_item.FHMASTERDATE).AddDays(-FFIXLEADTIME);
                        }
                        FEntryIdList.Add(_item.FENTRYID);
                        NeedQty += _item.NeedQty;
                        if ((FJITmaterialGroup == "总量控制规格类" || FJITmaterialGroup == "订单专用个性类") && FEntryIdList.Count < Convert.ToInt32(FJITMaterielDemand) && i < _DayPlanPpbom.Count) //订单专用个性类
                        //LogService.Write(FJITmaterialGroup);
                        //LogService.Write(FEntryIdList.Count);
                        //LogService.Write(Convert.ToDouble(FJITMaterielDemand));
                        //LogService.Write(_DayPlanPpbom.Count);
                        //LogService.Write(i);
                        if ((FJITmaterialGroup == "总量控制规格类" || FJITmaterialGroup == "订单专用个性类") && FEntryIdList.Count < Convert.ToDouble(FJITMaterielDemand) && i < _DayPlanPpbom.Count) //订单专用个性类
                        {
                            continue;
                        }
                        //LogService.Write("1.2.2");
                        foreach (var Purchase in _PurchaseInventory)
                        {
@@ -1652,11 +1968,15 @@
                                        F_QIMB_NOTE = Purchase.F_QIMB_NOTE,
                                        FNOTE = Purchase.FNOTE,
                                        FPURCHASEQTY = Purchase.FPURCHASEQTY,
                                        FJOINQTY = Purchase.FJOINQTY
                                        FJOINQTY = Purchase.FJOINQTY,
                                        FDAYPLANBILLNO = _item.FDAYPLANBILLNO
                                    });
                                    //扣除日计划明细已被分配的数量
                                    DayPlanPpbomls.NeedQty = 0;
                                }
                                //LogService.Write("1.2.3");
                                FEntryIdList.Clear();
                                //更新采购订单
                                //sqlList.Add($"/*dialect*/ update t_PUR_POOrderEntry set FPODemandPlanCount  =isnull(FPODemandPlanCount,0)+  '{NeedQty}' where FENTRYID = {Purchase.FENTRYID}");
@@ -1712,7 +2032,8 @@
                                        F_QIMB_NOTE = Purchase.F_QIMB_NOTE,
                                        FNOTE = Purchase.FNOTE,
                                        FPURCHASEQTY = Purchase.FPURCHASEQTY,
                                        FJOINQTY = Purchase.FJOINQTY
                                        FJOINQTY = Purchase.FJOINQTY,
                                        FDAYPLANBILLNO = _item.FDAYPLANBILLNO
                                    });
                                    //更新计划数量(剩余需要排的) ç»§ç»­åŽ»è®¡ç®—ä¸‹ä¸€ä¸ªé‡‡è´­è®¢å•
                                    DayPlanPpbomls.NeedQty -= Qty;
@@ -1733,17 +2054,22 @@
                                }
                            }
                        }
                        //LogService.Write("1.2.4");
                        NeedQty = 0;
                    }
                }
                //var PODemandPlanList222 = PODemandPlanTemp.GroupBy(p => new PODemandPlanTemp { PurchseFNUMBER = p.PurchseFNUMBER, FHMASTERDATE = p.FHMASTERDATE }).Select(x => new PODemandPlanTemp { PurchseFNUMBER = x.Key.PurchseFNUMBER, FHMASTERDATE = x.Key.FHMASTERDATE }).ToList();
                var PODemandPlanList = PODemandPlanTemp.GroupBy(p => new { p.PurchseFNUMBER, p.FHMASTERDATE }).Select(x => new PODemandPlanTemp { PurchseFNUMBER = x.Key.PurchseFNUMBER, FHMASTERDATE = x.Key.FHMASTERDATE }).ToList();
                //LogHelper.Info($"提料计划,数据准备完成,保存到Model实体,总行数:{PODemandPlanTemp.Count}");
                int tlmmm = 0;
                JArray FinalyResult = new JArray();
                //LogService.Write("2");
                foreach (var item in PODemandPlanList)
                {
                    tlmmm++;
@@ -1915,12 +2241,22 @@
                    //    tlmmm++;
                }
                if (tlmmm == PODemandPlanList.Count && tlmmm != 0)
                //LogService.Write("3");
                if (Error != "")
                {
                    oCN.Commit();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "运算成功!" + Error;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (tlmmm == PODemandPlanList.Count && tlmmm != 0)
                {
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "运算成功!";
                    objJsonResult.Message = "运算成功!" + Error;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
@@ -1929,7 +2265,7 @@
                    oCN.RollBack();//事务回滚
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = Error;
                    objJsonResult.Message = "运算失败!" + Error;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
@@ -1938,11 +2274,11 @@
                //////LogHelper.Info("提料计划执行完成,运行总时长:" + sw.Elapsed);
                //DBServiceHelper.ExecuteBatch(Context, sqlList);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "提料运算成功!";
                objJsonResult.data = null;
                return objJsonResult;
                //objJsonResult.code = "1";
                //objJsonResult.count = 1;
                //objJsonResult.Message = "提料运算成功!";
                //objJsonResult.data = null;
                //return objJsonResult;
            }
            catch (Exception e)
            {
@@ -2457,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 ç”Ÿäº§æ—¥è®¡åˆ’平台 è§£é”å·¥å•
        [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]
@@ -2478,7 +2866,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "生产明细行重复,重复的生产订单号:" + ds.Tables[0].Rows[i]["生产订单号"].ToString() + ",明细行号:" + ds.Tables[0].Rows[i]["生产订单明细行号"].ToString();
                        objJsonResult.Message = "生产明细行重复,重复的生产订单号:" + dt.Tables[0].Rows[i]["生产订单号"].ToString() + ",明细行号:" + dt.Tables[0].Rows[i]["生产订单明细行号"].ToString();
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -2534,5 +2922,405 @@
        }
        #endregion
        #region ç”Ÿäº§æ—¥è®¡åˆ’平台 æ•°æ®å‡†å¤‡ è®¾ç½®ä»»åŠ¡å•ç›¸å…³ä¿¡æ¯
        [Route("JIT_DayPlanPlatFormBill/ReadyData")]
        [HttpGet]
        public object ReadyData(string SWhere)
        {
            try
            {
                var list = SWhere.Split(',');
                DataTable dt = new DataTable("date");
                dt.Columns.Add("HICMOInterID", typeof(string));
                dt.Columns.Add("HICMOEntryID", typeof(string));
                dt.Columns.Add("小时产能", typeof(string));
                dt.Columns.Add("生产周期", typeof(decimal));
                dt.Columns.Add("开工余量", typeof(decimal));
                dt.Columns.Add("最迟开工日期", typeof(DateTime));
                dt.Columns.Add("最迟完工日期", typeof(DateTime));
                dt.Columns.Add("订单需求数量", typeof(decimal));
                dt.Columns.Add("订单交货期", typeof(DateTime));
                for (int i = 0; i < list.Length; i++)
                {
                    string HICMOInterID = list[i].Split(';')[0].ToString();
                    string HICMOEntryID = list[i].Split(';')[1].ToString();
                    string HSourceID = list[i].Split(';')[2].ToString();
                    Thread.Sleep(100);
                    ds = oCN.RunProcReturn("exec h_p_Sc_GetInfoByICMOBillNo " + HICMOInterID+","+ HICMOEntryID+","+ HSourceID, "h_p_Sc_GetInfoByICMOBillNo");
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                    }
                    else
                    {
                        DataRow dr = dt.NewRow();
                        dr["小时产能"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["产能"]);
                        dr["生产周期"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["生产周期"]);
                        dr["开工余量"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["开工余量"]);
                        dr["最迟开工日期"] = DBUtility.ClsPub.isDate(ds.Tables[0].Rows[0]["最迟开工日期"]);
                        dr["最迟完工日期"] = DBUtility.ClsPub.isDate(ds.Tables[0].Rows[0]["最迟完工日期"]);
                        dr["订单需求数量"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["订单需求数"]);
                        dr["订单交货期"] = DBUtility.ClsPub.isDate(ds.Tables[0].Rows[0]["订单交货期"]);
                        dr["HICMOInterID"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["HICMOInterID"]);
                        dr["HICMOEntryID"] = DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[0]["HICMOEntryID"]);
                        dt.Rows.Add(dr);
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = dt;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  ç¼ºæ–™åˆ†æžæŠ¥è¡¨
        public class MaterialShorAnalysis
        {
            public int? HORGID;
            public DateTime HBEGINDATE;
            public DateTime HENDDATE;
        }
        [Route("JIT_DayPlanPlatFormBill/MaterialShorAnalysisReport")]
        [HttpGet]
        public object MaterialShorAnalysisReport(string sWhere)
        {
            try
            {
                MaterialShorAnalysis Report = JsonConvert.DeserializeObject<MaterialShorAnalysis>(sWhere);
                ds = oCN.RunProcReturn($"exec h_p_JIT_MaterialShorAnalysisReportList {Report.HORGID},'{Report.HBEGINDATE}','{Report.HENDDATE}' ", "h_p_JIT_PODemandPlanBill_ReportList");
                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 æ ¹æ®ç‰©æ–™ID获取工艺路线 åˆ—表
        [Route("JIT_DayPlanPlatFormBill/GetRoutingListByMater")]
        [HttpGet]
        public object GetRoutingListByMater(int HMaterID, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                int IsHavingPermissions = 1;
                //判断是否有工艺路线编辑权限
                if (!DBUtility.ClsPub.Security_Log("Gy_RoutingBill_Edit", 1, false, user))
                {
                    IsHavingPermissions = 0;
                }
                ds = oCN.RunProcReturn("select * from  h_v_JIT_GetRoutingList_Mater where HMaterID = " + HMaterID , "h_v_JIT_GetRoutingList_Mater");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前物料没有维护工艺路线!请联系计划部进行维护";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.IsHavingPermissions = IsHavingPermissions;
                    return objJsonResult;
                }
                else
                {
                    //添加列名
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        Type dataType = col.DataType;
                        string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                        columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.list = columnNameList;
                    objJsonResult.IsHavingPermissions = IsHavingPermissions;
                    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_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 å­èµ„源ID,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
    }
}