From f0bf62f51e6ce2f27c870c240bf0884d83d92dd4 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期日, 16 十月 2022 01:34:49 +0800
Subject: [PATCH] 产能规划提交报错

---
 VueWebApi/DLL/DAL/ProductionManagementDAL.cs |  258 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 233 insertions(+), 25 deletions(-)

diff --git a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
index d0eb571..75913d9 100644
--- a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -477,15 +477,62 @@
         #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,string is_aps)
+        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, string is_aps, string bom_id)
         {
-            var sql = "";
+            string sql = "", wo_status = "", wrk_status = "";
             var dynamicParams = new DynamicParameters();
             List<object> list = new List<object>();
             try
             {
+                //鑾峰彇宸ヨ壓璺嚎棣栭亾宸ュ簭ID
+                sql = @"select distinct B.id  from TFlw_Rout  A
+                                 left join TFlw_Rtdt B on A.code=B.rout_code and b.first_choke='Y'
+                                 where A.code=@routecode";
+                dynamicParams.Add("@routecode", routecode);
+                var dtck = DapperHelper.selectdata(sql, dynamicParams);
+                if (dtck.Rows.Count <= 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "宸ュ崟瀵瑰簲宸ヨ壓璺嚎娌℃湁缁戝畾宸ュ簭!";
+                    mes.data = null;
+                    return mes;
+                }
+
                 if (opertype == "Add")
                 {
+                    if (is_aps == "Y")  //鏄惁鎺掔▼(鏄�)
+                    {
+                        //鍒ゆ柇鐗╂枡娓呭崟
+                        sql = "select id from TBom_Main  where materiel_code=@partcode and status='Y' and id=@bom_id";
+                        dynamicParams.Add("@partcode", partcode);
+                        dynamicParams.Add("@bom_id", bom_id);
+                        var data = DapperHelper.selectdata(sql, dynamicParams);
+                        if (data.Rows.Count <= 0)
+                        {
+                            mes.code = "300";
+                            mes.count = 0;
+                            mes.Message = "宸ュ崟瀵瑰簲鐨勪骇鍝佹病鏈夊缓绔婤OM鎴朆OM鏈鏍革紒";
+                            mes.data = null;
+                            return mes;
+                        }
+                        //澧炲姞宸ュ崟鐢ㄦ枡琛紙瀛愪欢锛�
+                        sql = @"insert into TK_Wrk_Allo(wo_code, seq, materiel_code, basqty, qty,bom_id,materieltype,stck_code,stopfeed,base_quantity,loss_quantity,m_quantity)
+                                select @wocode,A.seq,A.smateriel_code,A.total_quantity,(convert(decimal(18, 0), @uomqty)*A.Base_Quantity*(1+A.LOSS_QUANTITY/100))/C.quantity,
+                                A.m_id,A.pn_type,'','N',A.base_quantity,A.loss_quantity,C.quantity  
+                                from TBom_Deta A  left join  TBom_Main C on A.m_Id=C.id 
+                                left join TMateriel_Info B on A.smateriel_code = B.partcode
+                                where A.m_id=@bom_id";
+                        list.Add(new { str = sql, parm = new { wocode = mesordercode, uomqty = mesqty, bom_id = bom_id } });
+
+                        wo_status = "NEW";
+                        wrk_status = "NEW";
+                    }
+                    else //鍚�
+                    {
+                        wo_status = "ALLO";
+                        wrk_status = "ALLO";
+                    }
                     //鍐欏叆宸ュ崟琛�
                     sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,plan_startdate,plan_enddate,route_code,stck_code,lm_user,lm_date,materiel_code,m_po,piroque)
                                 values(@mesordercode,@wotype,@mesorderstus,@wkshopcode,@mesqty,@planstartdate,@planenddate,@routecode,@stck_code,@username,@CreateDate,@materiel_code,@m_po,@orderlev)";
@@ -497,7 +544,7 @@
                             mesordercode = mesordercode,
                             wotype = ordertype,
                             m_po = sourceorder,
-                            mesorderstus = "ALLO", //娲惧彂
+                            mesorderstus = wo_status, //鍗曟嵁鐘舵��
                             wkshopcode = wkshopcode,
                             mesqty = mesqty,
                             planstartdate = planstartdate,
@@ -529,18 +576,12 @@
                             planstartdate = planstartdate,
                             planenddate = planenddate,
                             routecode = routecode,
-                            status = "ALLO",  //娲惧彂
+                            status = wrk_status,  //宸ュ簭鐘舵��
                             username = username,
                             CreateDate = DateTime.Now.ToString()
                         }
                     });
