using JNPF.Common.Core.Manager; 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; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using Tnb.BasicData; using Tnb.BasicData.Entities; using Tnb.EquipMgr.Entities; using Tnb.PerMgr.Entities; 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 { /// /// 组装、包装生产提报服务 /// [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class PrdPackReportService : IPrdPackReportService, IDynamicApiController, ITransient { private readonly ISqlSugarClient _db; private readonly IDictionaryDataService _dictionaryDataService; private readonly IUserManager _userManager; private static Dictionary> _dicWorkLine = new(); public PrdPackReportService(ISqlSugarRepository repository, IUserManager userManager, IDictionaryDataService dictionaryDataService) { _db = repository.AsSugarClient(); _userManager = userManager; _dictionaryDataService = dictionaryDataService; } /// /// 获取组装包装生产任务记录,树形结构 /// /// [HttpPost] public async Task GetList(PrdPackReportQueryInput input) { if (input == null) { throw new ArgumentNullException("input"); } if (string.IsNullOrEmpty(input.stationId)) { return new { pagination = new PageResult(), list = Array.Empty() }; } List trees = new(); Dictionary dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); List list = await _db.Queryable().Where(it => it.Category == "workline").ToListAsync(); if (_dicWorkLine.Count < 1) { _dicWorkLine = list.ToDictionary(x => x.Id, x => Tuple.Create(x.EnCode, x.FullName)); } bool start = false; bool end = false; DateTime[] startTimes = new DateTime[2]; DateTime[] endTimes = new DateTime[2]; if (input.estimated_start_date != null && input.estimated_start_date.Count() == 2) { start = true; startTimes[0] = GetDateTimeMilliseconds(input.estimated_start_date![0]); startTimes[1] = GetDateTimeMilliseconds(input.estimated_start_date![1]); } if (input.estimated_end_date != null && input.estimated_end_date.Count() == 2) { end = true; endTimes[0] = GetDateTimeMilliseconds(input.estimated_end_date![0]); endTimes[1] = GetDateTimeMilliseconds(input.estimated_end_date![1]); } SqlSugarPagedList items = await _db.Queryable() .LeftJoin((a, b) => a.process_id == b.id) .LeftJoin((a, b, c) => a.mo_id == c.id) .LeftJoin((a, b, c, d) => a.id == d.parent_id) .WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code.Trim()) // .WhereIF(start, a => a.estimated_start_date != null&& startTimes[0] <= a.estimated_start_date && startTimes[1] >= a.estimated_start_date) // .WhereIF(end, a => a.estimated_end_date != null && endTimes[0] <= a.estimated_end_date && endTimes[1] >= a.estimated_end_date) .WhereIF(!string.IsNullOrEmpty(input.workline), a => list.Where(p => p.EnCode.Contains(input.workline) || p.FullName.Contains(input.workline)).Select(p => p.Id).ToList().Contains(a.workline_id!)) .Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled") .Where((a, b, c, d) => d.workstation_id == input.stationId) .OrderByDescending(a => a.create_time) .Select((a, b, c) => new PrdMoTask { id = a.id, mo_task_code = a.mo_task_code, workline_id = a.workline_id, process_id = a.process_id, plan_start_date = a.estimated_start_date, plan_end_date = a.estimated_end_date, plan_qty = a.scheduled_qty, // complete_qty = SqlFunc.Subqueryable().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty), complete_qty = a.last_process_complete_qty, mo_task_status = a.mo_task_status, }) .ToPagedListAsync(input.currentPage, input.pageSize); if (start) { items.list = items.list.Where(a => startTimes[0] <= a.plan_start_date && startTimes[1] >= a.plan_start_date).ToList(); } if (end) { items.list = items.list.Where(a => endTimes[0] <= a.plan_end_date && endTimes[1] >= a.plan_end_date).ToList(); } _db.ThenMapper(items.list, it => { it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; }); if (items != null && items.list != null && items.list.Any()) { foreach (PrdMoTask? item in items.list) { PackReportTreeOutput node = item.Adapt(); node.parentId = "0"; if (item.workline_id.IsNotEmptyOrNull()) { Tuple? workLine = _dicWorkLine.ContainsKey(item.workline_id) ? _dicWorkLine[item.workline_id] : null; if (workLine != null) { node.workline_id = $"{workLine.Item1}/{workLine.Item2}"; } } node.plan_start_date = item.plan_start_date.HasValue ? item.plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; node.plan_end_date = item.plan_end_date.HasValue ? item.plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; await GetChild(item.id, trees, dic, input.stationId); trees.Add(node); } } List treeList = trees.ToTree(); if (!string.IsNullOrEmpty(input.process)) { List removelist = new(); foreach (PackReportTreeOutput item in treeList) { bool flag = false; if (item.process_id != null && item.process_id.Contains(input.process)) { flag = true; } if (item.children != null && item.children.Count > 0) { List childs = item.children.Adapt>(); if (childs.Where(p => p.process_id.Contains(input.process)).Any()) { flag = true; } } if (!flag) { removelist.Add(item); } } removelist.ForEach(p => treeList.Remove(p)); } SqlSugarPagedList pagedList = new() { list = treeList, pagination = new Pagination { CurrentPage = input.currentPage, PageSize = input.pageSize, Total = treeList.Count } }; return PageResult.SqlSugarPageResult(pagedList); } private static DateTime GetDateTimeMilliseconds(long timestamp) { long begtime = timestamp * 10000; DateTime dt_1970 = new(1970, 1, 1, 8, 0, 0); long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度 long time_tricks = tricks_1970 + begtime;//日志日期刻度 DateTime dt = new(time_tricks);//转化为DateTime return dt; } private async Task GetChild(string parentId, List nodes, Dictionary dic, string stationId) { List items = await _db.Queryable() .LeftJoin((a, b) => a.process_id == b.id) .LeftJoin((a, b, c) => a.mo_id == c.id) .LeftJoin((a, b, c, d) => a.mbom_process_id == d.id) .Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled" && a.workstation_id == stationId) .OrderBy((a, b, c, d) => d.ordinal) .Select((a, b, c) => new PrdMoTask { id = a.id, mo_task_code = a.mo_task_code, workline_id = a.workline_id, process_id = a.process_id, process_code = b.process_code, process_name = b.process_name, plan_start_date = a.estimated_start_date, plan_end_date = a.estimated_end_date, plan_qty = a.scheduled_qty, //complete_qty = SqlFunc.Subqueryable().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty), complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0), mo_task_status = a.mo_task_status, }).ToListAsync(); _db.ThenMapper(items, it => { it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; }); if (items?.Count > 0) { List nsChild = items.Adapt>(); for (int i = 0; i < nsChild.Count; i++) { nsChild[i].parentId = parentId; nsChild[i].process_id = $"{items[i].process_code}/{items[i].process_name}"; nsChild[i].plan_start_date = items[i].plan_start_date.HasValue ? items[i].plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; nsChild[i].plan_end_date = items[i].plan_end_date.HasValue ? items[i].plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; if (nsChild[i].workline_id.IsNotEmptyOrNull()) { Tuple? workLine = _dicWorkLine.ContainsKey(nsChild[i].workline_id) ? _dicWorkLine[nsChild[i].workline_id] : null; if (workLine != null) { nsChild[i].workline_id = $"{workLine.Item1}/{workLine.Item2}"; } } } nodes.AddRange(nsChild); foreach (PrdMoTask? item in items) { await GetChild(item.id, nodes, dic, stationId); } } } /// /// pda端根据工位获取注塑挤出列表 /// /// [HttpPost] public async Task GetInjectionMoldingList(PrdPackReportQueryInput input) { if (string.IsNullOrEmpty(input.stationId)) { return new { pagination = new PageResult(), list = Array.Empty() }; } SqlSugarPagedList result = await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.process_id == c.id) .LeftJoin((a, b, c, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode) .LeftJoin((a, b, c, e, f) => a.eqp_id == f.id) .LeftJoin((a, b, c, e, f, g) => a.mold_id == g.id) .Where((a, b) => a.workstation_id == input.stationId && a.mo_task_status != DictConst.ToBeScheduledEncode && a.schedule_type == 1) .OrderByDescending((a, b) => a.create_time) .Select((a, b, c, e, f, g) => new PADPackageTaskPageOutput { id = a.id, mo_task_code = a.mo_task_code, mo_id = a.mo_id, material_id = a.material_id, material_code = b.code, material_name = b.name, workline_id = a.workline_id, // workline_name = d.FullName, bom_id = a.bom_id, mo_task_status = e.FullName, complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0), scrap_qty = a.scrap_qty, scheduled_qty = a.scheduled_qty, reported_work_qty = a.reported_work_qty, estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS), estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS), parent_id = a.parent_id, process_id = a.process_id, process_name = c.process_name, mbom_process_id = a.mbom_process_id, equip_id = a.eqp_id, equip_code = f.code, equip_name = f.name, mold_id = a.mold_id, mold_code = g.mold_code, mold_name = g.mold_name, }).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(result); } /// /// pda端根据工位获取组装包装列表 /// /// [HttpPost] public async Task GetPadList(PrdPackReportQueryInput input) { if (string.IsNullOrEmpty(input.stationId)) { return new { pagination = new PageResult(), list = Array.Empty() }; } SqlSugarPagedList result = await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.process_id == c.id) .LeftJoin((a, b, c, d) => a.workline_id == d.Id) .LeftJoin((a, b, c, d, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode) .Where((a, b) => a.workstation_id == input.stationId && a.mo_task_status != DictConst.ToBeScheduledEncode && a.schedule_type == 2) .OrderByDescending((a, b) => a.create_time) .Select((a, b, c, d, e) => new PADPackageTaskPageOutput { id = a.id, mo_task_code = a.mo_task_code, mo_id = a.mo_id, material_id = a.material_id, material_code = b.code, material_name = b.name, workline_id = a.workline_id, workline_name = d.FullName, bom_id = a.bom_id, mo_task_status = e.FullName, complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0), scrap_qty = a.scrap_qty, scheduled_qty = a.scheduled_qty, reported_work_qty = a.reported_work_qty, estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS), estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS), parent_id = a.parent_id, process_id = a.process_id, process_name = c.process_name, mbom_process_id = a.mbom_process_id, }).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(result); } /// /// PAD,pda端根据工位获取任务单列表 /// /// [HttpPost] public async Task GetPadPrdMoTaskList(PrdMoTaskListOutput input) { // if (string.IsNullOrEmpty(input.stationId)) // { // return new // { // pagination = new PageResult(), // list = Array.Empty() // }; // } Dictionary queryJson = string.IsNullOrEmpty(input.queryJson) ? new Dictionary() : input.queryJson.ToObject>(); string? mo_task_code = queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : ""; string? status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : ""; DateTime? start_time = queryJson.ContainsKey("start_time") ? queryJson["start_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["start_time"]) : null; DateTime? end_time = queryJson.ContainsKey("end_time") ? queryJson["end_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["end_time"]) : null; List statusList = new(); if (!string.IsNullOrEmpty(status)) { switch (status) { case "1": statusList.Add(DictConst.InProgressEnCode); statusList.Add(DictConst.MoStatusPauseCode); break; case "2": statusList.Add(DictConst.ToBeScheduledEncode); statusList.Add(DictConst.ToBeStartedEnCode); break; case "3": statusList.Add(DictConst.ComplatedEnCode); statusList.Add(DictConst.ClosedEnCode); break; } } // string mo_task_status = queryJson.ContainsKey("mo_task_status") ? queryJson["mo_task_status"].ToString() : ""; if (string.IsNullOrEmpty(input.sidx)) { input.sidx = "create_time"; input.sort = "desc"; } SqlSugarPagedList result = await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.process_id == c.id) .LeftJoin((a, b, c, d) => a.workline_id == d.Id) .LeftJoin((a, b, c, d, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode) .LeftJoin((a, b, c, d, e, f) => a.eqp_id == f.id) .LeftJoin((a, b, c, d, e, f, g) => a.mold_id == g.id) .LeftJoin((a, b, c, d, e, f, g, h) => a.material_id == h.output_material_id && a.eqp_id == h.equip_id && a.mold_id == h.molds_id && h.enabled == 1) .LeftJoin((a, b, c, d, e, f, g, h, i) => a.process_id == i.process_id && i.enabled == 1 && a.schedule_type==1) .LeftJoin((a, b, c, d, e, f, g, h, i, j) => a.mo_id == j.id) .LeftJoin((a, b, c, d, e, f, g, h, i, j, k) => a.material_id == k.material_id && k.auxiliary_unit_id == "KGM") .LeftJoin((a, b, c, d, e, f, g, h, i, j, k, l) => a.eqp_id == l.equip_id && l.enabled == 1 && l.label_name.Contains("允许称重"))//注塑空满箱请求 // .Where((a, b) => a.workstation_id == input.stationId) .Where((a, b) => a.worker_id == _userManager.UserId && (a.schedule_type==1 || (a.schedule_type==2 && a.parent_id!=null))) .WhereIF(!string.IsNullOrEmpty(mo_task_code), a => a.mo_task_code.Contains(mo_task_code)) //.WhereIF(!string.IsNullOrEmpty(mo_task_status),a=>a.mo_task_status==mo_task_status) .WhereIF(statusList.Count > 0, a => statusList.Contains(a.mo_task_status)) .WhereIF(status == "3" && start_time != null, a => a.act_end_date >= start_time) .WhereIF(status == "3" && end_time != null, a => a.act_end_date <= end_time) .Select((a, b, c, d, e, f, g, h, i, j, k, l) => new PADPackageTaskPageOutput { id = a.id, mo_task_code = a.mo_task_code, mo_id = a.mo_id, mo_code = j.mo_code, material_id = a.material_id, material_code = b.code, material_name = b.name, material_standard = b.material_specification, container_no = b.container_no, di = b.di, workline_id = a.workline_id, workline_name = d.FullName, bom_id = a.bom_id, mo_task_status = e.FullName, complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0), scrap_qty = a.scrap_qty, scheduled_qty = a.scheduled_qty, reported_work_qty = a.reported_work_qty, estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS), estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS), parent_id = a.parent_id, process_id = a.process_id, process_name = c.process_name, mbom_process_id = a.mbom_process_id, create_time = a.create_time, equip_id = a.eqp_id, equip_code = f.code, equip_name = f.name, mold_id = a.mold_id, mold_code = g.mold_code, mold_name = g.mold_name, schedule_type = a.schedule_type, mold_cavity = g.mold_cavity, moulding_cycle = h.moulding_cycle, standard_time = i.standard_time, act_start_date = a.act_start_date == null ? "" : a.act_start_date.Value.ToString(DbTimeFormat.SS), act_end_date = a.act_end_date == null ? "" : a.act_end_date.Value.ToString(DbTimeFormat.SS), plan_end_date = a.plan_end_date == null ? "" : a.plan_end_date.Value.ToString(DbTimeFormat.SS), minpacking = b.minpacking, main_num = k.number_of_primary_unit, deputy_num = k.number_of_auxiliary_unit, third_equip_code = f.code, weight_name = l.label_point, category_id = b.category_id, as_location_id = f.as_location_id, upmat_location_id = f.upmat_location_id, downmat_location_id = f.as_location_id, instock_warehouse_id = f.as_location_id, mold_location_id = g.location_id, }) .MergeTable() .OrderBy($"{input.sidx} {input.sort}") .ToPagedListAsync(input.currentPage, input.pageSize); if (!result.list.IsEmpty()) { foreach (var item in result.list) { if (item.as_location_id!=null && !item.as_location_id.IsEmpty()) { BasLocation basLocation = await _db.Queryable().SingleAsync(x => x.id == item.as_location_id); item.as_location_code = basLocation.location_code; } if (item.upmat_location_id!=null && !item.upmat_location_id.IsEmpty()) { BasLocation basLocation = await _db.Queryable().SingleAsync(x => x.id == item.upmat_location_id); item.upmat_location_code = basLocation.location_code; } if (item.downmat_location_id!=null && !item.downmat_location_id.IsEmpty()) { BasLocation basLocation = await _db.Queryable().SingleAsync(x => x.id == item.downmat_location_id); item.downmat_location_code = basLocation.location_code; } if (!string.IsNullOrEmpty(item.mold_location_id)) { ToolLocation basLocation = await _db.Queryable().SingleAsync(x => x.id == item.mold_location_id); item.mold_location_code = basLocation.location_code; } if (item.schedule_type == 2) { PerProcessStandardsH processStandardsH = await _db.Queryable() .Where(x => x.equip_id == item.equip_id && x.molds_id == item.mold_id && x.output_material_id == item.material_id && x.enabled == 1) .OrderByDescending(x => x.create_time).FirstAsync(); item.standard_time = processStandardsH?.moulding_cycle?.ToString(); } } } return PageResult.SqlSugarPageResult(result); } /// /// 上模校验 /// /// [HttpPost] public async Task CheckMold(CheckMoldInput input) { PrdMoTask prdMoTask = await _db.Queryable().SingleAsync(x => x.id == input.mo_task_id); 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("(10)"); if (arr.Length > 1) { string batch = arr[1]; PrdMoTask prdMoTask = await _db.Queryable().Where(x => x.batch == batch).FirstAsync(); string mo_task_code = prdMoTask.mo_task_code; 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.label_code.Split("(10)"); if (arr.Length > 1) { string batch = arr[1]; PrdMoTask prdMoTask = await _db.Queryable().Where(x => x.batch == batch).FirstAsync(); string mo_task_code = prdMoTask.mo_task_code; 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("校验失败"); } } }