From e8823190ca09087a4491eb10da6a7bfc3a45a83a Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 31 Dec 2021 14:45:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/WMS/WMSJitAppService.cs | 41 ++++- .../Entities/WMS-KanBan/WmsKanban.cs | 17 -- .../Report/KanbanUnSettledDapperRepository.cs | 149 ++++++++++++++++++ .../Services/Report/KanBanUnSettledExport.cs | 119 ++++++++++++++ 4 files changed, 305 insertions(+), 21 deletions(-) create mode 100644 src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs create mode 100644 src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSJitAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSJitAppService.cs index faa2ac24..251b7876 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSJitAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSJitAppService.cs @@ -57,7 +57,7 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts [AllowAnonymous] [Route("api/settleaccount/wmsjitoutput")] public class WMSJitAppService : - ApplicationService + SettleAccountApplicationBase { private readonly ISettleAccountBranchEfCoreRepository _wmsRepository; private readonly ISettleAccountBranchEfCoreRepository _wmsVersionRepository; @@ -76,12 +76,15 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts /// public WMSJitAppService( IExcelImportAppService excelImportService, - ISettleAccountBranchEfCoreRepository wmsRepository, + ISettleAccountBranchEfCoreRepository wmsRepository, ISettleAccountBranchEfCoreRepository job, ISettleAccountBranchEfCoreRepository wmsVersionRepository, WMSEfCoreRepository wmsefRespository, - WMSEfCoreRepository wmstbRespository - ) + WMSEfCoreRepository wmstbRespository, + IDistributedCache cache, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) { _job = job; _wmstbRespository = wmstbRespository; @@ -129,8 +132,38 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts } _lst.AddRange(_lsCopy.ToArray()); + + + + + var _ls1 = _lst.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList(); var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); + + + var error = from itm1 in outPutDetail + join itm2 in _ls1 on + new { itm1.MaterialCode, itm1.KennCode, itm1.ChassisNumber } + equals + new { itm2.MaterialCode, itm2.KennCode, itm2.ChassisNumber } + select itm1; + var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + + var checkList = new List(); + foreach (var itm in errList) + { + checkList.Add( new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); + } + + + if (checkList.Count > 0) + { + + return await ExportErrorReportAsync(checkList); + } + + + var query = from itm1 in _ls1 join itm2 in outPutDetail on new { itm1.MaterialCode, itm1.KennCode, itm1.ChassisNumber } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/WMS-KanBan/WmsKanban.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/WMS-KanBan/WmsKanban.cs index be78576f..2462194e 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/WMS-KanBan/WmsKanban.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/WMS-KanBan/WmsKanban.cs @@ -15,36 +15,19 @@ namespace Win.Sfs.SettleAccount.Entities.WMS_KanBan /// public DateTime BeginTime { set; get; } - - /// /// /// public string Version { set; get; } - - - - - /// /// 零件号 /// public string MaterialCode { set; get; } - - /// /// 用量 /// public decimal Qty { set; get; } - - - - - - - - } } 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 new file mode 100644 index 00000000..ad223d09 --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs @@ -0,0 +1,149 @@ +using Dapper; +using Magicodes.ExporterAndImporter.Core; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories.Dapper; +using Volo.Abp.EntityFrameworkCore; +using Win.Sfs.SettleAccount.Entities.FISes; +using Win.Sfs.SettleAccount.FISes; +//using Win.Sfs.Shared.Enums.SettleAccount; + +namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report +{ + public class KanbanUnSettled + { + [ExporterHeader(DisplayName = "交货单号")] + public string WmsBillNum { set; get; } + [ExporterHeader(DisplayName = "发货日期")] + public string BeginDate { set; get; } + [ExporterHeader(DisplayName = "看板号")] + public string Kanban { set; get; } + [ExporterHeader(DisplayName = "零件号")] + public string SapCode { set; get; } + [ExporterHeader(DisplayName = "零件描述")] + public string MaterialDesc { set; get; } + [ExporterHeader(DisplayName = "客户零件号")] + public string CustomerPartCode { set; get; } + [ExporterHeader(DisplayName = "物料组")] + public string MaterialGroup { set; get; } + [ExporterHeader(DisplayName = "结算数量")] + public decimal SettleQty { set; get; } + [ExporterHeader(DisplayName = "发货数量")] + public decimal Qty { set; get; } + [ExporterHeader(DisplayName = "量差")] + public decimal DiffQty { set; get; } + [ExporterHeader(DisplayName = "单价")] + public decimal Price { set; get; } + [ExporterHeader(DisplayName = "差异金额")] + public decimal DiffAMT { set; get; } + } + + public class KanbanUnSettledExtend + { + + [ExporterHeader(DisplayName = "客户物料号")] + public string MaterialCode { set; get; } + [ExporterHeader(DisplayName = "物料号")] + 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; } + [ExporterHeader(DisplayName = "发货数量")] + public string Qty { set; get; } + [ExporterHeader(DisplayName = "结算数量")] + public string SettleQty { set; get; } + [ExporterHeader(DisplayName = "量差")] + public string DiffQty { set; get; } + [ExporterHeader(DisplayName = "单价")] + public string Price { set; get; } + [ExporterHeader(DisplayName = "差异金额")] + public string DiffAMT { set; get; } + + + + } + + + + + + public class KanbanUnSettledDapperRepository : DapperRepository, ITransientDependency + { + public KanbanUnSettledDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + { + + } + public virtual List GetKanbanReportList( string version, string begintime, string 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" + + " a.WMSActualGoodsDate 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" + + " a.Qty,\n" + + " (\n" + + " a.Qty - ISNULL( b.Qty, 0 )) AS DiffQty \n" + + " FROM\n" + + " Set_WMSKanBanSettle A\n" + + " LEFT JOIN ( SELECT * FROM Set_KanBanSettle WHERE version = '{0}' ) 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" + + " ) TEMP1\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode"; + string str = string.Empty; + str += " where 1=1 "; + 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" + + " TEMP1.*,\n" + + " TEMP2.Price,\n" + + " ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " a.MaterialCode,\n" + + " C.MaterialCode SapCode,\n" + + " C.MaterialDesc,\n" + + " C.CustomerPartCode,\n" + + " C.EstimateTypeDesc MaterialGroup,\n" + + " isnull( a.Qty, 0 ) Qty,\n" + + " isnull( b.Qty, 0 ) SettleQty,\n" + + " isnull( a.Qty, 0 )- isnull( b.Qty, 0 ) DiffQty \n" + + " FROM\n" + + " ( SELECT SUM( Qty ) Qty, MaterialCode FROM Set_WMSKanBanSettle WHERE PartType = 1 GROUP BY MaterialCode ) a\n" + + " LEFT JOIN ( SELECT sum( qty ) Qty, MaterialCode FROM Set_KanBanSettle GROUP BY MaterialCode ) b ON a.MaterialCode = b.MaterialCode\n" + + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode \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"; + string str = string.Empty; + str += " where 1=1 "; + var _query = DbConnection.Query(sql, null, null, true, 1200, null); + var _list = _query.ToList(); + return _list; + } + + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs new file mode 100644 index 00000000..ff588b05 --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs @@ -0,0 +1,119 @@ +using Magicodes.ExporterAndImporter.Excel; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaskJob.EventArgs; +using TaskJob.Interfaces; +using Volo.Abp.BlobStoring; +using Volo.Abp.DependencyInjection; +using Win.Sfs.BaseData.ImportExcelCommon; +using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; + +namespace SettleAccount.Job.Services.Report +{ + public class KanBanUnSettledExport : ITransientDependency, IExportJob + { + + private readonly OutputService _outputService; + KanbanUnSettledDapperRepository _dapper; + private readonly IBlobContainer _fileContainer; + + public KanBanUnSettledExport(KanbanUnSettledDapperRepository dapper, OutputService outputService, + + IBlobContainer fileContainer + ) + { + + _dapper = dapper; + _outputService = outputService; + + _fileContainer = fileContainer; + } + + public string ExportFile(Guid id, List exportName, List p_list) + { + var _filename = exportName.FirstOrDefault(); + var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; + var materialCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; + var begin = p_list.Where(p => p.Name == "BeginTime").FirstOrDefault().Value; + var end = p_list.Where(p => p.Name == "EndTime").FirstOrDefault().Value; + var cp7begin = p_list.Where(p => p.Name == "Cp7BeginTime").FirstOrDefault().Value; + var cp7end = p_list.Where(p => p.Name == "Cp7EndTime").FirstOrDefault().Value; + var kenncode = p_list.Where(p => p.Name == "KennCode").FirstOrDefault().Value; + var chassisNumber = p_list.Where(p => p.Name == "ChassisNumber").FirstOrDefault().Value; + var materialGroup = p_list.Where(p => p.Name == "MaterialGroup").FirstOrDefault().Value; + var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value; + var _ls = _dapper.GetKanbanReportList(version, begin,end); + var _lst = _dapper.GetNoKanbanReportList(version, begin, end); + + + + if (!string.IsNullOrEmpty(materialGroup)) + { + var _groupList = materialGroup.Split(new char[] { ',' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _ls = _ls.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); + } + } + if (!string.IsNullOrEmpty(materialCode)) + { + var _groupList = materialCode.Split(new char[] { '\n' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _ls = _ls.Where(p => _groupList.Contains(p.CustomerPartCode)).ToList(); + } + } + if (!string.IsNullOrEmpty(sapCode)) + { + var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _ls = _ls.Where(p => _groupList.Contains(p.SapCode)).ToList(); + } + } + + + if (!string.IsNullOrEmpty(materialGroup)) + { + var _groupList = materialGroup.Split(new char[] { ',' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _lst = _lst.Where(p => _groupList.Contains(p.MaterialGroup)).ToList(); + } + } + if (!string.IsNullOrEmpty(materialCode)) + { + var _groupList = materialCode.Split(new char[] { '\n' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _lst = _lst.Where(p => _groupList.Contains(p.MaterialCode)).ToList(); + } + } + if (!string.IsNullOrEmpty(sapCode)) + { + var _groupList = sapCode.Split(new char[] { '\n' }).Distinct().ToList(); + if (_groupList.Count() > 0) + { + _lst = _lst.Where(p => _groupList.Contains(p.SapCode)).ToList(); + } + } + + + ExcelExporter _exporter = new ExcelExporter();//导出Excel + var result = _exporter.Append(_ls.ToList(), "有看板号未结差异对比") + .SeparateBySheet() + .Append(_lst.ToList(), "无看板号未结差异对比") + .ExportAppendDataAsByteArray(); + result.ShouldNotBeNull(); + _fileContainer.SaveAsync(_filename, result.Result, true); + + + + return id.ToString(); + } + } +}