生产bom保存接口
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
@@ -6,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.BasicData.Interfaces;
|
||||
using Tnb.BasicData.Entities.Dto;
|
||||
|
||||
namespace Tnb.BasicData
|
||||
{
|
||||
@@ -19,14 +21,211 @@ namespace Tnb.BasicData
|
||||
private readonly ISqlSugarRepository<BasMbom> _repository;
|
||||
private readonly DataBaseManager _dbManager;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public BasMbomService(
|
||||
ISqlSugarRepository<BasMbom> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
|
||||
ISqlSugarRepository<BasMbom> repository,
|
||||
DataBaseManager dbManager,
|
||||
IUserManager userManager,
|
||||
IDictionaryDataService dictionaryDataService)
|
||||
{
|
||||
_repository = repository;
|
||||
_dbManager = dbManager;
|
||||
_userManager = userManager;
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存生产bom
|
||||
/// </summary>
|
||||
/// <param name="mbomSaveDataInput"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<string> SaveData(MbomSaveDataInput mbomSaveDataInput)
|
||||
{
|
||||
DbResult<bool> 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,
|
||||
|
||||
};
|
||||
await _repository.InsertAsync(mbom);
|
||||
List<BasMbomProcess> processes = new List<BasMbomProcess>();
|
||||
List<BasMbomInput> inputs = new List<BasMbomInput>();
|
||||
List<BasMbomOutput> outputs = new List<BasMbomOutput>();
|
||||
|
||||
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,
|
||||
station = process.station,
|
||||
byproduct_status = process.byproduct_status,
|
||||
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
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<BasMbomProcess>(processes).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (inputs.Count > 0)
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (outputs.Count > 0)
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
else//修改
|
||||
{
|
||||
string orgId = _userManager.GetUserInfo().Result.organizeId;
|
||||
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<BasMbomProcess> processes = new List<BasMbomProcess>();
|
||||
List<BasMbomInput> inputs = new List<BasMbomInput>();
|
||||
List<BasMbomOutput> outputs = new List<BasMbomOutput>();
|
||||
|
||||
foreach (var process in mbomSaveDataInput.processes)
|
||||
{
|
||||
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,
|
||||
station = process.station,
|
||||
byproduct_status = process.byproduct_status,
|
||||
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await _repository.AsSugarClient().Deleteable<BasMbomProcess>().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync();
|
||||
await _repository.AsSugarClient().Deleteable<BasMbomInput>().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync();
|
||||
await _repository.AsSugarClient().Deleteable<BasMbomOutput>().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync();
|
||||
if (processes.Count > 0)
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (inputs.Count > 0)
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (outputs.Count > 0)
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user