齐套接口返回成功后再操作数据库,生产工单列表优化,提报完工数不能大于任务单数 完成后修改状态
This commit is contained in:
@@ -13,6 +13,7 @@ using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.BasicData.Entities;
|
||||
@@ -32,32 +33,30 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
private const string ModuleId = "27565198830357";
|
||||
private readonly ISqlSugarRepository<PrdKittingOutH> _repository;
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IBillRullService _billRullService;
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
|
||||
public PrdKittingOutService(ISqlSugarRepository<PrdKittingOutH> repository, IRunService runService, IUserManager userManager,IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
|
||||
public PrdKittingOutService(ISqlSugarRepository<PrdKittingOutH> repository, IRunService runService, IBillRullService billRullService,IUserManager userManager,IVisualDevService visualDevService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
_repository = repository;
|
||||
_userManager = userManager;
|
||||
_billRullService = billRullService;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
}
|
||||
|
||||
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
||||
{
|
||||
PrdKittingOutH prdKittingOutH = new PrdKittingOutH();
|
||||
try
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
List<MESKittingOutStkInput> input = new List<MESKittingOutStkInput>();
|
||||
visualDevModelDataCrInput.data["code"] = "111";
|
||||
input.Add(new MESKittingOutStkInput()
|
||||
{
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
@@ -68,8 +67,7 @@ namespace Tnb.ProductionMgr
|
||||
material_code = visualDevModelDataCrInput.data.ContainsKey("material_code") ? visualDevModelDataCrInput.data["material_code"].ToString() : "",
|
||||
collocation_scheme_id = visualDevModelDataCrInput.data.ContainsKey("collocation_scheme_id") ? visualDevModelDataCrInput.data["collocation_scheme_id"].ToString() : "",
|
||||
collocation_scheme_code = visualDevModelDataCrInput.data.ContainsKey("collocation_scheme_code") ? visualDevModelDataCrInput.data["collocation_scheme_code"].ToString() : "",
|
||||
source_id = visualDevModelDataCrInput.data.ContainsKey("code") ? visualDevModelDataCrInput.data["code"].ToString() : "",
|
||||
// source_id = "123",
|
||||
source_id = prdKittingOutH.id,
|
||||
seq = visualDevModelDataCrInput.data.ContainsKey("seq") ? (int)visualDevModelDataCrInput.data["seq"] : 0,
|
||||
create_id = _userManager.UserId,
|
||||
wmsKittingoutDs = new List<MESKittingOutStkDInput>(),
|
||||
@@ -91,8 +89,52 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
||||
prdKittingOutH.code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDKITTINGOUTSTOCK_CODE);
|
||||
prdKittingOutH.warehouse_id = visualDevModelDataCrInput.data.ContainsKey("warehouse_id") ? visualDevModelDataCrInput.data["warehouse_id"].ToString() : "";
|
||||
prdKittingOutH.location_code = visualDevModelDataCrInput.data.ContainsKey("location_code") ? visualDevModelDataCrInput.data["location_code"].ToString() : "";
|
||||
prdKittingOutH.material_id = visualDevModelDataCrInput.data.ContainsKey("material_id") ? visualDevModelDataCrInput.data["material_id"].ToString() : "";
|
||||
prdKittingOutH.material_code = visualDevModelDataCrInput.data.ContainsKey("material_code") ? visualDevModelDataCrInput.data["material_code"].ToString() : "";
|
||||
prdKittingOutH.collocation_scheme_id = visualDevModelDataCrInput.data.ContainsKey("collocation_scheme_id") ? visualDevModelDataCrInput.data["collocation_scheme_id"].ToString() : "";
|
||||
prdKittingOutH.collocation_scheme_code = visualDevModelDataCrInput.data.ContainsKey("collocation_scheme_code") ? visualDevModelDataCrInput.data["collocation_scheme_code"].ToString() : "";
|
||||
prdKittingOutH.worklinei_d = visualDevModelDataCrInput.data.ContainsKey("worklinei_d") ? visualDevModelDataCrInput.data["worklinei_d"].ToString() : "";
|
||||
prdKittingOutH.workstation_id = visualDevModelDataCrInput.data.ContainsKey("workstation_id") ? visualDevModelDataCrInput.data["workstation_id"].ToString() : "";
|
||||
prdKittingOutH.mo_task_id = visualDevModelDataCrInput.data.ContainsKey("mo_task_id") ? visualDevModelDataCrInput.data["mo_task_id"].ToString() : "";
|
||||
prdKittingOutH.seq = visualDevModelDataCrInput.data.ContainsKey("seq") ? visualDevModelDataCrInput.data["seq"]?.ToString() : "0";
|
||||
prdKittingOutH.create_id = _userManager.UserId;
|
||||
prdKittingOutH.create_time = DateTime.Now;
|
||||
prdKittingOutH.org_id = _userManager.GetUserInfo().Result.organizeId;
|
||||
List<PrdKittingOutD> prdKittingOutDs = new List<PrdKittingOutD>();
|
||||
foreach (var item in (JArray)visualDevModelDataCrInput.data["tableField115"])
|
||||
{
|
||||
prdKittingOutDs.Add(new PrdKittingOutD()
|
||||
{
|
||||
material_id = item.Value<string>("material_id"),
|
||||
material_code = item.Value<string>("material_code"),
|
||||
unit_id = item.Value<string>("unit_id"),
|
||||
unit_code = item.Value<string>("unit_code"),
|
||||
pr_qty = item.Value<decimal>("pr_qty"),
|
||||
code_batch = item.Value<string>("code_batch"),
|
||||
box = item.Value<int>("box"),
|
||||
kitting_out_id = prdKittingOutH.id,
|
||||
});
|
||||
}
|
||||
|
||||
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
// await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
||||
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
{
|
||||
await _repository.InsertAsync(prdKittingOutH);
|
||||
if (prdKittingOutDs.Count > 0)
|
||||
{
|
||||
await db.Insertable<PrdKittingOutD>(prdKittingOutDs).ExecuteCommandAsync();
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
throw Oops.Bah(result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using JNPF.DynamicApiController;
|
||||
using JNPF.Extensitions.EventBus;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
@@ -42,7 +43,8 @@ namespace Tnb.ProductionMgr
|
||||
[OverideVisualDev(ModuleId)]
|
||||
public class PrdMoService : IOverideVisualDevService, IPrdMoService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "25018860321301";
|
||||
// private const string ModuleId = "25018860321301";
|
||||
private const string ModuleId = "26900026924053";
|
||||
private readonly ISqlSugarRepository<PrdMo> _repository;
|
||||
private readonly IDataBaseManager _dataBaseManager;
|
||||
private readonly IUserManager _userManager;
|
||||
@@ -91,7 +93,17 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
row.Add("material_name", material.name);
|
||||
row.Add($"material_attribute", material.attribute);
|
||||
if (dic.ContainsKey("material_id"))
|
||||
{
|
||||
row["material_id"] = material.code + "/" + material.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (dic.ContainsKey("unit_id"))
|
||||
{
|
||||
string unitId = dic["unit_id"]?.ToString() ?? "";
|
||||
var unit = await db.Queryable<DictionaryDataEntity>().SingleAsync(x => x.Id == unitId);
|
||||
row["unit_id"] = unit?.FullName ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1313,6 +1313,13 @@ namespace Tnb.ProductionMgr
|
||||
var report = await db.Queryable<PrdReport>().FirstAsync(it => it.mo_task_id == input.mo_task_id);
|
||||
var prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
|
||||
|
||||
|
||||
bool flag = (prdMoTask.reported_work_qty ?? 0) + (prdMoTask.scrap_qty ?? 0) + input.reported_qty == prdMoTask.scheduled_qty;
|
||||
if ((prdMoTask.reported_work_qty ?? 0) + (prdMoTask.scrap_qty ?? 0) + input.reported_qty > prdMoTask.scheduled_qty)
|
||||
{
|
||||
throw Oops.Bah("已完成数量不能大于任务单数量");
|
||||
}
|
||||
|
||||
report = input.Adapt<PrdReport>();
|
||||
report.id = SnowflakeIdHelper.NextId();
|
||||
report.reported_qty = input.reported_qty;
|
||||
@@ -1346,6 +1353,7 @@ namespace Tnb.ProductionMgr
|
||||
await db.Updateable<PrdMoTask>()
|
||||
// .SetColumns(x => x.complete_qty == x.complete_qty + input.reported_qty)
|
||||
.SetColumns(x => x.reported_work_qty == input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
@@ -1353,6 +1361,7 @@ namespace Tnb.ProductionMgr
|
||||
await db.Updateable<PrdMoTask>()
|
||||
// .SetColumns(x => x.complete_qty == x.complete_qty + input.reported_qty)
|
||||
.SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
@@ -1366,11 +1375,13 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
await db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.last_process_complete_qty == input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
|
||||
}else if (parentMoTask?.last_process_complete_qty != null)
|
||||
{
|
||||
await db.Updateable<PrdMoTask>()
|
||||
.SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty)
|
||||
.SetColumnsIF(flag,x=>x.mo_task_status==DictConst.ComplatedEnCode)
|
||||
.Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
@@ -1386,81 +1397,81 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
|
||||
//扣除生产投料 按最先投入的依次扣除
|
||||
List<PrdFeedingD> prdFeedingDs = await db.Queryable<PrdFeedingH>()
|
||||
.LeftJoin<PrdFeedingD>((a,b)=>a.id==b.feeding_id)
|
||||
.Where((a,b) => a.workline_id == prdMoTask.workline_id && (b.status=="0" || b.status=="1"))
|
||||
.OrderBy((a,b) => b.create_time)
|
||||
.Select((a,b)=>b)
|
||||
.ToListAsync();
|
||||
|
||||
if (prdFeedingDs != null && prdFeedingDs.Count>0)
|
||||
{
|
||||
|
||||
BasMbom basMbom = await db.Queryable<BasMbom>().SingleAsync(x => x.id == prdMoTask.bom_id);
|
||||
List<BasMbomInput> basMbomInputs = await db.Queryable<BasMbomInput>().Where(x =>
|
||||
x.mbom_id == prdMoTask.bom_id && x.mbom_process_id == prdMoTask.mbom_process_id).ToListAsync();
|
||||
|
||||
foreach (var item in basMbomInputs)
|
||||
{
|
||||
var details = prdFeedingDs.Where(x => x.material_id == item.material_id).OrderBy(x=>x.create_time).ToList();
|
||||
if (details?.Count>0)
|
||||
{
|
||||
decimal deductNum = input.reported_qty * item.num / basMbom.num;
|
||||
decimal? notUseNum = details.Sum(x => x.num - x.use_num);
|
||||
if (notUseNum > deductNum)
|
||||
{
|
||||
|
||||
foreach (var detail in details)
|
||||
{
|
||||
|
||||
if (deductNum - (detail.num - detail.use_num) < 0)
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.use_num+deductNum)
|
||||
.SetColumns(x=>x.status=="1")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
.SetColumns(x=>x.status=="2")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
|
||||
deductNum = deductNum - (detail.num - detail.use_num);
|
||||
|
||||
if (deductNum <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (deductNum > 0)
|
||||
{
|
||||
throw new Exception("投入物料不足");
|
||||
}
|
||||
}
|
||||
else if(notUseNum == deductNum)
|
||||
{
|
||||
foreach (var detail in details)
|
||||
{
|
||||
await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
.SetColumns(x=>x.status=="2")
|
||||
.Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("投入物料不足");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//throw new Exception("无投入物料");
|
||||
}
|
||||
}
|
||||
}
|
||||
// List<PrdFeedingD> prdFeedingDs = await db.Queryable<PrdFeedingH>()
|
||||
// .LeftJoin<PrdFeedingD>((a,b)=>a.id==b.feeding_id)
|
||||
// .Where((a,b) => a.workline_id == prdMoTask.workline_id && (b.status=="0" || b.status=="1"))
|
||||
// .OrderBy((a,b) => b.create_time)
|
||||
// .Select((a,b)=>b)
|
||||
// .ToListAsync();
|
||||
//
|
||||
// if (prdFeedingDs != null && prdFeedingDs.Count>0)
|
||||
// {
|
||||
//
|
||||
// BasMbom basMbom = await db.Queryable<BasMbom>().SingleAsync(x => x.id == prdMoTask.bom_id);
|
||||
// List<BasMbomInput> basMbomInputs = await db.Queryable<BasMbomInput>().Where(x =>
|
||||
// x.mbom_id == prdMoTask.bom_id && x.mbom_process_id == prdMoTask.mbom_process_id).ToListAsync();
|
||||
//
|
||||
// foreach (var item in basMbomInputs)
|
||||
// {
|
||||
// var details = prdFeedingDs.Where(x => x.material_id == item.material_id).OrderBy(x=>x.create_time).ToList();
|
||||
// if (details?.Count>0)
|
||||
// {
|
||||
// decimal deductNum = input.reported_qty * item.num / basMbom.num;
|
||||
// decimal? notUseNum = details.Sum(x => x.num - x.use_num);
|
||||
// if (notUseNum > deductNum)
|
||||
// {
|
||||
//
|
||||
// foreach (var detail in details)
|
||||
// {
|
||||
//
|
||||
// if (deductNum - (detail.num - detail.use_num) < 0)
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.use_num+deductNum)
|
||||
// .SetColumns(x=>x.status=="1")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
// .SetColumns(x=>x.status=="2")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// deductNum = deductNum - (detail.num - detail.use_num);
|
||||
//
|
||||
// if (deductNum <= 0)
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (deductNum > 0)
|
||||
// {
|
||||
// throw new Exception("投入物料不足");
|
||||
// }
|
||||
// }
|
||||
// else if(notUseNum == deductNum)
|
||||
// {
|
||||
// foreach (var detail in details)
|
||||
// {
|
||||
// await db.Updateable<PrdFeedingD>().SetColumns(x => x.use_num == x.num)
|
||||
// .SetColumns(x=>x.status=="2")
|
||||
// .Where(x => x.id == detail.id).ExecuteCommandAsync();
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("投入物料不足");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("无投入物料");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user