From 9eb6dc41797cbace32a65877067a9c9ac3154f7a Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期日, 09 十月 2022 19:41:15 +0800
Subject: [PATCH] 安灯呼叫、安灯响应接口开发

---
 VueWebApi/DLL/DAL/ProductionManagementDAL.cs |  456 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 435 insertions(+), 21 deletions(-)

diff --git a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
index 1a51786..02f89de 100644
--- a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -145,13 +145,13 @@
                             parm = new
                             {
                                 wo_code = wo,
-                                wotype="PO",
+                                wotype = "PO",
                                 status = "NEW",
                                 wkshp_code = wkshopcode,
                                 plan_qty = cdqty + (decimal.Parse(markqty) - sumqty),  //鏈崟涓嬪崟鏁伴噺=鍒囧垎鏁伴噺+(涓嬪崟鏁伴噺-绱鍒囧垎涓嬪崟鏁伴噺)
                                 stck_code = warehousecode,
                                 materiel_code = partcode,
-                                sourceid=erporderid,
+                                sourceid = erporderid,
                                 m_po = erpordercode,
                                 username = username,
                                 CreateDate = DateTime.Now.ToString()
@@ -300,7 +300,7 @@
 
 
         #region[MES宸ュ崟鏌ヨ]
-        public static ToMessage MesOrderSearch(string mesorderstus, string mesordercode,string sourceorder,string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
+        public static ToMessage MesOrderSearch(string mesorderstus, string mesordercode, string sourceorder, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
         {
             var dynamicParams = new DynamicParameters();
             string search = "";
@@ -477,7 +477,7 @@
         #endregion
 
         #region[MES宸ュ崟鏂板銆佺紪杈戞彁浜
-        public static ToMessage AddUpdateMesOrder(string mesorderstus,string sourceorder,string ordertype, string mesordercode, string partcode, string mesqty, string routecode, string wkshopcode, string planstartdate, string planenddate, string orderlev, string username, string opertype)
+        public static ToMessage AddUpdateMesOrder(string mesorderstus, string sourceorder, string ordertype, string mesordercode, string partcode, string mesqty, string routecode, string wkshopcode, string planstartdate, string planenddate, string orderlev, string username, string opertype)
         {
             var sql = "";
             var dynamicParams = new DynamicParameters();
@@ -648,13 +648,13 @@
                         {
                             //鍥炲啓璁㈠崟琛ㄧ姸鎬佸強宸蹭笅鍗曟暟閲�
                             sql = @"update TKimp_Ewo set status='NEW',relse_qty=0  where wo=@m_po and id=@souceid";
-                            list.Add(new { str = sql, parm = new { m_po = m_po, souceid= souceid } });
+                            list.Add(new { str = sql, parm = new { m_po = m_po, souceid = souceid } });
                         }
                         else
                         {
                             //鍥炲啓璁㈠崟琛ㄧ姸鎬佸強宸蹭笅鍗曟暟閲�
                             sql = @"update TKimp_Ewo set status='CREATING',relse_qty=relse_qty-@orderqty  where wo=@m_po and id=@souceid";
-                            list.Add(new { str = sql, parm = new { m_po = m_po, souceid= souceid, orderqty = decimal.Parse(orderqty) } });
+                            list.Add(new { str = sql, parm = new { m_po = m_po, souceid = souceid, orderqty = decimal.Parse(orderqty) } });
                         }
                     }
                     //鍒犻櫎宸ュ崟宸ュ簭琛�
@@ -700,7 +700,7 @@
         #endregion
 
         #region[MES宸ュ崟鍏抽棴]
-        public static ToMessage ClosedMesOrder(string username,string wocode, string m_po)
+        public static ToMessage ClosedMesOrder(string username, string wocode, string m_po)
         {
             var sql = "";
             List<object> list = new List<object>();
@@ -712,7 +712,7 @@
                 list.Add(new { str = sql, parm = new { wocode = wocode } });
                 //鍥炲啓宸ュ崟琛ㄧ姸鎬佷负(鍏抽棴)
                 sql = @"update TK_Wrk_Man set status='CLOSED',closeuser=@username,closedate=@closedate  where wo_code=@wocode";
-                list.Add(new { str = sql, parm = new { wocode = wocode, username = username, closedate=DateTime.Now.ToString() } });
+                list.Add(new { str = sql, parm = new { wocode = wocode, username = username, closedate = DateTime.Now.ToString() } });
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
@@ -1146,7 +1146,7 @@
                     }
                     if (isend == "Y")  //褰撳墠宸ュ簭鏄湯閬撳伐搴�
                     {
-                        rt.nextstepcode ="";//璧嬬┖
+                        rt.nextstepcode = "";//璧嬬┖
                         rt.nextstepname = "";//璧嬬┖
                     }
                 }
@@ -1554,7 +1554,7 @@
         #endregion
 
         #region[鐢熶骇寮�鎶ュ伐,鎶ュ伐鎻愪氦]
-        public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string eqpcode, string usergroupcode, string reportuser, string taskqty, string startqty, string reportqty, string ngqty, string badcode,string remarks, string username)
+        public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string eqpcode, string usergroupcode, string reportuser, string taskqty, string startqty, string reportqty, string ngqty, string badcode, string remarks, string username)
         {
             var sql = "";
             string[] arra = new string[] { };
@@ -1618,7 +1618,7 @@
                         {
                             sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) 
                                 values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
-                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i],remarks=remarks,style = "B", lm_user = username, lm_date = date } });
+                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "B", lm_user = username, lm_date = date } });
 
                         }
                     }
