生产退料开发等

This commit is contained in:
2024-06-27 11:15:07 +08:00
parent 1765ebedc4
commit 8177d05cd2
17 changed files with 788 additions and 159 deletions

View File

@@ -0,0 +1,72 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities.Entity;
/// <summary>
/// wms生产退料单明细
/// </summary>
[SugarTable("wms_prd_return_d")]
public partial class WmsPrdReturnD : BaseEntity<string>
{
public WmsPrdReturnD()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 生产退料单id
/// </summary>
public string? bill_id { get; set; }
/// <summary>
/// 物料
/// </summary>
public string? material_id { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string? material_code { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string? material_name { get; set; }
/// <summary>
/// 数量
/// </summary>
public decimal? qty { get; set; }
/// <summary>
/// 已退料数量
/// </summary>
public decimal? ytqty { get; set; }
/// <summary>
/// 单位
/// </summary>
public string? unit_id { get; set; }
}

View File

@@ -0,0 +1,67 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities.Entity;
/// <summary>
/// wms生产退料单
/// </summary>
[SugarTable("wms_prd_return_h")]
public partial class WmsPrdReturnH : BaseEntity<string>
{
public WmsPrdReturnH()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 载具
/// </summary>
public string? carry_id { get; set; }
/// <summary>
/// 载具编码
/// </summary>
public string? carry_code { get; set; }
/// <summary>
/// 载具规格
/// </summary>
public string? carrystd_id { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 入库仓库
/// </summary>
public string? warehouse_id { get; set; }
/// <summary>
/// 生产退料单号
/// </summary>
public string? bill_code { get; set; }
/// <summary>
/// 单据状态
/// </summary>
public string? status { get; set; }
}

View File

@@ -15,6 +15,7 @@ using Tnb.EquipMgr.Entities;
using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Entities.Dto; using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Interfaces; using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Interfaces; using Tnb.WarehouseMgr.Interfaces;
@@ -34,6 +35,7 @@ namespace Tnb.ProductionMgr
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly IDictionaryDataService _dictionaryDataService; private readonly IDictionaryDataService _dictionaryDataService;
private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryBindService _wmsCarryBindService;
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
// private readonly WmsSignForDeliveryService _wmsSignForDeliveryService; // private readonly WmsSignForDeliveryService _wmsSignForDeliveryService;
@@ -45,6 +47,7 @@ namespace Tnb.ProductionMgr
// WmsSignForDeliveryService wmsSignForDeliveryService, // WmsSignForDeliveryService wmsSignForDeliveryService,
IDictionaryDataService dictionaryDataService, IDictionaryDataService dictionaryDataService,
IWmsCarryBindService wmsCarryBindService, IWmsCarryBindService wmsCarryBindService,
IWmsCarryUnbindService wmsCarryUnbindService,
IUserManager userManager IUserManager userManager
) )
{ {
@@ -55,6 +58,7 @@ namespace Tnb.ProductionMgr
_dictionaryDataService = dictionaryDataService; _dictionaryDataService = dictionaryDataService;
_billRullService = billRullService; _billRullService = billRullService;
_wmsCarryBindService = wmsCarryBindService; _wmsCarryBindService = wmsCarryBindService;
_wmsCarryUnbindService = wmsCarryUnbindService;
} }
@@ -457,7 +461,7 @@ namespace Tnb.ProductionMgr
_ = await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync(); _ = await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
_ = await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync(); _ = await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
_wmsCarryBindService.CarryCodeUnbind(new CarryCodeUnbindInput() _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput()
{ {
carry_id = carry.id carry_id = carry.id
}); });

View File

