80 lines
3.3 KiB
C#
80 lines
3.3 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Message.Service;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.TaskScheduler;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class MesForErpService: IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IBillRullService _billRuleService;
|
|
|
|
public MesForErpService(ISqlSugarRepository<PrdMo> repository,
|
|
IBillRullService billRuleService,
|
|
IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
_billRuleService = billRuleService;
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<string> SavePrdMo(PrdMo input)
|
|
{
|
|
if (input == null)
|
|
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<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}该单位");
|
|
|
|
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";
|
|
|
|
}
|
|
}
|
|
} |