@@ -1671,7 +1671,7 @@
                         {
                             sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) 
                                 values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
-                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks= remarks, style = "B", lm_user = username, lm_date = date } });
+                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "B", lm_user = username, lm_date = date } });
 
                         }
                     }
@@ -1791,7 +1791,7 @@
         #endregion
 
         #region[鐢熶骇寮�鎶ュ伐, 鏀舵枡鎻愪氦]
-        public static ToMessage SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string inuser, string taskqty, string sqty, string ngqty, string badcode,string remarks, string username)
+        public static ToMessage SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string inuser, string taskqty, string sqty, string ngqty, string badcode, string remarks, string username)
         {
             var sql = "";
             string[] arra1 = new string[] { };
@@ -1822,7 +1822,7 @@
                 dynamicParams.Add("@step_code", stepcode);
                 dynamicParams.Add("@wx_code", wxcode);
                 var da = DapperHelper.selectdata(sql, dynamicParams);
-                if (da.Rows.Count<=0) 
+                if (da.Rows.Count <= 0)
                 {
                     sql = @"select A.wx_code,B.name,A.fqty   from TK_Wrk_OutRecord A
                         inner join TCustomer B on A.wx_code=B.code
@@ -1834,7 +1834,7 @@
                     string wxstring = (string.Join(",", dr.Select(x => x.ToString()).ToArray()));
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟涓庡彂鏂欏鍗忎緵搴斿晢涓嶅尮閰�,搴斾负锛氥��"+wxstring+"銆�!";
+                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡澶栧崗渚涙柟涓庡彂鏂欏鍗忎緵搴斿晢涓嶅尮閰�,搴斾负锛氥��" + wxstring + "銆�!";
                     mes.data = null;
                     return mes;
                 }
@@ -1842,7 +1842,7 @@
                 {
                     mes.code = "300";
                     mes.count = 0;
-                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬鍙戞枡鏁伴噺:"+da.Rows[0]["FQTY"].ToString()+"!";
+                    mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬鍙戞枡鏁伴噺:" + da.Rows[0]["FQTY"].ToString() + "!";
                     mes.data = null;
                     return mes;
                 }
@@ -1862,7 +1862,7 @@
                     {
                         mes.code = "300";
                         mes.count = 0;
-                        mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬寰呮敹鏁伴噺:" + (sum_fqty- sum_sqty) + "!";
+                        mes.Message = "鎿嶄綔澶辫触,褰撳墠鏀舵枡鏁伴噺+涓嶈壇鏁伴噺,涓嶈兘澶т簬寰呮敹鏁伴噺:" + (sum_fqty - sum_sqty) + "!";
                         mes.data = null;
                         return mes;
                     }
@@ -1888,7 +1888,7 @@
                         {
                             sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) 
                                 values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
-                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks= remarks, style = "S", lm_user = username, lm_date = date } });
+                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "S", lm_user = username, lm_date = date } });
 
                         }
                     }
