生产bom工序表添加工艺路线子表id,esop

This commit is contained in:
2023-06-21 17:19:27 +08:00
parent eb0909fd28
commit e563920a39
11 changed files with 407 additions and 21 deletions

View File

@@ -0,0 +1,169 @@
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.BasicData.Entities.Dto;
using Tnb.BasicData.Interfaces;
namespace Tnb.BasicData
{
/// <summary>
/// esop关联
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
[Route("api/[area]/[controller]/[action]")]
[OverideVisualDev(ModelId)]
public class BasESopService : IBasESopService,IOverideVisualDevService,IDynamicApiController, ITransient
{
public const string ModelId = "26919620992277";
private readonly ISqlSugarRepository<BasESop> _repository;
private readonly IUserManager _userManager;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public BasESopService(
IUserManager userManager,
ISqlSugarRepository<BasESop> repository)
{
_repository = repository;
_userManager = userManager;
OverideFuncs.GetListAsync = GetList;
}
/// <summary>
/// ESOP列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, object>? queryJson = string.IsNullOrEmpty(input.queryJson) ? null : input.queryJson.ToObject<Dictionary<string, object>>();
string code = queryJson!=null && queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
string name = queryJson!=null && queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
string version = queryJson!=null && queryJson.ContainsKey("version") ? queryJson["version"].ToString() : "";
var list = await db.Queryable<BasESop, BasMbom, BasMbomProcess, UserEntity,BasProcess>((a, b, c, d,e) => new object[]
{
JoinType.Left, a.mbom_id == b.id,
JoinType.Left, a.mbom_process_id == c.id,
JoinType.Left, a.create_id == d.Id,
JoinType.Left, c.process_id == e.id,
})
.WhereIF(!string.IsNullOrEmpty(code), (a, b, c, d) => a.code.Contains(code))
.WhereIF(!string.IsNullOrEmpty(name), (a, b, c, d) => a.name.Contains(name))
.WhereIF(!string.IsNullOrEmpty(version), (a, b, c, d) => a.version.Contains(version))
.Where((a,b,c)=>a.enabled==1)
.Select((a, b, c, d,e) => new ESopListOutput
{
id = a.id,
code = a.code,
name = a.name,
mbom_id = b.version,
mbom_process_id = e.process_name,
version = a.version,
enabled = a.enabled==1 ? "是" : "否",
attachment = a.attachment,
remark = a.remark,
create_id = d.RealName,
create_time = a.create_time==null ? "" : a.create_time.Value.ToString("yyyy-MM-dd"),
mbom_id_id = a.mbom_id,
mbom_process_id_id = a.mbom_process_id
}).ToPagedListAsync((input?.currentPage??1), (input?.pageSize??50));
return PageResult<ESopListOutput>.SqlSugarPageResult(list);
}
[HttpPost]
public async Task<dynamic> GetHistoryList(EsopHistoryListQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
if (input!=null && !string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input?.queryJson ?? "");
}
string code = queryJson!=null && queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
string name = queryJson!=null && queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
string version = queryJson!=null && queryJson.ContainsKey("version") ? queryJson["version"].ToString() : "";
var list = await db.Queryable<BasESop, BasMbom, BasMbomProcess, UserEntity,BasProcess>((a, b, c, d,e) => new object[]
{
JoinType.Left, a.mbom_id == b.id,
JoinType.Left, a.mbom_process_id == c.id,
JoinType.Left, a.create_id == d.Id,
JoinType.Left, c.process_id == e.id,
})
.WhereIF(!string.IsNullOrEmpty(code), (a, b, c, d) => a.code.Contains(code))
.WhereIF(!string.IsNullOrEmpty(name), (a, b, c, d) => a.name.Contains(name))
.WhereIF(!string.IsNullOrEmpty(version), (a, b, c, d) => a.version.Contains(version))
.Where((a,b,c)=>a.mbom_id==input.mbom_id && a.mbom_process_id==input.mbom_process_id)
.Select((a, b, c, d,e) => new ESopListOutput
{
id = a.id,
code = a.code,
name = a.name,
mbom_id = b.version,
mbom_process_id = e.process_name,
version = a.version,
enabled = a.enabled==1 ? "是" : "否",
attachment = a.attachment,
remark = a.remark,
create_id = d.RealName,
create_time = a.create_time==null ? "" : a.create_time.Value.ToString("yyyy-MM-dd"),
mbom_id_id = a.mbom_id
}).ToPagedListAsync((input?.currentPage??1), (input?.pageSize??50));
return PageResult<ESopListOutput>.SqlSugarPageResult(list);
}
[HttpPost]
public async Task<dynamic> UploadNewVersion(UploadNewVersionInput input)
{
if (_repository.IsAny(x => x.mbom_id == input.mbom_id && x.mbom_process_id == input.mbom_process_id && x.version == input.version))
{
throw Oops.Bah("已存在该版本");
}
var db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
await _repository.UpdateAsync(x => new BasESop()
{
enabled = 0,
}, x => x.mbom_id == input.mbom_id && x.mbom_process_id == input.mbom_process_id);
BasESop basESop = new BasESop()
{
code = input.code,
name = input.name,
version = input.version,
attachment = input.attachment,
mbom_id = input.mbom_id,
mbom_process_id = input.mbom_process_id,
remark = input.remark,
create_id = _userManager.UserId,
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
enabled = 1,
};
await _repository.InsertAsync(basESop);
});
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "上传成功" : result.ErrorMessage;
}
}
}

View File

@@ -114,6 +114,7 @@ namespace Tnb.BasicData
{
mbomProcessOutDtos.Add(new MbomProcessOutDto()
{
id = process.id,
mbom_id = mbom.id,
process_id = process.process_id,
preparation_time = process.preparation_time,
@@ -159,7 +160,8 @@ namespace Tnb.BasicData
var result = await _db.Queryable<BasMbom>()
.LeftJoin<BasMbomProcess>((a, b) => a.id == b.mbom_id)
.LeftJoin<BasRouteH>((a, b, c) => a.route_id == c.id)
.LeftJoin<BasRouteD>((a, b, c, d) => b.process_id == d.process_id && c.id == d.route_id)
// .LeftJoin<BasRouteD>((a, b, c, d) => b.process_id == d.process_id && c.id == d.route_id)
.LeftJoin<BasRouteD>((a, b, c, d) => b.route_detail_id == d.id)
.LeftJoin<BasMbomOutput>((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
@@ -293,6 +295,7 @@ namespace Tnb.BasicData
station = process?.station ?? "",
byproduct_status = process.byproduct_status,
production_method = process.production_method,
route_detail_id = process.route_detail_id,
});
@@ -379,7 +382,7 @@ namespace Tnb.BasicData
}, x => x.id == mbomSaveDataInput.id);
}
List<BasMbomProcess> processes = new List<BasMbomProcess>();
// List<BasMbomProcess> processes = new List<BasMbomProcess>();
List<BasMbomInput> inputs = new List<BasMbomInput>();
List<BasMbomOutput> outputs = new List<BasMbomOutput>();
@@ -387,19 +390,29 @@ namespace Tnb.BasicData
{
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 ?? 0,
station = process.station,
byproduct_status = process.byproduct_status,
production_method = process.production_method,
});
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<BasMbomProcess>()
.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)
{
@@ -442,14 +455,14 @@ namespace Tnb.BasicData
if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
{
await _repository.AsSugarClient().Deleteable<BasMbomProcess>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// 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 (processes.Count > 0)
// {
// await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync();
// }
if (inputs.Count > 0)
{