From f0f1f59639e4efc93b8df93fd58d21fa757b1855 Mon Sep 17 00:00:00 2001 From: fyw Date: Thu, 9 May 2024 11:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E6=A3=80=E6=95=B0=E9=87=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NFine.Application/SRM/WatchPanelApp.cs | 193 ++++++++++++++++++------- 1 file changed, 141 insertions(+), 52 deletions(-) diff --git a/NFine.Application/SRM/WatchPanelApp.cs b/NFine.Application/SRM/WatchPanelApp.cs index f0c32e5..1340ecd 100644 --- a/NFine.Application/SRM/WatchPanelApp.cs +++ b/NFine.Application/SRM/WatchPanelApp.cs @@ -1632,64 +1632,153 @@ left join #Tempcccc cc on a.销售车辆号=cc.销售车辆号 drop table #Tcustt_TOCKQty - --用途程表关联wip表拼出所有的检验数据 - select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP, a.OPControlSeq,b.LOTNO, - isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode into #Tcustttemp1 - from ICSITEMROUTE2OPLot a with(nolock) - left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE - inner join (SELECT distinct a.ITEMCODE,a.ROUTECODE - from ICSITEMROUTE2OPLot a with(nolock) - left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE - WHERE b.ACTIONRESULT is not null - ) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE - - left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ + //--用途程表关联wip表拼出所有的检验数据 + //select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP, a.OPControlSeq,b.LOTNO, + //isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode into #Tcustttemp1 + //from ICSITEMROUTE2OPLot a with(nolock) + //left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE + //inner join (SELECT distinct a.ITEMCODE,a.ROUTECODE + //from ICSITEMROUTE2OPLot a with(nolock) + //left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE + //WHERE b.ACTIONRESULT is not null + // ) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE + + //left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ - order by ITEMCODE,OPControlSeq - --把wip表里有在开工的排除 - select ITEMCODE,ROUTECODE,ACTIONRESULT into #Tcusttfilter from icslotonwip with(nolock) - group by ITEMCODE,ROUTECODE,ACTIONRESULT HAVING COUNT(ITEMCODE) = 1 and COUNT(ROUTECODE)=1 - --找出待检的工序 - select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a - inner join - (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null--最小未检前一道结束的 - and ROUTECODE in - (select ROUTECODE from (select max(a.OPControlSeq) OPControlSeq,a.ROUTECODE from #Tcustttemp1 a - inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null group by ROUTECODE) b - on a.ROUTECODE = b.ROUTECODE and b.OPControlSeq >a.OPControlSeq and a.ACTIONRESULT = 'COLLECT_END' group by a.ROUTECODE) a ) - GROUP BY ROUTECODE) b - on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq - inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c - on a.ROUTECODE =c.ROUTECODE - where - not EXISTS( select 1 from #Tcusttfilter f - where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE ) + //order by ITEMCODE,OPControlSeq + //--把wip表里有在开工的排除 + //select ITEMCODE,ROUTECODE,ACTIONRESULT into #Tcusttfilter from icslotonwip with(nolock) + //group by ITEMCODE,ROUTECODE,ACTIONRESULT HAVING COUNT(ITEMCODE) = 1 and COUNT(ROUTECODE)=1 + //--找出待检的工序 + //select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a + //inner join + //(select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null--最小未检前一道结束的 + //and ROUTECODE in + //(select ROUTECODE from (select max(a.OPControlSeq) OPControlSeq,a.ROUTECODE from #Tcustttemp1 a + //inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null group by ROUTECODE) b + //on a.ROUTECODE = b.ROUTECODE and b.OPControlSeq >a.OPControlSeq and a.ACTIONRESULT = 'COLLECT_END' group by a.ROUTECODE) a ) + //GROUP BY ROUTECODE) b + //on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq + //inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c + //on a.ROUTECODE =c.ROUTECODE + //where + //not EXISTS( select 1 from #Tcusttfilter f + // where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE ) - --将数据拼接成在检和待检两部分 + //--将数据拼接成在检和待检两部分 - --1、待检验数据 待检车辆 - select count(1) Qty into #Tcustt_TOCKQty - from ( - select b.molotCode [销售车号] -- , dj.LOTNO [产品跟踪单], dj.OPCODE [工序代码] - from #TcusttDJ dj - inner join #Tcustttemp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop ='检验工序' - inner join icsmo b with(nolock) on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ - inner join ICSMO2user d with(nolock) on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE - where MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE()) - union - select c.molotCode [销售车号] --, d.LOTNO [产品跟踪单], d.OPCODE [工序代码] - from - (select * from ICSITEMROUTE2OP with(nolock) where optionalop ='检验工序' and routecode in( - select DISTINCT routecode from ICSITEMROUTE2OP with(nolock) GROUP BY routecode HAVING count(*) = 1 )) a --查询只有一道工序的工艺路线 - inner JOIN ICSMO2ROUTE b with(nolock) on a.routeid = b.routeid - inner join ICSMO c with(nolock) on c.id = b.moid - inner join ICSMO2user d with(nolock) on c.mocode = d.mocode and c.moseq = d.moseq - inner join ICSITEMROUTE2OPLot lot with(nolock) on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode + //--1、待检验数据 待检车辆 + // select count(1) Qty into #Tcustt_TOCKQty + // from ( + //select b.molotCode [销售车号] -- , dj.LOTNO [产品跟踪单], dj.OPCODE [工序代码] + //from #TcusttDJ dj + //inner join #Tcustttemp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop ='检验工序' + //inner join icsmo b with(nolock) on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ + //inner join ICSMO2user d with(nolock) on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE + //where MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE()) + //union + //select c.molotCode [销售车号] --, d.LOTNO [产品跟踪单], d.OPCODE [工序代码] + //from + //(select * from ICSITEMROUTE2OP with(nolock) where optionalop ='检验工序' and routecode in( + //select DISTINCT routecode from ICSITEMROUTE2OP with(nolock) GROUP BY routecode HAVING count(*) = 1 )) a --查询只有一道工序的工艺路线 + //inner JOIN ICSMO2ROUTE b with(nolock) on a.routeid = b.routeid + //inner join ICSMO c with(nolock) on c.id = b.moid + //inner join ICSMO2user d with(nolock) on c.mocode = d.mocode and c.moseq = d.moseq + //inner join ICSITEMROUTE2OPLot lot with(nolock) on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode - where not exists (select 1 from ICSLOTONWIP wip with(nolock) where wip.lotno = d.LOTNO and wip.opcode =d.OPCODE and wip.actionresult ='COLLECT_END' and MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE())) + //where not exists (select 1 from ICSLOTONWIP wip with(nolock) where wip.lotno = d.LOTNO and wip.opcode =d.OPCODE and wip.actionresult ='COLLECT_END' and MONTH(d.MTIME)=MONTH(GETDATE()) and YEAR((d.MTIME)) = YEAR(GETDATE())) - ) jj + //) jj + + + + select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP,a.controlMethod,a.OPControlSeq,b.LOTNO, + isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode,b.BeginTime,b.userCodeEnd,b.endtime into #temp1 + from ICSITEMROUTE2OPLot a + left join icslotonwip b on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE + inner join (SELECT a.ITEMCODE,a.ROUTECODE ,count(b.ACTIONRESULT) as 汇总 + from ICSITEMROUTE2OPLot a + left join icslotonwip b on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE + WHERE b.ACTIONRESULT is not null + GROUP BY a.ITEMCODE,a.ROUTECODE + HAVING COUNT(b.ACTIONRESULT) > 0) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE + left join icsmo d on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ + inner join ICSMO2user e on d.mocode = e.mocode and e.moseq = d.moseq and year(e.mtime) = year(GETDATE()) and month(e.mtime) = month(GETDATE()) + order by ITEMCODE,OPControlSeq + + + SELECT ITEMCODE,ROUTECODE,ACTIONRESULT INTO #FILTER FROM ICSLOTONWIP WHERE ACTIONRESULT ='COLLECT_BEGIN' + + --找出待检的工序 + select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #DJ from #temp1 a + inner join + (select min(OPControlSeq) OPControlSeq,ROUTECODE from #temp1 where OPTIONALOP = '检验工序' and LOTNO is null + and ROUTECODE in + ( SELECT Ta.ROUTECODE + FROM + ( + SELECT t1.OPControlSeq, t1.ROUTECODE + FROM + ( + SELECT min(OPControlSeq) AS OPControlSeq, ROUTECODE + FROM #temp1 + WHERE ACTIONRESULT = '~' AND LOTNO IS NULL + GROUP BY ROUTECODE + ) t1 + INNER JOIN + ( + SELECT MIN(OPControlSeq) AS OPControlSeq, ROUTECODE + FROM #temp1 + WHERE OPTIONALOP = '检验工序' AND LOTNO IS NULL + GROUP BY ROUTECODE + ) b + ON t1.ROUTECODE = b.ROUTECODE AND b.OPControlSeq = t1.OPControlSeq + ) Ta ) + GROUP BY ROUTECODE) b + on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq + inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip ) c + on a.ROUTECODE =c.ROUTECODE + where + not EXISTS( select 1 from #filter f + where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE ) + + select itemcode ,routecode, max(endtime) endtime into #yjCheck from #temp1 where ACTIONRESULT = 'COLLECT_END' group by itemcode ,routecode + + select t1.ROUTECODE , t1.opcode, t1.endtime,user1.Username as name + into #yjCheck1 + from + #yjCheck ck + LEFT JOIN #temp1 t1 on ck.ROUTECODE = t1. ROUTECODE and ck.itemcode = t1.itemcode and ck.endtime = t1.endtime + left join Sys_User user1 on user1.usercode = t1.UserCodeEnd + --将数据拼接成在检和待检两部分 + select count(1) Qty into #Tcustt_TOCKQty + from ( + + select distinct b.molotCode [销售车号] + from #DJ dj + inner join #temp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop ='检验工序' + inner join icsmo b on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ + inner join ICSMO2user d on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE + inner join ICSSO so on SO.socode = b.molotCode + left join ICSOP op on dj.opcode = OP.opcode + left join #yjCheck1 ck on ck.routecode = a.routecode + left join ICSITEMROUTE2OPLot lot on b.itemcode = lot.ITEMCODE and dj.ROUTECODE = lot.ROUTECODE and lot.OPCODE = dj.opcode + left join ICSINVENTORY e on a.ITEMCODE = e.INVCODE + where year(d.MTIME) = year(GETDATE()) and month(d.MTIME) = month(GETDATE()) and + union All + select distinct c.molotCode [销售车号] from + (select * from ICSITEMROUTE2OP where optionalop ='检验工序' and routecode in( + select DISTINCT routecode from ICSITEMROUTE2OP GROUP BY routecode HAVING count(*) = 1 )) a --查询只有一道工序的工艺路线 + inner JOIN ICSMO2ROUTE b on a.routeid = b.routeid + inner join ICSMO c on c.id = b.moid + inner join ICSMO2user d on c.mocode = d.mocode and c.moseq = d.moseq + inner join ICSITEMROUTE2OPLot lot on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode + inner join ICSINVENTORY e on c.ITEMCODE =e.invCode + left join ICSSO so on SO.socode = c.molotCode + left join ICSOP op on d.opcode = OP.opcode + where year(d.MTIME) = year(GETDATE()) and month(d.MTIME) = month(GETDATE()) and not exists (select 1 from ICSLOTONWIP wip where wip.lotno = d.LOTNO and wip.opcode =d.OPCODE and wip.actionresult ='COLLECT_END') + )jj --1、已检验数据 已检车辆