@@ -106,6 +106,7 @@ namespace Tnb.ProductionMgr
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly IWareHouseService _wareHouseService; private readonly IWareHouseService _wareHouseService;
private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryBindService _wmsCarryBindService;
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
private readonly IWmsEmptyOutstockService _wmsEmptyOutstockService; private readonly IWmsEmptyOutstockService _wmsEmptyOutstockService;
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>(); private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
@@ -114,7 +115,8 @@ namespace Tnb.ProductionMgr
#region #region
public RedisBackGround(StackExRedisHelper redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock public RedisBackGround(StackExRedisHelper redisData, IPrdInstockService prdInstockService, ISqlSugarRepository<RedisReadConfig> repository, IWmsPDAScanInStockService wmsPDAScanInStock
, IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, IWmsCarryBindService wmsCarryBindService, IWmsEmptyOutstockService wmsEmptyOutstockService) , IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, IWmsCarryBindService wmsCarryBindService,
IWmsCarryUnbindService wmsCarryUnbindService, IWmsEmptyOutstockService wmsEmptyOutstockService)
{ {
_redisData = redisData; _redisData = redisData;
_prdInstockService = prdInstockService; _prdInstockService = prdInstockService;
@@ -125,6 +127,7 @@ namespace Tnb.ProductionMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_wmsCarryBindService = wmsCarryBindService; _wmsCarryBindService = wmsCarryBindService;
_wmsEmptyOutstockService = wmsEmptyOutstockService; _wmsEmptyOutstockService = wmsEmptyOutstockService;
_wmsCarryUnbindService = wmsCarryUnbindService;
db_CheckGettimer = repository.CopyNew(); db_CheckGettimer = repository.CopyNew();
db_Scantimer = repository.CopyNew(); db_Scantimer = repository.CopyNew();
@@ -1456,7 +1459,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
carryBindInput.carry_code = wmsMechanicalArmH.rackcode; carryBindInput.carry_code = wmsMechanicalArmH.rackcode;
carryBindInput.source_code = wmsMechanicalArmH.outbill; carryBindInput.source_code = wmsMechanicalArmH.outbill;
await _wmsCarryBindService.CarryUnbind(carryBindInput); await _wmsCarryUnbindService.CarryUnbind(carryBindInput);
// 锁住终点库位 // 锁住终点库位
await db_Floor2timer移走下升降区未生成预任务且空托的料架.Updateable<BasLocation>(r => new BasLocation await db_Floor2timer移走下升降区未生成预任务且空托的料架.Updateable<BasLocation>(r => new BasLocation

View File

@@ -103,6 +103,9 @@ public class ModuleConsts
/// 模块标识-载具解绑 /// 模块标识-载具解绑
public const string MODULE_WMSCARRYUNBIND_ID = "26106270092325"; public const string MODULE_WMSCARRYUNBIND_ID = "26106270092325";
/// <summary> /// <summary>
/// 模块标识-生产退料单 todo
public const string MODULE_WMSPRDRETURN_ID = "MODULE_WMSPRDRETURN_ID";
/// <summary>
/// 模块标识-载具绑定 /// 模块标识-载具绑定
/// </summary> /// </summary>
public const string MODULE_WMSCARRYBIND_ID = "26105163614501"; public const string MODULE_WMSCARRYBIND_ID = "26105163614501";

View File

@@ -224,14 +224,18 @@
/// </summary> /// </summary>
public const string BIZTYPE_WMSDELIVERY_ID = "26585291847957"; public const string BIZTYPE_WMSDELIVERY_ID = "26585291847957";
/// <summary> /// <summary>
/// 预任务生成业务类型-销售出库下发 /// 预任务生成业务类型-销售出库
/// </summary> /// </summary>
public const string BIZTYPE_WMSSALERELEASE_ID = "25104446664213"; public const string BIZTYPE_WMSSALERELEASE_ID = "25104446664213";
/// <summary> /// <summary>
/// 预任务生成业务类型-原材料转库单下发 todo /// 预任务生成业务类型-原材料转库单 todo
/// </summary> /// </summary>
public const string BIZTYPE_WMSMATERIALTRANSFER_ID = "34354738929685"; public const string BIZTYPE_WMSMATERIALTRANSFER_ID = "34354738929685";
/// <summary> /// <summary>
/// 预任务生成业务类型-生产退料单 todo
/// </summary>
public const string BIZTYPE_PRDRETURN_ID = "BIZTYPE_PRDRETURN_ID";
/// <summary>
/// 预任务生成业务类型-载具绑定 /// 预任务生成业务类型-载具绑定
/// </summary> /// </summary>
public const string BIZTYPE_WMSCARRYBIND_ID = "27118595509525"; public const string BIZTYPE_WMSCARRYBIND_ID = "27118595509525";

View File

@@ -0,0 +1,32 @@
namespace Tnb.WarehouseMgr.Entities.Dto
{
/// <summary>
/// 库房业务更新输入参数
/// </summary>
public class PrdReturnInput
{
/// <summary>
/// 组织ID
/// </summary>
public string org_id { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string create_id { get; set; }
/// <summary>
/// 料架号
/// </summary>
public string? carry_code { get; set; }
/// <summary>
/// 起始库位
/// </summary>
public string? startlocation_id { get; set; }
/// <summary>
/// 生产退料单id
/// </summary>
public string source_id { get; set; }
}
}

View File

@@ -12,7 +12,5 @@ namespace Tnb.WarehouseMgr.Interfaces
Task<dynamic> CarryBind(VisualDevModelDataCrInput input); Task<dynamic> CarryBind(VisualDevModelDataCrInput input);
Task<Result> CarryBind(CarryBindInput input); Task<Result> CarryBind(CarryBindInput input);
Task<Result> CarryUnbind(CarryBindInput input);
Task<dynamic> CarryCodeUnbind(CarryCodeUnbindInput input);
} }
} }

View File

@@ -0,0 +1,15 @@
using JNPF.Common.Dtos.VisualDev;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
namespace Tnb.WarehouseMgr.Interfaces
{
/// <summary>
/// 载具绑定服务接口
/// </summary>
public interface IWmsCarryUnbindService
{
Task<Result> CarryUnbind(CarryBindInput input);
Task<dynamic> CarryCodeUnbind(CarryCodeUnbindInput input);
}
}

View File

@@ -0,0 +1,14 @@
using JNPF.Common.Dtos.VisualDev;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
namespace Tnb.WarehouseMgr.Interfaces
{
/// <summary>
/// 载具绑定服务接口
/// </summary>
public interface IWmsPrdReturnService
{
}
}

View File

@@ -19,6 +19,7 @@ using Newtonsoft.Json;
using Org.BouncyCastle.Crypto.Agreement; using Org.BouncyCastle.Crypto.Agreement;
using Senparc.CO2NET.Cache; using Senparc.CO2NET.Cache;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.Common.Extension; using Tnb.Common.Extension;
using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
@@ -399,11 +400,9 @@ namespace Tnb.WarehouseMgr
{ {
Logger.Information("开始处理WCS上传的取消任务"); Logger.Information("开始处理WCS上传的取消任务");
int row = await _db.Updateable<WmsDistaskH>().SetColumns(r => new WmsDistaskH int row = await _db.Updateable<WmsDistaskH>().SetColumns(r => new WmsDistaskH
{ {
agreement = "WCS上传取消(CANCELLED)信号 取消时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), agreement = "WCS上传取消(CANCELLED)信号",
status = WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID status = WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID
}).Where(P => P.bill_code.Contains(input.taskChainCode)).ExecuteCommandAsync(); }).Where(P => P.bill_code.Contains(input.taskChainCode)).ExecuteCommandAsync();
if (row > 0) if (row > 0)
@@ -420,11 +419,24 @@ namespace Tnb.WarehouseMgr
await WmsElevatorUnlock(wmsElevatorUnlockInput); await WmsElevatorUnlock(wmsElevatorUnlockInput);
Logger.Information($"WCS取消任务{wmsDistaskH.bill_code},自动解占用电梯{wmsDistaskH.device_id}"); Logger.Information($"WCS取消任务{wmsDistaskH.bill_code},自动解占用电梯{wmsDistaskH.device_id}");
} }
else
{
// 排除电梯任务 其他任务取消时自动解锁终点库位
int unlockRow = await _db.Updateable<BasLocation>().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.endlocation_code).ExecuteCommandAsync();
if (unlockRow > 0)
{
Logger.Information($"成功解锁库位{wmsDistaskH.endlocation_code}");
}
else
{
Logger.Information($"未成功解锁库位{wmsDistaskH.endlocation_code}");
}
}
} }
await _db.Updateable<WmsPretaskH>().SetColumns(r => new WmsPretaskH await _db.Updateable<WmsPretaskH>().SetColumns(r => new WmsPretaskH
{ {
note = "WCS上传取消(CANCELLED)信号 取消时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), note = "WCS上传取消(CANCELLED)信号",
status = WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID status = WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID
}).Where(P => wmsDistaskHCodes.Contains(P.bill_code)).ExecuteCommandAsync(); }).Where(P => wmsDistaskHCodes.Contains(P.bill_code)).ExecuteCommandAsync();
Logger.Information("成功处理WCS上传的取消任务"); Logger.Information("成功处理WCS上传的取消任务");
@@ -441,7 +453,7 @@ namespace Tnb.WarehouseMgr
Logger.Information("开始处理WCS上传的失败任务"); Logger.Information("开始处理WCS上传的失败任务");
int row = await _db.Updateable<WmsDistaskH>().SetColumns(r => new WmsDistaskH int row = await _db.Updateable<WmsDistaskH>().SetColumns(r => new WmsDistaskH
{ {
agreement = "WCS上传失败(FAILURE)信号 失败时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), agreement = "WCS上传失败(FAILURE)信号",
status = WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID status = WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID
}).Where(P => P.bill_code.Contains(input.taskChainCode)).ExecuteCommandAsync(); }).Where(P => P.bill_code.Contains(input.taskChainCode)).ExecuteCommandAsync();
if (row > 0) if (row > 0)
@@ -450,7 +462,7 @@ namespace Tnb.WarehouseMgr
await _db.Updateable<WmsPretaskH>().SetColumns(r => new WmsPretaskH await _db.Updateable<WmsPretaskH>().SetColumns(r => new WmsPretaskH
{ {
note = "WCS上传失败(FAILURE)信号 取消时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), note = "WCS上传失败(FAILURE)信号",
status = WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID status = WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID
}).Where(P => wmsDistaskHCodes.Contains(P.bill_code)).ExecuteCommandAsync(); }).Where(P => wmsDistaskHCodes.Contains(P.bill_code)).ExecuteCommandAsync();
Logger.Information("成功处理WCS上传的失败任务"); Logger.Information("成功处理WCS上传的失败任务");

