169 lines
7.7 KiB
C#
169 lines
7.7 KiB
C#
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;
|
|
|
|
}
|
|
}
|
|
} |