组装包装,生产排产代码调整

This commit is contained in:
DEVICE8\12494
2023-05-23 19:23:09 +08:00
parent 6ee558a3e4
commit f388692848
14 changed files with 632 additions and 155 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.BasicData.Entities.Dto
{
/// <summary>
/// 子工单列表
/// </summary>
public class SubBomListOutput
{
/// <summary>
/// 物料id
/// </summary>
public string material_id { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string material_code { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string material_name { get; set; }
/// <summary>
/// 物料型号
/// </summary>
public string material_category_code { get; set; }
/// <summary>
///输出数量
/// </summary>
public int output_qty { get; set; }
/// <summary>
/// 数量
/// </summary>
public string num { get; set;}
}
}

View File

@@ -1,7 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace Tnb.BasicData.Interfaces
{
public interface IBasMbomService
{
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id<69><64>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
/// </summary>
/// <param name="bomId">bomid</param>
/// <returns></returns>
Task<dynamic> GetSubMoListByBomId([FromRoute] string bomId);
}
}

View File

@@ -13,6 +13,8 @@ using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.BasicData.Interfaces;
using Tnb.BasicData.Entities.Dto;
using NPOI.OpenXmlFormats.Dml;
using JNPF.Common.Extension;
namespace Tnb.BasicData
{
@@ -29,6 +31,7 @@ namespace Tnb.BasicData
private readonly DataBaseManager _dbManager;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IUserManager _userManager;
private readonly ISqlSugarClient _db;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public BasMbomService(
@@ -41,6 +44,7 @@ namespace Tnb.BasicData
_dbManager = dbManager;
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
_db = repository.AsSugarClient();
// OverideFuncs.GetAsync = GetInfo;
OverideFuncs.GetListAsync = GetList;
}
@@ -79,6 +83,35 @@ namespace Tnb.BasicData
return PageResult<MbomListOutput>.SqlSugarPageResult(list);
}
/// <summary>
/// 根据bomid获取对应的子bom列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
public async Task<dynamic> GetSubMoListByBomId([FromRoute] string bomId)
{
if (string.IsNullOrEmpty(bomId)) throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty");
var result = await _db.Queryable<BasMbom>().LeftJoin<BasRouteD>((a, b) => a.route_id == b.route_id)
.LeftJoin<BasProcess>((a, b, c) => b.process_id == c.id)
.LeftJoin<BasMbomOutput>((a, b, c, d) => c.id == d.process_id)
.LeftJoin<BasMaterial>((a, b, c, d, e) => d.material_id == e.id)
.LeftJoin<BasMaterialCategory>((a, b, c, d, e, f) => e.category_id == f.id)
.Where((a, b, c, d, e, f) => a.id == bomId)
.Select((a, b, c, d, e, f) => new SubBomListOutput
{
material_id = e.id,
material_code = e.code,
material_name = e.name,
material_category_code = f.category_code,
num = d.num
})
.Mapper(it => it.output_qty = it.num.ParseToInt())
.Distinct()
.ToListAsync();
return result;
}
/// <summary>
/// 获取编辑信息
/// </summary>
@@ -125,6 +158,44 @@ namespace Tnb.BasicData
return mbomDataOutput;
}
/// <summary>
/// 根据物料id获取生产bom
/// </summary>
/// <param name="materialId"></param>
/// <remarks>
/// returns:
/// <br/>{
/// <br/> bom_id:bomid
/// <br/> material_code:物料编码
/// <br/> material_name:物料名称
/// <br/> start_time:有效开始时间
/// <br/> end_time:有效结束时间
/// <br/> version:bom版本
/// <br/> route_id:工艺路线id
/// <br/> route_name:工艺路线名称
/// <br/>}
/// </remarks>
[HttpGet]
public async Task<dynamic> GetMBomListByMaterialId([FromRoute] string materialId)
{
return await _db.Queryable<BasMbom>()
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
.LeftJoin<BasRouteH>((a, b, c) => a.route_id == c.id)
.Where((a, b, c) => a.material_id == materialId)
.Select((a, b, c) => new
{
bom_id = a.id,
material_code = b.code,
material_name = b.name,
start_time = a.start_time.HasValue ? a.start_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : null,
end_time = a.end_time.HasValue ? a.end_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : null,
version = a.version,
route_id = c.id,
route_name = c.name,
})
.ToListAsync();
}
/// <summary>
/// 保存生产bom
/// </summary>

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.EquipMgr.Interfaces
{
public interface IToolMoldMaintainPlanRunService
{
}
}

View File

@@ -83,111 +83,7 @@ namespace Tnb.EquipMgr
})
.ToListAsync();
}
[HttpGet]
public async Task<dynamic> GetMaintainInfoFromByPlanId([FromRoute] string planId)
{
dynamic info = new ExpandoObject();
var planMoldRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.id == planId);
if (planMoldRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().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<ToolMoldsEquipment>().FirstAsync(it => it.mold_id == mold.id);
if (moldEqpRelation != null)
{
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moldEqpRelation.equipment_id);
info.eqp_code = eqp.code;
info.eqp_name = eqp.name;
}
var itemGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (itemGroupRelation != null)
{
var itemGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == itemGroupRelation.item_group_id);
if (itemGroup != null)
{
info.item_group_name = itemGroup.name;
}
var itemRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == itemGroupRelation.item_group_id);
if (itemRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().FirstAsync(it => it.id == itemRelation.item_id);
if (checkItem != null)
{
info.item_name = checkItem.name;
}
}
}
}
}
return info;
}
/// <summary>
/// 模具保养计划执行-开始模具保养
/// </summary>
/// <param name="input">
/// {
/// plan_id:执行计划id
/// }
/// </param>
/// <returns></returns>
[HttpPost]
public async Task MaintainStart(MoldMaintainRunUpInput input)
{
try
{
await _db.Ado.BeginTranAsync();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId);
var plan = await _db.Queryable<ToolMoldMaintainPlan>().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<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.maintain_plan_id == input.plan_id);
if (moldPlanRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == moldPlanRelation.mold_id);
record.mold_code = mold?.mold_code;
record.mold_name = mold?.mold_name;
var moldGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (moldGroupRelation != null)
{
var maintainGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == moldGroupRelation.item_group_id);
record.group_name = maintainGroup.name;
var itemGrpRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == maintainGroup.id);
if (itemGrpRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().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;
}
}
/// <summary>
/// 关联模具