-                    //if (is_aps == "Y")  //鏄惁鎺掔▼
-                    //{
-                    //    string sql1 = "select id from TBom_Main  where materiel_code='" + PartNumber + "' and status='Y' and version='" + VsionId + "'";
-                    //    DataTable dt1 = DBHelper.GetTable(sql1);
-                    //}
 
-                    //澧炲姞宸ュ崟鐢ㄦ枡琛紙瀛愪欢锛�  
 
                     bool aa = DapperHelper.DoTransaction(list);
                     if (aa)
@@ -2529,6 +2570,174 @@
 
 
 
+        #region[浜ц兘瑙勫垝璁剧疆鏌ヨ]
+        public static ToMessage CapacityPlanningSetupSearch()
+        {
+            string sql = "";
+            try
+            {
+                sql = @"select code,name,wktme1_start,wktme2_start,wktme3_start,wktme4_start,wktme5_start,
+                        lm_user,lm_date,duration  
+                        from  TBas_wkshift_info";
+                var data = DapperHelper.selecttable(sql);
+                mes.code = "200";
+                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.data = data;
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[浜ц兘瑙勫垝璁剧疆鏂板]
+        public static ToMessage CapacityPlanningSetupAddUpdate(string username, List<CapacityPlanningSetup> objs)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鍒ゆ柇缂栫爜鏄惁閲嶅
+                sql = @"select *  from TBas_wkshift_info where code=@code";
+                dynamicParams.Add("@code", objs[0].CapSetupCode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "缂栫爜宸插瓨鍦�,涓嶈兘閲嶅!";
+                    mes.data = null;
+                    return mes;
+                }
+                //鍒ゆ柇鍚嶇О鏄惁閲嶅
+                sql = @"select *  from TBas_wkshift_info where name=@name";
+                dynamicParams.Add("@name", objs[0].CapSetupName);
+                var data0 = DapperHelper.selectdata(sql, dynamicParams);
+                if (data0.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "鍚嶇О宸插瓨鍦�,涓嶈兘閲嶅!";
+                    mes.data = null;
+                    return mes;
+                }
+                list.Clear();
+                //寰幆鍐欏叆璁惧绫诲瀷琛�
+                for (int i = 0; i < objs.Count; i++)
+                {
+                    sql = @"insert into TBas_wkshift_info(code, name, wktme1_start, wktme2_start, wktme3_start, wktme4_start, wktme5_start, lm_user, lm_date, duration)
+                            values(@code,@name,@wktme1_start,@wktme2_start,@wktme3_start,@wktme4_start,@wktme5_start,@lm_user,@lm_date,@duration)";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            code = objs[i].CapSetupCode,
+                            name = objs[i].CapSetupName,
+                            wktme1_start = objs[i].OneStartDate,
+                            wktme2_start = objs[i].TwoStartDate,
+                            wktme3_start = objs[i].ThreeStartDate,
+                            wktme4_start = objs[i].FourStartDate,
+                            wktme5_start = objs[i].FiveStartDate,
+                            lm_user = username,
+                            lm_date = DateTime.Now.ToString(),
+                            duration = objs[i].Duration
+                        }
+                    });
+                }
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    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 CapacityPlanningSetupDelete(string username, string capsetupcode)
+        {
+            var sql = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鍒ゆ柇鏂规鏄惁琚紩鐢�
+                sql = @"select *  from TWkm_capac_plan where wkshift_code=@capsetupcode";
+                dynamicParams.Add("@capsetupcode", capsetupcode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "鍒犻櫎澶辫触锛�,璇ユ柟妗堝凡缁忚浜ц兘瑙勫垝璧勬簮寮曠敤!";
+                    mes.data = null;
+                    return mes;
+                }
+                list.Clear();
+                //鍒犻櫎鏂规
+
+                sql = @"delete TBas_wkshift_info where code=@code";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        code = capsetupcode
+                    }
+                });
+
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    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 CapacityPlanningSearch(string workshop, string devicetype, string stustype, int startNum, int endNum, string prop, string order)
         {
@@ -2623,14 +2832,14 @@
             {
                 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)";
+                    var sql = @"insert into TWkm_capac_plan(wkshop, eqp_typecode, wkshift_code, enable, lm_user, lm_date,classtype) 
+                            values(@wkshop,@eqp_typecode,@wkshift_code,@enable,@lm_user,@lm_date,@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("@lm_date", DateTime.Now.ToString());
                     dynamicParams.Add("@classtype", captplantype);
                     int cont = DapperHelper.SQL(sql, dynamicParams);
                     if (cont > 0)
@@ -2694,10 +2903,10 @@
                 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++)
+                for (int i = 0; i < data.Rows.Count; i++)
                 {
-                    string DataTime = dt.Rows[i]["DataTime"].ToString();//鏃ユ湡
-                    string key = dt.Rows[i]["wkshift_code"].ToString(); //鏂规缂栫爜
+                    string DataTime = data.Rows[i]["DataTime"].ToString();//鏃ユ湡
+                    string key = data.Rows[i]["wkshift_code"].ToString(); //鏂规缂栫爜
                     CapaPlan cmp = new CapaPlan();
                     cmp.name = DataTime;
                     cmp.key = key;
@@ -2735,11 +2944,11 @@
                 dynamicParams.Add("@captplanid", captplanid);
                 dynamicParams.Add("@datetime", datetime);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
-                for (int i = 0; i < dt.Rows.Count; i++)
+                for (int i = 0; i < data.Rows.Count; i++)
                 {
-                    string code = dt.Rows[i]["code"].ToString();//鏂规缂栫爜
-                    string name = dt.Rows[i]["name"].ToString();//鏂规鍚嶇О
-                    string flag = dt.Rows[i]["flag"].ToString();   //閫変腑鏂规鏍囪瘑
+                    string code = data.Rows[i]["code"].ToString();//鏂规缂栫爜
+                    string name = data.Rows[i]["name"].ToString();//鏂规鍚嶇О
+                    string flag = data.Rows[i]["flag"].ToString();   //閫変腑鏂规鏍囪瘑
                     CapacityPlanSect cmp = new CapacityPlanSect();
                     cmp.CapCode = code;
                     cmp.CapName = name;
@@ -2748,7 +2957,7 @@
 
                     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);
+                    var db = DapperHelper.selectdata(sql1, dynamicParams);
 
                     for (int j = 0; j < db.Columns.Count; j++) //鏃堕棿娈�
                     {
@@ -2862,11 +3071,10 @@
                     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 
+                    string sql3 = @"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)";
+                                  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)  //濡傛灉鏃ユ湡鏈夊彉鍔�
@@ -2902,7 +3110,7 @@
                         }
                     }
                     //鏇存柊鎺掍骇鐢熶骇璧勬簮涓昏〃
-                    sql = @"update gn_wkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_time=@lm_time  where id=@id";
+                    sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_time=@lm_time  where id=@id";
                     list.Add(new
                     {
                         str = sql,

--
Gitblit v1.9.3