diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index 3359147b..c2d54a15 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -72,6 +72,10 @@ public static class DictConst /// public const string ToBeScheduledEncode = "ToBeScheduled"; /// + /// 任务单状态码-暂停 + /// + public const string MoStatusPauseCode = "Pause"; + /// /// 模具维修状态码-待维修 /// public const string MaintainStatusDWXCode = "DWX"; @@ -79,6 +83,14 @@ public static class DictConst /// 模具维修状态码-已完成 /// public const string MaintainStatusYWCCode = "YWC"; + /// + /// 模具保养状态-待保养编码 + /// + public const string MoldMaintainStatusDBYCode = "UnMaintain"; + /// + /// 模具保养状态TypeId + /// + public const string MoldMaintainStatusTypeId = "26171564065301"; diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs index cbc4ae56..da654111 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs @@ -14,6 +14,6 @@ namespace Tnb.EquipMgr.Entities.Dto /// /// 规则id /// - public string rule_id { get; set; } + public List ruleIds { get; set; } } } diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs new file mode 100644 index 00000000..7861402d --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.EquipMgr.Entities.Dto +{ + /// + /// 模具保养执行输入参数 + /// + public class MoldMaintainRunUpInput + { + /// + /// 执行计划id + /// + public string plan_id { get; set; } + } +} diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs index 10dada1a..7218b75f 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainPlanRelation.cs @@ -7,7 +7,7 @@ namespace Tnb.EquipMgr.Entities; /// -/// +/// 保养计划与模具关联表 /// [SugarTable("tool_mold_maintain_plan_relation")] public partial class ToolMoldMaintainPlanRelation : BaseEntity diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecord.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecord.cs new file mode 100644 index 00000000..6f2679d2 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainRunRecord.cs @@ -0,0 +1,97 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.EquipMgr.Entities; + +/// +/// +/// +[SugarTable("tool_mold_maintain_run_record")] +public partial class ToolMoldMaintainRunRecord : BaseEntity +{ + public ToolMoldMaintainRunRecord() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 计划单号 + /// + public string? plan_code { get; set; } + + /// + /// 保养方式 + /// + public string? mode { get; set; } + + /// + /// 计划状态 + /// + public string? plan_status { get; set; } + + /// + /// 制定人 + /// + public string? designer { get; set; } + + /// + /// 制定时间 + /// + public DateTime? designer_time { get; set; } + + /// + /// 模具编号 + /// + public string? mold_code { get; set; } + + /// + /// 模具名称 + /// + public string? mold_name { get; set; } + + /// + /// 设备编号 + /// + public string? eqp_code { get; set; } + + /// + /// 设备名称 + /// + public string? eqp_name { get; set; } + + /// + /// 保养组编码 + /// + public string? group_code { get; set; } + + /// + /// 保养组名称 + /// + public string? group_name { get; set; } + + /// + /// 保养项编号 + /// + public string? check_item_code { get; set; } + + /// + /// 保养项名称 + /// + public string? check_item_name { get; set; } + + /// + /// 计划开始时间 + /// + public DateTime? plan_start_time { get; set; } + + /// + /// 计划完成时间 + /// + public DateTime? plan_end_time { get; set; } + + /// + /// 计划时间 + /// + public decimal? plan_time { get; set; } + +} diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs index 4764c29a..73803225 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRuleService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Interfaces.System; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -32,10 +34,13 @@ namespace Tnb.EquipMgr { private readonly ISqlSugarClient _db; private readonly IUserManager _userManager; - public ToolMoldMaintainRuleService(ISqlSugarRepository repository, IUserManager userManager) + private readonly IDictionaryDataService _dictionaryDataService; + + public ToolMoldMaintainRuleService(ISqlSugarRepository repository, IUserManager userManager, IDictionaryDataService dictionaryDataService) { _db = repository.AsSugarClient(); _userManager = userManager; + _dictionaryDataService = dictionaryDataService; } /// /// 根据规则Id获取匹配的模具列表 @@ -78,6 +83,111 @@ namespace Tnb.EquipMgr }) .ToListAsync(); } + [HttpGet] + public async Task GetMaintainInfoFromByPlanId([FromRoute] string planId) + { + dynamic info = new ExpandoObject(); + var planMoldRelation = await _db.Queryable().FirstAsync(it => it.id == planId); + if (planMoldRelation != null) + { + var mold = await _db.Queryable().FirstAsync(it => it.id == planMoldRelation.mold_id); + if (mold != null) + { + info.mold_code = mold.mold_code; + info.mold_name = mold.mold_name; + var moldEqpRelation = await _db.Queryable().FirstAsync(it => it.mold_id == mold.id); + if (moldEqpRelation != null) + { + var eqp = await _db.Queryable().FirstAsync(it => it.id == moldEqpRelation.equipment_id); + info.eqp_code = eqp.code; + info.eqp_name = eqp.name; + } + var itemGroupRelation = await _db.Queryable().FirstAsync(it => it.mold_id == mold.id); + if (itemGroupRelation != null) + { + var itemGroup = await _db.Queryable().FirstAsync(it => it.id == itemGroupRelation.item_group_id); + if (itemGroup != null) + { + info.item_group_name = itemGroup.name; + } + var itemRelation = await _db.Queryable().FirstAsync(it => it.item_group_id == itemGroupRelation.item_group_id); + if (itemRelation != null) + { + var checkItem = await _db.Queryable().FirstAsync(it => it.id == itemRelation.item_id); + if (checkItem != null) + { + info.item_name = checkItem.name; + } + } + } + } + } + return info; + } + + /// + /// 模具保养计划执行-开始模具保养 + /// + /// + /// { + /// plan_id:执行计划id + /// } + /// + /// + [HttpPost] + public async Task MaintainStart(MoldMaintainRunUpInput input) + { + try + { + await _db.Ado.BeginTranAsync(); + + var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId); + var plan = await _db.Queryable().FirstAsync(it => it.id == input.plan_id); + if (plan != null) + { + plan.status = DictConst.MoldMaintainStatusDBYCode; + var row = await _db.Updateable(plan).ExecuteCommandAsync(); + if (row < 1) throw Oops.Oh(ErrorCode.COM1001); + ToolMoldMaintainRunRecord record = new(); + record.plan_code = plan.plan_code; + record.mode = plan.mode; + record.plan_status = dic.ContainsKey(plan.plan_code) ? dic[plan.plan_code].ToString() : ""; + record.designer = _userManager.RealName; + record.designer_time = DateTime.Now; + var moldPlanRelation = await _db.Queryable().FirstAsync(it => it.maintain_plan_id == input.plan_id); + if (moldPlanRelation != null) + { + var mold = await _db.Queryable().FirstAsync(it => it.id == moldPlanRelation.mold_id); + record.mold_code = mold?.mold_code; + record.mold_name = mold?.mold_name; + var moldGroupRelation = await _db.Queryable().FirstAsync(it => it.mold_id == mold.id); + if (moldGroupRelation != null) + { + var maintainGroup = await _db.Queryable().FirstAsync(it => it.id == moldGroupRelation.item_group_id); + record.group_name = maintainGroup.name; + var itemGrpRelation = await _db.Queryable().FirstAsync(it => it.item_group_id == maintainGroup.id); + if (itemGrpRelation != null) + { + var checkItem = await _db.Queryable().FirstAsync(it => it.id == itemGrpRelation.item_id); + record.check_item_name = checkItem.name; + } + } + } + record.plan_start_time = DateTime.Now; + row = await _db.Insertable(record).ExecuteCommandAsync(); + if (row < 1) throw Oops.Oh(ErrorCode.COM1001); + + await _db.Ado.CommitTranAsync(); + } + } + catch (Exception ex) + { + Log.Error("开始模具保养失败", ex); + await _db.Ado.RollbackTranAsync(); + throw; + } + + } /// /// 关联模具 @@ -89,6 +199,7 @@ namespace Tnb.EquipMgr public async Task RelevanceMold(RelevanceMoldInput input) { if (input == null) throw new ArgumentNullException(nameof(input)); + await _db.Deleteable().Where(it => it.rule_id == input.rule_id).ExecuteCommandAsync(); if (input.rowIds?.Count > 0) { List entities = new(); @@ -133,30 +244,34 @@ namespace Tnb.EquipMgr { await _db.Ado.BeginTranAsync(); - var maintainRule = await _db.Queryable().FirstAsync(it => it.id == input.rule_id); - if (maintainRule is not null) + var maintainRules = await _db.Queryable().Where(it => input.ruleIds.Contains(it.id)).ToListAsync(); + if (maintainRules?.Count > 0) { - if (maintainRule.cycle.HasValue && maintainRule.cycle.Value > 0) + List maintainPlans = new(); + List maintainPlanRelations = new(); + foreach (var maintainRule in maintainRules) { - ToolMoldMaintainPlan maintainPlan = new(); - maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}"; - maintainPlan.mode = maintainRule.mode; - maintainPlan.status = DictConst.UnMaintainStatusCode; - maintainPlan.plan_start_date = DateTime.Now; - maintainPlan.plan_end_date = DateTime.Now.AddDays(maintainRule.cycle.Value); - maintainPlan.create_id = _userManager.UserId; - maintainPlan.create_time = DateTime.Now; + if (maintainRule.cycle.HasValue && maintainRule.cycle.Value > 0) + { + ToolMoldMaintainPlan maintainPlan = new(); + maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}"; + maintainPlan.mode = maintainRule.mode; + maintainPlan.status = DictConst.UnMaintainStatusCode; + maintainPlan.plan_start_date = DateTime.Now; + maintainPlan.plan_end_date = DateTime.Now.AddDays(maintainRule.cycle.Value); + maintainPlan.create_id = _userManager.UserId; + maintainPlan.create_time = DateTime.Now; + maintainPlans.Add(maintainPlan); - await _db.Insertable(maintainPlan).ExecuteCommandAsync(); - - ToolMoldMaintainPlanRelation maintainPlanReation = new(); - maintainPlanReation.maintain_plan_id = maintainPlan.id; - maintainPlanReation.mold_id = (await _db.Queryable().FirstAsync(it => it.rule_id == maintainRule.id))?.mold_id!; - - await _db.Insertable(maintainPlanReation).ExecuteCommandAsync(); - - await _db.Ado.CommitTranAsync(); + ToolMoldMaintainPlanRelation maintainPlanReation = new(); + maintainPlanReation.maintain_plan_id = maintainPlan.id; + maintainPlanReation.mold_id = (await _db.Queryable().FirstAsync(it => it.rule_id == maintainRule.id))?.mold_id!; + maintainPlanRelations.Add(maintainPlanReation); + } } + await _db.Insertable(maintainPlans).ExecuteCommandAsync(); + await _db.Insertable(maintainPlanRelations).ExecuteCommandAsync(); + await _db.Ado.CommitTranAsync(); } } catch (Exception ex) diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryOutput.cs new file mode 100644 index 00000000..b1890e52 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryOutput.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class ClosedownHistoryOutput + { + /// + /// 停机开始时间 + /// + public DateTime? closedown_start_time { get; set; } + /// + /// 停机结束时间 + /// + public DateTime? closedown_end_time { get; set; } + /// + /// 停机时间 + /// + public decimal? closedown_time { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryQuery.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryQuery.cs new file mode 100644 index 00000000..86087362 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ClosedownHistoryQuery.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Filter; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 停机历史查询输入参数 + /// + public class ClosedownHistoryQuery : PageInputBase + { + /// + /// 开始时间 + /// + public DateTime? beginTime { get; set; } + /// + /// 结束时间 + /// + public DateTime? endTime { get; set; } + /// + /// 设备名称 + /// + public string eqpName { get; set; } + + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdCancelClosedownRecord.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdCancelClosedownRecord.cs index af59189b..9b1636a8 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdCancelClosedownRecord.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdCancelClosedownRecord.cs @@ -58,5 +58,19 @@ public partial class PrdCancelClosedownRecord : BaseEntity /// 停机结束时间 /// public DateTime? closedown_end_time { get; set; } + /// + /// 停机时间 + /// + public decimal? closedown_time { get; set; } + /// + /// 设备编码 + /// + public string eqp_code { get; set; } + /// + /// 设备名称 + /// + public string eqp_name { get; set; } + + } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs index 22bdcaf6..b38d7411 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -128,6 +129,54 @@ namespace Tnb.ProductionMgr } return result; } + /// + /// 获取停机历史记录 + /// + /// + /// + [HttpGet] + public async Task GetClosedownHistory([FromQuery] ClosedownHistoryQuery input) + { + var pagedList = await _db.Queryable() + .WhereIF(!string.IsNullOrEmpty(input.eqpName), it => it.eqp_name.Contains(input.eqpName)) + .WhereIF(input.beginTime.HasValue, it => it.closedown_start_time.Value == input.beginTime) + .WhereIF(input.endTime.HasValue, it => it.closedown_end_time.Value == input.endTime) + .Select(it => new ClosedownHistoryOutput + { + closedown_start_time = it.closedown_start_time, + closedown_end_time = it.closedown_end_time, + closedown_time = it.closedown_time, + }) + .ToPagedListAsync(input.currentPage, input.pageSize); + return pagedList; + } + /// + /// 根据设备id获取生产任务单信息,模具信息 + /// + /// 设备Id + /// + /// returns: + ///
{ + ///
mo_task_code:任务单编号 + ///
mold_code:模具编号 + ///
mold_name:模具名称 + ///
} + ///
+ [HttpGet] + public async Task GetInfoFromEqpId([FromRoute] string eqpId) + { + dynamic info = new ExpandoObject(); + var moTask = await _db.Queryable().Where(it => it.mo_task_status == DictConst.InProgressEnCode).FirstAsync(it => it.eqp_id == eqpId); + if (moTask != null) + { + var mold = await _db.Queryable().FirstAsync(it => it.id == moTask.mo_id); + info.mo_task_code = moTask.mo_task_code; + info.mold_code = mold?.mold_code; + info.mold_name = mold?.mold_name; + } + return info; + } + /// /// 异常停机-开始 @@ -145,7 +194,7 @@ namespace Tnb.ProductionMgr var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id); if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500); - if (moTaskList.Count > 0) + if (moTaskList?.Count > 0) { var cancelCloseDown = input.Adapt(); cancelCloseDown.id = SnowflakeIdHelper.NextId(); @@ -155,7 +204,10 @@ namespace Tnb.ProductionMgr cancelCloseDown.closedown_start_time = DateTime.Now; await _db.Insertable(cancelCloseDown).ExecuteCommandAsync(); + var eqp = await _db.Queryable().FirstAsync(it => it.id == input.eqp_id); var record = cancelCloseDown.Adapt(); + record.eqp_code = eqp?.code; + record.eqp_name = eqp?.name; await _db.Insertable(record).ExecuteCommandAsync(); var moldId = moTaskList.First().mold_id; @@ -179,13 +231,13 @@ namespace Tnb.ProductionMgr { Log.Error("停机开始失败", ex); await _db.Ado.RollbackTranAsync(); - throw ex; + throw; } } /// /// 停机结束 /// - /// + /// /// [HttpPost] public async Task CloseDownEnd(CloseDownStartInput input) @@ -196,46 +248,29 @@ namespace Tnb.ProductionMgr { await _db.Ado.BeginTranAsync(); - var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id); - if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500); - - var cancelCloseDown = input.Adapt(); - cancelCloseDown.id = SnowflakeIdHelper.NextId(); - cancelCloseDown.create_id = _userManager.UserId; - cancelCloseDown.create_time = DateTime.Now; - cancelCloseDown.closedown_start_time = DateTime.Now; - - var row = await _db.Insertable(cancelCloseDown).ExecuteCommandAsync(); - - var moldId = moTaskList.First().mold_id; - if (moldId.IsNullOrEmpty()) + var closeDown = await _db.Queryable().Where(it => it.eqp_id == input.eqp_id).OrderByDescending(it => it.closedown_start_time).FirstAsync(); + if (closeDown != null) { - var mold = await _moldService.GetListById(moldId); - var maintaindTask = new ToolMoldMaintainTask(); - maintaindTask.mold_id = moldId; - maintaindTask.code = DictConst.MaintainStatusYWCCode; - maintaindTask.create_id = _userManager.UserId; - maintaindTask.create_time = DateTime.Now; + closeDown.closedown_end_time = DateTime.Now; + await _db.Updateable(closeDown).ExecuteCommandAsync(); + var record = closeDown.Adapt(); + //计算停机时间间隔,以小时为单位 + if (record.closedown_start_time.HasValue && record.closedown_end_time.HasValue) + { + var interval = record.closedown_end_time.Value.Subtract(record.closedown_start_time.Value).TotalHours; + record.closedown_time = Convert.ToDecimal(interval); + } + await _db.Updateable(record).ExecuteCommandAsync(); - - await _maintainTaskService.Create(maintaindTask); + await _db.Ado.CommitTranAsync(); } - - await _db.Ado.CommitTranAsync(); } catch (Exception ex) { - Log.Error("停机开始失败", ex); + Log.Error("停机结束失败", ex); await _db.Ado.RollbackTranAsync(); + throw; } - //var row = await _db.Updateable().SetColumns(c => new ToolMoldMaintainTask - //{ - // status = DictConst.MaintainStatusDWXCode, - // modify_id = _userManager.UserId, - // modify_end_time = DateTime.Now, - //}) - // .ExecuteCommandAsync(); - //if (row < 1) throw Oops.Oh(ErrorCode.COM1001); } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 88efe23f..dc5a47f2 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -98,22 +98,22 @@ namespace Tnb.ProductionMgr [HttpGet("{materialId}")] public async Task GetMoldListByItemId(string materialId) { - var db = _repository.AsSugarClient(); - var list = await db.Queryable().InnerJoin((a, b) => a.material_id == b.id) - .Where((a, b) => a.material_id == materialId) - .Select((a, b) => new MoldListOutput - { - mold_id = a.id, - mold_code = a.mold_code, - mold_name = a.mold_name, - mold_type_code = a.mold_type_code, - material_name = b.name, - material_code = b.code, - available_stations = SqlFunc.Subqueryable().Where(it => it.mold_id == a.id).Count(), - }) - .ToListAsync(); - return list; - + var result = new List(); + result = await _db.Queryable() + .InnerJoin((a, b) => a.mold_id == b.id) + .InnerJoin((a, b, c) => a.material_id == c.id) + .Where((a, b, c) => a.material_id == materialId) + .Select((a, b, c) => new MoldListOutput + { + mold_id = a.id, + mold_code = b.mold_code, + mold_name = b.mold_name, + mold_type_code = b.mold_type_code, + material_name = c.name, + material_code = c.code, + available_stations = SqlFunc.Subqueryable().Where(it => it.mold_id == a.id).Count(), + }).ToListAsync(); + return result; } /// /// 根据模具Id获取设备列表 @@ -123,23 +123,21 @@ namespace Tnb.ProductionMgr [HttpGet("{moldId}")] public async Task GetEquipmentListByMoldId(string moldId) { - var items = await _repository.AsSugarClient().Queryable() - .Where(it => it.mold_id == moldId) - .Select(it => new EquipmentListOutput - { - eqp_id = it.id, - eqp_code = it.code, - eqp_type_code = SqlFunc.Subqueryable().Where(iit => iit.id == it.equip_type_id).Select(iit => iit.code), - eqp_machine_num = it.eqp_machine_num, - tonnage = it.tonnage, - task_list_qty = SqlFunc.Subqueryable().Where(x => x.eqp_id == it.id).Count(), - estimated_end_date = SqlFunc.Subqueryable().Where(x => x.eqp_id == it.id).OrderByDesc(o => o.plan_end_date).Select(x => x.plan_end_date) - }) - .Mapper(x => - { - x.first_date = x.estimated_end_date.HasValue ? x.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; - }) - .ToListAsync(); + var items = await _db.Queryable().InnerJoin((a, b) => a.equipment_id == b.id) + .Where((a, b) => a.mold_id == moldId) + .Select((a, b) => new EquipmentListOutput + { + eqp_id = b.id, + eqp_code = b.code, + eqp_type_code = SqlFunc.Subqueryable().Where(iit => iit.id == b.equip_type_id).Select(iit => iit.code), + eqp_machine_num = b.eqp_machine_num, + tonnage = b.tonnage, + task_list_qty = SqlFunc.Subqueryable().Where(x => x.eqp_id == b.id).Count(), + estimated_end_date = SqlFunc.Subqueryable().Where(x => x.eqp_id == b.id).OrderByDesc(o => o.plan_end_date).Select(x => x.plan_end_date) + }).Mapper(x => + { + x.first_date = x.estimated_end_date.HasValue ? x.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; + }).ToListAsync(); return items; } @@ -247,19 +245,17 @@ namespace Tnb.ProductionMgr materialProp = material != null ? material.material_property : ""; } - var res = await db.Queryable().Where(it => it.mo_task_code == mo_task_code) .Select(it => new PrdReportOutput { icmo_qty = it.icmo_qty, reported_work_qty = it.reported_work_qty, - //reported_qty = it.reported_qty, eqp_code = eqpCode, mold_code = moldCode, material_code = materialCode, material_name = materialName, prd_qty = it.prd_qty, - scrap_qty = SqlFunc.Subqueryable().Select(x => x.scrap_qty), + //scrap_qty = SqlFunc.Subqueryable().Select(x => x.scrap_qty), }) .Mapper(it => { @@ -274,9 +270,8 @@ namespace Tnb.ProductionMgr { icmo_qty = db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty, reported_work_qty = 0, - //reported_qty = 0, prd_qty = 0, - scrap_qty = 0, + //scrap_qty = 0, }; return res; } @@ -472,8 +467,6 @@ namespace Tnb.ProductionMgr return result; } - - #endregion @@ -602,81 +595,7 @@ namespace Tnb.ProductionMgr } return row > 0; } - /// - /// 获取组装包装排产任务列表 - /// - /// 拆解bom,生成组装包装任务列表,输入参数 - /// - /// output: - ///
{ - ///
workline_id:产线Id - ///
workline_name:产线名称 - ///
material_code:物料编码 - ///
material_name:物料名称 - ///
qty:输出料数量 - ///
} - ///
- [HttpPost] - public async Task GetPackSchedulingTaskList(UnPackSchedlingInput input) - { - if (_dicWorkLine.Count < 1) - { - _dicWorkLine = await _db.Queryable().Where(it => it.Category == "workline").ToDictionaryAsync(x => x.Id, x => x.FullName); - } - if (_dicProcess.Count < 1) - { - _dicProcess = await _db.Queryable().Select(it => new { id = it.id, process_name = it.process_name }).Distinct().ToDictionaryAsync(x => x.id, x => x.process_name); - } - var outputList = new List(); - var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); - if (bom != null && bom.route_id.IsNotEmptyOrNull()) - { - var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); - if (routes?.Count > 0) - { - var processIds = routes.Select(x => x.process_id).ToList(); - if (processIds?.Count > 0) - { - var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); - if (bomOutputs?.Count > 0) - { - foreach (var item in bomOutputs) - { - var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); - var output = new PackingSchedulingListOutput(); - output.mo_id = input.mo_id; - output.process_id = item.process_id; - output.workline_id = input.workline_id; - output.workline_name = _dicWorkLine.ContainsKey(input.workline_id) ? _dicWorkLine[input.workline_id].ToString() : ""; - output.process_name = _dicProcess[item.process_id]?.ToString(); - output.material_id = item.material_id; - output.material_code = material?.code; - output.material_name = material?.name; - output.qty = item.num; - outputList.Add(output); - } - } - } - } - } - //生成任务单号 - if (outputList.Count > 0) - { - var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); - if (mo != null && mo.mo_code.IsNotEmptyOrNull()) - { - var taskCodes = outputList.Where(it => it.mo_task_code.IsNotEmptyOrNull()).ToList(); - if (taskCodes == null || taskCodes.Count < 1) - { - for (int i = 1, len = outputList.Count; i <= len; i++) - { - outputList[i - 1].mo_task_code = $"{mo.mo_code}-{i.ToString().PadLeft(2, '0')}"; - } - } - } - } - return outputList; - } + /// /// 组装包装排产 /// @@ -700,7 +619,10 @@ namespace Tnb.ProductionMgr moTask.estimated_end_date = input.estimated_end_date; var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); var moCode = mo?.mo_code; - var taskCode = await _db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); + var taskCode = await _db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)) + .OrderByDescending(it => it.mo_task_code) + .Select(it => it.mo_task_code) + .FirstAsync(); if (taskCode!.IsNullOrEmpty()) { moTask.mo_task_code = $"{moCode}-01"; @@ -917,7 +839,6 @@ namespace Tnb.ProductionMgr var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); if (records != null && !records.Select(x => x.status).Contains(status)) { - taskLog.id = SnowflakeIdHelper.NextId(); taskLog.status = status; taskLogEntities.Add(taskLog); @@ -925,7 +846,6 @@ namespace Tnb.ProductionMgr } } row = await db.Insertable(taskLogEntities).ExecuteCommandAsync(); - } return (row > 0); } @@ -1128,8 +1048,6 @@ namespace Tnb.ProductionMgr { row["material_id"] = $"{material.code}/{material.name}"; } - - } //模具 if (dic.ContainsKey("mold_id")) @@ -1182,9 +1100,7 @@ namespace Tnb.ProductionMgr return row > 0; }); if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1002); - } - public async Task> GetListByEqpId(string eqpId) { return await _db.Queryable().Where(it => it.eqp_id == eqpId && it.mo_task_status == DictConst.InProgressEnCode).ToListAsync();