生产投料

This commit is contained in:
2024-06-28 11:09:03 +08:00
parent df0be4e15d
commit 8a13c5d593
4 changed files with 93 additions and 27 deletions

View File

@@ -19,6 +19,7 @@ namespace Tnb.ProductionMgr.Entities.Dto
public string code { get; set; }
public string carry_code { get; set; }
public string create_id { get; set; }
public string station_id { get; set; }
public string create_time { get; set; }
}

View File

@@ -94,5 +94,10 @@ public partial class PrdMaterialReceiptH : BaseEntity<string>
/// 生产bom工序id
/// </summary>
public string? mbom_process_id { get; set; }
/// <summary>
/// 第一次投料
/// </summary>
public bool first_feed { get; set; }
}

View File

@@ -95,12 +95,14 @@ namespace Tnb.ProductionMgr
act_start_date = a.act_start_date==null ? "" : a.act_start_date.Value.ToString(DbTimeFormat.SS),
tablefield102 = SqlFunc.Subqueryable<PrdFeedingH>()
.LeftJoin<UserEntity>((x,y)=>x.create_id==y.Id)
.Where(x=>x.mo_task_id==a.id).ToList((x,y)=>new PrdFeedingRecordUpListChildOutPut()
.LeftJoin<OrganizeEntity>((x,y,z)=>x.station_id==y.Id)
.Where(x=>x.mo_task_id==a.id).ToList((x,y,z)=>new PrdFeedingRecordUpListChildOutPut()
{
id = x.id,
code = x.code,
carry_code = x.carry_code,
create_id = y.RealName,
station_id = z.FullName,
create_time = x.create_time==null ? "" : x.create_time.Value.ToString(DbTimeFormat.SS),
}),

View File

@@ -4,6 +4,7 @@ using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
@@ -365,9 +366,11 @@ namespace Tnb.ProductionMgr
PrdFeedingH? prdFeedingH = null;
List<PrdFeedingD> list = new();
DbResult<bool> result2 = new();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
try
{
await db.Ado.BeginTranAsync();
PrdMoTask parentMoTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == moTask.parent_id);
string worklineId = moTask.workline_id;
if (parentMoTask != null && !string.IsNullOrEmpty(parentMoTask.workline_id))
@@ -402,6 +405,7 @@ namespace Tnb.ProductionMgr
org_id = _userManager.GetUserInfo().Result.organizeId
};
PrdMaterialReceiptH prdMaterialReceiptH = null;
if (input.details != null && input.details.Count > 0)
{
foreach (var item in input.details)
@@ -413,6 +417,17 @@ namespace Tnb.ProductionMgr
PrdMaterialReceiptD? detail = await db.Queryable<PrdMaterialReceiptD>()
.Where(x => x.member_carry_code == input.carry_code && x.is_all_feeding == 0).FirstAsync();
if (prdMaterialReceiptH == null)
{
prdMaterialReceiptH = await db.Queryable<PrdMaterialReceiptH>()
.SingleAsync(x => x.id == detail.material_receipt_id);
}
WmsCarryCode wmsCarryCode = await db.Queryable<WmsCarryCode>().Where(x=>x.carry_id==carry.id).FirstAsync();
if (wmsCarryCode == null)
{
throw Oops.Bah($"未找到条码信息,载具id{carry.id}");
}
decimal num = item.codeqty;
list.Add(new PrdFeedingD
{
@@ -420,34 +435,13 @@ namespace Tnb.ProductionMgr
material_receipt_detail_id = detail?.id,
material_id = item.material_id,
num = num,
batch = item.code_batch,
batch = wmsCarryCode.code_batch,
unit_id = item.unit_id,
carry_id = carry.id,
status = "0",
use_num = 0,
});
// Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryUnbind(new CarryBindInput()
// {
// org = prdFeedingH.org_id,
// create_id = prdFeedingH.create_id,
// carry_id = prdFeedingH.carry_id,
// carry_code = prdFeedingH.carry_code,
// carrystd_id = carry.carrystd_id,
// membercarry_code = detail.member_carry_code,
// membercarry_id = detail.member_carry_id,
// });
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput()
{
carry_id = detail.member_carry_id
});
if (result.code != JNPF.Common.Enums.HttpStatusCode.OK)
{
throw Oops.Bah(result.msg);
}
if (detail != null)
{
@@ -467,6 +461,32 @@ namespace Tnb.ProductionMgr
.SetColumns(x => x.feeding_num == x.feeding_num + num)
.Where(x => x.id == detail.id)
.ExecuteCommandAsync();
if (detail.feeding_num + num < detail.num)
{
await db.Updateable<WmsCarryCode>()
.SetColumns(x => x.codeqty == x.codeqty - num)
.Where(x => x.carry_id == detail.member_carry_id)
.ExecuteCommandAsync();
}
else
{
// await db.Updateable<WmsCarryCode>()
// .SetColumns(x => x.codeqty == 0)
// .Where(x => x.carry_id == detail.member_carry_id)
// .ExecuteCommandAsync();
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput()
{
carry_id = detail.member_carry_id
});
if (result.code != JNPF.Common.Enums.HttpStatusCode.OK)
{
throw Oops.Bah(result.msg);
}
}
}
}
else
@@ -475,6 +495,36 @@ namespace Tnb.ProductionMgr
}
}
if (prdMaterialReceiptH.first_feed)
{
List<PrdMaterialReceiptD> dList = await db.Queryable<PrdMaterialReceiptD>()
.Where(x => x.material_receipt_id == prdMaterialReceiptH.id).ToListAsync();
foreach (var item in dList)
{
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result2 = await _wmsCarryUnbindService.CarryUnbind(new CarryBindInput()
{
org = prdFeedingH.org_id,
create_id = prdFeedingH.create_id,
carry_id = prdFeedingH.carry_id,
carry_code = prdFeedingH.carry_code,
carrystd_id = carry.carrystd_id,
membercarry_code = item.member_carry_code,
membercarry_id = item.member_carry_id,
});
if (result2.code != JNPF.Common.Enums.HttpStatusCode.OK)
{
throw Oops.Bah(result2.msg);
}
}
await db.Updateable<PrdMaterialReceiptH>()
.SetColumns(x => x.first_feed == true)
.Where(x => x.id == prdMaterialReceiptH.id)
.ExecuteCommandAsync();
}
}
else
{
@@ -484,11 +534,19 @@ namespace Tnb.ProductionMgr
_ = await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
_ = await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
await db.Ado.CommitTranAsync();
});
}
catch (Exception e)
{
Log.Error(e.Message,e);
await db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
return !result.IsSuccess ? throw Oops.Bah(result.ErrorMessage) : (dynamic)(result.IsSuccess ? "投料成功" : result.ErrorMessage);
return "投料成功";
}
[HttpPost]