diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSKanBan/IWMSVWKanBanAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSKanBan/IWMSVWKanBanAppService.cs index 1ef8185e..35b74168 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSKanBan/IWMSVWKanBanAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSKanBan/IWMSVWKanBanAppService.cs @@ -21,7 +21,7 @@ namespace Win.Sfs.SettleAccount.Entities.WMSKanBan /// 上传的文件(前端已经限制只能上传一个附件) /// - Task WMSVWKanBanUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode); + // Task WMSVWKanBanUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode); diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSSparePart/IWMSSparePartAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSSparePart/IWMSSparePartAppService.cs index 6696223f..56ee2272 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSSparePart/IWMSSparePartAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/WMSSparePart/IWMSSparePartAppService.cs @@ -17,8 +17,8 @@ namespace Win.Sfs.SettleAccount.Entities.WMSSparePart /// 上传的文件(前端已经限制只能上传一个附件) /// - Task WMSSparePartUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, - string year, string period, string version, string customerCode); + //Task WMSSparePartUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, + // string year, string period, string version, string customerCode); /// /// 按ID获取唯一实体 diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-KanBan/WMSKanBanAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-KanBan/WMSKanBanAppService.cs new file mode 100644 index 00000000..07c1a9ee --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-KanBan/WMSKanBanAppService.cs @@ -0,0 +1,322 @@ +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Csv; +using Magicodes.ExporterAndImporter.Excel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Guids; +using Win.Sfs.BaseData.ImportExcelCommon; +using Win.Sfs.SettleAccount.Entities.WMSKanBan; +using Win.Sfs.Shared.Filter; +using Shouldly; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Caching; +using Win.Abp.Snowflakes; +using Win.Sfs.SettleAccount.CommonManagers; +using Volo.Abp; +using Microsoft.AspNetCore.Http; +using Win.Sfs.SettleAccount.ExcelImporter; +using EFCore.BulkExtensions; +using Win.Sfs.SettleAccount.ExportReports; +using Volo.Abp.Domain.Repositories; +using Win.Sfs.SettleAccount.Constant; +using Microsoft.AspNetCore.Authorization; +using Volo.Abp.Application.Dtos; + +namespace Win.Sfs.SettleAccount.Entities.WMS_KanBan +{ + /// + /// 大众看板发货明细 + /// + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + //[AllowAnonymous] + [Route("api/settleaccount/WMSVWKanBan")] + public class WMSKanBanAppService : SettleAccountApplicationBase, IWMSVWKanBanAppService + { + private readonly IGuidGenerator _guidGenerator; + + private readonly IExcelImportAppService _excelImportService; + + private readonly ISettleAccountBranchEfCoreRepository _versionRepository; + + private readonly ISettleAccountBranchEfCoreRepository _repository; + /// + /// 构建方法 + /// + /// 构建UID + /// 仓储接口 + /// 缓存 + public WMSKanBanAppService(IGuidGenerator guidGenerator, + ISettleAccountBranchEfCoreRepository versionRepository, + ISettleAccountBranchEfCoreRepository repository, + IDistributedCache cache, + IExcelImportAppService excelImportService, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) + { + _versionRepository = versionRepository; + _guidGenerator = guidGenerator; + _excelImportService = excelImportService; + _repository = repository; + } + + + /// + /// 导入功能 + /// + /// 上传的文件(前端已经限制只能上传一个附件) + /// + [HttpPost] + [Route("ExcelImport")] + [DisableRequestSizeLimit] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + public async Task WMSVWKanBanUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode) + { + if (string.IsNullOrEmpty(version)) + { + throw new BusinessException("版本不能空,必须传入!"); + } + List listImport = new List(); + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.UploadExcelImport(files, _excelImportService); + var entityList = ObjectMapper.Map, List>(result); + //删除版本 + var _versionQuery = _versionRepository.Where(p => p.Version == version); + await _versionQuery.BatchDeleteAsync(); + //删除明细 + var _query = _repository.Where(p => p.Version == version); + await _query.BatchDeleteAsync(); + //插入数据前检验 + var checkList = new List(); + var _group = entityList.GroupBy(x => new { x.Kanban, x.MaterialCode, x.Version }).Select(p => new { Count = p.Count(), Kanban = p.Key.Kanban, MaterialCode = p.Key.MaterialCode }); + foreach (var itm in _group) + { + if (itm.Count > 1) + { + checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("导入的零件号{0},其看板条码号{1}有重复数据,请检查!", itm.MaterialCode, itm.Kanban), string.Empty)); + } + } + var _id = GuidGenerator.Create(); + var _bomList = new List(); + _bomList.Add(new WMSKanBanVersion(_id, branchId, year, period, version, customerCode)); + foreach (var itm in entityList) + { + itm.SetValue(GuidGenerator.Create(), branchId, year, period, version, _id); + } + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + await _repository.GetDbContext().BulkInsertAsync(entityList); + await _versionRepository.GetDbContext().BulkInsertAsync(_bomList); + return ApplicationConsts.SuccessStr; + } + + /// + /// 按ID获取唯一实体 + /// + /// + /// 返回实体全部属性 + /// + /// ID + /// 实体DTO + [HttpGet] + [Route("{id}")] + [Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task GetAsync(Guid id) + { + var result = await GetFromCacheAsync(id); + var dto = ObjectMapper.Map(result); + return dto; + } + + + private async Task GetFromCacheAsync(Guid id) + { + var result = await _repository.GetAsync(id); + return result; + } + + + private async Task GetCountAsync(WMSVWKanBanRequestDto input) + { + return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); + } + + private async Task GetCountAsync(WMSVWKanBanVersionRequestDto input) + { + return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); + } + + + /// + /// 导出文件 + /// + /// + /// + [HttpPost] + [Route("Export")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task ExportAsync(WMSVWKanBanRequestDto input) + { + + IExporter _csv = new CsvExporter(); + IExporter _excel = new ExcelExporter(); + + if (!string.IsNullOrEmpty(input.Version)) + { + input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version }); + } + var entities = await _repository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, int.MaxValue, + 0, true); + + var dtoDetails = ObjectMapper.Map, List>(entities); + + string _fileName = string.Empty; + //声明导出容器 + + byte[] result = null; + switch (input.FileType) + { + case 0: + _fileName = string.Format("大众看板发货明细_{0}.csv", input.UserId.ToString()); + result = await _csv.ExportAsByteArray(dtoDetails); + break; + case 1: + _fileName = string.Format("大众看板发货明细_{0}.xlsx", input.UserId.ToString()); + result = await _excel.ExportAsByteArray(dtoDetails); + break; + } + result.ShouldNotBeNull(); + + //保存导出文件到服务器存成二进制 + await _excelImportService.SaveBlobAsync( + new SaveExcelImportInputDto + { + Name = _fileName, + Content = result + } + ); + return _fileName; + } + + + /// + /// 根据筛选条件获取实体列表 + /// + /// + /// 请求条件包括:筛选条件列表,排序条件,数据数量,页码 + /// + /// 请求条件 + /// 实体DTO列表 + [HttpPost] + [Route("list")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task> GetListAsync(WMSVWKanBanRequestDto input) + { + + if (!string.IsNullOrEmpty(input.Version)) + { + input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version }); + } + else + { + return new PagedResultDto(0, new List()); + } + var entities = await _repository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, input.MaxResultCount, + input.SkipCount, true); + var totalCount = await GetCountAsync(input); + var dtos = ObjectMapper.Map, List>(entities); + return new PagedResultDto(totalCount, dtos); + } + + + /// + /// 获取实体总数 + /// + /// 实体总数 + [HttpGet] + [Route("count")] + [Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task GetTotalCountAsync(Guid branchId) + { + return await _repository.GetCountAsync(branchId); + } + + /// + /// 获取全部实体列表 + /// + /// 实体DTO列表 + [HttpGet] + [Route("all")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task> GetAllAsync(Guid branchId) + { + var entities = await _repository.GetAllAsync(branchId, true); + + + var dtos = ObjectMapper.Map, List>(entities); + + + return new ListResultDto(dtos); + } + + + + /// + /// 删除实体 + /// + /// ID + /// + [HttpDelete] + [Route("{id}")] + /// [Authorize(SettleAccountPermissions.SettleAccounts.Delete)] + virtual public async Task DeleteAsync(Guid id) + { + await _repository.DeleteAsync(id); + } + + /// + /// 按IDs删除实体列表 + /// + /// IDs + /// 是否执行成功 + [HttpPost] + [Route("delete")] + // [Authorize(SettleAccountPermissions.SettleAccounts.Delete)] + virtual public async Task DeleteListAsync(List ids) + { + foreach (var id in ids) + { + var entity = await GetFromCacheAsync(id); + //await Cache.DeleteAsync(id.ToString()); + } + + return await _repository.DeleteListAsync(ids); + } + + + + /// + /// 版本列表查询 + /// + /// + /// + [HttpPost] + [Route("listversion")] + public async Task> GetVersionListAsync(WMSVWKanBanVersionRequestDto input) + { + var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, + input.SkipCount, true); + + var totalCount = await GetCountAsync(input); + var dtos = ObjectMapper.Map, List>(entities); + + return new PagedResultDto(totalCount, dtos); + } + + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-SparePart/WMSSparePartAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-SparePart/WMSSparePartAppService.cs new file mode 100644 index 00000000..59bd24f0 --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS-SparePart/WMSSparePartAppService.cs @@ -0,0 +1,326 @@ +using EFCore.BulkExtensions; +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Csv; +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Caching; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Guids; +using Win.Abp.Snowflakes; +using Win.Sfs.BaseData.ImportExcelCommon; +using Win.Sfs.SettleAccount.CommonManagers; +using Win.Sfs.SettleAccount.Constant; +using Win.Sfs.SettleAccount.Entities.WMSSparePart; +using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.SettleAccount.ExportReports; +using Win.Sfs.Shared.Filter; +using Shouldly; + + + + +namespace Win.Sfs.SettleAccount.Entities.WMS_SparePart +{ + /// + /// 大众备件服务 + /// + [Route("api/settleaccount/WMSSparePart")] + public class WMSSparePartAppService : SettleAccountApplicationBase, IWMSSparePartAppService + { + private readonly IGuidGenerator _guidGenerator; + + private readonly IExcelImportAppService _excelImportService; + + private readonly ISettleAccountBranchEfCoreRepository _versionRepository; + + private readonly ISettleAccountBranchEfCoreRepository _repository; + /// + /// 构建方法 + /// + /// 构建UID + /// 仓储接口 + /// 缓存 + public WMSSparePartAppService(IGuidGenerator guidGenerator, + ISettleAccountBranchEfCoreRepository versionRepository, + ISettleAccountBranchEfCoreRepository repository, + IDistributedCache cache, + IExcelImportAppService excelImportService, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) + { + _versionRepository = versionRepository; + _guidGenerator = guidGenerator; + _excelImportService = excelImportService; + _repository = repository; + } + + + /// + /// 导入功能 + /// + /// 上传的文件(前端已经限制只能上传一个附件) + /// + [HttpPost] + [Route("ExcelImport")] + [DisableRequestSizeLimit] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + public async Task WMSSparePartUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode) + { + if (string.IsNullOrEmpty(version)) + { + throw new BusinessException("版本不能空,必须传入!"); + } + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.UploadExcelImport(files, _excelImportService); + var entityList = ObjectMapper.Map, List>(result); + //删除版本 + var _versionQuery = _versionRepository.Where(p => p.Version == version); + await _versionQuery.BatchDeleteAsync(); + //删除明细 + var _query = _repository.Where(p => p.Version == version); + await _query.BatchDeleteAsync(); + //插入数据前检验 + var checkList = new List(); + var _group = entityList.GroupBy(x => new { x.LineNumber, x.MaterialCode, x.Version }).Select(p => new { Count = p.Count(), LineNumber = p.Key.LineNumber, MaterialCode = p.Key.MaterialCode }); + foreach (var itm in _group) + { + if (string.IsNullOrEmpty(itm.MaterialCode)) + { + checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("导入的行号为{0}的物料代码为空,请检查!", itm.LineNumber), string.Empty)); + } + } + var _id = GuidGenerator.Create(); + var _bomList = new List(); + _bomList.Add(new WMSSparePartVersion(_id, branchId, year, period, version, customerCode)); + foreach (var itm in entityList) + { + itm.SetValue(GuidGenerator.Create(), branchId, year, period, version); + } + if (checkList.Count > 0) + { + return await ExportErrorReportAsync(checkList); + } + await _repository.GetDbContext().BulkInsertAsync(entityList); + await _versionRepository.GetDbContext().BulkInsertAsync(_bomList); + return ApplicationConsts.SuccessStr; + } + + /// + /// 按ID获取唯一实体 + /// + /// + /// 返回实体全部属性 + /// + /// ID + /// 实体DTO + [HttpGet] + [Route("{id}")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task GetAsync(Guid id) + { + var result = await GetFromCacheAsync(id); + var dto = ObjectMapper.Map(result); + return dto; + } + + + private async Task GetFromCacheAsync(Guid id) + { + var result = await _repository.GetAsync(id); + return result; + } + + + private async Task GetCountAsync(WMSSparePartRequestDto input) + { + return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); + } + + private async Task GetCountAsync(WMSSparePartVersionRequestDto input) + { + return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); + } + + + /// + /// 导出文件 + /// + /// + /// + [HttpPost] + [Route("Export")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task ExportAsync(WMSSparePartRequestDto input) + { + if (string.IsNullOrEmpty(input.Version)) + { + throw new BusinessException("版本不能空,必须传入!"); + } + IExporter _csv = new CsvExporter(); + IExporter _excel = new ExcelExporter(); + if (!string.IsNullOrEmpty(input.Version)) + { + input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version }); + } + var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, + 0, true); + + var dtoDetails = ObjectMapper.Map, List>(entities); + + string _fileName = string.Empty; + //声明导出容器 + + byte[] result = null; + switch (input.FileType) + { + case 0: + _fileName = string.Format("大众备件发货明细_{0}.csv", input.UserId.ToString()); + result = await _csv.ExportAsByteArray(dtoDetails); + break; + case 1: + _fileName = string.Format("大众备件发货明细_{0}.xlsx", input.UserId.ToString()); + result = await _excel.ExportAsByteArray(dtoDetails); + break; + } + result.ShouldNotBeNull(); + + //保存导出文件到服务器存成二进制 + await _excelImportService.SaveBlobAsync( + new SaveExcelImportInputDto + { + Name = _fileName, + Content = result + } + ); + return _fileName; + } + + + /// + /// 根据筛选条件获取实体列表 + /// + /// + /// 请求条件包括:筛选条件列表,排序条件,数据数量,页码 + /// + /// 请求条件 + /// 实体DTO列表 + [HttpPost] + [Route("list")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task> GetListAsync(WMSSparePartRequestDto input) + { + if (!string.IsNullOrEmpty(input.Version)) + { + input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version }); + } + else + { + return new PagedResultDto(0, new List()); + } + + var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, input.MaxResultCount, + input.SkipCount, true); + + var totalCount = await GetCountAsync(input); + var dtos = ObjectMapper.Map, List>(entities); + + return new PagedResultDto(totalCount, dtos); + } + + + /// + /// 获取实体总数 + /// + /// 实体总数 + [HttpGet] + [Route("count")] + [Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task GetTotalCountAsync(Guid branchId) + { + return await _repository.GetCountAsync(branchId); + } + + /// + /// 获取全部实体列表 + /// + /// 实体DTO列表 + [HttpGet] + [Route("all")] + //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + virtual public async Task> GetAllAsync(Guid branchId) + { + var entities = await _repository.GetAllAsync(branchId, true); + + + var dtos = ObjectMapper.Map, List>(entities); + + + return new ListResultDto(dtos); + } + + + + /// + /// 删除实体 + /// + /// ID + /// + [HttpDelete] + [Route("{id}")] + /// [Authorize(SettleAccountPermissions.SettleAccounts.Delete)] + virtual public async Task DeleteAsync(Guid id) + { + await _repository.DeleteAsync(id); + } + + /// + /// 按IDs删除实体列表 + /// + /// IDs + /// 是否执行成功 + [HttpPost] + [Route("delete")] + // [Authorize(SettleAccountPermissions.SettleAccounts.Delete)] + virtual public async Task DeleteListAsync(List ids) + { + foreach (var id in ids) + { + var entity = await GetFromCacheAsync(id); + //await Cache.DeleteAsync(id.ToString()); + } + + return await _repository.DeleteListAsync(ids); + } + + + + /// + /// 版本列表查询 + /// + /// + /// + [HttpPost] + [Route("listversion")] + public async Task> GetVersionListAsync(WMSSparePartVersionRequestDto input) + { + var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, + input.SkipCount, true); + + var totalCount = await GetCountAsync(input); + var dtos = ObjectMapper.Map, List>(entities); + + return new PagedResultDto(totalCount, dtos); + } + + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs index 1559a11a..0c3076d6 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs @@ -55,10 +55,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices ISettleAccountBranchEfCoreRepository settlementPartVersionrepository, ISettleAccountBranchEfCoreRepository fisVersionrepository, ISettleAccountBranchEfCoreRepository itemInvoicePriceVersionrepository, - //ISettleAccountBranchEfCoreRepository materialRepository, - //ISettleAccountBranchEfCoreRepository repository, - //ISettleAccountBranchEfCoreRepository versionRepository, - //IDistributedCache cache, + IExcelImportAppService excelImportService, //ISnowflakeIdGenerator snowflakeIdGenerator, //ICommonManager commonManager, @@ -197,7 +194,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices /// - /// 导入功能 + /// 1.大众发票与结算核对汇总表 /// /// 上传的文件(前端已经限制只能上传一个附件) /// @@ -225,14 +222,14 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices customConditionList.Add(new CustomCondition() { Name = "ProjectName", Value = "结算与开票数据对比" }); customConditionList.Add(new CustomCondition() { Name = "Year", Value = year ?? DateTime.Now.Year.ToString() }); - var _taskid = await _service.ExportEnqueueAsync("结算与开票数据对比", ExportExtentsion.Excel, CurrentUser, typeof(InvoiceSettledDiffExportService), customConditionList, (rs) => + var _taskid = await _service.ExportEnqueueAsync("大众发票与结算核对汇总表", ExportExtentsion.Excel, CurrentUser, typeof(InvoiceSettledDiffExportService), customConditionList, (rs) => { }); return _taskid; } /// - /// 导入功能 + /// 3.大众准时化结算数量差异比对表 /// /// 上传的文件(前端已经限制只能上传一个附件) /// @@ -254,9 +251,34 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices } + /// + ///6.大众准时化未结差异比对表 + /// + /// 上传的文件(前端已经限制只能上传一个附件) + /// + [HttpGet] + [Route("UnSettleDiffExport-Make")] + [DisableRequestSizeLimit] + + public async Task UnSettleDiffExportServiceMake(string version, string materialCode, string begin, string end) + { + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "Version", Value = version }); + customConditionList.Add(new CustomCondition() { Name = "MaterialCode", Value = materialCode }); + customConditionList.Add(new CustomCondition() { Name = "BeginTime", Value = begin }); + customConditionList.Add(new CustomCondition() { Name = "EndTime", Value = end }); + var _taskid = await _service.ExportEnqueueAsync("大众准时化未结差异比对表", ExportExtentsion.Excel, CurrentUser, typeof(UnSettleDiffExportService), customConditionList, (rs) => + { + }); + return _taskid; + } + + + + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml index c5652139..0e1150fc 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml @@ -1739,6 +1739,166 @@ + + + 大众看板发货明细 + + + + + 构建方法 + + 构建UID + 仓储接口 + 缓存 + + + + 导入功能 + + 上传的文件(前端已经限制只能上传一个附件) + + + + + 按ID获取唯一实体 + + + 返回实体全部属性 + + ID + 实体DTO + + + + 导出文件 + + + + + + + 根据筛选条件获取实体列表 + + + 请求条件包括:筛选条件列表,排序条件,数据数量,页码 + + 请求条件 + 实体DTO列表 + + + + 获取实体总数 + + 实体总数 + + + + 获取全部实体列表 + + 实体DTO列表 + + + + 删除实体 + + ID + + + + + 按IDs删除实体列表 + + IDs + 是否执行成功 + + + + 版本列表查询 + + + + + + + 大众备件服务 + + + + + 构建方法 + + 构建UID + 仓储接口 + 缓存 + + + + 导入功能 + + 上传的文件(前端已经限制只能上传一个附件) + + + + + 按ID获取唯一实体 + + + 返回实体全部属性 + + ID + 实体DTO + + + + 导出文件 + + + + + + + 根据筛选条件获取实体列表 + + + 请求条件包括:筛选条件列表,排序条件,数据数量,页码 + + 请求条件 + 实体DTO列表 + + + + 获取实体总数 + + 实体总数 + + + + 获取全部实体列表 + + 实体DTO列表 + + + + 删除实体 + + ID + + + + + 按IDs删除实体列表 + + IDs + 是否执行成功 + + + + 版本列表查询 + + + + 区域相关应用服务 @@ -2289,18 +2449,25 @@ - 导入功能 + 1.大众发票与结算核对汇总表 上传的文件(前端已经限制只能上传一个附件) - 导入功能 + 3.大众准时化结算数量差异比对表 上传的文件(前端已经限制只能上传一个附件) + + + 6.大众准时化未结差异比对表 + + 上传的文件(前端已经限制只能上传一个附件) + + 结算总成和ERP总成价格对比 diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs index d5868c57..e3e108ad 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs @@ -3,9 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; namespace Win.Sfs.SettleAccount.Entities { + + public class CacheManager + { + public static List CacheMaterials { set; get; } + public static List CachePriceList { set; get; } + } + public interface ISettleAccountEntityBase { public string Version { set; get; } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs index 915baa30..f9913a45 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs @@ -12,14 +12,11 @@ namespace Win.Sfs.SettleAccount.Entities.UnSettle { [ExporterHeader(DisplayName = "结算平台未结数量 ")] public decimal Qty { set; get; } - [ExporterHeader(DisplayName = "定价 ")] - public decimal Price { set; get; } - [ExporterHeader(DisplayName = "金额 ")] - public decimal Amt { set; get; } + [ExporterHeader(DisplayName = "漏结标识 ")] public string Flag { set; get; } [ExporterHeader(DisplayName = "漏结期间 ")] - public string UNSettleVersion { set; get; } + public string UnSettleVersion { set; get; } [ExporterHeader(DisplayName = "说明 ")] public string Remark { set; get; } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs index 286b9e81..038609bd 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; namespace Win.Sfs.SettleAccount.Reports { + public class ReportDetailBase { [ExporterHeader(DisplayName = "交货单号 ")] @@ -17,7 +18,7 @@ namespace Win.Sfs.SettleAccount.Reports public string KENNCode { set; get; } [ExporterHeader(DisplayName = "底盘号")] public string ChassisNumber { set; get; } - [ExporterHeader(DisplayName = "M100交货状态 ")] + [ExporterHeader(DisplayName = "交货状态 ")] public string WmsState { set; get; } [ExporterHeader(DisplayName = "物料号")] public string SapMaterialCode { set; get; } @@ -26,13 +27,15 @@ namespace Win.Sfs.SettleAccount.Reports [ExporterHeader(DisplayName = "客户物料 ")] public string MaterialCode { set; get; } [ExporterHeader(DisplayName = "组件组物料 ")] - public string ParentMaterialCode { set; get; } + public string ParentSapMaterialCode { set; get; } [ExporterHeader(DisplayName = "组件组物料描述 ")] public string ParentMaterialDesc { set; get; } [ExporterHeader(DisplayName = "物料组(车型) ")] public string MaterialGroup { set; get; } - - + [ExporterHeader(DisplayName = "定价 ")] + public decimal Price { set; get; } + [ExporterHeader(DisplayName = "金额 ")] + public decimal Amt { set; get; } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs new file mode 100644 index 00000000..2c73e30a --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs @@ -0,0 +1,85 @@ +using Dapper; +using Magicodes.ExporterAndImporter.Core; +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; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; +using Win.Sfs.SettleAccount.Reports; + +namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report +{ + + + /// + /// 主数据Dapper表 + /// + public class ErpPartDapperRepository : DapperRepository, ITransientDependency + { + public ErpPartDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + { + + } + + public virtual List GetDiffReport(List childList) where T : ReportDetailBase, new() + { + List _materialList = new List(); + List _priceList = new List(); + if (CacheManager.CacheMaterials != null) + { + _materialList = CacheManager.CacheMaterials; + } + else + { + _materialList = DbConnection.Query("select * from set_material").ToList(); + } + if (CacheManager.CachePriceList != null) + { + _priceList = CacheManager.CachePriceList; + } + else + { + _priceList = DbConnection.Query("select MaterialCode,Price from Set_PriceList where version=(select max(version) from set_Set_PriceListVersion)").ToList(); + } + + List _list = new List(); + foreach (var itm in childList) + { + var parentMaterial = new T(); + parentMaterial.WmsBillNum = itm.WmsBillNum; + parentMaterial.CP5Time = itm.CP5Time; + parentMaterial.KENNCode = itm.KENNCode; + parentMaterial.ChassisNumber = itm.ChassisNumber; + parentMaterial.WmsState = itm.WmsState; + parentMaterial.SapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.MaterialDesc = itm.ParentMaterialDesc; + parentMaterial.MaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentSapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentMaterialDesc = itm.ParentMaterialDesc; + + var _price = _priceList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_price != null) + { + parentMaterial.Price = _price.Price; + parentMaterial.Amt = _price.Price; + } + var _material = _materialList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_material != null) + { + parentMaterial.MaterialGroup = _material.EstimateTypeDesc; + + } + _list.Add(parentMaterial); + } + + return _list; + + } + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs index 4cb3f017..b46e903d 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs @@ -20,74 +20,117 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob public virtual List GetInvoiceSettledDiffReportList(string version,string year, string tablename ,string materialcode) { - //string str = string.Empty; - //str += " where 1=1 "; - ////if (!string.IsNullOrEmpty(year)) - ////{ - //// str += string.Format(" and year='{0}' ", year); - ////} - //if (!string.IsNullOrEmpty(version)) - //{ - // str += string.Format(" and version='{0}' ", version); - //} - - - //// string sqlString = "select "+ string.Format(" {0} as Version ,",version) + "a.MaterialCode,isnull(b.qty,0) InvoiceQty,isnull(c.qty,0) SettleQty, (isnull(b.qty,0)-isnull(c.qty,0)) as DiffQty from (\n" + - //// " select distinct MaterialCode from( \n"+ - ////"select distinct MaterialCode from Set_Invoice {0}\n" + - //// "union all\n" + - //// "select distinct MaterialCode from {1} {0}\n" + - //// ") temp \n"+ - //// ") as a\n" + - //// "left join\n" + - //// "\n" + - //// "(select SUM(QTY) qty,MaterialCode from Set_Invoice {0} GROUP BY MaterialCode) b on a.MaterialCode=b.MaterialCode\n" + - //// "\n" + - //// "left join\n" + - //// "(select SUM(QTY) qty,MaterialCode from {1} {0} GROUP BY MaterialCode) c on a.MaterialCode=c.MaterialCode"; + + + // string sqlString = + //"SELECT \n" + string.Format(" '{0}' as Version ,", version) + "\n" + + //" b.*,\n" + + //" ISnull(\n" + + //" c.Qty,\n" + + //" IsNull( d.qty, 0 )) SettleQty,\n" + + //"CASE\n" + + //" \n" + + //" WHEN e.Type = 'CP7报废' THEN\n" + + //" isnull( e.Qty, 0 ) ELSE 0 \n" + + //" END AS CP7ScrapQty,\n" + + //"CASE\n" + + //" \n" + + //" WHEN e.Type = '索赔' THEN\n" + + //" isnull( e.Qty, 0 ) ELSE 0 \n" + + //" END AS ClaimQty,\n" + + //" (\n" + + //" b.InvoiceQty - ISnull(\n" + + //" c.Qty,\n" + + //" IsNull( d.qty, 0 ))) DiffQty,\n" + + //" Isnull( f.Price, 0 ) SalePrice,\n" + + //" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + + //" '' AS SapMaterialCode \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" Factory, MaterialCode,\n" + + //" SUM( QTY ) InvoiceQty,\n" + + //" sum( amt ) InvoiceAmt,\n" + + //" sum( amt )/ sum( Qty ) InvoicePrice \n" + + //" FROM\n" + + //" Set_Invoice \n" + + //" WHERE\n" + + //" version = '{0}' \n" + + //" GROUP BY\n" + + //" MaterialCode,Factory \n" + + //" ) b\n" + + //" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + + //" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + + //" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + + //" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode"; + string sqlString = -"SELECT \n" + string.Format(" '{0}' as Version ,", version) + "\n" + -" b.*,\n" + -" ISnull(\n" + -" c.Qty,\n" + -" IsNull( d.qty, 0 )) SettleQty,\n" + -"CASE\n" + -" \n" + -" WHEN e.Type = 'CP7报废' THEN\n" + -" isnull( e.Qty, 0 ) ELSE 0 \n" + -" END AS CP7ScrapQty,\n" + -"CASE\n" + -" \n" + -" WHEN e.Type = '索赔' THEN\n" + -" isnull( e.Qty, 0 ) ELSE 0 \n" + -" END AS ClaimQty,\n" + -" (\n" + -" b.InvoiceQty - ISnull(\n" + -" c.Qty,\n" + -" IsNull( d.qty, 0 ))) DiffQty,\n" + -" Isnull( f.Price, 0 ) SalePrice,\n" + -" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + -" '' AS SapMaterialCode \n" + + "SELECT\n" + +" temp1.*, temp1.InvoicePrice - Isnull( temp2.Price, 0 ) DiffPrice , \n" + +" temp2.Price SalePrice\n" + "FROM\n" + " (\n" + " SELECT\n" + -" Factory, MaterialCode,\n" + -" SUM( QTY ) InvoiceQty,\n" + -" sum( amt ) InvoiceAmt,\n" + -" sum( amt )/ sum( Qty ) InvoicePrice \n" + +string.Format(" '{0}' as Version ,", version)+"\n" + +" b.*,\n" + +" ISnull(\n" + +" c.Qty,\n" + +" IsNull( d.qty, 0 )) SettleQty,\n" + +" CASE\n" + +" \n" + +" WHEN e.Type = 'CP7报废' THEN\n" + +" isnull( e.Qty, 0 ) ELSE 0 \n" + +" END AS CP7ScrapQty,\n" + +" CASE\n" + +" \n" + +" WHEN e.Type = '索赔' THEN\n" + +" isnull( e.Qty, 0 ) ELSE 0 \n" + +" END AS ClaimQty,\n" + +" (\n" + +" b.InvoiceQty - ISnull(\n" + +" c.Qty,\n" + +" IsNull( d.qty, 0 ))) DiffQty,\n" + +//" Isnull( f.Price, 0 ) SalePrice,\n" + +//" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + +" g.MaterialCode AS SapMaterialCode,\n" + +" g.MaterialDesc AS MaterialDesc \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" Factory,\n" + +" MaterialCode,\n" + +" SUM( QTY ) InvoiceQty,\n" + +" sum( amt ) InvoiceAmt,\n" + +" sum( amt )/ sum( Qty ) InvoicePrice \n" + +" FROM\n" + +" Set_Invoice \n" + +" WHERE\n" + +" version = '{0}' \n" + +" GROUP BY\n" + +" MaterialCode,\n" + +" Factory \n" + +" ) b\n" + +" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + +" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + +" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + +//" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode\n" + +" LEFT JOIN Set_material g ON b.MaterialCode = g.CustomerPartCode \n" + +" ) temp1\n" + +" LEFT JOIN (\n" + +" SELECT\n" + +" Price,\n" + +" MaterialCode \n" + " FROM\n" + -" Set_Invoice \n" + +" Set_PriceList \n" + " WHERE\n" + -" version = '{0}' \n" + -" GROUP BY\n" + -" MaterialCode,Factory \n" + -" ) b\n" + -" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + -" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + -" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + -" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode"; +" version =(\n" + +" SELECT\n" + +" max( version ) \n" + +" FROM\n" + +" Set_PriceListVersion \n" + +" )) temp2 ON temp1.SapMaterialCode = temp2.MaterialCode"; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs index 1c611486..1153f1c3 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs @@ -46,6 +46,8 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report public string SapCode { set; get; } } + + [ExcelExporter(Name = "未结汇总", AutoFitAllColumn = true, MaxRowNumberOnASheet = 500000)] public class SettleFisDiffSum { diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs index 3a581541..26521d6f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs @@ -32,6 +32,9 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } + /// + /// 6.大众准时化未结差异比对表 + /// public class UnSettleDiffDapperRepository : DapperRepository, ITransientDependency { public UnSettleDiffDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) @@ -44,71 +47,125 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report string str1 = "where 1=1 "; - -string sql1 = "SELECT\n" + -" a.MaterialCode,\n" + -" a.KENNCode,\n" + -" a.ChassisNumber,\n" + -" a.qty unsettleQty,\n" + -" b.qty \n" + -" a.Cp5Time \n"+ - -"FROM\n" + -" Set_unsettle a\n" + -" LEFT JOIN (\n" + -" SELECT\n" + -" ItemCode,\n" + -" KENNCode,\n" + -" ChassisNumber2,\n" + -" sum( qty ) qty \n" + -" FROM\n" + -" Set_fis \n" + -" WHERE\n" + -" state = 0 \n" + -" OR state = 4 \n" + -" GROUP BY\n" + -" ItemCode,\n" + -" KENNCode,\n" + -" ChassisNumber2 \n" + -" ) b ON a.ChassisNumber = b.ChassisNumber2 \n" + -" AND a.MaterialCode = b.ItemCode \n" + -" AND a.KENNCode = b.KENNCode {0}"; - - - - string sql2 = - "SELECT\n" + - " a.*,\n" + - " b.Qty unsettleQty \n" + + string sql1 = "SELECT\n" + + " a.MaterialCode,\n" + + " a.KENNCode,\n" + + " a.ChassisNumber,\n" + + " a.qty UNSettleQty,\n" + + " b.qty,\n" + + " a.CP5A CP5Time,\n" + + " c.MaterialCode SapMaterialCode,\n" + + " c.MaterialDesc MaterialDesc,\n" + + " a.model Factory \n" + "FROM\n" + - " (\n" + + " Set_unsettle a\n" + + " LEFT JOIN (\n" + " SELECT\n" + - " WMSState,\n" + - " WMSBillNum,\n" + " ItemCode,\n" + " KENNCode,\n" + " ChassisNumber2,\n" + - " sum( qty ) qty,\n" + - " ErpMaterialCode,\n" + - " ChassisNumber \n" + + " sum( qty ) qty \n" + " FROM\n" + " Set_fis \n" + " WHERE\n" + " state = 0 \n" + + " OR state = 4 \n" + " GROUP BY\n" + " ItemCode,\n" + " KENNCode,\n" + " ChassisNumber2,\n" + - " WMSState,\n" + - " WMSBillNum,\n" + - " ErpMaterialCode,\n" + - " ChassisNumber \n" + - " Cp5Time \n" + - " ) a\n" + - " LEFT JOIN Set_unsettle b ON a.ChassisNumber2 = b.ChassisNumber \n" + - " AND b.MaterialCode = a.ItemCode \n" + - " AND a.KENNCode = b.KENNCode {0}"; + " Model \n" + + " ) b ON a.ChassisNumber = b.ChassisNumber2 \n" + + " AND a.MaterialCode = b.ItemCode \n" + + " AND a.KENNCode = b.KENNCode\n" + + " LEFT JOIN Set_material c ON a.MaterialCode = c.CustomerPartCode {0}"; + + + + string sql2 = + "SELECT\n" + +" t1.*,\n" + +" t1.Qty * T2.Price AMT,\n" + +" T2.Price,\n" + +" Qty -(\n" + +" ISNULL( UnSettleQty, 0 )) DiffQty,\n" + +" Qty -(\n" + +" ISNULL( UnSettleQty, 0 ))* isnull( t2.Price, 0 ) DiffPrice \n" + +"FROM\n" + +" (\n" + +" SELECT\n" + +" temp1.WMSState,\n" + +" temp1.WMSBillNum,\n" + +" temp1.MaterialCode,\n" + +" temp1.KENNCode,\n" + +" temp1.ChassisNumber2,\n" + +" temp1.Qty,\n" + +" temp1.ChassisNumber,\n" + +" temp1.CP5Time,\n" + +" temp1.UnSettleQty,\n" + +" temp1.SapMaterialCode,\n" + +" temp1.MaterialDesc,\n" + +" temp1.MaterialGroup,\n" + +" temp2.MaterialCode AS ParentSapMaterialCode,\n" + +" temp2.MaterialDesc AS ParentMaterialDesc \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" a.WMSState,\n" + +" a.WMSBillNum,\n" + +" a.MaterialCode,\n" + +" a.KENNCode,\n" + +" a.ChassisNumber2,\n" + +" a.Qty,\n" + +" a.ParentCode,\n" + +" a.ChassisNumber,\n" + +" a.CP5Time,\n" + +" b.Qty AS UnSettleQty,\n" + +" C.MaterialCode AS SapMaterialCode,\n" + +" C.MaterialDesc,\n" + +" C.EstimateTypeDesc AS MaterialGroup \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" WMSState,\n" + +" WMSBillNum,\n" + +" ItemCode AS MaterialCode,\n" + +" KENNCode,\n" + +" ChassisNumber2,\n" + +" SUM( Qty ) AS Qty,\n" + +" ErpMaterialCode AS ParentCode,\n" + +" ChassisNumber,\n" + +" CP5Time \n" + +" FROM\n" + +" Set_fis \n" + +" WHERE\n" + +" ( State = 0 ) \n" + +" GROUP BY\n" + +" ItemCode,\n" + +" KENNCode,\n" + +" ChassisNumber2,\n" + +" WMSState,\n" + +" WMSBillNum,\n" + +" ErpMaterialCode,\n" + +" ChassisNumber,\n" + +" CP5Time \n" + +" ) AS a\n" + +" LEFT OUTER JOIN Set_Unsettle AS b ON a.ChassisNumber2 = b.ChassisNumber \n" + +" AND b.MaterialCode = a.MaterialCode \n" + +" AND a.KENNCode = b.KENNCode\n" + +" LEFT OUTER JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode \n" + +" ) AS temp1\n" + +" LEFT OUTER JOIN Set_material AS temp2 ON temp1.ParentCode = temp2.CustomerPartCode \n" + +" ) t1\n" + +" LEFT JOIN (\n" + +" SELECT\n" + +" MaterialCode,\n" + +" Price \n" + +" FROM\n" + +" Set_PriceList \n" + +"WHERE\n" + +" version = ( SELECT max( version ) FROM Set_PriceListVersion )) t2 ON t1.MaterialCode = t2.MaterialCode"; string _sql = string.Empty; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs index ff33ff8f..f80f2d31 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs @@ -11,18 +11,23 @@ using Dapper; using Win.Sfs.SettleAccount.FISes; using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report.ExportDto; using Win.Sfs.SettleAccount.Entities.UnSettle; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { + /// + /// 7.大众准时化未结明细表(包含漏结,漏结要有标识) + /// public class UnSettledDetailDapperRepository : DapperRepository, ITransientDependency { - //ERP总成开票报表 + public UnSettledDetailDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } - public virtual List GetDiffReport(string year, string begin, string end, string customcode, string version,string materialCode,string materialGroup,string sapCode) + public virtual List GetDiffReport(string year, string begin, string end, string customcode, string version, string materialCode, string materialGroup, string sapCode) { string str = string.Empty; @@ -30,7 +35,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report if (!string.IsNullOrEmpty(begin)) { - str += string.Format(" and beginTime>'{0}' ",begin); + str += string.Format(" and beginTime>'{0}' ", begin); } if (!string.IsNullOrEmpty(end)) { @@ -38,81 +43,113 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } if (!string.IsNullOrEmpty(materialCode)) { - str += string.Format(" and MaterialCode='{0}' ", materialCode); + str += string.Format(" and ItemCode='{0}' ", materialCode); } if (!string.IsNullOrEmpty(materialGroup)) { str += string.Format(" and MaterialGroup='{0}' ", materialGroup); } - if (!string.IsNullOrEmpty(sapCode)) - { - str += string.Format(" and MaterialGroup='{0}' ", materialGroup); - } + //if (!string.IsNullOrEmpty(sapCode)) + //{ + // str += string.Format(" and SapCode='{0}' ", materialGroup); + //} var sqlString = - " SELECT\n" + - " A.*,\n" + - " C.Price,\n" + - " ISNULL( A.QTY, 0 )* ISNULL( C.Price, 0 ) AMT \n" + - "FROM\n" + - " (\n" + - " SELECT DISTINCT\n" + - " '' WMSState,\n" + - " '' UnSettleVersion,\n" + - " '' WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ErpMaterialCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " 1 QTY,\n" + - " ErpMaterialCode ParentMaterialCode,\n" + - " '' FLAG \n" + - " FROM\n" + - " Set_fis \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 0 {0} UNION ALL\n" + - " SELECT\n" + - " WMSState,\n" + - " UnSettleVersion,\n" + - " WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ItemCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " QTY,\n" + - " ErpMaterialCode,\n" + - " '' FLAG \n" + - " FROM\n" + - " [Set_fis] \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 0 {0} UNION ALL\n" + - " SELECT\n" + - " WMSState,\n" + - " UnSettleVersion,\n" + - " WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ItemCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " QTY,\n" + - " ErpMaterialCode,\n" + - " 'L' FLAG \n" + - " FROM\n" + - " [Set_fis] \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 4 {0}\n" + - " ) A\n" + - " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) ) C ON a.MaterialCode = c.MaterialCode"; - - - - string _sql = string.Format(sqlString, version); + "SELECT\n" + + " A.*,\n" + + " C.Price,\n" + + " ISNULL( A.QTY, 0 )* ISNULL( C.Price, 0 ) AMT,\n" + + " B.EstimateTypeDesc MaterialGroup,\n" + + " B.MaterialDesc MaterialDesc,\n" + + " d.MaterialDesc ParentMaterialDesc \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " WMSState,\n" + + " WMSBillNum,\n" + + " UnSettleVersion,\n" + + " BeginTime CP5Time,\n" + + " ItemCode MaterialCode,\n" + + " ChassisNumber,\n" + + " KENNCode,\n" + + " QTY,\n" + + " ErpMaterialCode ParentSapMaterialCode,\n" + + " '' FLAG \n" + + " FROM\n" + + " Set_fis {0} \n" + + " WHERE\n" + + " 1 = 1 \n" + + " AND STATE = 0 UNION ALL\n" + + " SELECT\n" + + " WMSState,\n" + + " UnSettleVersion,\n" + + " WMSBillNum,\n" + + " BeginTime CP5Time,\n" + + " ItemCode MaterialCode,\n" + + " ChassisNumber,\n" + + " KENNCode,\n" + + " QTY,\n" + + " ErpMaterialCode ParentSapMaterialCode,\n" + + " 'L' FLAG \n" + + " FROM\n" + + " Set_fis {0} \n" + + " WHERE\n" + + " 1 = 1 \n" + + " AND STATE = 4 \n" + + " ) A\n" + + " LEFT JOIN Set_material B ON a.MaterialCode = b.CustomerPartCode\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) ) C ON a.MaterialCode = c.MaterialCode\n" + + " LEFT JOIN Set_material d ON a.ParentSapMaterialCode = d.MaterialCode"; + + + + + + + + var _materialList = DbConnection.Query("select * from set_material").ToList(); + var _priceList = DbConnection.Query("select MaterialCode,Price from Set_PriceList where version=(select max(version) from set_Set_PriceListVersion)").ToList(); + + + + string _sql = string.Format(sqlString, str); ; var _query = DbConnection.Query(_sql); - return _query.ToList(); + + var _list = _query.ToList(); + var _ls = _list.Where(p=>p.Flag!="L").GroupBy(p => new { p.KENNCode, p.ChassisNumber, p.ParentSapMaterialCode }).Select(p => p.FirstOrDefault()).ToList(); + + foreach (var itm in _ls) + { + + var parentMaterial = new UnSettleDetailReport(); + parentMaterial.WmsBillNum = itm.WmsBillNum; + parentMaterial.CP5Time = itm.CP5Time; + parentMaterial.KENNCode = itm.KENNCode; + parentMaterial.ChassisNumber = itm.ChassisNumber; + parentMaterial.WmsState = itm.WmsState; + parentMaterial.SapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.MaterialDesc = itm.ParentMaterialDesc; + parentMaterial.MaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentSapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentMaterialDesc = itm.ParentMaterialDesc; + + var _price=_priceList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_price != null) + { + parentMaterial.Price = _price.Price; + parentMaterial.Amt = _price.Price; + } + var _material=_materialList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_material != null) + { + parentMaterial.MaterialGroup = _material.EstimateTypeDesc; + + } + _list.Add(parentMaterial); + } + + return _list; } } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs index 3881f5ed..e5d6f65f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs @@ -57,8 +57,26 @@ namespace SettleAccount.Job.Services _taskjobRepository.UpdateTaskJob(Id, _task); //保存导出文件到服务器存成二进制 } + public void Export(Guid Id, string fileName, List p_list, List p_list1) where T1 : class, new() + where T2: class, new() + { + ExcelExporter _exporter = new ExcelExporter();//导出Excel + + var result = _exporter + .Append(p_list, "sheet1") + .SeparateBySheet() + .Append(p_list1) + .ExportAppendDataAsByteArray(); + + + + result.ShouldNotBeNull(); + _fileContainer.SaveAsync(fileName, result.Result, true); + var _task = new Win.Sfs.SettleAccount.Entities.TaskJob() { DownFileName = fileName }; + _taskjobRepository.UpdateTaskJob(Id, _task); + //保存导出文件到服务器存成二进制 + } - diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs index 76951a32..099b2b5f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs @@ -70,8 +70,12 @@ namespace SettleAccount.Job.Services SalePrice =itm. SalePrice , DiffPrice =itm. DiffPrice , SapMaterialCode =itm.SapMaterialCode , - Factory = itm.Factory - + MaterialDesc=itm.MaterialDesc, + + + Factory = itm.Factory, + + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs index c2fd9c20..d223b3ce 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs @@ -1,5 +1,8 @@ -using System; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,12 +15,18 @@ using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; namespace SettleAccount.Job.Services.Report { + /// + /// 3.大众准时化结算数量差异比对表 + /// public class SettleFisDiffExportService : ITransientDependency, IExportJob { private readonly SettleFisDiffDetailDapperRepository _dapper; private readonly OutputService _outputService; + + + public SettleFisDiffExportService(SettleFisDiffDetailDapperRepository dapper, OutputService outputService) { _dapper = dapper; @@ -33,7 +42,7 @@ namespace SettleAccount.Job.Services.Report var end = p_list.Where(p => p.Name == "EndTime").FirstOrDefault().Value; var _list= _dapper.GetReportList(version, materialCode, begin,end); - _list.GroupBy(p => new { p.MaterialCode,p.SapCode }).Select(p =>new SettleFisDiffSum + var _ls= _list.GroupBy(p => new { p.MaterialCode,p.SapCode }).Select(p =>new SettleFisDiffSum { MaterialCode= p.Key.MaterialCode, @@ -46,18 +55,132 @@ namespace SettleAccount.Job.Services.Report }); + //_outputService.Export(id, string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()),_list.ToList(),_ls.ToList()); + _outputService.Export(id, string.Format("大众准时化结算数量合计_{0}.xlsx", Guid.NewGuid().ToString()), _ls.ToList()); - - - + _outputService.Export(id,string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()), _list); + return id.ToString(); + } + /// + /// 将数个Excel文件中的第一个工作表合并至一个Excel文件中 + /// + /// 需要合并的数个Excel文件路径 + /// 合并成的一个Excel文件路径 + private void MergeExcels(string[] excelFilePaths, string desFilePath) + { + XSSFWorkbook mergeWorkBook = new XSSFWorkbook(); + for (int i = 0; i < excelFilePaths.Length; i++) + { + if (File.Exists(excelFilePaths[i])) + { + using (FileStream fs = new FileStream(excelFilePaths[i], FileMode.Open, FileAccess.Read, FileShare.Write)) + { + XSSFWorkbook tmpWorkBook = new XSSFWorkbook(fs); + XSSFSheet tmpSheet = tmpWorkBook.GetSheetAt(0) as XSSFSheet; + if (excelFilePaths[i].Contains("当月结算表")) + { + IRow row = null; + for (int j = 2; j < tmpSheet.PhysicalNumberOfRows && tmpSheet.GetRow(j) != null; j++)/*j=1 从索引的第一行开始过滤掉表头*/ + { + row = tmpSheet.GetRow(j); + try + { + if (!string.IsNullOrWhiteSpace(row.GetCell(1).ToString()))/*验证数值非空*/ + { + //cell.CSS("color:red;font-weight:bold;font-size:11;font-name:宋体;border-type:thin;") + /*修改样式关键代码*/ + ICellStyle style = tmpWorkBook.CreateCellStyle(); + style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Orange.Index; + style.FillPattern = FillPattern.SolidForeground; + style.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Orange.Index; + + style.BorderTop = BorderStyle.Thin;//上 + style.BorderBottom = BorderStyle.Thin;//下 + style.BorderLeft = BorderStyle.Thin;//左 + style.BorderRight = BorderStyle.Thin;//右 + style.VerticalAlignment = VerticalAlignment.Center; + style.Alignment = HorizontalAlignment.Center; + + IFont font = tmpWorkBook.CreateFont(); + font.FontHeightInPoints = 10; // 字体大小 直接对应Excel中的字体大小 + font.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + font.IsBold = true;//加粗 + style.SetFont(font); + /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/ + for (int g = 0; g < row.Cells.Count; g++) + { + row.Cells[g].CellStyle = style; + } + row.RowStyle = style; + + if (row.GetCell(1).ToString() == "核算表不存在") + { + ICellStyle style1 = tmpWorkBook.CreateCellStyle(); + style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index; + style1.FillPattern = FillPattern.SolidForeground; + style1.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index; + + style1.BorderTop = BorderStyle.Thin;//上 + style1.BorderBottom = BorderStyle.Thin;//下 + style1.BorderLeft = BorderStyle.Thin;//左 + style1.BorderRight = BorderStyle.Thin;//右 + style1.VerticalAlignment = VerticalAlignment.Center; + style1.Alignment = HorizontalAlignment.Center; + IFont font1 = tmpWorkBook.CreateFont(); + font1.FontHeightInPoints = 10; // 字体大小 直接对应Excel中的字体大小 + font1.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + font1.IsBold = true;//加粗 + font1.Color = NPOI.HSSF.Util.HSSFColor.White.Index; + style1.SetFont(font); + //style.fon + //HSSFFont font = workbookAll.CreateFont(); + //font.FontHeightInPoints = 9; // 字体大小 直接对应Excel中的字体大小 + //font.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + //font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;//加粗 + //style.SetFont(font); + + + /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/ + for (int g = 0; g < row.Cells.Count; g++) + { + row.Cells[g].CellStyle = style1; + } + row.RowStyle = style1; + + } + /*重新修改文件指定单元格样式*/ + } + } + catch + { } + } + } + tmpSheet.CopyTo(mergeWorkBook, Path.GetFileNameWithoutExtension(excelFilePaths[i]), true, true); + } + } + /* 考虑数据量,此处可以限制最多可以合并工作表的数量 */ + //if (mergeWorkBook.NumberOfSheets >= 200) + //{ + // break; + //} + } + if (mergeWorkBook.NumberOfSheets != 0) + { + FileStream fsDesFile = new FileStream(desFilePath, FileMode.OpenOrCreate, FileAccess.Write); + mergeWorkBook.Write(fsDesFile); + fsDesFile.Close(); + mergeWorkBook.Close(); + } + else + { + mergeWorkBook.Close(); + } + } - _outputService.Export(id,string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()), _list); - return id.ToString(); - } } }