diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs
index 056da03d..825c64f7 100644
--- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs
+++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs
@@ -265,7 +265,25 @@
/// 盘点任务计算状态-未结算
///
public const string CLOSINGSTATUS_WJS_ID = "27674058079509";
-
-
+ ///
+ /// 盘点任务计算状态-盘亏
+ ///
+ public const string CLOSINGSTATUS_PK_ID = "27674064284949";
+ ///
+ /// 盘点任务计算状态-正常
+ ///
+ public const string CLOSINGSTATUS_NORMAL_ID = "27674060155413";
+ ///
+ /// 盘点任务计算状态-盘盈
+ ///
+ public const string CLOSINGSTATUS_PY_ID = "27674069224213";
+ ///
+ /// 盘点状态-盘点中
+ ///
+ public const string CHECKSTATUS_PDZ_ID = "27584592425493";
+ ///
+ /// 盘点状态-盘点结账
+ ///
+ public const string CHECKSTATUS_PDJZ_ID = "27584597303317";
}
}
diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TakeStockSignInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TakeStockSignInput.cs
index d116f304..2b177796 100644
--- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TakeStockSignInput.cs
+++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TakeStockSignInput.cs
@@ -11,6 +11,9 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs
///
public class TakeStockSignInput
{
+ ///
+ /// 盘点任务明细列表
+ ///
public List details{ get; set; }
}
}
diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs
index 4a7c9c3c..185b8835 100644
--- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs
+++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs
@@ -440,9 +440,17 @@ namespace Tnb.WarehouseMgr
.ToListAsync();
return items;
}
-
+ ///
+ /// 盘点签收
+ ///
+ /// 盘点签收输入参数
+ /// 有异常信息为失败,无异常为正常
+ ///
+ ///
+ [HttpPost]
public async Task TakeStockSign(TakeStockSignInput input)
{
+
if (input == null) throw new ArgumentNullException("input");
if (input.details == null) throw new ArgumentNullException(nameof(input.details));
var checkStockCodes = input.details.Adapt>();
@@ -452,114 +460,162 @@ namespace Tnb.WarehouseMgr
it.status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID &&
it.is_sign == 0).FirstAsync();
- if (disTask != null)
+ try
{
- disTask.is_sign = 1;
- _ = await _db.Updateable(disTask).UpdateColumns(it => it.is_sign).ExecuteCommandAsync();
- }
- var checkStock = await _db.Queryable().SingleAsync(it => it.id == checkStockCodes[0].checkstock_id);
- if (checkStock != null)
- {
- InStockStrategyQuery q = new() { warehouse_id = checkStock.warehouse_id };
- var endLocs = await _warehouseService.InStockStrategy(q);
- WmsPointH? sPoint = null, ePoint = null;
- var carry = await _db.Queryable().SingleAsync(it => it.id == checkStockCodes[0].carry_id);
- sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id);
- if (endLocs?.Count > 0)
+ await _db.Ado.BeginTranAsync();
+
+ if (disTask != null)
{
- ePoint = await _db.Queryable().FirstAsync(it => it.location_id == endLocs[0].id);
+ disTask.is_sign = 1;
+ _ = await _db.Updateable(disTask).UpdateColumns(it => it.is_sign).ExecuteCommandAsync();
}
- if (sPoint == null || ePoint == null) throw new AppFriendlyException("路径无效", 500);
- List points = await _warehouseService.PathAlgorithms(sPoint.id, ePoint.id);
- //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
- if (points?.Count > 0)
+ var checkStock = await _db.Queryable().SingleAsync(it => it.id == checkStockCodes[0].checkstock_id);
+ if (checkStock != null)
{
- if (points.Count <= 2)
+ InStockStrategyQuery q = new() { warehouse_id = checkStock!.warehouse_id! };
+ var endLocs = await _warehouseService.InStockStrategy(q);
+ WmsPointH? sPoint = null, ePoint = null;
+ var carry = await _db.Queryable().SingleAsync(it => it.id == checkStockCodes[0].carry_id);
+ sPoint = await _db.Queryable().FirstAsync(it => it.location_id == carry.location_id);
+ if (endLocs?.Count > 0)
{
- throw new AppFriendlyException("该路径不存在", 500);
+ ePoint = await _db.Queryable().FirstAsync(it => it.location_id == endLocs[0].id);
}
-
- List preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
+ if (sPoint == null || ePoint == null) throw new AppFriendlyException("路径无效", 500);
+ List points = await _warehouseService.PathAlgorithms(sPoint.id, ePoint.id);
+ //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
+ if (points?.Count > 0)
{
- WmsPointH? sPoint = it.FirstOrDefault();
- WmsPointH? ePoint = it.LastOrDefault();
-
- WmsPretaskH preTask = new()
+ if (points.Count <= 2)
{
- org_id = _userManager.User.OrganizeId!,
- startlocation_id = sPoint?.location_id!,
- startlocation_code = sPoint?.location_code!,
- endlocation_id = ePoint?.location_id!,
- endlocation_code = ePoint?.location_code!,
- start_floor = sPoint?.floor.ToString(),
- end_floor = ePoint?.floor.ToString(),
- startpoint_id = sPoint?.id!,
- startpoint_code = sPoint?.point_code!,
- endpoint_id = ePoint?.id!,
- endpoint_code = ePoint?.point_code!,
- bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(),
- status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,
- biz_type = WmsWareHouseConst.BIZTYPE_CARRYMOVEINSTOCK_ID,
- task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID,
- carry_id = carry?.id,
- carry_code = carry?.carry_code,
- area_id = sPoint?.area_id!,
- area_code = it.Key,
- create_id = _userManager.UserId,
- create_time = DateTime.Now
- };
+ throw new AppFriendlyException("该路径不存在", 500);
+ }
- return preTask;
- }).ToList();
- bool isOk = await _warehouseService.GenPreTask(preTasks, null!);
- if (isOk)
- {
- GenPreTaskUpInput preTaskUpInput = new()
+ List preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
{
- //RquireId = input.data["ReturnIdentity"].ToString()!,
- CarryId = checkStockCodes[0].carry_id,
- CarryStartLocationId = points.FirstOrDefault()!.location_id!,
- CarryStartLocationCode = points.FirstOrDefault()!.location_code!,
- LocationIds = points.Select(x => x.location_id).ToList()!
- };
+ WmsPointH? sPoint = it.FirstOrDefault();
+ WmsPointH? ePoint = it.LastOrDefault();
- WmsHandleH handleH = new()
+ WmsPretaskH preTask = new()
+ {
+ org_id = _userManager.User.OrganizeId!,
+ startlocation_id = sPoint?.location_id!,
+ startlocation_code = sPoint?.location_code!,
+ endlocation_id = ePoint?.location_id!,
+ endlocation_code = ePoint?.location_code!,
+ start_floor = sPoint?.floor.ToString(),
+ end_floor = ePoint?.floor.ToString(),
+ startpoint_id = sPoint?.id!,
+ startpoint_code = sPoint?.point_code!,
+ endpoint_id = ePoint?.id!,
+ endpoint_code = ePoint?.point_code!,
+ bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(),
+ status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,
+ biz_type = WmsWareHouseConst.BIZTYPE_CARRYMOVEINSTOCK_ID,
+ task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID,
+ carry_id = carry?.id ?? string.Empty,
+ carry_code = carry?.carry_code ?? string.Empty,
+ area_id = sPoint?.area_id!,
+ area_code = it.Key,
+ create_id = _userManager.UserId,
+ create_time = DateTime.Now
+ };
+
+ return preTask;
+ }).ToList();
+ bool isOk = await _warehouseService.GenPreTask(preTasks, null!);
+ if (isOk)
{
- org_id = _userManager.User.OrganizeId,
- startlocation_id = carry.location_id,
- endlocation_id = endLocs?[0].id ?? string.Empty,
- bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_CARRYMOINSTK_ENCODE).GetAwaiter().GetResult(),
- biz_type = WmsWareHouseConst.BIZTYPE_CARRYMOVEINSTOCK_ID,
- carry_id = checkStockCodes[0].carry_id,
- carry_code = carry?.carry_code ?? string.Empty,
- create_id = _userManager.UserId,
- create_time = DateTime.Now
- };
- preTaskUpInput.PreTaskRecord = handleH;
- //根据载具移入Id,回更单据状态
- _ = await _db.Updateable().SetColumns(it => new WmsMoveInstock { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync();
+ GenPreTaskUpInput preTaskUpInput = new()
+ {
+ //RquireId = input.data["ReturnIdentity"].ToString()!,
+ CarryId = checkStockCodes[0].carry_id,
+ CarryStartLocationId = points.FirstOrDefault()!.location_id!,
+ CarryStartLocationCode = points.FirstOrDefault()!.location_code!,
+ LocationIds = points.Select(x => x.location_id).ToList()!
+ };
- await _warehouseService.GenInStockTaskHandleAfter(preTaskUpInput,
- it => new WmsCarryH { is_lock = 1, location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode },
- it => new BasLocation { is_lock = 1 });
+ WmsHandleH handleH = new()
+ {
+ org_id = _userManager.User.OrganizeId,
+ startlocation_id = carry?.location_id ?? string.Empty,
+ endlocation_id = endLocs?[0].id ?? string.Empty,
+ bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_CARRYMOINSTK_ENCODE).GetAwaiter().GetResult(),
+ biz_type = WmsWareHouseConst.BIZTYPE_CARRYMOVEINSTOCK_ID,
+ carry_id = checkStockCodes?[0].carry_id ?? string.Empty,
+ carry_code = carry?.carry_code ?? string.Empty,
+ create_id = _userManager.UserId,
+ create_time = DateTime.Now
+ };
+ preTaskUpInput.PreTaskRecord = handleH;
+ //根据载具移入Id,回更单据状态
+ _ = await _db.Updateable().SetColumns(it => new WmsMoveInstock { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync();
+
+ await _warehouseService.GenInStockTaskHandleAfter(preTaskUpInput,
+ it => new WmsCarryH { is_lock = 1, location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode },
+ it => new BasLocation { is_lock = 1 });
+ }
}
}
- }
- foreach (var csCode in checkStockCodes)
- {
- csCode.id = SnowflakeIdHelper.NextId();
- var checkStockPartDs = await _db.Queryable().Where(it => it.checkstock_id == csCode.checkstock_id).ToListAsync();
- var checkStockDMap = checkStockPartDs.GroupBy(g => $"{g.carry_id}{g.material_id}{g.code_batch}").ToDictionary(x => x.Key, x => x.First().id);
- csCode.checkstock_d_id = checkStockDMap.ContainsKey($"{csCode.carry_id}{csCode.material_id}{csCode.code_batch}") ? checkStockDMap[$"{csCode.carry_id}{csCode.material_id}{csCode.code_batch}"] : "";
- }
- //插入 盘点code表
- await _db.Insertable(checkStockCodes).ExecuteCommandAsync();
- var detailIds = checkStockCodes.Select(x => x.checkstock_d_id).ToList();
- var checkStockDs = _db.Queryable().Where(it => detailIds.Contains(it.id)).ToListAsync();
- foreach (var csCode in checkStockCodes)
- {
+ foreach (var csCode in checkStockCodes!)
+ {
+ csCode.id = SnowflakeIdHelper.NextId();
+ var checkStockPartDs = await _db.Queryable().Where(it => it.checkstock_id == csCode.checkstock_id).ToListAsync();
+ var checkStockDMap = checkStockPartDs.GroupBy(g => $"{g.carry_id}{g.material_id}{g.code_batch}").ToDictionary(x => x.Key, x => x.First().id);
+ csCode.checkstock_d_id = checkStockDMap.ContainsKey($"{csCode.carry_id}{csCode.material_id}{csCode.code_batch}") ? checkStockDMap[$"{csCode.carry_id}{csCode.material_id}{csCode.code_batch}"] : "";
+ }
+ //插入 盘点code表
+ await _db.Insertable(checkStockCodes).ExecuteCommandAsync();
+ var detailIds = checkStockCodes.Select(x => x.checkstock_d_id).ToList();
+ var checkStockDs = await _db.Queryable().Where(it => detailIds.Contains(it.id)).ToListAsync();
+ foreach (var csd in checkStockDs)
+ {
+ var csCode = checkStockCodes.Find(x => x.checkstock_d_id == csd.id);
+ if (csCode != null)
+ {
+ csd.qty += csCode.codeqty;
+ var residueQty = csd.qty - csd.pr_qty;
+ if (residueQty == 0)
+ {
+ csd.closing_status = WmsWareHouseConst.CLOSINGSTATUS_NORMAL_ID;
+ }
+ else if (residueQty > 0)
+ {
+ csd.closing_status = WmsWareHouseConst.CLOSINGSTATUS_PY_ID;
+ }
+ else if (residueQty < 0)
+ {
+ csd.closing_status = WmsWareHouseConst.CLOSINGSTATUS_PK_ID;
+ }
+ }
+ }
+ _ = await _db.Updateable(checkStockDs).UpdateColumns(it => new { it.qty, it.closing_status }).ExecuteCommandAsync();
+ var checkStockDsGrp = checkStockDs.GroupBy(g => g.checkstock_id);
+ var checkStocks = await _db.Queryable().Where(it => checkStockDsGrp.Select(g => g.Key).Contains(it.id)).ToListAsync();
+ var tasks = new List>(checkStockDsGrp.Count());
+ foreach (var grp in checkStockDsGrp)
+ {
+ if (grp.All(x => x.closing_status != WmsWareHouseConst.CLOSINGSTATUS_WJS_ID))
+ {
+ var cs = checkStocks.Find(x => x.id == grp.Key);
+ if (cs != null)
+ {
+ cs.status = WmsWareHouseConst.CHECKSTATUS_PDJZ_ID;
+ tasks.Add(_db.Updateable(cs).UpdateColumns(it => it.status).ExecuteCommandAsync());
+ }
+ }
+ }
+ _ = await Task.WhenAll(tasks);
+
+ await _db.Ado.CommitTranAsync();
+ }
+ catch (Exception ex)
+ {
+ Logger.Error("盘点签收失败", ex);
+ await _db.Ado.RollbackTranAsync();
+ throw;
}
}