Browse Source

待检数量修改

master
fyw 2 years ago
parent
commit
f0f1f59639
  1. 171
      NFine.Application/SRM/WatchPanelApp.cs

171
NFine.Application/SRM/WatchPanelApp.cs

@ -1632,63 +1632,152 @@ left join #Tempcccc cc on a.销售车辆号=cc.销售车辆号
drop table #Tcustt_TOCKQty 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
//--用途程表关联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 )
//--将数据拼接成在检和待检两部分
//--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()))
left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ
//) 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 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,ROUTECODE,ACTIONRESULT INTO #FILTER FROM ICSLOTONWIP WHERE ACTIONRESULT ='COLLECT_BEGIN'
-- --
select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a
select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #DJ from #temp1 a
inner join inner join
(select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '' and LOTNO is null--
(select min(OPControlSeq) OPControlSeq,ROUTECODE from #temp1 where OPTIONALOP = '' and LOTNO is null
and ROUTECODE in 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 )
( 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 GROUP BY ROUTECODE) b
on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq
inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c
inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip ) c
on a.ROUTECODE =c.ROUTECODE on a.ROUTECODE =c.ROUTECODE
where where
not EXISTS( select 1 from #Tcusttfilter f
not EXISTS( select 1 from #filter f
where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE ) 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
--1
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 select count(1) Qty into #Tcustt_TOCKQty
from ( 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()))
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 )jj

Loading…
Cancel
Save