View File

@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells.Drawing;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
using Tnb.EquipMgr.Interfaces;
namespace Tnb.EquipMgr
{
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class ToolMoldMaintainPlanRunService : IToolMoldMaintainPlanRunService, IDynamicApiController, ITransient
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
private readonly IDictionaryDataService _dictionaryDataService;
public ToolMoldMaintainPlanRunService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager, IDictionaryDataService dictionaryDataService)
{
_db = repository.AsSugarClient();
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
}
/// <summary>
/// 根据计划id,获取相关联模具、设备、保养项目组、保养项,信息
/// </summary>
/// <param name="planId"></param>
/// <returns></returns>
[HttpGet]
public async Task<dynamic> GetMaintainInfoFromByPlanId([FromRoute] string planId)
{
dynamic info = new ExpandoObject();
var planMoldRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.id == planId);
if (planMoldRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().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<ToolMoldsEquipment>().FirstAsync(it => it.mold_id == mold.id);
if (moldEqpRelation != null)
{
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moldEqpRelation.equipment_id);
info.eqp_code = eqp.code;
info.eqp_name = eqp.name;
}
var itemGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (itemGroupRelation != null)
{
var itemGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == itemGroupRelation.item_group_id);
if (itemGroup != null)
{
info.item_group_name = itemGroup.name;
}
var itemRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == itemGroupRelation.item_group_id);
if (itemRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().FirstAsync(it => it.id == itemRelation.item_id);
if (checkItem != null)
{
info.item_name = checkItem.name;
}
}
}
}
}
return info;
}
/// <summary>
/// 模具保养计划执行-开始模具保养
/// </summary>
/// <param name="input">
/// {
/// plan_id:执行计划id
/// }
/// </param>
/// <returns></returns>
[HttpPost]
public async Task MaintainStart(MoldMaintainRunUpInput input)
{
try
{
await _db.Ado.BeginTranAsync();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId);
var plan = await _db.Queryable<ToolMoldMaintainPlan>().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<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.maintain_plan_id == input.plan_id);
if (moldPlanRelation != null)
{
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == moldPlanRelation.mold_id);
record.mold_code = mold?.mold_code;
record.mold_name = mold?.mold_name;
var moldGroupRelation = await _db.Queryable<ToolMoldMaintainGroupRelation>().FirstAsync(it => it.mold_id == mold.id);
if (moldGroupRelation != null)
{
var maintainGroup = await _db.Queryable<ToolMoldMaintainGroup>().FirstAsync(it => it.id == moldGroupRelation.item_group_id);
record.group_name = maintainGroup.name;
var itemGrpRelation = await _db.Queryable<ToolMoldMaintainGroupItem>().FirstAsync(it => it.item_group_id == maintainGroup.id);
if (itemGrpRelation != null)
{
var checkItem = await _db.Queryable<ToolMoldMaintainItem>().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;
}
}
/// <summary>
/// 模具保养计划执行-保养完成
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task MaintainFinish(MoldMaintainRunUpInput input)
{
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells.Drawing;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.DependencyInjection;
@@ -47,9 +48,11 @@ namespace Tnb.EquipMgr
_runService = runService;
_visualDevService = visualDevService;
OverideFuncs.GetListAsync = GetList;
//OverideFuncs.CreateAsync = Create;
}
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
if (_dicMold.Count < 1)

