From 164ed043c7dc88fd05074244c3951a9ccc0ceead Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期三, 29 三月 2023 10:54:50 +0800
Subject: [PATCH] 车间看板取数修改、订单下达获取工单语句修改、生产工单手工创建获取单号接口

---
 VueWebApi/DLL/DAL/ProductionManagementDAL.cs |  173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 164 insertions(+), 9 deletions(-)

diff --git a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
index 99241f7..745bc95 100644
--- a/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -127,7 +127,8 @@
                     //鑾峰彇鏈�澶у崟鎹彿
                     if (i == 1)  //棣栧崟鑾峰彇宸ュ崟鍙�
                     {
-                        sql = @"select isnull(max(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code))),0)+1 as worknumb from TK_Wrk_Man where m_po=@erpordercode";
+                        sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as worknumb   
+                                from TK_Wrk_Man where m_po=@erpordercode";
                         dynamicParams.Add("@erpordercode", erpordercode);
                         var data = DapperHelper.selectdata(sql, dynamicParams);
                         num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString());
@@ -391,6 +392,83 @@
         }
         #endregion
 
+        #region[MES鎶ュ簾琛ュ崟宸ュ崟鏌ヨ]
+        public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
+        {
+            var dynamicParams = new DynamicParameters();
+            string search = "";
+            try
+            {
+                if (mesordercode != "" && mesordercode != null)
+                {
+                    search += "and A.wo_code like '%'+@mesordercode+'%' ";
+                    dynamicParams.Add("@mesordercode", mesordercode);
+                }
+                if (sourceorder != "" && sourceorder != null)
+                {
+                    search += "and A.m_po like '%'+@sourceorder+'%' ";
+                    dynamicParams.Add("@sourceorder", sourceorder);
+                }
+                if (partcode != "" && partcode != null)
+                {
+                    search += "and A.materiel_code like '%'+@partcode+'%' ";
+                    dynamicParams.Add("@partcode", partcode);
+                }
+                if (partname != "" && partname != null)
+                {
+                    search += "and B.partname like '%'+@partname+'%' ";
+                    dynamicParams.Add("@partname", partname);
+                }
+                if (partspec != "" && partspec != null)
+                {
+                    search += "and B.partspec like '%'+@partspec+'%' ";
+                    dynamicParams.Add("@partspec", partspec);
+                }
+                if (createdate != "" && createdate != null)
+                {
+                    search += "and CONVERT(varchar(100),A.lm_date,23)=@createdate ";
+                    dynamicParams.Add("@createdate", createdate);
+                }
+                if (creatuser != "" && creatuser != null)
+                {
+                    search += "and U.username like '%'+@creatuser+'%' ";
+                    dynamicParams.Add("@creatuser", creatuser);
+                }
+
+                if (search == "")
+                {
+                    search = "and 1=1 ";
+                }
+                // --------------鏌ヨ鎸囧畾鏁版嵁--------------
+                var total = 0; //鎬绘潯鏁�
+                var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.org_name as wkshp_name,
+                            A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,U.username as lm_user,A.lm_date,S.bad_qty
+                            from TK_Wrk_Man A
+                            left join (select wo_code,sum(bad_qty) as bad_qty from  TK_Wrk_Step where bad_qty>0 group by wo_code) S on A.wo_code=S.wo_code
+                            left join TMateriel_Info B on A.materiel_code=B.partcode
+                            left join TOrganization C on A.wkshp_code=C.org_code
+                            left join T_Sec_Stck D on A.stck_code=D.code 
+                            left join TFlw_Rout E on A.route_code=E.code
+                            left join T_Sec_Stck F on A.stck_code=F.code 
+                            left join TUser U on A.lm_user=U.usercode 
+                            where A.is_delete<>'1'  and A.status='START' and A.wotype='PO' and S.bad_qty>0 " + search;
+                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 PartSelectRoute(string partcode)
         {
@@ -537,10 +615,11 @@
                     }
                 }
                 //鍒ゆ柇宸ヨ壓璺嚎瀵瑰簲宸ュ簭鍏宠仈鐨勫伐浣滅珯鏄惁鏈夎缃妭鎷嶅伐浠�
-                sql = @"select AA.step_code,AA.eqp_code,S.unprice  from (
-                        select A.code,B.step_code,C.eqp_code from TFlw_Rout A
+                sql = @"select AA.step_code,AA.eqp_code,AA.flwtype,S.unprice  from (
+                        select A.code,B.step_code,C.eqp_code,S.flwtype from TFlw_Rout A
                         inner join TFlw_Rtdt B on A.code=B.rout_code
                         left join TFlw_Rteqp C on B.step_code=C.step_code
+                        left join TStep S on B.step_code=S.stepcode
                         where A.code=@route_code
                         ) as AA
                         left join (select * from TPrteEqp_Stad   where materiel_code=@partcode and route_code=@route_code) as S on
