using System.Dynamic;
using JNPF.Common.Core.Manager;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.System;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NPOI.OpenXmlFormats.Shared;
using SqlSugar;
using Tnb.ProductionMgr.Entitys.Dto.PrdManage;
using Tnb.ProductionMgr.Entitys.Dto.WorkOrder;
using Tnb.ProductionMgr.Entitys.Entity;
using Tnb.ProductionPlanMgr.Entitys.Dto.WorkOrder;
using Tnb.ProductionPlanMgr.Interfaces;
namespace Tnb.ProductionPlanMgr
{
///
/// 生产计划管理
///
[ApiDescriptionSettings(Tag = "ProductionMgr", Name = "WorkOrderCreate", Order = 700)]
[Route("api/production/[controller]")]
public class PrdMoService : IPrdMoService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository _repository;
private readonly IDataBaseManager _dataBaseManager;
private readonly IUserManager _userManager;
public PrdMoService(ISqlSugarRepository repository, IDataBaseManager dataBaseManager,IUserManager userManager)
{
_repository = repository;
_dataBaseManager = dataBaseManager;
_userManager = userManager;
}
///
/// 生产工单创建-生产工单下发
///
/// 生产工单下发输入参数
///
[HttpPut("workorder-issue")]
public async Task WorkOrderIssue(MoCrInput input)
{
if (input is null)
{
throw new ArgumentNullException(nameof(input));
}
var db = await GetDbContext();
var row = await db.Updateable()
.SetColumns(it => new PrdMoEntity { MoStatus = "25019232867093" })
.Where(it => input.WorkOrderIds.Contains(it.Id))
.ExecuteCommandAsync();
return (row > 0);
}
///
/// 生产工单-生产排产
///
///
///
{
///
Id:生产任务主键Id
///
MoType:工单类型 1、注塑/挤出 2、组装/包装
///
MoId:工单Id
///
ItemId:产品编号
///
ItemName:产品名称
///
MoldId:模具Id
///
MoldName:模具名称
///
EqpId:设备Id
///
EqpName:设备名称
///
LineId:产线编号
///
LineName:产线名称
///
}
///
///
[HttpPost("scheduling")]
public async Task ProductionScheduling(ProductionSchedulingCrInput input)
{
var entity = input.Adapt();
entity.id ??= SnowflakeIdHelper.NextId();
entity.status = "ToBeScheduled"; //任务单状态默认,待排产
entity.create_id = _userManager.UserId;
entity.create_time = DateTime.Now;
var db = await GetDbContext();
var row = await db.Storageable(entity).ExecuteCommandAsync();
if (row > 0)
{
//修改工单状态为已排产,同事修改已排产数量
row = await db.Updateable().SetColumns(it => new PrdMoEntity
{
MoStatus = "25019252113685",
InputQty = entity.scheduled_num
})
.Where(it => it.Id == entity.mo_id).ExecuteCommandAsync();
}
return row > 0;
}
///
/// 生产任务下发
///
///
[HttpPost("task-release")]
public async Task PrdTaskRelease(PrdTaskReleaseUpInput input)
{
if (input is null)
{
throw new ArgumentNullException(nameof(input));
}
var db = await GetDbContext();
var row = await db.Updateable()
.SetColumns(it => new PrdTask { status = "ToBeStarted" })
.Where(it => input.TaskIds.Contains(it.id))
.ExecuteCommandAsync();
return (row > 0);
}
///
/// 根据产品ID获取模具列表
///
/// 产品ID
///
[HttpGet("moldlist/{itemId}")]
public async Task GetMoldListByItemId(string itemId)
{
var db = await GetDbContext("tnb_mom");
List items = await db.Queryable