@@ -1937,7 +1937,7 @@
                         {
                             sql = @"insert into  CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) 
                                 values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)";
-                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks= remarks, style = "S", lm_user = username, lm_date = date } });
+                            list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "S", lm_user = username, lm_date = date } });
 
                         }
                     }
@@ -2272,7 +2272,7 @@
         #endregion
 
         #region[鐢熶骇寮�鎶ュ伐,宸ュ簭妫�楠屾彁浜や繚瀛榏
-        public static ToMessage SaveMesOrderStepCheckItem(string mesordercode, string partcode, string stepcode, string checkstanedcode, string checkusercode, string checktypecode, string checkresult, string checkdescr,string checkqty, string username, List<StepCheck> json)
+        public static ToMessage SaveMesOrderStepCheckItem(string mesordercode, string partcode, string stepcode, string checkstanedcode, string checkusercode, string checktypecode, string checkresult, string checkdescr, string checkqty, string username, List<StepCheck> json)
         {
             var sql = "";
             string[] arra = new string[] { };
@@ -2302,7 +2302,7 @@
                 //鍐欏叆宸ュ簭妫�楠岃褰曚富琛�
                 sql = @"insert into  TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,check_result,check_descr,check_qty,lm_user,lm_date) 
                                 values(@mesordercode,@partcode,@stepcode,@checkstanedcode,@checkusercode,@checktypecode,@checktypename,@checkresult,@checkdescr,@check_qty,@lm_user,@lm_date)";
-                list.Add(new { str = sql, parm = new { mesordercode = mesordercode, partcode = partcode, stepcode = stepcode, checkstanedcode = checkstanedcode, checkusercode = checkusercode, checktypecode = checktypecode, checktypename = checktypename, checkresult = checkresult, checkdescr = checkdescr, check_qty=checkqty, lm_user = username, lm_date = date } });
+                list.Add(new { str = sql, parm = new { mesordercode = mesordercode, partcode = partcode, stepcode = stepcode, checkstanedcode = checkstanedcode, checkusercode = checkusercode, checktypecode = checktypecode, checktypename = checktypename, checkresult = checkresult, checkdescr = checkdescr, check_qty = checkqty, lm_user = username, lm_date = date } });
                 //鍐欏叆宸ュ簭妫�楠岃褰曞瓙琛�
                 //鑾峰彇涓昏〃鏈�澶D
                 sql = @"select ISNULL(IDENT_CURRENT('TStepCheckRecord')+1,1) as id";
@@ -2519,5 +2519,419 @@
             return mes;
         }
         #endregion
