生产管理新增,同组工单下发,取消同组工单

This commit is contained in:
DEVICE8\12494
2023-04-25 15:54:27 +08:00
parent 32898552dc
commit 967c013d16
7 changed files with 447 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
@@ -13,6 +14,7 @@ using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NPOI.OpenXmlFormats.Shared;
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
using SqlSugar;
using Tnb.ProductionMgr.Entitys.Dto.PrdManage;
using Tnb.ProductionMgr.Entitys.Dto.WorkOrder;
@@ -26,8 +28,8 @@ namespace Tnb.ProductionPlanMgr
/// <summary>
/// 生产计划管理
/// </summary>
[ApiDescriptionSettings(Tag = "ProductionMgr", Name = "WorkOrderCreate", Order = 700)]
[Route("api/production/[controller]")]
[ApiDescriptionSettings(Tag = "ProductionMgr", Area = "production", Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class PrdMoService : IPrdMoService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<PrdMo> _repository;
@@ -59,9 +61,18 @@ namespace Tnb.ProductionPlanMgr
{
throw new ArgumentNullException(nameof(input));
}
var db = _repository.AsSugarClient();
//获取同组工单的Id一起下发
var combineMoCodes = await db.Queryable<PrdMo>().Where(it => input.WorkOrderIds.Contains(it.id)).Select(it => it.combine_mo_code).ToListAsync();
if (combineMoCodes?.Count > 0)
{
var moIds = await db.Queryable<PrdMo>().Where(it => combineMoCodes.Contains(it.combine_mo_code) && !input.WorkOrderIds.Contains(it.id)).Select(it => it.id).ToListAsync();
input.WorkOrderIds = input.WorkOrderIds.Concat(moIds).ToList();
}
var row = await db.Updateable<PrdMo>()
.SetColumns(it => new PrdMo { mo_status = "25019232867093" })
.SetColumns(it => new PrdMo { mo_status = DictionaryConstants.IssueId })
.Where(it => input.WorkOrderIds.Contains(it.id))
.ExecuteCommandAsync();
return (row > 0);
@@ -74,31 +85,73 @@ namespace Tnb.ProductionPlanMgr
[HttpPost("relevancy")]
public async Task<dynamic> RelevancySameGroupMo(MoCrInput input)
{
var row = -1;
(bool executeRes, string errMsg) multi = (true, "");
var list = await _repository.AsSugarClient().Queryable<PrdMo>()
.InnerJoin<Molds>((a, b) => a.item_code == b.item_code)
.InnerJoin<Molds>((a, b) => a.item_code == b.item_id)
.Where((a, b) => input.WorkOrderIds.Contains(a.id))
.Select((a, b) => new
{
planDate = a.plan_start_date,
moldId = b.id,
mold_code = b.mold_code,
}).ToListAsync();
var planDateAll = true;
var moldIdAll = true;
if (list?.Count > 0)
{
var planDate = list.FirstOrDefault()?.planDate;
var moId = list.FirstOrDefault()?.moldId;
var moldCode = list.FirstOrDefault()?.mold_code;
var all = list.Skip(1).All(x => x.planDate == planDate && x.moldId == moId);
if (all)
planDateAll = list.Skip(1).All(x => x.planDate == planDate);
moldIdAll = list.Skip(1).All(x => x.mold_code == moldCode);
if (planDateAll && moldIdAll)
{
var groupId = SnowflakeIdHelper.NextId();
row = await _repository.AsSugarClient().Updateable<PrdMo>()
.SetColumns(c => new PrdMo { mo_group_no = groupId })
multi.executeRes = await _repository.AsSugarClient().Updateable<PrdMo>()
.SetColumns(c => new PrdMo { combine_mo_code = groupId })
.Where(it => input.WorkOrderIds.Contains(it.id))
.ExecuteCommandAsync();
.ExecuteCommandHasChangeAsync();
}
else
{
multi.executeRes = false;
if (!planDateAll)
{
throw new AppFriendlyException("计划开始日期不一致", null);
}
if (!moldIdAll)
{
throw new AppFriendlyException("未关联到同一模具下", null);
}
}
}
else
{
multi.executeRes = false;
if (!planDateAll)
{
throw new AppFriendlyException("计划开始日期不一致", null);
}
if (!moldIdAll)
{
throw new AppFriendlyException("未关联到同一模具下", null);
}
}
return row > 0;
return multi;
}
/// <summary>
/// 取消关联
/// </summary>
/// <param name="input">取消关联输入参数</param>
/// <returns></returns>
[HttpPost("CanelRelevancy")]
public async Task<dynamic> CanelRelevancy(MoCrInput input)
{
return await _repository.AsSugarClient().Updateable<PrdMo>()
.SetColumns(c => new PrdMo { combine_mo_code = "" })
.Where(it => input.WorkOrderIds.Contains(it.id))
.ExecuteCommandHasChangeAsync();
}
@@ -139,7 +192,7 @@ namespace Tnb.ProductionPlanMgr
{
await db.Ado.BeginTranAsync();
row = await db.Storageable(entity).ExecuteCommandAsync();
var taskLogEntity = input.Adapt<PrdTaskLog>();
taskLogEntity.id ??= SnowflakeIdHelper.NextId();
@@ -236,13 +289,36 @@ namespace Tnb.ProductionPlanMgr
mold_code = a.mold_code,
mold_name = a.mold_name,
item_name = b.item_name,
item_code = b.item_code,
cavity_qty = a.cavity_qty,
item_code = b.item_code,
})
.ToListAsync();
return list;
}
/// <summary>
/// 根据模具Id获取设备列表
/// </summary>
/// <param name="moldId"></param>
/// <returns></returns>
[HttpGet("equipments/{moldId}")]
public async Task<dynamic> GetEquipmentListByMoldId(string moldId)
{
var items = await _repository.AsSugarClient().Queryable<EqpEquipment>()
.InnerJoin<PrdTask>((a, b) => a.id == b.eqp_id)
.Where((a, b) => a.mold_id == moldId)
.Select((a, b) => new
{
eqp_code = a.eqp_code,
eqp_type_code = a.eqp_type_code,
tonnage = b.tonnage,
task_list_qty = SqlFunc.Subqueryable<PrdTask>().Where(it => it.eqp_id == a.id).Count(),
first_date = SqlFunc.Subqueryable<PrdTask>().Where(it => it.eqp_id == a.id).OrderByDesc(o => o.estimated_end_date).Select(it => it.estimated_end_date)
}).ToListAsync();
return items;
}
/// <summary>
/// 工单调整-生产任务重新排序
/// </summary>