View File

@@ -67,6 +67,7 @@ namespace Tnb.WarehouseMgr
private readonly ICacheManager _cacheManager; private readonly ICacheManager _cacheManager;
private readonly IElevatorControlService _elevatorControlService; private readonly IElevatorControlService _elevatorControlService;
private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryBindService _wmsCarryBindService;
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
private static readonly Dictionary<string, int> _elevatorAgvCtlStatusMap = new(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, int> _elevatorAgvCtlStatusMap = new(StringComparer.OrdinalIgnoreCase);
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>(); private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
private static Dictionary<string, object> locMap = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); private static Dictionary<string, object> locMap = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
@@ -86,6 +87,7 @@ namespace Tnb.WarehouseMgr
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, StackExRedisHelper redisData, public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, StackExRedisHelper redisData,
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService,
IWmsCarryBindService wmsCarryBindService, IWmsCarryBindService wmsCarryBindService,
IWmsCarryUnbindService wmsCarryUnbindService,
IRunService runService, IRunService runService,
IVisualDevService visualDevService IVisualDevService visualDevService
//IConfiguration configuration //IConfiguration configuration
@@ -99,6 +101,7 @@ namespace Tnb.WarehouseMgr
_elevatorControlService = elevatorControlService; _elevatorControlService = elevatorControlService;
_redisData = redisData; _redisData = redisData;
_wmsCarryBindService = wmsCarryBindService; _wmsCarryBindService = wmsCarryBindService;
_wmsCarryUnbindService = wmsCarryUnbindService;
_runService = runService; _runService = runService;
_visualDevService = visualDevService; _visualDevService = visualDevService;
//_configuration = configuration; //_configuration = configuration;
@@ -2133,7 +2136,7 @@ namespace Tnb.WarehouseMgr
CarryCodeUnbindInput carryCodeUnbindInput = new CarryCodeUnbindInput(); CarryCodeUnbindInput carryCodeUnbindInput = new CarryCodeUnbindInput();
carryCodeUnbindInput.carry_id = dt.carry_id; carryCodeUnbindInput.carry_id = dt.carry_id;
await _wmsCarryBindService.CarryCodeUnbind(carryCodeUnbindInput); await _wmsCarryUnbindService.CarryCodeUnbind(carryCodeUnbindInput);
} }
} }
// 成品调拨入库 // 成品调拨入库

View File

