862 lines
49 KiB
C#
862 lines
49 KiB
C#
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Filter;
|
||
using JNPF.Common.Security;
|
||
using JNPF.DependencyInjection;
|
||
using JNPF.DynamicApiController;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.JsonSerialization;
|
||
using JNPF.Logging;
|
||
using JNPF.Systems.Entitys.Permission;
|
||
using JNPF.Systems.Entitys.System;
|
||
using JNPF.VisualDev;
|
||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Newtonsoft.Json;
|
||
using SqlSugar;
|
||
using Tnb.BasicData.Entities;
|
||
using Tnb.EquipMgr.Entities;
|
||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||
using Tnb.QcMgr.Entities;
|
||
using Tnb.QcMgr.Interfaces;
|
||
using Tnb.WarehouseMgr.Entities.Consts;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||
using Tnb.WarehouseMgr.Interfaces;
|
||
using Tnb.ProductionMgr.Interfaces;
|
||
using Tnb.ProductionMgr.Entities;
|
||
using Tnb.ProductionMgr.Entities.Dto;
|
||
using Tnb.WarehouseMgr.Entities.Enums;
|
||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using JNPF.Common.Extension;
|
||
using Tnb.QcMgr.Entities.Entity;
|
||
using Tnb.BasicData;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using NPOI.SS.Formula.Functions;
|
||
using Tnb.QcMgr.Entities.Enums;
|
||
|
||
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;
|
||
private readonly IWmsSaleService _wmsSaleService;
|
||
private readonly IWmsPurchaseService _wmsPurchaseService;
|
||
private readonly IPrdMoTaskService _prdMoTaskService;
|
||
private readonly IBillRullService _billRullService;
|
||
private static SemaphoreSlim prdreportSemaphore = new(1);
|
||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||
public QcCheckTaskService(ISqlSugarRepository<QcCheckExecH> repository,
|
||
IUserManager userManager,
|
||
IWmsSaleService wmsSaleService,
|
||
IPrdMoTaskService prdMoTaskService,
|
||
IWmsPurchaseService wmsPurchaseService,
|
||
IBillRullService billRullService)
|
||
{
|
||
_repository = repository;
|
||
_userManager = userManager;
|
||
OverideFuncs.GetListAsync = GetListAsync;
|
||
_wmsSaleService= wmsSaleService;
|
||
_prdMoTaskService = prdMoTaskService;
|
||
_wmsPurchaseService= wmsPurchaseService;
|
||
_billRullService = billRullService;
|
||
}
|
||
|
||
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)
|
||
.LeftJoin<PrdReport>((a,b,c,d,e,f)=>a.report_id==f.id)
|
||
.LeftJoin<PrdMoTask>((a,b,c,d,e,f,g)=>a.mo_task_code==g.mo_task_code)
|
||
.LeftJoin<EqpEquipment>((a,b,c,d,e,f,g,h)=>g.eqp_id==h.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,f,g,h) => 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 ?? "",
|
||
mo_task_code = a.mo_task_code,
|
||
batch = a.batch,
|
||
qty = a.qty,
|
||
rqty = a.rqty,
|
||
material_standard = b.material_standard,
|
||
material_specification = b.material_specification,
|
||
equip_name = h.name,
|
||
extras = h.name,
|
||
f_flowid = b.material_standard,
|
||
f_flowtaskid = b.material_specification,
|
||
}).OrderByDescending(a => DateTime.Parse(a.tasktime)).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);
|
||
}
|
||
/// <summary>
|
||
/// 获取任务执行明细
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<dynamic> GetTaskItems(string id)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
QcCheckExecH QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == id).FirstAsync();
|
||
List<QcCheckExecD> QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == id).ToListAsync();
|
||
List<QcCheckItem> QcCheckItems = await db.Queryable<QcCheckItem>().ToListAsync();
|
||
List<QcCheckType> QcCheckTypes = await db.Queryable<QcCheckType>().ToListAsync();
|
||
List<QcErrorCause> QcErrorCauses = await db.Queryable<QcErrorCause>().ToListAsync();
|
||
List<QcErrorLevel> QcErrorLevels = await db.Queryable<QcErrorLevel>().ToListAsync();
|
||
|
||
PrdMoTask moTask = await db.Queryable<PrdMoTask>().Where(x => x.mo_task_code == QcCheckExecH.mo_task_code).FirstAsync();
|
||
if (moTask == null)
|
||
{
|
||
throw Oops.Bah($"未找到任务单{QcCheckExecH.mo_task_code}");
|
||
}
|
||
|
||
// if (string.IsNullOrEmpty(QcCheckExecH.report_id))
|
||
// {
|
||
// throw Oops.Bah($"未找到提报记录{QcCheckExecH.report_id}");
|
||
// }
|
||
BasMaterial basMaterial = await db.Queryable<BasMaterial>().Where(x=>x.id==moTask.material_id).FirstAsync();
|
||
PrdReport prdReport = await db.Queryable<PrdReport>().SingleAsync(x => x.id == QcCheckExecH.report_id);
|
||
UserEntity userEntity = null;
|
||
if (prdReport != null)
|
||
{
|
||
userEntity = await db.Queryable<UserEntity>().SingleAsync(x => x.Id == prdReport.create_id);
|
||
}
|
||
CheckTaskOut CheckTaskOut = new()
|
||
{
|
||
mainid = id,
|
||
wareid = QcCheckExecH.wareid!,
|
||
workid = QcCheckExecH.workid!,
|
||
status = QcCheckExecH.status!,
|
||
mo_task_code = QcCheckExecH.mo_task_code,
|
||
material_id = moTask.material_id,
|
||
material_code = basMaterial.code,
|
||
material_name = basMaterial.name,
|
||
checknum = !string.IsNullOrEmpty(QcCheckExecH.checknum) ? int.Parse(QcCheckExecH.checknum) : 0,
|
||
worker_name = userEntity?.RealName ?? "",
|
||
bill_code = QcCheckExecH.bill_code,
|
||
carry_code = prdReport!=null ? prdReport.material_box_code : "",
|
||
};
|
||
if (!string.IsNullOrEmpty(CheckTaskOut.workid))
|
||
{
|
||
CheckTaskOut.workname = db.Queryable<OrganizeEntity>().Where(p => p.Id == CheckTaskOut.workid).First()?.FullName;
|
||
}
|
||
|
||
CheckTaskOut.checktypes = new List<CheckExecTypeOut>();
|
||
foreach (QcCheckExecD QcCheckExecD in QcCheckExecDs)
|
||
{
|
||
if (CheckTaskOut.checktypes.Where(p => p.checktypeid == QcCheckExecD.typeid).ToList().Count == 0)
|
||
{
|
||
CheckExecTypeOut checkType = new()
|
||
{
|
||
checktypeid = QcCheckExecD.typeid!,
|
||
checktypename = QcCheckTypes.Where(p => p.id == QcCheckExecD.typeid).First().name!,
|
||
items = new List<ExecItemOut>()
|
||
};
|
||
CheckTaskOut.checktypes.Add(checkType);
|
||
}
|
||
ExecItemOut Item = new()
|
||
{
|
||
itemid = QcCheckExecD.itemid!,
|
||
itemdid = QcCheckExecD.id!,
|
||
code = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().code!,
|
||
name = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().name!,
|
||
setData = new ExecItemData
|
||
{
|
||
extype = QcCheckExecD.extype!,
|
||
excontent = JSON.Deserialize<Excontent>(QcCheckExecD.excontent!),
|
||
check = QcCheckExecD.check!
|
||
}
|
||
};
|
||
if (!string.IsNullOrEmpty(QcCheckExecD.errorcause))
|
||
{
|
||
string[] strs = QcCheckExecD.errorcause!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||
Item.setData.errorcause = new List<Error>();
|
||
foreach (string str in strs)
|
||
{
|
||
if (string.IsNullOrEmpty(str) || str == "null") continue;
|
||
Item.setData.errorcause.Add(new Error { id = str, name = QcErrorCauses.Where(p => p.id == str).First()?.name! });
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(QcCheckExecD.errorlevel))
|
||
{
|
||
string[] strs = QcCheckExecD.errorlevel!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||
Item.setData.errorlevel = new List<Error>();
|
||
foreach (string str in strs)
|
||
{
|
||
if (string.IsNullOrEmpty(str) || str == "null") continue;
|
||
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
|
||
{
|
||
extype = !string.IsNullOrEmpty(Item.setData.extype),
|
||
excontent = !string.IsNullOrEmpty(QcCheckExecD.excontent),
|
||
check = !string.IsNullOrEmpty(Item.setData.check),
|
||
errorcause = Item.setData.errorcause != null && (Item.setData.errorcause?.Count) != 0,
|
||
errorlevel = Item.setData.errorlevel != null && (Item.setData.errorlevel?.Count) != 0,
|
||
remark = !string.IsNullOrEmpty(Item.setData.remark),
|
||
attachment = !string.IsNullOrEmpty(Item.setData.attachment),
|
||
customer = !string.IsNullOrEmpty(Item.setData.customer),
|
||
isexec = Item.setData.isexec != null
|
||
};
|
||
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)
|
||
{
|
||
//CheckTaskInput.startEndTime = new long[] { 1730084456000, 1730170856000 };
|
||
await prdreportSemaphore.WaitAsync();
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
try
|
||
{
|
||
Dictionary<string, int> dic = new()
|
||
{
|
||
{ "ok", 1 },
|
||
{ "no", 2 },
|
||
{ "barelyOk", 4 },
|
||
{ "await", 8 },
|
||
{ "temporarily", 16 },
|
||
{ "checking", 32 },
|
||
};
|
||
QcCheckExecH QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == CheckTaskInput.mainid).FirstAsync();
|
||
if (QcCheckExecH == null)
|
||
throw Oops.Bah($"未找到质检任务:{CheckTaskInput.mainid}");
|
||
DictionaryTypeEntity DictionaryType = await db.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
|
||
DictionaryDataEntity 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("yyyy-MM-dd HH:mm:ss");
|
||
QcCheckExecH.check_type = CheckTaskInput.check_type;
|
||
QcCheckExecH.remark = CheckTaskInput.remark;
|
||
QcCheckExecH.attachment = CheckTaskInput.attachment;
|
||
|
||
#region 质检结论不合格, 需要记录暂控时间区间,并且记录载具信息
|
||
if (CheckTaskInput.result == "no")//质检结论不合格,记录暂控时间
|
||
{
|
||
if (CheckTaskInput.startEndTime == null || CheckTaskInput.startEndTime.Length <= 1)
|
||
{
|
||
throw Oops.Bah("不合格时,请选择时间区间");
|
||
}
|
||
QcCheckExecH.control_start_time = CheckTaskInput.startEndTime[0].TimeStampToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
|
||
QcCheckExecH.control_end_time = CheckTaskInput.startEndTime[1].TimeStampToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
#endregion
|
||
|
||
List<QcCheckExecD> QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == CheckTaskInput.mainid).ToListAsync();
|
||
|
||
int rqty = 0;
|
||
List<QcCheckExecD> QcCheckExecDdel = new();
|
||
List<QcCheckExecD> QcCheckExecDinsert = new();
|
||
if (CheckTaskInput.checktypes?.Count > 0)
|
||
{
|
||
for (int i = 0; i < CheckTaskInput.checktypes.Count; i++)
|
||
{
|
||
if (CheckTaskInput.checktypes[i].Count > 0)
|
||
{
|
||
foreach (Exextype exextype in CheckTaskInput.checktypes[i])
|
||
{
|
||
if (exextype.items != null)
|
||
{
|
||
foreach (ExecItemInput item in exextype.items)
|
||
{
|
||
//if (item.postItemForm == null)
|
||
//{
|
||
// throw Oops.Oh("执行失败");
|
||
//}
|
||
|
||
QcCheckExecD? 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);
|
||
}
|
||
|
||
QcCheckExecD insert = new()
|
||
{
|
||
mainid = QcCheckExecD.mainid,
|
||
extype = QcCheckExecD.extype,
|
||
excontent = QcCheckExecD.excontent,
|
||
check = QcCheckExecD.check,
|
||
errorcause = QcCheckExecD.errorcause,
|
||
errorlevel = QcCheckExecD.errorlevel,
|
||
remark = QcCheckExecD.remark,
|
||
attachment = QcCheckExecD.attachment,
|
||
isexec = QcCheckExecD.isexec,
|
||
custom = QcCheckExecD.custom,
|
||
typeid = QcCheckExecD.typeid,
|
||
itemid = QcCheckExecD.itemid,
|
||
create_id = QcCheckExecD.create_id,
|
||
create_time = QcCheckExecD.create_time,
|
||
postdata = item.postItemForm,
|
||
result = item.result,
|
||
checkindex = (i + 1).ToString(),
|
||
qty = item.qty
|
||
};
|
||
QcCheckExecDinsert.Add(insert);
|
||
|
||
rqty += item.qty;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
await db.Ado.BeginTranAsync();
|
||
QcCheckExecH.qty = int.Parse(CheckTaskInput.checknum) - rqty;
|
||
QcCheckExecH.rqty = rqty;
|
||
//_ = await db.Updateable(QcCheckExecH).ExecuteCommandAsync();
|
||
await db.Updateable<QcCheckExecH>()
|
||
.SetColumns(x => x.checknum == QcCheckExecH.checknum)
|
||
.SetColumns(x => x.status == QcCheckExecH.status)
|
||
.SetColumns(x => x.result == QcCheckExecH.result)
|
||
.SetColumns(x => x.execuser == QcCheckExecH.execuser)
|
||
.SetColumns(x => x.exectime == QcCheckExecH.exectime)
|
||
.SetColumns(x => x.check_type == QcCheckExecH.check_type)
|
||
.SetColumns(x => x.remark == QcCheckExecH.remark)
|
||
.SetColumns(x => x.attachment == QcCheckExecH.attachment)
|
||
.SetColumns(x => x.qty == QcCheckExecH.qty)
|
||
.SetColumns(x => x.rqty == QcCheckExecH.rqty)
|
||
.SetColumns(x => x.control_start_time == QcCheckExecH.control_start_time)
|
||
.SetColumns(x => x.control_end_time == QcCheckExecH.control_end_time)
|
||
.Where(x => x.id == CheckTaskInput.mainid)
|
||
.ExecuteCommandAsync();
|
||
_ = await db.Deleteable(QcCheckExecDdel).ExecuteCommandAsync();
|
||
_ = await db.Insertable(QcCheckExecDinsert).ExecuteCommandAsync();
|
||
//出厂检
|
||
if (QcCheckExecH.checktype == "26589783783701" && !string.IsNullOrEmpty(QcCheckExecH.extras))
|
||
{
|
||
MesCheckdCallbackUpinput mesCheckdCallbackUpinput = new MesCheckdCallbackUpinput();
|
||
mesCheckdCallbackUpinput.maintableid = QcCheckExecH.extras;
|
||
mesCheckdCallbackUpinput.check_conclusion = dic.Where(p => p.Key == CheckTaskInput.result).Any() ? dic.Where(p => p.Key == CheckTaskInput.result).First().Value : 0;
|
||
await _wmsSaleService.MesCheckdSaleCallback(mesCheckdCallbackUpinput);
|
||
}
|
||
//入厂检
|
||
else if (QcCheckExecH.checktype == "26589773352981" && !string.IsNullOrEmpty(QcCheckExecH.extras))
|
||
{
|
||
MesCheckdCallbackUpinput mesCheckdCallbackUpinput = new MesCheckdCallbackUpinput();
|
||
mesCheckdCallbackUpinput.maintableid = QcCheckExecH.extras;
|
||
mesCheckdCallbackUpinput.check_conclusion = dic.Where(p => p.Key == CheckTaskInput.result).Any() ? dic.Where(p => p.Key == CheckTaskInput.result).First().Value : 0;
|
||
await _wmsPurchaseService.MesCheckdPurchaseCallback(mesCheckdCallbackUpinput);
|
||
}
|
||
else if (QcCheckExecH.checktype == WmsWareHouseConst.LINGBUJIANZUIZHONGJIANYAN_ID)
|
||
{
|
||
PrdReport prdReport = await db.Queryable<PrdReport>().SingleAsync(x => x.id == QcCheckExecH.report_id);
|
||
decimal pqty = prdReport.reported_qty.Value - rqty;
|
||
if (rqty > Decimal.Parse(QcCheckExecH.checknum))
|
||
{
|
||
throw Oops.Bah("不合格数不能大于抽样数");
|
||
}
|
||
|
||
if (CheckTaskInput.result != "await")
|
||
{
|
||
string isCheck = dic[CheckTaskInput.result].ToString();
|
||
await db.Updateable<WmsCarryH>()
|
||
.SetColumns(x => x.is_check == isCheck)
|
||
.Where(x => x.carry_code == prdReport.material_box_code)
|
||
.ExecuteCommandAsync();
|
||
|
||
await _prdMoTaskService.ReportInstock(new CheckCompleteInput()
|
||
{
|
||
report_id = QcCheckExecH.report_id,
|
||
pqty = pqty,
|
||
rqty = rqty,
|
||
check_result = ((EnumCheckConclusion)dic[CheckTaskInput.result]).ToString(),
|
||
}, prdReport, db);
|
||
}
|
||
}
|
||
else if (QcCheckExecH.checktype == WmsWareHouseConst.XUNJIAN_ID || QcCheckExecH.checktype == WmsWareHouseConst.SHOUJIAN_ID || QcCheckExecH.checktype == WmsWareHouseConst.MOJIAN_ID)
|
||
{
|
||
PrdMoTask prdMoTask = await db.Queryable<PrdMoTask>().Where(x => x.mo_task_code == QcCheckExecH.mo_task_code && x.id != null).FirstAsync();
|
||
if (CheckTaskInput.result == "no")
|
||
{
|
||
string pauseReason = QcCheckExecH.checktype == WmsWareHouseConst.XUNJIAN_ID ? "巡检不合格" : QcCheckExecH.checktype == WmsWareHouseConst.SHOUJIAN_ID ? "首检不合格" : "末检不合格";
|
||
await _prdMoTaskService.PrdTaskRelease2(new PrdTaskReleaseUpInput()
|
||
{
|
||
TaskIds = NPOI.Util.Arrays.AsList(prdMoTask.id),
|
||
Behavior = "Pause",
|
||
PauseReeson = pauseReason
|
||
}, db);
|
||
|
||
#region 没看懂逻辑,暂时注释
|
||
//await _prdMoTaskService.SelfTestScrapped2(new SelfTestScrappedInput()
|
||
//{
|
||
// mo_task_id = prdMoTask.id,
|
||
// scrap_qty = rqty,
|
||
// remark = "抽样不合格报废",
|
||
// categoryItems = new List<SelfTestScrappedInputItem>()
|
||
// {
|
||
// new SelfTestScrappedInputItem()
|
||
// {
|
||
// category_id = "25574005966629",
|
||
// items = new List<defectItem>()
|
||
// {
|
||
// new defectItem()
|
||
// {
|
||
// defective_item = "抽样不合格报废",
|
||
// defective_item_qty = rqty
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//}, db);
|
||
#endregion
|
||
|
||
|
||
#region 记录时间区间内的载具信息
|
||
var prdCarrs = await db.Queryable<PrdReport>().Where(a => a.mo_task_id == prdMoTask.id && a.create_time >= CheckTaskInput.startEndTime[0].TimeStampToDateTime() && a.create_time <= CheckTaskInput.startEndTime[1].TimeStampToDateTime()).ToListAsync();
|
||
var qcCheckExecCarrys = new List<QcCheckExecCarry>();
|
||
foreach (var prdCarr in prdCarrs)
|
||
{
|
||
var wmsCarryH = await db.Queryable<WmsCarryH>().Where(r => r.carry_code == prdCarr.material_box_code).FirstAsync();
|
||
if (wmsCarryH == null)
|
||
continue;
|
||
|
||
WmsCarryCode wmsCarryCode = await db.Queryable<WmsCarryCode>().FirstAsync(x => x.carry_id == wmsCarryH.id);
|
||
BasLocation basLocation = await db.Queryable<BasLocation>().Where(r => r.location_code == wmsCarryH.location_code).FirstAsync();
|
||
//WmsCarryMat wmsCarryMat = await db.Queryable<WmsCarryMat>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||
|
||
var qcCheckExecCarry = new QcCheckExecCarry()
|
||
{
|
||
qc_check_exec_id = QcCheckExecH.id,
|
||
carry_id = wmsCarryH.id,
|
||
carry_code = wmsCarryH.carry_code,
|
||
warehouse_id = basLocation != null ? basLocation.wh_id : "",
|
||
qty = wmsCarryCode != null ? wmsCarryCode.codeqty.ToString() : "",
|
||
status = wmsCarryH.is_check,
|
||
location_id = basLocation != null ? basLocation.id : "",
|
||
location_code = basLocation != null ? basLocation.location_code : "",
|
||
material_id = wmsCarryCode?.material_id,
|
||
reporter_id= prdCarr.create_id,
|
||
processer_id=_userManager.UserId,
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now
|
||
};
|
||
qcCheckExecCarrys.Add(qcCheckExecCarry);
|
||
}
|
||
_ = await db.Insertable(qcCheckExecCarrys).ExecuteCommandAsync();
|
||
#endregion
|
||
|
||
|
||
|
||
//载具需要在中储仓和暂存仓才需要暂控
|
||
List<PrdReport> prdReports = await db.Queryable<PrdReport>().LeftJoin<WmsCarryH>((a, b) => a.material_box_code == b.carry_code).LeftJoin<BasLocation>((a, b, c) => b.location_id == c.id).LeftJoin<BasWarehouse>((a, b, c, d) => c.wh_id == d.id).Where((a, b, c, d) => a.mo_task_id == prdMoTask.id && a.create_time >= CheckTaskInput.startEndTime[0].TimeStampToDateTime() && a.create_time <= CheckTaskInput.startEndTime[1].TimeStampToDateTime() && (c.wh_id == WmsWareHouseConst.WAREHOUSE_ZC_ID || c.wh_id == WmsWareHouseConst.WAREHOUSE_ZCC_ID)).ToListAsync();
|
||
if (prdReports != null)
|
||
{
|
||
var carryCodes = prdReports.Select(r => r.material_box_code).Distinct().ToList();
|
||
if (carryCodes != null && carryCodes.Count > 0)
|
||
{
|
||
await db.Updateable<WmsCarryH>()
|
||
.SetColumns(x => x.is_check == ((int)EnumCheckConclusion.暂控).ToString())
|
||
.SetColumns(x => x.carry_status == "6")//把料架状态改为退料状态,会自动触发把料架上的子载具从二楼暂存仓退回一楼中储仓任务
|
||
.Where(x => carryCodes.Contains(x.carry_code))
|
||
.ExecuteCommandAsync();
|
||
|
||
|
||
|
||
#region 记录暂控处理单主/子表信息
|
||
|
||
if (carryCodes != null && carryCodes.Count > 0)
|
||
{
|
||
|
||
var basMaterial = await db.Queryable<BasMaterial>().Where(r => r.id == prdMoTask.material_id).FirstAsync();
|
||
string outWHid = ""; string inWHid = "";
|
||
if (basMaterial.category_id.Contains("DGJCJ") || basMaterial.category_id.Contains("ZSJ"))
|
||
{
|
||
outWHid = WmsWareHouseConst.WAREHOUSE_ZC_ID;
|
||
inWHid = "中储不合格品仓id";
|
||
}
|
||
else if (basMaterial.category_id.Contains("CGJCJ"))
|
||
{
|
||
outWHid = WmsWareHouseConst.WAREHOUSE_HCC_ID;
|
||
inWHid = "长管不合格品仓id";
|
||
}
|
||
|
||
var carryIds = await db.Queryable<WmsCarryH>().Where(r => carryCodes.Contains(r.carry_code)).Select(r => r.id).ToListAsync();
|
||
var wmsCarryCodes = await db.Queryable<WmsCarryCode>().Where(r => carryIds.Contains(r.carry_id) && r.material_id == QcCheckExecH.materialid).ToListAsync();
|
||
var codeQty = wmsCarryCodes == null ? 0 : wmsCarryCodes.Sum(r => r.codeqty);
|
||
var qcTempControlH = new QcTempControlH()
|
||
{
|
||
id = SnowflakeIdHelper.NextId(),
|
||
bill_code = await _billRullService.GetBillNumber(CodeTemplateConst.QCCONTROLTEMP_CODE),
|
||
source_code = QcCheckExecH.bill_code,
|
||
pro_task_code = QcCheckExecH.mo_task_code,
|
||
out_warehouse_id = outWHid,
|
||
in_warehouse_id = inWHid,
|
||
material_id = QcCheckExecH.materialid,
|
||
material_code = basMaterial.code,
|
||
control_lx_qty = carryCodes.Count.ToString(),
|
||
control_qty = codeQty.ToString(),
|
||
result = "暂控",
|
||
loger_id = _userManager.UserId,
|
||
confirmer_id = "",
|
||
status = ((int)EnumTempControlStatus.待确认).ToString(),
|
||
called_box_qty = "0",
|
||
called_qty = "0",
|
||
leave_call_box_qty = carryCodes.Count.ToString(),
|
||
leave_call_qty = codeQty.ToString(),
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
};
|
||
|
||
await db.Insertable(qcTempControlH).ExecuteCommandAsync();
|
||
|
||
var qcTempControlDs = new List<QcTempControlD>();
|
||
foreach (var carryCode in carryCodes)
|
||
{
|
||
var wmsCarryH = await db.Queryable<WmsCarryH>().Where(r => r.carry_code == carryCode).FirstAsync();
|
||
if (wmsCarryH == null)
|
||
continue;
|
||
|
||
WmsCarryCode wmsCarryCode = await db.Queryable<WmsCarryCode>().FirstAsync(x => x.carry_id == wmsCarryH.id);
|
||
BasLocation basLocation = await db.Queryable<BasLocation>().Where(r => r.location_code == wmsCarryH.location_code).FirstAsync();
|
||
if (basLocation == null)
|
||
throw Oops.Bah($"未找到编号为{wmsCarryH.location_code}的库位");
|
||
WmsCarryMat wmsCarryMat = await db.Queryable<WmsCarryMat>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||
BasWarehouse basWarehouse = await db.Queryable<BasWarehouse>().Where(r => r.id == basLocation.wh_id).FirstAsync();
|
||
var _prdReports = prdReports.Where(r => r.material_box_code == carryCode).First();
|
||
var qcTempConD = new QcTempControlD()
|
||
{
|
||
bill_id = qcTempControlH.id,
|
||
carry_id = wmsCarryH.id,
|
||
carry_code = carryCode,
|
||
warehouse_id = basLocation?.wh_id,
|
||
warehouse_code = basWarehouse.whcode,
|
||
location_code = basLocation?.location_code,
|
||
location_id = basLocation?.id,
|
||
qty = wmsCarryCode?.codeqty.ToString(),
|
||
submiter = _prdReports == null ? null : _prdReports.create_id,
|
||
maker_id = "",
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
check_status = "暂控",
|
||
call_status = "未呼叫"
|
||
};
|
||
qcTempControlDs.Add(qcTempConD);
|
||
}
|
||
await db.Insertable(qcTempControlDs).ExecuteCommandAsync();
|
||
}
|
||
#endregion
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//末检自动完工
|
||
if (QcCheckExecH.checktype == WmsWareHouseConst.MOJIAN_ID)
|
||
{
|
||
await _prdMoTaskService.PrdTaskRelease2(new PrdTaskReleaseUpInput()
|
||
{
|
||
TaskIds = NPOI.Util.Arrays.AsList(prdMoTask.id),
|
||
Behavior = "Compled",
|
||
}, db);
|
||
}
|
||
}
|
||
}
|
||
|
||
await db.Ado.CommitTranAsync();
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
await db.Ado.RollbackTranAsync();
|
||
JNPF.Logging.Log.Error(e.Message, e);
|
||
throw Oops.Oh("执行失败:" + e.Message);
|
||
}
|
||
finally
|
||
{
|
||
prdreportSemaphore.Release();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取任务结果明细
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<dynamic> GetTaskResult(string id)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
QcCheckExecH QcCheckExecH = await db.Queryable<QcCheckExecH>().Where(p => p.id == id).FirstAsync();
|
||
List<QcCheckExecD> QcCheckExecDs = await db.Queryable<QcCheckExecD>().Where(p => p.mainid == id).ToListAsync();
|
||
List<QcCheckItem> QcCheckItems = await db.Queryable<QcCheckItem>().ToListAsync();
|
||
List<QcCheckType> QcCheckTypes = await db.Queryable<QcCheckType>().ToListAsync();
|
||
List<QcErrorCause> QcErrorCauses = await db.Queryable<QcErrorCause>().ToListAsync();
|
||
List<QcErrorLevel> QcErrorLevels = await db.Queryable<QcErrorLevel>().ToListAsync();
|
||
|
||
Result 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)
|
||
.LeftJoin<PrdReport>((a, b, c, d, e, f) => a.report_id == f.id)
|
||
.LeftJoin<PrdMoTask>((a, b, c, d, e, f, g) => a.mo_task_code == g.mo_task_code)
|
||
.LeftJoin<EqpEquipment>((a, b, c, d, e, f, g, h) => g.eqp_id == h.id)
|
||
.Where((a, b, c, d, e) => a.id==id)
|
||
.Select((a, b, c, d, e, f, g, h) => new Result
|
||
{
|
||
mainid = a.id,
|
||
bill_code = a.bill_code,
|
||
material_name = b.name,
|
||
material_code = b.code,
|
||
material_standard = b.material_standard,
|
||
material_specification = b.material_specification,
|
||
checknum = a.checknum,
|
||
status = a.status,
|
||
result = a.result,
|
||
exectime = a.exectime ?? "",
|
||
execuser = e.RealName ?? "",
|
||
mo_task_code = a.mo_task_code,
|
||
batch = a.batch,
|
||
qty = a.qty,
|
||
equip_name = h.name,
|
||
checktypes = new List<List<Checktype>>(),
|
||
attachment = a.attachment,
|
||
}).FirstAsync();
|
||
Result.checktypes = new List<List<Checktype>>();
|
||
|
||
var qcCheckExecCarrys = await db.Queryable<QcCheckExecCarry>().Where(r => r.qc_check_exec_id == QcCheckExecH.id).ToListAsync();
|
||
if (qcCheckExecCarrys != null && qcCheckExecCarrys.Count > 0)
|
||
{
|
||
var checkCarrys = new List<CheckCarry>();
|
||
foreach (var acec in qcCheckExecCarrys)
|
||
{
|
||
WmsCarryH carryH = await db.Queryable<WmsCarryH>().FirstAsync(x => x.id == acec.carry_id);
|
||
BasMaterial basMaterial = await db.Queryable<BasMaterial>().SingleAsync(x => x.id == acec.material_id);
|
||
var carry = new CheckCarry()
|
||
{
|
||
carry_name = carryH.carry_name,
|
||
location_id = acec.location_id,
|
||
location_code = acec.location_code,
|
||
material_name = basMaterial?.name,
|
||
qty = string.IsNullOrEmpty(acec.qty) ? 0 : Convert.ToDecimal(acec.qty),
|
||
is_check = acec.status
|
||
};
|
||
checkCarrys.Add(carry);
|
||
}
|
||
Result.carryInfo = checkCarrys;
|
||
}
|
||
//if (!string.IsNullOrEmpty(QcCheckExecH.carry_code))
|
||
//{
|
||
// WmsCarryH carryH = await db.Queryable<WmsCarryH>().FirstAsync(x => x.carry_code == QcCheckExecH.carry_code);
|
||
// WmsCarryCode carryCode = await db.Queryable<WmsCarryCode>().FirstAsync(x => x.carry_id == carryH.id);
|
||
// string materialId = carryCode?.id ?? "";
|
||
// BasMaterial basMaterial = await db.Queryable<BasMaterial>().SingleAsync(x => x.id == materialId);
|
||
// Result.carryInfo = new CheckCarry()
|
||
// {
|
||
// carry_name = carryH.carry_name,
|
||
// location_id = carryH.location_id,
|
||
// location_code = carryH.location_code,
|
||
// material_name = basMaterial?.name,
|
||
// qty = carryCode?.codeqty ?? 0,
|
||
// };
|
||
//}
|
||
List<string?> groupkeys = QcCheckExecDs.Select(p => p.checkindex).Distinct().ToList();
|
||
foreach (string? key in groupkeys)
|
||
{
|
||
List<QcCheckExecD> QcCheckExecDsbykey = QcCheckExecDs.Where(p => p.checkindex == key).ToList();
|
||
List<Checktype> checktype = new();
|
||
foreach (QcCheckExecD? QcCheckExecD in QcCheckExecDsbykey)
|
||
{
|
||
if (checktype.Where(p => p.checktypeid == QcCheckExecD.typeid).ToList().Count == 0)
|
||
{
|
||
Checktype checkType = new()
|
||
{
|
||
checktypeid = QcCheckExecD.typeid!,
|
||
checktypename = QcCheckTypes.Where(p => p.id == QcCheckExecD.typeid).First().name!,
|
||
items = new List<ExecItem>()
|
||
};
|
||
checktype.Add(checkType);
|
||
}
|
||
ExecItem Item = new()
|
||
{
|
||
itemid = QcCheckExecD.itemid!,
|
||
itemdid = QcCheckExecD.id!,
|
||
code = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().code!,
|
||
name = QcCheckItems.Where(p => p.id == QcCheckExecD.itemid).First().name!,
|
||
result = QcCheckExecD.result,
|
||
setData = new ExecItemData
|
||
{
|
||
extype = QcCheckExecD.extype!,
|
||
excontent = JSON.Deserialize<Excontent>(QcCheckExecD.excontent!),
|
||
check = QcCheckExecD.check!
|
||
}
|
||
};
|
||
if (!string.IsNullOrEmpty(QcCheckExecD.errorcause))
|
||
{
|
||
string[] strs = QcCheckExecD.errorcause!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||
Item.setData.errorcause = new List<Error>();
|
||
foreach (string 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))
|
||
{
|
||
string[] strs = QcCheckExecD.errorlevel!.Replace("[", "").Replace("]", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||
Item.setData.errorlevel = new List<Error>();
|
||
foreach (string 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
|
||
{
|
||
extype = !string.IsNullOrEmpty(Item.setData.extype),
|
||
excontent = !string.IsNullOrEmpty(QcCheckExecD.excontent),
|
||
check = !string.IsNullOrEmpty(Item.setData.check),
|
||
errorcause = (Item.setData.errorcause?.Count) != 0,
|
||
errorlevel = (Item.setData.errorlevel?.Count) != 0,
|
||
remark = !string.IsNullOrEmpty(Item.setData.remark),
|
||
attachment = !string.IsNullOrEmpty(Item.setData.attachment),
|
||
customer = !string.IsNullOrEmpty(Item.setData.customer),
|
||
isexec = Item.setData.isexec != null
|
||
};
|
||
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;
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task CreateTaskData(CheckTaskData checkTaskData)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
DictionaryTypeEntity DictionaryType = await db.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
|
||
DictionaryDataEntity DictionaryData = await db.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
|
||
QcCheckExecH QcCheckExecH = new()
|
||
{
|
||
checktype = checkTaskData.checktype,
|
||
materialid = checkTaskData.materialid,
|
||
processid = checkTaskData.processid,
|
||
workid = checkTaskData.workid,
|
||
wareid = checkTaskData.wareid,
|
||
status = DictionaryData.Id,
|
||
tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now
|
||
};
|
||
List<QcCheckExecD> QcCheckExecDs = new();
|
||
if (checkTaskData.checktypes != null)
|
||
{
|
||
foreach (CheckTaskDataInput checktype in checkTaskData.checktypes)
|
||
{
|
||
if (checktype.items != null)
|
||
{
|
||
foreach (TaskItemInput item in checktype.items)
|
||
{
|
||
QcCheckExecD QcCheckExecD = new()
|
||
{
|
||
mainid = QcCheckExecH.id,
|
||
typeid = checktype.id,
|
||
itemid = item.itemid,
|
||
extype = item.extype,
|
||
excontent = item.excontent,
|
||
check = item.check,
|
||
errorcause = item.errorcause?.Replace("\"", "").Trim(),
|
||
errorlevel = item.errorlevel?.Replace("\"", "").Trim(),
|
||
remark = item.remark,
|
||
attachment = item.attachment,
|
||
isexec = item.isexec,
|
||
custom = item.customer,
|
||
create_id = _userManager.UserId,
|
||
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();
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|