This commit is contained in:
qianjiawei
2023-09-20 23:08:04 +08:00
parent f636b12517
commit 0f57d7d396
9 changed files with 310 additions and 72 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.QcMgr.Entities
{
public class CheckTaskData
{
public string? checktype { get; set; }
public string? materialid { get; set; }
public string? processid { get; set; }
public string? workid { get; set; }
public string? wareid { get; set; }
public List<CheckTaskDataInput>? checktypes { get; set; }
}
public class CheckTaskDataInput
{
public string? id { get; set; }
public List<TaskItemInput>? items { get; set; }
}
public class TaskItemInput
{
public string? itemid { get; set; }
public string? extype { get; set; }
public string? excontent { get; set; }
public string? check { get; set; }
public string? errorcause { get; set; }
public string? errorlevel { get; set; }
public string? remark { get; set; }
public string? attachment { get; set; }
public string? isexec { get; set; }
public string? customer { get; set; }
}
}

View File

@@ -94,7 +94,7 @@ namespace Tnb.QcMgr
CheckPlansOut.addid = QcCheckPlanAdd.id;
CheckPlansOut.triggertype = QcCheckPlanAdd.triggertype!;
CheckPlansOut.content = QcCheckPlanAdd.content!;
CheckPlansOut.number= QcCheckPlanAdd.number;
CheckPlansOut.number = QcCheckPlanAdd.number;
}
if (QcCheckPlanDs != null && QcCheckPlanDs.Count > 0)
{
@@ -137,7 +137,18 @@ namespace Tnb.QcMgr
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 (Item.setData.isexec == null)
{
Item.setShow.isexec = false;
}
else
{
if(!Item.setData.isexec.attachment&& !Item.setData.isexec.remark)
Item.setShow.isexec = false;
else
Item.setShow.isexec = true;
}
CheckPlansOut.checktypes.Where(p => p.checktypeid == QcCheckPlanD.typeid).First()?.items?.Add(Item);
}
}
@@ -187,6 +198,7 @@ namespace Tnb.QcMgr
{
if (string.IsNullOrEmpty(CheckPlanInput.mainid))
return;
await _timeTaskService.DeleteByName("生成质检任务" + CheckPlanInput.mainid);
await db.Deleteable<QcCheckPlanD>(p => p.mainid == CheckPlanInput.mainid).ExecuteCommandAsync();
await db.Deleteable<QcCheckPlanAdd>(p => p.mainid == CheckPlanInput.mainid).ExecuteCommandAsync();
QcCheckPlanAdd QcCheckPlanAdd = new QcCheckPlanAdd();
@@ -280,10 +292,47 @@ namespace Tnb.QcMgr
JoinType.Left,a.id == e.planid,
});
GetQuery(Query, entity);
var list = await Query
.WhereIF(!string.IsNullOrEmpty(entity.materialid), (a, b, c, d, e) => c.materialid == entity.materialid)
.WhereIF(!string.IsNullOrEmpty(entity.processid), (a, b, c, d, e) => d.processid == entity.processid)
.WhereIF(!string.IsNullOrEmpty(entity.workid), (a, b, c, d, e) => e.workid == entity.workid).ToListAsync();
var list = await Query.ToListAsync();
List<string> removes = new List<string>();
foreach (var data in list)
{
if (!string.IsNullOrEmpty(entity.materialid))
{
if (_repository.AsSugarClient().Queryable<QcCheckPlanMaterial>().Where(p => p.planid == data.id).Any())
{
if (!_repository.AsSugarClient().Queryable<QcCheckPlanMaterial>().Where(p => p.planid == data.id && p.materialid == entity.materialid).Any())
{
removes.Add(data.id);
}
}
}
if (!string.IsNullOrEmpty(entity.processid))
{
if (_repository.AsSugarClient().Queryable<QcCheckPlanProcess>().Where(p => p.planid == data.id).Any())
{
if (!_repository.AsSugarClient().Queryable<QcCheckPlanProcess>().Where(p => p.planid == data.id && p.processid == entity.processid).Any())
{
removes.Add(data.id);
}
}
}
if (!string.IsNullOrEmpty(entity.workid))
{
if (_repository.AsSugarClient().Queryable<QcCheckPlanWork>().Where(p => p.planid == data.id).Any())
{
if (!_repository.AsSugarClient().Queryable<QcCheckPlanWork>().Where(p => p.planid == data.id && p.workid == entity.workid).Any())
{
removes.Add(data.id);
}
}
}
}
list = list.Where(p => !removes.Contains(p.id)).ToList();
// .WhereIF(!string.IsNullOrEmpty(entity.materialid), (a, b, c, d, e) => c.materialid == entity.materialid)
// .WhereIF(!string.IsNullOrEmpty(entity.processid), (a, b, c, d, e) => d.processid == entity.processid)
// .WhereIF(!string.IsNullOrEmpty(entity.workid), (a, b, c, d, e) => e.workid == entity.workid).ToListAsync();
Filter(list, entity);
if (list.Count > 0)
await SaveTask(list, entity);
@@ -410,5 +459,6 @@ namespace Tnb.QcMgr
await _repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync();
}
}
}
}

View File

