320 lines
12 KiB
C#
320 lines
12 KiB
C#
using System.Dynamic;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using Senparc.Weixin.MP.AdvancedAPIs.Card;
|
|
using SqlSugar;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
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>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRYBIND_ID)]
|
|
public class WmsCarryBindService : BaseWareHouseService, IWmsCarryBindService
|
|
{
|
|
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IBillRullService _billRullService;
|
|
public WmsCarryBindService(
|
|
ISqlSugarRepository<WmsCarryH> repository,
|
|
IRunService runService,
|
|
IVisualDevService visualDevService,
|
|
IUserManager userManager,
|
|
IBillRullService billRullService)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
_userManager = userManager;
|
|
_billRullService = billRullService;
|
|
OverideFuncs.CreateAsync = CarryBind;
|
|
|
|
|
|
}
|
|
|
|
[NonAction]
|
|
public async Task<dynamic> CarryBind(VisualDevModelDataCrInput input)
|
|
{
|
|
bool isOk = false;
|
|
try
|
|
{
|
|
await _db.Ado.BeginTranAsync();
|
|
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYBIND_ID, true);
|
|
await _runService.Create(templateEntity, input);
|
|
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
string? carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : "";
|
|
string? subCarryId = input.data.ContainsKey("membercarry_id") ? input.data["membercarry_id"]?.ToString() : "";
|
|
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId);
|
|
WmsCarryH? subCarry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == subCarryId);
|
|
if (carry != null && subCarry != null)
|
|
{
|
|
carry.carry_status = ((int)EnumCarryStatus.占用).ToString();
|
|
int row = await _db.Updateable(carry).ExecuteCommandAsync();
|
|
subCarry.carry_status = ((int)EnumCarryStatus.占用).ToString();
|
|
row = await _db.Updateable(subCarry).ExecuteCommandAsync();
|
|
//更新载具明细表
|
|
WmsCarryD wmsCarryD = new()
|
|
{
|
|
id = SnowflakeIdHelper.NextId(),
|
|
carry_id = carry.id,
|
|
org_id = carry?.org_id!,
|
|
membercarry_id = subCarry.id,
|
|
membercarry_code = subCarry.carry_code,
|
|
loc = input.data[nameof(WmsCarrybindH.loc)].ParseToInt(1),
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now
|
|
};
|
|
row = await _db.Insertable(wmsCarryD).ExecuteCommandAsync();
|
|
List<WmsCarryCode> items = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == subCarryId).ToListAsync();
|
|
List<WmsCarrybindCode> wmsCarrybindCodes = new();
|
|
//更新载具绑定条码表
|
|
for (int i = 0; i < items.Count; i++)
|
|
{
|
|
WmsCarrybindCode wmsCarrybindCode = new()
|
|
{
|
|
id = SnowflakeIdHelper.NextId(),
|
|
org_id = (subCarry != null && subCarry.org_id != null) ? subCarry.org_id : _userManager.User.OrganizeId,
|
|
carrybind_id = input.data["ReturnIdentity"]?.ToString()!,
|
|
material_id = items[i].material_id,
|
|
material_code = items[i].material_code,
|
|
barcode = items[i].barcode,
|
|
code_batch = items[i].code_batch,
|
|
codeqty = items[i].codeqty,
|
|
membercarry_id = subCarry?.id,
|
|
membercarry_code = subCarry?.carry_code,
|
|
unit_id = items[i].unit_id,
|
|
unit_code = items[i].unit_code,
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now
|
|
};
|
|
wmsCarrybindCodes.Add(wmsCarrybindCode);
|
|
}
|
|
row = await _db.Insertable(wmsCarrybindCodes).ExecuteCommandAsync();
|
|
isOk = row > 0;
|
|
if (!isOk)
|
|
{
|
|
throw Oops.Oh(ErrorCode.COM1001);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (carry == null || subCarry == null)
|
|
{
|
|
throw new AppFriendlyException("没有可用的主载具", 500);
|
|
}
|
|
}
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
throw;
|
|
}
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetInfoByCode(string code)
|
|
{
|
|
|
|
var data = await _db.Queryable<WmsTempCode>().Where(p => p.barcode == code).FirstAsync();
|
|
if(data==null)
|
|
throw new AppFriendlyException("没有条码信息", 500);
|
|
var result = data.Adapt<CarryMaterialDetail>();
|
|
return result;
|
|
}
|
|
[HttpPost]
|
|
public async Task CarryMaterialBind(CarryMaterialBindInput input)
|
|
{
|
|
try
|
|
{
|
|
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carrycode);
|
|
List<WmsCarryCode> WmsCarryCodes = new List<WmsCarryCode>();
|
|
foreach (var detail in input.details)
|
|
{
|
|
var WmsCarryCode = detail.Adapt<WmsCarryCode>();
|
|
WmsCarryCode.id = SnowflakeIdHelper.NextId();
|
|
WmsCarryCode.carry_id = carry.id;
|
|
WmsCarryCode.is_out = 0;
|
|
WmsCarryCodes.Add(WmsCarryCode);
|
|
}
|
|
if (WmsCarryCodes.Count > 0)
|
|
await _db.Insertable(WmsCarryCodes).ExecuteCommandAsync();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new AppFriendlyException("绑定失败", 500);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 二楼机械手
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="AppFriendlyException"></exception>
|
|
[NonAction]
|
|
public async Task<dynamic> CarryBindFloor2UpDownMachine(CarryBindFloor2UpDownMachineInput input)
|
|
{
|
|
bool isOk = false;
|
|
try
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
|
|
WmsCarryH? subCarry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.membercarry_id);
|
|
if (carry != null && subCarry != null)
|
|
{
|
|
WmsCarryD wmsCarryD = new()
|
|
{
|
|
carry_id = input.carry_id,
|
|
membercarry_id = input.membercarry_id,
|
|
membercarry_code = input.membercarry_code,
|
|
loc = 1,
|
|
create_time = DateTime.Now
|
|
};
|
|
int row = await _db.Insertable(wmsCarryD).ExecuteCommandAsync();
|
|
isOk = row > 0;
|
|
if (!isOk)
|
|
{
|
|
throw Oops.Oh(ErrorCode.COM1001);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (carry == null || subCarry == null)
|
|
{
|
|
throw new AppFriendlyException("没有可用的主载具", 500);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 二楼机械手解绑定
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="AppFriendlyException"></exception>
|
|
[NonAction]
|
|
public async Task<dynamic> CarryUnbindFloor2UpDownMachine(CarryBindFloor2UpDownMachineInput input)
|
|
{
|
|
bool isOk = false;
|
|
try
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
|
|
if (carry != null)
|
|
{
|
|
int row = await _db.Deleteable<WmsCarryD>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
|
|
isOk = row > 0;
|
|
|
|
if (!isOk)
|
|
{
|
|
throw Oops.Oh(ErrorCode.COM1001);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (carry == null)
|
|
{
|
|
throw new AppFriendlyException("没有可用的主载具", 500);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="AppFriendlyException"></exception>
|
|
[NonAction]
|
|
public async Task<dynamic> CarryCodeUnbind(CarryCodeUnbindInput input)
|
|
{
|
|
bool isOk = false;
|
|
try
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
|
|
if (carry != null)
|
|
{
|
|
int row = await _db.Deleteable<WmsCarryCode>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
|
|
isOk = row > 0;
|
|
|
|
if (!isOk)
|
|
{
|
|
throw Oops.Oh(ErrorCode.COM1001);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (carry == null)
|
|
{
|
|
throw new AppFriendlyException("没有可用的主载具", 500);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
return Task.FromResult(true);
|
|
}
|
|
/* public override async Task ModifyAsync(WareHouseUpInput input)
|
|
{
|
|
if (input == null) throw new ArgumentNullException(nameof(input));
|
|
var isOk = await _db.Updateable<WmsCarryReplaceH>().SetColumns(it => new WmsCarryReplaceH { status = input.bizTypeId }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync();
|
|
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
|
|
}*/
|
|
}
|
|
}
|