erp生产工单

This commit is contained in:
2024-07-03 17:02:05 +08:00
parent d2f3a7aff7
commit 2da3feb5e4
8 changed files with 138 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
@@ -13,6 +14,7 @@ using SqlSugar;
using Tnb.BasicData;
using Tnb.BasicData.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Entities.Entity;
using Tnb.WarehouseMgr.Entities.Consts;
namespace Tnb.ProductionMgr
@@ -25,6 +27,14 @@ namespace Tnb.ProductionMgr
private readonly IUserManager _userManager;
private readonly IBillRullService _billRuleService;
public static Dictionary<string, string> moTypeDic = new Dictionary<string, string>()
{
["1"] = "25019163616533", //注塑
["2"] = "25019172714005", //挤出
["3"] = "25019181615125", //组装
["4"] = "25019191681045", //包装
};
public MesForErpService(ISqlSugarRepository<PrdMo> repository,
IBillRullService billRuleService,
IUserManager userManager)
@@ -36,45 +46,71 @@ namespace Tnb.ProductionMgr
[HttpPost]
[AllowAnonymous]
public async Task<string> SavePrdMo(PrdMo input)
public async Task<string> SavePrdMo(List<PrdMo> input)
{
if (input == null)
if (input == null || input.IsEmpty())
throw Oops.Bah("参数不能为空");
if(string.IsNullOrEmpty(input.mo_code))
throw Oops.Bah("工单代码不能为空");
if(string.IsNullOrEmpty(input.mo_type))
throw Oops.Bah("工单类型不能为空");
if(input.plan_start_date==null)
throw Oops.Bah("计划开始日期不能为空");
if(input.plan_end_date==null)
throw Oops.Bah("计划结束日期不能为空");
if(string.IsNullOrEmpty(input.material_code))
throw Oops.Bah("物料编号不能为空");
if(string.IsNullOrEmpty(input.unit_id))
throw Oops.Bah("单位不能为空");
if(input.plan_qty==null || input.plan_qty<=0)
throw Oops.Bah("计划数量不能为空");
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x => x.code == input.material_code);
if(basMaterial==null)
throw Oops.Bah($"未找到物料编号为{input.material_code}的物料");
List<PrdMo> moList = new List<PrdMo>();
List<ErpExtendField> extendFieldList = new List<ErpExtendField>();
foreach (var item in input)
{
if(string.IsNullOrEmpty(item.mo_code))
throw Oops.Bah("工单代码不能为空");
if(string.IsNullOrEmpty(item.mo_type))
throw Oops.Bah("工单类型不能为空");
if(item.plan_start_date==null)
throw Oops.Bah("计划开始日期不能为空");
if(item.plan_end_date==null)
throw Oops.Bah("计划结束日期不能为空");
if(string.IsNullOrEmpty(item.material_code))
throw Oops.Bah("物料编号不能为空");
if(string.IsNullOrEmpty(item.unit_id))
throw Oops.Bah("单位不能为空");
if(item.plan_qty==null || item.plan_qty<=0)
throw Oops.Bah("计划数量不能为空");
if(item.ebom_version==null || item.ebom_version.IsEmpty())
throw Oops.Bah("物料清单版本不能为空");
List<BasMaterialUnit> basMaterialUnits = await _db.Queryable<BasMaterialUnit>().Where(x => x.material_id == basMaterial.id).ToListAsync();
List<String> units = basMaterialUnits.Select(x => x.auxiliary_unit_id).Distinct().ToList();
if(units!=null && !string.IsNullOrEmpty(basMaterial.unit_id)) units.Add(basMaterial.unit_id);
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x => x.code == item.material_code);
if(basMaterial==null)
throw Oops.Bah($"未找到物料编号为{item.material_code}的物料");
List<BasMaterialUnit> basMaterialUnits = await _db.Queryable<BasMaterialUnit>().Where(x => x.material_id == basMaterial.id).ToListAsync();
List<String> units = basMaterialUnits.Select(x => x.auxiliary_unit_id).Distinct().ToList();
if(units!=null && !string.IsNullOrEmpty(basMaterial.unit_id)) units.Add(basMaterial.unit_id);
if(!units.Contains(input.unit_id))
throw Oops.Bah($"{basMaterial.name}不存在{input.unit_id}该单位");
if(!units.Contains(item.unit_id))
throw Oops.Bah($"{basMaterial.name}不存在{item.unit_id}该单位");
input.id = SnowflakeIdHelper.NextId();
input.mo_source = "1";
input.mo_code = input.mo_code;
input.create_id = WmsWareHouseConst.AdministratorUserId;
input.create_time = DateTime.Now;
input.mo_status = DictConst.ToBeScheduledId;
await _db.Insertable(input).ExecuteCommandAsync();
return "true";
item.id = SnowflakeIdHelper.NextId();
item.mo_source = "1";
item.mo_type = moTypeDic[item.mo_type];
item.mo_code = item.mo_code+"-"+item.erp_lineno;
item.create_id = WmsWareHouseConst.AdministratorUserId;
item.create_time = DateTime.Now;
item.mo_status = DictConst.ToBeScheduledId;
moList.Add(item);
extendFieldList.Add(new ErpExtendField()
{
id = SnowflakeIdHelper.NextId(),
org_id =WmsWareHouseConst.AdministratorOrgId,
table_name = "prd_mo",
table_id = item.id,
erp_lineno = item.erp_lineno,
erp_line_pk = item.erp_line_pk,
erp_mo_pk = item.erp_mo_pk,
create_time = DateTime.Now
});
}
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
{
await _db.Insertable(moList).ExecuteCommandAsync();
await _db.Insertable(extendFieldList).ExecuteCommandAsync();
});
return !result.IsSuccess ? result.ErrorMessage : "保存成功";
}
}
}