@@ -40,6 +40,12 @@ namespace Tnb.QcMgr
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string,string> dic= new Dictionary<string,string>();
dic.Add("ok", "合格");
dic.Add("no", "不合格");
dic.Add("barelyok", "让步合格");
dic.Add("await", "待检");
dic.Add("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() : "";
@@ -47,6 +53,7 @@ namespace Tnb.QcMgr
var list = await db.Queryable<DictionaryDataEntity>()
.LeftJoin<DictionaryTypeEntity>((a, b) => a.DictionaryTypeId == b.Id)
.Where((a, b) => b.FullName == "质检状态" || b.FullName == "质检类型选择").ToListAsync();
var BasLocations= await db.Queryable<BasLocation>().ToListAsync();
var result = await db.Queryable<QcCheckExecH>()
.LeftJoin<BasMaterial>((a, b) => a.materialid == b.id)
.LeftJoin<BasProcess>((a, b, c) => a.processid == c.id)
@@ -70,11 +77,13 @@ namespace Tnb.QcMgr
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);
}).OrderByDescending(a =>DateTime.Parse( a.exectime)).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 : "";
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);
}

View File

@@ -31,6 +31,7 @@ using Tnb.QcMgr.Entities;
using Tnb.QcMgr.Entities.Entity;
using Tnb.QcMgr.Interfaces;
using JNPF.Common.Extension;
using Microsoft.AspNetCore.Authorization;
namespace Tnb.QcMgr
{
@@ -56,6 +57,12 @@ namespace Tnb.QcMgr
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("ok", "合格");
dic.Add("no", "不合格");
dic.Add("barelyok", "让步合格");
dic.Add("await", "待检");
dic.Add("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() : "";
@@ -63,6 +70,7 @@ namespace Tnb.QcMgr
var list = await db.Queryable<DictionaryDataEntity>()
.LeftJoin<DictionaryTypeEntity>((a, b) => a.DictionaryTypeId == b.Id)
.Where((a, b) => b.FullName == "质检状态" || b.FullName == "质检类型选择").ToListAsync();
var BasLocations = await db.Queryable<BasLocation>().ToListAsync();
var result = await db.Queryable<QcCheckExecH>()
.LeftJoin<BasMaterial>((a, b) => a.materialid == b.id)
.LeftJoin<BasProcess>((a, b, c) => a.processid == c.id)
@@ -86,11 +94,13 @@ namespace Tnb.QcMgr
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);
}).OrderByDescending(a => DateTime.Parse(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 : "";
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);
}
@@ -164,8 +174,8 @@ namespace Tnb.QcMgr
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.errorcause = Item.setData.errorcause==null|| Item.setData.errorcause?.Count == 0 ? false : true;
Item.setShow.errorlevel = Item.setData.errorlevel == null || 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);
@@ -209,6 +219,8 @@ namespace Tnb.QcMgr
{
foreach (var item in exextype.items)
{
if (item.postItemForm == null)
throw Oops.Oh("执行失败");
var QcCheckExecD = QcCheckExecDs.Where(p => p.id == item.itemdid).FirstOrDefault();
if (QcCheckExecD == null)
continue;
@@ -229,7 +241,7 @@ namespace Tnb.QcMgr
insert.itemid = QcCheckExecD.itemid;
insert.create_id = QcCheckExecD.create_id;
insert.create_time = QcCheckExecD.create_time;
insert.postdata = item.postItemForm;
insert.postdata =
insert.result = item.result;
insert.checkindex = (i + 1).ToString();
QcCheckExecDinsert.Add(insert);
@@ -247,8 +259,7 @@ namespace Tnb.QcMgr
}
catch (Exception)
{
throw Oops.Oh(ErrorCode.COM1000);
throw Oops.Oh("执行失败");
}
}
@@ -339,6 +350,59 @@ namespace Tnb.QcMgr
return Result;
}
[HttpPost]
public async Task CreateTaskData(CheckTaskData checkTaskData)
{
var db = _repository.AsSugarClient();
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 QcCheckExecH = new QcCheckExecH();
QcCheckExecH.checktype = checkTaskData.checktype;
QcCheckExecH.materialid = checkTaskData.materialid;
QcCheckExecH.processid = checkTaskData.processid;
QcCheckExecH.workid = checkTaskData.workid;
QcCheckExecH.wareid = checkTaskData.wareid;
QcCheckExecH.status = DictionaryData.Id;
QcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
QcCheckExecH.create_id = _userManager.UserId;
QcCheckExecH.create_time = DateTime.Now;
List<QcCheckExecD> QcCheckExecDs = new List<QcCheckExecD>();
if (checkTaskData.checktypes != null)
{
foreach (var checktype in checkTaskData.checktypes)
{
if (checktype.items != null)
{
foreach (var item in checktype.items)
{
QcCheckExecD QcCheckExecD = new QcCheckExecD();
QcCheckExecD.mainid = QcCheckExecH.id;
QcCheckExecD.typeid = checktype.id;
QcCheckExecD.itemid = item.itemid;
QcCheckExecD.extype = item.extype;
QcCheckExecD.excontent = item.excontent;
QcCheckExecD.check = item.check;
QcCheckExecD.errorcause = item.errorcause?.Replace("\"", "").Trim();
QcCheckExecD.errorlevel = item.errorlevel?.Replace("\"", "").Trim();
QcCheckExecD.remark = item.remark;
QcCheckExecD.attachment = item.attachment;
QcCheckExecD.isexec = item.isexec;
QcCheckExecD.custom = item.customer;
QcCheckExecD.create_id = _userManager.UserId;
QcCheckExecD.create_time = DateTime.Now;
QcCheckExecDs.Add(QcCheckExecD);
}
}
}
}
await db.Ado.BeginTranAsync();
await db.Insertable(QcCheckExecH).ExecuteCommandAsync();
await db.Insertable(QcCheckExecDs).ExecuteCommandAsync();
await db.Ado.CommitTranAsync();
}
}
}