修正出库申请,根据工位获取匹配终止库位逻辑
This commit is contained in:
@@ -19,6 +19,7 @@ using JNPF.VisualDev.Interfaces;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using NPOI.SS.Formula.Functions;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using SqlSugar.DbConvert;
|
using SqlSugar.DbConvert;
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
@@ -76,14 +77,63 @@ namespace Tnb.WarehouseMgr
|
|||||||
OverideFuncs.CreateAsync = OutStockApplyFor;
|
OverideFuncs.CreateAsync = OutStockApplyFor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
|
private async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _db.Ado.BeginTranAsync();
|
await _db.Ado.BeginTranAsync();
|
||||||
//判断目标库位是否自动签收
|
//判断目标库位是否自动签收
|
||||||
var loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString());
|
BasLocation? loc = null;
|
||||||
|
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString());
|
||||||
|
}
|
||||||
|
else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)) && input.data[nameof(WmsOutstockH.station_id)].IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
//多个投料库位
|
||||||
|
/*
|
||||||
|
* 天益
|
||||||
|
* 2、不管库位是否为空, 获取到所有库位 A B
|
||||||
|
* 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9
|
||||||
|
* 2.2 哪个最少给哪个
|
||||||
|
*/
|
||||||
|
var org = await _db.Queryable<OrganizeEntity>().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString());
|
||||||
|
if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false)
|
||||||
|
{
|
||||||
|
var fLocIds = JArray.Parse(org.FeedingLocationId).Values<string>().ToList();
|
||||||
|
var minTaskNumLocs = await _db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id))
|
||||||
|
.GroupBy(it => it.endlocation_id)
|
||||||
|
.Select(it => new
|
||||||
|
{
|
||||||
|
it.endlocation_id,
|
||||||
|
count = SqlFunc.AggregateCount(it.endlocation_id)
|
||||||
|
})
|
||||||
|
.MergeTable()
|
||||||
|
.OrderBy(it => it.count)
|
||||||
|
.ToListAsync();
|
||||||
|
if (minTaskNumLocs?.Count > 0)
|
||||||
|
{
|
||||||
|
var freeLocIds = fLocIds.Except(minTaskNumLocs.Select(x => x.endlocation_id)).ToList();
|
||||||
|
if (freeLocIds?.Count > 0)
|
||||||
|
{
|
||||||
|
var rIdx = new Random().Next(0, freeLocIds.Count);
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == freeLocIds[rIdx]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var firstLocId = minTaskNumLocs.FirstOrDefault().endlocation_id;
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == firstLocId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (minTaskNumLocs?.Count < 1)
|
||||||
|
{
|
||||||
|
var rIdx = new Random().Next(0, fLocIds.Count);
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == fLocIds[rIdx]);
|
||||||
|
}
|
||||||
|
input.data[nameof(WmsOutstockH.location_id)] = loc.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var carryIds = new List<string>();
|
var carryIds = new List<string>();
|
||||||
//tablefield120 出库物料明细
|
//tablefield120 出库物料明细
|
||||||
@@ -98,20 +148,20 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
var OutStockStrategyInput = new OutStockStrategyQuery
|
var OutStockStrategyInput = new OutStockStrategyQuery
|
||||||
{
|
{
|
||||||
carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(),
|
carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)]?.ToString() ?? string.Empty,
|
||||||
warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)].ToString(),
|
warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)]?.ToString() ?? string.Empty,
|
||||||
material_id = os.material_id,
|
material_id = os.material_id,
|
||||||
code_batch = os.code_batch,
|
code_batch = os.code_batch,
|
||||||
};
|
};
|
||||||
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
|
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
|
||||||
Expression<Func<WmsCarryH, WmsCarryCode, bool>> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id))
|
Expression<Func<WmsCarryH, WmsCarryCode, bool>> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id)) && input.data[nameof(WmsOutstockH.carry_id)].IsNotEmptyOrNull()
|
||||||
? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString()
|
? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString()
|
||||||
: (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id);
|
: (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id);
|
||||||
|
|
||||||
List<WmsCarryCode>? carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
|
List<WmsCarryCode>? carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
|
||||||
.Where(whereExp)
|
.Where(whereExp)
|
||||||
.Select<WmsCarryCode>()
|
.Select<WmsCarryCode>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if (carryCodesPart?.Count > 0)
|
if (carryCodesPart?.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -177,8 +227,20 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
carryIds = allOutIds.Concat(sortingOutIds).ToList();
|
carryIds = allOutIds.Concat(sortingOutIds).ToList();
|
||||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync();
|
var carryH = new WmsCarryH
|
||||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync();
|
{
|
||||||
|
out_status = ((int)EnumOutStatus.全部出).ToString(),
|
||||||
|
source_id = input.data.ContainsKey(nameof(WmsOutstockH.source_id)) ? input.data[nameof(WmsOutstockH.source_id)]?.ToString() ?? string.Empty : string.Empty,
|
||||||
|
source_code = input.data.ContainsKey(nameof(WmsOutstockH.source_code)) ? input.data[nameof(WmsOutstockH.source_code)]?.ToString() ?? string.Empty : string.Empty,
|
||||||
|
};
|
||||||
|
await _db.Updateable(carryH)
|
||||||
|
.UpdateColumns(it => new { it.out_status, it.source_id, it.source_code })
|
||||||
|
.Where(it => allOutIds.Contains(it.id))
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
carryH.out_status = ((int)EnumOutStatus.分拣出).ToString();
|
||||||
|
await _db.Updateable(carryH)
|
||||||
|
.UpdateColumns(it => new { it.out_status, it.source_id, it.source_code })
|
||||||
|
.ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,37 +267,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
||||||
{
|
{
|
||||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString());
|
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == loc.id);
|
||||||
}
|
|
||||||
else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)))
|
|
||||||
{
|
|
||||||
//多个投料库位
|
|
||||||
/*
|
|
||||||
* 潍柴
|
|
||||||
* 1、那个库位状态是空的出那个
|
|
||||||
* 1.1、没有空位直接抛异常
|
|
||||||
*
|
|
||||||
* 天益
|
|
||||||
* 2、不管库位是否为空, 获取到所有库位 A B
|
|
||||||
* 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9
|
|
||||||
* 2.2 哪个最少给哪个
|
|
||||||
*/
|
|
||||||
var org = await _db.Queryable<OrganizeEntity>().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString());
|
|
||||||
if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false)
|
|
||||||
{
|
|
||||||
var fLocIds = JArray.Parse(org.FeedingLocationId).Values<string>();
|
|
||||||
var minTaskNumLoc = await _db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id))
|
|
||||||
.GroupBy(it => it.endlocation_id)
|
|
||||||
.Select(it => new
|
|
||||||
{
|
|
||||||
it.endlocation_id,
|
|
||||||
count = SqlFunc.AggregateCount(it.endlocation_id)
|
|
||||||
})
|
|
||||||
.MergeTable()
|
|
||||||
.OrderBy(it => it.count)
|
|
||||||
.FirstAsync();
|
|
||||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == minTaskNumLoc.endlocation_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sPoint != null && ePoint != null)
|
if (sPoint != null && ePoint != null)
|
||||||
@@ -323,8 +355,9 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
await _db.Ado.CommitTranAsync();
|
await _db.Ado.CommitTranAsync();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
JNPF.Logging.Log.Error(ex.ToString());
|
||||||
await _db.Ado.RollbackTranAsync();
|
await _db.Ado.RollbackTranAsync();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user