修改PDA投料

This commit is contained in:
FanLian
2023-06-20 20:10:34 +08:00
parent 5a4cbb95e7
commit 3c781a56bf

View File

@@ -11,6 +11,7 @@ using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev; using JNPF.VisualDev;
using Mapster; using Mapster;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities; using Tnb.BasicData.Entities;
using Tnb.Common.Utils; using Tnb.Common.Utils;
@@ -34,7 +35,7 @@ namespace Tnb.WarehouseMgr
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly WmsCarryService _wmsCarryService; private readonly WmsCarryService _wmsCarryService;
private static Dictionary<string, object> dicMaterial = new Dictionary<string, object>(); private static Dictionary<string, object> dicMaterial = new Dictionary<string, object>();
public WmsPDAFeedingService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager, IBillRullService billRullService,WmsCarryService wmsCarryService) public WmsPDAFeedingService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager, IBillRullService billRullService, WmsCarryService wmsCarryService)
{ {
_db = repository.AsSugarClient(); _db = repository.AsSugarClient();
_userManager = userManager; _userManager = userManager;
@@ -42,60 +43,66 @@ namespace Tnb.WarehouseMgr
_wmsCarryService = wmsCarryService; _wmsCarryService = wmsCarryService;
OverideFuncs.CreateAsync = WmsPDAFeeding; OverideFuncs.CreateAsync = WmsPDAFeeding;
} }
private async Task<dynamic> WmsPDAFeeding(VisualDevModelDataCrInput input) private async Task<dynamic> WmsPDAFeeding(VisualDevModelDataCrInput input)
{ {
var isOk = false; var isOk = false;
try try
{ {
await _db.Ado.BeginTranAsync(); await _db.Ado.BeginTranAsync();
var oldCarryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : ""; var carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : "";
var newCarryId = input.data.ContainsKey("newcarry_id") ? input.data["newcarry_id"]?.ToString() : ""; var feedBoxCode = input.data.ContainsKey("feedbox_code") ? input.data["feedbox_code"]?.ToString() : "";
var oldCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == oldCarryId); var carry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == carryId);
var newCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == newCarryId); var feedBox = await _db.Queryable<WmsFeedbox>().FirstAsync(it => it.feedbox_code == feedBoxCode);
if (oldCarry != null && newCarry != null) var citem = await _db.Queryable<WmsCarryMat>().FirstAsync(it => it.carry_id == carryId);
if (carry != null && feedBox != null)
{ {
ExChangeCarryInput carryInput = new() { old_carry_id = oldCarry.id, new_carry_id = newCarry.id }; feedBox.material_id = citem.material_id;
isOk = await _updateSubCarry<WmsCarryD>(carryInput); feedBox.material_code = citem.material_code;
isOk = await _updateSubCarry<WmsCarryMat>(carryInput); feedBox.qty = citem.qty;
isOk = await _updateSubCarry<WmsCarryCode>(carryInput); feedBox.batch = citem?.code_batch!;
var row = await _db.Updateable(feedBox).UpdateColumns(it => new
{
it.material_id,
it.material_code,
it.qty,
it.batch
}).ExecuteCommandAsync();
/* var row = await _db.Updateable(feedBox).SetColumns(it => new
{
it.material_id == item.material_id,it.material_code
}
)*/
newCarry.status = oldCarry.status; var items = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == carryId).ToListAsync();
newCarry.carry_status = oldCarry.carry_status; foreach (var item in items)
newCarry.location_id = oldCarry.location_id; {
newCarry.location_code = oldCarry.location_code; WmsFeedingrecordCode wmsFeedingRecordCode = new();
newCarry.is_lock = oldCarry.is_lock; wmsFeedingRecordCode.id = SnowflakeIdHelper.NextId();
newCarry.out_status = oldCarry.out_status; wmsFeedingRecordCode.org_id = carry?.org_id!;
newCarry.is_check = oldCarry.is_check; wmsFeedingRecordCode.record_id = input.data["ReturnIdentity"]?.ToString()!;
newCarry.bale_num = oldCarry.bale_num; wmsFeedingRecordCode.material_id = item.material_id;
newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id; wmsFeedingRecordCode.material_code = item.material_code;
newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code; wmsFeedingRecordCode.barcode = item.barcode;
newCarry.source_id = oldCarry.source_id; wmsFeedingRecordCode.code_batch = item.code_batch;
newCarry.source_code = oldCarry.source_code; wmsFeedingRecordCode.codeqty = item.codeqty;
newCarry.create_id = _userManager.UserId; wmsFeedingRecordCode.unit_id = item.unit_id;
newCarry.create_time = DateTime.Now; wmsFeedingRecordCode.unit_code = item.unit_code;
var row = await _db.Updateable(newCarry).ExecuteCommandAsync(); wmsFeedingRecordCode.create_id = _userManager.UserId;
WmsCarryReplaceH wmsCarryReplaceH = oldCarry.Adapt<WmsCarryReplaceH>(); wmsFeedingRecordCode.create_time = DateTime.Now;
wmsCarryReplaceH.id = SnowflakeIdHelper.NextId(); row = await _db.Insertable(wmsFeedingRecordCode).ExecuteCommandAsync();
wmsCarryReplaceH.org_id = oldCarry.org_id; }
wmsCarryReplaceH.bill_code = await _billRullService.GetBillNumber(WmsCarryConst.WMS_CARRY_REPLACE_ENCODE); row = await UpdateNullCarry(carry);
wmsCarryReplaceH.carry_id = oldCarry.id;
wmsCarryReplaceH.carry_code = oldCarry.carry_code;
wmsCarryReplaceH.newcarry_id = newCarry.id;
wmsCarryReplaceH.newcarry_code = newCarry.carry_code;
row = await _db.Insertable(wmsCarryReplaceH).ExecuteCommandAsync();
row = await UpdateNullCarry(oldCarry);
isOk = (row > 0); isOk = (row > 0);
if (!isOk) throw Oops.Oh(ErrorCode.COM1001); if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
} }
else else
{ {
if (oldCarry == null) if (carry == null)
{ {
throw new AppFriendlyException("没有可用的旧载具", 500); throw new AppFriendlyException("没有可用的旧载具", 500);
} }
if (newCarry == null) if (feedBox == null)
{ {
throw new AppFriendlyException("没有可用的新载具", 500); throw new AppFriendlyException("没有可用的新载具", 500);
} }