using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.BasicData.Entities.Dto;
using Tnb.BasicData.Interfaces;
namespace Tnb.BasicData
{
///
/// 生产bom
///
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
[Route("api/[area]/[controller]/[action]")]
[OverideVisualDev(ModelId)]
public class BasMbomService : IBasMbomService, IOverideVisualDevService, IDynamicApiController, ITransient
{
public const string ModelId = "27204627275029";
private readonly ISqlSugarRepository _repository;
private readonly DataBaseManager _dbManager;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IUserManager _userManager;
private readonly ISqlSugarClient _db;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public BasMbomService(
ISqlSugarRepository repository,
DataBaseManager dbManager,
IUserManager userManager,
IDictionaryDataService dictionaryDataService)
{
_repository = repository;
_dbManager = dbManager;
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
_db = repository.AsSugarClient();
// OverideFuncs.GetAsync = GetInfo;
OverideFuncs.GetListAsync = GetList;
}
///
/// 生产bom列表
///
///
///
public async Task GetList(VisualDevModelListQueryInput input)
{
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary? queryJson = string.IsNullOrEmpty(input.queryJson) ? null : input.queryJson.ToObject>();
string materialInfo = queryJson.ContainsKey("query_info") ? queryJson["query_info"].ToString() : "";
SqlSugarPagedList list = await db.Queryable((a, b, c, d) => new object[]
{
JoinType.Left, a.material_id == b.id,
JoinType.Left, a.ebom_id == c.id,
JoinType.Left, a.route_id == d.id,
})
.WhereIF(!string.IsNullOrEmpty(materialInfo), (a, b, c, d) => b.code.Contains(materialInfo) || b.name.Contains(materialInfo))
.Select((a, b, c, d) => new MbomListOutput
{
id = a.id,
material_id = b.code + "-" + b.name,
material_id_id = b.id,
version = a.version,
ebom_id = c.version,
route_id = d.name,
route_id_id = c.id,
start_time = a.start_time == null ? "" : a.start_time.Value.ToString("yyyy-MM-dd"),
end_time = a.end_time == null ? "" : a.end_time.Value.ToString("yyyy-MM-dd"),
is_first = SqlFunc.IIF(a.is_first == 0, "否", "是"),
}).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult.SqlSugarPageResult(list);
}
///
/// 获取编辑信息
///
///
///
public async Task GetInfo(string id)
{
ISqlSugarClient db = _repository.AsSugarClient();
BasMbom mbom = await _repository.GetSingleAsync(x => x.id == id);
List processes = await db.Queryable().Where(x => x.mbom_id == id).OrderBy(x => x.ordinal).ToListAsync();
List inputs = await db.Queryable().Where(x => x.mbom_id == id).ToListAsync();
List outputs = await db.Queryable().Where(x => x.mbom_id == id).ToListAsync();
MbomDataOutput mbomDataOutput = new();
List mbomProcessOutDtos = new();
mbomDataOutput.id = mbom.id;
mbomDataOutput.ebom_id = mbom.ebom_id;
mbomDataOutput.is_first = mbom.is_first;
mbomDataOutput.material_id = mbom.material_id;
mbomDataOutput.num = mbom.num;
mbomDataOutput.remark = mbom.remark;
mbomDataOutput.route_id = mbom.route_id;
mbomDataOutput.start_time = mbom.start_time;
mbomDataOutput.end_time = mbom.end_time;
mbomDataOutput.unit_id = mbom.unit_id;
mbomDataOutput.version = mbom.version;
foreach (BasMbomProcess process in processes)
{
mbomProcessOutDtos.Add(new MbomProcessOutDto()
{
id = process.id,
mbom_id = mbom.id,
process_id = process.process_id,
preparation_time = process.preparation_time,
station = process.station,
byproduct_status = process.byproduct_status,
production_method = process.production_method,
inputs = inputs.Where(x => x.process_id == process.process_id).ToList(),
outputs = outputs.Where(x => x.process_id == process.process_id).ToList(),
no = process.no,
last_process_no = process.last_process_no,
next_process_no = process.next_process_no
});
}
mbomDataOutput.processes = mbomProcessOutDtos;
return mbomDataOutput;
}
///
/// 复制生产bom
///
/// 物料id id
[HttpPost]
public async Task Copy(Dictionary parameters)
{
string id = parameters["id"];
var db = _repository.AsSugarClient();
BasMbom basMbom = await _repository.GetByIdAsync(id);
List mbomProcesses = await db.Queryable().Where(x => x.mbom_id == id).ToListAsync();
List mbomInputs = await db.Queryable().Where(x => x.mbom_id == id).ToListAsync();
List mbomOutputs = await db.Queryable().Where(x => x.mbom_id == id).ToListAsync();
string newId = SnowflakeIdHelper.NextId();
basMbom.id = newId;
basMbom.version += "_复制的请修改";
DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
_ = await _repository.InsertAsync(basMbom);
foreach (BasMbomProcess item in mbomProcesses)
{
item.id = SnowflakeIdHelper.NextId();
item.mbom_id = newId;
}
foreach (BasMbomInput item in mbomInputs)
{
item.id = SnowflakeIdHelper.NextId();
item.mbom_id = newId;
}
foreach (BasMbomOutput item in mbomOutputs)
{
item.id = SnowflakeIdHelper.NextId();
item.mbom_id = newId;
}
if(mbomProcesses!=null && mbomProcesses.Count>0) _ = await db.Insertable(mbomProcesses).ExecuteCommandAsync();
if(mbomInputs!=null && mbomInputs.Count>0) _ = await db.Insertable(mbomInputs).ExecuteCommandAsync();
if(mbomOutputs!=null && mbomOutputs.Count>0) _ = await db.Insertable(mbomOutputs).ExecuteCommandAsync();
});
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "复制成功" : result.ErrorMessage;
}
///
/// 根据bomid获取对应的子bom列表
///
/// bomId
///
///
///
/// returns:
///
{
///
version:bom版本
///
unit_id:单位id
///
route_name:工艺路线名称
///
process_id:工序id
///
material_id:物料id
///
material_code:物料编码
///
material_name:物料名称
///
material_category_code:类别code
///
output_qty:输出参数
///
}
///
[HttpGet]
public async Task GetSubMoListByBomId([FromRoute] string bomId)
{
if (string.IsNullOrEmpty(bomId))
{
throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty");
}
List result = await _db.Queryable()
.LeftJoin((a, b) => a.id == b.mbom_id)
.LeftJoin((a, b, c) => a.route_id == c.id)
// .LeftJoin((a, b, c, d) => b.process_id == d.process_id && c.id == d.route_id)
.LeftJoin((a, b, c, d) => b.route_detail_id == d.id)
.LeftJoin((a, b, c, d, e) => a.id == e.mbom_id && e.mbom_process_id == b.id)
.Where((a, b, c, d, e) => a.id == bomId)
.Select((a, b, c, d, e) => new SubBomListOutput
{
version = a.version,
unit_id = a.unit_id,
route_name = c.name,
process_id = b.process_id,
material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id),
material_code = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.code),
material_name = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.name),
material_standard = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.material_specification),
num = e.num,
ordinal = d.ordinal,
})
.Mapper(it => it.output_qty = it.num.ParseToInt())
.ToListAsync();
return result;
}
[HttpPost]
public async Task GetInputMaterialByMbomProcessId(Dictionary dic)
{
string id = dic["id"];
var result = await _repository.AsSugarClient().Queryable()
.Where(x => x.mbom_process_id == id)
.Select(x => new
{
x.material_id,
}).ToListAsync();
return result;
}
///
/// 根据物料id获取生产bom
///
///
///
/// returns:
///
{
///
bom_id:bomid
///
material_code:物料编码
///
material_name:物料名称
///
start_time:有效开始时间
///
end_time:有效结束时间
///
version:bom版本
///
route_id:工艺路线id
///
route_name:工艺路线名称
///
}
///
[HttpGet]
public async Task GetMBomListByMaterialId([FromRoute] string materialId)
{
return await _db.Queryable()
.LeftJoin((a, b) => a.material_id == b.id)
.LeftJoin((a, b, c) => a.route_id == c.id)
.Where((a, b, c) => a.material_id == materialId)
.Select((a, b, c) => new
{
bom_id = a.id,
material_code = b.code,
material_name = b.name,
start_time = a.start_time.HasValue ? a.start_time.Value.ToString(DbTimeFormat.SS) : null,
end_time = a.end_time.HasValue ? a.end_time.Value.ToString(DbTimeFormat.SS) : null,
a.version,
route_id = c.id,
route_name = c.name,
})
.ToListAsync();
}
// ///
// /// 保存生产bom
// ///
// ///
// ///
// [HttpPost]
// public async Task SaveData(MbomSaveDataInput mbomSaveDataInput)
// {
// ErrorCode errorCode = ErrorCode.COM1008;
// DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
// {
// //新增
// if (string.IsNullOrEmpty(mbomSaveDataInput.id))
// {
// string mbomId = SnowflakeIdHelper.NextId();
// string orgId = _userManager.GetUserInfo().Result.organizeId;
// BasMbom mbom = new BasMbom()
// {
// id = mbomId,
// org_id = orgId,
// material_id = mbomSaveDataInput.material_id,
// num = mbomSaveDataInput.num,
// unit_id = mbomSaveDataInput.unit_id,
// version = mbomSaveDataInput.version,
// start_time = mbomSaveDataInput.start_time,
// end_time = mbomSaveDataInput.end_time,
// ebom_id = mbomSaveDataInput.ebom_id,
// route_id = mbomSaveDataInput.route_id,
// is_first = mbomSaveDataInput.is_first,
// remark = mbomSaveDataInput.remark,
// create_id = _userManager.UserId,
// create_time = DateTime.Now,
//
// };
//
// if (await _repository.IsAnyAsync(x =>
// x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version))
// {
// errorCode = ErrorCode.COM1004;
// throw Oops.Oh(ErrorCode.COM1004);
// }
// await _repository.InsertAsync(mbom);
// List processes = new List();
// List inputs = new List();
// List outputs = new List();
//
// if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
// {
// int index = 0;
// foreach (var process in mbomSaveDataInput.processes)
// {
// string mbomProcessId = SnowflakeIdHelper.NextId();
// processes.Add(new BasMbomProcess()
// {
// id = mbomProcessId,
// org_id = orgId,
// mbom_id = mbomId,
// process_id = process?.process_id ?? "",
// preparation_time = process?.preparation_time ?? 0,
// station = process?.station ?? "",
// byproduct_status = process?.byproduct_status ?? 0,
// production_method = process?.production_method,
// route_detail_id = process?.route_detail_id ?? "",
// ordinal = ++index,
// is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
//
// });
//
// if (process!.inputs != null)
// {
// foreach (var input in process.inputs)
// {
// string inputId = SnowflakeIdHelper.NextId();
// inputs.Add(new BasMbomInput()
// {
// id = inputId,
// mbom_id = mbomId,
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = input.material_id,
// num = input.num,
// org_id = orgId,
// });
// }
// }
//
// if (process.outputs != null)
// {
// foreach (var output in process.outputs)
// {
// string outputId = SnowflakeIdHelper.NextId();
// outputs.Add(new BasMbomOutput()
// {
// id = outputId,
// mbom_id = mbomId,
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = output.material_id,
// num = output.num,
// org_id = orgId,
// });
// }
// }
// }
// }
//
// if (processes.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
// }
//
// if (inputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
// }
//
// if (outputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
// }
// }
// else//修改
// {
// if (await _repository.IsAnyAsync(x =>
// x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
// {
// errorCode = ErrorCode.COM1004;
// throw Oops.Oh(ErrorCode.COM1004);
// }
//
// string orgId = _userManager.GetUserInfo().Result.organizeId;
// if (mbomSaveDataInput != null)
// {
// await _repository.UpdateAsync(x => new BasMbom()
// {
// // org_id = orgId,
// material_id = mbomSaveDataInput.material_id,
// num = mbomSaveDataInput.num,
// unit_id = mbomSaveDataInput.unit_id,
// version = mbomSaveDataInput.version,
// start_time = mbomSaveDataInput.start_time,
// end_time = mbomSaveDataInput.end_time,
// ebom_id = mbomSaveDataInput.ebom_id,
// route_id = mbomSaveDataInput.route_id,
// is_first = mbomSaveDataInput.is_first,
// remark = mbomSaveDataInput.remark,
// modify_id = _userManager.UserId,
// modify_time = DateTime.Now,
//
// }, x => x.id == mbomSaveDataInput.id);
// }
// // List processes = new List();
// List inputs = new List();
// List outputs = new List();
//
// if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
// {
// foreach (var process in mbomSaveDataInput.processes)
// {
// string mbomProcessId = process.id;
// // string mbomProcessId = SnowflakeIdHelper.NextId();
// // processes.Add(new BasMbomProcess()
// // {
// // id = mbomProcessId,
// // org_id = orgId ?? "",
// // mbom_id = mbomSaveDataInput?.id ?? "",
// // process_id = process?.process_id ?? "",
// // preparation_time = process?.preparation_time ?? 0,
// // station = process.station,
// // byproduct_status = process.byproduct_status,
// // production_method = process.production_method,
// // route_detail_id = process.route_detail_id,
// //
// // });
//
// decimal preparation_time = process?.preparation_time ?? 0;
// await _repository.AsSugarClient().Updateable()
// .SetColumns(x => x.preparation_time == preparation_time)
// .SetColumns(x => x.station == process!.station)
// .SetColumns(x => x.byproduct_status == process!.byproduct_status)
// .SetColumns(x => x.production_method == process!.production_method)
// .Where(x => x.id == process!.id).ExecuteCommandAsync();
//
// if (process!.inputs != null)
// {
// foreach (var input in process.inputs)
// {
// string inputId = SnowflakeIdHelper.NextId();
// inputs.Add(new BasMbomInput()
// {
// id = inputId,
// mbom_id = mbomSaveDataInput?.id ?? "",
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = input.material_id,
// num = input.num,
// org_id = orgId,
// });
// }
// }
//
// if (process.outputs != null)
// {
// foreach (var output in process.outputs)
// {
// string outputId = SnowflakeIdHelper.NextId();
// outputs.Add(new BasMbomOutput()
// {
// id = outputId,
// mbom_id = mbomSaveDataInput?.id ?? "",
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = output.material_id,
// num = output.num,
// org_id = orgId,
// });
// }
// }
//
// }
// }
//
// if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
// {
// // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// }
// // if (processes.Count > 0)
// // {
// // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
// // }
//
// if (inputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
// }
//
// if (outputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
// }
// }
//
// });
//
// if (!result.IsSuccess)
// {
// if (!string.IsNullOrEmpty(mbomSaveDataInput.id))
// {
// if (errorCode != ErrorCode.COM1004)
// {
// throw Oops.Oh(ErrorCode.COM1001);
// }
// else
// {
// throw Oops.Oh(errorCode);
// }
// }
// else
// {
// if (errorCode != ErrorCode.COM1004)
// {
// throw Oops.Oh(ErrorCode.COM1000);
// }
// else
// {
// throw Oops.Oh(errorCode);
// }
// }
//
// }
// return result.IsSuccess ? "保存成功" : result.ErrorMessage;
// }
///
/// 保存生产bom
///
///
///
[HttpPost]
public async Task SaveDataNew(MbomSaveDataInput mbomSaveDataInput)
{
ErrorCode errorCode = ErrorCode.COM1008;
DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
//新增
if (string.IsNullOrEmpty(mbomSaveDataInput.id))
{
string mbomId = SnowflakeIdHelper.NextId();
string orgId = _userManager.GetUserInfo().Result.organizeId;
BasMbom mbom = new()
{
id = mbomId,
org_id = orgId,
material_id = mbomSaveDataInput.material_id,
num = mbomSaveDataInput.num,
full_qty = mbomSaveDataInput.full_qty,
unit_id = mbomSaveDataInput.unit_id,
version = mbomSaveDataInput.version,
start_time = mbomSaveDataInput.start_time,
end_time = mbomSaveDataInput.end_time,
ebom_id = mbomSaveDataInput.ebom_id,
route_id = mbomSaveDataInput.route_id,
is_first = mbomSaveDataInput.is_first,
remark = mbomSaveDataInput.remark,
create_id = _userManager.UserId,
create_time = DateTime.Now,
};
if (await _repository.IsAnyAsync(x =>
x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version))
{
errorCode = ErrorCode.COM1004;
throw Oops.Oh(ErrorCode.COM1004);
}
_ = await _repository.InsertAsync(mbom);
List processes = new();
List inputs = new();
List outputs = new();
if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
{
int index = 0;
foreach (MbomProcessDto? process in mbomSaveDataInput.processes)
{
string mbomProcessId = SnowflakeIdHelper.NextId();
processes.Add(new BasMbomProcess()
{
id = mbomProcessId,
org_id = orgId,
mbom_id = mbomId,
process_id = process?.process_id ?? "",
preparation_time = process?.preparation_time ?? 0,
station = process?.station ?? "",
byproduct_status = process!.byproduct_status,
production_method = process.production_method,
route_detail_id = process.route_detail_id,
ordinal = ++index,
is_last = string.IsNullOrEmpty(process.next_process_no) ? 1 : 0,
no = process!.no,
last_process_no = process.last_process_no,
next_process_no = process.next_process_no,
});
if (process.inputs != null)
{
foreach (BasMbomInput input in process.inputs)
{
string inputId = SnowflakeIdHelper.NextId();
inputs.Add(new BasMbomInput()
{
id = inputId,
mbom_id = mbomId,
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = input.material_id,
num = input.num,
molecule = input.molecule,
denominator = input.denominator,
org_id = orgId,
unit_id = input.unit_id,
});
}
}
if (process.outputs != null)
{
foreach (BasMbomOutput output in process.outputs)
{
string outputId = SnowflakeIdHelper.NextId();
outputs.Add(new BasMbomOutput()
{
id = outputId,
mbom_id = mbomId,
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = output.material_id,
num = output.num,
molecule = output.molecule,
denominator = output.denominator,
org_id = orgId,
unit_id = output.unit_id,
});
}
}
}
}
if (processes.Count > 0)
{
_ = await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
}
if (inputs.Count > 0)
{
_ = await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
}
if (outputs.Count > 0)
{
_ = await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
}
}
else//修改
{
if (await _repository.IsAnyAsync(x =>
x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
{
errorCode = ErrorCode.COM1004;
throw Oops.Oh(ErrorCode.COM1004);
}
string orgId = _userManager.GetUserInfo().Result.organizeId;
if (mbomSaveDataInput != null)
{
_ = await _repository.UpdateAsync(x => new BasMbom()
{
// org_id = orgId,
material_id = mbomSaveDataInput.material_id,
num = mbomSaveDataInput.num,
full_qty = mbomSaveDataInput.full_qty,
unit_id = mbomSaveDataInput.unit_id,
version = mbomSaveDataInput.version,
start_time = mbomSaveDataInput.start_time,
end_time = mbomSaveDataInput.end_time,
ebom_id = mbomSaveDataInput.ebom_id,
route_id = mbomSaveDataInput.route_id,
is_first = mbomSaveDataInput.is_first,
remark = mbomSaveDataInput.remark,
modify_id = _userManager.UserId,
modify_time = DateTime.Now,
}, x => x.id == mbomSaveDataInput.id);
}
// List processes = new List();
List inputs = new();
List outputs = new();
if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
{
foreach (MbomProcessDto? process in mbomSaveDataInput.processes)
{
string mbomProcessId = process.id;
// string mbomProcessId = SnowflakeIdHelper.NextId();
// processes.Add(new BasMbomProcess()
// {
// id = mbomProcessId,
// org_id = orgId ?? "",
// mbom_id = mbomSaveDataInput?.id ?? "",
// process_id = process?.process_id ?? "",
// preparation_time = process?.preparation_time ?? 0,
// station = process.station,
// byproduct_status = process.byproduct_status,
// production_method = process.production_method,
// route_detail_id = process.route_detail_id,
//
// });
decimal preparation_time = process?.preparation_time ?? 0;
_ = await _repository.AsSugarClient().Updateable()
.SetColumns(x => x.preparation_time == preparation_time)
.SetColumns(x => x.station == process!.station)
.SetColumns(x => x.byproduct_status == process!.byproduct_status)
.SetColumns(x => x.production_method == process!.production_method)
.SetColumns(x => x.process_id == process!.id)
.Where(x => x.id == process!.id).ExecuteCommandAsync();
if (process!.inputs != null)
{
foreach (BasMbomInput input in process.inputs)
{
string inputId = SnowflakeIdHelper.NextId();
inputs.Add(new BasMbomInput()
{
id = inputId,
mbom_id = mbomSaveDataInput?.id ?? "",
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = input.material_id,
num = input.num,
molecule = input.molecule,
denominator = input.denominator,
org_id = orgId,
unit_id = input.unit_id,
});
}
}
if (process.outputs != null)
{
foreach (BasMbomOutput output in process.outputs)
{
string outputId = SnowflakeIdHelper.NextId();
outputs.Add(new BasMbomOutput()
{
id = outputId,
mbom_id = mbomSaveDataInput?.id ?? "",
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = output.material_id,
num = output.num,
molecule = output.molecule,
denominator = output.denominator,
org_id = orgId,
unit_id = output.unit_id
});
}
}
}
}
if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
{
// await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
}
// if (processes.Count > 0)
// {
// await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
// }
if (inputs.Count > 0)
{
_ = await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
}
if (outputs.Count > 0)
{
_ = await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
}
}
});
if (!result.IsSuccess)
{
if (!string.IsNullOrEmpty(mbomSaveDataInput.id))
{
if (errorCode != ErrorCode.COM1004)
{
throw Oops.Oh(ErrorCode.COM1001);
}
else
{
throw Oops.Oh(errorCode);
}
}
else
{
if (errorCode != ErrorCode.COM1004)
{
throw Oops.Oh(ErrorCode.COM1000);
}
else
{
throw Oops.Oh(errorCode);
}
}
}
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
}
}
}