298 lines
14 KiB
C#
298 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using COSXML.Model.Tag;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using NPOI.Util;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
using Aspose.Cells.Drawing;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using DbModels;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Filter;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
using NPOI.OpenXmlFormats;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.System;
|
|
using Newtonsoft.Json;
|
|
using Tnb.BasicData;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class PrdTaskManageService : IPrdTaskManageService, IOverideVisualDevService, IDynamicApiController, ITransient
|
|
{
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
private const string ModuleId = "25617945906709";
|
|
private readonly ISqlSugarRepository<PrdTask> _repository;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
public PrdTaskManageService(
|
|
ISqlSugarRepository<PrdTask> repository,
|
|
IUserManager userManager,
|
|
IDictionaryDataService dictionaryDataService,
|
|
IRunService runService,
|
|
IVisualDevService visualDevService
|
|
)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
OverideFuncs.GetListAsync = GetList;
|
|
}
|
|
|
|
|
|
// private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
// {
|
|
// var db = _repository.AsSugarClient();
|
|
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
// var data = await _runService.GetListResult(templateEntity, input);
|
|
// if (data?.list?.Count > 0)
|
|
// {
|
|
// var statusField = "mo_task_status";
|
|
// var scheduledTypeField = nameof(PrdMoTask.schedule_type);
|
|
// data.list = data.list.Where(it => it.ContainsKey(statusField) &&
|
|
// it[statusField].IsNotEmptyOrNull() && it[statusField].ToString() != "待下发" &&
|
|
// it[scheduledTypeField].IsNotEmptyOrNull() && it[scheduledTypeField].ParseToInt() == 1
|
|
// ).ToList();
|
|
// foreach (var row in data.list)
|
|
// {
|
|
// var dic = row.ToDictionary(x => x.Key, x => x.Value);
|
|
// var pkName = "material_id";
|
|
// if (dic.ContainsKey(pkName))
|
|
// {
|
|
// var materialId = dic[pkName]?.ToString();
|
|
// var material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == materialId);
|
|
// if (material != null)
|
|
// {
|
|
// row[pkName] = $"{material.code}/{material.name}";
|
|
// }
|
|
// }
|
|
// //模具
|
|
// if (dic.ContainsKey("mold_id"))
|
|
// {
|
|
// var moldId = dic["mold_id"]?.ToString();
|
|
// var mold = await db.Queryable<ToolMolds>().FirstAsync(it => it.id == moldId);
|
|
// if (mold != null)
|
|
// {
|
|
// row["mold_id"] = $"{mold.mold_code}/{mold.mold_name}";
|
|
// }
|
|
// }
|
|
// //设备
|
|
// if (dic.ContainsKey("eqp_id"))
|
|
// {
|
|
// var eqpId = dic["eqp_id"]?.ToString();
|
|
// var eqp = await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == eqpId);
|
|
// if (eqp != null)
|
|
// {
|
|
// row["eqp_id"] = $"{eqp.code}/{eqp.name}";
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
// return data!;
|
|
// }
|
|
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
Dictionary<string, object> queryJson = input.queryJson!=null ? JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : null;
|
|
string moTaskCode = queryJson!=null && queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : "";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>()
|
|
{
|
|
[DictConst.ToBeStartedEnCode] = "待开工",
|
|
[DictConst.InProgressEnCode] = "进行中",
|
|
[DictConst.ClosedEnCode] = "关闭",
|
|
[DictConst.ComplatedEnCode] = "完工",
|
|
[DictConst.ToBeScheduledEncode] = "待排产",
|
|
[DictConst.MoStatusPauseCode] = "暂停",
|
|
[DictConst.MoStatusExceptionCode] = "异常",
|
|
[DictConst.MoStatusRevokeCode] = "撤销",
|
|
};
|
|
var result = await db.Queryable<PrdMoTask>()
|
|
.LeftJoin<EqpEquipment>((a, b) => a.eqp_id == b.id)
|
|
.LeftJoin<BasMaterial>((a, b, c) => a.material_id == c.id)
|
|
.LeftJoin<ToolMolds>((a, b, c, d) => a.mold_id == d.id)
|
|
//.Where((a,b,c,d)=>(a.mo_task_status==DictConst.ToBeStartedEnCode || a.mo_task_status==DictConst.InProgressEnCode || a.mo_task_status==DictConst.MoStatusExceptionCode))
|
|
.Where((a,b,c,d)=>a.schedule_type==1)
|
|
.WhereIF(!string.IsNullOrEmpty(moTaskCode),(a,b,c,d)=>a.mo_task_code.Contains(moTaskCode))
|
|
.OrderByDescending((a, b, c, d) => a.create_time)
|
|
.Select((a, b, c, d) => new PrdTaskManageListOutput()
|
|
{
|
|
id = a.id,
|
|
mo_task_code = a.mo_task_code,
|
|
material_id = c.code+"/"+c.name,
|
|
mold_id = d.mold_code+"/"+d.mold_name,
|
|
eqp_id = b.code+"/"+b.name,
|
|
plan_start_date = a.estimated_start_date==null ? "" : a.estimated_start_date.Value.ToString("yyyy-MM-dd"),
|
|
plan_end_date = a.estimated_end_date==null ? "" : a.estimated_end_date.Value.ToString("yyyy-MM-dd"),
|
|
plan_qty = a.scheduled_qty,
|
|
complete_qty = a.reported_work_qty,
|
|
mo_task_status = a.mo_task_status,
|
|
schedule_type = a.schedule_type.ToString()
|
|
|
|
})
|
|
.Mapper(x=>x.mo_task_status=dic[x.mo_task_status])
|
|
.ToPagedListAsync(input.currentPage, input.pageSize);
|
|
return PageResult<PrdTaskManageListOutput>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
|
|
// /// <summary>
|
|
// /// 根据任务单号获取提报记录明细
|
|
// /// </summary>
|
|
// /// <param name="icmoCode">任务单号</param>
|
|
// /// <remarks>
|
|
// /// returns:
|
|
// ///<br/> {
|
|
// ///<br/> icmo_qty:任务计划数量
|
|
// ///<br/> reported_work_qty:已报工数量
|
|
// ///<br/> reported_qty:报工数量
|
|
// ///<br/> prd_qty:生产数量
|
|
// ///<br/> }
|
|
// /// </remarks>
|
|
// [HttpGet]
|
|
// public async Task<dynamic> GetPrdReportByIcmoCode([FromRoute] string mo_task_code)
|
|
// {
|
|
// var db = _repository.AsSugarClient();
|
|
// var prdTask = await db.Queryable<PrdMoTask>().FirstAsync(it => it.mo_task_code == mo_task_code);
|
|
// var eqpCode = "";
|
|
// var moldCode = "";
|
|
// var materialCode = "";
|
|
// var materialName = "";
|
|
// var materialProp = "";
|
|
// if (prdTask != null)
|
|
// {
|
|
// var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
|
|
// var eqp = await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == prdTask.eqp_id);
|
|
// var mold = await db.Queryable<ToolMolds>().FirstAsync(it => it.id == prdTask.mold_id);
|
|
// var material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == prdTask.material_id);
|
|
// eqpCode = eqp != null ? eqp.code : "";
|
|
// moldCode = mold != null ? mold.mold_code : "";
|
|
// materialCode = material != null ? material.code : "";
|
|
// materialName = material != null ? material.name : "";
|
|
// materialProp = material != null ? material.material_property : "";
|
|
// prdTask.workline_code = (await db.Queryable<OrganizeEntity>().Where(it => it.Id == prdTask.workline_id && it.Category == "workline").FirstAsync())?.EnCode;
|
|
// prdTask.process_code = (await db.Queryable<BasProcess>().Where(it => it.id == prdTask.process_id).FirstAsync())?.process_code;
|
|
// if (dic.ContainsKey(prdTask.mo_task_status))
|
|
// {
|
|
// prdTask.mo_task_status = dic[prdTask.mo_task_status]?.ToString();
|
|
// }
|
|
//
|
|
// }
|
|
// var res = await db.Queryable<PrdReport>().Where(it => it.mo_task_code == mo_task_code)
|
|
// .Select(it => new PrdReportOutput
|
|
// {
|
|
// icmo_qty = it.icmo_qty,
|
|
// reported_work_qty = it.reported_work_qty,
|
|
// reported_qty = it.reported_qty,
|
|
// prd_qty = it.prd_qty,
|
|
// scrap_qty = SqlFunc.Subqueryable<PrdMoTaskDefect>().Where(pmtd => pmtd.mo_task_id == it.mo_task_id).Select(pmtd => pmtd.scrap_qty),
|
|
// })
|
|
// .Mapper(it =>
|
|
// {
|
|
// it.icmo_qty = it.icmo_qty ?? (
|
|
// db.Queryable<PrdMoTask>().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty < 1 ? 0 :
|
|
// (it.icmo_qty ?? db.Queryable<PrdMoTask>().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty ?? 0));
|
|
// it.reported_work_qty = it.reported_work_qty ?? 0;
|
|
// it.reported_qty = it.reported_qty ?? 0;
|
|
// it.prd_qty = it.prd_qty ?? 0;
|
|
// it.scrap_qty = it.scrap_qty ?? 0;
|
|
// })
|
|
// .FirstAsync();
|
|
// prdTask.eqp_code = eqpCode;
|
|
// prdTask.mold_code = moldCode;
|
|
// prdTask.material_code = materialCode;
|
|
// prdTask.material_name = materialName;
|
|
// prdTask.icmo_qty = res?.icmo_qty;
|
|
// prdTask.reported_work_qty = res?.reported_work_qty ?? 0;
|
|
// prdTask.reported_qty = res?.reported_qty ?? 0;
|
|
// prdTask.prd_qty = res?.prd_qty ?? 0;
|
|
// prdTask.scrap_qty = res?.scrap_qty ?? 0;
|
|
//
|
|
// return prdTask;
|
|
// }
|
|
|
|
|
|
/// <summary>
|
|
/// 根据任务单号获取提报记录明细
|
|
/// </summary>
|
|
/// <param name="icmoCode">任务单号</param>
|
|
/// <remarks>
|
|
/// returns:
|
|
///<br/> {
|
|
///<br/> icmo_qty:任务计划数量
|
|
///<br/> reported_work_qty:已报工数量
|
|
///<br/> reported_qty:报工数量
|
|
///<br/> prd_qty:生产数量
|
|
///<br/> }
|
|
/// </remarks>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetPrdReportByIcmoCode([FromRoute] string mo_task_code)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
|
|
var prdTask = await db.Queryable<PrdMoTask>()
|
|
.LeftJoin<BasMaterial>((a,b)=>a.material_id==b.id)
|
|
.LeftJoin<ToolMolds>((a,b,c)=>a.mold_id==c.id)
|
|
.LeftJoin<EqpEquipment>((a,b,c,d)=>a.eqp_id==d.id)
|
|
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e)=>e.DictionaryTypeId==DictConst.PrdTaskStatusTypeId && a.mo_task_status==e.EnCode)
|
|
.LeftJoin<OrganizeEntity>((a,b,c,d,e,f)=>a.workline_id==f.Id)
|
|
.LeftJoin<BasProcess>((a,b,c,d,e,f,g)=>a.process_id==g.id)
|
|
.Where((a,b) => a.mo_task_code == mo_task_code)
|
|
.Select((a,b,c,d,e,f,g) => new
|
|
{
|
|
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,
|
|
material_property = b.material_property,
|
|
mo_task_status = e.FullName,
|
|
plan_qty = a.plan_qty,
|
|
scheduled_qty = a.scheduled_qty,
|
|
complete_qty = a.reported_work_qty + a.scrap_qty,
|
|
scrap_qty = a.scrap_qty,
|
|
mold_code = c.mold_code,
|
|
// icmo_qty = a.icmo_qty,
|
|
reported_work_qty = a.reported_work_qty,
|
|
// reported_qty = a.reported_qty,
|
|
// prd_qty = a.prd_qty,
|
|
eqp_code = d.code,
|
|
mbom_process_id = a.mbom_process_id,
|
|
workline_name = f.FullName,
|
|
process_name = g.process_name,
|
|
process_id = a.process_id
|
|
}).FirstAsync();
|
|
|
|
return prdTask;
|
|
}
|
|
|
|
//public async Task<dynamic> GetPrdMoTaskList()
|
|
//{
|
|
// var db= _repository.AsSugarClient();
|
|
//}
|
|
}
|
|
}
|