Mes->Wms 生产入库接口调整
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tnb.WarehouseMgr.Entities.Dto.Inputs
|
||||||
|
{
|
||||||
|
public class MESCreateInstockInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 生产入库主表
|
||||||
|
/// </summary>
|
||||||
|
public WmsInstockH instock { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 生产入库明细表
|
||||||
|
/// </summary>
|
||||||
|
public List<WmsInstockD> instockds { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 入库申请条码明细表
|
||||||
|
/// </summary>
|
||||||
|
public List<WmsInstockCode> instockcodes { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
|
|
||||||
|
namespace Tnb.WarehouseMgr.Entities.Dto.Outputs
|
||||||
|
{
|
||||||
|
public class DataResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 响应状态码
|
||||||
|
/// </summary>
|
||||||
|
public HttpStatusCode code { get; set; } = HttpStatusCode.OK;
|
||||||
|
/// <summary>
|
||||||
|
/// 响应信息
|
||||||
|
/// </summary>
|
||||||
|
public string msg { get; set; }
|
||||||
|
public DateTime? timestamp { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 响应数据
|
||||||
|
/// </summary>
|
||||||
|
public object data { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using Aspose.Cells.Drawing;
|
using Aspose.Cells.Drawing;
|
||||||
using JNPF;
|
using JNPF;
|
||||||
using JNPF.Common.Contracts;
|
using JNPF.Common.Contracts;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using JNPF.DependencyInjection;
|
using JNPF.DependencyInjection;
|
||||||
using JNPF.DynamicApiController;
|
using JNPF.DynamicApiController;
|
||||||
@@ -15,6 +16,7 @@ using JNPF.VisualDev;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Tnb.WarehouseMgr.Entities.Attributes;
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
||||||
using Tnb.WarehouseMgr.Entities.Dto;
|
using Tnb.WarehouseMgr.Entities.Dto;
|
||||||
|
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
||||||
using Tnb.WarehouseMgr.Entities.Entity;
|
using Tnb.WarehouseMgr.Entities.Entity;
|
||||||
using Tnb.WarehouseMgr.Interfaces;
|
using Tnb.WarehouseMgr.Interfaces;
|
||||||
|
|
||||||
@@ -53,5 +55,67 @@ namespace Tnb.WarehouseMgr
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Api响应结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[NonAction]
|
||||||
|
protected async Task<dynamic> ToApiResult()
|
||||||
|
{
|
||||||
|
DataResult result = new();;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Api响应结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[NonAction]
|
||||||
|
protected async Task<dynamic> ToApiResult(HttpStatusCode statusCode, object data)
|
||||||
|
{
|
||||||
|
DataResult result = new();
|
||||||
|
result.code = statusCode;
|
||||||
|
result.data = data;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Api响应结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[NonAction]
|
||||||
|
protected async Task<dynamic> ToApiResult(HttpStatusCode statusCode, string msg)
|
||||||
|
{
|
||||||
|
DataResult result = new();
|
||||||
|
result.code = statusCode;
|
||||||
|
result.msg = msg;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Api响应结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[NonAction]
|
||||||
|
protected async Task<dynamic> ToApiResult(HttpStatusCode statusCode, string msg, object data)
|
||||||
|
{
|
||||||
|
DataResult result = new();
|
||||||
|
result.code = statusCode;
|
||||||
|
result.msg = msg;
|
||||||
|
result.data = data;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,37 +241,19 @@ namespace Tnb.WarehouseMgr
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<dynamic> MESCreateInstock(VisualDevModelDataCrInput input)
|
public async Task<dynamic> MESCreateInstock(MESCreateInstockInput input)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _db.Ado.BeginTranAsync();
|
await _db.Ado.BeginTranAsync();
|
||||||
WmsInstockH instock = new();
|
|
||||||
List<WmsInstockD> instockds = new();
|
|
||||||
List<WmsInstockCode> instockcodes = new();
|
|
||||||
//入库申请主表
|
//入库申请主表
|
||||||
if (input.data.ContainsKey("wmsInStockH"))
|
WmsInstockH instock = input.instock;
|
||||||
{
|
|
||||||
instock = input.data.ContainsKey("wmsInStockH").ToObject<WmsInstockH>();
|
|
||||||
}
|
|
||||||
//入库申请物料明细表
|
//入库申请物料明细表
|
||||||
if (input.data.ContainsKey("wmsInStockds"))
|
List<WmsInstockD> instockds = input.instockds;
|
||||||
{
|
|
||||||
if (input.data["wmsInStockds"] != null && input.data["wmsInStockds"].IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
instockds = input.data["wmsInStockds"].ToObject<List<WmsInstockD>>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//入库申请条码明细表
|
//入库申请条码明细表
|
||||||
if (input.data.ContainsKey("wmsInStockCodes"))
|
List<WmsInstockCode> instockcodes = input.instockcodes;
|
||||||
{
|
|
||||||
if (input.data["wmsInStockCodes"] != null && input.data["wmsInStockCodes"].IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
instockcodes = input.data["wmsInStockCodes"].ToObject<List<WmsInstockCode>>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//如果数据不全,
|
//如果数据不全,
|
||||||
if (instock.IsNull() || instock.carry_id.IsEmpty() || instock.location_id.IsEmpty() || instockds.Count < 1 || instockcodes.Count < 1)
|
if (instock.IsNull() || instock.carry_id.IsNullOrWhiteSpace() || instock.location_id.IsNullOrWhiteSpace() || instockds?.Count < 1 || instockcodes?.Count < 1)
|
||||||
{
|
{
|
||||||
//报错, 提示数据不全。
|
//报错, 提示数据不全。
|
||||||
throw new AppFriendlyException("数据不全!", 500);
|
throw new AppFriendlyException("数据不全!", 500);
|
||||||
@@ -287,7 +269,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
instock.create_time = DateTime.Now;
|
instock.create_time = DateTime.Now;
|
||||||
await _db.Insertable(instock).ExecuteCommandAsync();
|
await _db.Insertable(instock).ExecuteCommandAsync();
|
||||||
//明细表
|
//明细表
|
||||||
foreach (var instockd in instockds)
|
foreach (var instockd in instockds!)
|
||||||
{
|
{
|
||||||
instockd.id = SnowflakeIdHelper.NextId();
|
instockd.id = SnowflakeIdHelper.NextId();
|
||||||
instockd.bill_id = instock.id;
|
instockd.bill_id = instock.id;
|
||||||
@@ -300,7 +282,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
var items = instockds.Adapt<List<WmsInstockCode>>();
|
var items = instockds.Adapt<List<WmsInstockCode>>();
|
||||||
List<WmsInstockCode> instockCOdes = new();
|
List<WmsInstockCode> instockCOdes = new();
|
||||||
//条码表
|
//条码表
|
||||||
foreach (var instockcode in instockcodes)
|
foreach (var instockcode in instockcodes!)
|
||||||
{
|
{
|
||||||
instockcode.id = SnowflakeIdHelper.NextId();
|
instockcode.id = SnowflakeIdHelper.NextId();
|
||||||
var materialId = instockcode.material_id;
|
var materialId = instockcode.material_id;
|
||||||
@@ -328,16 +310,8 @@ namespace Tnb.WarehouseMgr
|
|||||||
//入库取终点 //出库起点
|
//入库取终点 //出库起点
|
||||||
var inStockStrategyInput = new InStockStrategyQuery { warehouse_id = instock.warehouse_id, Size = 1 };
|
var inStockStrategyInput = new InStockStrategyQuery { warehouse_id = instock.warehouse_id, Size = 1 };
|
||||||
var endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
var endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
||||||
WmsPointH sPoint = null!;
|
WmsPointH sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == instock.location_id);
|
||||||
WmsPointH ePoint = null!;
|
WmsPointH ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == endLocations[0].id);
|
||||||
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)
|
if (sPoint != null && ePoint != null)
|
||||||
{
|
{
|
||||||
@@ -406,52 +380,51 @@ namespace Tnb.WarehouseMgr
|
|||||||
preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()!.location_id!;
|
preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()!.location_id!;
|
||||||
preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()!.location_code!;
|
preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()!.location_code!;
|
||||||
preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList()!;
|
preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList()!;
|
||||||
if (input.data.ContainsKey("wmsInStockH"))
|
|
||||||
{
|
|
||||||
//创建预任务操作记录
|
|
||||||
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 =>
|
//创建预任务操作记录
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
x.id = SnowflakeIdHelper.NextId();
|
WmsHandleCode handleCode = jo.Adapt<WmsHandleCode>();
|
||||||
x.is_out = 0;
|
handleCode.id = SnowflakeIdHelper.NextId();
|
||||||
x.carry_id = instock!.carry_id!;
|
handleCode.org_id = _userManager.User.OrganizeId;
|
||||||
});
|
handleCode.bill_id = operBillId;
|
||||||
await _db.Insertable(carryCodes).ExecuteCommandAsync();
|
handleCode.create_id = _userManager.UserId;
|
||||||
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput,
|
handleCode.create_time = DateTime.Now;
|
||||||
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 },
|
preTaskUpInput.PreTaskHandleCodes.Add(handleCode);
|
||||||
it => new BasLocation { is_lock = 1, is_use = ((int)EnumCarryStatus.占用).ToString() });
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//生成载具条码记录
|
||||||
|
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 = instock!.carry_code!, 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.占用).ToString() });
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,9 +435,9 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
JNPF.Logging.Log.Error(ex.Message);
|
JNPF.Logging.Log.Error(ex.Message);
|
||||||
await _db.Ado.RollbackTranAsync();
|
await _db.Ado.RollbackTranAsync();
|
||||||
throw;
|
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
|
||||||
}
|
}
|
||||||
return Task.FromResult(true);
|
return await ToApiResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user