增加新业务转运签收
This commit is contained in:
137
WarehouseMgr/Tnb.WarehouseMgr/PDATransferSignService.cs
Normal file
137
WarehouseMgr/Tnb.WarehouseMgr/PDATransferSignService.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Mapster;
|
||||
using JNPF.Common.Security;
|
||||
using System.Collections.Immutable;
|
||||
//using JNPF.Extras.CollectiveOAuth.Utils;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class PDATransferSignService : BaseWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
private static Dictionary<string, object> _dicBizType = new();
|
||||
public PDATransferSignService(ISqlSugarRepository<WmsDistaskH> repository, IDictionaryDataService dictionaryDataService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转运签收
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task SignForDelivery(SignForDeliveryInput input)
|
||||
{
|
||||
if (_dicBizType.Count < 1)
|
||||
{
|
||||
_dicBizType = await _dictionaryDataService.GetDictionaryByTypeId(WmsWareHouseConst.WMS_BIZTYPE_ID);
|
||||
}
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
WmsCarryH? carry = null;
|
||||
WmsCarryH? newCarry = null;
|
||||
if (!input.carryId.IsNullOrWhiteSpace())
|
||||
{
|
||||
carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carryId);
|
||||
}
|
||||
else
|
||||
{
|
||||
carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carry_code);
|
||||
}
|
||||
if (!input.new_carry_code.IsNullOrWhiteSpace())
|
||||
newCarry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.new_carry_code);
|
||||
if (carry != null && newCarry != null)
|
||||
{
|
||||
if (carry?.location_id?.IsNotEmptyOrNull() ?? false)
|
||||
{
|
||||
var loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == carry.location_id);
|
||||
loc.is_use = ((int)EnumCarryStatus.空闲).ToString();
|
||||
await _db.Updateable(loc).UpdateColumns(it => it.is_use).ExecuteCommandAsync();
|
||||
}
|
||||
WmsDistaskH? disTask = null;
|
||||
if (!input.disTaskId.IsNullOrEmpty())
|
||||
{
|
||||
disTask = await _db.Queryable<WmsDistaskH>().SingleAsync(it => it.id == input.disTaskId);
|
||||
}
|
||||
else if (!input.carryId.IsNullOrEmpty())
|
||||
{
|
||||
disTask = await _db.Queryable<WmsDistaskH>().FirstAsync(it => it.carry_id == input.carryId && it.is_sign == 0);
|
||||
}
|
||||
else if (!input.carry_code.IsNullOrEmpty())
|
||||
{
|
||||
disTask = await _db.Queryable<WmsDistaskH>().FirstAsync(it => it.carry_code == input.carry_code && it.is_sign == 0);
|
||||
}
|
||||
if (disTask != null)
|
||||
{
|
||||
var nCCode = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == newCarry.id).ToListAsync();
|
||||
var dicMin = await _db.Queryable<BasMaterial>().Where(it => input.distaskCodes.Select(x => x.material_id).Contains(it.id)).ToDictionaryAsync(d => d.id, d => d.minpacking);
|
||||
WmsCarryCode cCode = new WmsCarryCode();
|
||||
List<WmsCarryCode> iCodes = new List<WmsCarryCode>();
|
||||
List<WmsCarryCode> uCodes = new List<WmsCarryCode>();
|
||||
foreach (var dCode in input.distaskCodes)
|
||||
{
|
||||
decimal codeQty = 0;
|
||||
var sMCode = nCCode.Find(x => x.material_id == dCode.material_id && x.codeqty <= dicMin[dCode.material_id].ParseToDecimal());
|
||||
cCode = dCode.Adapt<WmsCarryCode>();
|
||||
cCode.carry_id = newCarry.id;
|
||||
cCode.code_batch = $"{DateTime.Today.Year}{DateTime.Today.Month}{DateTime.Today.Day}";
|
||||
if (sMCode != null)
|
||||
{
|
||||
codeQty = sMCode.codeqty;
|
||||
cCode.codeqty += codeQty;
|
||||
cCode.id = sMCode.id;
|
||||
uCodes.Add(cCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
cCode.id = SnowflakeIdHelper.NextId();
|
||||
iCodes.Add(cCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
await _db.Insertable(iCodes).ExecuteCommandAsync();
|
||||
await _db.Updateable(uCodes).ExecuteCommandAsync();
|
||||
if (_dicBizType.ContainsKey(disTask.biz_type))
|
||||
{
|
||||
WareHouseUpInput upInput = new()
|
||||
{
|
||||
loginType = "web",
|
||||
bizTypeId = disTask.biz_type,
|
||||
requireId = disTask!.require_id!,
|
||||
carryIds = new List<string> { carry!.id },
|
||||
distaskCodes = input.distaskCodes
|
||||
};
|
||||
await DoUpdate(upInput); //回更业务
|
||||
}
|
||||
disTask.is_sign = 1;
|
||||
await _db.Updateable(disTask).UpdateColumns(it => it.is_sign).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user