From 746e7f425d60e5f5e632564e40eeb59e758efc2c Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Thu, 9 Nov 2023 10:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E5=8C=85=E8=A3=85=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/DictConst.cs | 5 + .../Dto/PrdManage/MarkingLabelInput.cs | 9 + .../Dto/PrdManage/TrayQrcodeInput.cs | 9 + .../Entity/PrdOutPackMarkLabel.cs | 57 ++++++ .../Entity/PrdOutPacking.cs | 37 ++++ .../IPrdInstockService.cs | 4 +- .../IPrdMoTaskService.cs | 16 ++ .../IPrdOutPackingService.cs | 14 ++ .../Tnb.ProductionMgr/PrdInstockService.cs | 191 +++++++++++++++++- .../Tnb.ProductionMgr/PrdMoTaskService.cs | 64 +++++- .../Tnb.ProductionMgr/PrdOutPackingService.cs | 46 +++++ .../Tnb.ProductionMgr/PrdPackReportService.cs | 144 ++++++++++++- 12 files changed, 586 insertions(+), 10 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MarkingLabelInput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/TrayQrcodeInput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPackMarkLabel.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPacking.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutPackingService.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr/PrdOutPackingService.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index 8fa89a1b..6a3d17e6 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -2,6 +2,11 @@ namespace Tnb.BasicData; public static class DictConst { + /// + /// 系统默认用户id 非人工的用此id + /// + public const string DEFAULTUSERID = "30018908123413"; + #region BasicData /// /// 计量单位 diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MarkingLabelInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MarkingLabelInput.cs new file mode 100644 index 00000000..737e7d98 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MarkingLabelInput.cs @@ -0,0 +1,9 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class MarkingLabelInput + { + public string station_id { get; set; } + public string mark_code { get; set; } + public string label_code { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/TrayQrcodeInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/TrayQrcodeInput.cs new file mode 100644 index 00000000..19a3fe2f --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/TrayQrcodeInput.cs @@ -0,0 +1,9 @@ +namespace Tnb.ProductionMgr.Entities.Dto +{ + public class TrayQrcodeInput + { + public string qrcode { get; set; } + + public string station_id { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPackMarkLabel.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPackMarkLabel.cs new file mode 100644 index 00000000..0da7ab0c --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPackMarkLabel.cs @@ -0,0 +1,57 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities; + +/// +/// 外包装喷码贴标验证表 +/// +[SugarTable("prd_out_pack_mark_label")] +public partial class PrdOutPackMarkLabel : BaseEntity +{ + public PrdOutPackMarkLabel() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 是否喷码 0 否 1 是 + /// + public int is_mark { get; set; } + + /// + /// 是否贴标 0 否 1 是 + /// + public int is_label { get; set; } + + /// + /// 任务单号 + /// + public string mo_task_code { get; set; } = string.Empty; + + /// + /// 物料号 + /// + public string material_code { get; set; } = string.Empty; + + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 创建时间 + /// + public DateTime create_time { get; set; } = DateTime.Now; + + /// + /// 状态 0 未提报 1 已提报 2 已发起入库申请 + /// + public string status { get; set; } = string.Empty; + + /// + /// 提报记录id + /// + public string report_id { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPacking.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPacking.cs new file mode 100644 index 00000000..87c3fd5b --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdOutPacking.cs @@ -0,0 +1,37 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities; + +/// +/// 外包装空托盘码表 +/// +[SugarTable("prd_out_packing")] +public partial class PrdOutPacking : BaseEntity +{ + public PrdOutPacking() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 托盘码 + /// + public string code { get; set; } = string.Empty; + + /// + /// 工位id + /// + public string station_id { get; set; } = string.Empty; + + /// + /// 状态 0 未使用 1 已使用 + /// + public string status { get; set; } = string.Empty; + + /// + /// 创建时间 + /// + public DateTime create_time { get; set; } = DateTime.Now; + +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdInstockService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdInstockService.cs index 68a697ea..3ee25438 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdInstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdInstockService.cs @@ -28,7 +28,7 @@ namespace Tnb.ProductionMgr.Interfaces /// /// /// - public Task InstockTypeOne(InstockInput inut); + public Task InstockTypeOne(InstockInput input); /// /// 短管挤出入库申请 @@ -49,6 +49,6 @@ namespace Tnb.ProductionMgr.Interfaces /// /// /// - public Task InstockOutPack(InstockInput inut); + public Task InstockOutPack(InstockInput input); } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs index e20aeba7..a2a45e06 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdMoTaskService.cs @@ -1,4 +1,5 @@ using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto; namespace Tnb.ProductionMgr.Interfaces { @@ -26,6 +27,21 @@ namespace Tnb.ProductionMgr.Interfaces /// /// Task GetPrdMoTaskInfoByStationId(Dictionary dic); + + /// + /// 外包装根据工位id获取喷码数据 + /// + /// + /// + Task GetMarkingInfoByStationId(MarkingLabelInput input); + + + /// + /// 外包装根据工位id获取贴标数据 + /// + /// + /// + Task GetLabelInfoByStationId(MarkingLabelInput input); } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutPackingService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutPackingService.cs new file mode 100644 index 00000000..4a555c77 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdOutPackingService.cs @@ -0,0 +1,14 @@ +using Tnb.ProductionMgr.Entities.Dto; + +namespace Tnb.ProductionMgr.Interfaces +{ + public interface IPrdOutPackingService + { + /// + /// 托盘二维码 + /// + /// + /// + public Task TrayQrcode(TrayQrcodeInput input); + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs index abbf5355..1a21e971 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs @@ -259,10 +259,10 @@ namespace Tnb.ProductionMgr /// /// [AllowAnonymous] - public async Task InstockTypeOne(InstockInput inut) + public async Task InstockTypeOne(InstockInput input) { - string equip_code = inut.equip_code; - string label_code = inut.label_code; + string equip_code = input.equip_code; + string label_code = input.label_code; string warehouse_id = "2"; if (!string.IsNullOrEmpty(equip_code)) { @@ -399,6 +399,7 @@ namespace Tnb.ProductionMgr { _ = await db.Insertable(prdInstockDs).ExecuteCommandAsync(); } + //todo 入库申请后是否修改提报记录状态 }); } @@ -626,9 +627,189 @@ namespace Tnb.ProductionMgr /// /// /// - public Task InstockOutPack(InstockInput inut) + public async Task InstockOutPack(InstockInput input) { - throw new NotImplementedException(); + string equip_code = input.equip_code; + string label_code = input.label_code; + string warehouse_id = "26103367464997";//四楼解析库 + if (!string.IsNullOrEmpty(equip_code)) + { + throw Oops.Bah("请传机台号"); + } + + if (!string.IsNullOrEmpty(label_code)) + { + throw Oops.Bah("请传标签号"); + } + + ISqlSugarClient db = _repository.AsSugarClient(); + EqpEquipment equipment = await db.Queryable() + .LeftJoin((x,y)=>x.id==y.equip_id) + .Where((x,y) => y.equip_code==equip_code && y.label_name==label_code && y.label_point=="外包装成品码垛点位") + .Select((x,y)=>x) + .FirstAsync(); + + + if (equipment == null) + { + throw Oops.Bah("未找到机台"); + } + + if (string.IsNullOrEmpty(equipment.as_location_id)) + { + throw Oops.Bah("未找到入库库位"); + } + + BasLocation basLocation = await db.Queryable().SingleAsync(x => x.id == equipment.as_location_id); + if (basLocation == null) + { + throw Oops.Bah("未找到入库库位"); + } + + OrganizeEntity station = await db.Queryable() + .LeftJoin((x, y) => x.Id == y.OrganizeId) + .Where((x, y) => y.ObjectType == "Eqp" && y.ObjectId == equipment.id).FirstAsync(); + + if (station == null) + { + throw Oops.Bah("未找到工位"); + } + + PrdOutPacking prdOutPacking = await db.Queryable().Where(x=>x.station_id==station.Id && x.status=="0").OrderByDescending(x=>x.create_time).FirstAsync(); + if (prdOutPacking == null) + { + throw Oops.Bah("未找到托盘"); + } + + var prdOutPackMarkLabelList = await db.Queryable().Where(x=>x.station_id==station.Id && x.status=="1").ToListAsync(); + if (prdOutPackMarkLabelList == null || prdOutPackMarkLabelList.Count <= 0) + { + throw Oops.Bah("未找到提报记录"); + } + + List reportIds = prdOutPackMarkLabelList.Select(x => x.report_id).ToList(); + + List prdReports = await db.Queryable().Where(x => reportIds.Contains(x.id)).ToListAsync(); + + if (prdReports == null || prdReports.Count<=0) + { + throw Oops.Bah("未找到提报记录"); + } + + PrdInstockH? prdInstockH = null; + List prdInstockDs = new() { }; + DbResult result2 = new(); + string material_id = prdReports[0].material_id; + BasMaterial basMaterial = await db.Queryable().SingleAsync(x => x.id == material_id); + DbResult result = await db.Ado.UseTranAsync(async () => + { + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(station.Id, DictConst.RegionCategoryWorklineCode); + OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(station.Id, DictConst.RegionCategoryWorkshopCode); + + prdInstockH = new PrdInstockH() + { + bill_type = DictConst.CHANCHENGPINRUKUDAN, + bill_date = DateTime.Now, + create_id = _userManager.UserId, + location_code = basLocation.location_code, + carry_code = prdOutPacking.code, + is_check = 1, + station_id = station.Id, + workline_id = workline?.Id ?? "", + workshop_id = workshop?.Id ?? "", + org_id = _userManager.GetUserInfo().Result.organizeId, + // warehouse_id = basLocation?.wh_id, + warehouse_id = warehouse_id, + status = 0, + }; + + foreach (var prdReport in prdReports) + { + prdInstockDs.Add(new PrdInstockD() + { + instock_id = prdInstockH.id, + report_id = prdReport.create_id, + material_id = prdReport.material_id, + material_code = basMaterial.code, + unit_id = prdReport.unit_id, + barcode = prdReport.barcode, + code_batch = prdReport.barcode + "0001", + quantity = (int)prdReport.reported_qty, + }); + } + }); + + if (result.IsSuccess) + { + MESCreateInstockInput mesCreateInstockInput = new() + { + instock = new MESWmsInstockHInput() + { + org_id = _userManager.GetUserInfo().Result.organizeId, + bill_date = DateTime.Now, + bill_type = DictConst.CHANCHENGPINRUKUDAN, + // warehouse_id = basLocation?.wh_id, + warehouse_id = warehouse_id, + source_id = prdInstockH.id, + create_id = _userManager.UserId, + carry_code = prdOutPacking.code, + location_code = basLocation.location_code, + is_check = 1, + }, + instockds = new List(), + instockcodes = new List() + }; + + foreach (var prdReport in prdReports) + { + mesCreateInstockInput.instockds.Add(new MESWmsInstockDInput() + { + material_id = prdReport.material_id, + material_code = basMaterial.code, + unit_id = prdReport.unit_id, + code_batch = prdReport.barcode, + pr_qty = (int)prdReport.reported_qty, + }); + + mesCreateInstockInput.instockcodes.Add(new MESWmsInstockCodeInput() + { + material_id = prdReport.material_id, + material_code = basMaterial.code, + unit_id = prdReport.unit_id, + barcode = prdReport.barcode, + code_batch = prdReport.barcode + "0001", + codeqty = (int)prdReport.reported_qty, + }); + } + + string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host; + Dictionary header = new() + { + ["Authorization"] = App.HttpContext.Request.Headers["Authorization"] + }; + string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK, JsonConvert.SerializeObject(mesCreateInstockInput), header); + Log.Information(sendResult); + AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); + result2 = authResponse.code != 200 || !authResponse.data.ObjToBool() + ? throw Oops.Bah(authResponse.msg) + : await db.Ado.UseTranAsync(async () => + { + _ = await _repository.InsertAsync(prdInstockH); + + if (prdInstockDs.Count > 0) + { + _ = await db.Insertable(prdInstockDs).ExecuteCommandAsync(); + } + + await db.Updateable() + .SetColumns(x => x.status == "2") + .Where(x => x.station_id == station.Id && x.status == "1").ExecuteCommandAsync(); + + //todo 入库申请后是否修改提报记录状态 + }); + } + + return !result2.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result2.IsSuccess ? "申请成功" : result2.ErrorMessage); } } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index e5383bf1..aff6e4fe 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -1114,9 +1114,12 @@ namespace Tnb.ProductionMgr throw Oops.Bah("已开始的不能再开始"); } - if (await db.Queryable().AnyAsync(x => x.workstation_id == item.workstation_id && x.mo_task_status == DictConst.InProgressEnCode && x.id != item.id)) + if (item.schedule_type == 2) { - throw Oops.Bah("该工位已有生产中的任务单"); + if (await db.Queryable().AnyAsync(x => x.workstation_id == item.workstation_id && x.mo_task_status == DictConst.InProgressEnCode && x.id != item.id)) + { + throw Oops.Bah("该工位已有生产中的任务单"); + } } if (item.mo_task_status is not DictConst.ToBeStartedEnCode and not DictConst.MoStatusPauseCode) @@ -2735,6 +2738,63 @@ namespace Tnb.ProductionMgr return prdMoTask; } + + /// + /// 外包装根据工位id获取喷码数据 + /// + /// + /// + [HttpPost] + public async Task GetMarkingInfoByStationId(MarkingLabelInput input) + { + PrdMoTask prdMoTask = await GetPrdMoTaskInfoByStationId(new Dictionary() + { + { "station_id", input.station_id } + }); + if (prdMoTask == null) throw Oops.Bah("没找到对应任务单"); + + PrdOutPackMarkLabel prdOutPackMarkLabel = new PrdOutPackMarkLabel() + { + is_mark = 0, + is_label = 0, + mo_task_code = prdMoTask.mo_task_code, + material_code = prdMoTask.material_code, + create_time = DateTime.Now, + }; + + await _db.Insertable(prdOutPackMarkLabel).ExecuteCommandAsync(); + + return prdMoTask.mo_task_code + "/" + prdMoTask.material_code; + } + + /// + /// 外包装根据工位id获取贴标数据 + /// + /// + /// + [HttpPost] + public async Task GetLabelInfoByStationId(MarkingLabelInput input) + { + PrdMoTask prdMoTask = await GetPrdMoTaskInfoByStationId(new Dictionary() + { + { "station_id", input.station_id } + }); + if (prdMoTask == null) throw Oops.Bah("没找到对应任务单"); + + PrdOutPackMarkLabel prdOutPackMarkLabel = new PrdOutPackMarkLabel() + { + is_mark = 0, + is_label = 0, + mo_task_code = prdMoTask.mo_task_code, + material_code = prdMoTask.material_code, + create_time = DateTime.Now, + station_id = input.station_id, + }; + + await _db.Insertable(prdOutPackMarkLabel).ExecuteCommandAsync(); + + return prdMoTask.mo_task_code + "/" + prdMoTask.material_code; + } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdOutPackingService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdOutPackingService.cs new file mode 100644 index 00000000..a07a1bef --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr/PrdOutPackingService.cs @@ -0,0 +1,46 @@ +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using JNPF.VisualDev; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto; +using Tnb.ProductionMgr.Interfaces; + +namespace Tnb.ProductionMgr +{ + [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + public class PrdOutPackingService : IPrdOutPackingService, IDynamicApiController, ITransient + { + private readonly ISqlSugarRepository _repository; + + public PrdOutPackingService(ISqlSugarRepository repository) + { + _repository = repository; + } + + /// + /// 托盘二维码 + /// + /// + /// + [HttpPost] + public async Task TrayQrcode(TrayQrcodeInput input) + { + PrdOutPacking prdOutPacking = await _repository.GetFirstAsync(x=>x.code==input.qrcode && x.station_id==input.station_id && x.status=="0"); + if (prdOutPacking != null) throw Oops.Bah("已存在该托盘"); + + prdOutPacking = new PrdOutPacking() + { + code = input.qrcode, + station_id = input.station_id, + create_time = DateTime.Now, + status = "0", + }; + + return await _repository.InsertAsync(prdOutPacking); + } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs index 6843bd63..9ea6e5f3 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs @@ -1,8 +1,10 @@ -using JNPF.Common.Extension; +using JNPF.Common.Enums; +using JNPF.Common.Extension; using JNPF.Common.Filter; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.FriendlyException; using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; @@ -17,6 +19,7 @@ using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities.Dto.PrdManage; using Tnb.ProductionMgr.Entities.Entity; using Tnb.ProductionMgr.Interfaces; +using Tnb.ProductionMgr.Entities.Dto; namespace Tnb.ProductionMgr @@ -487,5 +490,144 @@ namespace Tnb.ProductionMgr BasQrcode basQrcode = await _db.Queryable().Where(x => x.source_name == "TOOL_MOLDS" && x.code == input.mold_qrcode).FirstAsync(); return prdMoTask != null && basQrcode != null ? prdMoTask.mold_id == basQrcode.source_id : (dynamic)false; } + + /// + /// 外包装喷码校验 + /// + /// + /// + public async Task OutPackMarkCheck(MarkingLabelInput input) + { + string[] arr = input.mark_code.Split("/"); + if (arr.Length > 1) + { + string mo_task_code = arr[0]; + PrdMoTask prdMoTask = await _db.Queryable().Where(x => x.mo_task_code == mo_task_code).FirstAsync(); + if (prdMoTask == null) throw Oops.Bah("未找到对应任务单"); + BasMaterial basMaterial = await _db.Queryable().Where(x => x.id == prdMoTask.material_id).FirstAsync(); + DictionaryDataEntity unit = await _db.Queryable() + .LeftJoin((x, y) => x.Id == y.DictionaryTypeId) + .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == basMaterial.unit_id) + .Select((x, y) => y).FirstAsync(); + PrdOutPackMarkLabel prdOutPackMarkLabel = await _db.Queryable().Where(x=>x.mo_task_code==mo_task_code && x.status=="0" && x.is_mark==0).OrderByDescending(x=>x.create_time).FirstAsync(); + if (prdOutPackMarkLabel != null) + { + DbResult result = await _db.Ado.UseTranAsync(async () => + { + + if (prdOutPackMarkLabel.is_label == 1) + { + PrdReport prdReport = new PrdReport() + { + mo_task_id = prdMoTask.id, + mo_task_code = prdMoTask.mo_task_code, + create_id = DictConst.DEFAULTUSERID, + create_time = DateTime.Now, + reported_qty = 1, + unit_id = unit?.Id ?? "", + barcode = mo_task_code + DateTimeOffset.Now.ToUnixTimeSeconds().ToString(), + equip_id = prdMoTask.eqp_id, + mbom_process_id = prdMoTask.mbom_process_id, + station = prdMoTask.workstation_id, + status=0, + material_id = prdMoTask.material_id, + process_id = prdMoTask.process_id, + }; + + await _db.Updateable() + .SetColumns(x=>x.is_mark==1) + .SetColumns(x=>x.status=="1") + .SetColumns(x=>x.report_id==prdReport.id) + .ExecuteCommandAsync(); + + await _db.Insertable(prdReport).ExecuteCommandAsync(); + } + else + { + await _db.Updateable().SetColumns(x=>x.is_mark==1).ExecuteCommandAsync(); + } + }); + + return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "校验成功" : result.ErrorMessage; + + } + else + { + throw Oops.Bah("校验失败"); + } + } + + throw Oops.Bah("校验失败"); + } + + /// + /// 外包装贴标校验 + /// + /// + /// + public async Task OutPackLabelCheck(MarkingLabelInput input) + { + string[] arr = input.mark_code.Split("/"); + if (arr.Length > 1) + { + string mo_task_code = arr[0]; + PrdMoTask prdMoTask = await _db.Queryable().Where(x => x.mo_task_code == mo_task_code).FirstAsync(); + if (prdMoTask == null) throw Oops.Bah("未找到对应任务单"); + BasMaterial basMaterial = await _db.Queryable().Where(x => x.id == prdMoTask.material_id).FirstAsync(); + DictionaryDataEntity unit = await _db.Queryable() + .LeftJoin((x, y) => x.Id == y.DictionaryTypeId) + .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == basMaterial.unit_id) + .Select((x, y) => y).FirstAsync(); + PrdOutPackMarkLabel prdOutPackMarkLabel = await _db.Queryable().Where(x=>x.mo_task_code==mo_task_code && x.status=="0" && x.is_label==0).OrderByDescending(x=>x.create_time).FirstAsync(); + if (prdOutPackMarkLabel != null) + { + DbResult result = await _db.Ado.UseTranAsync(async () => + { + + if (prdOutPackMarkLabel.is_mark == 1) + { + PrdReport prdReport = new PrdReport() + { + mo_task_id = prdMoTask.id, + mo_task_code = prdMoTask.mo_task_code, + create_id = DictConst.DEFAULTUSERID, + create_time = DateTime.Now, + reported_qty = 1, + unit_id = unit?.Id ?? "", + barcode = mo_task_code + DateTimeOffset.Now.ToUnixTimeSeconds().ToString(), + equip_id = prdMoTask.eqp_id, + mbom_process_id = prdMoTask.mbom_process_id, + station = prdMoTask.workstation_id, + status=0, + material_id = prdMoTask.material_id, + process_id = prdMoTask.process_id, + }; + + await _db.Updateable() + .SetColumns(x=>x.is_label==1) + .SetColumns(x=>x.status=="1") + .SetColumns(x=>x.report_id==prdReport.id) + .ExecuteCommandAsync(); + + await _db.Insertable(prdReport).ExecuteCommandAsync(); + } + else + { + await _db.Updateable().SetColumns(x=>x.is_label==1).ExecuteCommandAsync(); + } + }); + + return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "校验成功" : result.ErrorMessage; + + } + else + { + throw Oops.Bah("校验失败"); + } + } + + throw Oops.Bah("校验失败"); + } + } }