@@ -266,116 +266,7 @@ namespace Tnb.WarehouseMgr
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功"); return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功");
} }
/// <summary>
/// 解绑定料箱到料架
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AppFriendlyException"></exception>
[NonAction]
public async Task<Result> CarryUnbind(CarryBindInput input)
{
bool isOk = false;
try
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
if (carry != null)
{
int row = await _db.Deleteable<WmsCarryD>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
isOk = row > 0;
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
// 插入子载具绑定记录
VisualDevModelDataCrInput visualDevModelCrInput = new() { data = new Dictionary<string, object>() };
visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_id)] = input.carry_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_code)] = input.carry_code;
visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_id)] = input.membercarry_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_code)] = input.membercarry_code;
visualDevModelCrInput.data[nameof(WmsCarrybindH.type)] = 0;
visualDevModelCrInput.data[nameof(WmsCarrybindH.carrystd_id)] = carry.carrystd_id;
if (!string.IsNullOrEmpty(input.create_id))
visualDevModelCrInput.data[nameof(WmsCarrybindH.create_id)] = input.create_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.create_time)] = DateTime.Now;
visualDevModelCrInput.data[nameof(WmsCarrybindH.loc)] = 1;
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYUNBIND_ID, true);
await _runService.Create(templateEntity, visualDevModelCrInput);
await _db.Ado.CommitTranAsync();
}
else
{
if (carry == null)
{
throw new AppFriendlyException("没有可用的主载具", 500);
}
}
}
catch (Exception ex)
{
Logger.LogError($"【CarryUnbind】 {ex.Message}");
Logger.LogError($"【CarryUnbind】 {ex.StackTrace}");
await _db.Ado.RollbackTranAsync();
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
}
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功");
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AppFriendlyException"></exception>
[NonAction]
public async Task<dynamic> CarryCodeUnbind(CarryCodeUnbindInput input)
{
bool isOk = false;
try
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
if (carry != null)
{
int row = await _db.Deleteable<WmsCarryCode>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
isOk = row > 0;
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
else
{
if (carry == null)
{
throw new AppFriendlyException("没有可用的主载具", 500);
}
}
}
catch (Exception ex)
{
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
}
return Task.FromResult(true);
}
/* public override async Task ModifyAsync(WareHouseUpInput input) /* public override async Task ModifyAsync(WareHouseUpInput input)
{ {
if (input == null) throw new ArgumentNullException(nameof(input)); if (input == null) throw new ArgumentNullException(nameof(input));

View File

@@ -6,8 +6,12 @@ using JNPF.FriendlyException;
using JNPF.VisualDev; using JNPF.VisualDev;
using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces; using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SqlSugar; using SqlSugar;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces; using Tnb.WarehouseMgr.Interfaces;
@@ -17,25 +21,22 @@ namespace Tnb.WarehouseMgr
/// 载具解绑 /// 载具解绑
/// </summary> /// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRYUNBIND_ID)] [OverideVisualDev(ModuleConsts.MODULE_WMSCARRYUNBIND_ID)]
public class WmsCarryUnbindService : BaseWareHouseService public class WmsCarryUnbindService : BaseWareHouseService, IWmsCarryUnbindService
{ {
private readonly ISqlSugarClient _db; private readonly ISqlSugarClient _db;
private readonly IRunService _runService; private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService; private readonly IVisualDevService _visualDevService;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IWareHouseService _wareHouseService;
public WmsCarryUnbindService( public WmsCarryUnbindService(
ISqlSugarRepository<WmsCarryH> repository, ISqlSugarRepository<WmsCarryH> repository,
IRunService runService, IRunService runService,
IVisualDevService visualDevService, IVisualDevService visualDevService,
IWareHouseService wareHouseService,
IUserManager userManager) IUserManager userManager)
{ {
_db = repository.AsSugarClient(); _db = repository.AsSugarClient();
_runService = runService; _runService = runService;
_visualDevService = visualDevService; _visualDevService = visualDevService;
_userManager = userManager; _userManager = userManager;
_wareHouseService = wareHouseService;
OverideFuncs.CreateAsync = CarryUnbind; OverideFuncs.CreateAsync = CarryUnbind;
} }
private async Task<dynamic> CarryUnbind(VisualDevModelDataCrInput input) private async Task<dynamic> CarryUnbind(VisualDevModelDataCrInput input)
@@ -119,5 +120,116 @@ namespace Tnb.WarehouseMgr
var isOk = await _db.Updateable<WmsCarryReplaceH>().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); var isOk = await _db.Updateable<WmsCarryReplaceH>().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync();
if (!isOk) throw Oops.Oh(ErrorCode.COM1001); if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
}*/ }*/
/// <summary>
/// 解绑定料箱到料架
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AppFriendlyException"></exception>
[NonAction]
public async Task<Result> CarryUnbind(CarryBindInput input)
{
bool isOk = false;
try
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
if (carry != null)
{
int row = await _db.Deleteable<WmsCarryD>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
isOk = row > 0;
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
// 插入子载具绑定记录
VisualDevModelDataCrInput visualDevModelCrInput = new() { data = new Dictionary<string, object>() };
visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_id)] = input.carry_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.carry_code)] = input.carry_code;
visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_id)] = input.membercarry_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.membercarry_code)] = input.membercarry_code;
visualDevModelCrInput.data[nameof(WmsCarrybindH.type)] = 0;
visualDevModelCrInput.data[nameof(WmsCarrybindH.carrystd_id)] = carry.carrystd_id;
if (!string.IsNullOrEmpty(input.create_id))
visualDevModelCrInput.data[nameof(WmsCarrybindH.create_id)] = input.create_id;
visualDevModelCrInput.data[nameof(WmsCarrybindH.create_time)] = DateTime.Now;
visualDevModelCrInput.data[nameof(WmsCarrybindH.loc)] = 1;
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYUNBIND_ID, true);
await _runService.Create(templateEntity, visualDevModelCrInput);
await _db.Ado.CommitTranAsync();
}
else
{
if (carry == null)
{
throw new AppFriendlyException("没有可用的主载具", 500);
}
}
}
catch (Exception ex)
{
Logger.LogError($"【CarryUnbind】 {ex.Message}");
Logger.LogError($"【CarryUnbind】 {ex.StackTrace}");
await _db.Ado.RollbackTranAsync();
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
}
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功");
}
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AppFriendlyException"></exception>
[NonAction]
public async Task<dynamic> CarryCodeUnbind(CarryCodeUnbindInput input)
{
bool isOk = false;
try
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
if (carry != null)
{
int row = await _db.Deleteable<WmsCarryCode>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
isOk = row > 0;
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
else
{
if (carry == null)
{
throw new AppFriendlyException("没有可用的主载具", 500);
}
}
}
catch (Exception ex)
{
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
}
return Task.FromResult(true);
}
} }
} }

View File

