You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
315 lines
13 KiB
315 lines
13 KiB
using NFine.Code;
|
|
using NFine.Data.Extensions;
|
|
using NFine.Domain._03_Entity.SRM;
|
|
using NFine.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NFine.Application.DHAY
|
|
{
|
|
public class FullProcessTraceabilityApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
#region [SQL]
|
|
string sql = @"select distinct a.MOCode,a.InvCode,inv.InvName,inv.InvStd,b.BatchCode,b.RKMtime,b.RKQTY,c.CKMtime,c.CKQTY from dbo.ICSMO a
|
|
left join dbo.ICSInventory inv on a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint
|
|
|
|
left join (select a.TransCode,c.BatchCode,a.WorkPoint, FORMAT(a.MTIME, 'yyyy-MM-dd') as RKMtime,sum(a.Quantity) as RKQTY from dbo.ICSWareHouseLotInfoLog a
|
|
left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSExtension c on b.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
|
|
where a.BusinessCode='17'
|
|
group by a.TransCode,c.BatchCode,a.WorkPoint,format(a.MTIME, 'yyyy-MM-dd') )b on a.MOCode=b.TransCode and a.WorkPoint=b.WorkPoint
|
|
|
|
left join (select d.TransCode,c.BatchCode,a.WorkPoint, FORMAT(a.MTIME, 'yyyy-MM-dd') as CKMtime,sum(a.Quantity) as CKQTY from dbo.ICSWareHouseLotInfoLog a
|
|
left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSInventoryLotDetail d on b.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint
|
|
left join dbo.ICSExtension c on b.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
|
|
where a.BusinessCode='19'
|
|
group by d.TransCode,c.BatchCode,a.WorkPoint,format(a.MTIME, 'yyyy-MM-dd') )c on a.MOCode=c.TransCode and a.WorkPoint=c.WorkPoint and b.BatchCode=c.BatchCode
|
|
|
|
where a.MOCode='" + queryParam["Code"].ToString() + "'";
|
|
|
|
#endregion
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
|
|
public DataTable GetGridJso2(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
//DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
#region [旧SQL]
|
|
// string sql = @"
|
|
|
|
//select b.TransCode,a.InvCode,sum(a.Quantity) as RKQTY ,isnull(cc.BatchCode,'') BatchCode,a.lotno
|
|
//INTO #TempMoPickFL
|
|
//from dbo.ICSInventoryLot a
|
|
//left join dbo.ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
//left join dbo.ICSExtension cc on a.ExtensionID=cc.ID and a.WorkPoint=cc.WorkPoint
|
|
//group by b.TransCode,a.InvCode,cc.BatchCode,a.lotno
|
|
|
|
|
|
//--查询工单领料的所有条码
|
|
|
|
//select ROW_NUMBER() OVER (partition by a.ID ORDER BY a.Sequence) AS SortSeq,c.LotNo,isnull(cc.BatchCode,'') BatchCode, b.InvCode, c.LLQTY as LLQTY ,a.MOCode,po.POCode PODocNo,o.InCode
|
|
|
|
//INTO #TempMoPickInv
|
|
//from dbo.ICSMO a
|
|
//left join dbo.ICSMOPick b on a.MODetailID= b.MODetailID and a.WorkPoint=b.WorkPoint
|
|
//left join (
|
|
// select a.TransCode,a.TransSequence,a.LotNo,sum(a.Quantity) as LLQTY from dbo.ICSWareHouseLotInfoLog a
|
|
// where a.BusinessCode='13'
|
|
// group by a.TransCode,a.TransSequence,a.LotNo) c on a.MOCode=c.TransCode and a.Sequence+'~'+b.Sequence =c.TransSequence
|
|
|
|
//left join dbo.ICSInventory inv on a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint
|
|
//left join dbo.ICSInventoryLot lot on c.LotNo=lot.LotNo and a.WorkPoint=lot.WorkPoint
|
|
//left join dbo.ICSExtension cc on lot.ExtensionID=cc.ID and a.WorkPoint=cc.WorkPoint
|
|
//left join dbo.ICSInventoryLotDetail dd on C.LotNo=dd.LotNo
|
|
//left join dbo.ICSPurchaseOrder po on dd.TransCode=po.POCode and dd.TransSequence = po.Sequence and a.WorkPoint=po.WorkPoint
|
|
// LEFT JOIN ICSOtherIn o ON dd.TransCode = o.InCode AND dd.TransSequence = o.Sequence
|
|
// where c.LotNo is not null
|
|
//;
|
|
|
|
//select a.lotno Cominlotno,c.lotno IssueLotNo,C.SortSeq,C.MOCODE,c.InvCode ,c.BatchCode
|
|
//into #Temp3333 from #TempMoPickInv c
|
|
//inner join #TempMoPickFL a on a.TransCode=c.mocode
|
|
//;
|
|
|
|
//WITH ICSMoALL AS
|
|
//(
|
|
// select
|
|
// 1 AS [Level],
|
|
// CAST(ii.SortSeq AS nvarchar(MAX)) AS SortSeq,
|
|
// CAST(REPLICATE('0',5-len(ii.SortSeq))+ii.SortSeq AS nvarchar(MAX)) AS Sort,
|
|
// ii.mocode tmocode,
|
|
// cast( ii.mocode as nvarchar(400)) Pmocode,
|
|
// cast( rr.TransCode as nvarchar(400)) mocode,
|
|
// ii.invcode tinvcode,
|
|
// ii.invcode Pivcode,
|
|
// ii.invcode invcode,
|
|
// ii.BatchCode tBatchCode,
|
|
// ii.BatchCode PBatchCode,
|
|
// ii.BatchCode BatchCode,
|
|
// ii.lotno Tlotno,
|
|
//ii.LOTNO PLOTNO,
|
|
// ii.lotno
|
|
|
|
|
|
// FROM #TempMoPickInv ii
|
|
//left join #TempMoPickFL rr on ii.lotno=rr.lotno where ii.mOCode='{0}'
|
|
//UNION ALL
|
|
// select
|
|
// b.[Level]+1 AS [Level],
|
|
// CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(c.SortSeq AS nvarchar(MAX)) AS SortSeq,
|
|
// CAST(b.Sort+'.'+REPLICATE('0',5-len(c.SortSeq))+CAST(c.SortSeq AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort,
|
|
// b.tmocode,
|
|
// cast(B.MOCODE as nvarchar(400)) PMOCODE,
|
|
// cast(C.MOCODE as nvarchar(400)) MOCODE,
|
|
// b.tinvcode,
|
|
// B.invcode Pinvcode,
|
|
// C.invcode,
|
|
// b.tBatchCode,
|
|
// B.BatchCode PBatchCode,
|
|
// C.BatchCode,
|
|
//b.tlotno,
|
|
//C.Cominlotno PLOTNO,
|
|
// C.IssueLotNo lotno
|
|
// FROM #Temp3333 c --工单入---工单领加
|
|
// INNER JOIN ICSMoALL b ON b.lotno=C.Cominlotno --上层领料=c.入条码
|
|
//where b.[Level]<10
|
|
//)
|
|
|
|
|
|
//SELECT * into #Temp444
|
|
//FROM ICSMoALL a
|
|
|
|
// select ff.invcode ,ff.lotno,ii.LLQTY , ff.BatchCode,ii.PODocNo,ii.InCode,ii2. mocode,ii3.RKQTY,ff.SortSeq,ff.Sort
|
|
// into #Tempgggg
|
|
//from #Temp444 ff left join #TempMoPickInv ii on ii.lotno=ff.lotno
|
|
//left join #Temp3333 ii2 on ii2.Cominlotno=ff.lotno
|
|
//left join #TempMoPickFL ii3 on ii3.lotno=ff.lotno
|
|
|
|
|
|
//select aa.invcode ,aa.BatchCode,aa.sortseq,aa.sort,inv.InvName,inv.InvStd ,bb.llqty,bb2.RKQTY,
|
|
//STUFF((select',' + PODocNo from (SELECT DISTINCT PODocNo FROM #Tempgggg gg
|
|
//where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode ) DD for xml path('')),1,1,'') PODocNo
|
|
//,
|
|
//STUFF((select',' + InCode from (SELECT DISTINCT InCode FROM #Tempgggg gg
|
|
//where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode ) DD for xml path('')),1,1,'') InCode
|
|
//,
|
|
//STUFF((select',' + mocode from (SELECT DISTINCT mocode FROM #Tempgggg gg
|
|
//where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode ) DD for xml path('')),1,1,'') mocode
|
|
//from ( select invcode ,BatchCode, sortseq,Sort from #Temp444 ) aa
|
|
|
|
//left join ( select invcode ,BatchCode,sortseq,sum(llqty) llqty from (select * from #Tempgggg ) hh group by invcode,BatchCode,sortseq ) bb
|
|
//on aa.invcode=bb.invcode and aa.BatchCode=bb.BatchCode and aa.sortseq=bb.sortseq
|
|
//left join ( select invcode ,BatchCode,sortseq,sum(RKQTY) RKQTY from (select * from #Tempgggg ) hh group by invcode,BatchCode,sortseq ) bb2
|
|
//on aa.invcode=bb2.invcode and aa.BatchCode=bb2.BatchCode and aa.sortseq=bb2.sortseq
|
|
//left join dbo.ICSInventory inv on inv.InvCode=aa.invcode
|
|
//order by aa.sort
|
|
|
|
|
|
//DROP TABLE #TempMoPickInv
|
|
//DROP TABLE #TempMoPickFL
|
|
//DROP table #Temp444
|
|
//DROP table #Temp3333
|
|
//DROP table #Tempgggg
|
|
|
|
|
|
//";
|
|
//string sql2 = string.Format(sql, queryParam["Code"].ToString());
|
|
#endregion
|
|
#region {SQL}
|
|
string sql = @"select b.TransCode,a.InvCode,sum(a.Quantity) as RKQTY ,isnull(cc.BatchCode,'') BatchCode,a.lotno
|
|
INTO #TempMoPickFL
|
|
from dbo.ICSInventoryLot a
|
|
left join dbo.ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join dbo.ICSExtension cc on a.ExtensionID=cc.ID and a.WorkPoint=cc.WorkPoint
|
|
group by b.TransCode,a.InvCode,cc.BatchCode,a.lotno
|
|
|
|
|
|
--查询工单领料的所有条码
|
|
select ROW_NUMBER() OVER (partition by a.ID ORDER BY a.Sequence) AS SortSeq,c.LotNo,isnull(cc.BatchCode,'') BatchCode, b.InvCode, c.LLQTY as LLQTY ,a.MOCode,po.POCode PODocNo,o.InCode
|
|
INTO #TempMoPickInv
|
|
from dbo.ICSMO a
|
|
left join dbo.ICSMOPick b on a.MODetailID= b.MODetailID and a.WorkPoint=b.WorkPoint
|
|
left join (
|
|
select a.TransCode,a.TransSequence,a.LotNo,sum(a.Quantity) as LLQTY from dbo.ICSWareHouseLotInfoLog a
|
|
where a.BusinessCode='13'
|
|
group by a.TransCode,a.TransSequence,a.LotNo) c on a.MOCode=c.TransCode and a.Sequence+'~'+b.Sequence =c.TransSequence
|
|
left join dbo.ICSInventory inv on a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint
|
|
left join dbo.ICSInventoryLot lot on c.LotNo=lot.LotNo and a.WorkPoint=lot.WorkPoint
|
|
left join dbo.ICSExtension cc on lot.ExtensionID=cc.ID and a.WorkPoint=cc.WorkPoint
|
|
left join dbo.ICSInventoryLotDetail dd on C.LotNo=dd.LotNo
|
|
left join dbo.ICSPurchaseOrder po on dd.TransCode=po.POCode and dd.TransSequence = po.Sequence and a.WorkPoint=po.WorkPoint
|
|
LEFT JOIN ICSOtherIn o ON dd.TransCode = o.InCode AND dd.TransSequence = o.Sequence
|
|
where c.LotNo is not null
|
|
;
|
|
|
|
select a.lotno Cominlotno,c.lotno IssueLotNo,C.SortSeq,C.MOCODE,c.InvCode ,c.BatchCode
|
|
into #Temp3333 from #TempMoPickInv c
|
|
inner join #TempMoPickFL a on a.TransCode=c.mocode
|
|
;
|
|
|
|
WITH ICSMoALL AS
|
|
(
|
|
select
|
|
1 AS [Level],
|
|
CAST(ii.SortSeq AS nvarchar(MAX)) AS SortSeq,
|
|
-- 初始层级:SortSeq补零到5位(如1→00001,10→00010)
|
|
CAST(REPLICATE('0', 5 - LEN(CAST(ii.SortSeq AS VARCHAR))) + CAST(ii.SortSeq AS VARCHAR) AS nvarchar(MAX)) AS Sort,
|
|
ii.mocode tmocode,
|
|
cast(ii.mocode as nvarchar(400)) Pmocode,
|
|
cast(rr.TransCode as nvarchar(400)) mocode,
|
|
ii.invcode tinvcode,
|
|
ii.invcode Pivcode,
|
|
ii.invcode invcode,
|
|
ii.BatchCode tBatchCode,
|
|
ii.BatchCode PBatchCode,
|
|
ii.BatchCode BatchCode,
|
|
ii.lotno Tlotno,
|
|
ii.LOTNO PLOTNO,
|
|
ii.lotno
|
|
FROM #TempMoPickInv ii
|
|
left join #TempMoPickFL rr on ii.lotno=rr.lotno
|
|
where ii.mOCode='{0}'
|
|
|
|
UNION ALL
|
|
|
|
select
|
|
b.[Level]+1 AS [Level],
|
|
-- 拼接层级序号(如1.1,10.2)
|
|
CAST(b.SortSeq AS nvarchar(MAX)) + '.' + CAST(c.SortSeq AS nvarchar(MAX)) AS SortSeq,
|
|
-- 核心修改:每一级都补零后拼接(如00001.00001,00010.00002)
|
|
CAST(b.Sort + '.' + REPLICATE('0', 5 - LEN(CAST(c.SortSeq AS VARCHAR))) + CAST(c.SortSeq AS VARCHAR) AS nvarchar(MAX)) AS Sort,
|
|
b.tmocode,
|
|
cast(B.MOCODE as nvarchar(400)) PMOCODE,
|
|
cast(C.MOCODE as nvarchar(400)) MOCODE,
|
|
b.tinvcode,
|
|
B.invcode Pinvcode,
|
|
C.invcode,
|
|
b.tBatchCode,
|
|
B.BatchCode PBatchCode,
|
|
C.BatchCode,
|
|
b.tlotno,
|
|
C.Cominlotno PLOTNO,
|
|
C.IssueLotNo lotno
|
|
FROM #Temp3333 c --工单入---工单领加
|
|
INNER JOIN ICSMoALL b ON b.lotno=C.Cominlotno --上层领料=c.入条码
|
|
where b.[Level]<10
|
|
)
|
|
|
|
SELECT * into #Temp444
|
|
FROM ICSMoALL a
|
|
|
|
select ff.invcode ,ff.lotno,ii.LLQTY , ff.BatchCode,ii.PODocNo,ii.InCode,ii2.mocode,ii3.RKQTY,ff.SortSeq,ff.Sort
|
|
into #Tempgggg
|
|
from #Temp444 ff
|
|
left join #TempMoPickInv ii on ii.lotno=ff.lotno
|
|
left join #Temp3333 ii2 on ii2.Cominlotno=ff.lotno
|
|
left join #TempMoPickFL ii3 on ii3.lotno=ff.lotno
|
|
|
|
-- 最终查询:直接按修正后的Sort字段排序(字符串排序即对应数值层级)
|
|
select
|
|
aa.invcode,
|
|
aa.BatchCode,
|
|
aa.sortseq,
|
|
aa.sort,
|
|
inv.InvName,
|
|
inv.InvStd,
|
|
bb.llqty,
|
|
bb2.RKQTY,
|
|
-- 合并PO单号(去重)
|
|
STUFF((select',' + PODocNo from (SELECT DISTINCT PODocNo FROM #Tempgggg gg where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode) DD for xml path('')),1,1,'') PODocNo,
|
|
-- 合并入库单号(去重)
|
|
STUFF((select',' + InCode from (SELECT DISTINCT InCode FROM #Tempgggg gg where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode) DD for xml path('')),1,1,'') InCode,
|
|
-- 合并工单号(去重)
|
|
STUFF((select',' + mocode from (SELECT DISTINCT mocode FROM #Tempgggg gg where aa.invcode=gg.invcode and aa.BatchCode=gg.BatchCode) DD for xml path('')),1,1,'') mocode
|
|
from (select invcode, BatchCode, sortseq, Sort from #Temp444) aa
|
|
left join (select invcode, BatchCode, sortseq, sum(llqty) llqty from (select * from #Tempgggg) hh group by invcode, BatchCode, sortseq) bb
|
|
on aa.invcode=bb.invcode and aa.BatchCode=bb.BatchCode and aa.sortseq=bb.sortseq
|
|
left join (select invcode, BatchCode, sortseq, sum(RKQTY) RKQTY from (select * from #Tempgggg) hh group by invcode, BatchCode, sortseq) bb2
|
|
on aa.invcode=bb2.invcode and aa.BatchCode=bb2.BatchCode and aa.sortseq=bb2.sortseq
|
|
left join dbo.ICSInventory inv on inv.InvCode=aa.invcode
|
|
-- 直接按修正后的Sort字段排序(无需再处理层级,字符串排序即正确)
|
|
order by aa.sort
|
|
|
|
-- 清理临时表
|
|
DROP TABLE #TempMoPickInv
|
|
DROP TABLE #TempMoPickFL
|
|
DROP table #Temp444
|
|
DROP table #Temp3333
|
|
DROP table #Tempgggg";
|
|
#endregion
|
|
sql = string.Format(sql, queryParam["Code"].ToString());
|
|
//return Repository().FindTableBySql(sql2.ToString());
|
|
DataTable dt = SqlHelper.GetDataTableBySqlDH(sql);
|
|
return dt;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|