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 { /// /// 载具服务 /// [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 repository, IUserManager userManager) { _db = repository.AsSugarClient(); _userManager = userManager; } /// /// 更换载具 /// /// /// 输入参数: ///
{ ///
old_carry_id:老载具id ///
new_carry_id:新载具ID ///
} /// /// /// [HttpPost] public async Task Exchange(ExChangeCarryInput input) { var row = -1; if (input == null) throw new ArgumentNullException("input"); var oldCarry = await _db.Queryable().FirstAsync(it => it.id == input.old_carry_id && it.is_lock == 0 && it.status == 0 && it.carry_status != 0); var newCarry = await _db.Queryable().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().Where(it => it.carry_id == oldCarry.id).ToListAsync(); if (subCarrys?.Count > 0) { List newSubCarrys = DeepCopyHelper.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().Where(it => it.carry_id == oldCarry.id).ToListAsync(); if (subCarryMats?.Count > 0) { List newCarryMats = DeepCopyHelper.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().Where(it => it.carry_id == oldCarry.id).ToListAsync(); if (subCarryCodes?.Count > 0) { List newCarrayCodes = DeepCopyHelper.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 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(); } } }