From 7ea0fc2e1cc4442b731dd1218543cca3825ab683 Mon Sep 17 00:00:00 2001 From: liuyunfeng Date: Wed, 8 Nov 2023 13:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E6=9D=BF=E3=80=81=E6=9F=B1=E6=8A=A4?= =?UTF-8?q?=E6=9D=BF=E6=89=93=E5=8D=B0=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MenBanReports/MenBanPrintInputDto.cs | 6 +- .../ZhuHuBanReports/ZhuHuBanPrintInputDto.cs | 5 +- .../Interfaces/IBillM100AppService.cs | 14 +- .../PrintTable/Dtos/QueryWaitPrintDto.cs | 96 + .../PrintTable/Dtos/WaitPrintDto.cs | 14 + .../Interfaces/IAlreadyPrintAppService.cs | 12 + .../Interfaces/IWaitPrintAppService.cs | 19 + .../WY.NewJit.Application.Contracts.csproj | 4 - .../WY.NewJit.Application.Contracts.xml | 145 +- .../MsgCheck/BillM100s/BillM100AppService.cs | 6333 ++++++----------- .../BillM100s/ZhuHuBanPackingRecService.cs | 8 +- .../PrintTable/AlreadyPrintAppService.cs | 3 +- .../PrintTable/WaitPrintAppService.cs | 1055 ++- .../PrintTable/WaitPrintAppService_ZHB.cs | 1096 +++ .../Common/SwaggerGroupConsts.cs | 1 + .../Extends/PaiGe/PrintTypeEnum.cs | 4 +- .../MsgCheck/Entitys/ZHBPrintStatus.cs | 48 +- .../MsgCheck/Services/M100DomainService.cs | 27 +- .../PrintTable/Entitys/LastPrintHostSN.cs | 17 + .../EntityFrameworkCore/NewJitDbContext.cs | 2 +- .../NewJitDbContextModelCreatingExtensions.cs | 14 +- 21 files changed, 4656 insertions(+), 4267 deletions(-) create mode 100644 src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/QueryWaitPrintDto.cs create mode 100644 src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IAlreadyPrintAppService.cs create mode 100644 src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IWaitPrintAppService.cs create mode 100644 src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService_ZHB.cs create mode 100644 src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/PrintTable/Entitys/LastPrintHostSN.cs diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/MenBanReports/MenBanPrintInputDto.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/MenBanReports/MenBanPrintInputDto.cs index 52e931e..8db7403 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/MenBanReports/MenBanPrintInputDto.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/MenBanReports/MenBanPrintInputDto.cs @@ -9,7 +9,7 @@ namespace WY.NewJit.Extends { /// - /// 打印类型:提供初次打印、重新打印、针对重新解析后单据的补打功能 + /// 打印类型:0 顺序打印 1 补账打印 3 重新打印 /// public PrintTypeEnum PrintType { get; set; } @@ -30,14 +30,14 @@ namespace WY.NewJit.Extends #region 重新打印、补打时使用 /// - /// 装箱单主表ID列表,报废时传入一个,重打时可传入多个 + /// 重新打印时使用。装箱单主表ID列表,报废时传入一个,重打时可传入多个 /// public virtual List ReportIdList { get; set; } /// /// 补打时使用 /// - public virtual List M100IdList { get; set; } + public virtual List WaitPrintIdList { get; set; } #endregion } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/ZhuHuBanReports/ZhuHuBanPrintInputDto.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/ZhuHuBanReports/ZhuHuBanPrintInputDto.cs index 1d9c4c4..bb2e0e3 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/ZhuHuBanReports/ZhuHuBanPrintInputDto.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/Extends/ZhuHuBanReports/ZhuHuBanPrintInputDto.cs @@ -42,8 +42,11 @@ namespace WY.NewJit.Extends /// /// 补打时使用 /// - public virtual List M100IdList { get; set; } + public virtual List WaitPrintIdList { get; set; } + /// + /// 1 门板 2 其它柱护板 3 柱护板 + /// public virtual string GroupName { get; set; } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgCheck/BillM100s/Interfaces/IBillM100AppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgCheck/BillM100s/Interfaces/IBillM100AppService.cs index a4b691f..e879029 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgCheck/BillM100s/Interfaces/IBillM100AppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgCheck/BillM100s/Interfaces/IBillM100AppService.cs @@ -62,40 +62,34 @@ namespace WY.NewJit.MsgCheck /// 执行成功返回真 Task ImportAsync(Byte[] input); - /// - /// 根据生产线获取正常打印单据的起始大众顺序号 - /// - /// 生产线 - /// 起始大众顺序号 - Task> GetPrintStartHostSN2(string productLine, string isZhuHuBan,string GroupName = null); /// /// 打印前检查门板大众顺序号是否断号 /// /// /// 断号时Item不为空 - Task> CheckMBHostSNBreakNum(MenBanPrintInputDto input); + //Task> CheckMBHostSNBreakNum(MenBanPrintInputDto input); /// /// 打印前检查柱护板大众顺序号是否断号 /// /// /// 断号时Item不为空 - Task> CheckZHBHostSNBreakNum(ZhuHuBanPrintInputDto input); + //Task> CheckZHBHostSNBreakNum(ZhuHuBanPrintInputDto input); /// /// 打印门板装箱单 /// /// /// 执行成功返回真 - Task> PrintMenBanPackingList(MenBanPrintInputDto input); + //Task> PrintMenBanPackingList(MenBanPrintInputDto input); /// /// 打印柱护板装箱单 /// /// /// 执行成功返回真 - Task> PrintZhuHuBanPackingList(ZhuHuBanPrintInputDto input); + //Task> PrintZhuHuBanPackingList(ZhuHuBanPrintInputDto input); #endregion diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/QueryWaitPrintDto.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/QueryWaitPrintDto.cs new file mode 100644 index 0000000..5dc32a9 --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/QueryWaitPrintDto.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; +using Volo.Abp.Application.Dtos; +using WY.NewJit.Common; +using WY.NewJit.MsgCheck; + +namespace WY.NewJit.PrintTable.Dtos +{ + [Serializable] + public class QueryWaitPrintDto : PagedAndSortedBase + { + /// + /// 大众顺序号起 + /// + public int? HostSNBegin { get; set; } + + /// + /// 大众顺序号止 + /// + public int? HostSNEnd { get; set; } + + /// + /// KNR起 + /// + public string KNRBegin { get; set; } + + /// + /// KNR止 + /// + public string KNREnd { get; set; } + + /// + /// 底牌号起 + /// + public string VINBegin { get; set; } + + /// + /// 底牌号止 + /// + public string VINEnd { get; set; } + + /// + /// 总成ID + /// + public Guid? AssemblyID { get; set; } + + /// + /// 上线时间起 + /// + public DateTime? OnlineTimeBegin { get; set; } + + /// + /// 上线时间止 + /// + public DateTime? OnlineTimeEnd { get; set; } + + + /// + /// 车型代码(取通用字典) + /// + public string VehicleModelCode { get; set; } + + /// + /// 生产线(派格按生产线分类) + /// + public virtual string ProductLine { get; set; } + + /// + /// 接收时间起 + /// + public DateTime? ReceiveTimeBegin { get; set; } + + /// + /// 接收时间止 + /// + public DateTime? ReceiveTimeEnd { get; set; } + + /// + /// 单据状态(0 空;1 未匹配;2 未打印;3 已打印 4 断号) + /// + public BillStatusEnum? BillStatus { get; set; } + + /// + /// 打印类型: 1 顺序打印 2 补账打印 + /// + public PrintTypeEnum? PrintType { get; set; } + + /// + /// 业务类型:1 门板 2 其它柱护板 3 柱护板 + /// + public BusinessTypeEnum? BusinessType { get; set; } + } +} + diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/WaitPrintDto.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/WaitPrintDto.cs index d301970..2639c20 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/WaitPrintDto.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Dtos/WaitPrintDto.cs @@ -138,5 +138,19 @@ namespace WY.NewJit.PrintTable [ExporterHeader(DisplayName = "最后修改人")] [ImporterHeader(Name = "最后修改人")] public Guid? LastModifierId { get; set; } + + /// + /// R100上线时间 + /// + [ExporterHeader(DisplayName = "R100上线时间")] + [ImporterHeader(Name = "R100上线时间")] + public DateTime R100OnlineTime { get; set; } + + /// + /// R100接收时间 + /// + [ExporterHeader(DisplayName = "R100接收时间")] + [ImporterHeader(Name = "R100接收时间")] + public DateTime? R100ReceiveTime { get; set; } } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IAlreadyPrintAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IAlreadyPrintAppService.cs new file mode 100644 index 0000000..e457e76 --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IAlreadyPrintAppService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WY.NewJit.PrintTable +{ + public interface IAlreadyPrintAppService + { + } +} diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IWaitPrintAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IWaitPrintAppService.cs new file mode 100644 index 0000000..f96ddbe --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/PrintTable/Interfaces/IWaitPrintAppService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WY.NewJit.PrintTable +{ + public interface IWaitPrintAppService + { + /// + /// 根据生产线获取正常打印单据的起始大众顺序号 + /// + /// 生产线 + /// 起始大众顺序号 + Task> GetPrintStartHostSN2(string productLine, string isZhuHuBan, string GroupName = null); + + } +} diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.csproj b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.csproj index 96740e1..1525bc8 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.csproj +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.csproj @@ -31,8 +31,4 @@ - - - - diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml index e42241c..8306222 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml @@ -186,7 +186,7 @@ - 打印类型:提供初次打印、重新打印、针对重新解析后单据的补打功能 + 打印类型:0 顺序打印 1 补账打印 3 重新打印 @@ -206,10 +206,10 @@ - 装箱单主表ID列表,报废时传入一个,重打时可传入多个 + 重新打印时使用。装箱单主表ID列表,报废时传入一个,重打时可传入多个 - + 补打时使用 @@ -558,11 +558,16 @@ 数据结果类型 1 全部数据, 2 选中数据(仅重新打印时使用) - + 补打时使用 + + + 1 门板 2 其它柱护板 3 柱护板 + + 柱护板主实体列表 A上C上 @@ -1910,41 +1915,6 @@ 导入文件流 执行成功返回真 - - - 根据生产线获取正常打印单据的起始大众顺序号 - - 生产线 - 起始大众顺序号 - - - - 打印前检查门板大众顺序号是否断号 - - - 断号时Item不为空 - - - - 打印前检查柱护板大众顺序号是否断号 - - - 断号时Item不为空 - - - - 打印门板装箱单 - - - 执行成功返回真 - - - - 打印柱护板装箱单 - - - 执行成功返回真 - 生产线超时提醒 @@ -3522,6 +3492,86 @@ 最后修改人 + + + 大众顺序号起 + + + + + 大众顺序号止 + + + + + KNR起 + + + + + KNR止 + + + + + 底牌号起 + + + + + 底牌号止 + + + + + 总成ID + + + + + 上线时间起 + + + + + 上线时间止 + + + + + 车型代码(取通用字典) + + + + + 生产线(派格按生产线分类) + + + + + 接收时间起 + + + + + 接收时间止 + + + + + 单据状态(0 空;1 未匹配;2 未打印;3 已打印 4 断号) + + + + + 打印类型: 1 顺序打印 2 补账打印 + + + + + 业务类型:1 门板 2 其它柱护板 3 柱护板 + + 零件查询结果DTO @@ -3617,5 +3667,22 @@ 最后修改人 + + + R100上线时间 + + + + + R100接收时间 + + + + + 根据生产线获取正常打印单据的起始大众顺序号 + + 生产线 + 起始大众顺序号 + diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs index 5bf0756..a8e7dbf 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs @@ -44,9 +44,8 @@ namespace WY.NewJit.MsgCheck private readonly IRepository _billM100PartRepository; - private readonly IRepository _printTemplateConfigurationRepository; - private readonly IRepository _zHBPrintStatusRepository; + //private readonly IRepository _zHBPrintStatusRepository; /// /// 日志 /// @@ -62,20 +61,12 @@ namespace WY.NewJit.MsgCheck /// private readonly IBlobContainer _blobContainer; - /// - /// 门板装箱单仓储 - /// - private readonly IRepository _menBanPackingListRepository; /// /// 门板装箱单仓储明细 /// private readonly IRepository _menBanPackingRecRepository; - /// - /// 柱护板装箱单仓储 - /// - private readonly IRepository _zhuHuBanPackingListRepository; /// /// 柱护板装箱单仓储明细 @@ -83,10 +74,6 @@ namespace WY.NewJit.MsgCheck private readonly IRepository _zhuHuBanPackingRecRepository; - /// - /// ERP总成仓储 - /// - private readonly IRepository _assemblyCfgErpRepository; /// /// 整车总成配置仓库 @@ -118,7 +105,7 @@ namespace WY.NewJit.MsgCheck /// 序列领域服务 /// private readonly SequenceDomainService _sequenceDomainService; - private readonly BillNumberRecordDomainService _aaa; + /// /// 配置 /// @@ -126,8 +113,6 @@ namespace WY.NewJit.MsgCheck private readonly IUnitOfWorkManager _unitOfWorkManager; - private readonly IRepository _tbBillRepository; - private readonly IRepository _tsSortDetailRepository; private readonly IRepository _tbBillHisRepository; private readonly IRepository _tsSortDetailHisRepository; @@ -142,8 +127,6 @@ namespace WY.NewJit.MsgCheck } } - private const string _providerCode = "0709FAW-VW7XH"; - private const int _hostSNMaxVal = 1999; /// @@ -162,9 +145,6 @@ namespace WY.NewJit.MsgCheck ILogger logger, NewJitDapperRepository newJitDapperRepository, IBlobContainer blobContainer, - IRepository menBanPackingListRepository, - IRepository zhuHuBanPackingListRepository, - IRepository assemblyCfgErpRepository, IRepository assemblyCfgVehicleRepository, IRepository partCfgRepository, IRepository materialExtRepository, @@ -175,25 +155,19 @@ namespace WY.NewJit.MsgCheck SequenceDomainService sequenceDomainService, Microsoft.Extensions.Configuration.IConfiguration configuration, IUnitOfWorkManager unitOfWorkManager, - IRepository tbBillRepository, - IRepository tsSortDetailRepository, IRepository tbBillHisRepository, - IRepository tsSortDetailHisRepository, - IRepository printTemplateConfigurationRepository, - IRepository zHBPrintStatusRepository, - BillNumberRecordDomainService aaa + IRepository tsSortDetailHisRepository + //IRepository printTemplateConfigurationRepository, + //IRepository zHBPrintStatusRepository + ) { - _aaa = aaa; _billM100Repository = BillM100Repository; _billM100PartRepository = BillM100PartRepository; _logger = logger; _newJitDapperRepository = newJitDapperRepository; _blobContainer = blobContainer; - _menBanPackingListRepository = menBanPackingListRepository; - _zhuHuBanPackingListRepository = zhuHuBanPackingListRepository; - _assemblyCfgErpRepository = assemblyCfgErpRepository; _assemblyCfgVehicleRepository = assemblyCfgVehicleRepository; _partCfgRepository = partCfgRepository; _materialExtRepository = materialExtRepository; @@ -204,38 +178,14 @@ namespace WY.NewJit.MsgCheck _sequenceDomainService = sequenceDomainService; _configuration = configuration; _unitOfWorkManager = unitOfWorkManager; - _tbBillRepository = tbBillRepository; - _tsSortDetailRepository = tsSortDetailRepository; _tbBillHisRepository = tbBillHisRepository; _tsSortDetailHisRepository = tsSortDetailHisRepository; - _printTemplateConfigurationRepository = printTemplateConfigurationRepository; - _zHBPrintStatusRepository = zHBPrintStatusRepository; + //_printTemplateConfigurationRepository = printTemplateConfigurationRepository; + //_zHBPrintStatusRepository = zHBPrintStatusRepository; } #endregion #region 私有方法 - [UnitOfWork] - [HttpPost] - [Route("get-billnumber")] - public async Task GetBillNumber(int number, string productLine,bool t) - { - if (t) - { - _aaa.CleanBillNumberRecordCache(); - } - - var res=await _aaa.GetBillNumber(number, productLine); - return res; - } - [UnitOfWork] - [HttpPost] - [Route("get-billnumberrec")] - public async Task GetBillNumberRec(bool isupdate) - { - - var ret = await _aaa.GetOrUpDateBillNumberRecordCache(isupdate); - return ret.Status; - } /// /// 查询柱护板 /// @@ -603,29 +553,6 @@ select * from return ret; } - /// - /// 取单据包含的ERP总成列表 - /// - /// - /// - private List GetErpAssemblyListByBill(Guid vehicleAssemblyId) - { - List retLst = new List(); - AssemblyCfgVehicle vobj = _assemblyCfgVehicleRepository.GetAsync(vehicleAssemblyId).GetAwaiter().GetResult(); //取单据对应的整车总成 - if (vobj != null && vobj.AssemblyCfgVehicleChilds != null && vobj.AssemblyCfgVehicleChilds.Count > 0) - { - List vehicleChildLst = vobj.AssemblyCfgVehicleChilds; - foreach (AssemblyCfgVehicleChild vehicleChildItm in vehicleChildLst) - { - AssemblyCfgErp erpObj = _assemblyCfgErpRepository.GetAsync(vehicleChildItm.ErpAssemblyId).GetAwaiter().GetResult(); - if (erpObj != null) - { - retLst.Add(erpObj); - } - } - } - return retLst; - } #endregion @@ -708,7 +635,7 @@ select * from return ret; } } - else if (input.PrintType == PrintTypeEnum.补打) + else if (input.PrintType == PrintTypeEnum.补账打印) { //string beginVin = input.BeginVin.TryToRight(6); //string endVin = input.EndVin.TryToRight(6); @@ -732,7 +659,7 @@ select * from } # region 断号处理 - if (isFillBreakNum == true && billLst.Count > 1 && input.PrintType != PrintTypeEnum.补打) + if (isFillBreakNum == true && billLst.Count > 1 && input.PrintType != PrintTypeEnum.补账打印) { billLst = DoBreakNumOperation(input.BeginHostSN, input.EndHostSN, billLst); } @@ -871,4313 +798,2401 @@ select * from /// /// 加1后的序号 /// - private string GetBillNum(long newSN) - { - string newSNStr = newSN.ToString(); - //装箱单号规则 1开头,11位,自增顺序号 - if (newSNStr.Length < 11) - { - return "F" + newSNStr.PadLeft(10, '0'); - } - return newSNStr; - } - - /// - /// 打印左侧或右侧门板 - /// - /// - /// - /// - /// - /// - /// - /// - /// - private List DoMBPrint(MenBanPrintInputDto input, int pageIdx, ref double maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) - { - const int _colNumberPerPage = 12; - List retLst = new List(); - - //取当前页内容 - List curPageLst = billLst.Skip(pageIdx * _colNumberPerPage).Take(_colNumberPerPage).ToList(); - //取车型 C8,Q5 - var vmLst = curPageLst.Select(itm => itm.VehicleModelCode).Distinct().ToList(); - string vmStr = ""; - foreach (var item in vmLst) - { - vmStr += item + ","; - } - if (vmStr.Length >0) - { - vmStr = vmStr.Substring(0, vmStr.Length - 1); - } - - //填充门板装箱单主实体 - MenBanPackingList mbObj = new MenBanPackingList(); - mbObj.SetId(GuidGenerator.Create()); - - long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - mbObj.BillNum = GetBillNum(maxBillNum2); - mbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); - - - mbObj.BillLocation = rightOrLeft; //右或左 - mbObj.ProviderCode = _providerCode; //供应商厂家代码 - mbObj.PartType = vmStr + " DP"; //零件类型 - mbObj.Capacity = curPageLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); //器具容量 - mbObj.PrintDate = printTime; //打印日期 - mbObj.PrintType = input.PrintType; - mbObj.ProductLine = input.ProductLine; - - var tempLst = curPageLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - if (tempLst.Count > 0) - { - mbObj.BeginVin = tempLst[0].VIN; - mbObj.EndVin = tempLst[tempLst.Count - 1].VIN; - mbObj.BeginHostSN = tempLst[0].HostSN.ToString(); - mbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); - } - mbObj.MinOnlineTime = tempLst.Min(itm => itm.OnlineTime); //本单据最早的上线时间 - - int posNum = 0; - string promMsg; //报表数据异常提示信息 - foreach (BillM100 billObj in curPageLst) - { - posNum++; - promMsg = ""; - //取物料信息 - MaterialExt leftObj = null; - MaterialExt rightObj = null; - if (billObj.AssemblyID != null) - { - //取单据包含的ERP总成列表 - List erpAssemblyLst = GetErpAssemblyListByBill((Guid)billObj.AssemblyID); - List erpCodeLst = erpAssemblyLst.Select(itm => itm.ErpAssemblyCode).ToList(); - //根据ERP总成编码取对应的物料扩展信息 - List materialExtLst = _materialExtRepository.Where(itm => erpCodeLst.Contains(itm.RelationKey)).ToList(); - if (erpCodeLst.Count != 4) - { - promMsg += $"*总成数量是{erpCodeLst.Count}*"; - } - if (erpCodeLst.Count == 4 && materialExtLst.Count == 0) - { - promMsg += $"*物料表没数据*"; - } - - //车型C8的第一二页分为左后, 右前,第三四页分为右后、左前;其它车型 第一二页分为左后、左前,第三四页分为右后、右前 - if (curPageLst[0].VehicleModelCode == "C8") - { - //C8 分为左前、右后 一组 右前、左后 一组,以前门为主,前门是右, 单子是右 - if (rightOrLeft == "右") - { - rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("右前")); - leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("左后")); - } - else //左 - { - rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("左前")); - leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("右后")); - } - } - else - { - leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains(rightOrLeft + "后")); - rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains(rightOrLeft + "前")); - } - } - - //填充门板装箱单明细 - MenBanPackingRec mbRec = new MenBanPackingRec(); - mbRec.SetId(GuidGenerator.Create()); - mbRec.M100BillId = billObj.Id; - mbRec.KNR = billObj.KNR; //KNR订单号 - mbRec.VIN = billObj.VIN; //底牌号 - mbRec.HostSN = billObj.HostSN.ToString(); //大众顺序号 - mbRec.TopBoxPositionNum = posNum.ToString().PadLeft(2, '0'); //上箱位号 - if (leftObj != null) //右后 - { - mbRec.VehicleModel_DoorPlankCode = leftObj.MaterialMemo; //车型门板代码 - mbRec.TopSAPMaterialNum = leftObj.MaterialNum; //上箱位 SAP物料号 - mbRec.TopMaterialDescription = leftObj.MaterialDescription2.IsNullOrEmpty() ? leftObj.MaterialDescription : leftObj.MaterialDescription2; //上箱位 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲) - } - else - { - if (billObj.VIN == null) - { - mbRec.TopMaterialDescription += "*断号*"; - } - else if (billObj.AssemblyID == null) - { - mbRec.TopMaterialDescription += "*未知总成*"; - } - else - { - mbRec.TopMaterialDescription += "*leftObj为空*"; - } - } - - if (rightObj != null) //右前 - { - mbRec.BelowSAPMaterialNum = rightObj.MaterialNum; //下箱位 SAP物料号 - mbRec.BelowMaterialDescription = rightObj.MaterialDescription2.IsNullOrEmpty() ? rightObj.MaterialDescription : rightObj.MaterialDescription2; //下箱位 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲) - } - else - { - if (billObj.VIN == null) - { - mbRec.TopMaterialDescription += "*断号*"; - } - else if (billObj.AssemblyID == null) - { - mbRec.BelowMaterialDescription += "*未知总成*"; - } - else - { - mbRec.BelowMaterialDescription += "*rightObj为空*"; - } - } - - if (string.IsNullOrEmpty(mbRec.KNR) == false && mbRec.KNR.Length == 10 && mbRec.KNR.Substring(4, 1) == "7" && string.IsNullOrEmpty(mbRec.VehicleModel_DoorPlankCode) == true) - { - mbRec.VehicleModel_DoorPlankCode += "*预批量*"; - } - - if (!String.IsNullOrEmpty(promMsg)) - { - mbRec.VehicleModel_DoorPlankCode += promMsg; - } - mbObj.Details.Add(mbRec); - } //foreach - retLst.Add(mbObj); //有用 - return retLst; - } /// /// 打印门板装箱单时调用库存系统接口 /// /// - private void CallWMSInterface_MB(List input) - { + //private void CallWMSInterface_MB(List input) + //{ - List targetMainLst = new List(); - List targetDetailLst = new List(); - List cxLst = new List(); - foreach (MenBanPackingList sourceObj in input) - { - TB_BILL targetMain = new TB_BILL(); - targetMain.BillNum = sourceObj.BillNum; //单据编号 - targetMain.State = 0; - targetMain.BillType = 206; //单据类型 - targetMain.SubBillType = 21004; //单据子类型 - targetMain.BillTime = sourceObj.PrintDate; //单据时间 - targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 - targetMain.DetailQty = 0; //明细数量 - targetMain.CustId = _providerCode; //供应商编号 - //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - //targetMain.DockCode = sourceObj.BillLocation; - - targetMain.GateCode = sourceObj.PartType; //B柱下 - targetMain.GateName = sourceObj.BillSerialNum; //顺序号 - targetMain.DockCode = sourceObj.BillLocation; //左或右 - targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间(预计到达时间) - targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 - targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 - targetMainLst.Add(targetMain); - int idx = 0; - int idx2 = 0; - foreach (MenBanPackingRec sourceRec in sourceObj.Details) - { - idx2++; - if (sourceRec.TopSAPMaterialNum.IsNullOrEmpty() == false) - { - var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.TopSAPMaterialNum && itm.MaterialType == "1"); - idx++; - TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.LineNum = idx2; //行号 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.SeqNum = idx2.ToString(); //顺序号sourceRec.HostSN.ToString() - targetDetail.PartCode = sourceRec.TopSAPMaterialNum; //物料号 - //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 - targetDetail.ProjectId = ""; //车型 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.State = "0"; //状态 - targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; - targetDetail.FullBarCode = null; - targetDetail.VendId = sourceRec.KNR; - - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - if (sourceRec.BelowSAPMaterialNum.IsNullOrEmpty() == false) - { - var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.BelowSAPMaterialNum && itm.MaterialType == "1"); - - idx++; - TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = sourceRec.BelowSAPMaterialNum; //物料号 - targetDetail.LineNum = (idx2 + 12); //行号 - targetDetail.SeqNum = (idx2 + 12).ToString(); //顺序号sourceRec.HostSN.ToString() - //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; - targetDetail.FullBarCode = null; - targetDetail.VendId = sourceRec.KNR; - - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - } - //生成车型 - string cxStr = ""; - foreach (string cxObj in cxLst.Distinct()) - { - cxStr += cxObj + "、"; - } - if (cxStr.Length > 0) - { - cxStr = cxStr.Substring(0, cxStr.Length - 1); - } - targetMain.ProjectId = cxStr; //添加车型 + // List targetMainLst = new List(); + // List targetDetailLst = new List(); + // List cxLst = new List(); + // foreach (MenBanPackingList sourceObj in input) + // { + // TB_BILL targetMain = new TB_BILL(); + // targetMain.BillNum = sourceObj.BillNum; //单据编号 + // targetMain.State = 0; + // targetMain.BillType = 206; //单据类型 + // targetMain.SubBillType = 21004; //单据子类型 + // targetMain.BillTime = sourceObj.PrintDate; //单据时间 + // targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 + // targetMain.DetailQty = 0; //明细数量 + // targetMain.CustId = _providerCode; //供应商编号 + // //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + // //targetMain.DockCode = sourceObj.BillLocation; + + // targetMain.GateCode = sourceObj.PartType; //B柱下 + // targetMain.GateName = sourceObj.BillSerialNum; //顺序号 + // targetMain.DockCode = sourceObj.BillLocation; //左或右 + // targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间(预计到达时间) + // targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 + // targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 + // targetMainLst.Add(targetMain); + // int idx = 0; + // int idx2 = 0; + // foreach (MenBanPackingRec sourceRec in sourceObj.Details) + // { + // idx2++; + // if (sourceRec.TopSAPMaterialNum.IsNullOrEmpty() == false) + // { + // var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.TopSAPMaterialNum && itm.MaterialType == "1"); + // idx++; + // TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); + // targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + // targetDetail.LineNum = idx2; //行号 + // targetDetail.VinCode = sourceRec.VIN; //VIN码 + // targetDetail.SeqNum = idx2.ToString(); //顺序号sourceRec.HostSN.ToString() + // targetDetail.PartCode = sourceRec.TopSAPMaterialNum; //物料号 + // //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 + // targetDetail.ProjectId = ""; //车型 + // targetDetail.PlanQty = 1; //计划数量 + // targetDetail.State = "0"; //状态 + // targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; + // targetDetail.FullBarCode = null; + // targetDetail.VendId = sourceRec.KNR; + + // //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + + // targetDetailLst.Add(targetDetail); + // if (materialObj != null && materialObj.VehicleModel != null) + // { + // cxLst.Add(materialObj.VehicleModel); + // } + // } + // if (sourceRec.BelowSAPMaterialNum.IsNullOrEmpty() == false) + // { + // var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.BelowSAPMaterialNum && itm.MaterialType == "1"); + + // idx++; + // TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); + // targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + // targetDetail.VinCode = sourceRec.VIN; //VIN码 + // targetDetail.PartCode = sourceRec.BelowSAPMaterialNum; //物料号 + // targetDetail.LineNum = (idx2 + 12); //行号 + // targetDetail.SeqNum = (idx2 + 12).ToString(); //顺序号sourceRec.HostSN.ToString() + // //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 + // targetDetail.ProjectId = ""; //车型 + // targetDetail.State = "0"; //状态 + // targetDetail.PlanQty = 1; //计划数量 + // targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; + // targetDetail.FullBarCode = null; + // targetDetail.VendId = sourceRec.KNR; + + // //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + + // targetDetailLst.Add(targetDetail); + // if (materialObj != null && materialObj.VehicleModel != null) + // { + // cxLst.Add(materialObj.VehicleModel); + // } + // } + // } + // //生成车型 + // string cxStr = ""; + // foreach (string cxObj in cxLst.Distinct()) + // { + // cxStr += cxObj + "、"; + // } + // if (cxStr.Length > 0) + // { + // cxStr = cxStr.Substring(0, cxStr.Length - 1); + // } + // targetMain.ProjectId = cxStr; //添加车型 - if (string.IsNullOrEmpty(cxStr)) - { - targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - } + // if (string.IsNullOrEmpty(cxStr)) + // { + // targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + // } - } - foreach (TB_BILL targetMain in targetMainLst) - { - //明细数量 - targetMain.DetailQty = targetDetailLst.Where(p=>p.BillNum== targetMain.BillNum).Count(); - int cnt = InsertOrUpdateWMSMain(targetMain); - if (cnt == 0) - { - throw new Exception("插入或更新库存系统接口表记录数为零!"); - } - } - foreach (TS_SORT_DETAIL targetDetail in targetDetailLst) - { - int cnt = InsertOrUpdateWMSDetail(targetDetail); - if (cnt == 0) - { - throw new Exception("插入或更新库存系统接口表记录数为零!"); - } - } + // } + // foreach (TB_BILL targetMain in targetMainLst) + // { + // //明细数量 + // targetMain.DetailQty = targetDetailLst.Where(p=>p.BillNum== targetMain.BillNum).Count(); + // int cnt = InsertOrUpdateWMSMain(targetMain); + // if (cnt == 0) + // { + // throw new Exception("插入或更新库存系统接口表记录数为零!"); + // } + // } + // foreach (TS_SORT_DETAIL targetDetail in targetDetailLst) + // { + // int cnt = InsertOrUpdateWMSDetail(targetDetail); + // if (cnt == 0) + // { + // throw new Exception("插入或更新库存系统接口表记录数为零!"); + // } + // } - } - private int InsertOrUpdateWMSMain(TB_BILL targetMain) - { - int ret = 0; - string sqlSelMain = string.Format("select * from TB_BILL where BillNum = '{0}'", targetMain.BillNum); - TB_BILL wmsMain = _wmsDapperRepository.GetSingleBySql(sqlSelMain, true); - if (wmsMain == null) - { - string sqlInsertMain = @" - insert into TB_BILL (BillNum, [State], BillType, SubBillType, BillTime, OperName, DetailQty, CustId, ProjectId, DockCode, GateCode, GateName, Remark) - values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')"; - sqlInsertMain = string.Format(sqlInsertMain, - targetMain.BillNum, targetMain.State, targetMain.BillType, targetMain.SubBillType, targetMain.BillTime, - targetMain.OperName, targetMain.DetailQty, targetMain.CustId, targetMain.ProjectId, targetMain.DockCode, targetMain.GateCode, targetMain.GateName, targetMain.Remark); - try - { - ret = _wmsDapperRepository.ExecuteSql(sqlInsertMain, null, true); - } - catch (Exception ex) - { - throw new Exception("调用InsertOrUpdateWMSMain方法时报错:" + ex.Message + "SQL:" + sqlInsertMain + "单据号:" + targetMain.BillNum); - } - } - else - { - if (wmsMain.State != 0) - { - throw new Exception("库存系统接口主表中已经存在该单据,并且已经排序,不能重新打印,单据号" + wmsMain.BillNum); - } - string sqlUpdateMain = @" - update TB_BILL set - [State] = '{1}', - BillType = '{2}', - SubBillType = '{3}', - BillTime = '{4}', - OperName = '{5}', - DetailQty = '{6}', - CustId = '{7}', - ProjectId = '{8}', - DockCode = '{9}', - GateCode = '{10}', - GateName = '{11}', - Remark = '{12}' - where BillNum = '{0}' - "; - sqlUpdateMain = string.Format(sqlUpdateMain, - targetMain.BillNum, targetMain.State, targetMain.BillType, targetMain.SubBillType, targetMain.BillTime, - targetMain.OperName, targetMain.DetailQty, targetMain.CustId, targetMain.ProjectId, targetMain.DockCode, targetMain.GateCode, targetMain.GateName, targetMain.Remark); - try - { - ret = _wmsDapperRepository.ExecuteSql(sqlUpdateMain, null, true); - } - catch (Exception ex) - { - throw new Exception("调用InsertOrUpdateWMSMain方法时报错:" + ex.Message + "SQL:" + sqlUpdateMain + "单据号:" + targetMain.BillNum); - } - - } - return ret; - } - private int InsertOrUpdateWMSDetail(TS_SORT_DETAIL targetDetail) - { - int ret = 0; - string sqlSelDetail = string.Format("select * from TS_SORT_DETAIL where BillNum = '{0}' and VinCode = '{1}' and PartCode = '{2}'", targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode); - TS_SORT_DETAIL wmsDetail = _wmsDapperRepository.GetSingleBySql(sqlSelDetail, true); - if (wmsDetail == null) - { - string sqlInsertDetail = @" - insert into TS_SORT_DETAIL ( - BillNum, VinCode, PartCode, LineNum, SeqNum, - ProjectId, [State], BarCode, PlanQty, CustPartCode, - FullBarCode, VendId) - values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}')"; - sqlInsertDetail = string.Format(sqlInsertDetail, - targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode, targetDetail.LineNum, targetDetail.SeqNum, - targetDetail.ProjectId, targetDetail.State, targetDetail.BarCode, targetDetail.PlanQty, targetDetail.CustPartCode, - targetDetail.FullBarCode, targetDetail.VendId); - try - { - ret = _wmsDapperRepository.ExecuteSql(sqlInsertDetail, null, true); - } - catch (Exception ex) - { - throw new Exception("调用InsertOrUpdateWMSDetail方法时报错:" + ex.Message + "SQL:" + sqlInsertDetail); - } - } - else - { - string sqlUpdateDetail = @" - update TS_SORT_DETAIL set - LineNum = '{3}', - SeqNum = '{4}', - ProjectId = '{5}', - [State] = '{6}', - BarCode = '{7}', - PlanQty = '{8}', - CustPartCode = '{9}', - FullBarCode = '{10}' - VendId = '{11}' - where BillNum = '{0}' and VinCode = '{1}' and PartCode = '{2}' - "; - sqlUpdateDetail = string.Format(sqlUpdateDetail, - targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode, targetDetail.LineNum, targetDetail.SeqNum, - targetDetail.ProjectId, targetDetail.State, targetDetail.BarCode, targetDetail.PlanQty, targetDetail.CustPartCode, - targetDetail.FullBarCode, targetDetail.VendId); - try - { - ret = _wmsDapperRepository.ExecuteSql(sqlUpdateDetail, null, true); - } - catch (Exception ex) - { - throw new Exception("调用InsertOrUpdateWMSDetail方法时报错:" + ex.Message + "SQL:" + sqlUpdateDetail); - } - } - return ret; - } - - #endregion - - #region 柱护板装箱单 - //private void DelOrScrapWMSInterface(string billNum) + //} + //private int InsertOrUpdateWMSMain(TB_BILL targetMain) //{ - // //重新打印时,库存系统接口如果存在已发运的正常打印单据,则不允许重新打印;如果存在未发运的正常打印单据则删除该单据 - // string oldBillNum = billNum; - // TB_BILL oldBillObj = _wmsDapperRepository.GetSingleBySql($"select top 1 * from TB_BILL where BillNum = '{oldBillNum}'", true); - // if (oldBillObj != null) + // int ret = 0; + // string sqlSelMain = string.Format("select * from TB_BILL where BillNum = '{0}'", targetMain.BillNum); + // TB_BILL wmsMain = _wmsDapperRepository.GetSingleBySql(sqlSelMain, true); + // if (wmsMain == null) + // { + // string sqlInsertMain = @" + // insert into TB_BILL (BillNum, [State], BillType, SubBillType, BillTime, OperName, DetailQty, CustId, ProjectId, DockCode, GateCode, GateName, Remark) + // values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')"; + // sqlInsertMain = string.Format(sqlInsertMain, + // targetMain.BillNum, targetMain.State, targetMain.BillType, targetMain.SubBillType, targetMain.BillTime, + // targetMain.OperName, targetMain.DetailQty, targetMain.CustId, targetMain.ProjectId, targetMain.DockCode, targetMain.GateCode, targetMain.GateName, targetMain.Remark); + // try + // { + // ret = _wmsDapperRepository.ExecuteSql(sqlInsertMain, null, true); + // } + // catch (Exception ex) + // { + // throw new Exception("调用InsertOrUpdateWMSMain方法时报错:" + ex.Message + "SQL:" + sqlInsertMain + "单据号:" + targetMain.BillNum); + // } + // } + // else // { - // if (oldBillObj.State == 0) + // if (wmsMain.State != 0) + // { + // throw new Exception("库存系统接口主表中已经存在该单据,并且已经排序,不能重新打印,单据号" + wmsMain.BillNum); + // } + // string sqlUpdateMain = @" + // update TB_BILL set + // [State] = '{1}', + // BillType = '{2}', + // SubBillType = '{3}', + // BillTime = '{4}', + // OperName = '{5}', + // DetailQty = '{6}', + // CustId = '{7}', + // ProjectId = '{8}', + // DockCode = '{9}', + // GateCode = '{10}', + // GateName = '{11}', + // Remark = '{12}' + // where BillNum = '{0}' + // "; + // sqlUpdateMain = string.Format(sqlUpdateMain, + // targetMain.BillNum, targetMain.State, targetMain.BillType, targetMain.SubBillType, targetMain.BillTime, + // targetMain.OperName, targetMain.DetailQty, targetMain.CustId, targetMain.ProjectId, targetMain.DockCode, targetMain.GateCode, targetMain.GateName, targetMain.Remark); + // try + // { + // ret = _wmsDapperRepository.ExecuteSql(sqlUpdateMain, null, true); + // } + // catch (Exception ex) // { - // string sqlMain = $"delete from TS_SORT_DETAIL where BillNum = '{oldBillNum}'"; - // _wmsDapperRepository.ExecuteSql(sqlMain, null, true); + // throw new Exception("调用InsertOrUpdateWMSMain方法时报错:" + ex.Message + "SQL:" + sqlUpdateMain + "单据号:" + targetMain.BillNum); + // } - // string sqlDetail = $"delete from TB_BILL where BillNum = '{oldBillNum}'"; - // _wmsDapperRepository.ExecuteSql(sqlDetail, null, true); + // } + // return ret; + //} + //private int InsertOrUpdateWMSDetail(TS_SORT_DETAIL targetDetail) + //{ + // int ret = 0; + // string sqlSelDetail = string.Format("select * from TS_SORT_DETAIL where BillNum = '{0}' and VinCode = '{1}' and PartCode = '{2}'", targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode); + // TS_SORT_DETAIL wmsDetail = _wmsDapperRepository.GetSingleBySql(sqlSelDetail, true); + // if (wmsDetail == null) + // { + // string sqlInsertDetail = @" + // insert into TS_SORT_DETAIL ( + // BillNum, VinCode, PartCode, LineNum, SeqNum, + // ProjectId, [State], BarCode, PlanQty, CustPartCode, + // FullBarCode, VendId) + // values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}')"; + // sqlInsertDetail = string.Format(sqlInsertDetail, + // targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode, targetDetail.LineNum, targetDetail.SeqNum, + // targetDetail.ProjectId, targetDetail.State, targetDetail.BarCode, targetDetail.PlanQty, targetDetail.CustPartCode, + // targetDetail.FullBarCode, targetDetail.VendId); + // try + // { + // ret = _wmsDapperRepository.ExecuteSql(sqlInsertDetail, null, true); // } - // else + // catch (Exception ex) + // { + // throw new Exception("调用InsertOrUpdateWMSDetail方法时报错:" + ex.Message + "SQL:" + sqlInsertDetail); + // } + // } + // else + // { + // string sqlUpdateDetail = @" + // update TS_SORT_DETAIL set + // LineNum = '{3}', + // SeqNum = '{4}', + // ProjectId = '{5}', + // [State] = '{6}', + // BarCode = '{7}', + // PlanQty = '{8}', + // CustPartCode = '{9}', + // FullBarCode = '{10}' + // VendId = '{11}' + // where BillNum = '{0}' and VinCode = '{1}' and PartCode = '{2}' + // "; + // sqlUpdateDetail = string.Format(sqlUpdateDetail, + // targetDetail.BillNum, targetDetail.VinCode, targetDetail.PartCode, targetDetail.LineNum, targetDetail.SeqNum, + // targetDetail.ProjectId, targetDetail.State, targetDetail.BarCode, targetDetail.PlanQty, targetDetail.CustPartCode, + // targetDetail.FullBarCode, targetDetail.VendId); + // try + // { + // ret = _wmsDapperRepository.ExecuteSql(sqlUpdateDetail, null, true); + // } + // catch (Exception ex) // { - // throw new BusinessException("1001", $"该单据{oldBillNum}在库存系统中已经排序或发运,不允许删除!"); + // throw new Exception("调用InsertOrUpdateWMSDetail方法时报错:" + ex.Message + "SQL:" + sqlUpdateDetail); // } // } + // return ret; //} - /// - /// 根据条件取用于打印的柱护板单据列表 - /// - /// - /// - /// - private async Task> GetZHBReportDetailList(ZhuHuBanPrintInputDto input, bool isFillBreakNum = false) - { - List billLst = new List(); - ListResultDto ret = new ListResultDto(billLst); + #endregion - int printBillCnt = 0; - if (input.PrintType == PrintTypeEnum.正常打印) - { - if ((input.BeginHostSN % 10000) > 1999) - { - throw new Exception("起始大众顺序号不能大于1999!"); - } - if (input.BeginHostSN > input.EndHostSN) - { - throw new Exception("起始大众顺序号不能大于止大众顺序号!"); - } - printBillCnt = input.EndHostSN - input.BeginHostSN + 1; + #region 报表公共方法 - var query = from a in _billM100Repository.Where(r => r.ProductLine == input.ProductLine - && r.CanNotPrint != true - && string.IsNullOrEmpty(r.PrintBillNum) == true - && r.HostSN >= input.BeginHostSN - && r.HostSN <= input.EndHostSN) - join b in _zHBPrintStatusRepository.Where(r => r.GroupName == input.GroupName) - on a.VIN equals b.VIN - into cls - from c in cls.DefaultIfEmpty() - where c.GroupName != null - select a.HostSN; - - - var oldsn = await query.ToListAsync(); - if ((input.EndHostSN % 10000) > 1999) - { - var firstObj = await _billM100Repository.FirstOrDefaultAsync(itm => - itm.ProductLine == input.ProductLine //指定生产线 - && itm.CanNotPrint != true //能打印 - && string.IsNullOrEmpty(itm.PrintBillNum) == true //不等于 已打印 - && itm.HostSN == input.BeginHostSN - && !oldsn.Contains(itm.HostSN) - ); - if (firstObj != null) - { - string firstSNStr = firstObj.SerialNumStr; - List idLst = await _billM100Repository.Where(itm => - itm.ProductLine == input.ProductLine //指定生产线 - && itm.CanNotPrint != true //能打印 - && string.IsNullOrEmpty(itm.PrintBillNum) == true //不等于 已打印 - && itm.SerialNumStr.CompareTo(firstSNStr) >= 0 - && !oldsn.Contains(itm.HostSN) - ) - .OrderBy(itm => itm.SerialNumStr) - .Take(printBillCnt * 2).Select(itm => itm.Id).ToListAsync(); - - var tempLst = await _billM100Repository.GetListAsync(itm => idLst.Contains(itm.Id), true); - - #region 1998、1999和0001、0002反了 - var tempLst1999 = tempLst.Where(itm => itm.HostSN % 10000 > 1999 - 240).OrderBy(itm => itm.HostSN).ToList(); - var tempLst0001 = tempLst.Where(itm => itm.HostSN % 10000 < 240).OrderBy(itm => itm.HostSN).ToList(); - billLst.AddRange(tempLst1999); - billLst.AddRange(tempLst0001); - billLst = billLst.Take(printBillCnt).ToList(); - #endregion - //billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); - } - else - { - throw new Exception("没有找到起始大众顺序号!!"); - } - } - else //起止大众顺序号都小于等于1999 - { - var firstObj2 = await _billM100Repository.FirstOrDefaultAsync(itm => - itm.ProductLine == input.ProductLine //指定生产线 - && itm.CanNotPrint != true //能打印 - && string.IsNullOrEmpty(itm.PrintBillNum) == true //不等于 已打印 - && itm.HostSN == input.BeginHostSN - && !oldsn.Contains(itm.HostSN) - ); - if (firstObj2 != null) - { - string firstSNStr2 = firstObj2.SerialNumStr; - billLst = await _billM100Repository.GetListAsync(itm => - itm.ProductLine == input.ProductLine //指定生产线 - && itm.CanNotPrint != true //能打印 - && string.IsNullOrEmpty(itm.PrintBillNum) == true //不等于 已打印 - && itm.SerialNumStr.CompareTo(firstSNStr2) >= 0 - && itm.HostSN >= input.BeginHostSN - && itm.HostSN <= input.EndHostSN - && !oldsn.Contains(itm.HostSN) - , true); - } - else - { - throw new Exception("没有找到起始大众顺序号!!"); - } - billLst = billLst.OrderBy(itm => itm.HostSN).ToList(); - } - - bool hasData = billLst.Any(); - if (hasData == false) - { - ret.Message = $"输入的起始大众顺序号没有对应的数据。生产线:{input.ProductLine},起止顺序号:{input.BeginHostSN} - {input.EndHostSN}"; - ret.Status = false; - return ret; - } - } - else if (input.PrintType == PrintTypeEnum.补打) - { - //string beginVin = input.BeginVin.TryToRight(6); - //string endVin = input.EndVin.TryToRight(6); - ////printBillCnt = endVin.TryToIntZero() - beginVin.TryToIntZero() + 1; - - //string sql = "select Id from FisBillM100 where ProductLine = '{0}' and BillStatus = {1} and right(vin,6) between '{2}' and '{3}'"; - //sql = string.Format(sql, input.ProductLine, (int)BillStatusEnum.Match, beginVin, endVin); - //List guidLst = await _newJitDapperRepository.GetListBySqlAsync(sql, true); - //if (guidLst.Count == 0) - //{ - // ret.Message = $"输入的起止底盘号没有对应的数据。生产线:{input.ProductLine},底盘号:{beginVin}至{endVin}"; - // ret.Status = false; - // return ret; - //} - - ////取指定生产线、等于已匹配状态、起止VIN范围 - //billLst = await _billM100Repository.GetListAsync( - // itm => guidLst.Contains(itm.Id) - // , true); - //billLst = billLst.OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - } - - #region 断号处理 - if (isFillBreakNum == true && billLst.Count > 1 && input.PrintType != PrintTypeEnum.补打) - { - billLst = DoBreakNumOperation(input.BeginHostSN, input.EndHostSN, billLst); - } - #endregion + /// + /// 根据生产线获取正常打印单据的起始大众顺序号 + /// + /// 生产线 + /// 起始大众顺序号 + //[UnitOfWork] + //[HttpGet] + //[Route("get-print-start-hostsn")] + //public virtual async Task> GetPrintStartHostSN(string productLine) + //{ + // int? beginHostSN = null; + // try + // { + // //存在已打印单据 + // var publishQry = _billM100Repository.Where(itm => itm.ProductLine == productLine && itm.BillStatus == BillStatusEnum.Publish); + // if (publishQry.Any() == true) + // { + // //取已打印最后一个单据 + // DateTime publishMaxCreateTime = publishQry.Max(itm => itm.CreationTime); + // //取指定生产线、不等于已打印状态、大于已打印最后一个单据、最小的CreationTime + // var query = _billM100Repository.Where(itm => + // itm.ProductLine == productLine + // && (itm.BillStatus != BillStatusEnum.Publish) + // && itm.CreationTime > publishMaxCreateTime); + // if (query.Any()) + // { + // DateTime minCreateTime = query.Min(itm => itm.CreationTime); + // //根据CreationTime取大众顺序号 + // var obj = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == productLine && itm.CreationTime == minCreateTime); + // if (obj != null) + // { + // beginHostSN = obj.HostSN; + // } + // } + // } + // else + // { + // //取指定生产线、不等于已打印状态、最小的CreationTime + // var query2 = _billM100Repository.Where(itm => + // itm.ProductLine == productLine + // && itm.BillStatus != BillStatusEnum.Publish); + // if (query2.Any()) + // { + // DateTime minCreateTime2 = query2.Min(itm => itm.CreationTime); + // //根据流水号取大众顺序号 + // var obj = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == productLine && itm.CreationTime == minCreateTime2); + // if (obj != null) + // { + // beginHostSN = obj.HostSN; + // } + // } + // } + // return new ObjectResultDto(beginHostSN); + // } + // catch (Exception ex) + // { + // ObjectResultDto ret = new ObjectResultDto(); + // ret.Status = false; + // ret.Message = _errorMessagePrefix + "GetPrintStartHostSN 执行出错:" + ex.Message; + // _logger.LogError(ret.Message); + // return ret; + // } + //} - if ((input.EndHostSN % 10000) > 1999) - { - #region 1998、1999和0001、0002反了 - var tempLst1999 = billLst.Where(itm => itm.HostSN % 10000 > 1999 - 240).OrderBy(itm => itm.HostSN).ToList(); - var tempLst0001 = billLst.Where(itm => itm.HostSN % 10000 < 240).OrderBy(itm => itm.HostSN).ToList(); - billLst.Clear(); - billLst.AddRange(tempLst1999); - billLst.AddRange(tempLst0001); - if (printBillCnt > 0) //tst - { - billLst = billLst.Take(printBillCnt).ToList(); - } - #endregion - } - else - { - if (printBillCnt > 0) //tst - billLst = billLst.OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).Take(printBillCnt).ToList(); - else - billLst = billLst.OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - } - //billLst = billLst.OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).Take(24).ToList(); - ret.Item = billLst; - return ret; - } /// - /// 打印柱护板(3*8 左右合并成一个单元格)A上C上 + /// 打印门板装箱单 /// - /// /// - /// - /// - /// - /// - /// - /// - private List DoZHBPrint_3x8_LRMerge(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) - { - List retLst = new List(); - - //填充柱护板装箱单主实体 - ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); - zhbObj.SetId(GuidGenerator.Create()); - - zhbObj.BillNum = GetBillNum(maxBillNum); - zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); - - zhbObj.BillLocation = null; //右或左或空 - zhbObj.ProviderCode = _providerCode; //供应商厂家代码 - zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 - //int rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish); - int rongLiang = billLst.Count(); - zhbObj.Capacity = $"{rongLiang * 2} + {rongLiang * 2}"; //器具容量 - zhbObj.PrintDate = printTime; //打印日期 - zhbObj.PrintType = input.PrintType; - zhbObj.ProductLine = input.ProductLine; - - var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - if (tempLst.Count > 0) - { - zhbObj.BeginVin = tempLst[0].VIN; ; - zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; - zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); - zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); - } - zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + /// 执行成功返回真 + //[UnitOfWork] + //[HttpPost] + //[Route("print-menban-packing-list")] + //public virtual async Task> PrintMenBanPackingList(MenBanPrintInputDto input) + //{ + // /* + // 1、 一次打印24辆车,分为4页纸张,四个纸张的装箱单号不是一样 + // 2、 按大众顺序号过滤打印,一次打印12套(不是24辆车),到1999后按2000、2001顺序排,下次打印按3延续排列右前 + // 5、 物料描述字体尽量大 + // 6、 右上角的“01 左” 字体尽量大 + // 7、 零件类别: C8是车型, DP表示门板 + // 8、 器具容量: 24表示当页包含24个门板 + // 9、 车型门板代码: 从物料汇总文件- 补充备注 字段中取 Q5-DV OQ N5K 3L4 QQ2 6XE 7HB 9VS 7X1 3Y4 + // 3、 根据物料描述字段区分左后、左前、右后、右前 + // 4、 车型C8的第一二页分为左后, 右前,第三四页分为右后、左前;其它车型 第一二页分为左后、左前,第三四页分为右后、 + // 10、 物料描述: 从物料汇总文件-物料描述 字段中取 + // */ + // MenBanPrintResultDto retObj = new MenBanPrintResultDto(); + // ObjectResultDto ret = new ObjectResultDto(retObj); + // ret.Status = false; + // try + // { + // List reportMainLst = new List(); - //取当前页的详细信息 - foreach (BillM100 billObj in billLst) - { - ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - if (billObj.BillM100Parts != null && billObj.BillM100Parts.Count > 0) - { - //取柱护板-A上C上 - if (zhbPartType == "A上C上") - { - //左、右两个单元格合并,合并后一页有24个单元格(3行*8列),一页包含24辆车、48个A上柱护板、48个C上柱护板 - MaterialExt materialObj = GetZhuHuBanByType("A柱上", rightOrLeft + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } + // if (input.PrintType == PrintTypeEnum.正常打印) + // { + // if (input.BeginHostSN != 0 && input.EndHostSN != 0) + // { + // if (input.BeginHostSN > input.EndHostSN) + // { + // ret.Message = "止大众顺序号必须大于等于起大众顺序号!"; + // ret.Status = false; + // return ret; + // } + // } + // ListResultDto tempLst = await GetMBReportDetailList(input, true); //----------------------------- + // List billLst = tempLst.Item; + // if (tempLst.Status == false) + // { + // ret.Message = tempLst.Message; + // ret.Status = false; + // return ret; + // } - MaterialExt materialObj2 = GetZhuHuBanByType("C柱上", rightOrLeft + "侧", billObj); - if (materialObj2 != null) - { - zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; - zhbRec.PartCode2 = materialObj2.RelationKey; - } + // int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - } //A上C上 - } - zhbObj.Details.Add(zhbRec); - } //foreach - retLst.Add(zhbObj); - return retLst; - } //DoZHBPrint + // double maxBillNum = 0; + + // DateTime printTime = ServerHelper.CurrentDateTime; - /// - /// 打印柱护板(3*8 分左右)A柱下A中 - /// - /// - /// - /// - /// - /// - /// - /// - /// - private List DoZHBPrint_3x8_LR(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) - { - List retLst = new List(); - - //填充柱护板装箱单主实体 - ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); - zhbObj.SetId(GuidGenerator.Create()); - - long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - zhbObj.BillNum = GetBillNum(maxBillNum2); - zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); - - zhbObj.BillLocation = rightOrLeft; //右或左或空 - zhbObj.ProviderCode = _providerCode; //供应商厂家代码 - zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 - //string rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); - string rongLiang = billLst.Count().ToString(); - zhbObj.Capacity = rongLiang + "+" + rongLiang; //器具容量 - zhbObj.PrintDate = printTime; //打印日期 - zhbObj.PrintType = input.PrintType; - zhbObj.ProductLine = input.ProductLine; - var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - if (tempLst.Count > 0) - { - zhbObj.BeginVin = tempLst[0].VIN; - zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; - zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); - zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); - } - zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + // for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) + // { + // //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 + // double maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); + // // 先打印两张:左后左前,再打印两张:右后右前 + // List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); + // List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); + + // //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 + // Guid sortId = GuidGenerator.Create(); + // foreach (var leftItm in leftLst) + // { + // leftItm.SortId = sortId; + // } + // foreach (var rightItm in rightLst) + // { + // rightItm.SortId = sortId; + // } + // reportMainLst.AddRange(rightLst); + // reportMainLst.AddRange(leftLst); + // } - //取当前页的详细信息 - foreach (BillM100 billObj in billLst) - { - ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - if (billObj.BillM100Parts != null && billObj.BillM100Parts.Count > 0) - { - //取A柱下、A中 - if (zhbPartType == "A柱下A中") - { - //每页3行*8列,一次打印24辆车,分两页,一张显示左A柱下A中、一张显示右; - //紧邻两行,上行显示A下、下行显示A中。A下目前只有一种颜色 - MaterialExt materialObj = GetZhuHuBanByType("A柱下", rightOrLeft + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } + // //调用派格版库存接口 + // CallWMSInterface_MB(reportMainLst); - MaterialExt materialObj2 = GetZhuHuBanByType("A柱中", rightOrLeft + "侧", billObj); - if (materialObj2 != null) - { - zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; - zhbRec.PartCode2 = materialObj2.RelationKey; - } + // //插入门板打印记录表 + // await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true); - }//if A柱下A中 - } - zhbObj.Details.Add(zhbRec); - } //foreach - retLst.Add(zhbObj); - return retLst; - } //DoZHBPrint + // //更新M100的门板打印标志:BillStatus=3 + // foreach (BillM100 billObj in billLst) + // { + // if (billObj.BillStatus == BillStatusEnum.Match) + // { + // billObj.SetBillStatus(BillStatusEnum.Publish); + // billObj.PrintTime = ServerHelper.CurrentDateTime; + // billObj.NeedReplenishPrint = 0; //不需要补打 + // await _billM100Repository.UpdateAsync(billObj, true); + // } + // else if (billObj.BillStatus == BillStatusEnum.NotMatch) + // { + // //billObj.PrintTime = ServerHelper.CurrentDateTime; + // billObj.NeedReplenishPrint = 1; //需要补打 + // await _billM100Repository.UpdateAsync(billObj, true); + // } + // } + // } + // else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 + // { + // reportMainLst = await _menBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); + // //按大众顺序号排序 + // foreach (var reportMainObj in reportMainLst) + // { + // List recLst = reportMainObj.Details; + // if (recLst == null) + // continue; + // //bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997")); + // //bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003")); + // bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997") + // || itm.HostSN.Contains("1996") || itm.HostSN.Contains("1995") || itm.HostSN.Contains("1994") + // || itm.HostSN.Contains("1993") || itm.HostSN.Contains("1992") || itm.HostSN.Contains("1991") + // || itm.HostSN.Contains("1990") || itm.HostSN.Contains("1989") || itm.HostSN.Contains("1988") + // || itm.HostSN.Contains("1987") || itm.HostSN.Contains("1986") || itm.HostSN.Contains("1985") + // || itm.HostSN.Contains("1984") || itm.HostSN.Contains("1983") || itm.HostSN.Contains("1982") + // || itm.HostSN.Contains("1981") || itm.HostSN.Contains("1980") || itm.HostSN.Contains("1979") + // || itm.HostSN.Contains("1978") || itm.HostSN.Contains("1977") || itm.HostSN.Contains("1976") + // ); + // bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003") + // || itm.HostSN.Contains("0004") || itm.HostSN.Contains("0005") || itm.HostSN.Contains("0006") + // || itm.HostSN.Contains("0007") || itm.HostSN.Contains("0008") || itm.HostSN.Contains("0009") + // || itm.HostSN.Contains("0010") || itm.HostSN.Contains("0011") || itm.HostSN.Contains("0012") + // || itm.HostSN.Contains("0013") || itm.HostSN.Contains("0014") || itm.HostSN.Contains("0015") + // || itm.HostSN.Contains("0016") || itm.HostSN.Contains("0017") || itm.HostSN.Contains("0018") + // || itm.HostSN.Contains("0019") || itm.HostSN.Contains("0020") || itm.HostSN.Contains("0021") + // || itm.HostSN.Contains("0022") || itm.HostSN.Contains("0023") || itm.HostSN.Contains("0024") + // ); + // if (has1999 && has0001) + // { + // reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN.TryToIntZero() % 10000) < 240 ? (itm.HostSN.TryToIntZero() % 10000 + 1999) : (itm.HostSN.TryToIntZero() % 10000)).ToList(); + // } + // else + // { + // reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); + // } + // } + // } + // else if (input.PrintType == PrintTypeEnum.补账打印) + // { + // List billLst = _billM100Repository.Where(itm => input.M100IdList.Contains(itm.Id)).OrderBy(itm => itm.SerialNumStr).ToList(); + // if (billLst.Count == 0) + // { + // ret.Message = "没有补打的单据,请先选择要补打的单据!"; + // ret.Status = false; + // return ret; + // } - /// - /// 打印柱护板(4*6 分左右)B柱上;B柱下;后轮上装饰板 - /// - /// - /// - /// - /// - /// - /// - /// - /// - private List DoZHBPrint_4x6_LR(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) - { - List retLst = new List(); + // int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - //填充柱护板装箱单主实体 - ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); - zhbObj.SetId(GuidGenerator.Create()); + // double maxBillNum = 0; - long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - zhbObj.BillNum = GetBillNum(maxBillNum2); - zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + // DateTime printTime = ServerHelper.CurrentDateTime; - zhbObj.BillLocation = rightOrLeft; //右或左 - zhbObj.ProviderCode = _providerCode; //供应商厂家代码 - zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 - if (zhbPartType == "后轮上装饰板") - { - //string rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); - string rongLiang = billLst.Count().ToString(); - zhbObj.Capacity = rongLiang + "+" + rongLiang; - } - else - { - //zhbObj.Capacity = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); //器具容量 - zhbObj.Capacity = billLst.Count().ToString(); //器具容量 - } - zhbObj.PrintDate = printTime; //打印日期 - zhbObj.PrintType = input.PrintType; - zhbObj.ProductLine = input.ProductLine; - var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - if (tempLst.Count > 0) - { - zhbObj.BeginVin = tempLst[0].VIN; - zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; - zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); - zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); - } - zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + // for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) + // { + // //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 + // double maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); + // // 先打印两张:左后左前,再打印两张:右后右前 + // List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); + // List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); + + // //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 + // Guid sortId = GuidGenerator.Create(); + // foreach (var leftItm in leftLst) + // { + // leftItm.SortId = sortId; + // } + // foreach (var rightItm in rightLst) + // { + // rightItm.SortId = sortId; + // } + // reportMainLst.AddRange(rightLst); + // reportMainLst.AddRange(leftLst); + // } + // //校验底盘号、零件是否重复打印 + // string checkVinPartRepeatSql = @" + // select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b + // on a.Id = b.MenBanPackingListId + // where a.ReportStatus = 0 + // and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}') + // "; + // foreach (MenBanPackingList reportMainObj in reportMainLst) + // { + // foreach (MenBanPackingRec reportRecObj in reportMainObj.Details) + // { + // string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.TopSAPMaterialNum); + // string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql(sql1, true); + // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false) + // { + // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.TopSAPMaterialNum}之间重复!"); + // } + + // string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.BelowSAPMaterialNum); + // string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql(sql2, true); + // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false) + // { + // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.BelowSAPMaterialNum}之间重复!"); + // } + // } + // } - //取当前页的详细信息 - foreach (BillM100 billObj in billLst) - { - ZhuHuBanPackingRec zhbRec; - if (billObj.BillM100Parts != null && billObj.BillM100Parts.Count > 0) - { - if (zhbPartType == "B柱上") - { - zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - - //B柱上:左右柱护板分别打印在不同的两页,每页4行*6列 - MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, rightOrLeft + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } - zhbObj.Details.Add(zhbRec); - } - else if (zhbPartType == "B柱下") - { - zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - - //B柱下:左右柱护板分别打印在不同的两页,每页4行*6列 - MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, rightOrLeft + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } - zhbObj.Details.Add(zhbRec); - } - else if (zhbPartType == "后轮上装饰板") - { - zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - //后轮上装饰板:显示后轮; 左右柱护板分别打印在不同的两页,每页4行*6列 - MaterialExt materialObj = GetZhuHuBanByType("后轮", rightOrLeft + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } + // //调用派格版库存接口 + // CallWMSInterface_MB(reportMainLst); - MaterialExt materialObj2 = GetZhuHuBanByType("上装饰板", rightOrLeft + "侧", billObj); - if (materialObj2 != null) - { - zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; - zhbRec.PartCode2 = materialObj2.RelationKey; - } - zhbObj.Details.Add(zhbRec); + // //插入门板打印记录表 + // await _menBanPackingListRepository.InsertManyAsync(reportMainLst); - } //if 后轮上装饰板 - } - else - { - //没有柱护板字典时,用空白单元格填充(之前不填充,造成后面空行) - zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - zhbObj.Details.Add(zhbRec); - } + // //更新M100的门板打印标志:BillStatus=3 + // foreach (BillM100 billObj in billLst) + // { + // if (billObj.BillStatus == BillStatusEnum.Match) + // { + // billObj.SetBillStatus(BillStatusEnum.Publish); + // billObj.PrintTime = ServerHelper.CurrentDateTime; + // await _billM100Repository.UpdateAsync(billObj); + // } + // } + // } - } //foreach - retLst.Add(zhbObj); - return retLst; - } //DoZHBPrint - /// - /// 打印柱护板(4*3 左右相邻)D柱 - /// - /// - /// - /// - /// - /// - /// - /// - /// - private List DoZHBPrint_4x3(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft = null) - { - List retLst = new List(); - - //填充柱护板装箱单主实体 - ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); - zhbObj.SetId(GuidGenerator.Create()); - - long maxBillNum2 = maxBillNum; //_sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - zhbObj.BillNum = GetBillNum(maxBillNum2); - zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); - - zhbObj.BillLocation = null; //右或左 - zhbObj.ProviderCode = _providerCode; //供应商厂家代码 - zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 - //int capacity = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish); - int capacity = billLst.Count(); - zhbObj.Capacity = $"{capacity}+{capacity}"; //器具容量 - zhbObj.PrintDate = printTime; //打印日期 - zhbObj.PrintType = input.PrintType; - zhbObj.ProductLine = input.ProductLine; - var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); - if (tempLst.Count > 0) - { - zhbObj.BeginVin = tempLst[0].VIN; - zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; - zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); - zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); - } - zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + // #region 格式转换 + // //实体 转 DTO + // List targetLst = ObjectMapper.Map, List>(reportMainLst); + // targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList(); - //取当前页的详细信息 - foreach (BillM100 billObj in billLst) - { - string[] leftRightArr = new string[2] { "左", "右" }; - if (rightOrLeft == "左") - { - leftRightArr = new string[1] { "左" }; - } - else if (rightOrLeft == "右") - { - leftRightArr = new string[1] { "右" }; - } - foreach (string leftRightStr in leftRightArr) - { - ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); - zhbRec.SetId(GuidGenerator.Create()); - zhbRec.M100BillId = billObj.Id; - zhbRec.KNR = billObj.KNR; - zhbRec.VIN = billObj.VIN; - zhbRec.HostSN = billObj.HostSN; - if (billObj.BillM100Parts != null && billObj.BillM100Parts.Count > 0) - { - if (zhbPartType == "D柱") - { - //D柱:每页4*6个单元格,相邻列分为左右两列,分别显示D柱左、D柱右。 右列的右侧留空格=》4*3套 - MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, leftRightStr + "侧", billObj); - if (materialObj != null) - { - zhbRec.MaterialDescription = materialObj.MaterialDescription; - zhbRec.PartCode = materialObj.RelationKey; - } - } //if D柱 - } - zhbObj.Details.Add(zhbRec); - } //二级foreach - } - retLst.Add(zhbObj); - return retLst; - } //DoZHBPrint - - /// - /// 打印柱护板装箱单时调用库存系统接口 - /// - /// - private void CallWMSInterface_ZHB(List input) - { - List targetMainLst = new List(); - List targetDetailLst = new List(); - - List cxLst = new List(); - foreach (ZhuHuBanPackingList sourceObj in input) - { - TB_BILL targetMain = new TB_BILL(); - targetMain.BillNum = sourceObj.BillNum; //单据编号 - targetMain.State = 0; - targetMain.BillType = 206; //单据类型 - targetMain.SubBillType = 20110; //单据子类型 - targetMain.BillTime = sourceObj.PrintDate; //单据时间 - targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 - targetMain.DetailQty = 0; //明细数量 - targetMain.CustId = _providerCode; //供应商编号 - //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - - targetMain.GateName = sourceObj.BillSerialNum; //顺序号 - targetMain.GateCode = sourceObj.PartType; //B柱下 - targetMain.DockCode = sourceObj.BillLocation; //左或右 - targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间 - targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 - targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 - - targetMainLst.Add(targetMain); - int idx = 0; - int barCode = 0; - foreach (ZhuHuBanPackingRec sourceRec in sourceObj.Details) - { - barCode++; - if (sourceRec.PartCode.IsNullOrEmpty() == false) - { - idx++; - //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode && itm.MaterialType == "2"); - var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode); - TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = materialObj == null ? sourceRec.PartCode : materialObj.MaterialNum; //SAP物料号 - targetDetail.LineNum = idx; //行号 - targetDetail.SeqNum = idx.ToString(); //顺序号 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - //targetDetail.BarCode = barCode.ToString(); //箱码 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = sourceRec.PartCode; //客户零件号 - targetDetail.FullBarCode = null; - targetDetail.VendId = sourceRec.KNR; - - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - - } - if (sourceRec.PartCode2.IsNullOrEmpty() == false) - { - idx++; - //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2 && itm.MaterialType == "2"); - var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2); - - TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = materialObj == null ? sourceRec.PartCode2 : materialObj.MaterialNum; //SAP物料号 - targetDetail.LineNum = idx; //行号 - targetDetail.SeqNum = idx.ToString(); //顺序号 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - //targetDetail.BarCode = barCode.ToString(); //箱码 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = sourceRec.PartCode2; //客户零件号 - targetDetail.FullBarCode = null; - targetDetail.VendId = sourceRec.KNR; - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - } - //生成车型 - string cxStr = ""; - foreach (string cxObj in cxLst.Distinct()) - { - cxStr += cxObj + "、"; - } - if (cxStr.Length > 0) - { - cxStr = cxStr.Substring(0, cxStr.Length - 1); - } - targetMain.ProjectId = cxStr; //添加车型 - - if (string.IsNullOrEmpty(cxStr)) - { - targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - } - } - foreach (TB_BILL targetMain in targetMainLst) - { - //明细数量 - targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); - - int cnt = InsertOrUpdateWMSMain(targetMain); - if (cnt == 0) - { - throw new Exception("插入或更新库存系统接口表记录数为零!"); - } - } - foreach (TS_SORT_DETAIL targetDetail in targetDetailLst) - { - int cnt = InsertOrUpdateWMSDetail(targetDetail); - if (cnt == 0) - { - throw new Exception("插入或更新库存系统接口表记录数为零!"); - } - } - } + // //补充空行 + // foreach (var masterObj in targetLst) + // { + // int trueCnt = masterObj.Details.Count; + // int planCnt = 12; + // if (trueCnt > planCnt) + // { + // throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + // } + // int diffCnt = planCnt - trueCnt; + // for (int i = 0; i < diffCnt; i++) + // { + // MenBanPackingRecDto dtlObj = new MenBanPackingRecDto(); + // masterObj.Details.Add(dtlObj); + // } + // } + // //子表BillNum赋值, BillNum填充空格 + // foreach (var masterObj in targetLst) + // { + // masterObj.BillNum = GetTrueString(masterObj.BillNum); + // int sn = 1; + // foreach (var detailObj in masterObj.Details) + // { + // detailObj.BillNum = masterObj.BillNum; + // detailObj.KNR = GetTrueString(detailObj.KNR); + // detailObj.sn = sn++; + // detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + // } + // } + // //返回结果格式转换 + // foreach (var masterObj in targetLst) + // { + // foreach (var detailObj in masterObj.Details) + // { + // retObj.DetailList.Add(detailObj); + // } + // masterObj.Details = null; + // retObj.MasterList.Add(masterObj); + // } + // #endregion + // ret.Status = true; + // return ret; + // } + // catch (Exception ex) + // { + // string errorMsg = _errorMessagePrefix + "PrintMenBanPackingList 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // throw new BusinessException("1001", errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } + //} - private static string GetTrueString(string str) - { - return str == null ? " " : str.Trim(); ; - } - /// - /// 查找M100结算件中是否包含指定类型(如D柱)的柱护板 - /// - /// - /// - /// - /// - private MaterialExt GetZhuHuBanByType(string p_materialType2, string p_materialType3, BillM100 p_billM100) - { - //List keyLst = _materialExtRepository.Where(itm => itm.MaterialType == "2" && itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3).Select(itm => itm.RelationKey).ToList(); //取A柱上物料对应的结算件编码 - List keyLst = _zhbCacheList.Where(itm => itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3).Select(itm => itm.RelationKey).ToList(); //取A柱上物料对应的结算件编码 - foreach (BillM100Part billObj in p_billM100.BillM100Parts) - { - if (keyLst.Contains(billObj.PartCode)) - { - //MaterialExt materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialType == "2" && itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3 && itm.RelationKey == billObj.PartCode); - MaterialExt materialObj = _zhbCacheList.FirstOrDefault(itm => itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3 && itm.RelationKey == billObj.PartCode); - if (materialObj != null) - { - return materialObj; - } - } - } - return null; - } - #endregion - #region 报表公共方法 /// - /// 打印前检查大众顺序号是否断号 + /// 打印柱护板装箱单 /// /// - /// 断号时Item不为空 - [UnitOfWork(false)] - [HttpPost] - [Route("check-mb-hostsn-break-num")] - public virtual async Task> CheckMBHostSNBreakNum(MenBanPrintInputDto input) - { - List retLst = new List(); - try - { - int lastNum = await GetMenBanLastPrintNum(input); - int newNum = lastNum + 1; - if ((lastNum % 10000) == 1999) - { - if ((input.BeginHostSN % 10000) != 1) - { - string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!"; - retLst.Add(msg); - _logger.LogDebug(msg); - } - } - else - { - if(newNum!= input.BeginHostSN) - { - string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!"; - retLst.Add(msg); - _logger.LogDebug(msg); - } - } - - ListResultDto tempLst = await GetMBReportDetailList(input, false); - List billLst = tempLst.Item; - if (billLst.Count < 2) - { - return new ListResultDto(retLst); - } - for (int i = 1; i < billLst.Count; i++) - { - BillM100 priorObj = billLst[i - 1]; - BillM100 curObj = billLst[i]; - int priorHostSN = (int)billLst[i - 1].HostSN; - int curHostSN = (int)billLst[i].HostSN; + /// 执行成功返回真 + //[UnitOfWork(isTransactional:false)] + //[HttpPost] + //[Route("print-zhuhuban-packing-list")] + //public virtual async Task> PrintZhuHuBanPackingList(ZhuHuBanPrintInputDto input) + //{ + // ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); + // ObjectResultDto ret = new ObjectResultDto(retObj); + // ret.Status = false; + // try + // { + // List reportMainLst = new List(); + // List forWMSLst = new List(); - if (curHostSN > priorHostSN) //0005、0006 - { - if (curHostSN > priorHostSN + 1) //0005、0008时,补号 0006、0007 - { - retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!"); - } - } - else if (curHostSN < priorHostSN) //1999到0001的情况 - { - if (curHostSN + _hostSNMaxVal > priorHostSN + 1) //0005、0008时,补号 0006、0007 - { - retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!"); - } - } - } - if (retLst.Count == 0 && billLst.Count < input.EndHostSN - input.BeginHostSN + 1) - { - retLst.Add($"本车装箱单不满架!"); - } - return new ListResultDto(retLst); - } - catch (Exception ex) - { - ListResultDto ret = new ListResultDto(); - ret.Status = false; - ret.Message = _errorMessagePrefix + "打印前检查大众顺序号是否断号ChecMBkHostSNBreakNum 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } + // if (input.PrintType == PrintTypeEnum.正常打印) + // { + // if (input.BeginHostSN > input.EndHostSN) + // { + // ret.Message = "起大众顺序号不能大于止大众顺序号!"; + // ret.Status = false; + // return ret; + // } - } + // ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- + // List billLst = tempLst.Item; + // if (tempLst.Status == false) + // { + // ret.Message = tempLst.Message; + // ret.Status = false; + // return ret; + // } + // if (billLst.Count > 24) + // { + // ret.Message = "打印柱护板单据的数量不能大于24!"; + // ret.Status = false; + // return ret; + // } + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - /// - /// 打印前检查大众顺序号是否断号 - /// - /// - /// 是否柱护板 - /// 断号时Item不为空 - [UnitOfWork(false)] - [HttpPost] - [Route("check-zhb-hostsn-break-num")] - public virtual async Task> CheckZHBHostSNBreakNum(ZhuHuBanPrintInputDto input) - { - List retLst = new List(); - try - { - int lastNum = await GetZhuHuBanLastPrintNum(input); - int newNum = lastNum + 1; - if ((lastNum % 10000) == 1999) - { - if ((input.BeginHostSN % 10000) != 1) - { - retLst.Add($"上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!"); - } - } - else - { - if (newNum != input.BeginHostSN) - { - retLst.Add($"上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!"); - } - } - ListResultDto tempLst = await GetZHBReportDetailList(input, false); - List billLst = tempLst.Item; - if (billLst.Count < 2) - { - return new ListResultDto(retLst); - } - for (int i = 1; i < billLst.Count; i++) - { - BillM100 priorObj = billLst[i - 1]; - BillM100 curObj = billLst[i]; - int priorHostSN = (int)billLst[i - 1].HostSN; - int curHostSN = (int)billLst[i].HostSN; + // long maxBillNum = 0; //子方法内部赋值 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; + + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + // //A柱下,A中 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + // //B柱上 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // //B柱下 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + + // //后轮,上装饰板 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + + // #region 调用库存接口 + // //List forWMSLst = new List(); + // //forWMSLst.AddRange(reportMainLst); + // //forWMSLst.AddRange(acLstOnlyWMSUse); + // CallWMSInterface_ZHB(forWMSLst); + // #endregion + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // } - if (curHostSN > priorHostSN) //0005、0006 - { - if (curHostSN > priorHostSN + 1) //0005、0008时,补号 0006、0007 - { - retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!"); - } - } - else if (curHostSN < priorHostSN) //1999到0001的情况 - { - if (curHostSN + _hostSNMaxVal > priorHostSN + 1) //0005、0008时,补号 0006、0007 - { - retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!"); - } - } - } - return new ListResultDto(retLst); - } - catch (Exception ex) - { - ListResultDto ret = new ListResultDto(); - ret.Status = false; - ret.Message = _errorMessagePrefix + "打印前检查大众顺序号是否断号CheckZHBHostSNBreakNum 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // await _billM100Repository.UpdateManyAsync(updLst, true); - /// - /// 根据生产线获取正常打印单据的起始大众顺序号 - /// - /// 生产线 - /// 起始大众顺序号 - //[UnitOfWork] - //[HttpGet] - //[Route("get-print-start-hostsn")] - //public virtual async Task> GetPrintStartHostSN(string productLine) - //{ - // int? beginHostSN = null; - // try - // { - // //存在已打印单据 - // var publishQry = _billM100Repository.Where(itm => itm.ProductLine == productLine && itm.BillStatus == BillStatusEnum.Publish); - // if (publishQry.Any() == true) + // } + // else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 // { - // //取已打印最后一个单据 - // DateTime publishMaxCreateTime = publishQry.Max(itm => itm.CreationTime); - // //取指定生产线、不等于已打印状态、大于已打印最后一个单据、最小的CreationTime - // var query = _billM100Repository.Where(itm => - // itm.ProductLine == productLine - // && (itm.BillStatus != BillStatusEnum.Publish) - // && itm.CreationTime > publishMaxCreateTime); - // if (query.Any()) + // if (input.DataResultType == "1") //全部11条数据 // { - // DateTime minCreateTime = query.Min(itm => itm.CreationTime); - // //根据CreationTime取大众顺序号 - // var obj = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == productLine && itm.CreationTime == minCreateTime); - // if (obj != null) + // var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); + // if (firObj != null) // { - // beginHostSN = obj.HostSN; + // Guid? sortId = firObj.SortId; + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); // } // } - // } - // else - // { - // //取指定生产线、不等于已打印状态、最小的CreationTime - // var query2 = _billM100Repository.Where(itm => - // itm.ProductLine == productLine - // && itm.BillStatus != BillStatusEnum.Publish); - // if (query2.Any()) + // else // { - // DateTime minCreateTime2 = query2.Min(itm => itm.CreationTime); - // //根据流水号取大众顺序号 - // var obj = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == productLine && itm.CreationTime == minCreateTime2); - // if (obj != null) + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); + // } + + // //按大众顺序号排序 + // foreach (var reportMainObj in reportMainLst) + // { + // List recLst = reportMainObj.Details; + // if (recLst == null) + // continue; + // //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); + // //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); + // bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) >= 1999 - 24); + // bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) <= 24); + // if (has1999 && has0001) // { - // beginHostSN = obj.HostSN; + // reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) <= 23 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); + // } + // else + // { + // reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); // } // } // } - // return new ObjectResultDto(beginHostSN); - // } - // catch (Exception ex) - // { - // ObjectResultDto ret = new ObjectResultDto(); - // ret.Status = false; - // ret.Message = _errorMessagePrefix + "GetPrintStartHostSN 执行出错:" + ex.Message; - // _logger.LogError(ret.Message); - // return ret; - // } - //} + // else if (input.PrintType == PrintTypeEnum.补账打印) + // { + // if (input.M100IdList.Count > 24) + // { + // throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); + // } - /// - /// 根据生产线获取正常打印单据的起始大众顺序号2 - /// - /// 生产线 - /// 柱护板是1 门板是非1 - /// 柱护板分组类型 - /// 起始大众顺序号 - [UnitOfWork] - [HttpGet] - [Route("get-print-start-hostsn2")] - public virtual async Task> GetPrintStartHostSN2(string productLine, string isZhuHuBan,string GroupName=null) - { - int? beginHostSN = null; - try - { - if (isZhuHuBan == "1") //是柱护板, 根据PrintBillNum非空判断是柱护板 - { - //string minSNStr = await _billM100Repository.Where(itm => - // itm.ProductLine == productLine //指定生产线 - // && itm.CanNotPrint != true //能打印 - // && string.IsNullOrEmpty(itm.PrintBillNum) == true //等于 未打印 - // && itm.NeedReplenishPrint != 1 //排除补打 - // ).MinAsync(itm => itm.SerialNumStr); - string sql = @" -with d as -( - select *from [dbo].[FisZHBPrintStatus] where groupName='{1}' -) + // List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); + // if (billLst.Count == 0) + // { + // ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; + // ret.Status = false; + // return ret; + // } + // billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); -select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - where ProductLine='{0}' and (CanNotPrint !=1 or CanNotPrint is null) and (PrintBillNum is null or PrintBillNum ='') and (NeedReplenishPrint!=1 or NeedReplenishPrint is null) and d.BillStatus is null"; + // long maxBillNum = 0; //全局唯一装箱单号 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; //右上角顺序号01-99 - sql = string.Format(sql, productLine, GroupName); - var minSNStr = await _newJitDapperRepository.GetSingleBySqlAsync(sql); + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + // //A柱下,A中 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + // //B柱上 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // //B柱下 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + + // //后轮,上装饰板 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + + // #region 调用库存接口 + // //List forWMSLst = new List(); + // //forWMSLst.AddRange(reportMainLst); + // //forWMSLst.AddRange(acLstOnlyWMSUse); + // CallWMSInterface_ZHB(forWMSLst); + // #endregion + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // } + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // await _billM100Repository.UpdateManyAsync(updLst, true); + // } - beginHostSN = await _billM100Repository.Where(itm => - itm.ProductLine == productLine //指定生产线 - && itm.CanNotPrint != true //能打印 - && string.IsNullOrEmpty(itm.PrintBillNum) == true //等于 未打印 - && itm.SerialNumStr == minSNStr - ).MinAsync(itm => itm.HostSN); - } - else //---------------门板----------------------------------------------------------------------------------- - { - string minSNStr2 = await _billM100Repository.Where(itm => - itm.ProductLine == productLine //指定生产线 - && itm.CanNotPrint != true //能打印 - //&& itm.BillStatus == BillStatusEnum.Match //等于 未打印(和M100上线信息匹配) - && itm.BillStatus != BillStatusEnum.Publish //未知总成也显示在装箱单 - && itm.NeedReplenishPrint != 1 //排除补打 - ).MinAsync(itm => itm.SerialNumStr); - - beginHostSN = await _billM100Repository.Where(itm => - itm.ProductLine == productLine //指定生产线 - && itm.CanNotPrint != true //能打印 - //&& itm.BillStatus == BillStatusEnum.Match //等于 未打印 - && itm.BillStatus != BillStatusEnum.Publish //未知总成也显示在装箱单 - && itm.SerialNumStr == minSNStr2 - ).MinAsync(itm => itm.HostSN); - } - return new ObjectResultDto(beginHostSN); - } - catch (Exception ex) - { - ObjectResultDto ret = new ObjectResultDto(); - ret.Status = false; - ret.Message = _errorMessagePrefix + "GetPrintStartHostSN2 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } - - /// - /// 打印门板装箱单 - /// - /// - /// 执行成功返回真 - [UnitOfWork] - [HttpPost] - [Route("print-menban-packing-list")] - public virtual async Task> PrintMenBanPackingList(MenBanPrintInputDto input) - { - /* - 1、 一次打印24辆车,分为4页纸张,四个纸张的装箱单号不是一样 - 2、 按大众顺序号过滤打印,一次打印12套(不是24辆车),到1999后按2000、2001顺序排,下次打印按3延续排列右前 - 5、 物料描述字体尽量大 - 6、 右上角的“01 左” 字体尽量大 - 7、 零件类别: C8是车型, DP表示门板 - 8、 器具容量: 24表示当页包含24个门板 - 9、 车型门板代码: 从物料汇总文件- 补充备注 字段中取 Q5-DV OQ N5K 3L4 QQ2 6XE 7HB 9VS 7X1 3Y4 - 3、 根据物料描述字段区分左后、左前、右后、右前 - 4、 车型C8的第一二页分为左后, 右前,第三四页分为右后、左前;其它车型 第一二页分为左后、左前,第三四页分为右后、 - 10、 物料描述: 从物料汇总文件-物料描述 字段中取 - */ - MenBanPrintResultDto retObj = new MenBanPrintResultDto(); - ObjectResultDto ret = new ObjectResultDto(retObj); - ret.Status = false; - try - { - List reportMainLst = new List(); - - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN != 0 && input.EndHostSN != 0) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "止大众顺序号必须大于等于起大众顺序号!"; - ret.Status = false; - return ret; - } - } - ListResultDto tempLst = await GetMBReportDetailList(input, true); //----------------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - - int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - - double maxBillNum = 0; - - DateTime printTime = ServerHelper.CurrentDateTime; - - for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) - { - //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 - double maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); - // 先打印两张:左后左前,再打印两张:右后右前 - List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); - List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); - - //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 - Guid sortId = GuidGenerator.Create(); - foreach (var leftItm in leftLst) - { - leftItm.SortId = sortId; - } - foreach (var rightItm in rightLst) - { - rightItm.SortId = sortId; - } - - reportMainLst.AddRange(rightLst); - reportMainLst.AddRange(leftLst); - } - - //调用派格版库存接口 - CallWMSInterface_MB(reportMainLst); - - //插入门板打印记录表 - await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true); - - //更新M100的门板打印标志:BillStatus=3 - foreach (BillM100 billObj in billLst) - { - if (billObj.BillStatus == BillStatusEnum.Match) - { - billObj.SetBillStatus(BillStatusEnum.Publish); - billObj.PrintTime = ServerHelper.CurrentDateTime; - billObj.NeedReplenishPrint = 0; //不需要补打 - await _billM100Repository.UpdateAsync(billObj, true); - } - else if (billObj.BillStatus == BillStatusEnum.NotMatch) - { - //billObj.PrintTime = ServerHelper.CurrentDateTime; - billObj.NeedReplenishPrint = 1; //需要补打 - await _billM100Repository.UpdateAsync(billObj, true); - } - } - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - reportMainLst = await _menBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); - //按大众顺序号排序 - foreach (var reportMainObj in reportMainLst) - { - List recLst = reportMainObj.Details; - if (recLst == null) - continue; - //bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997")); - //bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003")); - bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997") - || itm.HostSN.Contains("1996") || itm.HostSN.Contains("1995") || itm.HostSN.Contains("1994") - || itm.HostSN.Contains("1993") || itm.HostSN.Contains("1992") || itm.HostSN.Contains("1991") - || itm.HostSN.Contains("1990") || itm.HostSN.Contains("1989") || itm.HostSN.Contains("1988") - || itm.HostSN.Contains("1987") || itm.HostSN.Contains("1986") || itm.HostSN.Contains("1985") - || itm.HostSN.Contains("1984") || itm.HostSN.Contains("1983") || itm.HostSN.Contains("1982") - || itm.HostSN.Contains("1981") || itm.HostSN.Contains("1980") || itm.HostSN.Contains("1979") - || itm.HostSN.Contains("1978") || itm.HostSN.Contains("1977") || itm.HostSN.Contains("1976") - ); - bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003") - || itm.HostSN.Contains("0004") || itm.HostSN.Contains("0005") || itm.HostSN.Contains("0006") - || itm.HostSN.Contains("0007") || itm.HostSN.Contains("0008") || itm.HostSN.Contains("0009") - || itm.HostSN.Contains("0010") || itm.HostSN.Contains("0011") || itm.HostSN.Contains("0012") - || itm.HostSN.Contains("0013") || itm.HostSN.Contains("0014") || itm.HostSN.Contains("0015") - || itm.HostSN.Contains("0016") || itm.HostSN.Contains("0017") || itm.HostSN.Contains("0018") - || itm.HostSN.Contains("0019") || itm.HostSN.Contains("0020") || itm.HostSN.Contains("0021") - || itm.HostSN.Contains("0022") || itm.HostSN.Contains("0023") || itm.HostSN.Contains("0024") - ); - if (has1999 && has0001) - { - reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN.TryToIntZero() % 10000) < 240 ? (itm.HostSN.TryToIntZero() % 10000 + 1999) : (itm.HostSN.TryToIntZero() % 10000)).ToList(); - } - else - { - reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); - } - } - } - else if (input.PrintType == PrintTypeEnum.补打) - { - List billLst = _billM100Repository.Where(itm => input.M100IdList.Contains(itm.Id)).OrderBy(itm => itm.SerialNumStr).ToList(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的单据,请先选择要补打的单据!"; - ret.Status = false; - return ret; - } - - int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - - double maxBillNum = 0; - - DateTime printTime = ServerHelper.CurrentDateTime; - - for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) - { - //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 - double maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); - // 先打印两张:左后左前,再打印两张:右后右前 - List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); - List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); - - //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 - Guid sortId = GuidGenerator.Create(); - foreach (var leftItm in leftLst) - { - leftItm.SortId = sortId; - } - foreach (var rightItm in rightLst) - { - rightItm.SortId = sortId; - } - - reportMainLst.AddRange(rightLst); - reportMainLst.AddRange(leftLst); - } - //校验底盘号、零件是否重复打印 - string checkVinPartRepeatSql = @" - select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b - on a.Id = b.MenBanPackingListId - where a.ReportStatus = 0 - and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}') - "; - foreach (MenBanPackingList reportMainObj in reportMainLst) - { - foreach (MenBanPackingRec reportRecObj in reportMainObj.Details) - { - string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.TopSAPMaterialNum); - string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql(sql1, true); - if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false) - { - throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.TopSAPMaterialNum}之间重复!"); - } - - string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.BelowSAPMaterialNum); - string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql(sql2, true); - if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false) - { - throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.BelowSAPMaterialNum}之间重复!"); - } - } - } - - //调用派格版库存接口 - CallWMSInterface_MB(reportMainLst); - - //插入门板打印记录表 - await _menBanPackingListRepository.InsertManyAsync(reportMainLst); - - //更新M100的门板打印标志:BillStatus=3 - foreach (BillM100 billObj in billLst) - { - if (billObj.BillStatus == BillStatusEnum.Match) - { - billObj.SetBillStatus(BillStatusEnum.Publish); - billObj.PrintTime = ServerHelper.CurrentDateTime; - await _billM100Repository.UpdateAsync(billObj); - } - } - } - - - #region 格式转换 - //实体 转 DTO - List targetLst = ObjectMapper.Map, List>(reportMainLst); - targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList(); - - //补充空行 - foreach (var masterObj in targetLst) - { - int trueCnt = masterObj.Details.Count; - int planCnt = 12; - if (trueCnt > planCnt) - { - throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); - } - int diffCnt = planCnt - trueCnt; - for (int i = 0; i < diffCnt; i++) - { - MenBanPackingRecDto dtlObj = new MenBanPackingRecDto(); - masterObj.Details.Add(dtlObj); - } - } - //子表BillNum赋值, BillNum填充空格 - foreach (var masterObj in targetLst) - { - masterObj.BillNum = GetTrueString(masterObj.BillNum); - int sn = 1; - foreach (var detailObj in masterObj.Details) - { - detailObj.BillNum = masterObj.BillNum; - detailObj.KNR = GetTrueString(detailObj.KNR); - detailObj.sn = sn++; - detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 - } - } - //返回结果格式转换 - foreach (var masterObj in targetLst) - { - foreach (var detailObj in masterObj.Details) - { - retObj.DetailList.Add(detailObj); - } - masterObj.Details = null; - retObj.MasterList.Add(masterObj); - } - #endregion - ret.Status = true; - return ret; - } - catch (Exception ex) - { - string errorMsg = _errorMessagePrefix + "PrintMenBanPackingList 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - throw new BusinessException("1001", errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; - } - } - - - - - /// - /// 打印柱护板装箱单 - /// - /// - /// 执行成功返回真 - [UnitOfWork(isTransactional:false)] - [HttpPost] - [Route("print-zhuhuban-packing-list")] - public virtual async Task> PrintZhuHuBanPackingList(ZhuHuBanPrintInputDto input) - { - ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); - ObjectResultDto ret = new ObjectResultDto(retObj); - ret.Status = false; - try - { - List reportMainLst = new List(); - List forWMSLst = new List(); - - - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "起大众顺序号不能大于止大众顺序号!"; - ret.Status = false; - return ret; - } - - ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - if (billLst.Count > 24) - { - ret.Message = "打印柱护板单据的数量不能大于24!"; - ret.Status = false; - return ret; - } - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - - long maxBillNum = 0; //子方法内部赋值 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; - - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - //A柱下,A中 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - //B柱上 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - //B柱下 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - //后轮,上装饰板 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - #region 调用库存接口 - //List forWMSLst = new List(); - //forWMSLst.AddRange(reportMainLst); - //forWMSLst.AddRange(acLstOnlyWMSUse); - CallWMSInterface_ZHB(forWMSLst); - #endregion - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - } - - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - if (input.DataResultType == "1") //全部11条数据 - { - var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); - if (firObj != null) - { - Guid? sortId = firObj.SortId; - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); - } - } - else - { - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); - } - - //按大众顺序号排序 - foreach (var reportMainObj in reportMainLst) - { - List recLst = reportMainObj.Details; - if (recLst == null) - continue; - //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); - //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); - bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) >= 1999 - 24); - bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) <= 24); - if (has1999 && has0001) - { - reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) <= 23 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); - } - else - { - reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); - } - } - } - else if (input.PrintType == PrintTypeEnum.补打) - { - if (input.M100IdList.Count > 24) - { - throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); - } - - List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; - ret.Status = false; - return ret; - } - billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); - - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - - long maxBillNum = 0; //全局唯一装箱单号 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; //右上角顺序号01-99 - - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - //A柱下,A中 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - //B柱上 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - //B柱下 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - //后轮,上装饰板 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - #region 调用库存接口 - //List forWMSLst = new List(); - //forWMSLst.AddRange(reportMainLst); - //forWMSLst.AddRange(acLstOnlyWMSUse); - CallWMSInterface_ZHB(forWMSLst); - #endregion - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - } - - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - } - - #region 返回结果格式转换 - //实体 转 DTO - List targetLst = ObjectMapper.Map, List>(reportMainLst); - //补充空行 - foreach (var masterObj in targetLst) - { - int trueCnt = masterObj.Details.Count; - - int planCnt = 0; - switch (masterObj.PartType) - { - case "A上C上": - case "A柱下A中": - case "B柱上": - case "B柱下": - case "后轮上装饰板": - planCnt = 24; - break; - case "D柱": - planCnt = 12; - break; - default: - planCnt = 24; - break; - } - if (trueCnt > planCnt) - { - throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); - } - int diffCnt = planCnt - trueCnt; - for (int i = 0; i < diffCnt; i++) - { - ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); - masterObj.Details.Add(dtlObj); - } - } - //子表BillNum赋值, BillNum填充空格, SN赋值 - foreach (var masterObj in targetLst) - { - masterObj.BillNum = GetTrueString(masterObj.BillNum); - int sn = 1; - foreach (var detailObj in masterObj.Details) - { - detailObj.BillNum = masterObj.BillNum; - detailObj.KNR = GetTrueString(detailObj.KNR); - detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); - detailObj.sn = sn++; - detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 - //客户要求显示零件描述,替换之前的零件编码 - detailObj.PartCode = detailObj.MaterialDescription; - detailObj.PartCode2 = detailObj.MaterialDescription2; - detailObj.MaterialDescription = null; - detailObj.MaterialDescription2 = null; - } - } - - retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); - if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; - foreach (var masterObj in retObj.MasterList_AC) - { - retObj.DetailList_AC.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); - if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; - foreach (var masterObj in retObj.MasterList_AA) - { - retObj.DetailList_AA.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); - if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; - foreach (var masterObj in retObj.MasterList_BS) - { - retObj.DetailList_BS.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); - if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; - foreach (var masterObj in retObj.MasterList_BX) - { - retObj.DetailList_BX.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); - if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; - foreach (var masterObj in retObj.MasterList_D) - { - retObj.DetailList_D.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); - if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; - foreach (var masterObj in retObj.MasterList_HL) - { - retObj.DetailList_HL.AddRange(masterObj.Details); - masterObj.Details = null; - } - #endregion - ret.Status = true; - return ret; - } - catch (Exception ex) - { - string errorMsg = _errorMessagePrefix + "PrintZhuHuBanPackingList 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - throw new BusinessException("1001", errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; - } - } + // #region 返回结果格式转换 + // //实体 转 DTO + // List targetLst = ObjectMapper.Map, List>(reportMainLst); + // //补充空行 + // foreach (var masterObj in targetLst) + // { + // int trueCnt = masterObj.Details.Count; - /// - /// 相同VIN的左右SortId相同,用于作废 - /// - /// - /// - //private void ModifySortId(List lst1, List lst2 = null) - //{ - // Guid sortId = GuidGenerator.Create(); - // foreach (var itm in lst1) - // { - // itm.SortId = sortId; - // } - // if (lst2 != null) - // { - // foreach (var itm in lst2) + // int planCnt = 0; + // switch (masterObj.PartType) + // { + // case "A上C上": + // case "A柱下A中": + // case "B柱上": + // case "B柱下": + // case "后轮上装饰板": + // planCnt = 24; + // break; + // case "D柱": + // planCnt = 12; + // break; + // default: + // planCnt = 24; + // break; + // } + // if (trueCnt > planCnt) + // { + // throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + // } + // int diffCnt = planCnt - trueCnt; + // for (int i = 0; i < diffCnt; i++) + // { + // ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); + // masterObj.Details.Add(dtlObj); + // } + // } + // //子表BillNum赋值, BillNum填充空格, SN赋值 + // foreach (var masterObj in targetLst) // { - // itm.SortId = sortId; + // masterObj.BillNum = GetTrueString(masterObj.BillNum); + // int sn = 1; + // foreach (var detailObj in masterObj.Details) + // { + // detailObj.BillNum = masterObj.BillNum; + // detailObj.KNR = GetTrueString(detailObj.KNR); + // detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); + // detailObj.sn = sn++; + // detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + // //客户要求显示零件描述,替换之前的零件编码 + // detailObj.PartCode = detailObj.MaterialDescription; + // detailObj.PartCode2 = detailObj.MaterialDescription2; + // detailObj.MaterialDescription = null; + // detailObj.MaterialDescription2 = null; + // } // } - // } - //} - - #endregion - #region 补打 - /// - /// 取门板补打列表(IsNeedReplenishPrint=true、单据状态BillStatus是未打印) - /// - /// 输入查询条件 - /// 返回符合条件的排序分页列表 - [HttpGet] - [UnitOfWork(false)] - [Route("replenish-print-list")] - public virtual async Task> GetReplenishPrintListAsync(QueryBillM100Dto input) - { - _logger.LogDebug(_errorMessagePrefix + "GetReplenishPrintListAsync 进入"); - try - { - input.CanNotPrint = null; //忽略不能打印 - input.ZHBBillStatus = null; - input.BillStatus = BillStatusEnum.Match; //单据状态是已解析未打印 - input.IsNeedReplenishPrint = true; //只显示需要补打的记录 - PagedResultDto ret = await QueryByConditionAsync(input, (PagedAndSortedBase)input); - return ret; - } - catch (Exception ex) - { - string errMsg = _errorMessagePrefix + "GetReplenishPrintListAsync 执行出错:" + ex.Message; - _logger.LogError(errMsg); - return new PagedResultDto(0, new List()); - } - } - - /// - /// 取柱护板补打列表(IsNeedReplenishPrint=true、单据状态BillStatus是未打印) - /// - /// 输入查询条件 - /// 返回符合条件的排序分页列表 - [HttpGet] - [UnitOfWork(false)] - [Route("replenish-print-zhb-list")] - public virtual async Task> GetReplenishPrintZHBListAsync(QueryBillM100Dto input) - { - _logger.LogDebug(_errorMessagePrefix + "GetReplenishPrintZHBListAsync 进入"); - try - { - input.CanNotPrint = null; //忽略不能打印 - input.BillStatus = null; - input.ZHBBillStatus = ZHBBillStatusEnum.NotPrint; //柱护板状态是已解析未打印 - input.IsNeedReplenishPrint = true; //只显示需要补打的记录 - PagedResultDto ret = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); - return ret; - } - catch (Exception ex) - { - string errMsg = _errorMessagePrefix + "GetReplenishPrintZHBListAsync 执行出错:" + ex.Message; - _logger.LogError(errMsg); - return new PagedResultDto(0, new List()); - } - } - - #endregion - - #region 公共方法 - - /// - /// 根据筛选条件获取分页实体列表 - /// - /// 输入查询条件 - /// 输入分页条件 - /// 返回符合条件的排序分页列表 - [HttpGet] - [UnitOfWork(false)] - [Route("list")] - public virtual async Task> GetListAsync(QueryBillM100Dto input) - { - _logger.LogDebug(_errorMessagePrefix + "GetListAsync 进入"); - try - { - PagedResultDto ret = new PagedResultDto(); - if (!string.IsNullOrEmpty(input.GroupName)) - { - ret = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); - } - else - { - ret = await QueryByConditionAsync(input, (PagedAndSortedBase)input); - } - - return ret; - } - catch (Exception ex) - { - string errMsg = _errorMessagePrefix + "GetListAsync 执行出错:" + ex.Message; - _logger.LogError(errMsg); - return new PagedResultDto(0, new List()); - } - } + // retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); + // if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; + // foreach (var masterObj in retObj.MasterList_AC) + // { + // retObj.DetailList_AC.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - /// - /// 按主键获取唯一实体 - /// - /// 主键 - /// 实体信息 - [HttpGet] - [Route("{id}")]//obj/ - public virtual async Task> GetAsync(Guid id) - { - _logger.LogDebug(_errorMessagePrefix + "GetAsync 进入"); - ObjectResultDto ret = new ObjectResultDto(); - try - { - BillM100 sourceObj = await _billM100Repository.GetAsync(id); - BillM100Dto targetObj = ObjectMapper.Map(sourceObj); - ret.Item = targetObj; - return ret; - } - catch (Exception ex) - { - ret.Status = false; - ret.Message = _errorMessagePrefix + "GetAsync 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } + // retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); + // if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; + // foreach (var masterObj in retObj.MasterList_AA) + // { + // retObj.DetailList_AA.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - /// - /// 添加实体 - /// - /// 添加内容 - /// 执行成功返回真 - [HttpPost] - [UnitOfWork] - [Route("")]//create - public virtual async Task> CreateAsync(CreateUpdateBillM100Dto input) - { - _logger.LogDebug(_errorMessagePrefix + "CreateAsync 进入"); - ObjectResultDto ret = new ObjectResultDto(); - try - { - //取M100单据 最大流水号 - //int billMaxSN = _billM100Repository.Max(itm => itm.SerialNum) ?? 0; + // retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); + // if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; + // foreach (var masterObj in retObj.MasterList_BS) + // { + // retObj.DetailList_BS.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - BillM100 obj = ObjectMapper.Map(input); - #region 主子表主键Id赋值 - foreach (var item in obj.BillM100Parts) - { - item.SetId(GuidGenerator.Create()); - } - #endregion - obj.SetSerialNum(ServerHelper.VinToSN(obj.VIN)); //++billMaxSN 取底盘后六位 - obj.SerialNumStr = ServerHelper.ToSerialNumStr(obj.OnlineTime, obj.HostSN, "m100", obj.ProductLine); - BillM100 obj2 = await _billM100Repository.InsertAsync(obj); - ret.Item = obj2.Id; //返回添加对象的主键 - return ret; - } - catch (Exception ex) - { - ret.Status = false; - ret.Message = _errorMessagePrefix + "CreateAsync 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } + // retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); + // if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; + // foreach (var masterObj in retObj.MasterList_BX) + // { + // retObj.DetailList_BX.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); + // if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; + // foreach (var masterObj in retObj.MasterList_D) + // { + // retObj.DetailList_D.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); + // if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; + // foreach (var masterObj in retObj.MasterList_HL) + // { + // retObj.DetailList_HL.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + // #endregion + // ret.Status = true; + // return ret; + // } + // catch (Exception ex) + // { + // string errorMsg = _errorMessagePrefix + "PrintZhuHuBanPackingList 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // throw new BusinessException("1001", errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } + //} /// - /// 修改实体 + /// 相同VIN的左右SortId相同,用于作废 /// - /// 更新主键 - /// 修改内容 - /// 执行成功返回真 - [HttpPut] - [UnitOfWork] - [Route("{id}")]//update/ - public virtual async Task UpdateAsync(Guid id, CreateUpdateBillM100Dto input) - { - _logger.LogDebug(_errorMessagePrefix + "UpdateAsync 进入"); - ObjectResultDto ret = new ObjectResultDto(); - try - { - BillM100 targetObj = await _billM100Repository.GetAsync(id); - await _billM100PartRepository.DeleteManyAsync(targetObj.BillM100Parts); //先删除子实体列表 - ObjectMapper.Map(input, targetObj); - await _billM100Repository.UpdateAsync(targetObj); - await _billM100PartRepository.InsertManyAsync(targetObj.BillM100Parts); //再添加子实体列表 - return ret; - } - catch (Exception ex) - { - ret.Status = false; - ret.Message = _errorMessagePrefix + "UpdateAsync 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } + /// + /// + //private void ModifySortId(List lst1, List lst2 = null) + //{ + // Guid sortId = GuidGenerator.Create(); + // foreach (var itm in lst1) + // { + // itm.SortId = sortId; + // } + // if (lst2 != null) + // { + // foreach (var itm in lst2) + // { + // itm.SortId = sortId; + // } + // } + //} + + #endregion + #region 补打 /// - /// 删除实体 + /// 取门板补打列表(IsNeedReplenishPrint=true、单据状态BillStatus是未打印) /// - /// 删除主键 - /// 执行成功返回真 - [UnitOfWork] - [HttpDelete] - [Route("{id}")]//delete/ - public virtual async Task DeleteAsync(string id) + /// 输入查询条件 + /// 返回符合条件的排序分页列表 + [HttpGet] + [UnitOfWork(false)] + [Route("replenish-print-list")] + public virtual async Task> GetReplenishPrintListAsync(QueryBillM100Dto input) { - _logger.LogDebug(_errorMessagePrefix + "DeleteAsync 进入"); - ObjectResultDto ret = new ObjectResultDto(); + _logger.LogDebug(_errorMessagePrefix + "GetReplenishPrintListAsync 进入"); try { - List idLst = ServerHelper.GetGuidListByStr(id); - foreach (Guid item in idLst) - { - BillM100 sourceObj = await _billM100Repository.GetAsync(item); - if (sourceObj != null) - { - await _billM100PartRepository.DeleteManyAsync(sourceObj.BillM100Parts); - await _billM100Repository.DeleteAsync(item); - } - } + input.CanNotPrint = null; //忽略不能打印 + input.ZHBBillStatus = null; + input.BillStatus = BillStatusEnum.Match; //单据状态是已解析未打印 + input.IsNeedReplenishPrint = true; //只显示需要补打的记录 + PagedResultDto ret = await QueryByConditionAsync(input, (PagedAndSortedBase)input); return ret; } catch (Exception ex) { - ret.Status = false; - ret.Message = _errorMessagePrefix + "DeleteAsync 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; + string errMsg = _errorMessagePrefix + "GetReplenishPrintListAsync 执行出错:" + ex.Message; + _logger.LogError(errMsg); + return new PagedResultDto(0, new List()); } } /// - /// 导出信息 + /// 取柱护板补打列表(IsNeedReplenishPrint=true、单据状态BillStatus是未打印) /// - /// 导出查询条件 - /// 执行成功返回真 + /// 输入查询条件 + /// 返回符合条件的排序分页列表 + [HttpGet] [UnitOfWork(false)] - [HttpPost] - [Route("export")] - public virtual async Task> ExportAsync(QueryBillM100Dto input) + [Route("replenish-print-zhb-list")] + public virtual async Task> GetReplenishPrintZHBListAsync(QueryBillM100Dto input) { - _logger.LogDebug(_errorMessagePrefix + "ExportAsync 进入"); - ObjectResultDto ret = new ObjectResultDto(); + _logger.LogDebug(_errorMessagePrefix + "GetReplenishPrintZHBListAsync 进入"); try { - input.SkipCount = 0; - input.MaxResultCount = 50000; - PagedResultDto query = new PagedResultDto(); - if (!string.IsNullOrEmpty(input.GroupName)) - { - query = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); - } - else - { - query = await QueryByConditionAsync(input, (PagedAndSortedBase)input); - } - List items = query.Items.ToList(); - //将实体列表转换成excel文件流 - IExporter exporter = new ExcelExporter(); - byte[] byteArr = await exporter.ExportAsByteArray(items); - byteArr.ShouldNotBeNull(); - //将excel文件流保存到服务器端文件系统 - string fileName = string.Format("单据M100_{0}.xlsx", Guid.NewGuid().ToString()); - await _blobContainer.SaveAsync(fileName, byteArr); - - ret.Item = fileName; + input.CanNotPrint = null; //忽略不能打印 + input.BillStatus = null; + input.ZHBBillStatus = ZHBBillStatusEnum.NotPrint; //柱护板状态是已解析未打印 + input.IsNeedReplenishPrint = true; //只显示需要补打的记录 + PagedResultDto ret = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); return ret; } catch (Exception ex) { - ret.Status = false; - ret.Message = _errorMessagePrefix + "ExportAsync 执行出错:" + ex.Message; - _logger.LogError(ret.Message); - return ret; - } - } - - /// - /// 导入信息 - /// - /// 导入文件流 - /// 执行成功返回真 - [UnitOfWork] - [HttpPost] - [Route("import")] - public virtual async Task ImportAsync(byte[] input) - { - throw new NotImplementedException("暂不实现所有导入"); - } - - #endregion - - - #region 超时提醒 - /// - /// 生产线超时提醒 - /// - /// 生产线编号列表 - /// 生产线超时情况 - [UnitOfWork] - [HttpPost] - [Route("product-line-timeout-remind")] - public virtual async Task> ProductLineTimeoutRemind(TimeOutRemindInputDto input) - { - List retLst = new List(); - foreach (string plStr in input.ProductLineList) - { - TimeOutRemindResultDto retObj = new TimeOutRemindResultDto(); - retObj.ProductLine = plStr; - retObj.ConfigMinutes = _configuration[$"ConfigDic:ProductLineTimeoutRemind:{plStr}"].TryToInt() ?? 30; - - string maxSNStr = await _billM100Repository.Where(itm => itm.ProductLine == plStr).MaxAsync(itm => itm.SerialNumStr); - BillM100 lastBill = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == plStr && itm.SerialNumStr == maxSNStr); - if (lastBill != null) - { - retObj.LastReceiveTime = lastBill.ReceiveTime ?? ServerHelper.CurrentDateTime; - retObj.TimeoutMinutes = MinuteDiff(retObj.LastReceiveTime, ServerHelper.CurrentDateTime); - } - retLst.Add(retObj); + string errMsg = _errorMessagePrefix + "GetReplenishPrintZHBListAsync 执行出错:" + ex.Message; + _logger.LogError(errMsg); + return new PagedResultDto(0, new List()); } - return new ListResultDto(retLst); - } - - private int MinuteDiff(DateTime beginTime, DateTime endTime) - { - TimeSpan beginSpan = new TimeSpan(beginTime.Ticks); - TimeSpan endSpan = new TimeSpan(endTime.Ticks); - TimeSpan diffSpan = endSpan.Subtract(beginSpan).Duration(); - return (int)(diffSpan.TotalMinutes); } - #endregion - - #region 保存报表、加载打印报表分离 - //[UnitOfWork] - [UnitOfWork(IsDisabled = true)] - [HttpPost] - [Route("save-menban-report")] - public virtual async Task>> SaveMenBanReport(MenBanPrintInputDto input) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - _logger.LogDebug(_errorMessagePrefix + "SaveMenBanReport 进入"); - - List retLst = new List(); - ObjectResultDto> ret = new ObjectResultDto>(); - ret.Status = false; - - using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified)) - { - try - { - List reportMainLst = new List(); - - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN != 0 && input.EndHostSN != 0) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "止大众顺序号必须大于等于起大众顺序号!"; - ret.Status = false; - return ret; - } - } - ListResultDto tempLst = await GetMBReportDetailList(input, true); //----------------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - sw.Stop(); - _logger.LogWarning($"SaveMenBanReport读取数据 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - - double maxBillNum = 0; - - DateTime printTime = ServerHelper.CurrentDateTime; - - for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) - { - //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 - double maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); - // 先打印两张:左后左前,再打印两张:右后右前 - List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); - List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); - - //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 - Guid sortId = GuidGenerator.Create(); - foreach (var leftItm in leftLst) - { - leftItm.SortId = sortId; - } - foreach (var rightItm in rightLst) - { - rightItm.SortId = sortId; - } - - reportMainLst.AddRange(rightLst); - reportMainLst.AddRange(leftLst); - } - sw.Stop(); - _logger.LogWarning($"SaveMenBanReport转换数据 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - //插入门板打印记录表 - await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true); - retLst.AddRange(reportMainLst.Select(itm => itm.Id)); - //foreach (var reportMainObj in reportMainLst) - //{ - // var insObj = await _menBanPackingListRepository.InsertAsync(reportMainObj, true); - // if (insObj != null) - // { - // retLst.Add(insObj.Id); - // } - //} - sw.Stop(); - _logger.LogWarning($"SaveMenBanReport插入门板打印记录表 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - //调用派格版库存接口 - await SaveMiddleTable_MB(reportMainLst); - sw.Stop(); - _logger.LogWarning($"SaveMenBanReport插入中间表 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - //更新M100的门板打印标志:BillStatus=3 - foreach (BillM100 billObj in billLst) - { - if (billObj.BillStatus == BillStatusEnum.Match) - { - billObj.SetBillStatus(BillStatusEnum.Publish); - billObj.PrintTime = ServerHelper.CurrentDateTime; - billObj.NeedReplenishPrint = 0; //不需要补打 - await _billM100Repository.UpdateAsync(billObj, true); - } - else if (billObj.BillStatus == BillStatusEnum.NotMatch) - { - //billObj.PrintTime = ServerHelper.CurrentDateTime; - billObj.NeedReplenishPrint = 1; //需要补打 - await _billM100Repository.UpdateAsync(billObj, true); - } - } - sw.Stop(); - _logger.LogWarning($"SaveMenBanReport更新M100的门板打印标志 - {sw.ElapsedMilliseconds}毫秒"); - - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - throw new BusinessException("请调用LoadMenBanReport方法!"); - } - else if (input.PrintType == PrintTypeEnum.补打) - { - List billLst = _billM100Repository.Where(itm => input.M100IdList.Contains(itm.Id)).OrderBy(itm => itm.SerialNumStr).ToList(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的单据,请先选择要补打的单据!"; - ret.Status = false; - return ret; - } - - int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 - - double maxBillNum = 0; - - DateTime printTime = ServerHelper.CurrentDateTime; - - for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) - { - //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 - double maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); - // 先打印两张:左后左前,再打印两张:右后右前 - List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); - List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); - - //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 - Guid sortId = GuidGenerator.Create(); - foreach (var leftItm in leftLst) - { - leftItm.SortId = sortId; - } - foreach (var rightItm in rightLst) - { - rightItm.SortId = sortId; - } - - reportMainLst.AddRange(rightLst); - reportMainLst.AddRange(leftLst); - } - //校验底盘号、零件是否重复打印 - string checkVinPartRepeatSql = @" - select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b - on a.Id = b.MenBanPackingListId - where a.ReportStatus = 0 - and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}') - "; - foreach (MenBanPackingList reportMainObj in reportMainLst) - { - foreach (MenBanPackingRec reportRecObj in reportMainObj.Details) - { - string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.TopSAPMaterialNum); - string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql(sql1, true); - if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false) - { - throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.TopSAPMaterialNum}之间重复!"); - } - - string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.BelowSAPMaterialNum); - string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql(sql2, true); - if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false) - { - throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.BelowSAPMaterialNum}之间重复!"); - } - } - } + #endregion - //调用派格版库存接口 - await SaveMiddleTable_MB(reportMainLst); + #region 公共方法 - //插入门板打印记录表 - //await _menBanPackingListRepository.InsertManyAsync(reportMainLst); - foreach (var reportMainObj in reportMainLst) - { - var insObj = await _menBanPackingListRepository.InsertAsync(reportMainObj, true); - if (insObj != null) - { - retLst.Add(insObj.Id); - } - } - //更新M100的门板打印标志:BillStatus=3 - foreach (BillM100 billObj in billLst) - { - if (billObj.BillStatus == BillStatusEnum.Match) - { - billObj.SetBillStatus(BillStatusEnum.Publish); - billObj.PrintTime = ServerHelper.CurrentDateTime; - await _billM100Repository.UpdateAsync(billObj); - } - } - } //补打if - await uow.CompleteAsync(); - ret.Status = true; - ret.Item = retLst; - return ret; + /// + /// 根据筛选条件获取分页实体列表 + /// + /// 输入查询条件 + /// 输入分页条件 + /// 返回符合条件的排序分页列表 + [HttpGet] + [UnitOfWork(false)] + [Route("list")] + public virtual async Task> GetListAsync(QueryBillM100Dto input) + { + _logger.LogDebug(_errorMessagePrefix + "GetListAsync 进入"); + try + { + PagedResultDto ret = new PagedResultDto(); + if (!string.IsNullOrEmpty(input.GroupName)) + { + ret = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); } - catch (Exception ex) + else { - await uow.RollbackAsync(); - string errorMsg = _errorMessagePrefix + "SaveMenBanReport 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; + ret = await QueryByConditionAsync(input, (PagedAndSortedBase)input); } - } //事务 + + return ret; + } + catch (Exception ex) + { + string errMsg = _errorMessagePrefix + "GetListAsync 执行出错:" + ex.Message; + _logger.LogError(errMsg); + return new PagedResultDto(0, new List()); + } } - [UnitOfWork] - [HttpPost] - [Route("load-menban-report")] - public virtual async Task> LoadMenBanReport(List input) + /// + /// 按主键获取唯一实体 + /// + /// 主键 + /// 实体信息 + [HttpGet] + [Route("{id}")]//obj/ + public virtual async Task> GetAsync(Guid id) { - _logger.LogDebug(_errorMessagePrefix + "LoadMenBanReport 进入"); - - MenBanPrintResultDto retObj = new MenBanPrintResultDto(); - ObjectResultDto ret = new ObjectResultDto(retObj); - ret.Status = false; + _logger.LogDebug(_errorMessagePrefix + "GetAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); try { - List reportMainLst = new List(); - - reportMainLst = await _menBanPackingListRepository.GetListAsync(itm => input.Contains(itm.Id) == true, true); - //按大众顺序号排序 - foreach (var reportMainObj in reportMainLst) - { - List recLst = reportMainObj.Details; - if (recLst == null) - continue; - - bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997") - || itm.HostSN.Contains("1996") || itm.HostSN.Contains("1995") || itm.HostSN.Contains("1994") - || itm.HostSN.Contains("1993") || itm.HostSN.Contains("1992") || itm.HostSN.Contains("1991") - || itm.HostSN.Contains("1990") || itm.HostSN.Contains("1989") || itm.HostSN.Contains("1988") - || itm.HostSN.Contains("1987") || itm.HostSN.Contains("1986") || itm.HostSN.Contains("1985") - || itm.HostSN.Contains("1984") || itm.HostSN.Contains("1983") || itm.HostSN.Contains("1982") - || itm.HostSN.Contains("1981") || itm.HostSN.Contains("1980") || itm.HostSN.Contains("1979") - || itm.HostSN.Contains("1978") || itm.HostSN.Contains("1977") || itm.HostSN.Contains("1976") - ); - bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003") - || itm.HostSN.Contains("0004") || itm.HostSN.Contains("0005") || itm.HostSN.Contains("0006") - || itm.HostSN.Contains("0007") || itm.HostSN.Contains("0008") || itm.HostSN.Contains("0009") - || itm.HostSN.Contains("0010") || itm.HostSN.Contains("0011") || itm.HostSN.Contains("0012") - || itm.HostSN.Contains("0013") || itm.HostSN.Contains("0014") || itm.HostSN.Contains("0015") - || itm.HostSN.Contains("0016") || itm.HostSN.Contains("0017") || itm.HostSN.Contains("0018") - || itm.HostSN.Contains("0019") || itm.HostSN.Contains("0020") || itm.HostSN.Contains("0021") - || itm.HostSN.Contains("0022") || itm.HostSN.Contains("0023") || itm.HostSN.Contains("0024") - ); - if (has1999 && has0001) - { - reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN.TryToIntZero() % 10000) < 240 ? (itm.HostSN.TryToIntZero() % 10000 + 1999) : (itm.HostSN.TryToIntZero() % 10000)).ToList(); - } - else - { - reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); - } - } + BillM100 sourceObj = await _billM100Repository.GetAsync(id); + BillM100Dto targetObj = ObjectMapper.Map(sourceObj); + ret.Item = targetObj; + return ret; + } + catch (Exception ex) + { + ret.Status = false; + ret.Message = _errorMessagePrefix + "GetAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); + return ret; + } + } - #region 格式转换 - //实体 转 DTO - List targetLst = ObjectMapper.Map, List>(reportMainLst); - targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList(); + /// + /// 添加实体 + /// + /// 添加内容 + /// 执行成功返回真 + [HttpPost] + [UnitOfWork] + [Route("")]//create + public virtual async Task> CreateAsync(CreateUpdateBillM100Dto input) + { + _logger.LogDebug(_errorMessagePrefix + "CreateAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); + try + { + //取M100单据 最大流水号 + //int billMaxSN = _billM100Repository.Max(itm => itm.SerialNum) ?? 0; - //补充空行 - foreach (var masterObj in targetLst) - { - int trueCnt = masterObj.Details.Count; - int planCnt = 12; - if (trueCnt > planCnt) - { - throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); - } - int diffCnt = planCnt - trueCnt; - for (int i = 0; i < diffCnt; i++) - { - MenBanPackingRecDto dtlObj = new MenBanPackingRecDto(); - masterObj.Details.Add(dtlObj); - } - } - //子表BillNum赋值, BillNum填充空格 - foreach (var masterObj in targetLst) - { - masterObj.BillNum = GetTrueString(masterObj.BillNum); - int sn = 1; - foreach (var detailObj in masterObj.Details) - { - detailObj.BillNum = masterObj.BillNum; - detailObj.KNR = GetTrueString(detailObj.KNR); - detailObj.sn = sn++; - detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 - } - } - //返回结果格式转换 - foreach (var masterObj in targetLst) + BillM100 obj = ObjectMapper.Map(input); + #region 主子表主键Id赋值 + foreach (var item in obj.BillM100Parts) { - foreach (var detailObj in masterObj.Details) - { - retObj.DetailList.Add(detailObj); - } - masterObj.Details = null; - retObj.MasterList.Add(masterObj); + item.SetId(GuidGenerator.Create()); } #endregion - ret.Status = true; + obj.SetSerialNum(ServerHelper.VinToSN(obj.VIN)); //++billMaxSN 取底盘后六位 + obj.SerialNumStr = ServerHelper.ToSerialNumStr(obj.OnlineTime, obj.HostSN, "m100", obj.ProductLine); + BillM100 obj2 = await _billM100Repository.InsertAsync(obj); + ret.Item = obj2.Id; //返回添加对象的主键 return ret; } catch (Exception ex) { - string errorMsg = _errorMessagePrefix + "LoadMenBanReport 执行出错:" + ex.Message; - _logger.LogError(errorMsg); ret.Status = false; - ret.Message = ex.Message; + ret.Message = _errorMessagePrefix + "CreateAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); return ret; } } - - - /// - /// 打印柱护板装箱单 + /// 修改实体 /// - /// + /// 更新主键 + /// 修改内容 /// 执行成功返回真 + [HttpPut] [UnitOfWork] - [HttpPost] - [Route("print-group-zhuhuban-packing-list")] - public virtual async Task> PrintGroupZhuHuBanPackingList(ZhuHuBanPrintInputDto input) + [Route("{id}")]//update/ + public virtual async Task UpdateAsync(Guid id, CreateUpdateBillM100Dto input) { - ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); - ObjectResultDto ret = new ObjectResultDto(retObj); - ret.Status = false; + _logger.LogDebug(_errorMessagePrefix + "UpdateAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); try { - List reportMainLst = new List(); - List forWMSLst = new List(); - - - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "起大众顺序号不能大于止大众顺序号!"; - ret.Status = false; - return ret; - } - - ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - if (billLst.Count > 24) - { - ret.Message = "打印柱护板单据的数量不能大于24!"; - ret.Status = false; - return ret; - } - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - - long maxBillNum = 0; //子方法内部赋值 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; - - //获取当前打印柱护板的零件类型 - var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); - foreach (var partType in partTypes) - { - switch (partType.PartType) - { - case "A上C上": - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - break; - case "A柱下A中": - //A柱下,A中 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - - break; - case "B柱上": - //B柱上 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - break; - case "B柱下": - //B柱下 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - break; - case "D柱": - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - break; - case "后轮上装饰板": - //后轮,上装饰板 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - break; - } - } - - #region 调用库存接口 - //List forWMSLst = new List(); - //forWMSLst.AddRange(reportMainLst); - //forWMSLst.AddRange(acLstOnlyWMSUse); - CallWMSInterface_ZHB(forWMSLst); - #endregion - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - } - - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - if (input.DataResultType == "1") //全部11条数据 - { - var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); - if (firObj != null) - { - Guid? sortId = firObj.SortId; - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); - } - } - else - { - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); - } - - //按大众顺序号排序 - foreach (var reportMainObj in reportMainLst) - { - List recLst = reportMainObj.Details; - if (recLst == null) - continue; - //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); - //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); - bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) >= 1977); - bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) <= 23); - if (has1999 && has0001) - { - reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) <= 23 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); - } - else - { - reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); - } - } - } - else if (input.PrintType == PrintTypeEnum.补打) - { - if (input.M100IdList.Count > 24) - { - throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); - } - - List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; - ret.Status = false; - return ret; - } - billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); - - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - - long maxBillNum = 0; //全局唯一装箱单号 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; //右上角顺序号01-99 - - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - //A柱下,A中 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - //B柱上 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - //B柱下 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - //后轮,上装饰板 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - #region 调用库存接口 - //List forWMSLst = new List(); - //forWMSLst.AddRange(reportMainLst); - //forWMSLst.AddRange(acLstOnlyWMSUse); - CallWMSInterface_ZHB(forWMSLst); - #endregion - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - } - - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - } - - #region 返回结果格式转换 - //实体 转 DTO - List targetLst = ObjectMapper.Map, List>(reportMainLst); - //补充空行 - foreach (var masterObj in targetLst) - { - int trueCnt = masterObj.Details.Count; - - int planCnt = 0; - switch (masterObj.PartType) - { - case "A上C上": - case "A柱下A中": - case "B柱上": - case "B柱下": - case "后轮上装饰板": - planCnt = 24; - break; - case "D柱": - planCnt = 12; - break; - default: - planCnt = 24; - break; - } - if (trueCnt > planCnt) - { - throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); - } - int diffCnt = planCnt - trueCnt; - for (int i = 0; i < diffCnt; i++) - { - ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); - masterObj.Details.Add(dtlObj); - } - } - //子表BillNum赋值, BillNum填充空格, SN赋值 - foreach (var masterObj in targetLst) - { - masterObj.BillNum = GetTrueString(masterObj.BillNum); - int sn = 1; - foreach (var detailObj in masterObj.Details) - { - detailObj.BillNum = masterObj.BillNum; - detailObj.KNR = GetTrueString(detailObj.KNR); - detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); - detailObj.sn = sn++; - detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 - //客户要求显示零件描述,替换之前的零件编码 - detailObj.PartCode = detailObj.MaterialDescription; - detailObj.PartCode2 = detailObj.MaterialDescription2; - detailObj.MaterialDescription = null; - detailObj.MaterialDescription2 = null; - } - } - - retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); - if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; - foreach (var masterObj in retObj.MasterList_AC) - { - retObj.DetailList_AC.AddRange(masterObj.Details); - masterObj.Details = null; - } - - retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); - if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; - foreach (var masterObj in retObj.MasterList_AA) - { - retObj.DetailList_AA.AddRange(masterObj.Details); - masterObj.Details = null; - } + BillM100 targetObj = await _billM100Repository.GetAsync(id); + await _billM100PartRepository.DeleteManyAsync(targetObj.BillM100Parts); //先删除子实体列表 + ObjectMapper.Map(input, targetObj); + await _billM100Repository.UpdateAsync(targetObj); + await _billM100PartRepository.InsertManyAsync(targetObj.BillM100Parts); //再添加子实体列表 + return ret; + } + catch (Exception ex) + { + ret.Status = false; + ret.Message = _errorMessagePrefix + "UpdateAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); + return ret; + } + } - retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); - if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; - foreach (var masterObj in retObj.MasterList_BS) + /// + /// 删除实体 + /// + /// 删除主键 + /// 执行成功返回真 + [UnitOfWork] + [HttpDelete] + [Route("{id}")]//delete/ + public virtual async Task DeleteAsync(string id) + { + _logger.LogDebug(_errorMessagePrefix + "DeleteAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); + try + { + List idLst = ServerHelper.GetGuidListByStr(id); + foreach (Guid item in idLst) { - retObj.DetailList_BS.AddRange(masterObj.Details); - masterObj.Details = null; + BillM100 sourceObj = await _billM100Repository.GetAsync(item); + if (sourceObj != null) + { + await _billM100PartRepository.DeleteManyAsync(sourceObj.BillM100Parts); + await _billM100Repository.DeleteAsync(item); + } } + return ret; + } + catch (Exception ex) + { + ret.Status = false; + ret.Message = _errorMessagePrefix + "DeleteAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); + return ret; + } + } - retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); - if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; - foreach (var masterObj in retObj.MasterList_BX) + /// + /// 导出信息 + /// + /// 导出查询条件 + /// 执行成功返回真 + [UnitOfWork(false)] + [HttpPost] + [Route("export")] + public virtual async Task> ExportAsync(QueryBillM100Dto input) + { + _logger.LogDebug(_errorMessagePrefix + "ExportAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); + try + { + input.SkipCount = 0; + input.MaxResultCount = 50000; + PagedResultDto query = new PagedResultDto(); + if (!string.IsNullOrEmpty(input.GroupName)) { - retObj.DetailList_BX.AddRange(masterObj.Details); - masterObj.Details = null; + query = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); } - - retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); - if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; - foreach (var masterObj in retObj.MasterList_D) + else { - retObj.DetailList_D.AddRange(masterObj.Details); - masterObj.Details = null; + query = await QueryByConditionAsync(input, (PagedAndSortedBase)input); } + List items = query.Items.ToList(); + //将实体列表转换成excel文件流 + IExporter exporter = new ExcelExporter(); + byte[] byteArr = await exporter.ExportAsByteArray(items); + byteArr.ShouldNotBeNull(); + //将excel文件流保存到服务器端文件系统 + string fileName = string.Format("单据M100_{0}.xlsx", Guid.NewGuid().ToString()); + await _blobContainer.SaveAsync(fileName, byteArr); - retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); - if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; - foreach (var masterObj in retObj.MasterList_HL) - { - retObj.DetailList_HL.AddRange(masterObj.Details); - masterObj.Details = null; - } - #endregion - ret.Status = true; + ret.Item = fileName; return ret; } catch (Exception ex) { - string errorMsg = _errorMessagePrefix + "PrintZhuHuBanPackingList 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - throw new BusinessException("1001", errorMsg); ret.Status = false; - ret.Message = ex.Message; + ret.Message = _errorMessagePrefix + "ExportAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); return ret; } } /// - /// 保存柱护板装箱单报表 + /// 导入信息 /// + /// 导入文件流 + /// 执行成功返回真 [UnitOfWork] [HttpPost] - [Route("save-group-zhuhuban-report")] - public virtual async Task>> SaveGroupZhuHuBanReport(ZhuHuBanPrintInputDto input) + [Route("import")] + public virtual async Task ImportAsync(byte[] input) { - _logger.LogDebug(_errorMessagePrefix + "SaveGroupZhuHuBanReport 进入"); + throw new NotImplementedException("暂不实现所有导入"); + } + + #endregion + - List retLst = new List(); - ObjectResultDto> ret = new ObjectResultDto>(); - ret.Status = false; - using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified )) + #region 超时提醒 + /// + /// 生产线超时提醒 + /// + /// 生产线编号列表 + /// 生产线超时情况 + [UnitOfWork] + [HttpPost] + [Route("product-line-timeout-remind")] + public virtual async Task> ProductLineTimeoutRemind(TimeOutRemindInputDto input) + { + List retLst = new List(); + foreach (string plStr in input.ProductLineList) { - try + TimeOutRemindResultDto retObj = new TimeOutRemindResultDto(); + retObj.ProductLine = plStr; + retObj.ConfigMinutes = _configuration[$"ConfigDic:ProductLineTimeoutRemind:{plStr}"].TryToInt() ?? 30; + + string maxSNStr = await _billM100Repository.Where(itm => itm.ProductLine == plStr).MaxAsync(itm => itm.SerialNumStr); + BillM100 lastBill = await _billM100Repository.FirstOrDefaultAsync(itm => itm.ProductLine == plStr && itm.SerialNumStr == maxSNStr); + if (lastBill != null) { - List reportMainLst = new List(); - List forWMSLst = new List(); + retObj.LastReceiveTime = lastBill.ReceiveTime ?? ServerHelper.CurrentDateTime; + retObj.TimeoutMinutes = MinuteDiff(retObj.LastReceiveTime, ServerHelper.CurrentDateTime); + } + retLst.Add(retObj); + } + return new ListResultDto(retLst); + } - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "起大众顺序号不能大于止大众顺序号!"; - ret.Status = false; - return ret; - } + private int MinuteDiff(DateTime beginTime, DateTime endTime) + { + TimeSpan beginSpan = new TimeSpan(beginTime.Ticks); + TimeSpan endSpan = new TimeSpan(endTime.Ticks); + TimeSpan diffSpan = endSpan.Subtract(beginSpan).Duration(); + return (int)(diffSpan.TotalMinutes); + } - ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - if (billLst.Count > 24) - { - ret.Message = "打印柱护板单据的数量不能大于24!"; - ret.Status = false; - return ret; - } - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + #endregion - long maxBillNum = 0; //子方法内部赋值 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; + #region 保存报表、加载打印报表分离 + //[UnitOfWork] + //[UnitOfWork] + //[HttpPost] + //[Route("load-menban-report")] + //public virtual async Task> LoadMenBanReport(List input) + //{ + // _logger.LogDebug(_errorMessagePrefix + "LoadMenBanReport 进入"); - + // MenBanPrintResultDto retObj = new MenBanPrintResultDto(); + // ObjectResultDto ret = new ObjectResultDto(retObj); + // ret.Status = false; + // try + // { + // List reportMainLst = new List(); - //获取当前打印柱护板的零件类型 - var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); - foreach (var partType in partTypes) - { - switch (partType.PartType) - { - case "A上C上": - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - break; - case "A柱下A中": - //A柱下,A中 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - break; - case "B柱上": - //B柱上 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - break; - case "B柱下": - //B柱下 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - break; - case "D柱": - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - break; - case "后轮上装饰板": - //后轮,上装饰板 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - break; - } - } - #region 调用库存接口 - await SaveMiddleTable_ZHB(forWMSLst); - #endregion + // reportMainLst = await _menBanPackingListRepository.GetListAsync(itm => input.Contains(itm.Id) == true, true); + // //按大众顺序号排序 + // foreach (var reportMainObj in reportMainLst) + // { + // List recLst = reportMainObj.Details; + // if (recLst == null) + // continue; + + // bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997") + // || itm.HostSN.Contains("1996") || itm.HostSN.Contains("1995") || itm.HostSN.Contains("1994") + // || itm.HostSN.Contains("1993") || itm.HostSN.Contains("1992") || itm.HostSN.Contains("1991") + // || itm.HostSN.Contains("1990") || itm.HostSN.Contains("1989") || itm.HostSN.Contains("1988") + // || itm.HostSN.Contains("1987") || itm.HostSN.Contains("1986") || itm.HostSN.Contains("1985") + // || itm.HostSN.Contains("1984") || itm.HostSN.Contains("1983") || itm.HostSN.Contains("1982") + // || itm.HostSN.Contains("1981") || itm.HostSN.Contains("1980") || itm.HostSN.Contains("1979") + // || itm.HostSN.Contains("1978") || itm.HostSN.Contains("1977") || itm.HostSN.Contains("1976") + // ); + // bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003") + // || itm.HostSN.Contains("0004") || itm.HostSN.Contains("0005") || itm.HostSN.Contains("0006") + // || itm.HostSN.Contains("0007") || itm.HostSN.Contains("0008") || itm.HostSN.Contains("0009") + // || itm.HostSN.Contains("0010") || itm.HostSN.Contains("0011") || itm.HostSN.Contains("0012") + // || itm.HostSN.Contains("0013") || itm.HostSN.Contains("0014") || itm.HostSN.Contains("0015") + // || itm.HostSN.Contains("0016") || itm.HostSN.Contains("0017") || itm.HostSN.Contains("0018") + // || itm.HostSN.Contains("0019") || itm.HostSN.Contains("0020") || itm.HostSN.Contains("0021") + // || itm.HostSN.Contains("0022") || itm.HostSN.Contains("0023") || itm.HostSN.Contains("0024") + // ); + // if (has1999 && has0001) + // { + // reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN.TryToIntZero() % 10000) < 240 ? (itm.HostSN.TryToIntZero() % 10000 + 1999) : (itm.HostSN.TryToIntZero() % 10000)).ToList(); + // } + // else + // { + // reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); + // } + // } - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - if (insObj2 != null) - { - retLst.Add(insObj2.Id); - } - } + // #region 格式转换 + // //实体 转 DTO + // List targetLst = ObjectMapper.Map, List>(reportMainLst); + // targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList(); - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - List list = new List(); - foreach (var updObj in updLst) - { - ZHBPrintStatus item = new ZHBPrintStatus( - GuidGenerator.Create(), - updObj.VIN, - input.GroupName, - 1 - ); - list.Add(item); - - //updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _zHBPrintStatusRepository.InsertManyAsync(list);//柱护板插入状态 - await _billM100Repository.UpdateManyAsync(updLst, true); - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - throw new BusinessException("请调用LoadZhuHuBanReport方法!"); - } - else if (input.PrintType == PrintTypeEnum.补打) - { - if (input.M100IdList.Count > 24) - { - throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); - } + // //补充空行 + // foreach (var masterObj in targetLst) + // { + // int trueCnt = masterObj.Details.Count; + // int planCnt = 12; + // if (trueCnt > planCnt) + // { + // throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + // } + // int diffCnt = planCnt - trueCnt; + // for (int i = 0; i < diffCnt; i++) + // { + // MenBanPackingRecDto dtlObj = new MenBanPackingRecDto(); + // masterObj.Details.Add(dtlObj); + // } + // } + // //子表BillNum赋值, BillNum填充空格 + // foreach (var masterObj in targetLst) + // { + // masterObj.BillNum = GetTrueString(masterObj.BillNum); + // int sn = 1; + // foreach (var detailObj in masterObj.Details) + // { + // detailObj.BillNum = masterObj.BillNum; + // detailObj.KNR = GetTrueString(detailObj.KNR); + // detailObj.sn = sn++; + // detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + // } + // } + // //返回结果格式转换 + // foreach (var masterObj in targetLst) + // { + // foreach (var detailObj in masterObj.Details) + // { + // retObj.DetailList.Add(detailObj); + // } + // masterObj.Details = null; + // retObj.MasterList.Add(masterObj); + // } + // #endregion + // ret.Status = true; + // return ret; + // } + // catch (Exception ex) + // { + // string errorMsg = _errorMessagePrefix + "LoadMenBanReport 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } + //} - List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; - ret.Status = false; - return ret; - } - billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - long maxBillNum = 0; //全局唯一装箱单号 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; //右上角顺序号01-99 - //获取当前打印柱护板的零件类型 - var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); - foreach (var partType in partTypes) - { - switch (partType.PartType) - { - case "A上C上": - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - break; - case "A柱下A中": - //A柱下,A中 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - break; - case "B柱上": - - //B柱上 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - break; - case "B柱下": - //B柱下 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - break; - case "D柱": - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - break; - case "后轮上装饰板": - //后轮,上装饰板 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - break; - } - } - #region 调用库存接口 - await SaveMiddleTable_ZHB(forWMSLst); - #endregion + /// + /// 打印柱护板装箱单 + /// + /// + /// 执行成功返回真 + //[UnitOfWork] + //[HttpPost] + //[Route("print-group-zhuhuban-packing-list")] + //public virtual async Task> PrintGroupZhuHuBanPackingList(ZhuHuBanPrintInputDto input) + //{ + // ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); + // ObjectResultDto ret = new ObjectResultDto(retObj); + // ret.Status = false; + // try + // { + // List reportMainLst = new List(); + // List forWMSLst = new List(); - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - if (insObj2 != null) - { - retLst.Add(insObj2.Id); - } - } - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - } //补打if + // if (input.PrintType == PrintTypeEnum.正常打印) + // { + // if (input.BeginHostSN > input.EndHostSN) + // { + // ret.Message = "起大众顺序号不能大于止大众顺序号!"; + // ret.Status = false; + // return ret; + // } + + // ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- + // List billLst = tempLst.Item; + // if (tempLst.Status == false) + // { + // ret.Message = tempLst.Message; + // ret.Status = false; + // return ret; + // } + // if (billLst.Count > 24) + // { + // ret.Message = "打印柱护板单据的数量不能大于24!"; + // ret.Status = false; + // return ret; + // } + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + + // long maxBillNum = 0; //子方法内部赋值 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; + + // //获取当前打印柱护板的零件类型 + // var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); + // foreach (var partType in partTypes) + // { + // switch (partType.PartType) + // { + // case "A上C上": + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + // break; + // case "A柱下A中": + // //A柱下,A中 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + + // break; + // case "B柱上": + // //B柱上 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // break; + // case "B柱下": + // //B柱下 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // break; + // case "D柱": + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + // break; + // case "后轮上装饰板": + // //后轮,上装饰板 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + // break; + // } + // } + + // #region 调用库存接口 + // //List forWMSLst = new List(); + // //forWMSLst.AddRange(reportMainLst); + // //forWMSLst.AddRange(acLstOnlyWMSUse); + // CallWMSInterface_ZHB(forWMSLst); + // #endregion + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // } + + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // await _billM100Repository.UpdateManyAsync(updLst, true); + + // } + // else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 + // { + // if (input.DataResultType == "1") //全部11条数据 + // { + // var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); + // if (firObj != null) + // { + // Guid? sortId = firObj.SortId; + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); + // } + // } + // else + // { + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); + // } + + // //按大众顺序号排序 + // foreach (var reportMainObj in reportMainLst) + // { + // List recLst = reportMainObj.Details; + // if (recLst == null) + // continue; + // //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); + // //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); + // bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) >= 1977); + // bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) <= 23); + // if (has1999 && has0001) + // { + // reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) <= 23 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); + // } + // else + // { + // reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); + // } + // } + // } + // else if (input.PrintType == PrintTypeEnum.补账打印) + // { + // if (input.M100IdList.Count > 24) + // { + // throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); + // } + + // List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); + // if (billLst.Count == 0) + // { + // ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; + // ret.Status = false; + // return ret; + // } + // billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); + + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + + // long maxBillNum = 0; //全局唯一装箱单号 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; //右上角顺序号01-99 + + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + // //A柱下,A中 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + // //B柱上 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // //B柱下 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + + // //后轮,上装饰板 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + + // #region 调用库存接口 + // //List forWMSLst = new List(); + // //forWMSLst.AddRange(reportMainLst); + // //forWMSLst.AddRange(acLstOnlyWMSUse); + // CallWMSInterface_ZHB(forWMSLst); + // #endregion + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // var ret22 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // } + + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // await _billM100Repository.UpdateManyAsync(updLst, true); + // } + + // #region 返回结果格式转换 + // //实体 转 DTO + // List targetLst = ObjectMapper.Map, List>(reportMainLst); + // //补充空行 + // foreach (var masterObj in targetLst) + // { + // int trueCnt = masterObj.Details.Count; + + // int planCnt = 0; + // switch (masterObj.PartType) + // { + // case "A上C上": + // case "A柱下A中": + // case "B柱上": + // case "B柱下": + // case "后轮上装饰板": + // planCnt = 24; + // break; + // case "D柱": + // planCnt = 12; + // break; + // default: + // planCnt = 24; + // break; + // } + // if (trueCnt > planCnt) + // { + // throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + // } + // int diffCnt = planCnt - trueCnt; + // for (int i = 0; i < diffCnt; i++) + // { + // ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); + // masterObj.Details.Add(dtlObj); + // } + // } + // //子表BillNum赋值, BillNum填充空格, SN赋值 + // foreach (var masterObj in targetLst) + // { + // masterObj.BillNum = GetTrueString(masterObj.BillNum); + // int sn = 1; + // foreach (var detailObj in masterObj.Details) + // { + // detailObj.BillNum = masterObj.BillNum; + // detailObj.KNR = GetTrueString(detailObj.KNR); + // detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); + // detailObj.sn = sn++; + // detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + // //客户要求显示零件描述,替换之前的零件编码 + // detailObj.PartCode = detailObj.MaterialDescription; + // detailObj.PartCode2 = detailObj.MaterialDescription2; + // detailObj.MaterialDescription = null; + // detailObj.MaterialDescription2 = null; + // } + // } + + // retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); + // if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; + // foreach (var masterObj in retObj.MasterList_AC) + // { + // retObj.DetailList_AC.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); + // if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; + // foreach (var masterObj in retObj.MasterList_AA) + // { + // retObj.DetailList_AA.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); + // if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; + // foreach (var masterObj in retObj.MasterList_BS) + // { + // retObj.DetailList_BS.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); + // if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; + // foreach (var masterObj in retObj.MasterList_BX) + // { + // retObj.DetailList_BX.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - await uow.CompleteAsync(); - ret.Status = true; - ret.Item = retLst; - return ret; - } - catch (Exception ex) - { - await uow.RollbackAsync(); - string errorMsg = _errorMessagePrefix + "SaveGroupZhuHuBanReport 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - //throw new BusinessException("1001", errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; - } + // retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); + // if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; + // foreach (var masterObj in retObj.MasterList_D) + // { + // retObj.DetailList_D.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + + // retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); + // if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; + // foreach (var masterObj in retObj.MasterList_HL) + // { + // retObj.DetailList_HL.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + // #endregion + // ret.Status = true; + // return ret; + // } + // catch (Exception ex) + // { + // string errorMsg = _errorMessagePrefix + "PrintZhuHuBanPackingList 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // throw new BusinessException("1001", errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } + //} - } //事务 - } /// /// 保存柱护板装箱单报表 /// - [UnitOfWork(IsDisabled = true)] - [HttpPost] - [Route("save-zhuhuban-report")] - public virtual async Task>> SaveZhuHuBanReport(ZhuHuBanPrintInputDto input) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - _logger.LogDebug(_errorMessagePrefix + "SaveZhuHuBanReport 进入"); - List retLst = new List(); - ObjectResultDto> ret = new ObjectResultDto>(); - ret.Status = false; - using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified)) - { - try - { - List reportMainLst = new List(); - List forWMSLst = new List(); + //[UnitOfWork(IsDisabled = true)] + //[HttpPost] + //[Route("save-zhuhuban-report")] + //public virtual async Task>> SaveZhuHuBanReport(ZhuHuBanPrintInputDto input) + //{ + // Stopwatch sw = new Stopwatch(); + // sw.Start(); + // _logger.LogDebug(_errorMessagePrefix + "SaveZhuHuBanReport 进入"); + // List retLst = new List(); + // ObjectResultDto> ret = new ObjectResultDto>(); + // ret.Status = false; + // using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified)) + // { + // try + // { + // List reportMainLst = new List(); + // List forWMSLst = new List(); - if (input.PrintType == PrintTypeEnum.正常打印) - { - if (input.BeginHostSN > input.EndHostSN) - { - ret.Message = "起大众顺序号不能大于止大众顺序号!"; - ret.Status = false; - return ret; - } + // if (input.PrintType == PrintTypeEnum.正常打印) + // { + // if (input.BeginHostSN > input.EndHostSN) + // { + // ret.Message = "起大众顺序号不能大于止大众顺序号!"; + // ret.Status = false; + // return ret; + // } - ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- - List billLst = tempLst.Item; - if (tempLst.Status == false) - { - ret.Message = tempLst.Message; - ret.Status = false; - return ret; - } - if (billLst.Count > 24) - { - ret.Message = "打印柱护板单据的数量不能大于24!"; - ret.Status = false; - return ret; - } - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + // ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- + // List billLst = tempLst.Item; + // if (tempLst.Status == false) + // { + // ret.Message = tempLst.Message; + // ret.Status = false; + // return ret; + // } + // if (billLst.Count > 24) + // { + // ret.Message = "打印柱护板单据的数量不能大于24!"; + // ret.Status = false; + // return ret; + // } + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 加载缓存 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 加载缓存 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); - long maxBillNum = 0; //子方法内部赋值 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; + // long maxBillNum = 0; //子方法内部赋值 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); //插入序列表、并返回序列 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 转换A上C上 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - - //A柱下,A中 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - //B柱上 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - //B柱下 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - //后轮,上装饰板 - maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 转换除A上C上的其它 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - - #region 调用库存接口 - await SaveMiddleTable_ZHB(forWMSLst); - #endregion - - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 保存中间库 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - //var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - //if (insObj2 != null) - //{ - // retLst.Add(insObj2.Id); - //} - retLst.Add(srcObj2.Id); - } - await _zhuHuBanPackingListRepository.InsertManyAsync(reportMainLst); + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); //插入序列表、并返回序列 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 转换A上C上 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); + + + // //A柱下,A中 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + // //B柱上 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // //B柱下 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + + // //后轮,上装饰板 + // maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 转换除A上C上的其它 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); + + + // #region 调用库存接口 + // await SaveMiddleTable_ZHB(forWMSLst); + // #endregion + + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 保存中间库 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); + + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // //var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // //if (insObj2 != null) + // //{ + // // retLst.Add(insObj2.Id); + // //} + // retLst.Add(srcObj2.Id); + // } + // await _zhuHuBanPackingListRepository.InsertManyAsync(reportMainLst); - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 插入柱护板打印记录表 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 插入柱护板打印记录表 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - //await _billM100Repository.UpdateManyAsync(updLst, true); - await _billM100Repository.UpdateManyAsync(updLst); + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // //await _billM100Repository.UpdateManyAsync(updLst, true); + // await _billM100Repository.UpdateManyAsync(updLst); - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport 更新M100的柱护板打印标志 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - } - else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 - { - throw new BusinessException("请调用LoadZhuHuBanReport方法!"); - } - else if (input.PrintType == PrintTypeEnum.补打) - { - if (input.M100IdList.Count > 24) - { - throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); - } + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport 更新M100的柱护板打印标志 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); + // } + // else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 + // { + // throw new BusinessException("请调用LoadZhuHuBanReport方法!"); + // } + // else if (input.PrintType == PrintTypeEnum.补账打印) + // { + // if (input.M100IdList.Count > 24) + // { + // throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); + // } - List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); - if (billLst.Count == 0) - { - ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; - ret.Status = false; - return ret; - } - billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); + // List billLst = _billM100Repository.GetListAsync(itm => input.M100IdList.Contains(itm.Id), true).GetAwaiter().GetResult(); + // if (billLst.Count == 0) + // { + // ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; + // ret.Status = false; + // return ret; + // } + // billLst = billLst.OrderBy(itm => itm.SerialNumStr).ToList(); - //加载柱护板缓存列表 - _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + // //加载柱护板缓存列表 + // _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 - long maxBillNum = 0; //全局唯一装箱单号 - DateTime printTime = ServerHelper.CurrentDateTime; - double maxSN; //右上角顺序号01-99 + // long maxBillNum = 0; //全局唯一装箱单号 + // DateTime printTime = ServerHelper.CurrentDateTime; + // double maxSN; //右上角顺序号01-99 - //A上C上 - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); - List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 - if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) - { - acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 - } - reportMainLst.AddRange(acLst); - forWMSLst.AddRange(acLstOnlyWMSUse); - //A柱下,A中 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); - - List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); - List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(aaLst1); - reportMainLst.AddRange(aaLst2); - forWMSLst.AddRange(aaLst1); - forWMSLst.AddRange(aaLst2); - //B柱上 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); - List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bUpLst1); - reportMainLst.AddRange(bUpLst2); - forWMSLst.AddRange(bUpLst1); - forWMSLst.AddRange(bUpLst2); - //B柱下 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); - - List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); - List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(bDownLst1); - reportMainLst.AddRange(bDownLst2); - forWMSLst.AddRange(bDownLst1); - forWMSLst.AddRange(bDownLst2); - //D柱 - var lst1 = billLst.Take(12).ToList(); - var lst2 = billLst.Skip(12).ToList(); - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); - List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); - - maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); - List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); - List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); - reportMainLst.AddRange(dLst1); - reportMainLst.AddRange(dLst2); - forWMSLst.AddRange(forWMSLst1); - forWMSLst.AddRange(forWMSLst2); - - //后轮,上装饰板 - maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); - List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); - List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); - reportMainLst.AddRange(hsLst1); - reportMainLst.AddRange(hsLst2); - forWMSLst.AddRange(hsLst1); - forWMSLst.AddRange(hsLst2); - - #region 调用库存接口 - await SaveMiddleTable_ZHB(forWMSLst); - #endregion - - //插入柱护板打印记录表 - Guid sortId = GuidGenerator.Create(); - foreach (var srcObj2 in reportMainLst) - { - srcObj2.SortId = sortId; //一次打印SortId相同 - var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); - if (insObj2 != null) - { - retLst.Add(insObj2.Id); - } - } + // //A上C上 + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + // List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + // if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + // { + // acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + // } + // reportMainLst.AddRange(acLst); + // forWMSLst.AddRange(acLstOnlyWMSUse); + // //A柱下,A中 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + // List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(aaLst1); + // reportMainLst.AddRange(aaLst2); + // forWMSLst.AddRange(aaLst1); + // forWMSLst.AddRange(aaLst2); + // //B柱上 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + // List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bUpLst1); + // reportMainLst.AddRange(bUpLst2); + // forWMSLst.AddRange(bUpLst1); + // forWMSLst.AddRange(bUpLst2); + // //B柱下 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + // List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(bDownLst1); + // reportMainLst.AddRange(bDownLst2); + // forWMSLst.AddRange(bDownLst1); + // forWMSLst.AddRange(bDownLst2); + // //D柱 + // var lst1 = billLst.Take(12).ToList(); + // var lst2 = billLst.Skip(12).ToList(); + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); + // List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); + + // maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + // List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + // List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + // reportMainLst.AddRange(dLst1); + // reportMainLst.AddRange(dLst2); + // forWMSLst.AddRange(forWMSLst1); + // forWMSLst.AddRange(forWMSLst2); + + // //后轮,上装饰板 + // maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + // List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + // List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + // reportMainLst.AddRange(hsLst1); + // reportMainLst.AddRange(hsLst2); + // forWMSLst.AddRange(hsLst1); + // forWMSLst.AddRange(hsLst2); + + // #region 调用库存接口 + // await SaveMiddleTable_ZHB(forWMSLst); + // #endregion + + // //插入柱护板打印记录表 + // Guid sortId = GuidGenerator.Create(); + // foreach (var srcObj2 in reportMainLst) + // { + // srcObj2.SortId = sortId; //一次打印SortId相同 + // var insObj2 = await _zhuHuBanPackingListRepository.InsertAsync(srcObj2, true); + // if (insObj2 != null) + // { + // retLst.Add(insObj2.Id); + // } + // } - ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 - var updIdLst = billLst.Select(itm => itm.Id).ToList(); - var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); - foreach (var updObj in updLst) - { - updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" - updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 - } - await _billM100Repository.UpdateManyAsync(updLst, true); - } //补打if + // ////更新M100的柱护板打印标志: PrintBillNum不为空时表示已打印 + // var updIdLst = billLst.Select(itm => itm.Id).ToList(); + // var updLst = await _billM100Repository.GetListAsync(itm => updIdLst.Contains(itm.Id)); + // foreach (var updObj in updLst) + // { + // updObj.SetZHBBillStatus(ZHBBillStatusEnum.Print); //PrintBillNum = "柱护板已打印" + // updObj.PrintTime2 = ServerHelper.CurrentDateTime; //PrintTime只适用于门板 + // } + // await _billM100Repository.UpdateManyAsync(updLst, true); + // } //补打if - await uow.CompleteAsync(); - sw.Stop(); - _logger.LogWarning($"SaveZhuHuBanReport CompleteAsync - {sw.ElapsedMilliseconds}毫秒"); + // await uow.CompleteAsync(); + // sw.Stop(); + // _logger.LogWarning($"SaveZhuHuBanReport CompleteAsync - {sw.ElapsedMilliseconds}毫秒"); - ret.Status = true; - ret.Item = retLst; - return ret; - } - catch (Exception ex) - { - await uow.RollbackAsync(); - string errorMsg = _errorMessagePrefix + "SaveZhuHuBanReport 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - //throw new BusinessException("1001", errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; - } + // ret.Status = true; + // ret.Item = retLst; + // return ret; + // } + // catch (Exception ex) + // { + // await uow.RollbackAsync(); + // string errorMsg = _errorMessagePrefix + "SaveZhuHuBanReport 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // //throw new BusinessException("1001", errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } - } //事务 - } + // } //事务 + //} /// /// 加载柱护板装箱单报表【仅ReportIdList、DataResultType参数有效】 /// - [UnitOfWork] - [HttpPost] - [Route("load-zhuhuban-report")] - public virtual async Task> LoadZhuHuBanReport(ZhuHuBanPrintInputDto input) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - - _logger.LogDebug(_errorMessagePrefix + "LoadZhuHuBanReport 进入"); - - ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); - ObjectResultDto ret = new ObjectResultDto(retObj); - ret.Status = false; - try - { - List reportMainLst = new List(); - List forWMSLst = new List(); - - if (input.DataResultType == "1") //全部11条数据 - { - var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); - if (firObj != null) - { - Guid? sortId = firObj.SortId; - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); - } - } - else - { - reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); - } - - sw.Stop(); - _logger.LogWarning($"LoadZhuHuBanReport 取柱护板数据 - {sw.ElapsedMilliseconds}毫秒"); - sw.Start(); - - //按大众顺序号排序 - foreach (var reportMainObj in reportMainLst) - { - List recLst = reportMainObj.Details; - if (recLst == null) - continue; - //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); - //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); - bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) > 1999 - 240); - bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) < 240); - if (has1999 && has0001) - { - reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) < 240 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); - } - else - { - reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); - } - } + //[UnitOfWork] + //[HttpPost] + //[Route("load-zhuhuban-report")] + //public virtual async Task> LoadZhuHuBanReport(ZhuHuBanPrintInputDto input) + //{ + // Stopwatch sw = new Stopwatch(); + // sw.Start(); - #region 返回结果格式转换 - //实体 转 DTO - List targetLst = ObjectMapper.Map, List>(reportMainLst); - //补充空行 - foreach (var masterObj in targetLst) - { - int trueCnt = masterObj.Details.Count; + // _logger.LogDebug(_errorMessagePrefix + "LoadZhuHuBanReport 进入"); - int planCnt = 0; - switch (masterObj.PartType) - { - case "A上C上": - case "A柱下A中": - case "B柱上": - case "B柱下": - case "后轮上装饰板": - planCnt = 24; - break; - case "D柱": - planCnt = 12; - break; - default: - planCnt = 24; - break; - } - if (trueCnt > planCnt) - { - throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); - } - int diffCnt = planCnt - trueCnt; - for (int i = 0; i < diffCnt; i++) - { - ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); - masterObj.Details.Add(dtlObj); - } - } - //子表BillNum赋值, BillNum填充空格, SN赋值 - foreach (var masterObj in targetLst) - { - masterObj.BillNum = GetTrueString(masterObj.BillNum); - int sn = 1; - foreach (var detailObj in masterObj.Details) - { - detailObj.BillNum = masterObj.BillNum; - detailObj.KNR = GetTrueString(detailObj.KNR); - detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); - detailObj.sn = sn++; - detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 - //客户要求显示零件描述,替换之前的零件编码 - detailObj.PartCode = detailObj.MaterialDescription; - detailObj.PartCode2 = detailObj.MaterialDescription2; - detailObj.MaterialDescription = null; - detailObj.MaterialDescription2 = null; - } - } + // ZhuHuBanPrintResultDto retObj = new ZhuHuBanPrintResultDto(); + // ObjectResultDto ret = new ObjectResultDto(retObj); + // ret.Status = false; + // try + // { + // List reportMainLst = new List(); + // List forWMSLst = new List(); - retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); - if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; - foreach (var masterObj in retObj.MasterList_AC) - { - retObj.DetailList_AC.AddRange(masterObj.Details); - masterObj.Details = null; - } + // if (input.DataResultType == "1") //全部11条数据 + // { + // var firObj = await _zhuHuBanPackingListRepository.FirstOrDefaultAsync(itm => input.ReportIdList.Contains(itm.Id)); + // if (firObj != null) + // { + // Guid? sortId = firObj.SortId; + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => itm.SortId == sortId, true); + // } + // } + // else + // { + // reportMainLst = await _zhuHuBanPackingListRepository.GetListAsync(itm => input.ReportIdList.Contains(itm.Id), true); + // } - retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); - if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; - foreach (var masterObj in retObj.MasterList_AA) - { - retObj.DetailList_AA.AddRange(masterObj.Details); - masterObj.Details = null; - } + // sw.Stop(); + // _logger.LogWarning($"LoadZhuHuBanReport 取柱护板数据 - {sw.ElapsedMilliseconds}毫秒"); + // sw.Start(); - retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); - if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; - foreach (var masterObj in retObj.MasterList_BS) - { - retObj.DetailList_BS.AddRange(masterObj.Details); - masterObj.Details = null; - } + // //按大众顺序号排序 + // foreach (var reportMainObj in reportMainLst) + // { + // List recLst = reportMainObj.Details; + // if (recLst == null) + // continue; + // //bool has1999 = recLst.Any(itm => itm.HostSN.ToString().Contains("1999") || itm.HostSN.ToString().Contains("1998")); + // //bool has0001 = recLst.Any(itm => itm.HostSN.ToString().Contains("0001") || itm.HostSN.ToString().Contains("0002")); + // bool has1999 = recLst.Any(itm => (itm.HostSN % 10000) > 1999 - 240); + // bool has0001 = recLst.Any(itm => (itm.HostSN % 10000) < 240); + // if (has1999 && has0001) + // { + // reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN % 10000) < 240 ? (itm.HostSN % 10000 + 1999) : (itm.HostSN % 10000)).ToList(); + // } + // else + // { + // reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList(); + // } + // } - retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); - if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; - foreach (var masterObj in retObj.MasterList_BX) - { - retObj.DetailList_BX.AddRange(masterObj.Details); - masterObj.Details = null; - } + // #region 返回结果格式转换 + // //实体 转 DTO + // List targetLst = ObjectMapper.Map, List>(reportMainLst); + // //补充空行 + // foreach (var masterObj in targetLst) + // { + // int trueCnt = masterObj.Details.Count; - retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); - if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; - foreach (var masterObj in retObj.MasterList_D) - { - retObj.DetailList_D.AddRange(masterObj.Details); - masterObj.Details = null; - } + // int planCnt = 0; + // switch (masterObj.PartType) + // { + // case "A上C上": + // case "A柱下A中": + // case "B柱上": + // case "B柱下": + // case "后轮上装饰板": + // planCnt = 24; + // break; + // case "D柱": + // planCnt = 12; + // break; + // default: + // planCnt = 24; + // break; + // } + // if (trueCnt > planCnt) + // { + // throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + // } + // int diffCnt = planCnt - trueCnt; + // for (int i = 0; i < diffCnt; i++) + // { + // ZhuHuBanPackingRecDto dtlObj = new ZhuHuBanPackingRecDto(); + // masterObj.Details.Add(dtlObj); + // } + // } + // //子表BillNum赋值, BillNum填充空格, SN赋值 + // foreach (var masterObj in targetLst) + // { + // masterObj.BillNum = GetTrueString(masterObj.BillNum); + // int sn = 1; + // foreach (var detailObj in masterObj.Details) + // { + // detailObj.BillNum = masterObj.BillNum; + // detailObj.KNR = GetTrueString(detailObj.KNR); + // detailObj.KNR = detailObj.KNR.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("/n", "").Replace("/r", ""); + // detailObj.sn = sn++; + // detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + // //客户要求显示零件描述,替换之前的零件编码 + // detailObj.PartCode = detailObj.MaterialDescription; + // detailObj.PartCode2 = detailObj.MaterialDescription2; + // detailObj.MaterialDescription = null; + // detailObj.MaterialDescription2 = null; + // } + // } - retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); - if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; - foreach (var masterObj in retObj.MasterList_HL) - { - retObj.DetailList_HL.AddRange(masterObj.Details); - masterObj.Details = null; - } - #endregion + // retObj.MasterList_AC = targetLst.Where(itm => itm.PartType == "A上C上").ToList(); + // if (retObj.MasterList_AC.Count == 0) retObj.IsVisibleAC = false; + // foreach (var masterObj in retObj.MasterList_AC) + // { + // retObj.DetailList_AC.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - sw.Stop(); - _logger.LogWarning($"LoadZhuHuBanReport 排序及转换 - {sw.ElapsedMilliseconds}毫秒"); + // retObj.MasterList_AA = targetLst.Where(itm => itm.PartType == "A柱下A中").ToList(); + // if (retObj.MasterList_AA.Count == 0) retObj.IsVisibleAA = false; + // foreach (var masterObj in retObj.MasterList_AA) + // { + // retObj.DetailList_AA.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - ret.Status = true; - return ret; - } - catch (Exception ex) - { - string errorMsg = _errorMessagePrefix + "LoadZhuHuBanReport 执行出错:" + ex.Message; - _logger.LogError(errorMsg); - //throw new BusinessException("1001", errorMsg); - ret.Status = false; - ret.Message = ex.Message; - return ret; - } - } + // retObj.MasterList_BS = targetLst.Where(itm => itm.PartType == "B柱上").ToList(); + // if (retObj.MasterList_BS.Count == 0) retObj.IsVisibleBS = false; + // foreach (var masterObj in retObj.MasterList_BS) + // { + // retObj.DetailList_BS.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - /// - /// 保存门板信息到中间表,中间表是位于FIS库,和WMS中间表结构相同 - /// - /// - private async Task SaveMiddleTable_MB(List input) - { - List targetMainLst = new List(); - List targetDetailLst = new List(); - List cxLst = new List(); - foreach (MenBanPackingList sourceObj in input) - { - FisTB_BILL targetMain = new FisTB_BILL(); - targetMain.BillNum = sourceObj.BillNum; //单据编号 - targetMain.State = 0; - targetMain.BillType = 206; //单据类型 - targetMain.SubBillType = 21004; //单据子类型 - targetMain.BillTime = sourceObj.PrintDate; //单据时间 - targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 - targetMain.DetailQty = 0; //明细数量 - targetMain.CustId = _providerCode; //供应商编号 - //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - //targetMain.DockCode = sourceObj.BillLocation; - - targetMain.GateCode = sourceObj.PartType; //B柱下 - targetMain.GateName = sourceObj.BillSerialNum; //顺序号 - targetMain.DockCode = sourceObj.BillLocation; //左或右 - targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间(预计到达时间) - targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 - targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 - targetMainLst.Add(targetMain); - int idx = 0; - int idx2 = 0; - foreach (MenBanPackingRec sourceRec in sourceObj.Details) - { - idx2++; - if (sourceRec.TopSAPMaterialNum.IsNullOrEmpty() == false) - { - var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.TopSAPMaterialNum && itm.MaterialType == "1"); - idx++; - FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.LineNum = idx2; //行号 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.SeqNum = idx2.ToString(); //顺序号sourceRec.HostSN.ToString() - targetDetail.PartCode = sourceRec.TopSAPMaterialNum; //物料号 - //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 - targetDetail.ProjectId = ""; //车型 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.State = "0"; //状态 - targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; - targetDetail.FullBarCode = "-"; - targetDetail.VendId = sourceRec.KNR; - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - if (sourceRec.BelowSAPMaterialNum.IsNullOrEmpty() == false) - { - var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.BelowSAPMaterialNum && itm.MaterialType == "1"); - - idx++; - FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = sourceRec.BelowSAPMaterialNum; //物料号 - targetDetail.LineNum = (idx2 + 12); //行号 - targetDetail.SeqNum = (idx2 + 12).ToString(); //顺序号sourceRec.HostSN.ToString() - //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; - targetDetail.FullBarCode = "-"; - targetDetail.VendId = sourceRec.KNR; - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - } - //生成车型 - string cxStr = ""; - foreach (string cxObj in cxLst.Distinct()) - { - cxStr += cxObj + "、"; - } - if (cxStr.Length > 0) - { - cxStr = cxStr.Substring(0, cxStr.Length - 1); - } - targetMain.ProjectId = cxStr; //添加车型 + // retObj.MasterList_BX = targetLst.Where(itm => itm.PartType == "B柱下").ToList(); + // if (retObj.MasterList_BX.Count == 0) retObj.IsVisibleBX = false; + // foreach (var masterObj in retObj.MasterList_BX) + // { + // retObj.DetailList_BX.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - if (string.IsNullOrEmpty(cxStr)) - { - targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - } - } + // retObj.MasterList_D = targetLst.Where(itm => itm.PartType == "D柱").ToList(); + // if (retObj.MasterList_D.Count == 0) retObj.IsVisibleD = false; + // foreach (var masterObj in retObj.MasterList_D) + // { + // retObj.DetailList_D.AddRange(masterObj.Details); + // masterObj.Details = null; + // } - foreach (FisTB_BILL targetMain in targetMainLst) - { - //明细数量 - targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); - } - //保存到数据表 - await _tbBillRepository.InsertManyAsync(targetMainLst, true); - await _tsSortDetailRepository.InsertManyAsync(targetDetailLst, true); - } + // retObj.MasterList_HL = targetLst.Where(itm => itm.PartType == "后轮上装饰板").ToList(); + // if (retObj.MasterList_HL.Count == 0) retObj.IsVisibleHL = false; + // foreach (var masterObj in retObj.MasterList_HL) + // { + // retObj.DetailList_HL.AddRange(masterObj.Details); + // masterObj.Details = null; + // } + // #endregion - /// - /// 保存柱护板信息到中间表,中间表是位于FIS库,和WMS中间表结构相同 - /// - /// - private async Task SaveMiddleTable_ZHB(List input) - { - List targetMainLst = new List(); - List targetDetailLst = new List(); + // sw.Stop(); + // _logger.LogWarning($"LoadZhuHuBanReport 排序及转换 - {sw.ElapsedMilliseconds}毫秒"); - List cxLst = new List(); - foreach (ZhuHuBanPackingList sourceObj in input) - { - FisTB_BILL targetMain = new FisTB_BILL(); - targetMain.BillNum = sourceObj.BillNum; //单据编号 - targetMain.State = 0; - targetMain.BillType = 206; //单据类型 - targetMain.SubBillType = 20110; //单据子类型 - targetMain.BillTime = sourceObj.PrintDate; //单据时间 - targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 - targetMain.DetailQty = 0; //明细数量 - targetMain.CustId = _providerCode; //供应商编号 - //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - - targetMain.GateName = sourceObj.BillSerialNum; //顺序号 - targetMain.GateCode = sourceObj.PartType; //B柱下 - targetMain.DockCode = sourceObj.BillLocation; //左或右 - targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间 - targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 - targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 - targetMainLst.Add(targetMain); - int idx = 0; - int barCode = 0; - foreach (ZhuHuBanPackingRec sourceRec in sourceObj.Details) - { - barCode++; - if (sourceRec.PartCode.IsNullOrEmpty() == false) - { - idx++; - //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode && itm.MaterialType == "2"); - var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode); - FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = materialObj == null ? sourceRec.PartCode : materialObj.MaterialNum; //SAP物料号 - targetDetail.LineNum = idx; //行号 - targetDetail.SeqNum = idx.ToString(); //顺序号 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - //targetDetail.BarCode = barCode.ToString(); //箱码 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = sourceRec.PartCode; //客户零件号 - targetDetail.FullBarCode = "-"; - targetDetail.VendId = sourceRec.KNR; - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } + // ret.Status = true; + // return ret; + // } + // catch (Exception ex) + // { + // string errorMsg = _errorMessagePrefix + "LoadZhuHuBanReport 执行出错:" + ex.Message; + // _logger.LogError(errorMsg); + // //throw new BusinessException("1001", errorMsg); + // ret.Status = false; + // ret.Message = ex.Message; + // return ret; + // } + //} - } - if (sourceRec.PartCode2.IsNullOrEmpty() == false) - { - idx++; - //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2 && itm.MaterialType == "2"); - var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2); - - FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); - targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 - targetDetail.VinCode = sourceRec.VIN; //VIN码 - targetDetail.PartCode = materialObj == null ? sourceRec.PartCode2 : materialObj.MaterialNum; //SAP物料号 - targetDetail.LineNum = idx; //行号 - targetDetail.SeqNum = idx.ToString(); //顺序号 - targetDetail.ProjectId = ""; //车型 - targetDetail.State = "0"; //状态 - //targetDetail.BarCode = barCode.ToString(); //箱码 - targetDetail.PlanQty = 1; //计划数量 - targetDetail.CustPartCode = sourceRec.PartCode2; //客户零件号 - targetDetail.FullBarCode = "-"; - targetDetail.VendId = sourceRec.KNR; - //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 - targetDetailLst.Add(targetDetail); - if (materialObj != null && materialObj.VehicleModel != null) - { - cxLst.Add(materialObj.VehicleModel); - } - } - } - //生成车型 - string cxStr = ""; - foreach (string cxObj in cxLst.Distinct()) - { - cxStr += cxObj + "、"; - } - if (cxStr.Length > 0) - { - cxStr = cxStr.Substring(0, cxStr.Length - 1); - } - targetMain.ProjectId = cxStr; //添加车型 - if (string.IsNullOrEmpty(cxStr)) - { - targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 - } - } - foreach (FisTB_BILL targetMain in targetMainLst) - { - //明细数量 - targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); - } - //保存到数据表 - //await _tbBillRepository.InsertManyAsync(targetMainLst, true); - //await _tsSortDetailRepository.InsertManyAsync(targetDetailLst, true); - await _tbBillRepository.InsertManyAsync(targetMainLst); - await _tsSortDetailRepository.InsertManyAsync(targetDetailLst); - } #endregion diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/ZhuHuBanPackingRecService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/ZhuHuBanPackingRecService.cs index 80c4e2a..1965a57 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/ZhuHuBanPackingRecService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/ZhuHuBanPackingRecService.cs @@ -55,7 +55,7 @@ namespace Win.Sfs.SettleAccount.FISes private readonly LineSNDomianService _lineSNDomianServic; private readonly IRepository _tbBillScrapRepository; - private readonly IRepository _zHBPrintStatusRepository; + //private readonly IRepository _zHBPrintStatusRepository; private readonly IRepository _printTemplateConfigurationRepository; /// @@ -67,7 +67,7 @@ namespace Win.Sfs.SettleAccount.FISes WMSDapperRepository wmsRepository, LineSNDomianService lineSNDomianServic, IRepository tbBillScrapRepository, - IRepository zHBPrintStatusRepository, + //IRepository zHBPrintStatusRepository, IRepository printTemplateConfigurationRepository ) @@ -77,7 +77,7 @@ namespace Win.Sfs.SettleAccount.FISes _billM100Repository = billM100Repository; _lineSNDomianServic = lineSNDomianServic; _tbBillScrapRepository = tbBillScrapRepository; - _zHBPrintStatusRepository = zHBPrintStatusRepository; + //_zHBPrintStatusRepository = zHBPrintStatusRepository; _printTemplateConfigurationRepository = printTemplateConfigurationRepository; } @@ -366,7 +366,7 @@ namespace Win.Sfs.SettleAccount.FISes var types = await _ZhuHuBanPackingListRepository.Where(p => idList.Contains(p.Id)).Select(p => p.PartType).Distinct().ToListAsync(); var groupName = await _printTemplateConfigurationRepository.FirstOrDefaultAsync(r => types.Contains(r.PartType)); var vins = _childList.Select(p => p.VIN).Distinct().ToList(); - await _zHBPrintStatusRepository.DeleteAsync(r => vins.Contains(r.VIN) && r.GroupName == groupName.GroupName); + //await _zHBPrintStatusRepository.DeleteAsync(r => vins.Contains(r.VIN) && r.GroupName == groupName.GroupName); } else { diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/AlreadyPrintAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/AlreadyPrintAppService.cs index 7b12a54..59625e3 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/AlreadyPrintAppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/AlreadyPrintAppService.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp.Application.Services; namespace WY.NewJit.PrintTable { - internal class AlreadyPrintAppService + public class AlreadyPrintAppService : ApplicationService, IAlreadyPrintAppService { } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService.cs index 6f62b0e..33ea011 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService.cs @@ -1,12 +1,1063 @@ -using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Uow; +using WY.NewJit.Common; +using WY.NewJit.Commons; +using WY.NewJit.EntityFrameworkCore; +using WY.NewJit.Extends; +using WY.NewJit.Extends.PaiGe; +using WY.NewJit.Extends.PaiGe.WMS; +using WY.NewJit.MsgBaseData; +using WY.NewJit.MsgCheck; +using WY.NewJit.PrintTable.Dtos; namespace WY.NewJit.PrintTable { - internal class WaitPrintAppService + [Route("api/newjit/wait-print")] + [ApiExplorerSettings(GroupName = SwaggerGroupConsts.报文打印)] + public partial class WaitPrintAppService : ApplicationService, IWaitPrintAppService { + /// + /// 错误信息前缀 + /// + private string _errorMessagePrefix + { + get + { + return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."; + } + } + + private const string _providerCode = "0709FAW-VW7XH"; + + /// + /// 柱护板缓存列表(打印柱护板时用到) + /// + private List _zhbCacheList = new List(); + + public IRepository _waitPrintRepository; + + /// + /// 日志 + /// + private ILogger _logger; + + /// + /// Dapper仓储 + /// + private readonly NewJitDapperRepository _newJitDapperRepository; + + private readonly IUnitOfWorkManager _unitOfWorkManager; + + /// + /// 最大右边号的领域方法 + /// + private readonly LineSNDomianService _lineSNDomianService; + + /// + /// 序列领域服务 + /// + private readonly SequenceDomainService _sequenceDomainService; + + /// + /// 整车总成配置仓库 + /// + private readonly IRepository _assemblyCfgVehicleRepository; + + /// + /// ERP总成仓储 + /// + private readonly IRepository _assemblyCfgErpRepository; + + /// + /// 派格版本物料库扩展 + /// + private readonly IRepository _materialExtRepository; + + /// + /// 门板装箱单仓储 + /// + private readonly IRepository _menBanPackingListRepository; + + private readonly IRepository _tbBillRepository; + private readonly IRepository _tsSortDetailRepository; + private readonly IRepository _alreadyPrintRepository; + + /// + /// 柱护板装箱单仓储 + /// + private readonly IRepository _zhuHuBanPackingListRepository; + + private readonly IRepository _printTemplateConfigurationRepository; + + private readonly M100DomainService _m100DomainService; + + public WaitPrintAppService( + IRepository waitPrintRepository, + ILogger logger, + NewJitDapperRepository newJitDapperRepository, + IUnitOfWorkManager unitOfWorkManager, + LineSNDomianService lineSNDomianService, + SequenceDomainService sequenceDomainService, + IRepository assemblyCfgVehicleRepository, + IRepository assemblyCfgErpRepository, + IRepository materialExtRepository, + IRepository menBanPackingListRepository, + IRepository tbBillRepository, + IRepository tsSortDetailRepository, + IRepository alreadyPrintRepository, + IRepository zhuHuBanPackingListRepository, + IRepository printTemplateConfigurationRepository, + M100DomainService m100DomainService + ) + { + _waitPrintRepository = waitPrintRepository; + _logger = logger; + _newJitDapperRepository = newJitDapperRepository; + _unitOfWorkManager = unitOfWorkManager; + _lineSNDomianService = lineSNDomianService; + _sequenceDomainService = sequenceDomainService; + _assemblyCfgVehicleRepository = assemblyCfgVehicleRepository; + _assemblyCfgErpRepository = assemblyCfgErpRepository; + _materialExtRepository = materialExtRepository; + _menBanPackingListRepository = menBanPackingListRepository; + _tbBillRepository = tbBillRepository; + _tsSortDetailRepository = tsSortDetailRepository; + _alreadyPrintRepository = alreadyPrintRepository; + _zhuHuBanPackingListRepository = zhuHuBanPackingListRepository; + _printTemplateConfigurationRepository = printTemplateConfigurationRepository; + _m100DomainService = m100DomainService; + } + + #region 私有方法 + /// + /// 取单表记录总数 + /// + /// + /// + /// + /// + /// + /// + public async Task GetEntityCountAsync(string tableName, string where) + { + string sql = $"select count(*) from {tableName} where 1=1 {where}"; + var ret = await _newJitDapperRepository.GetSingleBySqlAsync(sql); + return ret; + } + + /// + /// 取单表当前页数据 + /// + /// + /// + /// + /// + /// + /// + /// + public async Task> GetEntityListAsync(string tableName, string where, string orderFieldName, int pageSize, int pageIndex) + { + int skipNum = (pageIndex - 1) * pageSize; + int takeNum = pageSize; + string sql = $"select * from {tableName} where 1=1 {where} order by {orderFieldName} offset {skipNum} rows fetch next {takeNum} rows only"; + var ret = await _newJitDapperRepository.GetListBySqlAsync(sql); + return ret; + } + + public async Task> GetEntityListFromToAsync(string tableName, string where, string orderFieldName, int skipNum, int takeNum) + { + string sql = $"select * from {tableName} where 1=1 {where} order by {orderFieldName} offset {skipNum} rows fetch next {takeNum} rows only"; + var ret = await _newJitDapperRepository.GetListBySqlAsync(sql); + return ret; + } + + private static string GetWhere(QueryWaitPrintDto input) + { + string where = ""; + if (input.HostSNBegin != null) + { + where += string.Format(" and HostSN >= {0}", input.HostSNBegin); + } + if (input.HostSNEnd != null) + { + where += string.Format(" and HostSN <= {0}", input.HostSNEnd); + } + if (!string.IsNullOrEmpty(input.KNRBegin)) + { + where += string.Format(" and KNR >= '{0}'", input.KNRBegin); + } + if (!string.IsNullOrEmpty(input.KNREnd)) + { + where += string.Format(" and KNR <= '{0}'", input.KNREnd); + } + if (!string.IsNullOrEmpty(input.VINBegin)) + { + where += string.Format(" and VIN >= '{0}'", input.VINBegin); + } + if (!string.IsNullOrEmpty(input.VINEnd)) + { + where += string.Format(" and VIN <= '{0}'", input.VINEnd); + } + if (input.AssemblyID != null) + { + where += string.Format(" and AssemblyID = '{0}'", input.AssemblyID.ToString()); + } + if (input.OnlineTimeBegin != null) + { + where += string.Format(" and OnlineTime >= '{0}'", ((DateTime)input.OnlineTimeBegin).ToString("yyyy-MM-dd HH:mm:ss")); + } + if (input.OnlineTimeEnd != null) + { + where += string.Format(" and OnlineTime <= '{0}'", ((DateTime)input.OnlineTimeEnd).ToString("yyyy-MM-dd HH:mm:ss")); + } + if (input.VehicleModelCode != null) + { + where += string.Format(" and VehicleModelCode like '%{0}%'", input.VehicleModelCode); + } + if (input.ProductLine != null) + { + where += string.Format(" and ProductLine = '{0}'", input.ProductLine); + } + if (input.ReceiveTimeBegin != null) + { + where += string.Format(" and ReceiveTime >= '{0}'", ((DateTime)input.ReceiveTimeBegin).ToString("yyyy-MM-dd HH:mm:ss")); + } + if (input.ReceiveTimeEnd != null) + { + where += string.Format(" and ReceiveTime <= '{0}'", ((DateTime)input.ReceiveTimeEnd).ToString("yyyy-MM-dd HH:mm:ss")); + } + if (input.BillStatus != null && input.BillStatus != BillStatusEnum.None) + { + where += string.Format(" and BillStatus = {0}", ((int)input.BillStatus).ToString()); + } + if (input.BusinessType != null) + { + where += string.Format(" and BusinessType = {0}", ((int)input.BusinessType).ToString()); + } + if (input.PrintType != null) + { + where += string.Format(" and PrintType = {0}", ((int)input.PrintType).ToString()); + } + return where; + } + + /// + /// 根据筛选条件获取实体列表 + /// + private async Task> QueryByConditionAsync(QueryWaitPrintDto input, PagedAndSortedBase page) + { + PagedResultDto ret = new PagedResultDto(); + + string where = GetWhere(input); + + ret.TotalCount = await GetEntityCountAsync("FisWaitPrint", where); + + //计算分页 + int fromRec = page.SkipCount + 1; + int ToRec = page.SkipCount + page.MaxResultCount; + + var lst = await GetEntityListFromToAsync("FisWaitPrint", where, "HostSN2", fromRec, ToRec); + ret.Items = lst; + return ret; + } + + /// + /// 查询柱护板 + /// + /// + /// + /// + private async Task> QueryZHBByConditionAsync(QueryWaitPrintDto input, PagedAndSortedBase page) + { + PagedResultDto ret = new PagedResultDto(); + + string where = GetWhere(input); + + ret.TotalCount = await GetEntityCountAsync("FisWaitPrint", where); + + //计算分页 + int fromRec = page.SkipCount + 1; + int ToRec = page.SkipCount + page.MaxResultCount; + + var lst = await GetEntityListFromToAsync("FisWaitPrint", where, "HostSN2", fromRec, ToRec); + ret.Items = lst; + return ret; + } + + #endregion + + #region 门板私有方法 + /// + /// 根据条件取用于打印的门板单据列表 + /// + /// + /// 断号时是否填充【1.5版已作废】 + /// + private async Task> GetMBReportDetailList(MenBanPrintInputDto input, bool isFillBreakNum = false) + { + List billLst = new List(); + ListResultDto ret = new ListResultDto(billLst); + + int printBillCnt = 0; + if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.正常打印) + { + if ((input.BeginHostSN % 10000) > 1999) + { + throw new Exception("起始大众顺序号不能大于1999!"); + } + if (input.BeginHostSN > input.EndHostSN) + { + throw new Exception("起始大众顺序号不能大于止大众顺序号!"); + } + + printBillCnt = input.EndHostSN - input.BeginHostSN + 1; + + int minHostSN2 = await _waitPrintRepository.Where(itm => + itm.BusinessType == BusinessTypeEnum.MenBan + && itm.ProductLine == input.ProductLine //生产线 + && itm.PrintType == PrintTypeEnum.OrderPrint //顺序打印 + && itm.HostSN == input.BeginHostSN + ).MinAsync(itm => itm.HostSN2); + + var firstObj = await _waitPrintRepository.FirstOrDefaultAsync(itm => itm.HostSN2 == minHostSN2); + if (firstObj == null) + { + throw new Exception("没有找到起始大众顺序号!!"); + } + + billLst = await _waitPrintRepository.Where(itm => + itm.BusinessType == BusinessTypeEnum.MenBan + && itm.ProductLine == input.ProductLine //生产线 + && itm.PrintType == PrintTypeEnum.OrderPrint //顺序打印 + && itm.HostSN2 >= minHostSN2) + .OrderBy(itm => itm.HostSN2) + .Take(printBillCnt).ToListAsync(); + + bool hasData = billLst.Any(); + if (hasData == false) + { + ret.Message = $"输入的起始大众顺序号没有对应的数据。生产线:{input.ProductLine},起止顺序号:{input.BeginHostSN} - {input.EndHostSN}"; + ret.Status = false; + return ret; + } + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.补账打印) + { + } + ret.Status = true; + ret.Item = billLst; + return ret; + } + + /// + /// 打印左侧或右侧门板 + /// + /// + /// + /// + /// + /// + /// + /// + /// + private List DoMBPrint(MenBanPrintInputDto input, int pageIdx, ref double maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) + { + const int _colNumberPerPage = 12; + List retLst = new List(); + + //取当前页内容 + List curPageLst = billLst.Skip(pageIdx * _colNumberPerPage).Take(_colNumberPerPage).ToList(); + //取车型 C8,Q5 + var vmLst = curPageLst.Select(itm => itm.VehicleModelCode).Distinct().ToList(); + string vmStr = ""; + foreach (var item in vmLst) + { + vmStr += item + ","; + } + if (vmStr.Length > 0) + { + vmStr = vmStr.Substring(0, vmStr.Length - 1); + } + + //填充门板装箱单主实体 + MenBanPackingList mbObj = new MenBanPackingList(); + mbObj.SetId(GuidGenerator.Create()); + + long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + mbObj.BillNum = GetBillNum(maxBillNum2); + mbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + + + mbObj.BillLocation = rightOrLeft; //右或左 + mbObj.ProviderCode = _providerCode; //供应商厂家代码 + mbObj.PartType = vmStr + " DP"; //零件类型 + mbObj.Capacity = curPageLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); //器具容量 + mbObj.PrintDate = printTime; //打印日期 + mbObj.PrintType = input.PrintType; + mbObj.ProductLine = input.ProductLine; + + var tempLst = curPageLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); + if (tempLst.Count > 0) + { + mbObj.BeginVin = tempLst[0].VIN; + mbObj.EndVin = tempLst[tempLst.Count - 1].VIN; + mbObj.BeginHostSN = tempLst[0].HostSN.ToString(); + mbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); + } + mbObj.MinOnlineTime = tempLst.Min(itm => itm.OnlineTime); //本单据最早的上线时间 + + int posNum = 0; + string promMsg; //报表数据异常提示信息 + foreach (WaitPrint billObj in curPageLst) + { + posNum++; + promMsg = ""; + //取物料信息 + MaterialExt leftObj = null; + MaterialExt rightObj = null; + if (billObj.AssemblyID != null) + { + //取单据包含的ERP总成列表 + List erpAssemblyLst = GetErpAssemblyListByBill((Guid)billObj.AssemblyID); + List erpCodeLst = erpAssemblyLst.Select(itm => itm.ErpAssemblyCode).ToList(); + //根据ERP总成编码取对应的物料扩展信息 + List materialExtLst = _materialExtRepository.Where(itm => erpCodeLst.Contains(itm.RelationKey)).ToList(); + if (erpCodeLst.Count != 4) + { + promMsg += $"*总成数量是{erpCodeLst.Count}*"; + } + if (erpCodeLst.Count == 4 && materialExtLst.Count == 0) + { + promMsg += $"*物料表没数据*"; + } + + //车型C8的第一二页分为左后, 右前,第三四页分为右后、左前;其它车型 第一二页分为左后、左前,第三四页分为右后、右前 + if (curPageLst[0].VehicleModelCode == "C8") + { + //C8 分为左前、右后 一组 右前、左后 一组,以前门为主,前门是右, 单子是右 + if (rightOrLeft == "右") + { + rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("右前")); + leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("左后")); + } + else //左 + { + rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("左前")); + leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains("右后")); + } + } + else + { + leftObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains(rightOrLeft + "后")); + rightObj = materialExtLst.FirstOrDefault(itm => itm.MaterialDescription.Contains(rightOrLeft + "前")); + } + } + + //填充门板装箱单明细 + MenBanPackingRec mbRec = new MenBanPackingRec(); + mbRec.SetId(GuidGenerator.Create()); + mbRec.M100BillId = billObj.Id; + mbRec.KNR = billObj.KNR; //KNR订单号 + mbRec.VIN = billObj.VIN; //底牌号 + mbRec.HostSN = billObj.HostSN.ToString(); //大众顺序号 + mbRec.TopBoxPositionNum = posNum.ToString().PadLeft(2, '0'); //上箱位号 + if (leftObj != null) //右后 + { + mbRec.VehicleModel_DoorPlankCode = leftObj.MaterialMemo; //车型门板代码 + mbRec.TopSAPMaterialNum = leftObj.MaterialNum; //上箱位 SAP物料号 + mbRec.TopMaterialDescription = leftObj.MaterialDescription2.IsNullOrEmpty() ? leftObj.MaterialDescription : leftObj.MaterialDescription2; //上箱位 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲) + } + else + { + if (billObj.VIN == null) + { + mbRec.TopMaterialDescription += "*断号*"; + } + else if (billObj.AssemblyID == null) + { + mbRec.TopMaterialDescription += "*未知总成*"; + } + else + { + mbRec.TopMaterialDescription += "*leftObj为空*"; + } + } + + if (rightObj != null) //右前 + { + mbRec.BelowSAPMaterialNum = rightObj.MaterialNum; //下箱位 SAP物料号 + mbRec.BelowMaterialDescription = rightObj.MaterialDescription2.IsNullOrEmpty() ? rightObj.MaterialDescription : rightObj.MaterialDescription2; //下箱位 物料描述(大小量纲、物料描述字段值同时存在时,优先显示大小量纲) + } + else + { + if (billObj.VIN == null) + { + mbRec.TopMaterialDescription += "*断号*"; + } + else if (billObj.AssemblyID == null) + { + mbRec.BelowMaterialDescription += "*未知总成*"; + } + else + { + mbRec.BelowMaterialDescription += "*rightObj为空*"; + } + } + + if (string.IsNullOrEmpty(mbRec.KNR) == false && mbRec.KNR.Length == 10 && mbRec.KNR.Substring(4, 1) == "7" && string.IsNullOrEmpty(mbRec.VehicleModel_DoorPlankCode) == true) + { + mbRec.VehicleModel_DoorPlankCode += "*预批量*"; + } + + if (!String.IsNullOrEmpty(promMsg)) + { + mbRec.VehicleModel_DoorPlankCode += promMsg; + } + mbObj.Details.Add(mbRec); + } //foreach + + retLst.Add(mbObj); //有用 + return retLst; + } + + private string GetBillNum(long newSN) + { + string newSNStr = newSN.ToString(); + //装箱单号规则 1开头,11位,自增顺序号 + if (newSNStr.Length < 11) + { + return "F" + newSNStr.PadLeft(10, '0'); + } + return newSNStr; + } + + /// + /// 取单据包含的ERP总成列表 + /// + /// + /// + private List GetErpAssemblyListByBill(Guid vehicleAssemblyId) + { + List retLst = new List(); + AssemblyCfgVehicle vobj = _assemblyCfgVehicleRepository.GetAsync(vehicleAssemblyId).GetAwaiter().GetResult(); //取单据对应的整车总成 + if (vobj != null && vobj.AssemblyCfgVehicleChilds != null && vobj.AssemblyCfgVehicleChilds.Count > 0) + { + List vehicleChildLst = vobj.AssemblyCfgVehicleChilds; + foreach (AssemblyCfgVehicleChild vehicleChildItm in vehicleChildLst) + { + AssemblyCfgErp erpObj = _assemblyCfgErpRepository.GetAsync(vehicleChildItm.ErpAssemblyId).GetAwaiter().GetResult(); + if (erpObj != null) + { + retLst.Add(erpObj); + } + } + } + return retLst; + } + + /// + /// 保存门板信息到中间表,中间表是位于FIS库,和WMS中间表结构相同 + /// + /// + private async Task SaveMiddleTable_MB(List input) + { + List targetMainLst = new List(); + List targetDetailLst = new List(); + List cxLst = new List(); + foreach (MenBanPackingList sourceObj in input) + { + FisTB_BILL targetMain = new FisTB_BILL(); + targetMain.BillNum = sourceObj.BillNum; //单据编号 + targetMain.State = 0; + targetMain.BillType = 206; //单据类型 + targetMain.SubBillType = 21004; //单据子类型 + targetMain.BillTime = sourceObj.PrintDate; //单据时间 + targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 + targetMain.DetailQty = 0; //明细数量 + targetMain.CustId = _providerCode; //供应商编号 + //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + //targetMain.DockCode = sourceObj.BillLocation; + + targetMain.GateCode = sourceObj.PartType; //B柱下 + targetMain.GateName = sourceObj.BillSerialNum; //顺序号 + targetMain.DockCode = sourceObj.BillLocation; //左或右 + targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间(预计到达时间) + targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 + targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 + targetMainLst.Add(targetMain); + int idx = 0; + int idx2 = 0; + foreach (MenBanPackingRec sourceRec in sourceObj.Details) + { + idx2++; + if (sourceRec.TopSAPMaterialNum.IsNullOrEmpty() == false) + { + var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.TopSAPMaterialNum && itm.MaterialType == "1"); + idx++; + FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); + targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + targetDetail.LineNum = idx2; //行号 + targetDetail.VinCode = sourceRec.VIN; //VIN码 + targetDetail.SeqNum = idx2.ToString(); //顺序号sourceRec.HostSN.ToString() + targetDetail.PartCode = sourceRec.TopSAPMaterialNum; //物料号 + //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 + targetDetail.ProjectId = ""; //车型 + targetDetail.PlanQty = 1; //计划数量 + targetDetail.State = "0"; //状态 + targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; + targetDetail.FullBarCode = "-"; + targetDetail.VendId = sourceRec.KNR; + //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + targetDetailLst.Add(targetDetail); + if (materialObj != null && materialObj.VehicleModel != null) + { + cxLst.Add(materialObj.VehicleModel); + } + } + if (sourceRec.BelowSAPMaterialNum.IsNullOrEmpty() == false) + { + var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialNum == sourceRec.BelowSAPMaterialNum && itm.MaterialType == "1"); + + idx++; + FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); + targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + targetDetail.VinCode = sourceRec.VIN; //VIN码 + targetDetail.PartCode = sourceRec.BelowSAPMaterialNum; //物料号 + targetDetail.LineNum = (idx2 + 12); //行号 + targetDetail.SeqNum = (idx2 + 12).ToString(); //顺序号sourceRec.HostSN.ToString() + //targetDetail.BarCode = sourceRec.TopBoxPositionNum; //箱码 + targetDetail.ProjectId = ""; //车型 + targetDetail.State = "0"; //状态 + targetDetail.PlanQty = 1; //计划数量 + targetDetail.CustPartCode = materialObj == null ? null : materialObj.RelationKey; + targetDetail.FullBarCode = "-"; + targetDetail.VendId = sourceRec.KNR; + //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + targetDetailLst.Add(targetDetail); + if (materialObj != null && materialObj.VehicleModel != null) + { + cxLst.Add(materialObj.VehicleModel); + } + } + } + //生成车型 + string cxStr = ""; + foreach (string cxObj in cxLst.Distinct()) + { + cxStr += cxObj + "、"; + } + if (cxStr.Length > 0) + { + cxStr = cxStr.Substring(0, cxStr.Length - 1); + } + targetMain.ProjectId = cxStr; //添加车型 + + if (string.IsNullOrEmpty(cxStr)) + { + targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + } + } + + foreach (FisTB_BILL targetMain in targetMainLst) + { + //明细数量 + targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); + } + //保存到数据表 + await _tbBillRepository.InsertManyAsync(targetMainLst, true); + await _tsSortDetailRepository.InsertManyAsync(targetDetailLst, true); + } + #endregion + + + /// + /// 根据生产线获取正常打印单据的起始大众顺序号2 + /// + /// 生产线 + /// 柱护板是1 门板是非1 + /// 柱护板分组类型: 1 门板 2 其它柱护板 3 柱护板 + /// 起始大众顺序号 + [UnitOfWork] + [HttpGet] + [Route("get-print-start-hostsn2")] + public virtual async Task> GetPrintStartHostSN2(string productLine, string isZhuHuBan, string GroupName = null) + { + + int? beginHostSN = null; + try + { + if (isZhuHuBan == "1") //是柱护板, 根据PrintBillNum非空判断是柱护板 + { + var qry = _waitPrintRepository.Where(itm => + itm.BusinessType == (BusinessTypeEnum)(GroupName.TryToIntZero()) + && itm.ProductLine == productLine + && itm.PrintType == PrintTypeEnum.OrderPrint); + + int? minHostSN2 = await qry.MinAsync(itm => itm.HostSN2); + if (minHostSN2 == null) + { + return new ObjectResultDto(true, "未打印表中没有待打印的柱护板数据"); + } + beginHostSN = (await _waitPrintRepository.FirstAsync(itm => itm.HostSN2 == minHostSN2)).HostSN; + } + else //---------------门板----------------------------------------------------------------------------------- + { + var qry = _waitPrintRepository.Where(itm => + itm.BusinessType == BusinessTypeEnum.MenBan + && itm.ProductLine == productLine + && itm.PrintType == PrintTypeEnum.OrderPrint); + + int? minHostSN2 = await qry.MinAsync(itm => itm.HostSN2); + if (minHostSN2 == null) + { + return new ObjectResultDto(true, "未打印表中没有待打印的门板数据"); + } + beginHostSN = (await _waitPrintRepository.FirstAsync(itm => itm.HostSN2 == minHostSN2)).HostSN; + } + return new ObjectResultDto(beginHostSN); + } + catch (Exception ex) + { + ObjectResultDto ret = new ObjectResultDto(); + ret.Status = false; + ret.Message = _errorMessagePrefix + "GetPrintStartHostSN2 执行出错:" + ex.Message; + _logger.LogError(ret.Message); + return ret; + } + } + + /// + /// 根据筛选条件获取分页实体列表 + /// + /// 输入查询条件 + /// 输入分页条件 + /// 返回符合条件的排序分页列表 + [HttpGet] + [UnitOfWork(false)] + [Route("list")] + public virtual async Task> GetListAsync(QueryWaitPrintDto input) + { + _logger.LogDebug(_errorMessagePrefix + "GetListAsync 进入"); + try + { + PagedResultDto ret = new PagedResultDto(); + if (input.BusinessType == BusinessTypeEnum.MenBan) + { + ret = await QueryByConditionAsync(input, (PagedAndSortedBase)input); + } + else if (input.BusinessType == BusinessTypeEnum.OtherZhuHuBan || input.BusinessType == BusinessTypeEnum.ZhuHuBan) + { + ret = await QueryZHBByConditionAsync(input, (PagedAndSortedBase)input); + } + else + { + throw new BusinessException("1001", "请传入正确的BusinessType参数!"); + } + return ret; + } + catch (Exception ex) + { + string errMsg = _errorMessagePrefix + "GetListAsync 执行出错:" + ex.Message; + _logger.LogError(errMsg); + return new PagedResultDto(0, new List()); + } + } + + #region 门板打印 + /// + /// 打印前检查大众顺序号是否断号 + /// + /// + /// 断号时Item不为空 + [UnitOfWork(false)] + [HttpPost] + [Route("check-mb-hostsn-break-num")] + public virtual async Task> CheckMBHostSNBreakNum(MenBanPrintInputDto input) + { + //报文解析时已经校验断号,打印前不用校验 + List retLst = new List(); + return new ListResultDto(retLst); + } + + [UnitOfWork(IsDisabled = true)] + [HttpPost] + [Route("save-menban-report")] + public virtual async Task> SaveMenBanReport(MenBanPrintInputDto input) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + _logger.LogDebug(_errorMessagePrefix + "SaveMenBanReport 进入"); + + MenBanPrintResultDto retObj = new MenBanPrintResultDto(); + ObjectResultDto ret = new ObjectResultDto(retObj); + + using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified)) + { + try + { + List reportMainLst = new List(); + + if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.正常打印) + { + if (input.BeginHostSN != 0 && input.EndHostSN != 0) + { + if (input.BeginHostSN > input.EndHostSN) + { + ret.Message = "止大众顺序号必须大于等于起大众顺序号!"; + ret.Status = false; + return ret; + } + } + ListResultDto tempLst = await GetMBReportDetailList(input); + List billLst = tempLst.Item; + if (tempLst.Status == false) + { + ret.Message = tempLst.Message; + ret.Status = false; + return ret; + } + sw.Stop(); + _logger.LogWarning($"SaveMenBanReport读取数据 - {sw.ElapsedMilliseconds}毫秒"); + sw.Start(); + int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 + + double maxBillNum = 0; + + DateTime printTime = ServerHelper.CurrentDateTime; + + for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) + { + //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 + double maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty); + // 先打印两张:左后左前,再打印两张:右后右前 + List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); + List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); + + //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 + Guid sortId = GuidGenerator.Create(); + foreach (var leftItm in leftLst) + { + leftItm.SortId = sortId; + } + foreach (var rightItm in rightLst) + { + rightItm.SortId = sortId; + } + + reportMainLst.AddRange(rightLst); + reportMainLst.AddRange(leftLst); + } + sw.Stop(); + _logger.LogWarning($"SaveMenBanReport转换数据 - {sw.ElapsedMilliseconds}毫秒"); + sw.Start(); + //1.插入门板打印记录表 + await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true); + sw.Stop(); + _logger.LogWarning($"SaveMenBanReport插入门板打印记录表 - {sw.ElapsedMilliseconds}毫秒"); + sw.Start(); + + //2.调用派格版库存接口 + await SaveMiddleTable_MB(reportMainLst); + sw.Stop(); + _logger.LogWarning($"SaveMenBanReport插入中间表 - {sw.ElapsedMilliseconds}毫秒"); + sw.Start(); + + //3.插入已打印表、删除未打印表 + List alreadyPrintLst = ObjectMapper.Map, List>(billLst); + await _alreadyPrintRepository.InsertManyAsync(alreadyPrintLst); + await _waitPrintRepository.DeleteManyAsync(billLst); + sw.Stop(); + _logger.LogWarning($"插入已打印表、删除未打印表 - {sw.ElapsedMilliseconds}毫秒"); + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 + { + throw new BusinessException("请调用LoadMenBanReport方法!"); + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.补账打印) + { + List billLst = _waitPrintRepository.Where(itm => input.WaitPrintIdList.Contains(itm.Id)).OrderBy(itm => itm.HostSN2).ToList(); + if (billLst.Count == 0) + { + ret.Message = "没有补打的单据,请先选择要补打的单据!"; + ret.Status = false; + return ret; + } + bool allMatch = billLst.All(itm => itm.BillStatus == BillStatusEnum.Match); + if (allMatch) + { + ret.Message = "选择要补打的单据中必须全部是已解析的报文!"; + ret.Status = false; + return ret; + } + + int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数 + + double maxBillNum = 0; + + DateTime printTime = ServerHelper.CurrentDateTime; + + for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) + { + //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右 + double maxSN = 0; + //先打印两张:左后左前,再打印两张:右后右前 + List leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左"); + List rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右"); + + //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右 + Guid sortId = GuidGenerator.Create(); + foreach (var leftItm in leftLst) + { + leftItm.SortId = sortId; + } + foreach (var rightItm in rightLst) + { + rightItm.SortId = sortId; + } + + reportMainLst.AddRange(rightLst); + reportMainLst.AddRange(leftLst); + } + //校验底盘号、零件是否重复打印 + //string checkVinPartRepeatSql = @" + //select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b + // on a.Id = b.MenBanPackingListId + // where a.ReportStatus = 0 + // and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}') + //"; + //foreach (MenBanPackingList reportMainObj in reportMainLst) + //{ + // foreach (MenBanPackingRec reportRecObj in reportMainObj.Details) + // { + // string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.TopSAPMaterialNum); + // string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql(sql1, true); + // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false) + // { + // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.TopSAPMaterialNum}之间重复!"); + // } + + // string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.BelowSAPMaterialNum); + // string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql(sql2, true); + // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false) + // { + // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.BelowSAPMaterialNum}之间重复!"); + // } + // } + //} + + //1.调用派格版库存接口 + await SaveMiddleTable_MB(reportMainLst); + + //2.插入门板打印记录表 + await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true); + + //3.插入已打印表、删除未打印表 + List alreadyPrintLst = ObjectMapper.Map, List>(billLst); + await _alreadyPrintRepository.InsertManyAsync(alreadyPrintLst); + await _waitPrintRepository.DeleteManyAsync(billLst); + + } //补打if + + #region 格式转换 + //实体 转 DTO + List targetLst = ObjectMapper.Map, List>(reportMainLst); + targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList(); + + //补充空行 + foreach (var masterObj in targetLst) + { + int trueCnt = masterObj.Details.Count; + int planCnt = 12; + if (trueCnt > planCnt) + { + throw new Exception($"实际打印行数{trueCnt}超过每页总行数{planCnt}, 底盘起{masterObj.BeginVin}底盘止{masterObj.EndVin}"); + } + int diffCnt = planCnt - trueCnt; + for (int i = 0; i < diffCnt; i++) + { + MenBanPackingRecDto dtlObj = new MenBanPackingRecDto(); + masterObj.Details.Add(dtlObj); + } + } + //子表BillNum赋值, BillNum填充空格 + foreach (var masterObj in targetLst) + { + masterObj.BillNum = GetTrueString(masterObj.BillNum); + int sn = 1; + foreach (var detailObj in masterObj.Details) + { + detailObj.BillNum = masterObj.BillNum; + detailObj.KNR = GetTrueString(detailObj.KNR); + detailObj.sn = sn++; + detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位 + } + } + //返回结果格式转换 + foreach (var masterObj in targetLst) + { + foreach (var detailObj in masterObj.Details) + { + retObj.DetailList.Add(detailObj); + } + masterObj.Details = null; + retObj.MasterList.Add(masterObj); + } + #endregion + + + + await uow.CompleteAsync(); + ret.Status = true; + return ret; + } + catch (Exception ex) + { + await uow.RollbackAsync(); + string errorMsg = _errorMessagePrefix + "SaveMenBanReport 执行出错:" + ex.Message; + _logger.LogError(errorMsg); + ret.Status = false; + ret.Message = ex.Message; + return ret; + } + } //事务 + } + + private static string GetTrueString(string str) + { + return str == null ? " " : str.Trim(); ; + } + + #endregion + + #region 柱护板打印 + /// + /// 打印前检查大众顺序号是否断号 + /// + /// + /// 是否柱护板 + /// 断号时Item不为空 + [UnitOfWork(false)] + [HttpPost] + [Route("check-zhb-hostsn-break-num")] + public virtual async Task> CheckZHBHostSNBreakNum(ZhuHuBanPrintInputDto input) + { + List retLst = new List(); + return new ListResultDto(retLst); + } + + #endregion + } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService_ZHB.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService_ZHB.cs new file mode 100644 index 0000000..0e07044 --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/PrintTable/WaitPrintAppService_ZHB.cs @@ -0,0 +1,1096 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Uow; +using WY.NewJit.Common; +using WY.NewJit.Commons; +using WY.NewJit.EntityFrameworkCore; +using WY.NewJit.Extends; +using WY.NewJit.Extends.PaiGe; +using WY.NewJit.Extends.PaiGe.WMS; +using WY.NewJit.MsgBaseData; +using WY.NewJit.MsgCheck; +using WY.NewJit.PrintTable.Dtos; + +namespace WY.NewJit.PrintTable +{ + [Route("api/newjit/wait-print")] + public partial class WaitPrintAppService : ApplicationService, IWaitPrintAppService + { + private static Dictionary> _m100PartDicCache; + + #region 柱护板装箱单 + //private void DelOrScrapWMSInterface(string billNum) + //{ + // //重新打印时,库存系统接口如果存在已发运的正常打印单据,则不允许重新打印;如果存在未发运的正常打印单据则删除该单据 + // string oldBillNum = billNum; + // TB_BILL oldBillObj = _wmsDapperRepository.GetSingleBySql($"select top 1 * from TB_BILL where BillNum = '{oldBillNum}'", true); + // if (oldBillObj != null) + // { + // if (oldBillObj.State == 0) + // { + // string sqlMain = $"delete from TS_SORT_DETAIL where BillNum = '{oldBillNum}'"; + // _wmsDapperRepository.ExecuteSql(sqlMain, null, true); + + // string sqlDetail = $"delete from TB_BILL where BillNum = '{oldBillNum}'"; + // _wmsDapperRepository.ExecuteSql(sqlDetail, null, true); + // } + // else + // { + // throw new BusinessException("1001", $"该单据{oldBillNum}在库存系统中已经排序或发运,不允许删除!"); + // } + // } + //} + + + /// + /// 打印柱护板(3*8 左右合并成一个单元格)A上C上 + /// + /// + /// + /// + /// + /// + /// + /// + /// + private List DoZHBPrint_3x8_LRMerge(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) + { + List retLst = new List(); + + //填充柱护板装箱单主实体 + ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); + zhbObj.SetId(GuidGenerator.Create()); + + zhbObj.BillNum = GetBillNum(maxBillNum); + zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + + zhbObj.BillLocation = null; //右或左或空 + zhbObj.ProviderCode = _providerCode; //供应商厂家代码 + zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 + //int rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish); + int rongLiang = billLst.Count(); + zhbObj.Capacity = $"{rongLiang * 2} + {rongLiang * 2}"; //器具容量 + zhbObj.PrintDate = printTime; //打印日期 + zhbObj.PrintType = input.PrintType; + zhbObj.ProductLine = input.ProductLine; + + var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); + if (tempLst.Count > 0) + { + zhbObj.BeginVin = tempLst[0].VIN; ; + zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; + zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); + zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); + } + zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + + //取当前页的详细信息 + foreach (WaitPrint billObj in billLst) + { + ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + + if (_m100PartDicCache[billObj.M100Id] != null && _m100PartDicCache[billObj.M100Id].Count > 0) + { + //取柱护板-A上C上 + if (zhbPartType == "A上C上") + { + //左、右两个单元格合并,合并后一页有24个单元格(3行*8列),一页包含24辆车、48个A上柱护板、48个C上柱护板 + MaterialExt materialObj = GetZhuHuBanByType("A柱上", rightOrLeft + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + + MaterialExt materialObj2 = GetZhuHuBanByType("C柱上", rightOrLeft + "侧", billObj); + if (materialObj2 != null) + { + zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; + zhbRec.PartCode2 = materialObj2.RelationKey; + } + + } //A上C上 + } + zhbObj.Details.Add(zhbRec); + } //foreach + retLst.Add(zhbObj); + return retLst; + } //DoZHBPrint + + /// + /// 打印柱护板(3*8 分左右)A柱下A中 + /// + /// + /// + /// + /// + /// + /// + /// + /// + private List DoZHBPrint_3x8_LR(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) + { + List retLst = new List(); + + //填充柱护板装箱单主实体 + ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); + zhbObj.SetId(GuidGenerator.Create()); + + long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + zhbObj.BillNum = GetBillNum(maxBillNum2); + zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + + zhbObj.BillLocation = rightOrLeft; //右或左或空 + zhbObj.ProviderCode = _providerCode; //供应商厂家代码 + zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 + //string rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); + string rongLiang = billLst.Count().ToString(); + zhbObj.Capacity = rongLiang + "+" + rongLiang; //器具容量 + zhbObj.PrintDate = printTime; //打印日期 + zhbObj.PrintType = input.PrintType; + zhbObj.ProductLine = input.ProductLine; + var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); + if (tempLst.Count > 0) + { + zhbObj.BeginVin = tempLst[0].VIN; + zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; + zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); + zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); + } + zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + + + //取当前页的详细信息 + foreach (WaitPrint billObj in billLst) + { + ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + if (_m100PartDicCache[billObj.M100Id] != null && _m100PartDicCache[billObj.M100Id].Count > 0) + { + //取A柱下、A中 + if (zhbPartType == "A柱下A中") + { + //每页3行*8列,一次打印24辆车,分两页,一张显示左A柱下A中、一张显示右; + //紧邻两行,上行显示A下、下行显示A中。A下目前只有一种颜色 + MaterialExt materialObj = GetZhuHuBanByType("A柱下", rightOrLeft + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + + MaterialExt materialObj2 = GetZhuHuBanByType("A柱中", rightOrLeft + "侧", billObj); + if (materialObj2 != null) + { + zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; + zhbRec.PartCode2 = materialObj2.RelationKey; + } + + }//if A柱下A中 + } + zhbObj.Details.Add(zhbRec); + } //foreach + retLst.Add(zhbObj); + return retLst; + } //DoZHBPrint + + /// + /// 打印柱护板(4*6 分左右)B柱上;B柱下;后轮上装饰板 + /// + /// + /// + /// + /// + /// + /// + /// + /// + private List DoZHBPrint_4x6_LR(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft) + { + List retLst = new List(); + + //填充柱护板装箱单主实体 + ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); + zhbObj.SetId(GuidGenerator.Create()); + + long maxBillNum2 = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + zhbObj.BillNum = GetBillNum(maxBillNum2); + zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + + zhbObj.BillLocation = rightOrLeft; //右或左 + zhbObj.ProviderCode = _providerCode; //供应商厂家代码 + zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 + if (zhbPartType == "后轮上装饰板") + { + //string rongLiang = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); + string rongLiang = billLst.Count().ToString(); + zhbObj.Capacity = rongLiang + "+" + rongLiang; + } + else + { + //zhbObj.Capacity = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish).ToString(); //器具容量 + zhbObj.Capacity = billLst.Count().ToString(); //器具容量 + } + zhbObj.PrintDate = printTime; //打印日期 + zhbObj.PrintType = input.PrintType; + zhbObj.ProductLine = input.ProductLine; + var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); + if (tempLst.Count > 0) + { + zhbObj.BeginVin = tempLst[0].VIN; + zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; + zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); + zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); + } + zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + + + //取当前页的详细信息 + foreach (WaitPrint billObj in billLst) + { + ZhuHuBanPackingRec zhbRec; + if (_m100PartDicCache[billObj.M100Id] != null && _m100PartDicCache[billObj.M100Id].Count > 0) + { + if (zhbPartType == "B柱上") + { + zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + + //B柱上:左右柱护板分别打印在不同的两页,每页4行*6列 + MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, rightOrLeft + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + zhbObj.Details.Add(zhbRec); + } + else if (zhbPartType == "B柱下") + { + zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + + //B柱下:左右柱护板分别打印在不同的两页,每页4行*6列 + MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, rightOrLeft + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + zhbObj.Details.Add(zhbRec); + } + else if (zhbPartType == "后轮上装饰板") + { + zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + //后轮上装饰板:显示后轮; 左右柱护板分别打印在不同的两页,每页4行*6列 + MaterialExt materialObj = GetZhuHuBanByType("后轮", rightOrLeft + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + + MaterialExt materialObj2 = GetZhuHuBanByType("上装饰板", rightOrLeft + "侧", billObj); + if (materialObj2 != null) + { + zhbRec.MaterialDescription2 = materialObj2.MaterialDescription; + zhbRec.PartCode2 = materialObj2.RelationKey; + } + zhbObj.Details.Add(zhbRec); + + } //if 后轮上装饰板 + } + else + { + //没有柱护板字典时,用空白单元格填充(之前不填充,造成后面空行) + zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + zhbObj.Details.Add(zhbRec); + } + + } //foreach + retLst.Add(zhbObj); + return retLst; + } //DoZHBPrint + + /// + /// 打印柱护板(4*3 左右相邻)D柱 + /// + /// + /// + /// + /// + /// + /// + /// + /// + private List DoZHBPrint_4x3(string zhbPartType, ZhuHuBanPrintInputDto input, long maxBillNum, double maxSN, DateTime printTime, List billLst, string rightOrLeft = null) + { + List retLst = new List(); + + //填充柱护板装箱单主实体 + ZhuHuBanPackingList zhbObj = new ZhuHuBanPackingList(); + zhbObj.SetId(GuidGenerator.Create()); + + long maxBillNum2 = maxBillNum; //_sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + zhbObj.BillNum = GetBillNum(maxBillNum2); + zhbObj.BillSerialNum = maxSN.ToString().PadLeft(2, '0'); + + zhbObj.BillLocation = null; //右或左 + zhbObj.ProviderCode = _providerCode; //供应商厂家代码 + zhbObj.PartType = zhbPartType; //零件类型:例如 B柱下 + //int capacity = billLst.Count(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish); + int capacity = billLst.Count(); + zhbObj.Capacity = $"{capacity}+{capacity}"; //器具容量 + zhbObj.PrintDate = printTime; //打印日期 + zhbObj.PrintType = input.PrintType; + zhbObj.ProductLine = input.ProductLine; + var tempLst = billLst.Where(itm => string.IsNullOrEmpty(itm.VIN) == false).OrderBy(itm => itm.OnlineTime).ThenBy(itm => itm.HostSN).ToList(); + if (tempLst.Count > 0) + { + zhbObj.BeginVin = tempLst[0].VIN; + zhbObj.EndVin = tempLst[tempLst.Count - 1].VIN; + zhbObj.BeginHostSN = tempLst[0].HostSN.ToString(); + zhbObj.EndHostSN = tempLst[tempLst.Count - 1].HostSN.ToString(); + } + zhbObj.MinOnlineTime = billLst.Min(itm => itm.OnlineTime); //取最早上线时间,库存接口用 + + //取当前页的详细信息 + foreach (WaitPrint billObj in billLst) + { + string[] leftRightArr = new string[2] { "左", "右" }; + if (rightOrLeft == "左") + { + leftRightArr = new string[1] { "左" }; + } + else if (rightOrLeft == "右") + { + leftRightArr = new string[1] { "右" }; + } + foreach (string leftRightStr in leftRightArr) + { + ZhuHuBanPackingRec zhbRec = new ZhuHuBanPackingRec(); + zhbRec.SetId(GuidGenerator.Create()); + zhbRec.M100BillId = billObj.Id; + zhbRec.KNR = billObj.KNR; + zhbRec.VIN = billObj.VIN; + zhbRec.HostSN = billObj.HostSN; + if (_m100PartDicCache[billObj.M100Id] != null && _m100PartDicCache[billObj.M100Id].Count > 0) + { + if (zhbPartType == "D柱") + { + //D柱:每页4*6个单元格,相邻列分为左右两列,分别显示D柱左、D柱右。 右列的右侧留空格=》4*3套 + MaterialExt materialObj = GetZhuHuBanByType(zhbPartType, leftRightStr + "侧", billObj); + if (materialObj != null) + { + zhbRec.MaterialDescription = materialObj.MaterialDescription; + zhbRec.PartCode = materialObj.RelationKey; + } + } //if D柱 + } + zhbObj.Details.Add(zhbRec); + } //二级foreach + } + retLst.Add(zhbObj); + return retLst; + } //DoZHBPrint + + /// + /// 打印柱护板装箱单时调用库存系统接口 + /// + /// + //private void CallWMSInterface_ZHB(List input) + //{ + // List targetMainLst = new List(); + // List targetDetailLst = new List(); + + // List cxLst = new List(); + // foreach (ZhuHuBanPackingList sourceObj in input) + // { + // TB_BILL targetMain = new TB_BILL(); + // targetMain.BillNum = sourceObj.BillNum; //单据编号 + // targetMain.State = 0; + // targetMain.BillType = 206; //单据类型 + // targetMain.SubBillType = 20110; //单据子类型 + // targetMain.BillTime = sourceObj.PrintDate; //单据时间 + // targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 + // targetMain.DetailQty = 0; //明细数量 + // targetMain.CustId = _providerCode; //供应商编号 + // //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + + // targetMain.GateName = sourceObj.BillSerialNum; //顺序号 + // targetMain.GateCode = sourceObj.PartType; //B柱下 + // targetMain.DockCode = sourceObj.BillLocation; //左或右 + // targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间 + // targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 + // targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 + + // targetMainLst.Add(targetMain); + // int idx = 0; + // int barCode = 0; + // foreach (ZhuHuBanPackingRec sourceRec in sourceObj.Details) + // { + // barCode++; + // if (sourceRec.PartCode.IsNullOrEmpty() == false) + // { + // idx++; + // //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode && itm.MaterialType == "2"); + // var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode); + // TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); + // targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + // targetDetail.VinCode = sourceRec.VIN; //VIN码 + // targetDetail.PartCode = materialObj == null ? sourceRec.PartCode : materialObj.MaterialNum; //SAP物料号 + // targetDetail.LineNum = idx; //行号 + // targetDetail.SeqNum = idx.ToString(); //顺序号 + // targetDetail.ProjectId = ""; //车型 + // targetDetail.State = "0"; //状态 + // //targetDetail.BarCode = barCode.ToString(); //箱码 + // targetDetail.PlanQty = 1; //计划数量 + // targetDetail.CustPartCode = sourceRec.PartCode; //客户零件号 + // targetDetail.FullBarCode = null; + // targetDetail.VendId = sourceRec.KNR; + + // //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + + // targetDetailLst.Add(targetDetail); + // if (materialObj != null && materialObj.VehicleModel != null) + // { + // cxLst.Add(materialObj.VehicleModel); + // } + + // } + // if (sourceRec.PartCode2.IsNullOrEmpty() == false) + // { + // idx++; + // //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2 && itm.MaterialType == "2"); + // var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2); + + // TS_SORT_DETAIL targetDetail = new TS_SORT_DETAIL(); + // targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + // targetDetail.VinCode = sourceRec.VIN; //VIN码 + // targetDetail.PartCode = materialObj == null ? sourceRec.PartCode2 : materialObj.MaterialNum; //SAP物料号 + // targetDetail.LineNum = idx; //行号 + // targetDetail.SeqNum = idx.ToString(); //顺序号 + // targetDetail.ProjectId = ""; //车型 + // targetDetail.State = "0"; //状态 + // //targetDetail.BarCode = barCode.ToString(); //箱码 + // targetDetail.PlanQty = 1; //计划数量 + // targetDetail.CustPartCode = sourceRec.PartCode2; //客户零件号 + // targetDetail.FullBarCode = null; + // targetDetail.VendId = sourceRec.KNR; + // //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + + // targetDetailLst.Add(targetDetail); + // if (materialObj != null && materialObj.VehicleModel != null) + // { + // cxLst.Add(materialObj.VehicleModel); + // } + // } + // } + // //生成车型 + // string cxStr = ""; + // foreach (string cxObj in cxLst.Distinct()) + // { + // cxStr += cxObj + "、"; + // } + // if (cxStr.Length > 0) + // { + // cxStr = cxStr.Substring(0, cxStr.Length - 1); + // } + // targetMain.ProjectId = cxStr; //添加车型 + + // if (string.IsNullOrEmpty(cxStr)) + // { + // targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + // } + // } + // foreach (TB_BILL targetMain in targetMainLst) + // { + // //明细数量 + // targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); + + // int cnt = InsertOrUpdateWMSMain(targetMain); + // if (cnt == 0) + // { + // throw new Exception("插入或更新库存系统接口表记录数为零!"); + // } + // } + // foreach (TS_SORT_DETAIL targetDetail in targetDetailLst) + // { + // int cnt = InsertOrUpdateWMSDetail(targetDetail); + // if (cnt == 0) + // { + // throw new Exception("插入或更新库存系统接口表记录数为零!"); + // } + // } + //} + + /// + /// 查找M100结算件中是否包含指定类型(如D柱)的柱护板 + /// + /// + /// + /// + /// + private MaterialExt GetZhuHuBanByType(string p_materialType2, string p_materialType3, WaitPrint p_waitPrint) + { + List keyLst = _zhbCacheList.Where(itm => itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3).Select(itm => itm.RelationKey).ToList(); //取A柱上物料对应的结算件编码 + foreach (BillM100Part billObj in _m100PartDicCache[p_waitPrint.M100Id]) + { + if (keyLst.Contains(billObj.PartCode)) + { + //MaterialExt materialObj = _materialExtRepository.FirstOrDefault(itm => itm.MaterialType == "2" && itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3 && itm.RelationKey == billObj.PartCode); + MaterialExt materialObj = _zhbCacheList.FirstOrDefault(itm => itm.MaterialType2 == p_materialType2 && itm.MaterialType3 == p_materialType3 && itm.RelationKey == billObj.PartCode); + if (materialObj != null) + { + return materialObj; + } + } + } + return null; + } + #endregion + + + #region 柱护板私有方法 + /// + /// 保存柱护板信息到中间表,中间表是位于FIS库,和WMS中间表结构相同 + /// + /// + private async Task SaveMiddleTable_ZHB(List input) + { + List targetMainLst = new List(); + List targetDetailLst = new List(); + + List cxLst = new List(); + foreach (ZhuHuBanPackingList sourceObj in input) + { + FisTB_BILL targetMain = new FisTB_BILL(); + targetMain.BillNum = sourceObj.BillNum; //单据编号 + targetMain.State = 0; + targetMain.BillType = 206; //单据类型 + targetMain.SubBillType = 20110; //单据子类型 + targetMain.BillTime = sourceObj.PrintDate; //单据时间 + targetMain.OperName = sourceObj.CreatorId.ToString(); //操作员 + targetMain.DetailQty = 0; //明细数量 + targetMain.CustId = _providerCode; //供应商编号 + //targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + + targetMain.GateName = sourceObj.BillSerialNum; //顺序号 + targetMain.GateCode = sourceObj.PartType; //B柱下 + targetMain.DockCode = sourceObj.BillLocation; //左或右 + targetMain.Remark = sourceObj.MinOnlineTime == null ? null : ((DateTime)sourceObj.MinOnlineTime).ToString("yyyy-MM-dd HH:mm"); //最早上线时间 + targetMain.TransportType = sourceObj.BillSerialNum; //顺序号 + targetMain.SourceBillNum3 = sourceObj.ProductLine; //2022-10-13加生产线 + targetMainLst.Add(targetMain); + int idx = 0; + int barCode = 0; + foreach (ZhuHuBanPackingRec sourceRec in sourceObj.Details) + { + barCode++; + if (sourceRec.PartCode.IsNullOrEmpty() == false) + { + idx++; + //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode && itm.MaterialType == "2"); + var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode); + FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); + targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + targetDetail.VinCode = sourceRec.VIN; //VIN码 + targetDetail.PartCode = materialObj == null ? sourceRec.PartCode : materialObj.MaterialNum; //SAP物料号 + targetDetail.LineNum = idx; //行号 + targetDetail.SeqNum = idx.ToString(); //顺序号 + targetDetail.ProjectId = ""; //车型 + targetDetail.State = "0"; //状态 + //targetDetail.BarCode = barCode.ToString(); //箱码 + targetDetail.PlanQty = 1; //计划数量 + targetDetail.CustPartCode = sourceRec.PartCode; //客户零件号 + targetDetail.FullBarCode = "-"; + targetDetail.VendId = sourceRec.KNR; + //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + targetDetailLst.Add(targetDetail); + if (materialObj != null && materialObj.VehicleModel != null) + { + cxLst.Add(materialObj.VehicleModel); + } + + } + if (sourceRec.PartCode2.IsNullOrEmpty() == false) + { + idx++; + //var materialObj = _materialExtRepository.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2 && itm.MaterialType == "2"); + var materialObj = _zhbCacheList.FirstOrDefault(itm => itm.RelationKey == sourceRec.PartCode2); + + FisTS_SORT_DETAIL targetDetail = new FisTS_SORT_DETAIL(); + targetDetail.BillNum = sourceObj.BillNum; //单据编号 通过该字段和主表弱连接 + targetDetail.VinCode = sourceRec.VIN; //VIN码 + targetDetail.PartCode = materialObj == null ? sourceRec.PartCode2 : materialObj.MaterialNum; //SAP物料号 + targetDetail.LineNum = idx; //行号 + targetDetail.SeqNum = idx.ToString(); //顺序号 + targetDetail.ProjectId = ""; //车型 + targetDetail.State = "0"; //状态 + //targetDetail.BarCode = barCode.ToString(); //箱码 + targetDetail.PlanQty = 1; //计划数量 + targetDetail.CustPartCode = sourceRec.PartCode2; //客户零件号 + targetDetail.FullBarCode = "-"; + targetDetail.VendId = sourceRec.KNR; + //targetDetail.BarCode = sourceRec.HostSN.ToString(); //2022-10-13加 + targetDetailLst.Add(targetDetail); + if (materialObj != null && materialObj.VehicleModel != null) + { + cxLst.Add(materialObj.VehicleModel); + } + } + } + //生成车型 + string cxStr = ""; + foreach (string cxObj in cxLst.Distinct()) + { + cxStr += cxObj + "、"; + } + if (cxStr.Length > 0) + { + cxStr = cxStr.Substring(0, cxStr.Length - 1); + } + targetMain.ProjectId = cxStr; //添加车型 + + if (string.IsNullOrEmpty(cxStr)) + { + targetMain.ProjectId = sourceObj.PartType == null ? null : sourceObj.PartType.Replace(" DP", ""); //添加车型 + } + } + foreach (FisTB_BILL targetMain in targetMainLst) + { + //明细数量 + targetMain.DetailQty = targetDetailLst.Where(p => p.BillNum == targetMain.BillNum).Count(); + } + //保存到数据表 + //await _tbBillRepository.InsertManyAsync(targetMainLst, true); + //await _tsSortDetailRepository.InsertManyAsync(targetDetailLst, true); + await _tbBillRepository.InsertManyAsync(targetMainLst); + await _tsSortDetailRepository.InsertManyAsync(targetDetailLst); + + + + + } + + /// + /// 根据条件取用于打印的柱护板单据列表 + /// + /// + /// + /// + private async Task> GetZHBReportDetailList(ZhuHuBanPrintInputDto input, bool isFillBreakNum = false) + { + List billLst = new List(); + ListResultDto ret = new ListResultDto(billLst); + + int printBillCnt = 0; + if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.正常打印) + { + if ((input.BeginHostSN % 10000) > 1999) + { + throw new Exception("起始大众顺序号不能大于1999!"); + } + if (input.BeginHostSN > input.EndHostSN) + { + throw new Exception("起始大众顺序号不能大于止大众顺序号!"); + } + + printBillCnt = input.EndHostSN - input.BeginHostSN + 1; + + BusinessTypeEnum busiType; + if (input.GroupName == "2") + { + busiType = BusinessTypeEnum.OtherZhuHuBan; + } + else if (input.GroupName == "3") + { + busiType = BusinessTypeEnum.ZhuHuBan; + } + else + { + throw new Exception("input.GroupName参数值必须是2或3!"); + } + + int minHostSN2 = await _waitPrintRepository.Where(itm => + itm.BusinessType == busiType + && itm.ProductLine == input.ProductLine //生产线 + && itm.PrintType == PrintTypeEnum.OrderPrint //顺序打印 + && itm.HostSN == input.BeginHostSN + ).MinAsync(itm => itm.HostSN2); + + var firstObj = await _waitPrintRepository.FirstOrDefaultAsync(itm => itm.HostSN2 == minHostSN2); + if (firstObj == null) + { + throw new Exception("没有找到起始大众顺序号!!"); + } + + billLst = await _waitPrintRepository.Where(itm => + itm.BusinessType == busiType + && itm.ProductLine == input.ProductLine //生产线 + && itm.PrintType == PrintTypeEnum.OrderPrint //顺序打印 + && itm.HostSN2 >= minHostSN2) + .OrderBy(itm => itm.HostSN2) + .Take(printBillCnt).ToListAsync(); + + bool hasData = billLst.Any(); + if (hasData == false) + { + ret.Message = $"输入的起始大众顺序号没有对应的数据。生产线:{input.ProductLine},起止顺序号:{input.BeginHostSN} - {input.EndHostSN}"; + ret.Status = false; + return ret; + } + + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.补账打印) + { + } + ret.Status = true; + ret.Item = billLst; + return ret; + } + + #endregion + + #region 柱护板公有方法 + /// + /// 保存柱护板装箱单报表 + /// + [UnitOfWork] + [HttpPost] + [Route("save-group-zhuhuban-report")] + public virtual async Task>> SaveGroupZhuHuBanReport(ZhuHuBanPrintInputDto input) + { + _logger.LogDebug(_errorMessagePrefix + "SaveGroupZhuHuBanReport 进入"); + + List retLst = new List(); + ObjectResultDto> ret = new ObjectResultDto>(); + ret.Status = false; + using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified)) + { + try + { + List reportMainLst = new List(); + List forWMSLst = new List(); + + if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.正常打印) + { + if (input.BeginHostSN > input.EndHostSN) + { + ret.Message = "起大众顺序号不能大于止大众顺序号!"; + ret.Status = false; + return ret; + } + + ListResultDto tempLst = await GetZHBReportDetailList(input, true); //------------------- + List billLst = tempLst.Item; + if (tempLst.Status == false) + { + ret.Message = tempLst.Message; + ret.Status = false; + return ret; + } + if (billLst.Count > 24) + { + ret.Message = "打印柱护板单据的数量不能大于24!"; + ret.Status = false; + return ret; + } + //加载柱护板缓存列表 + _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + //加载M100零件缓存 + _m100PartDicCache = await _m100DomainService.GetM100PartDic(billLst.Select(itm => itm.M100Id).ToList()); + + long maxBillNum = 0; //子方法内部赋值 + DateTime printTime = ServerHelper.CurrentDateTime; + double maxSN; + + //获取当前打印柱护板的零件类型 + var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); + foreach (var partType in partTypes) + { + switch (partType.PartType) + { + case "A上C上": + //A上C上 + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + { + acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + } + reportMainLst.AddRange(acLst); + forWMSLst.AddRange(acLstOnlyWMSUse); + break; + case "A柱下A中": + //A柱下,A中 + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(aaLst1); + reportMainLst.AddRange(aaLst2); + forWMSLst.AddRange(aaLst1); + forWMSLst.AddRange(aaLst2); + break; + case "B柱上": + //B柱上 + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(bUpLst1); + reportMainLst.AddRange(bUpLst2); + forWMSLst.AddRange(bUpLst1); + forWMSLst.AddRange(bUpLst2); + break; + case "B柱下": + //B柱下 + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(bDownLst1); + reportMainLst.AddRange(bDownLst2); + forWMSLst.AddRange(bDownLst1); + forWMSLst.AddRange(bDownLst2); + break; + case "D柱": + //D柱 + var lst1 = billLst.Take(12).ToList(); + var lst2 = billLst.Skip(12).ToList(); + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); //左用于打印 + List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); //左右用于库存接口 + + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + reportMainLst.AddRange(dLst1); + reportMainLst.AddRange(dLst2); + forWMSLst.AddRange(forWMSLst1); + forWMSLst.AddRange(forWMSLst2); + break; + case "后轮上装饰板": + //后轮,上装饰板 + maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(hsLst1); + reportMainLst.AddRange(hsLst2); + forWMSLst.AddRange(hsLst1); + forWMSLst.AddRange(hsLst2); + break; + } + } + #region 1. 调用库存接口 + await SaveMiddleTable_ZHB(forWMSLst); + #endregion + + //2. 插入柱护板打印记录表 + Guid sortId = GuidGenerator.Create(); + foreach (var srcObj2 in reportMainLst) + { + srcObj2.SortId = sortId; //一次打印SortId相同 + } + await _zhuHuBanPackingListRepository.InsertManyAsync(reportMainLst, true); + + //3.插入已打印表、删除未打印表 + List alreadyPrintLst = ObjectMapper.Map, List>(billLst); + await _alreadyPrintRepository.InsertManyAsync(alreadyPrintLst); + await _waitPrintRepository.DeleteManyAsync(billLst); + + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据 + { + throw new BusinessException("请调用LoadZhuHuBanReport方法!"); + } + else if (input.PrintType == WY.NewJit.Extends.PaiGe.PrintTypeEnum.补账打印) + { + if (input.WaitPrintIdList.Count > 24) + { + throw new BusinessException("1001", $"选中的柱护板补打不能超过24个底盘!"); + } + + List billLst = _waitPrintRepository.GetListAsync(itm => input.WaitPrintIdList.Contains(itm.Id), true).GetAwaiter().GetResult(); + if (billLst.Count == 0) + { + ret.Message = "没有补打的柱护板,请先选择要补打的柱护板!"; + ret.Status = false; + return ret; + } + billLst = billLst.OrderBy(itm => itm.HostSN2).ToList(); + + //加载柱护板缓存列表 + _zhbCacheList = _materialExtRepository.Where(itm => itm.MaterialType == "2").ToList(); //取柱护板零件 + + long maxBillNum = 0; //全局唯一装箱单号 + DateTime printTime = ServerHelper.CurrentDateTime; + double maxSN; //右上角顺序号01-99 + + //获取当前打印柱护板的零件类型 + var partTypes = await _printTemplateConfigurationRepository.GetListAsync(r => r.GroupName == input.GroupName); + foreach (var partType in partTypes) + { + switch (partType.PartType) + { + case "A上C上": + //A上C上 + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A上C上"); + List acLst = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "左"); + List acLstOnlyWMSUse = DoZHBPrint_3x8_LRMerge("A上C上", input, maxBillNum, maxSN, printTime, billLst, "右"); //仅库存系统接口使用,打印记录表不保存 + if (acLstOnlyWMSUse.Count > 0 && acLst.Count > 0) + { + acLstOnlyWMSUse[0].Details.InsertRange(0, acLst[0].Details); //右插入左 + } + reportMainLst.AddRange(acLst); + forWMSLst.AddRange(acLstOnlyWMSUse); + break; + case "A柱下A中": + //A柱下,A中 + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "A柱下A中"); + + List aaLst1 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "左"); + List aaLst2 = DoZHBPrint_3x8_LR("A柱下A中", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(aaLst1); + reportMainLst.AddRange(aaLst2); + forWMSLst.AddRange(aaLst1); + forWMSLst.AddRange(aaLst2); + break; + case "B柱上": + + //B柱上 + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱上"); + List bUpLst1 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "左"); + List bUpLst2 = DoZHBPrint_4x6_LR("B柱上", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(bUpLst1); + reportMainLst.AddRange(bUpLst2); + forWMSLst.AddRange(bUpLst1); + forWMSLst.AddRange(bUpLst2); + break; + case "B柱下": + //B柱下 + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "B柱下"); + + List bDownLst1 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "左"); + List bDownLst2 = DoZHBPrint_4x6_LR("B柱下", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(bDownLst1); + reportMainLst.AddRange(bDownLst2); + forWMSLst.AddRange(bDownLst1); + forWMSLst.AddRange(bDownLst2); + break; + case "D柱": + //D柱 + var lst1 = billLst.Take(12).ToList(); + var lst2 = billLst.Skip(12).ToList(); + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + List dLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1, "左"); + List forWMSLst1 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst1); + + maxBillNum = _sequenceDomainService.GetSequence(SequenceTypeEnum.门板及柱护板装箱单号); + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "D柱"); + List dLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2, "左"); + List forWMSLst2 = DoZHBPrint_4x3("D柱", input, maxBillNum, maxSN, printTime, lst2); + reportMainLst.AddRange(dLst1); + reportMainLst.AddRange(dLst2); + forWMSLst.AddRange(forWMSLst1); + forWMSLst.AddRange(forWMSLst2); + + break; + case "后轮上装饰板": + //后轮,上装饰板 + maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.柱护板, input.ProductLine, "后轮上装饰板"); + List hsLst1 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "左"); + List hsLst2 = DoZHBPrint_4x6_LR("后轮上装饰板", input, maxBillNum, maxSN, printTime, billLst, "右"); + reportMainLst.AddRange(hsLst1); + reportMainLst.AddRange(hsLst2); + forWMSLst.AddRange(hsLst1); + forWMSLst.AddRange(hsLst2); + + break; + } + } + #region 调用库存接口 + await SaveMiddleTable_ZHB(forWMSLst); + #endregion + + //插入柱护板打印记录表 + Guid sortId = GuidGenerator.Create(); + foreach (var srcObj2 in reportMainLst) + { + srcObj2.SortId = sortId; //一次打印SortId相同 + } + await _zhuHuBanPackingListRepository.InsertManyAsync(reportMainLst, true); + + //3.插入已打印表、删除未打印表 + List alreadyPrintLst = ObjectMapper.Map, List>(billLst); + await _alreadyPrintRepository.InsertManyAsync(alreadyPrintLst); + await _waitPrintRepository.DeleteManyAsync(billLst); + } //补打if + + await uow.CompleteAsync(); + ret.Status = true; + ret.Item = retLst; + return ret; + } + catch (Exception ex) + { + await uow.RollbackAsync(); + string errorMsg = _errorMessagePrefix + "SaveGroupZhuHuBanReport 执行出错:" + ex.Message; + _logger.LogError(errorMsg); + //throw new BusinessException("1001", errorMsg); + ret.Status = false; + ret.Message = ex.Message; + return ret; + } + + } //事务 + } + + #endregion + + } +} diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/SwaggerGroupConsts.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/SwaggerGroupConsts.cs index 59869e5..991c7cf 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/SwaggerGroupConsts.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/SwaggerGroupConsts.cs @@ -12,6 +12,7 @@ namespace WY.NewJit.Common public const string 报文解析及校验 = "报文解析及校验"; public const string 基础数据 = "基础数据"; public const string 扩展 = "扩展"; + public const string 报文打印 = "报文打印"; } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Extends/PaiGe/PrintTypeEnum.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Extends/PaiGe/PrintTypeEnum.cs index 4d82160..5ed80c0 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Extends/PaiGe/PrintTypeEnum.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Extends/PaiGe/PrintTypeEnum.cs @@ -7,8 +7,8 @@ namespace WY.NewJit.Extends.PaiGe public enum PrintTypeEnum { 正常打印, - 重新打印, - 补打 + 补账打印, + 重新打印 } public enum ReportStatusEnum diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/ZHBPrintStatus.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/ZHBPrintStatus.cs index 9bdd7ef..1e703a1 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/ZHBPrintStatus.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/ZHBPrintStatus.cs @@ -10,31 +10,31 @@ namespace WY.NewJit.MsgCheck /// ///打印模板状态表 /// - public class ZHBPrintStatus : AuditedAggregateRoot - { - public ZHBPrintStatus() - { - } + //public class ZHBPrintStatus : AuditedAggregateRoot + //{ + // public ZHBPrintStatus() + // { + // } - public ZHBPrintStatus(Guid id, string vIN, string groupName, int billStatus) : base(id) - { - VIN = vIN; - GroupName = groupName; + // public ZHBPrintStatus(Guid id, string vIN, string groupName, int billStatus) : base(id) + // { + // VIN = vIN; + // GroupName = groupName; - BillStatus = billStatus; - } + // BillStatus = billStatus; + // } - /// - /// 地盘号 - /// - public virtual string VIN { get; set; } - /// - /// 组类别 - /// - public virtual string GroupName { get; set; } - /// - /// 状态 - /// - public virtual int BillStatus { get; set; } - } + // /// + // /// 地盘号 + // /// + // public virtual string VIN { get; set; } + // /// + // /// 组类别 + // /// + // public virtual string GroupName { get; set; } + // /// + // /// 状态 + // /// + // public virtual int BillStatus { get; set; } + //} } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M100DomainService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M100DomainService.cs index 65d3db2..52a981b 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M100DomainService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M100DomainService.cs @@ -49,9 +49,9 @@ namespace WY.NewJit.MsgCheck BillNumberRecord billNumRec = await _billNumRecDomainSrv.GetBillNumber(m100Obj.HostSN.TryToIntNotNull(), m100Obj.ProductLine); var normalObj = billNumRec.Datas.FirstOrDefault(itm => itm.BillNumberType == BillNumberTypeEnum.正常); var lateObj = billNumRec.Datas.FirstOrDefault(itm => itm.BillNumberType == BillNumberTypeEnum.迟到); - var breaknumLst = billNumRec.Datas.Where(itm => itm.BillNumberType == BillNumberTypeEnum.断号).ToList(); + var breakNumLst = billNumRec.Datas.Where(itm => itm.BillNumberType == BillNumberTypeEnum.断号).ToList(); //更新M100 - m100Obj.HostSN2 = normalObj.HostSN2.TryToInt(); + m100Obj.HostSN2 = normalObj != null ? normalObj.HostSN2 : lateObj.HostSN2; //M100转换成WaitPrint:一个底盘、08产线插入3条记录,其它产线插入1条记录 WaitPrint[] wpArr; if (m100Obj.ProductLine == "08") @@ -68,19 +68,19 @@ namespace WY.NewJit.MsgCheck } //处理断号 - if (breaknumLst.Count > 0) + if (breakNumLst.Count > 0) { - List breakNumLst = new List(); - foreach (var sourceWaitPrint in wpArr) + List waitPrintBreakNumLst = new List(); + foreach (var sourceWaitPrint in wpArr) //遍历门板、柱护板、其它柱护板 { - foreach (var breaknum in breaknumLst) + foreach (var breaknum in breakNumLst) //遍历断号 { WaitPrint targetWaitPrint = new WaitPrint(GuidGenerator.Create()); targetWaitPrint.M100Id = Guid.Parse("00000000-0000-0000-0000-000000000000"); targetWaitPrint.BusinessType = sourceWaitPrint.BusinessType; targetWaitPrint.ProductLine = sourceWaitPrint.ProductLine; targetWaitPrint.OnlineTime = sourceWaitPrint.OnlineTime; - targetWaitPrint.HostSN = breaknum.ToString().Right(5).TryToIntZero(); + targetWaitPrint.HostSN = breaknum.HostSN; targetWaitPrint.KNR = null; targetWaitPrint.VIN = null; targetWaitPrint.VehicleModelCode = null; @@ -94,10 +94,10 @@ namespace WY.NewJit.MsgCheck targetWaitPrint.CreatorId = null; targetWaitPrint.LastModificationTime = null; targetWaitPrint.LastModifierId = null; - breakNumLst.Add(targetWaitPrint); + waitPrintBreakNumLst.Add(targetWaitPrint); } } - await _waitPrintRepository.InsertManyAsync(breakNumLst, autoSave); //插入断号 + await _waitPrintRepository.InsertManyAsync(waitPrintBreakNumLst, autoSave); //插入断号 } //处理正常、迟到 BillM100 m100Ret = null; @@ -110,7 +110,7 @@ namespace WY.NewJit.MsgCheck { m100Ret = await _billM100Repository.InsertAsync(m100Obj, autoSave); //插入M100 - foreach (var item in wpArr) + foreach (var item in wpArr) //遍历门板、柱护板、其它柱护板 { var insObj = await _waitPrintRepository.FirstOrDefaultAsync(itm => itm.HostSN2 == m100Obj.HostSN2 @@ -125,6 +125,7 @@ namespace WY.NewJit.MsgCheck else { //如果未打印表没有----对应断号记录,则插入 + item.PrintType = PrintTypeEnum.ReplenishPrint; var insertRet = await _waitPrintRepository.InsertAsync(item, autoSave); } } @@ -213,5 +214,11 @@ namespace WY.NewJit.MsgCheck targetWaitPrint.LastModifierId = sourceWaitPrint.LastModifierId; } + public async Task>> GetM100PartDic(List m100IdLst) + { + List m100Lst = await _billM100Repository.GetListAsync(itm => m100IdLst.Contains(itm.Id), true); + Dictionary> ret = m100Lst.ToDictionary(itm => itm.Id, itm2 => itm2.BillM100Parts); + return ret; + } } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/PrintTable/Entitys/LastPrintHostSN.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/PrintTable/Entitys/LastPrintHostSN.cs new file mode 100644 index 0000000..b883301 --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/PrintTable/Entitys/LastPrintHostSN.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; + +namespace WY.NewJit.PrintTable +{ + public class LastPrintHostSN : Entity + { + public string ProductLineCode { get; set; } + + public int HostSN { get; set; } + + } +} diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContext.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContext.cs index 2b28da7..751f159 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContext.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContext.cs @@ -62,7 +62,7 @@ namespace WY.NewJit.EntityFrameworkCore #region 报文解析及校验 - public DbSet ZHBPrintStatus { get; set; } + //public DbSet ZHBPrintStatus { get; set; } public DbSet BillM100s { get; set; } public DbSet BillM100Parts { get; set; } public DbSet BillM110s { get; set; } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContextModelCreatingExtensions.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContextModelCreatingExtensions.cs index bedb7fd..100eca6 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContextModelCreatingExtensions.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.EntityFrameworkCore/EntityFrameworkCore/NewJitDbContextModelCreatingExtensions.cs @@ -176,13 +176,13 @@ namespace WY.NewJit.EntityFrameworkCore }); - builder.Entity(b => { - b.ToTable(NewJitConsts.DbTablePrefix + nameof(ZHBPrintStatus)); - b.ConfigureByConvention(); - b.Property(itm => itm.GroupName).HasColumnType("varchar").HasMaxLength(50); - b.Property(itm => itm.VIN).HasColumnType("varchar").HasMaxLength(50); - b.HasIndex(x => new { x.GroupName, x.VIN }).IsUnique(); - }); + //builder.Entity(b => { + // b.ToTable(NewJitConsts.DbTablePrefix + nameof(ZHBPrintStatus)); + // b.ConfigureByConvention(); + // b.Property(itm => itm.GroupName).HasColumnType("varchar").HasMaxLength(50); + // b.Property(itm => itm.VIN).HasColumnType("varchar").HasMaxLength(50); + // b.HasIndex(x => new { x.GroupName, x.VIN }).IsUnique(); + //}); builder.Entity(b =>