147 lines
8.6 KiB
C#
147 lines
8.6 KiB
C#
using System.Linq.Expressions;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.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.QcMgr.Entities;
|
|
|
|
namespace Tnb.QcMgr
|
|
{ /// <summary>
|
|
/// 质检任务模块
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 800)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class QcCheckTaskResultService : IDynamicApiController, ITransient, IOverideVisualDevService
|
|
{
|
|
private const string ModuleId = "26873741070613";
|
|
private readonly ISqlSugarRepository<QcCheckExecH> _repository;
|
|
private readonly IUserManager _userManager;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
public QcCheckTaskResultService(ISqlSugarRepository<QcCheckExecH> repository, IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
OverideFuncs.GetListAsync = GetListAsync;
|
|
}
|
|
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
Dictionary<string, string> dic = new()
|
|
{
|
|
{ "ok", "合格" },
|
|
{ "no", "不合格" },
|
|
{ "barelyok", "让步合格" },
|
|
{ "await", "待检" },
|
|
{ "temporarily", "暂控" }
|
|
};
|
|
Dictionary<string, string>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
|
|
string materialid = queryJson.ContainsKey("materialid") ? queryJson["materialid"].ToString() : "";
|
|
string checktype = queryJson.ContainsKey("checktype") ? queryJson["checktype"].ToString() : "";
|
|
string status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : "";
|
|
List<DictionaryDataEntity> list = await db.Queryable<DictionaryDataEntity>()
|
|
.LeftJoin<DictionaryTypeEntity>((a, b) => a.DictionaryTypeId == b.Id)
|
|
.Where((a, b) => b.FullName == "质检状态" || b.FullName == "质检类型选择").ToListAsync();
|
|
List<BasLocation> BasLocations = await db.Queryable<BasLocation>().ToListAsync();
|
|
SqlSugarPagedList<QcCheckExecHOut> result = await db.Queryable<QcCheckExecH>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.materialid == b.id)
|
|
.LeftJoin<BasProcess>((a, b, c) => a.processid == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => a.workid == d.Id)
|
|
.LeftJoin<UserEntity>((a, b, c, d, e) => a.execuser == e.Id)
|
|
.WhereIF(!string.IsNullOrEmpty(materialid), (a, b, c, d, e) => b.name.Contains(materialid))
|
|
.WhereIF(!string.IsNullOrEmpty(checktype), (a, b, c, d, e) => a.checktype == checktype)
|
|
.WhereIF(!string.IsNullOrEmpty(status), (a, b, c, d, e) => a.status == status)
|
|
.Where((a, b, c, d, e) => a.status == list.Where(p => p.FullName == "已完成").First().Id)
|
|
.Select((a, b, c, d, e) => new QcCheckExecHOut
|
|
{
|
|
id = a.id,
|
|
materialid = b.name,
|
|
checktype = a.checktype,
|
|
workid = d.FullName,
|
|
processid = c.process_name,
|
|
wareid = a.wareid,
|
|
checknum = a.checknum,
|
|
status = a.status,
|
|
result = a.result,
|
|
tasktime = a.tasktime ?? "",
|
|
exectime = a.exectime ?? "",
|
|
execuser = e.RealName ?? "",
|
|
}).OrderByDescending(a => DateTime.Parse(a.exectime)).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
foreach (QcCheckExecHOut? item in result.list)
|
|
{
|
|
item.checktype = list.Select(p => p.Id).Contains(item.checktype) ? list.Where(p => p.Id == item.checktype).First().FullName : "";
|
|
item.status = list.Select(p => p.Id).Contains(item.status) ? list.Where(p => p.Id == item.status).First().FullName : "";
|
|
item.result = dic.Where(p => p.Key == item.result).Any() ? dic.Where(p => p.Key == item.result).First().Value : "";
|
|
item.wareid = BasLocations.Where(p => p.id == item.wareid).Any() ? BasLocations.Where(p => p.id == item.wareid).First().location_code : "";
|
|
}
|
|
return PageResult<QcCheckExecHOut>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetCheckTask(VisualDevModelListQueryInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
Dictionary<string, string> dic = new()
|
|
{
|
|
{ "ok", "合格" },
|
|
{ "no", "不合格" },
|
|
{ "barelyOk", "让步合格" },
|
|
{ "await", "待检" },
|
|
{ "temporarily", "暂控" }
|
|
};
|
|
Dictionary<string, string>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
|
|
string materialid = queryJson.ContainsKey("materialid") ? queryJson["materialid"].ToString() : "";
|
|
string checktype = queryJson.ContainsKey("checktype") ? queryJson["checktype"].ToString() : "";
|
|
string status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : "";
|
|
List<DictionaryDataEntity> list = await db.Queryable<DictionaryDataEntity>()
|
|
.LeftJoin<DictionaryTypeEntity>((a, b) => a.DictionaryTypeId == b.Id)
|
|
.Where((a, b) => b.FullName == "质检状态" || b.FullName == "质检类型选择").ToListAsync();
|
|
List<BasLocation> BasLocations = await db.Queryable<BasLocation>().ToListAsync();
|
|
Expression<Func<QcCheckExecHOut, object>> expression = list.Where(p => p.FullName == "待执行").First().Id == status
|
|
? (a => DateTime.Parse(a.tasktime!))
|
|
: (a => DateTime.Parse(a.exectime!));
|
|
SqlSugarPagedList<QcCheckExecHOut> result = await db.Queryable<QcCheckExecH>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.materialid == b.id)
|
|
.LeftJoin<BasProcess>((a, b, c) => a.processid == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => a.workid == d.Id)
|
|
.LeftJoin<UserEntity>((a, b, c, d, e) => a.execuser == e.Id)
|
|
.WhereIF(!string.IsNullOrEmpty(materialid), (a, b, c, d, e) => a.materialid == materialid)
|
|
.WhereIF(!string.IsNullOrEmpty(checktype), (a, b, c, d, e) => a.checktype == checktype)
|
|
.WhereIF(!string.IsNullOrEmpty(status), (a, b, c, d, e) => a.status == status)
|
|
// .Where((a, b, c, d, e) => a.status == list.Where(p => p.FullName == "已完成").First().Id)
|
|
.Select((a, b, c, d, e) => new QcCheckExecHOut
|
|
{
|
|
id = a.id,
|
|
materialid = b.name,
|
|
checktype = a.checktype,
|
|
workid = d.FullName,
|
|
processid = c.process_name,
|
|
wareid = a.wareid,
|
|
checknum = a.checknum,
|
|
status = a.status,
|
|
result = a.result,
|
|
tasktime = a.tasktime ?? "",
|
|
exectime = a.exectime ?? "",
|
|
execuser = e.RealName ?? "",
|
|
}).OrderByDescending(expression).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
foreach (QcCheckExecHOut? item in result.list)
|
|
{
|
|
item.checktype = list.Select(p => p.Id).Contains(item.checktype) ? list.Where(p => p.Id == item.checktype).First().FullName : "";
|
|
item.status = list.Select(p => p.Id).Contains(item.status) ? list.Where(p => p.Id == item.status).First().FullName : "";
|
|
item.result = dic.Where(p => p.Key == item.result).Any() ? dic.Where(p => p.Key == item.result).First().Value : "";
|
|
item.wareid = BasLocations.Where(p => p.id == item.wareid).Any() ? BasLocations.Where(p => p.id == item.wareid).First().location_code : "";
|
|
}
|
|
return PageResult<QcCheckExecHOut>.SqlSugarPageResult(result);
|
|
}
|
|
}
|
|
}
|