@@ -49,7 +49,7 @@ namespace Tnb.WarehouseMgr
[ServiceModule(BizTypeId)] [ServiceModule(BizTypeId)]
public class WmsMaterialTransferService : BaseWareHouseService public class WmsMaterialTransferService : BaseWareHouseService
{ {
private const string BizTypeId = "34354738929685"; private const string BizTypeId = WmsWareHouseConst.BIZTYPE_WMSMATERIALTRANSFER_ID;
private readonly ISqlSugarClient _db; private readonly ISqlSugarClient _db;
private readonly IRunService _runService; private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService; private readonly IVisualDevService _visualDevService;
@@ -57,6 +57,7 @@ namespace Tnb.WarehouseMgr
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryBindService _wmsCarryBindService;
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
public static SemaphoreSlim s_taskDistributeToZCC = new(1); public static SemaphoreSlim s_taskDistributeToZCC = new(1);
@@ -67,7 +68,8 @@ namespace Tnb.WarehouseMgr
IWareHouseService wareHouseService, IWareHouseService wareHouseService,
IUserManager userManager, IUserManager userManager,
IBillRullService billRullService, IBillRullService billRullService,
IEventPublisher eventPublisher, IEventPublisher eventPublisher,
IWmsCarryUnbindService wmsCarryUnbindService,
IWmsCarryBindService wmsCarryBindService) IWmsCarryBindService wmsCarryBindService)
{ {
_db = repository.AsSugarClient(); _db = repository.AsSugarClient();
@@ -77,6 +79,7 @@ namespace Tnb.WarehouseMgr
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
_wmsCarryBindService = wmsCarryBindService; _wmsCarryBindService = wmsCarryBindService;
_wmsCarryUnbindService = wmsCarryUnbindService;
OverideFuncs.GetListAsync = GetList; OverideFuncs.GetListAsync = GetList;
} }
@@ -565,33 +568,45 @@ namespace Tnb.WarehouseMgr
{ {
throw new ArgumentNullException(nameof(input)); throw new ArgumentNullException(nameof(input));
} }
List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == input.carryIds[0]).ToListAsync();
if (wmsCarryCodes.Count == 0) try
{ {
Logger.LogWarning($"【ModifyAsync】载具{input.carryIds[0]}没有绑定物料条码"); List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == input.carryIds[0]).ToListAsync();
return; if (wmsCarryCodes.Count == 0)
{
Logger.LogWarning($"【WmsMaterialTransferService ModifyAsync】载具{input.carryIds[0]}没有绑定物料条码");
return;
}
await _db.Ado.BeginTranAsync();
// 更新已转数量
bool isOk = await _db.Updateable<WmsMaterialTransferD>().SetColumns(it => new WmsMaterialTransferD { yzqty = it.yzqty + wmsCarryCodes.Sum(r => r.codeqty) })
.Where(it => it.id == input.source_id).ExecuteCommandHasChangeAsync();
// 如果所有明细已完成 更新主表状态为完成
WmsMaterialTransferD wmsMaterialTransferd = await _db.Queryable<WmsMaterialTransferD>().Where(r => r.id == input.source_id).SingleAsync();
List<WmsMaterialTransferD> wmsMaterialTransferDs = _db.Queryable<WmsMaterialTransferD>()
.Where(a => a.bill_id == wmsMaterialTransferd.bill_id && a.yzqty < a.qty).ToList();
bool isOk2 = true;
if (wmsMaterialTransferDs.Count == 0)
{
isOk2 = await _db.Updateable<WmsMaterialTransfer>().SetColumns(it => new WmsMaterialTransfer { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID })
.Where(it => it.id == wmsMaterialTransferd.bill_id).ExecuteCommandHasChangeAsync();
}
// require_code是任务单
//string mo_task_code = input.require_code;
if (!isOk || !isOk2)
{
throw Oops.Oh(ErrorCode.COM1001);
}
await _db.Ado.CommitTranAsync();
} }
// 更新已转数量 catch(Exception ex)
bool isOk = await _db.Updateable<WmsMaterialTransferD>().SetColumns(it => new WmsMaterialTransferD { yzqty = it.yzqty + wmsCarryCodes.Sum(r => r.codeqty)})
.Where(it => it.id == input.source_id).ExecuteCommandHasChangeAsync();
// 如果所有明细已完成 更新主表状态为完成
WmsMaterialTransferD wmsMaterialTransferd = await _db.Queryable<WmsMaterialTransferD>().Where(r => r.id == input.source_id).SingleAsync();
List<WmsMaterialTransferD> wmsMaterialTransferDs = _db.Queryable<WmsMaterialTransferD>()
.Where(a => a.bill_id == wmsMaterialTransferd.bill_id && a.yzqty < a.qty).ToList();
bool isOk2 = true;
if (wmsMaterialTransferDs.Count == 0)
{ {
isOk2 = await _db.Updateable<WmsMaterialTransfer>().SetColumns(it => new WmsMaterialTransfer { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }) Logger.LogError("【WmsPrdReturnService ModifyAsync】" + ex.Message);
.Where(it => it.id == wmsMaterialTransferd.bill_id).ExecuteCommandHasChangeAsync(); Logger.LogError("【WmsPrdReturnService ModifyAsync】" + ex.StackTrace);
} await _db.Ado.RollbackTranAsync();
// require_code是任务单
//string mo_task_code = input.require_code;
if (!isOk || !isOk2)
{
throw Oops.Oh(ErrorCode.COM1001);
} }
} }
@@ -999,7 +1014,7 @@ namespace Tnb.WarehouseMgr
CarryBindInput carryBindInput = new(); CarryBindInput carryBindInput = new();
carryBindInput.carry_id = wmsCarryH.id; carryBindInput.carry_id = wmsCarryH.id;
carryBindInput.carry_code = wmsCarryH.carry_code; carryBindInput.carry_code = wmsCarryH.carry_code;
var resCarryUnbind = await _wmsCarryBindService.CarryUnbind(carryBindInput); var resCarryUnbind = await _wmsCarryUnbindService.CarryUnbind(carryBindInput);
if (resCarryUnbind.code != JNPF.Common.Enums.HttpStatusCode.OK) if (resCarryUnbind.code != JNPF.Common.Enums.HttpStatusCode.OK)
{ {
throw new AppFriendlyException($"解除绑定料箱到料架失败 载具 {input.carry_code}", 500); throw new AppFriendlyException($"解除绑定料箱到料架失败 载具 {input.carry_code}", 500);
@@ -1021,7 +1036,7 @@ namespace Tnb.WarehouseMgr
} }
} }
Logger.LogWarning($"【RackEmptyInstock】开始生成预任务"); Logger.LogWarning($"【RackInstock】开始生成预任务");
CommonCreatePretaskInput commonCreatePretaskInput = new(); CommonCreatePretaskInput commonCreatePretaskInput = new();
commonCreatePretaskInput.startlocation_id = startlocation.id; commonCreatePretaskInput.startlocation_id = startlocation.id;
commonCreatePretaskInput.endlocation_id = endlocation.id; commonCreatePretaskInput.endlocation_id = endlocation.id;
@@ -1080,7 +1095,7 @@ namespace Tnb.WarehouseMgr
await _db.Ado.BeginTranAsync(); await _db.Ado.BeginTranAsync();
Logger.LogWarning($"【RackEmptyInstock】开始生成预任务"); Logger.LogWarning($"【RackInstock】开始生成预任务");
CommonCreatePretaskInput commonCreatePretaskInput = new(); CommonCreatePretaskInput commonCreatePretaskInput = new();
commonCreatePretaskInput.startlocation_id = startlocation.id; commonCreatePretaskInput.startlocation_id = startlocation.id;
commonCreatePretaskInput.endlocation_id = endlocation.id; commonCreatePretaskInput.endlocation_id = endlocation.id;
@@ -1095,7 +1110,7 @@ namespace Tnb.WarehouseMgr
Logger.LogInformation($"【RackInstock】生成预任务失败 载具 {input.carry_code}"); Logger.LogInformation($"【RackInstock】生成预任务失败 载具 {input.carry_code}");
throw new AppFriendlyException($"生成预任务失败 载具 {input.carry_code}", 500); throw new AppFriendlyException($"生成预任务失败 载具 {input.carry_code}", 500);
} }
Logger.LogWarning($"【RackEmptyInstock】生成预任务成功"); Logger.LogWarning($"【RackInstock】生成预任务成功");
await _db.Ado.CommitTranAsync(); await _db.Ado.CommitTranAsync();
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -35,6 +35,7 @@ namespace Tnb.WarehouseMgr
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly IWareHouseService _wareHouseService; private readonly IWareHouseService _wareHouseService;
private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryBindService _wmsCarryBindService;
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
private readonly IWmsCarryService _wmsCarryService; private readonly IWmsCarryService _wmsCarryService;
@@ -47,6 +48,7 @@ namespace Tnb.WarehouseMgr
IWareHouseService wareHouseService, IWareHouseService wareHouseService,
IBillRullService billRullService, IBillRullService billRullService,
IWmsCarryBindService wmsCarryBindService, IWmsCarryBindService wmsCarryBindService,
IWmsCarryUnbindService wmsCarryUnbindService,
IWmsCarryService wmsCarryService) IWmsCarryService wmsCarryService)
{ {
_db = repository.AsSugarClient(); _db = repository.AsSugarClient();
@@ -56,6 +58,7 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_wmsCarryBindService = wmsCarryBindService; _wmsCarryBindService = wmsCarryBindService;
_wmsCarryUnbindService = wmsCarryUnbindService;
_wmsCarryService = wmsCarryService; _wmsCarryService = wmsCarryService;
OverideFuncs.CreateAsync = PDACarryBind; OverideFuncs.CreateAsync = PDACarryBind;
} }
@@ -401,7 +404,7 @@ namespace Tnb.WarehouseMgr
WmsCarryH wmsCarryH = _db.Queryable<WmsCarryH>().Where(r => r.location_id == input.location_id).First(); WmsCarryH wmsCarryH = _db.Queryable<WmsCarryH>().Where(r => r.location_id == input.location_id).First();
CarryCodeUnbindInput carryCodeUnbindInput = new CarryCodeUnbindInput(); CarryCodeUnbindInput carryCodeUnbindInput = new CarryCodeUnbindInput();
carryCodeUnbindInput.carry_id = wmsCarryH.id; carryCodeUnbindInput.carry_id = wmsCarryH.id;
await _wmsCarryBindService.CarryCodeUnbind(carryCodeUnbindInput); await _wmsCarryUnbindService.CarryCodeUnbind(carryCodeUnbindInput);
await _db.Ado.CommitTranAsync(); await _db.Ado.CommitTranAsync();
} }

