137 lines
5.5 KiB
C#
137 lines
5.5 KiB
C#
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Enums;
|
||
using JNPF.Common.Security;
|
||
using JNPF.DependencyInjection;
|
||
using JNPF.DynamicApiController;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using SqlSugar;
|
||
using Tnb.BasicData.Entities;
|
||
using Tnb.ProductionMgr.Entities;
|
||
using Tnb.ProductionMgr.Entities.Dto;
|
||
using Tnb.ProductionMgr.Interfaces;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities.Dto;
|
||
using Tnb.ProductionMgr.Entities.Consts;
|
||
|
||
namespace Tnb.ProductionMgr
|
||
{
|
||
/// <summary>
|
||
/// 业务实现:物料签收
|
||
/// </summary>
|
||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||
[Route("api/[area]/[controller]/[action]")]
|
||
public class PrdMaterialReceiptService : IPrdMaterialReceiptService, IDynamicApiController, ITransient
|
||
{
|
||
private readonly ISqlSugarRepository<PrdMaterialReceiptH> _repository;
|
||
private readonly IUserManager _userManager;
|
||
private readonly IBillRullService _billRullService;
|
||
|
||
|
||
public PrdMaterialReceiptService(
|
||
ISqlSugarRepository<PrdMaterialReceiptH> repository,
|
||
IBillRullService billRullService,
|
||
IUserManager userManager
|
||
)
|
||
{
|
||
_repository = repository;
|
||
_userManager = userManager;
|
||
_billRullService = billRullService;
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> GetInfoByQrCode(string qrCode)
|
||
{
|
||
var db = _repository.AsSugarClient();
|
||
var result = await db.Queryable<WmsCarryH>()
|
||
.Where((a) => a.carry_code == qrCode)
|
||
.Select(a => new
|
||
{
|
||
carry_id = a.id,
|
||
carry_name = a.carry_name,
|
||
children = SqlFunc.Subqueryable<WmsCarryCode>()
|
||
.LeftJoin<BasMaterial>((b,c)=>b.material_id==c.id)
|
||
.Where((b,c)=>a.id==b.carry_id).ToList((b,c)=>new CarryCodeDetailOutput()
|
||
{
|
||
unit_id = c.unit_id,
|
||
barcode = b.barcode,
|
||
code_batch = b.code_batch,
|
||
codeqty = b.codeqty,
|
||
material_id = b.material_id,
|
||
material_code = c.code,
|
||
material_name = c.name
|
||
})
|
||
}).FirstAsync();
|
||
return result;
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> SaveData(MaterialReceiptInput 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 inputMaterials = await db.Queryable<BasMbomInput>()
|
||
.Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == input.mbom_process_id)
|
||
.Select(x=>x.material_id)
|
||
.ToListAsync();
|
||
|
||
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.MATERIAL_RECEIPT_CODE);
|
||
PrdMaterialReceiptH prdMaterialReceiptH = new PrdMaterialReceiptH()
|
||
{
|
||
code = code,
|
||
station_id = input.station_id,
|
||
mo_task_id = input.mo_task_id,
|
||
process_id = input.process_id,
|
||
equip_id = input.equip_id,
|
||
workshop_id = input.workshop_id,
|
||
carry_id = input.carry_id,
|
||
workline_id = input.workline_id,
|
||
carry_code = input.carry_code,
|
||
remark = input.remark,
|
||
mbom_process_id = input.mbom_process_id,
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
org_id = _userManager.GetUserInfo().Result.organizeId
|
||
};
|
||
|
||
List<PrdMaterialReceiptD> list = new List<PrdMaterialReceiptD>();
|
||
if (input.details != null && input.details.Count > 0)
|
||
{
|
||
foreach (var item in input.details)
|
||
{
|
||
if(!inputMaterials.Contains(item["material_id"]))
|
||
throw new Exception("该物料不是生产bom投入物料,不能签收");
|
||
|
||
list.Add(new PrdMaterialReceiptD
|
||
{
|
||
material_receipt_id = prdMaterialReceiptH.id,
|
||
material_id = item["material_id"],
|
||
num = Convert.ToDecimal(item["num"]),
|
||
batch = item["batch"],
|
||
unit_id = item["unit_id"],
|
||
carry_id = input.carry_id,
|
||
is_all_feeding = 0,
|
||
feeding_num = 0,
|
||
});
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("没有签收物料");
|
||
}
|
||
|
||
|
||
await db.Insertable<PrdMaterialReceiptH>(prdMaterialReceiptH).ExecuteCommandAsync();
|
||
await db.Insertable<PrdMaterialReceiptD>(list).ExecuteCommandAsync();
|
||
|
||
});
|
||
|
||
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
|
||
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
|
||
}
|
||
}
|
||
} |