+
+
+
+        #region[浜ц兘瑙勫垝鏌ヨ]
+        public static ToMessage CapacityPlanningSearch(string workshop, string devicetype, string stustype, int startNum, int endNum, string prop, string order)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (workshop != "" && workshop != null)
+                {
+                    search += "and A.wksp_code=@workshop ";
+                    dynamicParams.Add("@workshop", workshop);
+                }
+                if (devicetype != "" && devicetype != null)
+                {
+                    search += "and A.code=@devicetype ";
+                    dynamicParams.Add("@devicetype", devicetype);
+                }
+                if (stustype != "" && stustype != null)
+                {
+                    search += "and B.enable=@stustype ";
+                    dynamicParams.Add("@stustype", stustype);
+                }
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                // --------------鏌ヨ鎸囧畾鏁版嵁--------------
+                var total = 0; //鎬绘潯鏁�
+                var sql = @"select 
+                            B.id             CaptPlanId, 
+                            A.wksp_code      CaptPlanWorkShopid,
+                            C.org_name       CaptPlanWorkShop,
+                            A.code           CaptPlanDeviceTypeid,
+                            A.name           CaptPlanDeviceType,
+                            A.ClassType      CaptPlanType,
+                            E.aa             CaptPlanShopCalendar,
+                            E.RR             CaptPlanShopMaxDate,
+                            E.TT             CaptPlanShopCalendarList,
+                            B.wkshift_code   CaptPlanWorkShiftCode,
+                            D.name           CaptPlanWorkShift,
+                            D.duration       CaptPlanDuration, 
+                            B.lm_date        CaptPlanDate,
+                            B.ENABLE         CaptPlanStus,                     
+                            G.username       CaptPlanUser
+                            FROM( 
+                            select distinct B.wksp_code,A.code,A.name,'D' ClassType   from TEqpType A
+                            left join TEqpInfo B on A.code=B.eqptype_code
+                            left join TFlw_Rteqp C on B.code=C.eqp_code
+                            left join TFlw_Rtdt  D on C.step_code=D.step_code
+                            where D.first_choke='Y'  --order by A.code
+                            )A
+                            left join TOrganization C on A.wksp_code=C.org_code
+                            left join TWkm_capac_plan B ON A.wksp_code=B.wkshop and A.code=B.eqp_typecode 
+                            left join TBas_wkshift_info D on B.wkshift_code=D.code
+                            left join TUser  G   on B.lm_user=G.usercode
+                            left join (
+                               select m_id, 
+                               min(CONVERT(varchar(100), wkdate, 23))+'~'+max(CONVERT(varchar(100), wkdate, 23)) aa,
+                               max(CONVERT(varchar(100), wkdate, 23))RR,
+                               STUFF((
+                                    SELECT ',' + CONVERT(varchar(100),t1.wkdate, 23)
+                                      FROM TWkm_capac_plan_sub t1
+                                      WHERE t1.m_id = t0.m_id
+                                      ORDER BY t1.m_id
+                                      FOR XML PATH('')), 1, LEN(','), '') AS TT
+                                      FROM TWkm_capac_plan_sub t0 where CONVERT(varchar(100), wkdate, 23)>=CONVERT(varchar(100),getdate(), 23) 
+                                      GROUP BY t0.m_id  
+                             ) E on B.id=E.m_id
+                            where C.description='W' ";
+                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
+                mes.code = "200";
+                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.count = total;
+                mes.data = data.ToList();
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[浜ц兘瑙勫垝榛樿鏂规淇濆瓨鎻愪氦]
+        public static ToMessage CapacityPlanSubmit(string type, string captplanid, string wkshopcode, string capunitcode, string capsetupcode, string captplantype, string username)
+        {
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                if (type == "Add")
+                {
+                    var sql = @"insert into TWkm_capac_plan(wkshop, eqp_typecode, wkshift_code, enable, lm_user, lm_time,classtype) 
+                            values(@wkshop,@eqp_typecode,@wkshift_code,@enable,@lm_user,@lm_time,@classtype)";
+                    dynamicParams.Add("@wkshop", wkshopcode);
+                    dynamicParams.Add("@eqp_typecode", capunitcode);
+                    dynamicParams.Add("@wkshift_code", capsetupcode);
+                    dynamicParams.Add("@enable", "Y");
+                    dynamicParams.Add("@lm_user", username);
+                    dynamicParams.Add("@lm_time", DateTime.Now.ToString());
+                    dynamicParams.Add("@classtype", captplantype);
+                    int cont = DapperHelper.SQL(sql, dynamicParams);
+                    if (cont > 0)
+                    {
+                        mes.code = "200";
+                        mes.count = 0;
+                        mes.Message = "鏂板鎿嶄綔鎴愬姛!";
+                        mes.data = null;
+                    }
+                    else
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "鏂板鎿嶄綔澶辫触!";
+                        mes.data = null;
+                    }
+                }
+                if (type == "Update")
+                {
+                    var sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,lm_user=@username,lm_date=@CreateDate where id=@captplanid";
+                    dynamicParams.Add("@captplanid", captplanid);
+                    dynamicParams.Add("@wkshift_code", capsetupcode);
+                    dynamicParams.Add("@username", username);
+                    dynamicParams.Add("@CreateDate", DateTime.Now.ToString());
+                    int cont = DapperHelper.SQL(sql, dynamicParams);
+                    if (cont > 0)
+                    {
+                        mes.code = "200";
+                        mes.count = 0;
+                        mes.Message = "淇敼鎿嶄綔鎴愬姛!";
+                        mes.data = null;
+                    }
+                    else
+                    {
+                        mes.code = "300";
+                        mes.count = 0;
+                        mes.Message = "淇敼鎿嶄綔澶辫触!";
+                        mes.data = null;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[浜ц兘瑙勫垝鐐瑰嚮鏃ュ巻缁勪欢鏌ユ壘宸插叧鑱旂殑鏃ユ湡鏂规]
+        public static ToMessage CapacityPlanningCalendar(string captplanid)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            List<CapaPlan> list = new List<CapaPlan>();
+            try
+            {
+                sql = @"select CONVERT(varchar(100), wkdate, 23) DataTime,wkshift_code   from TWkm_capac_plan_sub where m_id=@captplanid";
+                dynamicParams.Add("@captplanid", captplanid);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    string DataTime = dt.Rows[i]["DataTime"].ToString();//鏃ユ湡
+                    string key = dt.Rows[i]["wkshift_code"].ToString(); //鏂规缂栫爜
+                    CapaPlan cmp = new CapaPlan();
+                    cmp.name = DataTime;
+                    cmp.key = key;
+                    list.Add(cmp);
+                }
+                mes.code = "200";
+                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.data = list;
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[浜ц兘瑙勫垝鏃ュ巻鍙屽嚮鏃跺甫鍑哄搴旂殑鏂规]
+        public static ToMessage CapacityPlanningOnclickSelect(string captplanid, string datetime)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            List<CapacityPlanSect> list = new List<CapacityPlanSect>();
+            try
+            {
+                sql = @"select distinct AA.code,AA.name,(case  when AA.Stus is null then 'N' else 'Y' end) flag
+                        from
+                        (
+                        select A.code,A.name,B.wkshift_code Stus  from TBas_wkshift_info A
+                        left join TWkm_capac_plan_sub B on A.code= B.wkshift_code and B.m_id=@captplanid and CONVERT(varchar(100), wkdate, 23)=@datetime
+                        ) AA  order by code";
+                dynamicParams.Add("@captplanid", captplanid);
+                dynamicParams.Add("@datetime", datetime);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    string code = dt.Rows[i]["code"].ToString();//鏂规缂栫爜
+                    string name = dt.Rows[i]["name"].ToString();//鏂规鍚嶇О
+                    string flag = dt.Rows[i]["flag"].ToString();   //閫変腑鏂规鏍囪瘑
+                    CapacityPlanSect cmp = new CapacityPlanSect();
+                    cmp.CapCode = code;
+                    cmp.CapName = name;
+                    cmp.CapStus = flag;
+                    cmp.list = new List<object>();
+
+                    string sql1 = @"select wktme1_start,wktme2_start,wktme3_start,wktme4_start,wktme5_start  from TBas_wkshift_info where code=@code";
+                    dynamicParams.Add("@code", code);
+                    var db = DapperHelper.selectdata(sql, dynamicParams);
+
+                    for (int j = 0; j < db.Columns.Count; j++) //鏃堕棿娈�
+                    {
+                        if (db.Rows[0][j].ToString().Trim() != null && db.Rows[0][j].ToString().Trim() != "")
+                        {
+                            cmp.list.Add(db.Rows[0][j].ToString());
+                        }
+                    }
+                    list.Add(cmp);
+                }
+                mes.code = "200";
+                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.data = list;
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[浜ц兘瑙勫垝宸ヤ綔鏃ュ巻閫夋嫨鎻愪氦]
+        public static ToMessage CapacityPlanningGivePlanSubmit(string captplanid, string wkshopcode, string capunitcode, string capsetupcode, string captplantype, List<CapaPlan> objs, string type, string username)
+        {
+            string sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                list.Clear();
+                if (capsetupcode == "" || capsetupcode == null)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "榛樿鏂规閫夋嫨涓嶈兘涓虹┖!";
+                    mes.data = null;
+                    return mes;
+                }
+                if (objs.Count <= 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "宸ヤ綔鏃ュ巻閫夋嫨涓嶈兘涓虹┖!";
+                    mes.data = null;
+                    return mes;
+                }
+                if (type == "Add")
+                {
+                    for (int i = 0; i < objs.Count; i++)
+                    {
+                        sql = @"insert into TWkm_capac_plan_sub(m_id, wkdate,wkshift_code) 
+                                     values(@m_id,@wkdate,@wkshift_code)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                m_id = captplanid,
+                                wkdate = objs[i].name,
+                                wkshift_code = objs[i].key
+                            }
+                        });
+                    }
+                    bool aa = DapperHelper.DoTransaction(list);
+                    if (aa)
+                    {
+                        mes.code = "200";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔鎴愬姛!";
+                        mes.data = null;
+                    }
+                    else
+                    {
+                        mes.code = "200";
+                        mes.count = 0;
+                        mes.Message = "鎿嶄綔澶辫触!";
+                        mes.data = null;
+                    }
+
+                }
+                if (type == "Update")
+                {
+                    //瀹氫箟涓や釜鏁扮粍鐢ㄦ潵瀵规瘮淇敼鍓嶅悗鏃ユ湡鍙婃柟妗堢殑鍙樺寲
+                    List<CapaPlan> ids = new List<CapaPlan>();
+                    List<CapaPlan> ids1 = new List<CapaPlan>();
+                    for (int i = 0; i < objs.Count; i++)
+                    {
+                        ids.Add(objs[i]);
+                    }
+
+                    //鏍规嵁id鏌ユ壘鏃ュ巻鏃堕棿
+                    string sql2 = @"select CONVERT(varchar(100), wkdate, 23) wkdate,wkshift_code  from TWkm_capac_plan_sub where m_id=@m_id";
+                    dynamicParams.Add("@m_id", captplanid);
+                    var dt2 = DapperHelper.selectdata(sql2, dynamicParams);
+                    if (dt2.Rows.Count > 0)
+                    {
+                        for (int k = 0; k < dt2.Rows.Count; k++)
+                        {
+                            CapaPlan ids2 = new CapaPlan();
+                            ids2.name = dt2.Rows[k]["wkdate"].ToString();
+                            ids2.key = dt2.Rows[k]["wkshift_code"].ToString();
+                            ids1.Add(ids2);
+                        }
+                    }
+
+                    List<CapaPlan> list3 = ids.Except(ids1).ToList(); //琛ㄧずids涓摢浜涘�兼槸ids1涓墍涓嶅瓨鍦ㄧ殑;
+                    List<CapaPlan> list4 = ids1.Except(ids).ToList(); //琛ㄧずids1涓摢浜涘�兼槸ids涓墍涓嶅瓨鍦ㄧ殑;
+                    list4 = list3.Union(list4).ToList();
+                    //鏌ユ壘鍏抽敭宸ュ簭璁惧銆佸伐浣嶇兢缁勭殑鎵�鏈夎澶�
+                    string sql3 = @"select *  from(
+                                  select distinct A.code,A.name  from TEqpInfo A 
+                                  left join TFlw_Rteqp B on A.code=B.eqp_code
+                                  left join TFlw_Rtdt D on B.step_code=D.step_code                 
+                                  where A.wksp_code=@wkshopcode  and D.first_choke='Y'  order by A.code)";
+                    dynamicParams.Add("@wkshopcode", wkshopcode);
+                    var dt3 = DapperHelper.selectdata(sql3, dynamicParams);
+                    if (list4.Count > 0)  //濡傛灉鏃ユ湡鏈夊彉鍔�
+                    {
+                        if (dt3.Rows.Count > 0)
+                        {
+                            for (int m = 0; m < list4.Count; m++)
+                            {
+                                for (int n = 0; n < dt3.Rows.Count; n++)
+                                {
+                                    string sql4 = @"select  A.wo_code,A.eqp_code,A.Time_Start,A.time_end, 
+                                                 (case  B.Status when 'SCHED' then '宸叉帓绋�' when 'ALLOC' then '宸叉淳鍙�' when 'START' then '宸插紑宸�' end ) status   
+                                                  from TK_Wrk_EqpAps  A
+                                                  left join mes_tk_wrk_man B on A.wo_code=B.Wo_Code
+                                                  left join gn_eqp_eqpinfo C on A.eqp_code=C.code
+                                                  where TO_char(time_start,'YYYY-MM-DD')='" + list4[m].name + "' and A.eqp_code='" + dt3.Rows[n]["CODE"] + "' and B.isaps='Y' and B.status IN('SCHED','ALLOC','START')";
+                                    DataTable dt4 = DBHelper.GetTable(sql4);
+                                    if (dt4.Rows.Count > 0)
+                                    {
+                                        for (int g = 0; g < dt4.Rows.Count; g++)
+                                        {
+                                            json = new DWZJson()
+                                            {
+                                                statusCode = "300",
+                                                message = "淇敼澶辫触锛�,鏃ユ湡锛�" + dt4.Rows[g]["TIME_START"] + "鏈夈��" + dt4.Rows[g]["STATUS"] + "銆戝伐鍗曪細" + dt4.Rows[g]["WO_CODE"] + "",
+                                            };
+                                            return json;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+
+                    list.Add(@"update gn_wkm_capac_plan set wkshift_code='" + CapSetupCode + "',classtype='" + CaptPlanType + "', enable='Y',lm_user='" + lm_user + "',lm_time=sysdate  where id='" + CaptPlanId + "'");
+                    list.Add(@"delete gn_wkm_capac_plan_sub where m_id='" + CaptPlanId + "'");
+                    for (int i = 0; i < objs.Count; i++)
+                    {
+                        list.Add(@"insert into gn_wkm_capac_plan_sub(m_id, id, wkdate,wkshift_code) 
+                                     values('" + CaptPlanId + "',gn_wkm_capac_plan_sub_S.nextVal,to_date('" + objs[i].name + "','yyyy-MM-dd'),'" + objs[i].key + "')");
+                    }
+                    int count = DBHelper.Executesqltran(list, pt.ToArray());
+                    if (count > 0)
+                    {
+                        json = new DWZJson()
+                        {
+                            statusCode = "200",
+                            message = "淇敼鎴愬姛锛�",
+                        };
+                    }
+                    else
+                    {
+                        json = new DWZJson()
+                        {
+                            statusCode = "300",
+                            message = "淇敼澶辫触锛�",
+                        };
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+
+                json = new DWZJson()
+                {
+                    statusCode = "300",
+                    message = e.Message,
+                };
+            }
+            return mes;
+        }
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3