149 lines
6.0 KiB
C#
149 lines
6.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using JNPF.Common.Contracts;
|
||
using JNPF.Common.Enums;
|
||
using JNPF.Common.Extension;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using Mapster;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.CodeAnalysis.Operations;
|
||
using SqlSugar;
|
||
using Tnb.BasicData.Entities;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities.Consts;
|
||
using Tnb.WarehouseMgr.Entities.Dto;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||
using Tnb.WarehouseMgr.Entities.Enums;
|
||
using Tnb.WarehouseMgr.Interfaces;
|
||
|
||
namespace Tnb.WarehouseMgr
|
||
{
|
||
/// <summary>
|
||
/// 出库签收
|
||
/// </summary>
|
||
public class WmsSignForDeliveryService : BaseWareHouseService, IWmsSignForDeliveryService
|
||
{
|
||
private readonly ISqlSugarClient _db;
|
||
private readonly IWmsCarryService _wareCarryService;
|
||
private readonly IDictionaryDataService _dictionaryDataService;
|
||
private readonly IWmsCarryMoveInStockService _wmsCarryMoveInStockService;
|
||
private static Dictionary<string, object> _dicBizType = new();
|
||
public WmsSignForDeliveryService(ISqlSugarRepository<WmsDistaskH> repository, IWmsCarryService wareCarryService, IDictionaryDataService dictionaryDataService, IWmsCarryMoveInStockService wmsCarryMoveInStockService)
|
||
{
|
||
_db = repository.AsSugarClient();
|
||
_wareCarryService = wareCarryService;
|
||
_dictionaryDataService = dictionaryDataService;
|
||
_wmsCarryMoveInStockService = wmsCarryMoveInStockService;
|
||
}
|
||
/// <summary>
|
||
/// 根据载具ID获取,对应的执行任务记录
|
||
/// </summary>
|
||
/// <param name="carryId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<dynamic> GetDisTasksByCarryId([FromRoute] string carryId)
|
||
{
|
||
var item = await _db.Queryable<WmsDistaskH>().FirstAsync(it => it.carry_id == carryId && it.status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID && it.is_sign == 0);
|
||
return item;
|
||
}
|
||
/// <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;
|
||
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 (carry != 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)
|
||
{
|
||
if (_dicBizType.ContainsKey(disTask.biz_type))
|
||
{
|
||
WareHouseUpInput upInput = new()
|
||
{
|
||
loginType = "web",
|
||
bizTypeId = disTask.biz_type,
|
||
requireId = disTask!.require_id!,
|
||
carryIds = new List<string> { input.carryId },
|
||
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;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// MES调用载具签收接口
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<dynamic> MESCarrySign(MESCarrySignInput input)
|
||
{
|
||
var isSuccessFul = false;
|
||
if (input.IsNull()) throw new ArgumentNullException("input");
|
||
var signInput = input.Adapt<SignForDeliveryInput>();
|
||
if(signInput.carryId.IsNotEmptyOrNull()) signInput.carryId = "";
|
||
try
|
||
{
|
||
await SignForDelivery(signInput);
|
||
isSuccessFul = true;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
isSuccessFul = false;
|
||
}
|
||
return isSuccessFul;
|
||
}
|
||
}
|
||
}
|