Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs

137 lines
6.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.Common.Utils;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
/// <summary>
/// 载具服务
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class WmsCarryService : IWmsCarryService, IDynamicApiController, ITransient
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
public WmsCarryService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager)
{
_db = repository.AsSugarClient();
_userManager = userManager;
}
/// <summary>
/// 更换载具
/// </summary>
/// <param name="input">
/// 输入参数:
/// <br/>{
/// <br/> old_carry_id:老载具id
/// <br/> new_carry_id新载具ID
/// <br/>}
/// </param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[HttpPost]
public async Task Exchange(ExChangeCarryInput 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 subCarrys = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
if (subCarrys?.Count > 0)
{
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;
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.is_lock = oldCarry.is_lock;
newCarry.out_status = oldCarry.out_status;
newCarry.is_check = oldCarry.is_check;
newCarry.bale_num = oldCarry.bale_num;
newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id;
newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code;
newCarry.source_id = oldCarry.source_id;
newCarry.source_code = oldCarry.source_code;
newCarry.create_id = _userManager.UserId;
newCarry.create_time = DateTime.Now;
row = await _db.Updateable(newCarry).ExecuteCommandAsync();
row = await UpdateNullCarry(oldCarry);
}
}
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
}
public 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();
}
}
}