From d651bcdf14c623897fec6742e5c346900966a5ba Mon Sep 17 00:00:00 2001 From: 44673626 <44673626@qq.com> Date: Tue, 29 Mar 2022 16:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BC=97=E7=9C=8B=E6=9D=BF=E6=9C=AA?= =?UTF-8?q?=E7=BB=93=E7=9B=B8=E5=85=B3=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Report/KanbanUnSettledDapperRepository.cs | 306 +++++++++++++++++- .../Services/Report/KanBanUnSettledExport.cs | 24 +- 2 files changed, 309 insertions(+), 21 deletions(-) diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs index 7658fcfa..46b7a6b6 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs @@ -94,25 +94,16 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report public class KanbanUnSettledExtend { - - - - - - - - - -[ExporterHeader(DisplayName = "客户物料号")] + [ExporterHeader(DisplayName = "客户物料号")] public string MaterialCode { set; get; } [ExporterHeader(DisplayName = "物料号")] - public string SapCode { set; get; } + public string SapCode { set; get; } [ExporterHeader(DisplayName = "物料名称")] public string MaterialDesc { set; get; } //[ExporterHeader(DisplayName = "ERP物料号")] //public string CustomerPartCode { set; get; } [ExporterHeader(DisplayName = "物料组车型")] - public string MaterialGroup { set; get; } + public string MaterialGroup { set; get; } [ExporterHeader(DisplayName = "发货数量")] public string Qty { set; get; } [ExporterHeader(DisplayName = "结算数量")] @@ -130,6 +121,18 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report + public class CompareKanban + { + public string WmsBillNum { set; get; } + public string MaterialCode { set; get; } + public string Kanban { set; get; } + + public string WmsDate { set; get; } + + } + + + public class KanbanUnSettledDapperRepository : DapperRepository, ITransientDependency @@ -139,6 +142,200 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } public virtual List GetKanbanReportList(string version, string begintime, string endtime, string iscontionversion) + { + string contion = string.Empty; + //选中,是否过滤掉当期结算数据 + if (iscontionversion == "0") + { + contion += string.Format(" WHERE Version <'{0}' ", version); + } + else + { + contion += " WHERE 1=1 "; + } + + string str = string.Empty; + //str += " where 1=1 "; + if (!string.IsNullOrEmpty(begintime) && Convert.ToDateTime(begintime) != DateTime.MinValue) + { + str += string.Format(" and a.WMSActualGoodsDate >='{0}' ", begintime); + } + if (!string.IsNullOrEmpty(endtime) && Convert.ToDateTime(endtime) != DateTime.MinValue) + { + str += string.Format(" and a.WMSActualGoodsDate<='{0}' ", endtime); + } + + string sql = "SELECT\n" + + " * \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " TEMP1.*,\n" + + " TEMP2.Price,\n" + + " ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " '' WmsBillNum,\n" + + " CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" + + " a.Kanban,\n" + + " C.MaterialCode SapCode,\n" + + " C.MaterialDesc,\n" + + " C.CustomerPartCode,\n" + + " C.EstimateTypeDesc MaterialGroup,\n" + + " ISNULL( B.Qty, 0 ) SettleQty,\n" + + " ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" + + " isnull( tt.qty, 0 ) BackQty,\n" + + " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + + " FROM\n" + + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n" + + " LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" + + " AND a.MaterialCode = b.MaterialCode \n" + + " WHERE\n" + + " B.Kanban IS NULL \n" + + " AND B.MaterialCode IS NULL {0} \n" + + " ) TEMP1\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n" + + " ) UNION1 UNION ALL\n" + + "SELECT\n" + + " * \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " TEMP1.*,\n" + + " TEMP2.Price,\n" + + " ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " '' WmsBillNum,\n" + + " CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" + + " a.Kanban,\n" + + " C.MaterialCode SapCode,\n" + + " C.MaterialDesc,\n" + + " C.CustomerPartCode,\n" + + " C.EstimateTypeDesc MaterialGroup,\n" + + " ISNULL( B.Qty, 0 ) SettleQty,\n" + + " ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" + + " isnull( tt.qty, 0 ) BackQty,\n" + + " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + + " FROM\n" + + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n" + + " INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" + + " AND a.MaterialCode = b.MaterialCode \n" + + " WHERE\n" + + " a.WMSDeliveryQty> B.Qty {0}\n" + + " ) TEMP1\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n" + + " ) UNION2"; + + + + sql = string.Format(sql, str, contion,version); + + + //发运数据中,查出看板号+物料号相同的重复数据 + var sql2 = "SELECT\n" + + " a.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " a.Kanban ,\n" + + " A.LastModificationTime WmsDate \n" + + "FROM\n" + + " Set_WMSKanBanSettle A\n" + + " INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode"; + var listCompare = DbConnection.Query(sql2); + + + //查询发运表中,看权号+物料号没有重复的数据 + var sql3 = "SELECT\n" + + " a.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " a.Kanban,\n" + + " A.LastModificationTime WmsDate \n" + + "FROM\n" + + " Set_WMSKanBanSettle A\n" + + " LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" + + "WHERE\n" + + " B.Kanban IS NULL"; + + var listCompare1 = DbConnection.Query(sql3); + + + //发运数据比较 + List _ls = new List(); + foreach (var itm in listCompare.ToList()) + { + var first = _ls.FirstOrDefault(p => p.Kanban == itm.Kanban && p.MaterialCode == itm.MaterialCode); + if (first != null) + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + + first.WmsBillNum += "," + itm.WmsBillNum; + first.WmsDate += "," + itm.WmsDate; + } + else + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + _ls.Add(itm); + } + + } + + foreach (var itm in listCompare1.ToList()) + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + _ls.Add(itm); + } + + var _query = DbConnection.Query(sql, null, null, true, 1200, null); + var _list = _query.ToList(); + + + //数据整合,相同看板号+物料号的交货单号合并成一行中以逗号分隔 + foreach (var itm1 in _list) + { + var itm = _ls.FirstOrDefault(p => p.Kanban == itm1.WmsBillNum && p.MaterialCode == itm1.SapCode); + if (itm != null) + { + itm1.WmsBillNum = itm.WmsBillNum; + itm1.BeginDate = itm.WmsDate; + } + } + + + + + return _list; + } + + /// + /// 原始看板未结数据 + /// + /// + /// + /// + /// + /// + public virtual List GetOriginalKanbanReportList(string version, string begintime, string endtime, string iscontionversion) { string contion = string.Empty; //选中,是否过滤掉当期结算数据 @@ -186,7 +383,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " AND A.MaterialCode = B.MaterialCode\n" + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode \n" + - " left join set_backQty as tt on a.Kanban = tt.Code and a.MaterialCode = b.MaterialCode and a.version='"+version+"'\n"+ + " left join set_backQty as tt on a.Kanban = tt.Code and a.MaterialCode = b.MaterialCode and a.version='" + version + "'\n" + " WHERE\n" + " B.Kanban IS NULL \n" + " AND B.MaterialCode IS NULL {0}\n" + @@ -194,12 +391,93 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode"; - + sql = string.Format(sql, str, contion); var _query = DbConnection.Query(sql, null, null, true, 1200, null); var _list = _query.ToList(); return _list; } + + + /// + /// 有发货有结算,且发货数量大于结算数量的数据,将要整合到未结数据中 + /// + /// + /// + /// + /// + /// + public virtual List GetWMSKanbanReportList(string version, string begintime, string endtime, string iscontionversion) + { + string contion = string.Empty; + //选中,是否过滤掉当期结算数据 + if (iscontionversion == "0") + { + contion += string.Format(" WHERE Version <'{0}' ", version); + } + else + { + contion += " WHERE 1=1 "; + } + + string str = string.Empty; + //str += " where 1=1 "; + if (!string.IsNullOrEmpty(begintime) && Convert.ToDateTime(begintime) != DateTime.MinValue) + { + str += string.Format(" and a.WMSActualGoodsDate >='{0}' ", begintime); + } + if (!string.IsNullOrEmpty(endtime) && Convert.ToDateTime(endtime) != DateTime.MinValue) + { + str += string.Format(" and a.WMSActualGoodsDate<='{0}' ", endtime); + } + + string sql = "SELECT\n" + + " TEMP1.*,\n" + + " TEMP2.Price,\n" + + " ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " a.WMSDeliveryNote WmsBillNum,\n" + + " CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" + + " a.Kanban,\n" + + " C.MaterialCode SapCode,\n" + + " C.MaterialDesc,\n" + + " C.CustomerPartCode,\n" + + " C.EstimateTypeDesc MaterialGroup,\n" + + " ISNULL( B.Qty, 0 ) SettleQty,\n" + + " ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" + + " isnull( tt.qty, 0 ) BackQty,\n" + + " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + + " FROM\n" + + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate ) A\n" + + " INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban\n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" + + " AND a.MaterialCode = b.MaterialCode \n" + + " WHERE\n" + + " a.WMSDeliveryQty> B.Qty {0}\n" + + " ) TEMP1\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode"; + + + + sql = string.Format(sql, str, contion,version); + var _query = DbConnection.Query(sql, null, null, true, 1200, null); + var _list = _query.ToList(); + return _list; + } + + + + + + + + + + public virtual List GetNoKanbanReportList(string version, string begintime, string endtime) { var sql = "SELECT\n" + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs index 9c3cfa91..60f5a700 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs @@ -45,8 +45,15 @@ namespace SettleAccount.Job.Services.Report var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value; - var _ls = _dapper.GetKanbanReportList(version, begin,end, iscontionversion); - // var _lst = _dapper.GetNoKanbanReportList(version, begin, end); + var _ls = _dapper.GetKanbanReportList(version, begin, end, iscontionversion); + + //有发货有结算,且发货数量大于结算 + var _ls_wmskanban = _dapper.GetWMSKanbanReportList(version, begin, end, iscontionversion); + + //原始看板未对比数据 + var _ls_orgiinal_kanban = _dapper.GetOriginalKanbanReportList(version, begin, end, iscontionversion); + + // var _lst = _dapper.GetNoKanbanReportList(version, begin, end); //if (!string.IsNullOrEmpty(materialGroup)) //{ // var _groupList = materialGroup.Split(new char[] { ',' }).Distinct().ToList(); @@ -55,7 +62,7 @@ namespace SettleAccount.Job.Services.Report // _ls = _ls.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); // } //} - + if (!string.IsNullOrEmpty(sapCode)) { var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList(); @@ -81,7 +88,7 @@ namespace SettleAccount.Job.Services.Report _ls = _ls.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); } } - + @@ -94,10 +101,13 @@ namespace SettleAccount.Job.Services.Report // _lst = _lst.Where(p => _groupList.Contains(p.MaterialCode)).ToList(); // } //} - + ExcelExporter _exporter = new ExcelExporter();//导出Excel - var result = _exporter.Append(_ls.ToList(), "有发货无结算差异对比") - + var result = _exporter.Append(_ls.ToList(), "有发货无结算差异原始对比") + .SeparateBySheet() + .Append(_ls_orgiinal_kanban.ToList(), "原始看板未结对比数据") + .SeparateBySheet() + .Append(_ls_wmskanban.ToList(), "有发货有结算(发货数量大于结算)") .ExportAppendDataAsByteArray(); result.ShouldNotBeNull(); _fileContainer.SaveAsync(_filename, result.Result, true);