Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
2023-11-14 17:49:45 +08:00
5 changed files with 60 additions and 40 deletions

View File

@@ -15,7 +15,6 @@ using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
//using NPOI.SS.Formula.Functions;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.Common.Extension;
@@ -594,7 +593,7 @@ namespace Tnb.WarehouseMgr
if (tuple.sysStatus.ToEnum<EnumSysStatus>() == EnumSysStatus. && tuple.runStatus.ToEnum<EnumRunStatus>() == EnumRunStatus.)
{
Log.Information($"disTask.require_id={disTask.require_id}");
Logger.Information($"disTask.require_id={disTask.require_id}");
List<string> disTaskIds = new() { disTask.id };
var upInput = new { disTaskIds = disTask.id };
TaskExecuteAfterUpInput teaUpInput = new()
@@ -690,7 +689,7 @@ namespace Tnb.WarehouseMgr
}
catch (Exception ex)
{
Log.Error("任务执行失败", ex);
Logger.Error("任务执行失败", ex);
await _db.Ado.RollbackTranAsync();
throw;
}
@@ -707,7 +706,7 @@ namespace Tnb.WarehouseMgr
{
await _db.Ado.BeginTranAsync();
_ = await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
_ = await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID,act_start_date = DateTime.Now }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
//清空载具库位数据
var carryAndLocIds = await _db.Queryable<WmsDistaskH>().Where(it => input.disTaskIds.Contains(it.id)).Select(it => new { it.carry_id, it.startlocation_id }).ToListAsync();
if (carryAndLocIds?.Count > 0)
@@ -726,7 +725,7 @@ namespace Tnb.WarehouseMgr
}
catch (Exception ex)
{
Log.Error("设备取返回操作失败", ex);
Logger.Error("设备取返回操作失败", ex);
await _db.Ado.RollbackTranAsync();
}
}
@@ -742,7 +741,7 @@ namespace Tnb.WarehouseMgr
await _db.Ado.BeginTranAsync();
//更新任务执行表,单据状态为 完成
_ = await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
_ = await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID,act_end_date = DateTime.Now }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
List<WmsDistaskH> disTasks = await _db.Queryable<WmsDistaskH>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id).Where(a => input.disTaskIds.Contains(a.id)).Select((a, b) => new WmsDistaskH { carry_status = b.carry_status }, true).ToListAsync();
if (disTasks?.Count > 0)
{
@@ -835,7 +834,7 @@ namespace Tnb.WarehouseMgr
catch (Exception ex)
{
Logger.Error($"任务结束失败", ex);
Log.Error($"任务结束失败堆栈异常", ex.StackTrace);
Logger.Error($"任务结束失败堆栈异常", ex);
await _db.Ado.RollbackTranAsync();
throw;
}

View File

@@ -78,8 +78,8 @@ namespace Tnb.WarehouseMgr
{
List<string> billStatus = new()
{
WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID,
WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID,
WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID,
WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID,
};
Expression<Func<WmsDistaskH, BasLocation, bool>> filter = Expressionable.Create<WmsDistaskH, BasLocation>()
.And((a, b) => b.wh_id == input.data[nameof(WmsCheckstockH.warehouse_id)].ToString())
@@ -93,7 +93,7 @@ namespace Tnb.WarehouseMgr
Task.Run(() => FetchDisTasks((a, b) => a.endlocation_id == b.id, filter))
};
List<WmsDistaskH>[] disTasks = await Task.WhenAll(queryTasks);
if (disTasks?.Length > 0)
if (disTasks?.Length > 0 && disTasks.Any(list => list?.Count > 0))
{
throw new AppFriendlyException("该仓库还有未完成的任务,不允许盘点!", 500);
}
@@ -273,7 +273,8 @@ namespace Tnb.WarehouseMgr
private Task<List<WmsDistaskH>> FetchDisTasks(Expression<Func<WmsDistaskH, BasLocation, bool>> joinExp, Expression<Func<WmsDistaskH, BasLocation, bool>> whereExp)
{
return _db.Queryable<WmsDistaskH>().InnerJoin<BasLocation>(joinExp).Where(whereExp).Select<WmsDistaskH>().ToListAsync();
return _db.CopyNew().Queryable<WmsDistaskH>().InnerJoin<BasLocation>(joinExp).Where(whereExp).Select<WmsDistaskH>().ToListAsync();
}
/// <summary>
/// 根据盘点类型获取任务明细
@@ -290,7 +291,7 @@ namespace Tnb.WarehouseMgr
[HttpGet]
public async Task<dynamic> GetTaskDetailByCheckType([FromQuery] CheckDetailQuery input)
{
if(_carryMap.Count == 0)
if (_carryMap.Count == 0)
{
_carryMap = await _db.Queryable<WmsCarryH>().ToDictionaryAsync(x => x.id, x => x.carry_code);
}
@@ -299,28 +300,26 @@ namespace Tnb.WarehouseMgr
.And((a, b, c) => a.wh_id == input.warehouse_id)
.And((a, b, c) => a.is_type == ((int)EnumLocationType.).ToString())
.And((a, b, c) => c.is_lock == 0);
switch (input.CheckType)
filterExpable = input.CheckType switch
{
case EnumCheckType.:
filterExpable.AndIF(!string.IsNullOrEmpty(input.material_id), (a, b, c) => b.material_id == input.material_id);
break;
case EnumCheckType.:
filterExpable.AndIF(input.regionIds?.Count> 0, (a, b, c) => input.regionIds.Contains(a.region_id));
break;
}
EnumCheckType. => filterExpable.AndIF(!string.IsNullOrEmpty(input.material_id), (a, b, c) => b.material_id == input.material_id),
EnumCheckType. => filterExpable.AndIF(input.regionIds?.Count > 0, (a, b, c) => input.regionIds.Contains(a.region_id)),
_ => filterExpable,
};
var carryCodes = await _db.Queryable<BasLocation>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.location_id)
.InnerJoin<WmsCarryH>((a, b, c) => b.carry_id == c.id)
.Where(filterExpable.ToExpression())
.Select<WmsCarryCode>()
.ToListAsync();
List<CheckTaskDetailOutput> outputs = carryCodes.GroupBy(g => new { g.material_code, g.code_batch, g.location_code, g.carry_id }).Select(x => new CheckTaskDetailOutput
List<WmsCheckstockD> outputs = carryCodes.GroupBy(g => new { g.material_code, g.code_batch, g.location_code, g.carry_id }).Select(x => new WmsCheckstockD
{
material_code = x.Key.material_code,
code_batch = x.Key.code_batch,
location_code = x.Key.location_code,
carry_id = x.Key.carry_id,
carry_code = _carryMap[x.Key.carry_id]?.ToString() ?? string.Empty,
location_id = x.FirstOrDefault(y => y.location_code == x.Key.location_code)?.location_id ?? string.Empty,
location_code = x.Key.location_code,
pr_qty = x.Sum(d => d.codeqty),
closing_status = WmsWareHouseConst.CLOSINGSTATUS_WJS_ID,
qty = 0,

View File

@@ -1,4 +1,5 @@
using System.Linq.Expressions;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
@@ -33,7 +34,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSTOCK_ID)]
[ServiceModule(BizTypeId)]
public class WmsOutStockService : BaseWareHouseService, IWmsOutStockService
public class WmsOutStockService : BaseWareHouseService<WmsOutStockService>, IWmsOutStockService
{
private const string BizTypeId = "26191522660645";
private readonly ISqlSugarClient _db;
@@ -70,6 +71,7 @@ namespace Tnb.WarehouseMgr
_wareCarryService = wareCarryService;
OverideFuncs.CreateAsync = OutStockApplyFor;
_ = InitializationTask;
}
public async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
@@ -112,7 +114,7 @@ namespace Tnb.WarehouseMgr
List<string?> freeLocIds = fLocIds.Except(minTaskNumLocs.Select(x => x.endlocation_id)).ToList();
if (freeLocIds?.Count > 0)
{
int rIdx = new Random().Next(0, freeLocIds.Count);
int rIdx = Random.Shared.Next(0, freeLocIds.Count);
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == freeLocIds[rIdx]);
}
else
@@ -123,7 +125,7 @@ namespace Tnb.WarehouseMgr
}
else if (minTaskNumLocs?.Count < 1)
{
int rIdx = new Random().Next(0, fLocIds.Count);
int rIdx = Random.Shared.Next(0, fLocIds.Count);
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == fLocIds[rIdx]);
}
input.data[nameof(WmsOutstockH.location_id)] = loc.id;
@@ -133,16 +135,16 @@ namespace Tnb.WarehouseMgr
List<string> carryIds = new();
var mapKeys = new List<string> { "tablefield120", "details" };
//tablefield120 出库物料明细
if (input.data.Keys.Any(k => mapKeys.Contains(k))) //input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull()
{
if (input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull())
{
outStockDList = input.data["tablefield120"].ToObject<List<WmsOutstockD>>();
}
else
else
{
outStockDList = input.data["details"].ToObject<List<WmsOutstockD>>();
}
@@ -269,7 +271,7 @@ namespace Tnb.WarehouseMgr
int ele = 2;
foreach (WmsCarryH carry in carrys)
{
bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, loc);
if (!isMatch)
{
@@ -289,7 +291,7 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
List<WmsPointH> points = await _wareHouseService.PathAlgorithmsEle(sPoint.id, ePoint.id, ele);
List<WmsPointH> points = await _wareHouseService.PathAlgorithmsEle(sPoint.id, ePoint.id, ele);
locIds.AddRange(points.Select(x => x.location_id).ToList()!);
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
if (points?.Count > 0)
@@ -817,6 +819,7 @@ namespace Tnb.WarehouseMgr
try
{
Stopwatch sw = Stopwatch.StartNew();
await _db.Ado.BeginTranAsync();
@@ -829,6 +832,7 @@ namespace Tnb.WarehouseMgr
EnumOutStatus outStatus = carry.out_status.ToEnum<EnumOutStatus>();
if (outStatus == EnumOutStatus.)
{
Stopwatch swAllOut = Stopwatch.StartNew();
//当前载具对应的所有条码插入
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == carryId).ToListAsync();
List<WmsOutstockCode> outStockCodes = carryCodes.Adapt<List<WmsOutstockCode>>();
@@ -872,10 +876,14 @@ namespace Tnb.WarehouseMgr
//如果没有完成,修改为工作中
_ = await _db.Updateable<WmsOutstockH>().SetColumns(it => new WmsOutstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync();
}
_ = await _wareCarryService.UpdateNullCarry(carry).Unwrap();
_ = _wareCarryService.UpdateNullCarry(carry).Unwrap();
swAllOut.Stop();
Logger.Information($"全部出耗时:{swAllOut.ElapsedMilliseconds}ms");
}
else if (outStatus == EnumOutStatus.)
{
Stopwatch swFJOut = Stopwatch.StartNew();
if (input.distaskCodes?.Count > 0)
{
List<WmsOutstockCode> osCodes = input.distaskCodes.Adapt<List<WmsOutstockCode>>();
@@ -962,6 +970,13 @@ namespace Tnb.WarehouseMgr
}
int row = await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.).ToString() }).Where(it => input.carryIds.Contains(it.id)).ExecuteCommandAsync();
_ = await _db.Deleteable<WmsCarryMat>().Where(it => input.carryIds.Contains(it.carry_id)).ExecuteCommandAsync();
swFJOut.Stop();
Logger.Information($"出库申请运行耗时{swFJOut.ElapsedMilliseconds}ms");
sw = Stopwatch.StartNew();
//载具移入
WmsOutstockH outStockH = await _db.Queryable<WmsOutstockH>().SingleAsync(it => it.id == input.requireId);
VisualDevModelDataCrInput visulDevInput = new()
@@ -980,12 +995,18 @@ namespace Tnb.WarehouseMgr
}
};
await _wmsCarryMoveInStockService.CarryMoveIn(visulDevInput);
_ = _wmsCarryMoveInStockService.CarryMoveIn(visulDevInput);
Logger.Information($"载具移入耗时{sw.ElapsedMilliseconds}ms");
await _db.Ado.CommitTranAsync();
}
}
await _db.Ado.CommitTranAsync();
}
}
catch (Exception)

