增加MES入库接口
This commit is contained in:
@@ -19,6 +19,9 @@ namespace Tnb.WarehouseMgr.Entities.Consts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 业务类型TypeId
|
/// 业务类型TypeId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
///
|
||||||
|
|
||||||
|
|
||||||
public const string WMS_BIZTYPE_ID = "25043955941909";
|
public const string WMS_BIZTYPE_ID = "25043955941909";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 预任务生成EnCode
|
/// 预任务生成EnCode
|
||||||
@@ -28,6 +31,11 @@ namespace Tnb.WarehouseMgr.Entities.Consts
|
|||||||
/// 载具移入生成Encode
|
/// 载具移入生成Encode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string WMS_CARRYMOINSTK_ENCODE = "CarryMoInStk";
|
public const string WMS_CARRYMOINSTK_ENCODE = "CarryMoInStk";
|
||||||
|
/// <summary>
|
||||||
|
/// 入库申请生成Encode
|
||||||
|
/// </summary>
|
||||||
|
public const string WMS_INSTOCK_ENCODE = "WmsInStock";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 任务执行ENCODE
|
/// 任务执行ENCODE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,17 +5,26 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Aop.Api.Domain;
|
using Aop.Api.Domain;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Dtos.VisualDev;
|
||||||
|
using JNPF.Common.Extension;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.FriendlyException;
|
||||||
using JNPF.Systems.Interfaces.System;
|
using JNPF.Systems.Interfaces.System;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Minio.DataModel;
|
using Minio.DataModel;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
|
using Tnb.Common.Utils;
|
||||||
using Tnb.WarehouseMgr.Entities;
|
using Tnb.WarehouseMgr.Entities;
|
||||||
using Tnb.WarehouseMgr.Entities.Attributes;
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
||||||
using Tnb.WarehouseMgr.Entities.Consts;
|
using Tnb.WarehouseMgr.Entities.Consts;
|
||||||
using Tnb.WarehouseMgr.Entities.Dto;
|
using Tnb.WarehouseMgr.Entities.Dto;
|
||||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||||
|
using Tnb.WarehouseMgr.Entities.Enums;
|
||||||
using Tnb.WarehouseMgr.Interfaces;
|
using Tnb.WarehouseMgr.Interfaces;
|
||||||
|
|
||||||
namespace Tnb.WarehouseMgr
|
namespace Tnb.WarehouseMgr
|
||||||
@@ -30,6 +39,8 @@ namespace Tnb.WarehouseMgr
|
|||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
private readonly IDictionaryDataService _dictionaryDataService;
|
private readonly IDictionaryDataService _dictionaryDataService;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly IWareHouseService _wareHouseService;
|
||||||
|
private readonly IBillRullService _billRullService;
|
||||||
private static Dictionary<string, object> _dicBillCodes = new();
|
private static Dictionary<string, object> _dicBillCodes = new();
|
||||||
public WmsInStockService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IUserManager userManager)
|
public WmsInStockService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IUserManager userManager)
|
||||||
{
|
{
|
||||||
@@ -213,6 +224,220 @@ namespace Tnb.WarehouseMgr
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 入库申请-MES对接功能
|
||||||
|
/// MES系统下发时,需要有对应的入库申请数据,和载具信息,起始库位ID,入库仓库
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
//[HttpPost]
|
||||||
|
private async Task<dynamic> MESCreateInstock(VisualDevModelDataCrInput input)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _db.Ado.BeginTranAsync();
|
||||||
|
WmsInstockH instock = new();
|
||||||
|
List<WmsInstockD> instockds = new();
|
||||||
|
List<WmsInstockCode> instockcodes = new();
|
||||||
|
//入库申请主表
|
||||||
|
if (input.data.ContainsKey("wmsInStock")) {
|
||||||
|
instock = input.data.ContainsKey("wmsInStock").ToObject<WmsInstockH>();
|
||||||
|
}
|
||||||
|
//入库申请物料明细表
|
||||||
|
if (input.data.ContainsKey("instockds"))
|
||||||
|
{
|
||||||
|
if (input.data["instockds"] != null && input.data["instockds"].IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
instockds = input.data["instockds"].ToObject<List<WmsInstockD>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//入库申请条码明细表
|
||||||
|
if (input.data.ContainsKey("instockcodes")) {
|
||||||
|
if (input.data["instockcodes"] != null && input.data["instockcodes"].IsNotEmptyOrNull()) {
|
||||||
|
instockcodes = input.data["instockcodes"].ToObject<List<WmsInstockCode>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果数据不全,
|
||||||
|
if (instock.IsNotEmptyOrNull() || instock.carry_id.IsEmpty()|| instock.location_id.IsEmpty() || instockds.Count<1 || instockcodes.Count<1) {
|
||||||
|
//报错, 提示数据不全。
|
||||||
|
throw new AppFriendlyException("数据不全!", 500);
|
||||||
|
}
|
||||||
|
// 生成入库申请数据,添加其他数据 主表
|
||||||
|
instock.id = SnowflakeIdHelper.NextId();
|
||||||
|
instock.biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID;
|
||||||
|
instock.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_INSTOCK_ENCODE).GetAwaiter().GetResult();
|
||||||
|
await _db.Insertable(instock).ExecuteCommandAsync();
|
||||||
|
//明细表
|
||||||
|
foreach (var instockd in instockds)
|
||||||
|
{
|
||||||
|
instockd.id = SnowflakeIdHelper.NextId();
|
||||||
|
instockd.bill_id = instock.id;
|
||||||
|
}
|
||||||
|
await _db.Insertable(instockds).ExecuteCommandAsync();
|
||||||
|
var items = instockds.Adapt<List<WmsInstockCode>>();
|
||||||
|
List<WmsInstockCode> instockCOdes = new();
|
||||||
|
//条码表
|
||||||
|
foreach (var instockcode in instockcodes)
|
||||||
|
{
|
||||||
|
var materialId = instockcode.material_id;
|
||||||
|
var materialCode = instockcode.material_code;
|
||||||
|
var codeBatch = instockcode.code_batch;
|
||||||
|
var b = items.Find(x => x.material_code == materialCode && x.code_batch == codeBatch);
|
||||||
|
if (b != null)
|
||||||
|
{
|
||||||
|
var c = DeepCopyHelper<WmsInstockCode>.DeepCopy(b);
|
||||||
|
c.id = SnowflakeIdHelper.NextId();
|
||||||
|
c.bill_d_id = instockcodes.Find(x => x.material_code == materialCode && x.code_batch == codeBatch)?.id!;
|
||||||
|
c.barcode = instockcode.barcode;
|
||||||
|
c.codeqty = instockcode.codeqty;
|
||||||
|
instockCOdes.Add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var orgId = _userManager.User.OrganizeId;
|
||||||
|
await _db.Insertable(instockCOdes).CallEntityMethod(it => it.Create(orgId)).ExecuteCommandAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//生成预任务申请
|
||||||
|
//入库取终点 //出库起点
|
||||||
|
var inStockStrategyInput = new InStockStrategyQuery { warehouse_id = instock.warehouse_id, Size = 1 };
|
||||||
|
var endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
||||||
|
WmsPointH sPoint = null!;
|
||||||
|
WmsPointH ePoint = null!;
|
||||||
|
if (input.data.ContainsKey(nameof(WmsHandleH.startlocation_id)))
|
||||||
|
{
|
||||||
|
sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == instock.location_id);
|
||||||
|
}
|
||||||
|
if (endLocations?.Count > 0)
|
||||||
|
{
|
||||||
|
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == endLocations[0].id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sPoint != null && ePoint != null)
|
||||||
|
{
|
||||||
|
var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
|
||||||
|
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
|
||||||
|
if (points?.Count > 0)
|
||||||
|
{
|
||||||
|
if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500);
|
||||||
|
var preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
|
||||||
|
{
|
||||||
|
var sPoint = it.FirstOrDefault();
|
||||||
|
var ePoint = it.LastOrDefault();
|
||||||
|
|
||||||
|
WmsPretaskH preTask = new();
|
||||||
|
preTask.org_id = _userManager.User.OrganizeId;
|
||||||
|
preTask.startlocation_id = sPoint?.location_id!;
|
||||||
|
preTask.startlocation_code = sPoint?.location_code!;
|
||||||
|
preTask.endlocation_id = ePoint?.location_id!;
|
||||||
|
preTask.endlocation_code = ePoint?.location_code!;
|
||||||
|
preTask.start_floor = sPoint?.floor.ToString();
|
||||||
|
preTask.end_floor = ePoint?.floor.ToString();
|
||||||
|
preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult();
|
||||||
|
preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID;
|
||||||
|
preTask.biz_type = instock.biz_type;
|
||||||
|
preTask.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||||
|
preTask.carry_id = instock.carry_id;
|
||||||
|
preTask.carry_code = instock.carry_code;
|
||||||
|
preTask.area_id = sPoint?.area_id!;
|
||||||
|
preTask.area_code = it.Key;
|
||||||
|
preTask.require_id = instock.id;
|
||||||
|
preTask.require_code = instock.bill_code;
|
||||||
|
preTask.create_id = _userManager.UserId;
|
||||||
|
preTask.create_time = DateTime.Now;
|
||||||
|
return preTask;
|
||||||
|
}).ToList();
|
||||||
|
//生成预任务条码信息
|
||||||
|
List<WmsPretaskCode> pretaskCodes = new();
|
||||||
|
foreach (var pt in preTasks)
|
||||||
|
{
|
||||||
|
if (instockCOdes.Count() > 0)
|
||||||
|
{
|
||||||
|
foreach (var jo in instockCOdes)
|
||||||
|
{
|
||||||
|
var ptc = pt.Adapt<WmsPretaskCode>();
|
||||||
|
ptc.id = SnowflakeIdHelper.NextId();
|
||||||
|
ptc.bill_id = pt.id;
|
||||||
|
ptc.material_id = jo.material_id;
|
||||||
|
ptc.material_code = jo.material_code;
|
||||||
|
ptc.barcode = jo.barcode;
|
||||||
|
ptc.codeqty = jo.codeqty;
|
||||||
|
ptc.unit_id = jo.unit_id!;
|
||||||
|
ptc.code_batch = jo.code_batch;
|
||||||
|
pretaskCodes.Add(ptc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成预任务,同时如果包含条码信息同时插入条码记录
|
||||||
|
var isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes);
|
||||||
|
if (isOk)
|
||||||
|
{
|
||||||
|
var requireIdField = "require_id";
|
||||||
|
|
||||||
|
var preTaskUpInput = new GenPreTaskUpInput();
|
||||||
|
preTaskUpInput.RquireId = instock.id;
|
||||||
|
preTaskUpInput.CarryId = instock.carry_id;
|
||||||
|
preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()!.location_id!;
|
||||||
|
preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()!.location_code!;
|
||||||
|
preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList()!;
|
||||||
|
if (input.data.ContainsKey("wmsInStock"))
|
||||||
|
{
|
||||||
|
//创建预任务操作记录
|
||||||
|
var operBillId = string.Empty;
|
||||||
|
if (instock != null)
|
||||||
|
{
|
||||||
|
var handleH = instock.Adapt<WmsHandleH>();
|
||||||
|
operBillId = handleH.id = SnowflakeIdHelper.NextId();
|
||||||
|
handleH.startlocation_id = instock.location_id;
|
||||||
|
handleH.carry_id = instock.carry_id;
|
||||||
|
handleH.carry_code = instock.carry_code;
|
||||||
|
preTaskUpInput.PreTaskRecord = handleH;
|
||||||
|
}
|
||||||
|
//创建预任务条码操作记录
|
||||||
|
if (instockcodes != null && instockcodes.Count() > 0)
|
||||||
|
{
|
||||||
|
foreach (var jo in instockcodes)
|
||||||
|
{
|
||||||
|
WmsHandleCode handleCode = jo.Adapt<WmsHandleCode>();
|
||||||
|
handleCode.id = SnowflakeIdHelper.NextId();
|
||||||
|
handleCode.org_id = _userManager.User.OrganizeId;
|
||||||
|
handleCode.bill_id = operBillId;
|
||||||
|
handleCode.create_id = _userManager.UserId;
|
||||||
|
handleCode.create_time = DateTime.Now;
|
||||||
|
preTaskUpInput.PreTaskHandleCodes.Add(handleCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//生成载具条码记录
|
||||||
|
var carryCodes = preTaskUpInput.PreTaskHandleCodes.Adapt<List<WmsCarryCode>>();
|
||||||
|
|
||||||
|
carryCodes.ForEach(x =>
|
||||||
|
{
|
||||||
|
x.id = SnowflakeIdHelper.NextId();
|
||||||
|
x.is_out = 0;
|
||||||
|
x.carry_id = instock.carry_id;
|
||||||
|
});
|
||||||
|
await _db.Insertable(carryCodes).ExecuteCommandAsync();
|
||||||
|
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput,
|
||||||
|
it => new WmsCarryH { carry_code = input.data[nameof(WmsCarryH.carry_code)].ToString()!, is_lock = 1, carry_status = ((int)EnumCarryStatus.占用).ToString(), location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode },
|
||||||
|
it => new BasLocation { is_lock = 1, is_use = (int)EnumCarryStatus.占用 });
|
||||||
|
if (instockCOdes?.Count > 0)
|
||||||
|
{
|
||||||
|
await _db.Updateable<WmsInstockD>().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instockCOdes.Select(x => x.bill_d_id).Contains(it.id)).ExecuteCommandAsync();
|
||||||
|
await _db.Updateable<WmsInstockH>().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock.id).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _db.Ado.CommitTranAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await _db.Ado.RollbackTranAsync();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user