673 lines
34 KiB
C#
673 lines
34 KiB
C#
using JNPF.Common.Enums;
|
|
using JNPF.Common.Extension;
|
|
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.Entitys.System;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.PerMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
using Tnb.ProductionMgr.Entities.Entity;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
using Tnb.ProductionMgr.Entities.Dto;
|
|
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
/// <summary>
|
|
/// 组装、包装生产提报服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
|
|
public class PrdPackReportService : IPrdPackReportService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
private static Dictionary<string, Tuple<string, string>> _dicWorkLine = new();
|
|
public PrdPackReportService(ISqlSugarRepository<PrdMoTask> repository, IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_dictionaryDataService = dictionaryDataService;
|
|
}
|
|
/// <summary>
|
|
/// 获取组装包装生产任务记录,树形结构
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetList(PrdPackReportQueryInput input)
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException("input");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(input.stationId))
|
|
{
|
|
return new
|
|
{
|
|
pagination = new PageResult(),
|
|
list = Array.Empty<string>()
|
|
};
|
|
}
|
|
|
|
List<PackReportTreeOutput> trees = new();
|
|
Dictionary<string, object> dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
|
|
List<OrganizeEntity> list = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workline").ToListAsync();
|
|
if (_dicWorkLine.Count < 1)
|
|
{
|
|
|
|
_dicWorkLine = list.ToDictionary(x => x.Id, x => Tuple.Create<string, string>(x.EnCode, x.FullName));
|
|
}
|
|
bool start = false;
|
|
bool end = false;
|
|
DateTime[] startTimes = new DateTime[2];
|
|
DateTime[] endTimes = new DateTime[2];
|
|
if (input.estimated_start_date != null && input.estimated_start_date.Count() == 2)
|
|
{
|
|
start = true;
|
|
startTimes[0] = GetDateTimeMilliseconds(input.estimated_start_date![0]);
|
|
startTimes[1] = GetDateTimeMilliseconds(input.estimated_start_date![1]);
|
|
|
|
}
|
|
if (input.estimated_end_date != null && input.estimated_end_date.Count() == 2)
|
|
{
|
|
end = true;
|
|
endTimes[0] = GetDateTimeMilliseconds(input.estimated_end_date![0]);
|
|
endTimes[1] = GetDateTimeMilliseconds(input.estimated_end_date![1]);
|
|
|
|
}
|
|
SqlSugarPagedList<PrdMoTask> items = await _db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasProcess>((a, b) => a.process_id == b.id)
|
|
.LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
|
|
.LeftJoin<PrdMoTask>((a, b, c, d) => a.id == d.parent_id)
|
|
.WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code.Trim())
|
|
// .WhereIF(start, a => a.estimated_start_date != null&& startTimes[0] <= a.estimated_start_date && startTimes[1] >= a.estimated_start_date)
|
|
// .WhereIF(end, a => a.estimated_end_date != null && endTimes[0] <= a.estimated_end_date && endTimes[1] >= a.estimated_end_date)
|
|
.WhereIF(!string.IsNullOrEmpty(input.workline), a => list.Where(p => p.EnCode.Contains(input.workline) || p.FullName.Contains(input.workline)).Select(p => p.Id).ToList().Contains(a.workline_id!))
|
|
.Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled")
|
|
.Where((a, b, c, d) => d.workstation_id == input.stationId)
|
|
.OrderByDescending(a => a.create_time)
|
|
.Select((a, b, c) => new PrdMoTask
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
workline_id = a.workline_id,
|
|
process_id = a.process_id,
|
|
plan_start_date = a.estimated_start_date,
|
|
plan_end_date = a.estimated_end_date,
|
|
plan_qty = a.scheduled_qty,
|
|
// complete_qty = SqlFunc.Subqueryable<PrdReport>().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty),
|
|
complete_qty = a.last_process_complete_qty,
|
|
mo_task_status = a.mo_task_status,
|
|
|
|
})
|
|
.ToPagedListAsync(input.currentPage, input.pageSize);
|
|
if (start)
|
|
{
|
|
items.list = items.list.Where(a => startTimes[0] <= a.plan_start_date && startTimes[1] >= a.plan_start_date).ToList();
|
|
}
|
|
|
|
if (end)
|
|
{
|
|
items.list = items.list.Where(a => endTimes[0] <= a.plan_end_date && endTimes[1] >= a.plan_end_date).ToList();
|
|
}
|
|
|
|
_db.ThenMapper(items.list, it =>
|
|
{
|
|
it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
|
|
});
|
|
|
|
if (items != null && items.list != null && items.list.Any())
|
|
{
|
|
foreach (PrdMoTask? item in items.list)
|
|
{
|
|
PackReportTreeOutput node = item.Adapt<PackReportTreeOutput>();
|
|
node.parentId = "0";
|
|
if (item.workline_id.IsNotEmptyOrNull())
|
|
{
|
|
Tuple<string, string>? workLine = _dicWorkLine.ContainsKey(item.workline_id) ? _dicWorkLine[item.workline_id] : null;
|
|
if (workLine != null)
|
|
{
|
|
node.workline_id = $"{workLine.Item1}/{workLine.Item2}";
|
|
}
|
|
}
|
|
node.plan_start_date = item.plan_start_date.HasValue ? item.plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
|
node.plan_end_date = item.plan_end_date.HasValue ? item.plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
|
await GetChild(item.id, trees, dic, input.stationId);
|
|
trees.Add(node);
|
|
}
|
|
}
|
|
List<PackReportTreeOutput> treeList = trees.ToTree();
|
|
if (!string.IsNullOrEmpty(input.process))
|
|
{
|
|
List<PackReportTreeOutput> removelist = new();
|
|
foreach (PackReportTreeOutput item in treeList)
|
|
{
|
|
bool flag = false;
|
|
if (item.process_id != null && item.process_id.Contains(input.process))
|
|
{
|
|
flag = true;
|
|
}
|
|
|
|
if (item.children != null && item.children.Count > 0)
|
|
{
|
|
List<PackReportTreeOutput> childs = item.children.Adapt<List<PackReportTreeOutput>>();
|
|
if (childs.Where(p => p.process_id.Contains(input.process)).Any())
|
|
{
|
|
flag = true;
|
|
}
|
|
}
|
|
if (!flag)
|
|
{
|
|
removelist.Add(item);
|
|
}
|
|
}
|
|
removelist.ForEach(p => treeList.Remove(p));
|
|
|
|
}
|
|
SqlSugarPagedList<PackReportTreeOutput> pagedList = new()
|
|
{
|
|
list = treeList,
|
|
pagination = new Pagination
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = treeList.Count
|
|
}
|
|
};
|
|
return PageResult<PackReportTreeOutput>.SqlSugarPageResult(pagedList);
|
|
}
|
|
private static DateTime GetDateTimeMilliseconds(long timestamp)
|
|
{
|
|
long begtime = timestamp * 10000;
|
|
DateTime dt_1970 = new(1970, 1, 1, 8, 0, 0);
|
|
long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
|
|
long time_tricks = tricks_1970 + begtime;//日志日期刻度
|
|
DateTime dt = new(time_tricks);//转化为DateTime
|
|
return dt;
|
|
|
|
}
|
|
private async Task GetChild(string parentId, List<PackReportTreeOutput> nodes, Dictionary<string, object> dic, string stationId)
|
|
{
|
|
List<PrdMoTask> items = await _db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasProcess>((a, b) => a.process_id == b.id)
|
|
.LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
|
|
.LeftJoin<BasMbomProcess>((a, b, c, d) => a.mbom_process_id == d.id)
|
|
.Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled" && a.workstation_id == stationId)
|
|
.OrderBy((a, b, c, d) => d.ordinal)
|
|
.Select((a, b, c) => new PrdMoTask
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
workline_id = a.workline_id,
|
|
process_id = a.process_id,
|
|
process_code = b.process_code,
|
|
process_name = b.process_name,
|
|
plan_start_date = a.estimated_start_date,
|
|
plan_end_date = a.estimated_end_date,
|
|
plan_qty = a.scheduled_qty,
|
|
//complete_qty = SqlFunc.Subqueryable<PrdReport>().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty),
|
|
complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0),
|
|
mo_task_status = a.mo_task_status,
|
|
|
|
}).ToListAsync();
|
|
_db.ThenMapper(items, it =>
|
|
{
|
|
it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
|
|
});
|
|
|
|
if (items?.Count > 0)
|
|
{
|
|
List<PackReportTreeOutput> nsChild = items.Adapt<List<PackReportTreeOutput>>();
|
|
for (int i = 0; i < nsChild.Count; i++)
|
|
{
|
|
nsChild[i].parentId = parentId;
|
|
nsChild[i].process_id = $"{items[i].process_code}/{items[i].process_name}";
|
|
nsChild[i].plan_start_date = items[i].plan_start_date.HasValue ? items[i].plan_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
|
nsChild[i].plan_end_date = items[i].plan_end_date.HasValue ? items[i].plan_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
|
|
|
if (nsChild[i].workline_id.IsNotEmptyOrNull())
|
|
{
|
|
Tuple<string, string>? workLine = _dicWorkLine.ContainsKey(nsChild[i].workline_id) ? _dicWorkLine[nsChild[i].workline_id] : null;
|
|
if (workLine != null)
|
|
{
|
|
nsChild[i].workline_id = $"{workLine.Item1}/{workLine.Item2}";
|
|
}
|
|
}
|
|
}
|
|
|
|
nodes.AddRange(nsChild);
|
|
foreach (PrdMoTask? item in items)
|
|
{
|
|
await GetChild(item.id, nodes, dic, stationId);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// pda端根据工位获取注塑挤出列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetInjectionMoldingList(PrdPackReportQueryInput input)
|
|
{
|
|
if (string.IsNullOrEmpty(input.stationId))
|
|
{
|
|
return new
|
|
{
|
|
pagination = new PageResult(),
|
|
list = Array.Empty<string>()
|
|
};
|
|
}
|
|
|
|
SqlSugarPagedList<PADPackageTaskPageOutput> result = await _db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.LeftJoin<BasProcess>((a, b, c) => a.process_id == c.id)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode)
|
|
.LeftJoin<EqpEquipment>((a, b, c, e, f) => a.eqp_id == f.id)
|
|
.LeftJoin<ToolMolds>((a, b, c, e, f, g) => a.mold_id == g.id)
|
|
.Where((a, b) => a.workstation_id == input.stationId && a.mo_task_status != DictConst.ToBeScheduledEncode && a.schedule_type == 1)
|
|
.OrderByDescending((a, b) => a.create_time)
|
|
.Select((a, b, c, e, f, g) => new PADPackageTaskPageOutput
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
mo_id = a.mo_id,
|
|
material_id = a.material_id,
|
|
material_code = b.code,
|
|
material_name = b.name,
|
|
workline_id = a.workline_id,
|
|
// workline_name = d.FullName,
|
|
bom_id = a.bom_id,
|
|
mo_task_status = e.FullName,
|
|
complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0),
|
|
scrap_qty = a.scrap_qty,
|
|
scheduled_qty = a.scheduled_qty,
|
|
reported_work_qty = a.reported_work_qty,
|
|
estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS),
|
|
estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS),
|
|
parent_id = a.parent_id,
|
|
process_id = a.process_id,
|
|
process_name = c.process_name,
|
|
mbom_process_id = a.mbom_process_id,
|
|
equip_id = a.eqp_id,
|
|
equip_code = f.code,
|
|
equip_name = f.name,
|
|
mold_id = a.mold_id,
|
|
mold_code = g.mold_code,
|
|
mold_name = g.mold_name,
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<PADPackageTaskPageOutput>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// pda端根据工位获取组装包装列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetPadList(PrdPackReportQueryInput input)
|
|
{
|
|
if (string.IsNullOrEmpty(input.stationId))
|
|
{
|
|
return new
|
|
{
|
|
pagination = new PageResult(),
|
|
list = Array.Empty<string>()
|
|
};
|
|
}
|
|
|
|
SqlSugarPagedList<PADPackageTaskPageOutput> result = await _db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.LeftJoin<BasProcess>((a, b, c) => a.process_id == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => a.workline_id == d.Id)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode)
|
|
.Where((a, b) => a.workstation_id == input.stationId && a.mo_task_status != DictConst.ToBeScheduledEncode && a.schedule_type == 2)
|
|
.OrderByDescending((a, b) => a.create_time)
|
|
.Select((a, b, c, d, e) => new PADPackageTaskPageOutput
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
mo_id = a.mo_id,
|
|
material_id = a.material_id,
|
|
material_code = b.code,
|
|
material_name = b.name,
|
|
workline_id = a.workline_id,
|
|
workline_name = d.FullName,
|
|
bom_id = a.bom_id,
|
|
mo_task_status = e.FullName,
|
|
complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0),
|
|
scrap_qty = a.scrap_qty,
|
|
scheduled_qty = a.scheduled_qty,
|
|
reported_work_qty = a.reported_work_qty,
|
|
estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS),
|
|
estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS),
|
|
parent_id = a.parent_id,
|
|
process_id = a.process_id,
|
|
process_name = c.process_name,
|
|
mbom_process_id = a.mbom_process_id,
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<PADPackageTaskPageOutput>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// pda端根据工位获取任务单列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetPadPrdMoTaskList(PrdMoTaskListOutput input)
|
|
{
|
|
if (string.IsNullOrEmpty(input.stationId))
|
|
{
|
|
return new
|
|
{
|
|
pagination = new PageResult(),
|
|
list = Array.Empty<string>()
|
|
};
|
|
}
|
|
|
|
Dictionary<string, object> queryJson = string.IsNullOrEmpty(input.queryJson) ? new Dictionary<string, object>() : input.queryJson.ToObject<Dictionary<string, object>>();
|
|
string? mo_task_code = queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : "";
|
|
string? status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : "";
|
|
DateTime? start_time = queryJson.ContainsKey("start_time") ? queryJson["start_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["start_time"]) : null;
|
|
DateTime? end_time = queryJson.ContainsKey("end_time") ? queryJson["end_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["end_time"]) : null;
|
|
List<string> statusList = new();
|
|
if (!string.IsNullOrEmpty(status))
|
|
{
|
|
switch (status)
|
|
{
|
|
case "1":
|
|
statusList.Add(DictConst.InProgressEnCode);
|
|
statusList.Add(DictConst.MoStatusPauseCode);
|
|
break;
|
|
case "2":
|
|
statusList.Add(DictConst.ToBeScheduledEncode);
|
|
statusList.Add(DictConst.ToBeStartedEnCode);
|
|
break;
|
|
case "3":
|
|
statusList.Add(DictConst.ComplatedEnCode);
|
|
statusList.Add(DictConst.ClosedEnCode);
|
|
break;
|
|
}
|
|
}
|
|
// string mo_task_status = queryJson.ContainsKey("mo_task_status") ? queryJson["mo_task_status"].ToString() : "";
|
|
if (string.IsNullOrEmpty(input.sidx))
|
|
{
|
|
input.sidx = "create_time";
|
|
input.sort = "desc";
|
|
}
|
|
|
|
SqlSugarPagedList<PADPackageTaskPageOutput> result = await _db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.LeftJoin<BasProcess>((a, b, c) => a.process_id == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => a.workline_id == d.Id)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode)
|
|
.LeftJoin<EqpEquipment>((a, b, c, d, e, f) => a.eqp_id == f.id)
|
|
.LeftJoin<ToolMolds>((a, b, c, d, e, f, g) => a.mold_id == g.id)
|
|
.LeftJoin<PerProcessStandardsH>((a, b, c, d, e, f, g, h) => a.material_id == h.output_material_id && a.eqp_id == h.equip_id && a.mold_id == h.molds_id && h.enabled == 1)
|
|
.LeftJoin<BasStandardTime>((a, b, c, d, e, f, g, h, i) => a.process_id == i.process_id && i.enabled == 1 && a.schedule_type==1)
|
|
.LeftJoin<PrdMo>((a, b, c, d, e, f, g, h, i, j) => a.mo_id == j.id)
|
|
.LeftJoin<BasMaterialUnit>((a, b, c, d, e, f, g, h, i, j, k) => a.material_id == k.material_id && k.auxiliary_unit_id == "kg")
|
|
.LeftJoin<EqpDaq>((a, b, c, d, e, f, g, h, i, j, k, l) => a.eqp_id == l.equip_id && l.enabled == 1 && l.label_name.Contains("允许称重"))//注塑空满箱请求
|
|
.Where((a, b) => a.workstation_id == input.stationId)
|
|
.WhereIF(!string.IsNullOrEmpty(mo_task_code), a => a.mo_task_code.Contains(mo_task_code))
|
|
//.WhereIF(!string.IsNullOrEmpty(mo_task_status),a=>a.mo_task_status==mo_task_status)
|
|
.WhereIF(statusList.Count > 0, a => statusList.Contains(a.mo_task_status))
|
|
.WhereIF(status == "3" && start_time != null, a => a.act_end_date >= start_time)
|
|
.WhereIF(status == "3" && end_time != null, a => a.act_end_date <= end_time)
|
|
.Select((a, b, c, d, e, f, g, h, i, j, k, l) => new PADPackageTaskPageOutput
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
mo_id = a.mo_id,
|
|
mo_code = j.mo_code,
|
|
material_id = a.material_id,
|
|
material_code = b.code,
|
|
material_name = b.name,
|
|
material_standard = b.material_standard,
|
|
container_no = b.container_no,
|
|
di = b.di,
|
|
workline_id = a.workline_id,
|
|
workline_name = d.FullName,
|
|
bom_id = a.bom_id,
|
|
mo_task_status = e.FullName,
|
|
complete_qty = SqlFunc.IsNull(a.reported_work_qty, 0) + SqlFunc.IsNull(a.scrap_qty, 0),
|
|
scrap_qty = a.scrap_qty,
|
|
scheduled_qty = a.scheduled_qty,
|
|
reported_work_qty = a.reported_work_qty,
|
|
estimated_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString(DbTimeFormat.SS),
|
|
estimated_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString(DbTimeFormat.SS),
|
|
parent_id = a.parent_id,
|
|
process_id = a.process_id,
|
|
process_name = c.process_name,
|
|
mbom_process_id = a.mbom_process_id,
|
|
create_time = a.create_time,
|
|
equip_id = a.eqp_id,
|
|
equip_code = f.code,
|
|
equip_name = f.name,
|
|
mold_id = a.mold_id,
|
|
mold_code = g.mold_code,
|
|
mold_name = g.mold_name,
|
|
schedule_type = a.schedule_type,
|
|
mold_cavity = g.mold_cavity,
|
|
moulding_cycle = h.moulding_cycle,
|
|
standard_time = i.standard_time,
|
|
act_start_date = a.act_start_date == null ? "" : a.act_start_date.Value.ToString(DbTimeFormat.SS),
|
|
act_end_date = a.act_end_date == null ? "" : a.act_end_date.Value.ToString(DbTimeFormat.SS),
|
|
plan_end_date = a.plan_end_date == null ? "" : a.plan_end_date.Value.ToString(DbTimeFormat.SS),
|
|
minpacking = b.minpacking,
|
|
main_num = k.number_of_primary_unit,
|
|
deputy_num = k.number_of_auxiliary_unit,
|
|
third_equip_code = f.code,
|
|
weight_name = l.label_point,
|
|
category_id = b.category_id,
|
|
as_location_id = f.as_location_id,
|
|
upmat_location_id = f.upmat_location_id,
|
|
downmat_location_id = f.as_location_id,
|
|
instock_warehouse_id = f.as_location_id,
|
|
})
|
|
.MergeTable()
|
|
.OrderBy($"{input.sidx} {input.sort}")
|
|
.ToPagedListAsync(input.currentPage, input.pageSize);
|
|
if (!result.list.IsEmpty())
|
|
{
|
|
foreach (var item in result.list)
|
|
{
|
|
if (item.as_location_id!=null && !item.as_location_id.IsEmpty())
|
|
{
|
|
BasLocation basLocation = await _db.Queryable<BasLocation>().SingleAsync(x => x.id == item.as_location_id);
|
|
item.as_location_code = basLocation.location_code;
|
|
}
|
|
if (item.upmat_location_id!=null && !item.upmat_location_id.IsEmpty())
|
|
{
|
|
BasLocation basLocation = await _db.Queryable<BasLocation>().SingleAsync(x => x.id == item.upmat_location_id);
|
|
item.upmat_location_code = basLocation.location_code;
|
|
}
|
|
if (item.downmat_location_id!=null && !item.downmat_location_id.IsEmpty())
|
|
{
|
|
BasLocation basLocation = await _db.Queryable<BasLocation>().SingleAsync(x => x.id == item.downmat_location_id);
|
|
item.downmat_location_code = basLocation.location_code;
|
|
}
|
|
|
|
if (item.schedule_type == 2)
|
|
{
|
|
PerProcessStandardsH processStandardsH = await _db.Queryable<PerProcessStandardsH>()
|
|
.Where(x => x.equip_id == item.equip_id && x.molds_id == item.mold_id &&
|
|
x.output_material_id == item.material_id && x.enabled == 1)
|
|
.OrderByDescending(x => x.create_time).FirstAsync();
|
|
item.standard_time = processStandardsH?.moulding_cycle?.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
return PageResult<PADPackageTaskPageOutput>.SqlSugarPageResult(result);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上模校验
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> CheckMold(CheckMoldInput input)
|
|
{
|
|
PrdMoTask prdMoTask = await _db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
|
|
BasQrcode basQrcode = await _db.Queryable<BasQrcode>().Where(x => x.source_name == "TOOL_MOLDS" && x.code == input.mold_qrcode).FirstAsync();
|
|
return prdMoTask != null && basQrcode != null ? prdMoTask.mold_id == basQrcode.source_id : (dynamic)false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 外包装喷码校验
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<dynamic> OutPackMarkCheck(MarkingLabelInput input)
|
|
{
|
|
string[] arr = input.mark_code.Split("(10)");
|
|
if (arr.Length > 1)
|
|
{
|
|
string batch = arr[1];
|
|
PrdMoTask prdMoTask = await _db.Queryable<PrdMoTask>().Where(x => x.batch == batch).FirstAsync();
|
|
string mo_task_code = prdMoTask.mo_task_code;
|
|
if (prdMoTask == null) throw Oops.Bah("未找到对应任务单");
|
|
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().Where(x => x.id == prdMoTask.material_id).FirstAsync();
|
|
DictionaryDataEntity unit = await _db.Queryable<DictionaryTypeEntity>()
|
|
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
|
.Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == basMaterial.unit_id)
|
|
.Select((x, y) => y).FirstAsync();
|
|
PrdOutPackMarkLabel prdOutPackMarkLabel = await _db.Queryable<PrdOutPackMarkLabel>().Where(x=>x.mo_task_code==mo_task_code && x.status=="0" && x.is_mark==0).OrderByDescending(x=>x.create_time).FirstAsync();
|
|
if (prdOutPackMarkLabel != null)
|
|
{
|
|
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
|
|
{
|
|
|
|
if (prdOutPackMarkLabel.is_label == 1)
|
|
{
|
|
PrdReport prdReport = new PrdReport()
|
|
{
|
|
mo_task_id = prdMoTask.id,
|
|
mo_task_code = prdMoTask.mo_task_code,
|
|
create_id = DictConst.DEFAULTUSERID,
|
|
create_time = DateTime.Now,
|
|
reported_qty = 1,
|
|
unit_id = unit?.Id ?? "",
|
|
barcode = mo_task_code + DateTimeOffset.Now.ToUnixTimeSeconds().ToString(),
|
|
equip_id = prdMoTask.eqp_id,
|
|
mbom_process_id = prdMoTask.mbom_process_id,
|
|
station = prdMoTask.workstation_id,
|
|
status=0,
|
|
material_id = prdMoTask.material_id,
|
|
process_id = prdMoTask.process_id,
|
|
};
|
|
|
|
await _db.Updateable<PrdOutPackMarkLabel>()
|
|
.SetColumns(x=>x.is_mark==1)
|
|
.SetColumns(x=>x.status=="1")
|
|
.SetColumns(x=>x.report_id==prdReport.id)
|
|
.ExecuteCommandAsync();
|
|
|
|
await _db.Insertable<PrdReport>(prdReport).ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
await _db.Updateable<PrdOutPackMarkLabel>().SetColumns(x=>x.is_mark==1).ExecuteCommandAsync();
|
|
}
|
|
});
|
|
|
|
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "校验成功" : result.ErrorMessage;
|
|
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("校验失败");
|
|
}
|
|
}
|
|
|
|
throw Oops.Bah("校验失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 外包装贴标校验
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<dynamic> OutPackLabelCheck(MarkingLabelInput input)
|
|
{
|
|
string[] arr = input.label_code.Split("(10)");
|
|
if (arr.Length > 1)
|
|
{
|
|
string batch = arr[1];
|
|
PrdMoTask prdMoTask = await _db.Queryable<PrdMoTask>().Where(x => x.batch == batch).FirstAsync();
|
|
string mo_task_code = prdMoTask.mo_task_code;
|
|
if (prdMoTask == null) throw Oops.Bah("未找到对应任务单");
|
|
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().Where(x => x.id == prdMoTask.material_id).FirstAsync();
|
|
DictionaryDataEntity unit = await _db.Queryable<DictionaryTypeEntity>()
|
|
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
|
.Where((x, y) => x.EnCode == DictConst.MeasurementUnit && y.EnCode == basMaterial.unit_id)
|
|
.Select((x, y) => y).FirstAsync();
|
|
PrdOutPackMarkLabel prdOutPackMarkLabel = await _db.Queryable<PrdOutPackMarkLabel>().Where(x=>x.mo_task_code==mo_task_code && x.status=="0" && x.is_label==0).OrderByDescending(x=>x.create_time).FirstAsync();
|
|
if (prdOutPackMarkLabel != null)
|
|
{
|
|
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
|
|
{
|
|
|
|
if (prdOutPackMarkLabel.is_mark == 1)
|
|
{
|
|
PrdReport prdReport = new PrdReport()
|
|
{
|
|
mo_task_id = prdMoTask.id,
|
|
mo_task_code = prdMoTask.mo_task_code,
|
|
create_id = DictConst.DEFAULTUSERID,
|
|
create_time = DateTime.Now,
|
|
reported_qty = 1,
|
|
unit_id = unit?.Id ?? "",
|
|
barcode = mo_task_code + DateTimeOffset.Now.ToUnixTimeSeconds().ToString(),
|
|
equip_id = prdMoTask.eqp_id,
|
|
mbom_process_id = prdMoTask.mbom_process_id,
|
|
station = prdMoTask.workstation_id,
|
|
status=0,
|
|
material_id = prdMoTask.material_id,
|
|
process_id = prdMoTask.process_id,
|
|
};
|
|
|
|
await _db.Updateable<PrdOutPackMarkLabel>()
|
|
.SetColumns(x=>x.is_label==1)
|
|
.SetColumns(x=>x.status=="1")
|
|
.SetColumns(x=>x.report_id==prdReport.id)
|
|
.ExecuteCommandAsync();
|
|
|
|
await _db.Insertable<PrdReport>(prdReport).ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
await _db.Updateable<PrdOutPackMarkLabel>().SetColumns(x=>x.is_label==1).ExecuteCommandAsync();
|
|
}
|
|
});
|
|
|
|
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "校验成功" : result.ErrorMessage;
|
|
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("校验失败");
|
|
}
|
|
}
|
|
|
|
throw Oops.Bah("校验失败");
|
|
}
|
|
|
|
}
|
|
}
|