@@ -550,15 +629,45 @@
                 var dtc = DapperHelper.selectdata(sql, dynamicParams);
                 for (int i = 0; i < dtc.Rows.Count; i++)
                 {
-                    if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0)
+                    if (dtc.Rows[i]["flwtype"].ToString() == "Z") //鍒ゆ柇宸ュ簭鏄惁涓鸿嚜鍒�
                     {
-                        mes.code = "300";
-                        mes.count = 0;
-                        mes.Message = "鑺傛媿宸ヤ环涓細褰撳墠浜у搧銆�" + partcode + "銆戯紝瀵瑰簲宸ヨ壓璺嚎銆�" + routecode + "銆戞湭璁剧疆(鎴栨湭璁剧疆鍏�)鎴栧伐浠峰皬浜庣瓑浜�0!";
-                        mes.data = null;
-                        return mes;
+                        if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0)
+                        {
+                            mes.code = "300";
+                            mes.count = 0;
+                            mes.Message = "鑺傛媿宸ヤ环涓細褰撳墠浜у搧銆�" + partcode + "銆戯紝瀵瑰簲宸ヨ壓璺嚎銆�" + routecode + "銆戞湭璁剧疆(鎴栨湭璁剧疆鍏�)鎴栧伐浠峰皬浜庣瓑浜�0!";
+                            mes.data = null;
+                            return mes;
+                        }
                     }
                 }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[MES宸ュ崟鏂板銆佽幏鍙栧伐鍗曞彿]
+        public static ToMessage AddMesOrderCodeSearch()
+        {
+            string sql = "";
+            string wo_code = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鑾峰彇鍗曟嵁鍙�
+                sql = @"SELECT 'SGPO'+CONVERT(varchar(12) , getdate(), 112 )+'_'+cast(isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as varchar) as numct
+                        FROM TK_Wrk_Man where wo_code like '%SGPO%'";
+                var data = DapperHelper.selecttable(sql);
+                mes.code = "200";
+                mes.Message = "鏌ヨ鎴愬姛!";
+                mes.data = data.Rows[0]["numct"].ToString();
             }
             catch (Exception e)
             {
@@ -678,6 +787,23 @@
                         }
                     });
 
+                    //鍐欏叆宸ュ崟宸ヨ壓璺嚎宸ュ簭宸ヤ环澶嶅埗琛�
+                    sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code)
+                           select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice,
+                           S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code
+                           from TFlw_Rtdt A
+                           inner join TFlw_Rteqp C on A.step_code=C.step_code
+                           inner join (select *   from TPrteEqp_Stad  where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            mesordercode = mesordercode,
+                            materiel_code = partcode,
+                            routecode = routecode
+                        }
+                    });
 
                     bool aa = DapperHelper.DoTransaction(list);
                     if (aa)
@@ -771,6 +897,35 @@
                             CreateDate = DateTime.Now.ToString()
                         }
                     });
+
+                    //鍒犻櫎宸ュ崟宸ヨ壓璺嚎宸ュ簭宸ヤ环澶嶅埗琛�
+                    sql = @"delete TWoPrteEqp_Stad where wo=@mesordercode";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            mesordercode = mesordercode
+                        }
+                    });
+                    //鍐欏叆宸ュ崟宸ヨ壓璺嚎宸ュ簭宸ヤ环澶嶅埗琛�
+                    sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code)
+                           select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice,
+                           S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code
+                           from TFlw_Rtdt A
+                           inner join TFlw_Rteqp C on A.step_code=C.step_code
+                           inner join (select *   from TPrteEqp_Stad  where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            mesordercode = mesordercode,
+                            materiel_code = partcode,
+                            routecode = routecode
+                        }
+                    });
+
                     bool aa = DapperHelper.DoTransaction(list);
                     if (aa)
                     {

--
Gitblit v1.9.3