345 lines
19 KiB
C#
345 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
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.JsonSerialization;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.BasicData;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.QcMgr.Entities;
|
|
using Tnb.QcMgr.Entities;
|
|
using Tnb.QcMgr.Entities.Entity;
|
|
using Tnb.QcMgr.Interfaces;
|
|
using JNPF.Common.Extension;
|
|
|
|
namespace Tnb.QcMgr
|
|
{
|
|
/// <summary>
|
|
/// 质检任务模块
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 800)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class QcCheckTaskService : IQcCheckTaskService, IDynamicApiController, ITransient, IOverideVisualDevService
|
|
{
|
|
private const string ModuleId = "26745613138709";
|
|
private readonly ISqlSugarRepository<QcCheckExecH> _repository;
|
|
private readonly IUserManager _userManager;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
public QcCheckTaskService(ISqlSugarRepository<QcCheckExecH> repository, IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
OverideFuncs.GetListAsync = GetListAsync;
|
|
}
|
|
|
|
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
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() : "";
|
|
var list = await db.Queryable<DictionaryDataEntity>()
|
|
.LeftJoin<DictionaryTypeEntity>((a, b) => a.DictionaryTypeId == b.Id)
|
|
.Where((a, b) => b.FullName == "质检状态" || b.FullName == "质检类型选择").ToListAsync();
|
|
var 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 == null ? "" : a.tasktime,
|
|
exectime = a.exectime == null ? "" : a.exectime,
|
|
execuser = e.RealName == null ? "" : e.RealName,
|
|
}).OrderByDescending(a => a.tasktime).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
foreach (var 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 : "";
|
|
}
|
|
return PageResult<QcCheckExecHOut>.SqlSugarPageResult(result);
|
|
}
|
|
/// <summary>
|
|
/// 获取任务执行明细
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetTaskItems(string id)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == id).FirstAsync();
|
|
var QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == id).ToListAsync();
|
|
var QcCheckItems = await db.Queryable<QcCheckItem>().ToListAsync();
|
|
var QcCheckTypes = await db.Queryable<QcCheckType>().ToListAsync();
|
|
var QcErrorCauses = await db.Queryable<QcErrorCause>().ToListAsync();
|
|
var QcErrorLevels = await db.Queryable<QcErrorLevel>().ToListAsync();
|
|
|
|
CheckTaskOut CheckTaskOut = new CheckTaskOut();
|
|
CheckTaskOut.mainid = id;
|
|
CheckTaskOut.wareid = QcCheckExecH.wareid!;
|
|
CheckTaskOut.workid = QcCheckExecH.workid!;
|
|
CheckTaskOut.status = QcCheckExecH.status!;
|
|
if (!string.IsNullOrEmpty(CheckTaskOut.workid))
|
|
CheckTaskOut.workname = db.Queryable<OrganizeEntity>().Where(p => p.Id == CheckTaskOut.workid).First().FullName;
|
|
CheckTaskOut.checktypes = new List<CheckExecTypeOut>();
|
|
foreach (var QcCheckExecD in QcCheckExecDs)
|
|
{
|
|
if (CheckTaskOut.checktypes.Where(p => p.checktypeid == QcCheckExecD.typeid).ToList().Count == 0)
|
|
{
|
|
CheckExecTypeOut checkType = new CheckExecTypeOut();
|
|
checkType.checktypeid = QcCheckExecD.typeid!;
|
|
checkType.checktypename = QcCheckTypes.Where(p => p.id == QcCheckExecD.typeid).First().name!;
|
|
checkType.items = new List<ExecItemOut>();
|
|
CheckTaskOut.checktypes.Add(checkType);
|
|
}
|
|
ExecItemOut Item = new ExecItemOut();
|
|
Item.itemid = QcCheckExecD.itemid!;
|
|
Item.itemdid = QcCheckExecD.id!;
|
|
Item.code = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().code!;
|
|
Item.name = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().name!;
|
|
Item.setData = new ExecItemData();
|
|
Item.setData.extype = QcCheckExecD.extype!;
|
|
Item.setData.excontent = JSON.Deserialize<Excontent>(QcCheckExecD.excontent!);
|
|
Item.setData.check = QcCheckExecD.check!;
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.errorcause))
|
|
{
|
|
var strs = QcCheckExecD.errorcause!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
Item.setData.errorcause = new List<Error>();
|
|
foreach (var str in strs)
|
|
{
|
|
Item.setData.errorcause.Add(new Error { id = str, name = QcErrorCauses.Where(p => p.id == str).First().name! });
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.errorlevel))
|
|
{
|
|
var strs = QcCheckExecD.errorlevel!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
Item.setData.errorlevel = new List<Error>();
|
|
foreach (var str in strs)
|
|
{
|
|
Item.setData.errorlevel.Add(new Error { id = str, name = QcErrorLevels.Where(p => p.id == str).First().name! });
|
|
}
|
|
}
|
|
Item.setData.remark = QcCheckExecD.remark!;
|
|
Item.setData.attachment = QcCheckExecD.attachment!;
|
|
Item.setData.customer = QcCheckExecD.custom!;
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.isexec))
|
|
Item.setData.isexec = JSON.Deserialize<IsexecE>(QcCheckExecD.isexec!);
|
|
Item.setShow = new ExecItemShow();
|
|
Item.setShow.extype = !string.IsNullOrEmpty(Item.setData.extype);
|
|
Item.setShow.excontent = !string.IsNullOrEmpty(QcCheckExecD.excontent);
|
|
Item.setShow.check = !string.IsNullOrEmpty(Item.setData.check);
|
|
Item.setShow.errorcause = Item.setData.errorcause?.Count == 0 ? false : true;
|
|
Item.setShow.errorlevel = Item.setData.errorlevel?.Count == 0 ? false : true;
|
|
Item.setShow.remark = !string.IsNullOrEmpty(Item.setData.remark);
|
|
Item.setShow.attachment = !string.IsNullOrEmpty(Item.setData.attachment);
|
|
Item.setShow.customer = !string.IsNullOrEmpty(Item.setData.customer);
|
|
Item.setShow.isexec = Item.setData.isexec == null ? false : true;
|
|
CheckTaskOut.checktypes.Where(p => p.checktypeid == QcCheckExecD.typeid).First()?.items?.Add(Item);
|
|
}
|
|
return CheckTaskOut;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行任务
|
|
/// </summary>
|
|
/// <param name="CheckTaskInput"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task SaveData(CheckTaskInput CheckTaskInput)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
try
|
|
{
|
|
var QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == CheckTaskInput.mainid).FirstAsync();
|
|
var DictionaryType = await db.Queryable<DictionaryTypeEntity>().Where(p=>p.FullName== "质检状态").FirstAsync();
|
|
var DictionaryData = await db.Queryable< DictionaryDataEntity >().Where(p => p.DictionaryTypeId==DictionaryType.Id&&p.FullName== "已完成").FirstAsync();
|
|
QcCheckExecH.checknum = CheckTaskInput.checknum;
|
|
QcCheckExecH.status = DictionaryData.Id;
|
|
QcCheckExecH.result = CheckTaskInput.result;
|
|
QcCheckExecH.execuser = _userManager.UserId;
|
|
QcCheckExecH.exectime = DateTime.Now.ToString();
|
|
var QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == CheckTaskInput.mainid).ToListAsync();
|
|
var QcCheckExecDdel = new List<QcCheckExecD>();
|
|
var QcCheckExecDinsert = new List<QcCheckExecD>();
|
|
if (CheckTaskInput.checktypes?.Count > 0)
|
|
{
|
|
for (int i=0;i< CheckTaskInput.checktypes.Count;i++)
|
|
{
|
|
if (CheckTaskInput.checktypes[i].Count > 0)
|
|
{
|
|
foreach (var exextype in CheckTaskInput.checktypes[i])
|
|
{
|
|
if (exextype.items != null)
|
|
{
|
|
foreach (var item in exextype.items)
|
|
{
|
|
var QcCheckExecD = QcCheckExecDs.Where(p => p.id == item.itemdid).FirstOrDefault();
|
|
if (QcCheckExecD == null)
|
|
continue;
|
|
if (QcCheckExecDdel.Where(p => p.id == QcCheckExecD.id).FirstOrDefault() == null)
|
|
QcCheckExecDdel.Add(QcCheckExecD);
|
|
var insert = new QcCheckExecD();
|
|
insert.mainid = QcCheckExecD.mainid;
|
|
insert.extype = QcCheckExecD.extype;
|
|
insert.excontent = QcCheckExecD.excontent;
|
|
insert.check = QcCheckExecD.check;
|
|
insert.errorcause = QcCheckExecD.errorcause;
|
|
insert.errorlevel = QcCheckExecD.errorlevel;
|
|
insert.remark = QcCheckExecD.remark;
|
|
insert.attachment = QcCheckExecD.attachment;
|
|
insert.isexec = QcCheckExecD.isexec;
|
|
insert.custom = QcCheckExecD.custom;
|
|
insert.typeid = QcCheckExecD.typeid;
|
|
insert.itemid = QcCheckExecD.itemid;
|
|
insert.create_id = QcCheckExecD.create_id;
|
|
insert.create_time = QcCheckExecD.create_time;
|
|
insert.postdata = item.postItemForm;
|
|
insert.result = item.result;
|
|
insert.checkindex = (i + 1).ToString();
|
|
QcCheckExecDinsert.Add(insert);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await db.Ado.BeginTranAsync();
|
|
await db.Updateable(QcCheckExecH).ExecuteCommandAsync();
|
|
await db.Deleteable(QcCheckExecDdel).ExecuteCommandAsync();
|
|
await db.Insertable(QcCheckExecDinsert).ExecuteCommandAsync();
|
|
await db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw Oops.Oh(ErrorCode.COM1000);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取任务结果明细
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetTaskResult(string id)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == id).FirstAsync();
|
|
var QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == id).ToListAsync();
|
|
var QcCheckItems = await db.Queryable<QcCheckItem>().ToListAsync();
|
|
var QcCheckTypes = await db.Queryable<QcCheckType>().ToListAsync();
|
|
var QcErrorCauses = await db.Queryable<QcErrorCause>().ToListAsync();
|
|
var QcErrorLevels = await db.Queryable<QcErrorLevel>().ToListAsync();
|
|
|
|
Result Result = new Result();
|
|
Result.mainid = id;
|
|
Result.checknum = QcCheckExecH.checknum!;
|
|
Result.status = QcCheckExecH.status!;
|
|
Result.checktypes = new List<List<Checktype>>();
|
|
var groupkeys = QcCheckExecDs.Select(p=>p.checkindex).Distinct().ToList();
|
|
foreach (var key in groupkeys)
|
|
{
|
|
var QcCheckExecDsbykey= QcCheckExecDs.Where(p=>p.checkindex==key).ToList();
|
|
var checktype = new List<Checktype>();
|
|
foreach (var QcCheckExecD in QcCheckExecDsbykey)
|
|
{
|
|
if (checktype.Where(p => p.checktypeid == QcCheckExecD.typeid).ToList().Count == 0)
|
|
{
|
|
Checktype checkType = new Checktype();
|
|
checkType.checktypeid = QcCheckExecD.typeid!;
|
|
checkType.checktypename = QcCheckTypes.Where(p => p.id == QcCheckExecD.typeid).First().name!;
|
|
checkType.items = new List<ExecItem>();
|
|
checktype.Add(checkType);
|
|
}
|
|
ExecItem Item = new ExecItem();
|
|
Item.itemid = QcCheckExecD.itemid!;
|
|
Item.itemdid = QcCheckExecD.id!;
|
|
Item.code = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().code!;
|
|
Item.name = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().name!;
|
|
Item.setData = new ExecItemData();
|
|
Item.setData.extype = QcCheckExecD.extype!;
|
|
Item.setData.excontent = JSON.Deserialize<Excontent>(QcCheckExecD.excontent!);
|
|
Item.setData.check = QcCheckExecD.check!;
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.errorcause))
|
|
{
|
|
var strs = QcCheckExecD.errorcause!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
Item.setData.errorcause = new List<Error>();
|
|
foreach (var str in strs)
|
|
{
|
|
Item.setData.errorcause.Add(new Error { id = str, name = QcErrorCauses.Where(p => p.id == str).First().name! });
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.errorlevel))
|
|
{
|
|
var strs = QcCheckExecD.errorlevel!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
Item.setData.errorlevel = new List<Error>();
|
|
foreach (var str in strs)
|
|
{
|
|
Item.setData.errorlevel.Add(new Error { id = str, name = QcErrorLevels.Where(p => p.id == str).First().name! });
|
|
}
|
|
}
|
|
Item.setData.remark = QcCheckExecD.remark!;
|
|
Item.setData.attachment = QcCheckExecD.attachment!;
|
|
Item.setData.customer = QcCheckExecD.custom!;
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.isexec))
|
|
Item.setData.isexec = JSON.Deserialize<IsexecE>(QcCheckExecD.isexec!);
|
|
Item.setShow = new ExecItemShow();
|
|
Item.setShow.extype = !string.IsNullOrEmpty(Item.setData.extype);
|
|
Item.setShow.excontent = !string.IsNullOrEmpty(QcCheckExecD.excontent);
|
|
Item.setShow.check = !string.IsNullOrEmpty(Item.setData.check);
|
|
Item.setShow.errorcause = Item.setData.errorcause?.Count == 0 ? false : true;
|
|
Item.setShow.errorlevel = Item.setData.errorlevel?.Count == 0 ? false : true;
|
|
Item.setShow.remark = !string.IsNullOrEmpty(Item.setData.remark);
|
|
Item.setShow.attachment = !string.IsNullOrEmpty(Item.setData.attachment);
|
|
Item.setShow.customer = !string.IsNullOrEmpty(Item.setData.customer);
|
|
Item.setShow.isexec = Item.setData.isexec == null ? false : true;
|
|
if (!string.IsNullOrEmpty(QcCheckExecD.postdata))
|
|
Item.postItemForm = JSON.Deserialize<PostItemForm>(QcCheckExecD.postdata!);
|
|
checktype.Where(p => p.checktypeid == QcCheckExecD.typeid).First()?.items?.Add(Item);
|
|
}
|
|
Result.checktypes.Add(checktype);
|
|
}
|
|
|
|
return Result;
|
|
}
|
|
}
|
|
|
|
}
|