View File

@@ -28,7 +28,7 @@ namespace Tnb.WarehouseMgr
/// 采购收货、销售发货,通用业务类
/// </summary>
/// <typeparam name="TSubEntity"></typeparam>
public class WmsPurchaseAndSaleCommonService<TSubEntity> : BaseWareHouseService where TSubEntity : BaseEntity<string>, IPurchaseAndSaleEntity, IPurchaseAndSaleQueryEntity
public class WmsPurchaseAndSaleCommonService<TSubEntity> : BaseWareHouseService where TSubEntity : BaseEntity<string>, IPurchaseAndSaleEntity, IPurchaseAndSaleQueryEntity,new()
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
@@ -86,7 +86,7 @@ namespace Tnb.WarehouseMgr
x.modify_time = DateTime.Now;
});
await _db.Updateable(purchaseDs).ExecuteCommandAsync();
await _db.Updateable(purchaseDs).UpdateColumns(it => new { it.purchase_prqty, it.line_status }).ExecuteCommandAsync();
if (purchaseDs.All(x => x.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID))
{
@@ -125,7 +125,7 @@ namespace Tnb.WarehouseMgr
return await _db.Updateable<TEntity>().SetColumns(it => it.audit_status == (int)input.auditType).Where(it => input.ids.Contains(it.id)).ExecuteCommandHasChangeAsync();
}
protected Task SyncMesData(string maintableId,List<string> materialIds,EnumTriggerEvent triggerEvent)
protected Task SyncMesData(string maintableId, List<string> materialIds, EnumTriggerEvent triggerEvent)
{
CreateTaskEntity ctEntity = new();
ctEntity.maintableid = maintableId;

View File

@@ -80,6 +80,7 @@ namespace Tnb.WarehouseMgr
instockDs = purchaseDs.Adapt<List<WmsInstockD>>();
instockDs.ForEach(instockD =>
{
instockD.bill_id =instock.id;
instockD.create_id = _userManager.UserId;
instockD.create_time = DateTime.Now;
instockD.org_id = _userManager.User.OrganizeId;
@@ -87,7 +88,7 @@ namespace Tnb.WarehouseMgr
await _db.Insertable(instockDs).ExecuteCommandAsync();
}
//通知Mes接口
_ = SyncMesData(instock.id, instockDs.Select(x => x.material_id).ToList(), EnumTriggerEvent.);
//_ = SyncMesData(instock.id, instockDs.Select(x => x.material_id).ToList(), EnumTriggerEvent.入厂检按物料编号);
await _db.Ado.CommitTranAsync();
}
catch (Exception ex)