View File

@@ -8,14 +8,22 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
{
public class ClosedownHistoryOutput
{
/// <summary>
/// 设备编码
/// </summary>
public string eqp_code { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string eqp_name { get; set; }
/// <summary>
/// 停机开始时间
/// </summary>
public DateTime? closedown_start_time { get; set; }
public string? closedown_start_time { get; set; }
/// <summary>
/// 停机结束时间
/// </summary>
public DateTime? closedown_end_time { get; set; }
public string? closedown_end_time { get; set; }
/// <summary>
/// 停机时间
/// </summary>

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
{
public class GenSubMoCrInput
{
/// <summary>
/// 父工单id
/// </summary>
public string mo_id { get; set; }
/// <summary>
/// 子物料ids
/// </summary>
public List<string> ids { get; set; }
}
//public class SubMo
//{
// /// <summary>
// /// 物料id
// /// </summary>
// public string material_id { get; set; }
// /// <summary>
// /// 物料编码
// /// </summary>
// public string material_code { get; set; }
// /// <summary>
// /// 物料名称
// /// </summary>
// public string material_name { get; set; }
// /// <summary>
// /// 物料型号
// /// </summary>
// public string material_category_code { get; set; }
// /// <summary>
// ///输出数量
// /// </summary>
// public int output_qty { get; set; }
//}
}

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Security;
namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
{
public class PrdMotreeOutput : TreeModel
{
public string? org_id { get; set; }
/// <summary>
/// 工单id
/// </summary>
public string mo_id { get; set; }
/// <summary>
/// 工单代码
/// </summary>
public string mo_code { get; set; } = string.Empty;
/// <summary>
/// 物料编号
/// </summary>
public string? material_code { get; set; }
/// <summary>
/// 工单类型1-正常工单、2-返工工单、3-试制工单
/// </summary>
public string? mo_type { get; set; }
/// <summary>
/// 生产状态 Initial: 初始, Confirm:确认 Release: 下发, Open: 生产中, Close: 关单, Pending: 暂停
/// </summary>
public string? mo_status { get; set; }
/// <summary>
/// 计划生产数量
/// </summary>
public int? plan_qty { get; set; }
/// <summary>
/// 已投入数量
/// </summary>
public int? input_qty { get; set; }
/// <summary>
/// 已完工数量
/// </summary>
public int? complete_qty { get; set; }
/// <summary>
/// 报废数量
/// </summary>
public int? scrap_qty { get; set; }
/// <summary>
/// 计划开始时间
/// </summary>
public DateTime? plan_start_date { get; set; }
/// <summary>
/// 计划结束时间
/// </summary>
public DateTime? plan_end_date { get; set; }
/// <summary>
/// 是否生派工单
/// </summary>
public int? is_create_dispatch { get; set; }
/// <summary>
/// 产线代码
/// </summary>
public string? production_linecode { get; set; }
/// <summary>
/// 是否合并
/// </summary>
public int? is_merge { get; set; }
/// <summary>
/// 组合工单
/// </summary>
public string? combine_mo_code { get; set; }
/// <summary>
/// 时间戳
/// </summary>
public string? time_stamp { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 物料ID
/// </summary>
public string? material_id { get; set; }
/// <summary>
/// 已排产数量
/// </summary>
public int? scheduled_qty { get; set; }
/// <summary>
/// 父工单id
/// </summary>
public string parent_id { get; set; }
}
}

View File

@@ -218,5 +218,9 @@ public partial class PrdMo : BaseEntity<string>
/// 已排产数量
/// </summary>
public int? scheduled_qty { get; set; }
/// <summary>
/// 父工单id
/// </summary>
public string parent_id { get; set; }
}

View File

@@ -139,15 +139,17 @@ namespace Tnb.ProductionMgr
{
var pagedList = await _db.Queryable<PrdCancelClosedownRecord>()
.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)
.WhereIF(input.beginTime.HasValue, it => it.closedown_start_time.Value >= input.beginTime)
.WhereIF(input.endTime.HasValue, it => it.closedown_start_time.Value <= input.endTime)
.Select(it => new ClosedownHistoryOutput
{
closedown_start_time = it.closedown_start_time,
closedown_end_time = it.closedown_end_time,
eqp_code = it.eqp_code,
eqp_name = it.eqp_name,
closedown_start_time = it.closedown_start_time.HasValue ? it.closedown_start_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : null,
closedown_end_time = it.closedown_end_time.HasValue ? it.closedown_end_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : null,
closedown_time = it.closedown_time,
})
.ToPagedListAsync(input.currentPage, input.pageSize);
.ToListAsync();
return pagedList;
}
/// <summary>
@@ -216,8 +218,9 @@ namespace Tnb.ProductionMgr
var mold = await _moldService.GetListById(moldId);
var maintaindTask = new ToolMoldMaintainTask();
maintaindTask.mold_id = moldId;
maintaindTask.code = DictConst.MaintainStatusDWXCode;
maintaindTask.code = mold.mold_code;
maintaindTask.create_id = _userManager.UserId;
maintaindTask.status = DictConst.UnMaintainStatusCode;
maintaindTask.create_time = DateTime.Now;
await _maintainTaskService.Create(maintaindTask);

View File

@@ -49,6 +49,7 @@ namespace Tnb.ProductionMgr
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private readonly ISqlSugarClient _db;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
@@ -67,6 +68,7 @@ namespace Tnb.ProductionMgr
_dictionaryDataService = dictionaryDataService;
_runService = runService;
_visualDevService = visualDevService;
_db = _repository.AsSugarClient();
OverideFuncs.GetListAsync = GetList;
}
@@ -241,6 +243,8 @@ namespace Tnb.ProductionMgr
.ExecuteCommandHasChangeAsync();
}
#endregion
}
}

