1
This commit is contained in:
@@ -122,7 +122,7 @@ public partial class WmsSetsortingH : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 顺序号
|
||||
/// </summary>
|
||||
public int order { get; set; }
|
||||
public int seq { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
@@ -152,11 +152,21 @@ public partial class WmsSetsortingH : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string modify_id { get; set; } = string.Empty;
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime modify_time { get; set; } = DateTime.Now;
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流程任务Id
|
||||
/// </summary>
|
||||
public string? f_flowtaskid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流程引擎Id
|
||||
/// </summary>
|
||||
public string? f_flowid { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 齐套分拣主表
|
||||
/// </summary>
|
||||
public partial class WmsSetsortingH
|
||||
{
|
||||
/// <summary>
|
||||
/// 载具ID
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string? carry_id { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string? carry_code { get; get; }
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace Tnb.WarehouseMgr
|
||||
foreach (var os in outStockDList)
|
||||
{
|
||||
var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
|
||||
.Where((a, b) => b.material_id == os.material_id && b.code_batch == os.code_batch && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用)
|
||||
.Where((a, b) => b.material_id == os.material_id && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用)
|
||||
.Select<WmsCarryCode>()
|
||||
.ToListAsync();
|
||||
if (carryCodesPart?.Count > 0)
|
||||
|
||||
247
WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs
Normal file
247
WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs
Normal file
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 齐套分拣服务类
|
||||
/// </summary>
|
||||
public class WmsSetSortingService : BaseWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IWareHouseService _wareHouseService;
|
||||
private readonly IBillRullService _billRullService;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public WmsSetSortingService(ISqlSugarRepository<WmsSetsortingH> repository, IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_wareHouseService = wareHouseService;
|
||||
_billRullService = billRullService;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 齐套分拣(新增状态)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task PackSortingByAdd()
|
||||
{
|
||||
var setSortings = await _db.Queryable<WmsSetsortingH>()
|
||||
.Where(a => a.status == WmsWareHouseConst.BILLSTATUS_ADD_ID).OrderBy(a => a.seq)
|
||||
.ToListAsync();
|
||||
var items = await _db.Queryable<WmsSetsortingH>().Where(it => it.status == WmsWareHouseConst.BILLSTATUS_ON_ID).ToListAsync();
|
||||
var onFlag = items?.Count > 0;
|
||||
if (setSortings?.Count > 0 && !onFlag)
|
||||
{
|
||||
var singleSorting = setSortings[^setSortings.Count];
|
||||
var setSortingDList = await _db.Queryable<WmsSetsortingD>().Where(it => it.bill_id == singleSorting.id).ToListAsync();
|
||||
if (setSortingDList?.Count > 0)
|
||||
{
|
||||
List<WmsCarryMat> carryMats = new();
|
||||
List<WmsCarryCode> carryCodes = new();
|
||||
List<string> carryIds = new();
|
||||
foreach (var os in setSortingDList)
|
||||
{
|
||||
var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
|
||||
.Where((a, b) => b.material_id == os.material_id && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用)
|
||||
.WhereIF(!string.IsNullOrEmpty(os.code_batch), (a, b) => b.code_batch == os.code_batch)
|
||||
.Select<WmsCarryCode>()
|
||||
.ToListAsync();
|
||||
if (carryCodesPart?.Count > 0)
|
||||
{
|
||||
carryCodes.AddRange(carryCodesPart);
|
||||
var codeQty = carryCodes.Sum(x => x.codeqty);
|
||||
if (codeQty < os.pr_qty)
|
||||
{
|
||||
throw new AppFriendlyException($"需要出库[{os.pr_qty}],实际库存{codeQty},数量不足", 500);
|
||||
}
|
||||
var partCarryMats = carryCodesPart.Adapt<List<WmsCarryMat>>();
|
||||
partCarryMats.ForEach(x =>
|
||||
{
|
||||
x.need_qty = (int)os.pr_qty;
|
||||
x.real_qty = codeQty;
|
||||
});
|
||||
carryMats.AddRange(partCarryMats);
|
||||
}
|
||||
}
|
||||
if (carryMats.Count > 0)
|
||||
{
|
||||
carryMats.ForEach(x => x.id = SnowflakeIdHelper.NextId());
|
||||
carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch })
|
||||
.Select(x =>
|
||||
{
|
||||
WmsCarryMat? carryMat = x.FirstOrDefault()!;
|
||||
carryMat.real_qty = x.Sum(d => d.real_qty);
|
||||
return carryMat;
|
||||
})
|
||||
.ToList();
|
||||
await _db.Insertable(carryMats).ExecuteCommandAsync();
|
||||
var dic = carryMats.DistinctBy(x => x.carry_id).ToDictionary(x => x.carry_id, x => x.real_qty);
|
||||
var allOutIds = new List<string>();
|
||||
var sortingOutIds = new List<string>();
|
||||
foreach (var pair in dic)
|
||||
{
|
||||
var codes = carryCodes.FindAll(x => x.carry_id == pair.Key);
|
||||
if (codes?.Count > 0)
|
||||
{
|
||||
if (pair.Value == codes.Sum(d => d.codeqty))
|
||||
{
|
||||
allOutIds.Add(pair.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortingOutIds.Add(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
carryIds = allOutIds.Concat(sortingOutIds).ToList();
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync();
|
||||
//天益项目不需要
|
||||
//await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync();
|
||||
}
|
||||
var carrys = await _db.Queryable<WmsCarryH>().Where(it => carryIds.Contains(it.id)).ToListAsync();
|
||||
if (carrys?.Count > 0)
|
||||
{
|
||||
List<WmsPretaskH> preTasks = new();
|
||||
List<string> locIds = new();
|
||||
foreach (var carry in carrys)
|
||||
{
|
||||
WmsPointH sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
|
||||
WmsPointH ePoint = null!;
|
||||
|
||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString());
|
||||
|
||||
if (sPoint != null && ePoint != null)
|
||||
{
|
||||
var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
|
||||
locIds.AddRange(points.Select(x => x.location_id).ToList()!);
|
||||
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
|
||||
if (points?.Count > 0)
|
||||
{
|
||||
if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500);
|
||||
var curPreTasks = 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 = WmsWareHouseConst.BIZTYPE_WMSOUTSTOCK_ID;
|
||||
preTask.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
|
||||
preTask.carry_id = carry.id;
|
||||
preTask.carry_code = carry.carry_code;
|
||||
preTask.area_id = sPoint?.area_id!;
|
||||
preTask.area_code = it.Key;
|
||||
preTask.require_id = input.data["ReturnIdentity"].ToString();
|
||||
preTask.require_code = input.data[nameof(preTask.bill_code)]?.ToString()!;
|
||||
preTask.create_id = _userManager.UserId;
|
||||
preTask.create_time = DateTime.Now;
|
||||
return preTask;
|
||||
}).ToList();
|
||||
if (loc.is_sign == 0)
|
||||
{
|
||||
curPreTasks[^1].is_sign = 0; // 修改最后一个元素的是否签收值
|
||||
}
|
||||
preTasks.AddRange(curPreTasks);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
var isOk = await _wareHouseService.GenPreTask(preTasks, null);
|
||||
GenPreTaskUpInput genPreTaskAfterUpInput = new();
|
||||
genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList();
|
||||
genPreTaskAfterUpInput.LocationIds = new HashSet<string>(locIds).ToList();
|
||||
await _wareHouseService.GenInStockTaskHandleAfter(genPreTaskAfterUpInput, it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region MyRegion
|
||||
//foreach (var ss in setSortings)
|
||||
//{
|
||||
// var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == ss.carry_id);
|
||||
// if (carry != null)
|
||||
// {
|
||||
// WmsPointH sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
|
||||
// WmsPointH ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == ss.location_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 = ss.biz_type;
|
||||
// preTask.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||
// preTask.carry_id = ss.carry_id;
|
||||
// preTask.carry_code = ss.carry_code;
|
||||
// preTask.area_id = sPoint?.area_id;
|
||||
// preTask.area_code = it.Key;
|
||||
// preTask.require_id = ss.id;
|
||||
// preTask.require_code = ss.bill_code;
|
||||
// preTask.create_id = _userManager.UserId;
|
||||
// preTask.create_time = DateTime.Now;
|
||||
// return preTask;
|
||||
// }).ToList();
|
||||
// await _wareHouseService.GenPreTask(preTasks, null!);
|
||||
// var subCarrys = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == ss.carry_id).ToListAsync();
|
||||
// var carryIds = subCarrys.Select(x => x.carry_id).Concat(new[] { ss.carry_id }).Distinct().ToList();
|
||||
// GenPreTaskUpInput genPreTaskInput = new() { CarryIds = carryIds, LocationIds = new List<string> { carry.location_id, ss.location_id } };
|
||||
// await _wareHouseService.GenInStockTaskHandleAfter(genPreTaskInput, it => new WmsCarryH { is_lock = 1, carry_status = ((int)EnumCarryStatus.齐套分拣).ToString() }, it => new BasLocation { is_lock = 1 });
|
||||
// ss.status = WmsWareHouseConst.BILLSTATUS_ON_ID;
|
||||
// await _db.Updateable(ss).UpdateColumns(it => it.status).ExecuteCommandAsync();
|
||||
// onFlag = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ namespace Tnb.WarehouseMgr
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetDisTasksByCarryId([FromRoute] string carryId)
|
||||
{
|
||||
var items = await _db.Queryable<WmsDistaskH>().Where(it => it.carry_id == carryId && it.status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID && it.is_sign == 0).ToArrayAsync();
|
||||
return items;
|
||||
var item = await _db.Queryable<WmsDistaskH>().FirstAsync(it => it.carry_id == carryId && it.status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID && it.is_sign == 0);
|
||||
return item;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task SaveData()
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Tnb.WarehouseMgr
|
||||
var setSortingH = ko.Adapt<WmsSetsortingH>();
|
||||
setSortingH.id = SnowflakeIdHelper.NextId();
|
||||
setSortingH.kittingout_id = ko.id;
|
||||
setSortingH.order = ko.seq;
|
||||
setSortingH.seq = ko.seq;
|
||||
setSortingH.org_id = _userManager.User.OrganizeId;
|
||||
setSortingH.create_id = _userManager.UserId;
|
||||
setSortingH.create_time = DateTime.Now;
|
||||
@@ -131,7 +131,7 @@ namespace Tnb.WarehouseMgr
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => it.id == koGrp.Key && it.is_use == "0" && it.is_lock == 0).ToListAsync();
|
||||
if (locs?.Count > 0)
|
||||
{
|
||||
|
||||
|
||||
var arr = koGrp.ToArray();
|
||||
var ko = arr[^arr.Length];
|
||||
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == ko.carry_id);
|
||||
|
||||
Reference in New Issue
Block a user