View File

@@ -0,0 +1,381 @@
using System.Security.Cryptography.X509Certificates;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.FriendlyException;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NPOI.POIFS.Storage;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
using Tnb.WarehouseMgr.Entities.Entity;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
/// <summary>
/// 载具解绑
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSPRDRETURN_ID)]
[ServiceModule(BizTypeId)]
public class WmsPrdReturnService : BaseWareHouseService, IWmsPrdReturnService
{
private const string BizTypeId = WmsWareHouseConst.BIZTYPE_PRDRETURN_ID;
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private readonly IUserManager _userManager;
private readonly IWareHouseService _wareHouseService;
public WmsPrdReturnService(
ISqlSugarRepository<WmsCarryH> repository,
IRunService runService,
IVisualDevService visualDevService,
IWareHouseService wareHouseService,
IUserManager userManager)
{
_db = repository.AsSugarClient();
_runService = runService;
_visualDevService = visualDevService;
_userManager = userManager;
_wareHouseService = wareHouseService;
}
/// <summary>
/// 从产线呼叫装料架到暂存仓/缓存仓
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost, NonUnify, AllowAnonymous]
public async Task<Result> PrdReturn(PrdReturnInput input)
{
WmsPrdReturnH wmsPrdReturnH = await _db.Queryable<WmsPrdReturnH>().Where(r => r.id == input.source_id).FirstAsync();
if (wmsPrdReturnH == null)
{
Logger.LogWarning($"【PrdReturn】不存在id为{input.source_id}的生产退料单!");
throw new AppFriendlyException($"【PrdReturn】不存在id为{input.startlocation_id}的生产退料单!", 500);
}
if (wmsPrdReturnH.status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)
{
Logger.LogWarning($"【PrdReturn】生产退料单{wmsPrdReturnH.bill_code}状态为已完成!");
throw new AppFriendlyException($"【PrdReturn】生产退料单{wmsPrdReturnH.bill_code}状态为已完成!", 500);
}
if (wmsPrdReturnH.status == WmsWareHouseConst.BILLSTATUS_CANCEL_ID)
{
Logger.LogWarning($"【PrdReturn】生产退料单{wmsPrdReturnH.bill_code}状态为已取消!");
throw new AppFriendlyException($"【PrdReturn】生产退料单{wmsPrdReturnH.bill_code}状态为已取消!", 500);
}
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().Where(r => r.carry_code == input.carry_code).FirstAsync();
// 料架到暂存仓
if (wmsCarryH.carrystd_id == "26037267399717")
{
return await Return_到暂存仓(input, wmsCarryH, wmsPrdReturnH);
}
// 载运小车和载运料架到缓存仓
else if (wmsCarryH.carrystd_id == "26103233723941" || wmsCarryH.carrystd_id == "34995839046677")
{
return await Return_到缓存仓(input, wmsCarryH, wmsPrdReturnH);
}
else
{
Logger.LogError($"【PrdReturn】当前载具的规格id是{wmsCarryH.carrystd_id} 无法处理此类型的载具!");
return await ToApiResult(HttpStatusCode.InternalServerError, $"【PrdReturn】当前载具的规格id是{wmsCarryH.carrystd_id} 无法处理此类型的载具!");
}
}
async Task<Result> Return_到暂存仓(PrdReturnInput input, WmsCarryH wmsCarryH, WmsPrdReturnH wmsPrdReturnH)
{
try
{
BasLocation startlocation = _db.Queryable<BasLocation>().Where(r => r.id == input.startlocation_id).First();
if (startlocation == null)
{
Logger.LogWarning($"【PrdReturn】不存在id为{input.startlocation_id}的库位!");
throw new AppFriendlyException($"【PrdReturn】不存在id为{input.startlocation_id}的库位!", 500);
}
if (string.IsNullOrEmpty(input.carry_code))
{
Logger.LogWarning($"【PrdReturn】料架不能为空{input.carry_code}");
throw new AppFriendlyException($"【PrdReturn】料架不能为空{input.carry_code}", 500);
}
// 找到未占用且未锁定的库位
ISugarQueryable<BasLocation> rackEndLocations =
_db.Queryable<BasLocation>()
.Where(r => r.wh_id == "33780009364245" && r.is_use == "0" && r.is_lock == 0 && r.is_type == "0").OrderBy(a => a.id).Take(1);
if (rackEndLocations.Count() == 0)
{
Logger.LogWarning($"【PrdReturn】没有可用的终点库位");
throw new AppFriendlyException($"【PrdReturn】没有可用的终点库位", 500);
}
BasLocation endlocation = rackEndLocations.First();
var memberCarryCodes = _db.Queryable<WmsCarryD>()
.InnerJoin<WmsCarryH>((a, b) => a.membercarry_id == b.id)
.InnerJoin<WmsCarryCode>((a, b, c) => b.id == c.carry_id)
.Where((a, b, c) => a.carry_id == wmsCarryH.id).Select((a, b, c) => new
{
carry_code = b.carry_code,
barcode = c.barcode,
material_id = c.material_id,
material_code = c.material_code,
}).ToList();
List<string> matIds = memberCarryCodes.Select(r => r.material_id).Distinct().ToList();
// 匹配生产退料单明细的物料种类
List<string> existsMatIds = _db.Queryable<WmsPrdReturnD>().Where(r => r.bill_id == input.source_id).Select(r => r.material_id).Distinct().ToList();
List<string> notExistsMatIds = matIds.Where(r => !existsMatIds.Contains(r)).ToList();
if (notExistsMatIds.Count() > 0)
{
var existsMat = memberCarryCodes.Where(r => notExistsMatIds.Contains(r.material_id)).Select(r => new
{
carry_code = r.carry_code,
barcode = r.barcode,
});
string msg = "";
foreach (var row in existsMat)
{
msg += $",料箱{row.carry_code} 条码{row.barcode}";
}
Logger.LogWarning($"【PrdReturn】存在装有与生产退料单明细不匹配物料的料箱请检查 {msg.Trim(',')}");
throw new AppFriendlyException($"【PrdReturn】存在装有与生产退料单明细不匹配物料的料箱请检查{msg.Trim(',')}", 500);
}
WmsPretaskH wmsPretaskH = _db.Queryable<WmsPretaskH>().Where(r => r.carry_code == wmsCarryH.carry_code && r.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID).First();
if (wmsPretaskH != null)
{
Logger.LogWarning($"【CallRackToProductionLine】此料架{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}");
throw new AppFriendlyException($"此料架{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}", 500);
}
await _db.Ado.BeginTranAsync();
Logger.LogWarning($"【PrdReturn】开始生成预任务");
CommonCreatePretaskInput commonCreatePretaskInput = new();
commonCreatePretaskInput.startlocation_id = startlocation.id;
commonCreatePretaskInput.endlocation_id = endlocation.id;
commonCreatePretaskInput.source_id = input.source_id;
commonCreatePretaskInput.carry_id = wmsCarryH.id;
commonCreatePretaskInput.carry_code = input.carry_code;
commonCreatePretaskInput.task_type = "";
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_PRDRETURN_ID;
var res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput);
if (res.code != JNPF.Common.Enums.HttpStatusCode.OK)
{
Logger.LogInformation($"【PrdReturn】生成预任务失败 载具 {input.carry_code}");
throw new AppFriendlyException($"生成预任务失败 载具 {input.carry_code}", 500);
}
Logger.LogWarning($"【PrdReturn】生成预任务成功");
await _db.Ado.CommitTranAsync();
}
catch (Exception ex)
{
Logger.LogError("【PrdReturn】" + ex.Message);
Logger.LogError("【PrdReturn】" + ex.StackTrace);
await _db.Ado.RollbackTranAsync();
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
}
return await ToApiResult(HttpStatusCode.OK, "成功");
}
async Task<Result> Return_到缓存仓(PrdReturnInput input, WmsCarryH wmsCarryH, WmsPrdReturnH wmsPrdReturnH)
{
try
{
BasLocation startlocation = _db.Queryable<BasLocation>().Where(r => r.id == input.startlocation_id).First();
if (startlocation == null)
{
Logger.LogWarning($"【PrdReturn】不存在id为{input.startlocation_id}的库位!");
throw new AppFriendlyException($"【PrdReturn】不存在id为{input.startlocation_id}的库位!", 500);
}
if (string.IsNullOrEmpty(input.carry_code))
{
Logger.LogWarning($"【PrdReturn】料架不能为空{input.carry_code}");
throw new AppFriendlyException($"【PrdReturn】料架不能为空{input.carry_code}", 500);
}
// 找到未占用且未锁定的库位
ISugarQueryable<BasLocation> rackEndLocations =
_db.Queryable<BasLocation>()
.Where(r => r.wh_id == "26103348825381" && r.is_use == "0" && r.is_lock == 0 && r.is_type == "0").OrderBy(a => a.id).Take(1);
if (rackEndLocations.Count() == 0)
{
Logger.LogWarning($"【PrdReturn】没有可用的终点库位");
throw new AppFriendlyException($"【PrdReturn】没有可用的终点库位", 500);
}
BasLocation endlocation = rackEndLocations.First();
var memberCarryCodes = _db.Queryable<WmsCarryH>()
.InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
.Where((a, b) => a.id == wmsCarryH.id).Select((a, b) => new
{
carry_code = a.carry_code,
barcode = b.barcode,
material_id = b.material_id,
material_code = b.material_code,
}).ToList();
List<string> matIds = memberCarryCodes.Select(r => r.material_id).Distinct().ToList();
// 匹配生产退料单明细的物料种类
List<string> existsMatIds = _db.Queryable<WmsPrdReturnD>().Where(r => r.bill_id == input.source_id).Select(r => r.material_id).Distinct().ToList();
List<string> notExistsMatIds = matIds.Where(r => !existsMatIds.Contains(r)).ToList();
if (notExistsMatIds.Count() > 0)
{
var existsMat = memberCarryCodes.Where(r => notExistsMatIds.Contains(r.material_id)).Select(r => new
{
carry_code = r.carry_code,
barcode = r.barcode,
});
string msg = "";
foreach (var row in existsMat)
{
msg += $",料箱{row.carry_code} 条码{row.barcode}";
}
Logger.LogWarning($"【PrdReturn】存在装有与生产退料单明细不匹配物料的料箱请检查 {msg.Trim(',')}");
throw new AppFriendlyException($"【PrdReturn】存在装有与生产退料单明细不匹配物料的料箱请检查{msg.Trim(',')}", 500);
}
WmsPretaskH wmsPretaskH = _db.Queryable<WmsPretaskH>().Where(r => r.carry_code == wmsCarryH.carry_code && r.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID).First();
if (wmsPretaskH != null)
{
Logger.LogWarning($"【CallRackToProductionLine】此料架{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}");
throw new AppFriendlyException($"此料架{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}", 500);
}
await _db.Ado.BeginTranAsync();
Logger.LogWarning($"【PrdReturn】开始生成预任务");
CommonCreatePretaskInput commonCreatePretaskInput = new();
commonCreatePretaskInput.startlocation_id = startlocation.id;
commonCreatePretaskInput.endlocation_id = endlocation.id;
commonCreatePretaskInput.source_id = input.source_id;
commonCreatePretaskInput.carry_id = wmsCarryH.id;
commonCreatePretaskInput.carry_code = input.carry_code;
commonCreatePretaskInput.task_type = "";
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_PRDRETURN_ID;
var res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput);
if (res.code != JNPF.Common.Enums.HttpStatusCode.OK)
{
Logger.LogInformation($"【PrdReturn】生成预任务失败 载具 {input.carry_code}");
throw new AppFriendlyException($"生成预任务失败 载具 {input.carry_code}", 500);
}
Logger.LogWarning($"【PrdReturn】生成预任务成功");
await _db.Ado.CommitTranAsync();
}
catch (Exception ex)
{
Logger.LogError("【PrdReturn】" + ex.Message);
Logger.LogError("【PrdReturn】" + ex.StackTrace);
await _db.Ado.RollbackTranAsync();
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
}
return await ToApiResult(HttpStatusCode.OK, "成功");
}
public override async Task ModifyAsync(WareHouseUpInput input)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
try
{
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().Where(r => r.id == input.carryIds[0]).FirstAsync();
List<WmsCarryCode> wmsCarryCodes = null;
// 料架到暂存仓
if (wmsCarryH.carrystd_id == "26037267399717")
{
wmsCarryCodes = _db.Queryable<WmsCarryD>()
.InnerJoin<WmsCarryH>((a, b) => a.membercarry_id == b.id)
.InnerJoin<WmsCarryCode>((a, b, c) => b.id == c.carry_id)
.Where((a, b, c) => a.carry_id == wmsCarryH.id).Select((a, b, c) => c).ToList();
}
// 载运小车和载运料架到缓存仓
else if (wmsCarryH.carrystd_id == "26103233723941" || wmsCarryH.carrystd_id == "34995839046677")
{
wmsCarryCodes = _db.Queryable<WmsCarryH>()
.InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
.Where((a, b) => a.id == wmsCarryH.id).Select((a, b) => b).ToList();
}
else
{
Logger.LogError($"【WmsPrdReturnService ModifyAsync】当前载具的规格id是{wmsCarryH.carrystd_id} 无法处理此类型的载具!");
return;
}
if (wmsCarryCodes.Count == 0)
{
Logger.LogWarning($"【WmsPrdReturnService ModifyAsync】载具{input.carryIds[0]}没有绑定物料条码");
return;
}
await _db.Ado.BeginTranAsync();
// 更新已转数量
List<WmsPrdReturnD> wmsPrdReturnDs = _db.Queryable<WmsPrdReturnD>().Where(r => r.bill_id == input.source_id).ToList();
foreach (WmsPrdReturnD wmsPrdReturnD in wmsPrdReturnDs)
{
decimal qty = wmsCarryCodes.Where(r => r.material_id == wmsPrdReturnD.material_id).Sum(r => r.codeqty);
wmsPrdReturnD.ytqty = wmsPrdReturnD.ytqty + qty;
}
bool isOk = await _db.Updateable(wmsPrdReturnDs).UpdateColumns(r => r.ytqty).ExecuteCommandAsync() > 0;
// 如果所有明细已完成 更新主表状态为完成
wmsPrdReturnDs = _db.Queryable<WmsPrdReturnD>()
.Where(a => a.bill_id == input.source_id && a.ytqty < a.qty).ToList();
bool isOk2 = true;
if (wmsPrdReturnDs.Count == 0)
{
isOk2 = await _db.Updateable<WmsPrdReturnH>().SetColumns(it => new WmsPrdReturnH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID })
.Where(it => it.id == input.source_id).ExecuteCommandHasChangeAsync();
}
// require_code是任务单
//string mo_task_code = input.require_code;
if (!isOk || !isOk2)
{
throw Oops.Oh(ErrorCode.COM1001);
}
await _db.Ado.CommitTranAsync();
}
catch(Exception ex)
{
Logger.LogError("【WmsPrdReturnService ModifyAsync】" + ex.Message);
Logger.LogError("【WmsPrdReturnService ModifyAsync】" + ex.StackTrace);
await _db.Ado.RollbackTranAsync();
}
}
}
}