From ab780f99454e132e717f8fde35eb2b5a1d632b9b Mon Sep 17 00:00:00 2001 From: xuli Date: Fri, 12 Apr 2024 15:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E6=9D=BF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NFine.Application/SRM/WatchPanelApp.cs | 239 +++++++++++++++---------- 1 file changed, 143 insertions(+), 96 deletions(-) diff --git a/NFine.Application/SRM/WatchPanelApp.cs b/NFine.Application/SRM/WatchPanelApp.cs index a180946..81565be 100644 --- a/NFine.Application/SRM/WatchPanelApp.cs +++ b/NFine.Application/SRM/WatchPanelApp.cs @@ -1129,66 +1129,99 @@ select * from ( string SqlText = ""; SqlText = @" + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD_Tt')) + drop table #TempCCDD_Tt if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD')) drop table #TempCCDD -SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,C.MOCODE 工单号,LL.OPSEQ, -a.OPCODE 工序代码,ppp.opname 工序名称,us.UserName 报工人, + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempFFF')) + drop table #TempFFF + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempXXXXX')) + drop table #TempXXXXX + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempZTPP')) + drop table #TempZTPP + +SELECT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,C.MOCODE 工单号, +a.OPCODE 工序代码,ppp.opname 工序名称,us.UserName 报工人,B.UserCodeBegin, CASE WHEN A.ACTIONRESULT='COLLECT_BEGIN' then '----生产中----' WHEN A.ACTIONRESULT='COLLECT_END' then '----已结束----' end as 工序结束状态, -SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime)) as '报工时长', -isnull(SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime))-ISNULL(xx.[暂停时长],0),'') AS 有效时间, -xx.[暂停时长], + DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime) as '报工时长', isnull(CONVERT(VARCHAR,B.BeginDateTime,120),'') 开工时间, -isnull(CONVERT(VARCHAR,B.EndDateTime,120),'') 完工时间, -isnull(CONVERT(VARCHAR,xx.开始时间 ,120),'') as 暂停开始时间, -isnull(CONVERT(VARCHAR,xx.结束时间,120),'') as 暂停结束时间, -isnull(xx.[暂停原因],'') 暂停原因, -xx.[暂停备注] -into #TempCCDD -FROM ICSLOTONWIP A -LEFT JOIN ICSLOTONWIPDetail B ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODE -LEFT JOIN ICSOP ppp on a.OPCODE=ppp.OPCODE -LEFT JOIN ICSLOTSIMULATION nn on nn.LOTNO=A.LOTNO -LEFT JOIN Sys_User us on us.UserCode=B.UserCodeBegin -LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ -LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ -LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE -LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE -LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND B.ECCode=UU.CREWCODE -LEFT JOIN (SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,gg.ROUTECODE 工艺路线 ,A.LOTNO 跟踪单号, -c.MOCODE 工单号,c.MOSEQ 工单行号, A.OPCODE 工序,us.UserName as 报工人, +isnull(CONVERT(VARCHAR,B.EndDateTime,120),'') 完工时间 ,A.ID,B.ID DetailID,B.BeginDateTime,B.EndDateTime + +into #TempCCDD_Tt +FROM ICSLOTONWIP A with(nolock) +LEFT JOIN ICSLOTONWIPDetail B with(nolock) ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODE +LEFT JOIN ICSOP ppp with(nolock) on a.OPCODE=ppp.OPCODE +LEFT JOIN Sys_User us with(nolock) on us.UserCode=B.UserCodeBegin +LEFT JOIN ICSMO C with(nolock) ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ +LEFT JOIN ICSINVENTORY dd with(nolock) on C.ITEMCODE=dd.INVCODE +where 1=1 AND b.Type='标准报工' and a.WorkPoint='6000' and B.BeginDateTime>=DATEADD(mm, -1, getdate()) +ORDER BY C.molotcode, C.ITEMCODE , us.UserName asc + + + SELECT A.id, + PP.Usercode , pp.BeginTime 开始时间, -pp.EndTime 结束时间, -SUM(DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime)) as '暂停时长' , -isnull(vv.EnumText,'') 暂停原因, -pp.Memo 暂停备注 -from ICSLOTONWIP A INNER JOIN ICSLOTPAUSE pp on A.Lotno=pp.lotno and A.opcode=pp.opcode - -LEFT JOIN Sys_User us on us.UserCode=PP.Usercode -LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ -LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ -LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE -LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE -LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND pp.EATTRIBUTE1=UU.CREWCODE -LEFT JOIN Sys_EnumValues vv on vv.EnumValue=pp.RESCODE --AND vv.EnumKey='00022' -where pp.MODELCODE='标准报工' and vv.EnumKey='00022' --AND a.LOTNO=''-- and A.ACTIONRESULT = 'COLLECT_END' -GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName,pp.BeginTime,pp.EndTime,vv.EnumText , -pp.Memo) -xx on xx.[工单号]=c.MOCODE AND xx.[工单行号]=c.MOSEQ AND A.OPCODE=xx.[工序] AND xx.[报工人]=us.UserName AND xx.开始时间 >B.BeginDateTime ---AND xx.结束时间 < B.EndDateTime -AND ISNULL(xx.结束时间, '2024-02-21 17:37:02') < ISNULL(B.EndDateTime, '2025-02-21 17:37:02') -where 1=1 AND b.Type='标准报工' and a.WorkPoint='6000' and B.BeginDateTime>=DATEADD(mm, -3, getdate()) -GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE , -us.UserName,xx.[暂停时长],nn.ISCOM,b.MTIME,B.BeginDateTime, B.EndDateTime,xx.[开始时间],xx.[结束时间],ppp.opname,xx.[暂停原因], -xx.[暂停备注],A.ACTIONRESULT,LL.OPSEQ - -ORDER BY C.molotcode, C.ITEMCODE ,LL.OPSEQ,us.UserName asc - - -SELECT *,case when 暂停开始时间 is not null and 暂停结束时间 is null then '暂停中' else '' end 暂停状态 FROM #TempCCDD -WHERE CONVERT(varchar(10), 开工时间, 21) =(SELECT MAX(CONVERT(varchar(10), 开工时间, 21)) FROM #TempCCDD) -ORDER BY 销售车号,物料编码,报工人 +pp.EndTime 结束时间, +isnull(vv.EnumText,'') 暂停原因 , +DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime) 暂停时长 +into #TempFFF +from ICSLOTONWIP A with(nolock) +INNER JOIN ICSLOTPAUSE pp with(nolock) on A.Lotno=pp.lotno and A.opcode=pp.opcode +LEFT JOIN Sys_EnumValues vv with(nolock) on vv.EnumValue=pp.RESCODE +where pp.MODELCODE='标准报工' and vv.EnumKey='00022' + and pp.BeginTime >=DATEADD(mm, -1, getdate()) + + + + + SELECT DD.DetailID,XX.暂停时长,xx.暂停原因,xx.开始时间 暂停开始时间,xx.结束时间 暂停结束时间 +into #TempXXXXX +FROM #TempCCDD_Tt DD +LEFT JOIN #TempFFF XX ON DD.ID=XX.ID AND xx.[Usercode]=DD.UserCodeBegin AND xx.开始时间 >DD.BeginDateTime +AND ISNULL(xx.结束时间, '2024-02-21 17:37:02') < ISNULL(DD.EndDateTime, '2025-02-21 17:37:02') + +SELECT DetailID,SUM(暂停时长) 暂停时长,MIN(暂停开始时间) 暂停开始时间,MAX(暂停结束时间) 暂停结束时间, + STUFF((select',' + 暂停原因 from (SELECT DISTINCT 暂停原因 + FROM #TempXXXXX SS WHERE SS.DetailID=HH.DetailID ) DD for xml path('')),1,1,'') 暂停原因 + INTO #TempZTPP +FROM #TempXXXXX HH +GROUP BY DetailID + +SELECT 销售车号, 物料编码, 物料名称 , 工单号, 工序代码, 工序名称, 报工人, 工序结束状态, + DATEDIFF(MINUTE, DD.BeginDateTime, DD.EndDateTime) as '报工时长', + DATEDIFF(MINUTE, dd.BeginDateTime, dd.EndDateTime) -ISNULL(xx.[暂停时长],0) AS 有效时间, + xx.[暂停时长] 暂停时长, + DD.开工时间, + DD.完工时间, + xx.暂停开始时间 暂停开始时间, + xx.暂停结束时间 暂停结束时间, +isnull(xx.[暂停原因],'') 暂停原因 , + case when 暂停开始时间 is not null and 暂停结束时间 is null then '暂停中' else '' end 暂停状态 +FROM #TempCCDD_Tt DD +LEFT JOIN #TempZTPP xx on XX.DetailID=DD.DetailID +WHERE CONVERT(varchar(10), dd.开工时间, 21) =(SELECT MAX(CONVERT(varchar(10), 开工时间, 21)) FROM #TempCCDD_Tt) + +ORDER BY 销售车号, 物料编码 ,报工人 asc + + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD_Tt')) + drop table #TempCCDD_Tt if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD')) drop table #TempCCDD + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempFFF')) + drop table #TempFFF + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempXXXXX')) + drop table #TempXXXXX + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempZTPP')) + drop table #TempZTPP + "; @@ -1213,7 +1246,7 @@ ORDER BY 销售车号,物料编码,报工人 select isnull(realsaleout,0) 上月度发车 from ICSZXBoardSaleout where id = '1') b on 1=1 left join ( select isnull(realsaleout,0) 年度发车 from ICSZXBoardSaleout - where id = '2') on 1=1 "; + where id = '2') f on 1=1 "; DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); return dt; } @@ -1225,48 +1258,62 @@ ORDER BY 销售车号,物料编码,报工人 string where1 = ""; string SqlText = ""; - SqlText = @" --socode销售车辆号 monum工单总行 wipnum报告结束数量 wipbnum报告的数量含开工中 - select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum , isnull(wipb.num ,0) as wipbnum - into #tempNum - from - ( - select tso.socode ,count(*) as monum from - icsso tso - left join icsmo tmo on tso.socode = tmo.molotcode - group by tso.socode - ) tmo - left join ( - select tso.socode ,count(*) as wipnum from - icsso tso - left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode - LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode - where wip.iscom='1' - group by tso.socode - ) wip on tmo.socode = wip.socode - left join - ( - select tso.socode ,count(*) as num from - icsso tso - left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode - LEFT JOIN ICSLOTONWIP wip on tmo.mocode = wip.mocode - where wip.actionresult!='' - group by tso.socode - ) wipb on tmo.socode = wipb.socode - - select row_number() over (order by a.客户交货期,a.销售车辆号)as 序号, a.* from ( - select distinct tso.socode 销售车辆号,convert(varchar(10),tso.plandate,120) as 客户交货期, isnull(convert(char(4),cus.fname),'') 用户单位, - inv.invname as 产品名称, - concat(cast(cast(tnum.wipnum * 1.0 / tnum.monum as decimal(18,3))* 100 as decimal(18,0)),'%') 进度, - (case when tnum.wipnum/tnum.monum =1 then '已完工' when tnum.wipbnum >0 then '开工中' else '未开工' end ) 生产状态 - from - icsso tso - left join ICSCustomer cus on tso.cusid = cus.FCUSTID - left join icsmo tmo on tso.socode = tmo.molotcode - left join #tempNum tnum on tnum.socode = tso.socode - left join ICSINVENTORY inv on inv.invstd LIKE '%'+'.'+tmo.molotcode - where tso.status = 'C' and tmo.id in(select moid from ICSMO2ROUTE)) a - if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum')) - drop table #tempNum "; + SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempSSCC')) + drop table #TempSSCC + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum')) + drop table #tempNum + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOCCOM')) + drop table #TempMOCCOM + + select distinct tso.socode 销售车辆号,convert(varchar(10),tso.plandate,120) as 客户交货期, + isnull(convert(char(4),cus.fname),'') 用户单位, inv.invname as 产品名称 + into #TempSSCC + from + icsso tso with(nolock) + left join ICSCustomer cus with(nolock) on tso.cusid = cus.FCUSTID + left join icsmo tmo with(nolock) on tso.socode = tmo.molotcode + left join ICSINVENTORY inv with(nolock) on inv.invcode=tmo.molotcode + where tso.status = 'C' and tmo.id in(select moid from ICSMO2ROUTE with(nolock) ) + + + select count(id) wipnum,molotcode + into #TempMOCCOM + FROM (SELECT id,molotcode + from ( + select tmo.id, molotcode,tmo.moplanqty, wip.LOTQTY + from icsmo tmo with(nolock) + INNER join ICSLOTSIMULATION wip with(nolock) ON tmo.mocode = wip.mocode and wip.iscom='1' + and tmo.moseq=wip.moseq + where tmo.molotcode in (select distinct 销售车辆号 from #TempSSCC) + ) jj + group by id,molotcode + having(max(moplanqty)<=sum(LOTQTY)) + ) HH + GROUP BY molotcode + + + select tso.销售车辆号 ,isnull(( select count(*) + from icsmo tmo with(nolock) where tso.销售车辆号 = tmo.molotcode),0) monum , + isnull(CCOM.wipnum,0) wipnum , + case when exists(select 1 from icsmo tmo where tso.销售车辆号 = tmo.molotcode + and exists(select 1 from ICSLOTONWIP wip with(nolock) where tmo.mocode = wip.mocode and wip.actionresult!='') ) then 1 else 0 end wipbnum into #tempNum + from ( select distinct 销售车辆号 from #TempSSCC) tso + LEFT JOIN #TempMOCCOM CCOM ON CCOM.molotcode=TSO.销售车辆号 + + + + select row_number() over (order by a.客户交货期,a.销售车辆号)as 序号, a.* + from ( + + select tso.销售车辆号, 客户交货期, 用户单位, + 产品名称, + concat(cast(cast(tnum.wipnum * 1.0 / tnum.monum as decimal(18,3))* 100 as decimal(18,0)),'%') 进度, + (case when tnum.wipnum/tnum.monum =1 then '已完工' when tnum.wipbnum >0 then '开工中' else '未开工' end ) 生产状态 + from #TempSSCC tso + left join #tempNum tnum on tnum.销售车辆号 = tso.销售车辆号 + + ) a + "; DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);