载具更换代码优化
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
@@ -18,16 +26,22 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class WmsCarryService : IWmsCarryService, IDynamicApiController, ITransient
|
||||
[OverideVisualDev(ModuleId)]
|
||||
public class WmsCarryService : IOverideVisualDevService, IWmsCarryService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "26188532491557";
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
public WmsCarryService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager)
|
||||
private readonly IBillRullService _billRullService;
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
public WmsCarryService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager, IBillRullService billRullService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
_billRullService = billRullService;
|
||||
OverideFuncs.CreateAsync = ExchangeCarry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更换载具
|
||||
/// </summary>
|
||||
@@ -41,64 +55,27 @@ namespace Tnb.WarehouseMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
[HttpPost]
|
||||
public async Task Exchange(ExChangeCarryInput input)
|
||||
public async Task<dynamic> ExchangeCarry(VisualDevModelDataCrInput input)
|
||||
{
|
||||
var row = -1;
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
var oldCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == input.old_carry_id && it.is_lock == 0 && it.status == 0 && it.carry_status != 0);
|
||||
var newCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == input.new_carry_id && it.is_lock == 0 && it.status == 0 && it.carry_status == 0);
|
||||
if (oldCarry != null && newCarry != null)
|
||||
var isOk = false;
|
||||
try
|
||||
{
|
||||
var subCarrys = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarrys?.Count > 0)
|
||||
await _db.Ado.BeginTranAsync();
|
||||
var oldCarryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : "";
|
||||
var newCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : "";
|
||||
var oldCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == oldCarryId);
|
||||
var newCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == newCarryId);
|
||||
if (oldCarry != null && newCarry != null)
|
||||
{
|
||||
List<WmsCarryD> newSubCarrys = DeepCopyHelper<WmsCarryD>.DeepCopyList(subCarrys);
|
||||
if (newSubCarrys?.Count > 0)
|
||||
{
|
||||
newSubCarrys.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newSubCarrys).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarrys).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
var subCarryMats = await _db.Queryable<WmsCarryMat>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarryMats?.Count > 0)
|
||||
{
|
||||
List<WmsCarryMat> newCarryMats = DeepCopyHelper<WmsCarryMat>.DeepCopyList(subCarryMats);
|
||||
if (newCarryMats?.Count > 0)
|
||||
{
|
||||
newCarryMats.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newCarryMats).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarryMats).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
var subCarryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarryCodes?.Count > 0)
|
||||
{
|
||||
List<WmsCarryCode> newCarrayCodes = DeepCopyHelper<WmsCarryCode>.DeepCopyList(subCarryCodes);
|
||||
if (newCarrayCodes?.Count > 0)
|
||||
{
|
||||
newCarrayCodes.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newCarrayCodes).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarryCodes).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
newCarry.carry_name = oldCarry.carry_name;
|
||||
ExChangeCarryInput carryInput = new() { old_carry_id = oldCarry.id, new_carry_id = newCarry.id };
|
||||
isOk = await _updateSubCarry<WmsCarryD>(carryInput);
|
||||
isOk = await _updateSubCarry<WmsCarryMat>(carryInput);
|
||||
isOk = await _updateSubCarry<WmsCarryCode>(carryInput);
|
||||
|
||||
newCarry.status = oldCarry.status;
|
||||
newCarry.carry_status = oldCarry.carry_status;
|
||||
newCarry.carrystd_id = oldCarry.carrystd_id;
|
||||
newCarry.location_id = oldCarry.location_id;
|
||||
newCarry.carry_code = oldCarry.location_code;
|
||||
newCarry.location_code = oldCarry.location_code;
|
||||
newCarry.is_lock = oldCarry.is_lock;
|
||||
newCarry.out_status = oldCarry.out_status;
|
||||
newCarry.is_check = oldCarry.is_check;
|
||||
@@ -109,29 +86,91 @@ namespace Tnb.WarehouseMgr
|
||||
newCarry.source_code = oldCarry.source_code;
|
||||
newCarry.create_id = _userManager.UserId;
|
||||
newCarry.create_time = DateTime.Now;
|
||||
row = await _db.Updateable(newCarry).ExecuteCommandAsync();
|
||||
var row = await _db.Updateable(newCarry).ExecuteCommandAsync();
|
||||
WmsCarryReplaceH wmsCarryReplaceH = oldCarry.Adapt<WmsCarryReplaceH>();
|
||||
wmsCarryReplaceH.org_id = oldCarry.org_id;
|
||||
wmsCarryReplaceH.bill_code = await _billRullService.GetBillNumber(WmsCarryConst.WMS_CARRY_REPLACE_ENCODE);
|
||||
wmsCarryReplaceH.carry_id = oldCarry.id;
|
||||
wmsCarryReplaceH.carry_code = oldCarry.carry_code;
|
||||
wmsCarryReplaceH.newcarry_id = newCarry.id;
|
||||
wmsCarryReplaceH.newcarry_code = newCarry.carry_code;
|
||||
row = await _db.Insertable(wmsCarryReplaceH).ExecuteCommandAsync();
|
||||
row = await UpdateNullCarry(oldCarry);
|
||||
isOk = (row > 0);
|
||||
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oldCarry == null)
|
||||
{
|
||||
throw new AppFriendlyException("没有可用的旧载具", 500);
|
||||
}
|
||||
if (newCarry == null)
|
||||
{
|
||||
throw new AppFriendlyException("没有可用的新载具", 500);
|
||||
}
|
||||
|
||||
}
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("载具更换失败", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
public Task<int> UpdateNullCarry(WmsCarryH carryObj)
|
||||
public async Task<int> UpdateNullCarry(WmsCarryH carryObj)
|
||||
{
|
||||
carryObj.carry_name = null;
|
||||
carryObj.status = 0;
|
||||
carryObj.carry_status = 0;
|
||||
carryObj.carrystd_id = null;
|
||||
carryObj.location_id = null;
|
||||
carryObj.carry_code = null;
|
||||
carryObj.out_status = null;
|
||||
carryObj.is_check = 0;
|
||||
carryObj.bale_num = null;
|
||||
carryObj.collocation_scheme_id = null;
|
||||
carryObj.collocation_scheme_code = null;
|
||||
carryObj.source_id = null;
|
||||
carryObj.source_code = null;
|
||||
return _db.Updateable(carryObj).ExecuteCommandAsync();
|
||||
var row = -1;
|
||||
try
|
||||
{
|
||||
carryObj.status = 0;
|
||||
carryObj.carry_status = "0";
|
||||
carryObj.location_id = null;
|
||||
carryObj.location_code = null;
|
||||
carryObj.out_status = "0";
|
||||
carryObj.is_check = 0;
|
||||
carryObj.status = 1;
|
||||
carryObj.bale_num = null;
|
||||
carryObj.collocation_scheme_id = null;
|
||||
carryObj.collocation_scheme_code = null;
|
||||
carryObj.source_id = null;
|
||||
carryObj.source_code = null;
|
||||
row = await _db.Updateable(carryObj).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
private async Task<bool> _updateSubCarry<T>(ExChangeCarryInput input) where T : BaseEntity<string>, IWmsCarryEntity, new()
|
||||
{
|
||||
var row = -1;
|
||||
var items = await _db.Queryable<T>().Where(it => it.carry_id == input.old_carry_id).ToListAsync();
|
||||
if (items?.Count > 0)
|
||||
{
|
||||
List<T> newItems = DeepCopyHelper<T>.DeepCopyList(items);
|
||||
if (newItems?.Count > 0)
|
||||
{
|
||||
newItems.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.carry_id = input.new_carry_id;
|
||||
|
||||
});
|
||||
row = await _db.Insertable(newItems).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(items).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
return (row > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user