This commit is contained in:
2023-06-21 11:17:32 +08:00
parent c4434ce477
commit 1e555f372f
6 changed files with 70 additions and 15 deletions

View File

@@ -179,6 +179,56 @@ namespace Tnb.ProductionMgr
.ExecuteCommandAsync();
return (row > 0);
}
// /// <summary>
// /// 关联同组工单
// /// </summary>
// /// <param name="input">关联同组工单输入参数</param>
// /// <returns></returns>
// [HttpPost]
// public async Task<dynamic> RelevancySameGroupMo(MoCrInput input)
// {
// (bool executeRes, string errMsg) multi = (true, "");
// var list = await _repository.AsSugarClient().Queryable<PrdMo>()
// .InnerJoin<ToolMolds>((a, b) => a.material_id == b.material_id)
// .Where((a, b) => input.WorkOrderIds.Contains(a.id))
// .Select((a, b) => new
// {
// planDate = a.plan_start_date,
// mold_code = b.mold_code,
// }).ToListAsync();
// var planDateAll = true;
// var moldIdAll = true;
// if (list?.Count > 0)
// {
// var planDate = list.FirstOrDefault()?.planDate;
// var moldCode = list.FirstOrDefault()?.mold_code;
//
// planDateAll = list.Skip(1).All(x => x.planDate == planDate);
// moldIdAll = list.Skip(1).All(x => x.mold_code == moldCode);
// if (planDateAll && moldIdAll)
// {
// var groupId = SnowflakeIdHelper.NextId();
// multi.executeRes = await _repository.AsSugarClient().Updateable<PrdMo>()
// .SetColumns(c => new PrdMo { combine_mo_code = groupId })
// .Where(it => input.WorkOrderIds.Contains(it.id))
// .ExecuteCommandHasChangeAsync();
// }
// else
// {
// multi.executeRes = false;
// if (!planDateAll)
// {
// throw new AppFriendlyException("计划开始日期不一致", null);
// }
// if (!moldIdAll)
// {
// throw new AppFriendlyException("未关联到同一模具下", null);
// }
// }
// }
// return multi;
// }
/// <summary>
/// 关联同组工单
/// </summary>
@@ -189,12 +239,13 @@ namespace Tnb.ProductionMgr
{
(bool executeRes, string errMsg) multi = (true, "");
var list = await _repository.AsSugarClient().Queryable<PrdMo>()
.InnerJoin<ToolMolds>((a, b) => a.material_id == b.material_id)
.Where((a, b) => input.WorkOrderIds.Contains(a.id))
.Select((a, b) => new
.LeftJoin<ToolMoldsMaterial>((a, b) => a.material_id == b.material_id)
.LeftJoin<ToolMolds>((a,b,c)=>b.mold_id==c.id)
.Where((a, b,c) => input.WorkOrderIds.Contains(a.id))
.Select((a, b,c) => new
{
planDate = a.plan_start_date,
mold_code = b.mold_code,
mold_code = c.mold_code,
}).ToListAsync();
var planDateAll = true;
var moldIdAll = true;
@@ -203,8 +254,8 @@ namespace Tnb.ProductionMgr
var planDate = list.FirstOrDefault()?.planDate;
var moldCode = list.FirstOrDefault()?.mold_code;
planDateAll = list.Skip(1).All(x => x.planDate == planDate);
moldIdAll = list.Skip(1).All(x => x.mold_code == moldCode);
planDateAll = list.All(x => x.planDate == planDate);
moldIdAll = moldCode != null && list.All(x => x.mold_code == moldCode);
if (planDateAll && moldIdAll)
{
var groupId = SnowflakeIdHelper.NextId();
@@ -218,11 +269,11 @@ namespace Tnb.ProductionMgr
multi.executeRes = false;
if (!planDateAll)
{
throw new AppFriendlyException("计划开始日期不一致", null);
throw Oops.Bah("计划开始日期不一致");
}
if (!moldIdAll)
{
throw new AppFriendlyException("未关联到同一模具下", null);
throw Oops.Bah("未关联到同一模具下");
}
}
}