View File

@@ -466,6 +466,35 @@ namespace Tnb.ProductionMgr
.ToListAsync();
return result;
}
/// <summary>
/// 获取组装、包装 待排产工单树形列表
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<dynamic> GetUnSchedulingList()
{
List<PrdMotreeOutput> trees = new();
var list = await _db.Queryable<PrdMo>().Where(it => string.IsNullOrEmpty(it.parent_id) && it.mo_status == DictConst.ScheduledId).ToListAsync();
foreach (var item in list)
{
var node = item.Adapt<PrdMotreeOutput>();
node.mo_id = item.id;
node.id = SnowflakeIdHelper.NextId();
node.parentId = "0";
var items = await _db.Queryable<PrdMo>().Where(it => it.parent_id == item.id).ToListAsync();
if (items?.Count() > 0)
{
var childNodes = items.Adapt<List<PrdMotreeOutput>>();
for (int i = 0; i < items.Count; i++)
{
childNodes[i].mo_id = items[i].id;
}
trees.AddRange(childNodes);
}
trees.Add(node);
}
return trees.ToTree();
}
#endregion
@@ -653,6 +682,24 @@ namespace Tnb.ProductionMgr
taskLog.mo_task_id = moTask.id;
taskLog.mo_task_code = moTask.mo_task_code!;
row = await _db.Insertable(taskLog).ExecuteCommandAsync();
//将生产任务插入到自检报废记录表
//var sacipRecord = new PrdMoTaskDefectRecord();
//sacipRecord.id = SnowflakeIdHelper.NextId();
//sacipRecord.material_code = material?.code!;
//sacipRecord.material_name = material?.name!;
//sacipRecord.eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moTask.eqp_id))?.code!;
//sacipRecord.mold_name = (await db.Queryable<ToolMolds>().FirstAsync(it => it.id == moTask.mold_id))?.mold_name!;
//sacipRecord.estimated_start_date = moTask.plan_start_date;
//sacipRecord.estimated_end_date = moTask.plan_end_date;
//sacipRecord.plan_qty = moTask.plan_qty;
//sacipRecord.scrap_qty = moTask.scrap_qty;
//sacipRecord.status = moTask.mo_task_status;
//sacipRecord.create_id = _userManager.UserId;
//sacipRecord.create_time = DateTime.Now;
//sacipRecord.mo_task_id = moTask.id;
//sacipRecord.mo_task_code = moTask.mo_task_code;
//await db.Insertable(sacipRecord).ExecuteCommandAsync();
//根据工单号获取当前工单包含的已排产数
var schedQty = _db.Queryable<PrdMoTask>().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty);
if (mo != null)
@@ -1026,6 +1073,54 @@ namespace Tnb.ProductionMgr
return row > 0;
}
/// <summary>
/// 生成子工单
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task GenSubMo(GenSubMoCrInput input)
{
if (input is null) throw new ArgumentNullException("input");
if (input.ids is null || input.ids.Count == 0) throw new ArgumentException($"{nameof(input.ids)} not be null or count zero");
var curMo = await _db.Queryable<PrdMo>().FirstAsync(it => it.id == input.mo_id);
if (curMo == null) throw new ArgumentNullException("创建子工单时的父工单不能为null");
List<PrdMo> subMoList = new();
var outputMaterials = await _db.Queryable<BasMaterial>().LeftJoin<BasMbomOutput>((a, b) => a.id == b.material_id)
.Where((a, b) => input.ids.Contains(a.id))
.Select((a, b) => new
{
material_id = a.id,
material_code = a.code,
num = b.num,
})
.ToListAsync();
foreach (var om in outputMaterials)
{
PrdMo subMo = new();
subMo.material_id = om.material_id;
subMo.material_code = om.material_code;
subMo.plan_qty = om.num.ParseToInt() * curMo.plan_qty;
subMo.mo_type = curMo.mo_type;
subMo.parent_id = curMo.id;
subMo.plan_start_date = curMo.plan_start_date;
subMo.plan_end_date = curMo.plan_end_date;
subMo.create_id = _userManager.UserId;
subMo.create_time = DateTime.Now;
subMo.mo_status = DictConst.WaitProductId;
subMoList.Add(subMo);
}
//生成子工单编码
for (int i = 0; i < subMoList.Count; i++)
{
var num = (i + 1).ToString().PadLeft(2, '0');
subMoList[i].mo_code = $"{subMoList[i].mo_code}-{num}";
}
var row = await _db.Insertable(subMoList).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
}
#endregion