1
duhe
2025-03-03 773e65fc78cd6300aaa706efdcb5756db9ad59a4
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/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";
@@ -198,9 +201,8 @@
                string sReturn = "";
                oSystemParameter.ShowBill(ref sReturn);
                for (int i = 0; i < list.Count; i++)
                {
                {
                    TrueCount = 0;
                    SumCount = 0;
                    long HInterID = 0;
@@ -248,10 +250,10 @@
                                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";
@@ -331,7 +333,7 @@
                            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 > 1)
@@ -355,7 +357,25 @@
                    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++)
@@ -376,7 +396,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]);
@@ -393,6 +413,8 @@
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                LogService.CustomWriteLog("2.5:", DateTime.Now.ToString("yyyy-MM-dd"));
@@ -401,6 +423,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;
@@ -421,7 +445,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)
            {
@@ -444,6 +468,15 @@
                    "HMasterDate,HQty,HUseTimes)" +
                            $"values({HInterID}, {(ds.Tables[0].Rows.Count + 1)}," +
                            $" '{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";
@@ -1621,11 +1654,16 @@
                    {
                        sqlName = "AIS20240809105013";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "宝工")
                    {
                        sqlName = "AIS20250102123554";
                    }
                    else
                    {
                        sqlName = "AIS20210811135644";
                    }
                }
                if (HTLType == "缺料")
                {
@@ -2618,6 +2656,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]
@@ -2858,16 +2948,31 @@
        {
            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)
                {
                    //数据表格添加动态日期
                    for (int j = 1; j <= 31; j++)
                    if (oSystemParameter.omodel.WMS_CampanyName == "添康科技") //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称     ç©ºç™½ä¸ºé€šç”¨
                    {
                        ds.Tables[0].Columns.Add(DateTime.Now.AddDays(j - 1).ToString("yyyy-MM-dd"), typeof(Int32));
                        //数据表格添加动态日期
                        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;
@@ -2895,5 +3000,138 @@
            }
        }
        #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)
        {
            try
            {
                ds = oCN.RunProcReturn("exec h_p_Gy_MaterialMouldByMater " + HMaterID + "," + HSourceID, "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 HMouldPCTime)
        {
            try
            {
                ds = oCN.RunProcReturn("exec h_p_JIT_AddMouldOccupancyTime " + HMouldID + "," + HSourceID + "," + HICMOInterID + "," + HICMOEntryID + ",'" + HMouldPCTime + "'", "h_p_JIT_AddMouldOccupancyTime");
                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
    }
}