生产管理-生产工单排产代码调整
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
using System.Dynamic;
|
||||
using Aop.Api.Domain;
|
||||
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.Logging;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -26,14 +29,22 @@ namespace Tnb.ProductionPlanMgr
|
||||
[Route("api/production/[controller]")]
|
||||
public class PrdMoService : IPrdMoService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<PrdMoEntity> _repository;
|
||||
private readonly ISqlSugarRepository<PrdMo> _repository;
|
||||
private readonly IDataBaseManager _dataBaseManager;
|
||||
private readonly IUserManager _userManager;
|
||||
public PrdMoService(ISqlSugarRepository<PrdMoEntity> repository, IDataBaseManager dataBaseManager,IUserManager userManager)
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
|
||||
public PrdMoService(
|
||||
ISqlSugarRepository<PrdMo> repository,
|
||||
IDataBaseManager dataBaseManager,
|
||||
IUserManager userManager,
|
||||
IDictionaryDataService dictionaryDataService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_dataBaseManager = dataBaseManager;
|
||||
_userManager = userManager;
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 生产工单创建-生产工单下发
|
||||
@@ -47,13 +58,49 @@ namespace Tnb.ProductionPlanMgr
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
var db = await GetDbContext();
|
||||
var row = await db.Updateable<PrdMoEntity>()
|
||||
.SetColumns(it => new PrdMoEntity { MoStatus = "25019232867093" })
|
||||
.Where(it => input.WorkOrderIds.Contains(it.Id))
|
||||
.ExecuteCommandAsync();
|
||||
var db = _repository.AsSugarClient();
|
||||
var row = await db.Updateable<PrdMo>()
|
||||
.SetColumns(it => new PrdMo { mo_status = "25019232867093" })
|
||||
.Where(it => input.WorkOrderIds.Contains(it.id))
|
||||
.ExecuteCommandAsync();
|
||||
return (row > 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// 关联同组工单
|
||||
/// </summary>
|
||||
/// <param name="input">关联同组工单输入参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("relevancy")]
|
||||
public async Task<dynamic> RelevancySameGroupMo(MoCrInput input)
|
||||
{
|
||||
var row = -1;
|
||||
var list = await _repository.AsSugarClient().Queryable<PrdMo>()
|
||||
.InnerJoin<Molds>((a, b) => a.item_code == b.item_code)
|
||||
.Where((a, b) => input.WorkOrderIds.Contains(a.id))
|
||||
.Select((a, b) => new
|
||||
{
|
||||
planDate = a.plan_start_date,
|
||||
moldId = b.id,
|
||||
}).ToListAsync();
|
||||
if (list?.Count > 0)
|
||||
{
|
||||
var planDate = list.FirstOrDefault()?.planDate;
|
||||
var moId = list.FirstOrDefault()?.moldId;
|
||||
|
||||
var all = list.Skip(1).All(x => x.planDate == planDate && x.moldId == moId);
|
||||
if (all)
|
||||
{
|
||||
var groupId = SnowflakeIdHelper.NextId();
|
||||
row = await _repository.AsSugarClient().Updateable<PrdMo>()
|
||||
.SetColumns(c => new PrdMo { mo_group_no = groupId })
|
||||
.Where(it => input.WorkOrderIds.Contains(it.id))
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
return row > 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生产工单-生产排产
|
||||
/// </summary>
|
||||
@@ -77,23 +124,49 @@ namespace Tnb.ProductionPlanMgr
|
||||
[HttpPost("scheduling")]
|
||||
public async Task<dynamic> ProductionScheduling(ProductionSchedulingCrInput input)
|
||||
{
|
||||
var entity = input.Adapt<PrdTask>();
|
||||
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)
|
||||
var row = -1;
|
||||
if (input.mo_type.HasValue && input.mo_type.Value == 1)
|
||||
{
|
||||
//修改工单状态为已排产,同事修改已排产数量
|
||||
row = await db.Updateable<PrdMoEntity>().SetColumns(it => new PrdMoEntity
|
||||
input.id ??= SnowflakeIdHelper.NextId();
|
||||
var entity = input.Adapt<PrdTask>();
|
||||
entity.status = "ToBeScheduled"; //任务单状态默认,待排产
|
||||
entity.create_id = _userManager.UserId;
|
||||
entity.create_time = DateTime.Now;
|
||||
|
||||
var db = _repository.AsSugarClient();
|
||||
try
|
||||
{
|
||||
MoStatus = "25019252113685",
|
||||
InputQty = entity.scheduled_num
|
||||
})
|
||||
.Where(it => it.Id == entity.mo_id).ExecuteCommandAsync();
|
||||
await db.Ado.BeginTranAsync();
|
||||
row = await db.Storageable(entity).ExecuteCommandAsync();
|
||||
var taskLogEntity = input.Adapt<PrdTaskLog>();
|
||||
taskLogEntity.id ??= SnowflakeIdHelper.NextId();
|
||||
taskLogEntity.status ??= "ToBeStarted";
|
||||
taskLogEntity.create_id = _userManager.UserId;
|
||||
taskLogEntity.create_time = DateTime.Now;
|
||||
taskLogEntity.operator_name = _userManager.RealName;
|
||||
|
||||
//任务状态变更时插入操作记录
|
||||
if (!db.Queryable<PrdTaskLog>().Where(it => it.task_id == input.id && it.status == taskLogEntity.status).Any())
|
||||
{
|
||||
row = await db.Insertable(taskLogEntity).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
//修改工单状态为已排产,同事修改已排产数量
|
||||
row = await db.Updateable<PrdMo>().SetColumns(it => new PrdMo
|
||||
{
|
||||
mo_status = "25019252113685",
|
||||
input_qty = entity.scheduled_num
|
||||
})
|
||||
.Where(it => it.id == entity.mo_id).ExecuteCommandAsync();
|
||||
}
|
||||
await db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("生产任务发布时发生错误", ex);
|
||||
await db.Ado.RollbackTranAsync();
|
||||
}
|
||||
}
|
||||
return row > 0;
|
||||
}
|
||||
@@ -108,7 +181,7 @@ namespace Tnb.ProductionPlanMgr
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
var db = await GetDbContext();
|
||||
var db = _repository.AsSugarClient(); ;
|
||||
var row = await db.Updateable<PrdTask>()
|
||||
.SetColumns(it => new PrdTask { status = "ToBeStarted" })
|
||||
.Where(it => input.TaskIds.Contains(it.id))
|
||||
@@ -118,36 +191,63 @@ namespace Tnb.ProductionPlanMgr
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据产品ID获取模具列表
|
||||
/// </summary>
|
||||
/// <param name="itemId">产品ID</param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// <br/>return results:
|
||||
/// <br/>[
|
||||
/// <br/> {
|
||||
/// <br/> mold_code:模具编号
|
||||
/// <br/> mold_name:模具名称
|
||||
/// <br/> item_name:产品名称
|
||||
/// <br/> item_code:产品编号
|
||||
/// <br/> cavity_num:模穴数
|
||||
/// <br/> }
|
||||
/// <br/>]
|
||||
/// </remarks>
|
||||
[HttpGet("moldlist/{itemId}")]
|
||||
public async Task<dynamic> GetMoldListByItemId(string itemId)
|
||||
{
|
||||
var db = await GetDbContext("tnb_mom");
|
||||
List<dynamic> items = await db.Queryable<object>().AS("bas_item").Select(new List<SelectModel>()
|
||||
{
|
||||
new SelectModel{ FiledName="id" },
|
||||
new SelectModel{ FiledName="item_name" },
|
||||
}).ToListAsync();
|
||||
var itemDic = items.ToDictionary(x => x.id, x => x.item_name);
|
||||
db = await GetDbContext("tnb_eqp");
|
||||
var moldList = await db.Queryable<Molds>().Where(it => it.item_id == itemId).ToListAsync();
|
||||
var list = moldList.Adapt<List<MoldListOutput>>();
|
||||
db.ThenMapper(list, x => x.item_name = itemDic.ContainsKey(x.item_id) ? itemDic[x.item_id] : "");
|
||||
|
||||
var db = _repository.AsSugarClient();
|
||||
var list = await db.Queryable<Molds>().InnerJoin<BasItem>((a, b) => a.item_id == b.id)
|
||||
.Where((a, b) => a.item_id == itemId)
|
||||
.Select((a, b) => new MoldListOutput
|
||||
{
|
||||
id = a.id,
|
||||
mold_code = a.mold_code,
|
||||
mold_name = a.mold_name,
|
||||
item_name = b.item_name,
|
||||
item_code = b.item_code,
|
||||
cavity_num = a.cavity_num,
|
||||
})
|
||||
.ToListAsync();
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task<ISqlSugarClient> GetDbContext(string dbName = "tnb_mes")
|
||||
/// <summary>
|
||||
/// 查看工单操作记录
|
||||
/// </summary>
|
||||
/// <param name="input">操作记录查询输入参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("record/{moId}")]
|
||||
public async Task<dynamic> GetMoOperRecord(PrdTaskOperInput input)
|
||||
{
|
||||
var link = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == dbName);
|
||||
var db = _dataBaseManager.ChangeDataBase(link);
|
||||
return db;
|
||||
var list = await _repository.AsSugarClient().Queryable<PrdTask>().LeftJoin<PrdTaskLog>((a, b) => a.prd_task_id == b.id)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.mo_no), a => a.mo_id == input.mo_no)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.task_no), b => b.prd_task_id == input.task_no)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.item_code), a => a.item_code == input.item_code)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.eqp_code), a => a.eqp_type_code == input.eqp_code)
|
||||
.WhereIF(input.plan_start_date.HasValue, a => a.plan_start_date >= input.plan_start_date!.Value)
|
||||
.WhereIF(input.plan_end_date.HasValue, a => a.plan_end_date <= input.plan_end_date!.Value)
|
||||
.ToListAsync();
|
||||
var data = list.Adapt<List<PrdTaskOperOutput>>();
|
||||
var dic = await _dictionaryDataService.GetDicByTypeId("25572555259157");
|
||||
_repository.AsSugarClient().ThenMapper(data, x => x.statusName = dic.ContainsKey(x.status) ? dic[x.status].ToString() : "");
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user