生产bom复制
This commit is contained in:
@@ -131,6 +131,55 @@ namespace Tnb.BasicData
|
||||
mbomDataOutput.processes = mbomProcessOutDtos;
|
||||
return mbomDataOutput;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复制生产bom
|
||||
/// </summary>
|
||||
/// <param name="parameters">物料id id</param>
|
||||
[HttpPost]
|
||||
public async Task<string> Copy(Dictionary<string, string> parameters)
|
||||
{
|
||||
string id = parameters["id"];
|
||||
var db = _repository.AsSugarClient();
|
||||
BasMbom basMbom = await _repository.GetByIdAsync(id);
|
||||
|
||||
List<BasMbomProcess> mbomProcesses = await db.Queryable<BasMbomProcess>().Where(x => x.mbom_id == id).ToListAsync();
|
||||
List<BasMbomInput> mbomInputs = await db.Queryable<BasMbomInput>().Where(x => x.mbom_id == id).ToListAsync();
|
||||
List<BasMbomOutput> mbomOutputs = await db.Queryable<BasMbomOutput>().Where(x => x.mbom_id == id).ToListAsync();
|
||||
|
||||
string newId = SnowflakeIdHelper.NextId();
|
||||
basMbom.id = newId;
|
||||
basMbom.version += "_复制的请修改";
|
||||
|
||||
DbResult<bool> 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<BasMbomProcess>(mbomProcesses).ExecuteCommandAsync();
|
||||
if(mbomInputs!=null && mbomInputs.Count>0) _ = await db.Insertable<BasMbomInput>(mbomInputs).ExecuteCommandAsync();
|
||||
if(mbomOutputs!=null && mbomOutputs.Count>0) _ = await db.Insertable<BasMbomOutput>(mbomOutputs).ExecuteCommandAsync();
|
||||
|
||||
});
|
||||
|
||||
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "复制成功" : result.ErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user