物料签收新接口

This commit is contained in:
2023-07-14 14:32:47 +08:00
parent 1eaae0a983
commit 0203cec1ca
3 changed files with 166 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ClearScript.Util.Web;
@@ -13,6 +14,8 @@ using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Consts;
using Tnb.WarehouseMgr;
using Tnb.WarehouseMgr.Entities;
namespace Tnb.ProductionMgr
{
@@ -26,16 +29,20 @@ namespace Tnb.ProductionMgr
private readonly ISqlSugarRepository<PrdFeedingH> _repository;
private readonly IUserManager _userManager;
private readonly IBillRullService _billRullService;
private readonly WmsSignForDeliveryService _wmsSignForDeliveryService;
public PrdFeedingService(
ISqlSugarRepository<PrdFeedingH> repository,
IBillRullService billRullService,
WmsSignForDeliveryService wmsSignForDeliveryService,
IUserManager userManager
)
{
_repository = repository;
_userManager = userManager;
_wmsSignForDeliveryService = _wmsSignForDeliveryService;
_billRullService = billRullService;
}
@@ -132,6 +139,131 @@ namespace Tnb.ProductionMgr
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
});
if (result.IsSuccess)
{
//签收后调用载具签收接口
await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
{
org_id = _userManager.GetUserInfo().Result.organizeId,
create_id = _userManager.UserId,
carry_code = input.carry_code ?? "",
});
}
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
}
[HttpPost]
public async Task<dynamic> SaveDataNew(MaterialReceiptNewInput input)
{
var db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
var moTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == input.mo_task_id);
var parentMoTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == moTask.parent_id);
var carry = await db.Queryable<WmsCarryH>().SingleAsync(x => x.carry_code == input.carry_code);
var workline = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == parentMoTask.workline_id);
var workshop = await db.Queryable<OrganizeEntity>().SingleAsync(x=>x.Id==workline.ParentId);
var inputMaterials = await db.Queryable<BasMbomInput>()
.Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == moTask.mbom_process_id)
.Select(x=>x.material_id)
.ToListAsync();
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE);
PrdFeedingH prdFeedingH = new PrdFeedingH()
{
code = code,
station_id = input.station_id,
mo_task_id = input.mo_task_id,
process_id = moTask.process_id,
equip_id = input.equip_id,
workshop_id = workshop?.Id,
carry_id = carry.id,
workline_id = moTask.workline_id,
carry_code = input.carry_code,
// remark = input.remark,
mbom_process_id = moTask.mbom_process_id,
create_id = _userManager.UserId,
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId
};
List<PrdFeedingD> list = new List<PrdFeedingD>();
if (input.details != null && input.details.Count > 0)
{
foreach (var item in input.details)
{
if(!inputMaterials.Contains(item["material_id"]))
throw new Exception("该物料不是生产bom投入物料不能签收");
var detail = await db.Queryable<PrdMaterialReceiptD>()
.Where(x => x.carry_id == carry.id && x.is_all_feeding == 0).FirstAsync();
decimal num = Convert.ToDecimal(item["num"]);
list.Add(new PrdFeedingD
{
feeding_id = prdFeedingH.id,
material_receipt_detail_id = detail?.id,
material_id = item["material_id"],
num = num,
batch = item["batch"],
unit_id = item["unit_id"],
carry_id = carry.id,
status = "0",
use_num = 0,
});
if (detail != null)
{
if(detail.feeding_num + num > detail.num)
{
throw new Exception("投料数量不能大于签收数量");
}else if (detail.feeding_num + num == detail.num)
{
await db.Updateable<PrdMaterialReceiptD>()
.SetColumns(x => x.feeding_num == x.feeding_num + num)
.SetColumns(x => x.is_all_feeding == 1)
.Where(x => x.id == detail.id)
.ExecuteCommandAsync();
}
else
{
await db.Updateable<PrdMaterialReceiptD>()
.SetColumns(x => x.feeding_num == x.feeding_num + num)
.Where(x => x.id == detail.id)
.ExecuteCommandAsync();
}
}
else
{
throw new Exception("没有签收单,无法投料");
}
}
}
else
{
throw new Exception("没有签收物料");
}
await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
});
if (result.IsSuccess)
{
//签收后调用载具签收接口
await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
{
org_id = _userManager.GetUserInfo().Result.organizeId,
create_id = _userManager.UserId,
carry_code = input.carry_code ?? "",
});
}
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
return result.IsSuccess ? "签收成功" : result.ErrorMessage;