218 lines
12 KiB
C#
218 lines
12 KiB
C#
using Aop.Api.Domain;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev.Engine.Enum.VisualDevModelData;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
using Tnb.Common.Redis;
|
|
using Tnb.QcMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Microsoft.AspNetCore.Components.Route("api/[area]/[controller]/[action]")]
|
|
public class BiService: IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
private readonly RedisData2 _redisData;
|
|
|
|
public BiService(ISqlSugarRepository<Material> repository,
|
|
RedisData2 redisData,
|
|
IBillRullService billRuleService,
|
|
IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
_redisData = redisData;
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<ZhuSuBiOutput> GetZhuSuBiData(ZhuSuBiInput input)
|
|
{
|
|
string dayStr = input.day!=null && !input.day.IsEmpty() ? input.day : DateTime.Now.ToString("yyyy-MM-dd");
|
|
string monthStr = dayStr.Substring(0, 7);
|
|
ZhuSuBiOutput output = new ZhuSuBiOutput();
|
|
output.day_month_yield = new DayMonthYieldOutput();
|
|
decimal? monthQualifiedQty = await _db.Queryable<PrdReport>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.Where((a, b) => a.create_time.ToString("yyyy-MM") == monthStr && b.category_id.Contains("ZSJ"))
|
|
.GroupBy((a, b) => a.org_id)
|
|
.Select((a, b) => SqlFunc.AggregateSum(a.reported_qty))
|
|
.FirstAsync();
|
|
|
|
decimal? monthUnQualifiedQty = await _db.Queryable<PrdMoTaskDefect>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.Where((a, b) => a.create_time.ToString("yyyy-MM") == monthStr && b.category_id.Contains("ZSJ"))
|
|
.GroupBy((a, b) => a.org_id)
|
|
.Select((a, b) => SqlFunc.AggregateSum(a.scrap_qty))
|
|
.FirstAsync();
|
|
|
|
decimal? dayQualifiedQty = await _db.Queryable<PrdReport>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.Where((a, b) => a.create_time.ToString("yyyy-MM-dd") == monthStr && b.category_id.Contains("ZSJ"))
|
|
.GroupBy((a, b) => a.org_id)
|
|
.Select((a, b) => SqlFunc.AggregateSum(a.reported_qty))
|
|
.FirstAsync();
|
|
|
|
decimal? dayUnQualifiedQty = await _db.Queryable<PrdMoTaskDefect>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.Where((a, b) => a.create_time.ToString("yyyy-MM-dd") == monthStr && b.category_id.Contains("ZSJ"))
|
|
.GroupBy((a, b) => a.org_id)
|
|
.Select((a, b) => SqlFunc.AggregateSum(a.scrap_qty))
|
|
.FirstAsync();
|
|
output.day_month_yield.month_qty = monthQualifiedQty!=null ? monthQualifiedQty.Value : 0;
|
|
output.day_month_yield.day_qty = dayQualifiedQty !=null ? dayQualifiedQty.Value : 0;
|
|
output.day_month_yield.month_qualified_percent = output.day_month_yield.month_qty==0 ? 0 :decimal.Parse((monthQualifiedQty.Value/(monthQualifiedQty.Value+monthUnQualifiedQty.Value)).ToString("F"));
|
|
output.day_month_yield.day_qualified_percent = output.day_month_yield.day_qty==0 ? 0 : decimal.Parse((dayQualifiedQty.Value/(dayQualifiedQty.Value+dayUnQualifiedQty.Value)).ToString("F"));
|
|
|
|
var queryable1 =_db.Queryable<PrdReport>()
|
|
.LeftJoin<PrdMoTask>((a,b)=>a.mo_task_id==b.id)
|
|
.LeftJoin<BasMaterial>((a,b,c)=>a.material_id==c.id)
|
|
.LeftJoin<UserEntity>((a,b,c,d)=>a.create_id==d.Id)
|
|
.LeftJoin<OrganizeEntity>((a,b,c,d,e)=>b.workline_id==e.Id)
|
|
.LeftJoin<EqpEquipment>((a,b,c,d,e,f)=>b.eqp_id==f.id)
|
|
.Where((a,b,c)=>(b.mo_task_status==DictConst.MoStatusPauseCode || b.mo_task_status==DictConst.InProgressEnCode) && c.category_id.Contains("ZSJ"))
|
|
.Select((a,b,c,d,e,f)=>new ReportRecordOutput
|
|
{
|
|
mo_task_code = b.mo_task_code,
|
|
material_name = c.name,
|
|
// workline_name = e.FullName,
|
|
workline_name = f.name,
|
|
report_type = "合格",
|
|
qty = a.reported_qty.Value,
|
|
repoter_name = d.RealName,
|
|
plan_qty = b.scheduled_qty.Value,
|
|
remain_plan_qty = b.scheduled_qty.Value-(b.reported_work_qty!=null ? b.reported_work_qty.Value : 0)-(b.scrap_qty!=null ? b.scrap_qty.Value : 0),
|
|
report_time = a.create_time.ToString(DbTimeFormat.SS)
|
|
});
|
|
|
|
var queryable2 =_db.Queryable<PrdMoTaskDefect>()
|
|
.LeftJoin<PrdMoTask>((a,b)=>a.mo_task_id==b.id)
|
|
.LeftJoin<BasMaterial>((a,b,c)=>a.material_id==c.id)
|
|
.LeftJoin<UserEntity>((a,b,c,d)=>a.create_id==d.Id)
|
|
.LeftJoin<OrganizeEntity>((a,b,c,d,e)=>b.workline_id==e.Id)
|
|
.LeftJoin<EqpEquipment>((a,b,c,d,e,f)=>b.eqp_id==f.id)
|
|
.Where((a,b,c)=>(b.mo_task_status==DictConst.MoStatusPauseCode || b.mo_task_status==DictConst.InProgressEnCode) && c.category_id.Contains("ZSJ"))
|
|
.Select((a,b,c,d,e,f)=>new ReportRecordOutput
|
|
{
|
|
mo_task_code = b.mo_task_code,
|
|
material_name = c.name,
|
|
// workline_name = e.FullName,
|
|
workline_name = f.name,
|
|
report_type = "不合格",
|
|
qty = a.scrap_qty,
|
|
repoter_name = d.RealName,
|
|
plan_qty = b.scheduled_qty.Value,
|
|
remain_plan_qty = b.scheduled_qty.Value-(b.reported_work_qty!=null ? b.reported_work_qty.Value : 0)-(b.scrap_qty!=null ? b.scrap_qty.Value : 0),
|
|
report_time = a.create_time.ToString(DbTimeFormat.SS)
|
|
});
|
|
output.report_record_list = await _db.UnionAll(queryable1, queryable2)
|
|
.OrderByDescending(a => a.report_time)
|
|
.ToListAsync();
|
|
|
|
output.equip_pie_list = await _db.Queryable<EqpEquipment>()
|
|
.GroupBy(x => x.status)
|
|
// .OrderBy(x=>x.code)
|
|
.Select(x => new EquipPieOutput
|
|
{
|
|
name = x.status,
|
|
value = SqlFunc.AggregateCount(x.id)
|
|
})
|
|
|
|
.ToListAsync();
|
|
|
|
output.equip_info_list = await _db.Queryable<EqpEquipment>()
|
|
.LeftJoin<EqpEquipType>((x,y)=>x.equip_type_id==y.id)
|
|
.Where((x,y)=>y.code=="ZSJ")
|
|
.OrderBy(x=>x.code)
|
|
.Select(x => new EquipPieOutput
|
|
{
|
|
code = x.code,
|
|
name = x.name,
|
|
status = x.status
|
|
}).ToListAsync();
|
|
foreach (var item in output.equip_info_list)
|
|
{
|
|
item.status = _redisData.Get<string>($"{item.code}:ActStsMach");
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<ZlBiOutput> GetZlBiData()
|
|
{
|
|
ZlBiOutput result = new ZlBiOutput();
|
|
int mo_task_count = await _db.Queryable<PrdMoTask>().Where(x=>x.mo_task_status==DictConst.InProgressEnCode && (x.schedule_type==1 || (x.schedule_type==2 && x.parent_id!=null))).CountAsync();
|
|
int qc_all_count = await _db.Queryable<QcCheckExecH>().Where(x=>x.status=="26745591857941").CountAsync();
|
|
int qc_complete_count = await _db.Queryable<QcCheckExecH>().Where(x=>x.status=="26745885292053").CountAsync();
|
|
int qc_ok_count = await _db.Queryable<QcCheckExecH>().Where(x=>x.result=="ok" || x.result=="barelyOk").CountAsync();
|
|
|
|
List<ZlBiQcTaskListOutput> list = await _db.Queryable<QcCheckExecH>()
|
|
.LeftJoin<PrdMoTask>((a, b) => a.mo_task_code == b.mo_task_code)
|
|
.LeftJoin<EqpEquipment>((a, b, c) => b.eqp_id == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => b.workline_id == d.Id)
|
|
.LeftJoin<BasMaterial>((a, b, c, d, e) => a.materialid == e.id)
|
|
.LeftJoin<UserEntity>((a, b, c, d, e, f) => a.execuser == f.Id)
|
|
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e,f,g)=>a.checktype==g.Id)
|
|
.Where((a) => a.status == "26745885292053")
|
|
.Select((a, b, c, d, e, f,g) => new ZlBiQcTaskListOutput
|
|
{
|
|
mo_task_code = a.mo_task_code,
|
|
equip_workline_name = c.name!=null ? c.name : d.FullName,
|
|
checktype = g.FullName,
|
|
material_name = e.name,
|
|
material_specification = e.material_specification,
|
|
material_standard = e.material_standard,
|
|
qty = a.qty,
|
|
rqty = a.rqty,
|
|
result = a.result,
|
|
execuser = f.RealName,
|
|
exectime = a.exectime
|
|
}).OrderByDescending(a => a.exectime).Take(10).ToListAsync();
|
|
|
|
List<ZlBiQcTaskDetailListOutput> detailList = await _db.Queryable<QcCheckExecH>()
|
|
.LeftJoin<PrdMoTask>((a, b) => a.mo_task_code == b.mo_task_code)
|
|
.LeftJoin<EqpEquipment>((a, b, c) => b.eqp_id == c.id)
|
|
.LeftJoin<OrganizeEntity>((a, b, c, d) => b.workline_id == d.Id)
|
|
.LeftJoin<BasMaterial>((a, b, c, d, e) => a.materialid == e.id)
|
|
.LeftJoin<UserEntity>((a, b, c, d, e, f) => a.execuser == f.Id)
|
|
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e,f,g)=>a.checktype==g.Id)
|
|
.Where((a) => a.status == "26745591857941")
|
|
.Select((a, b, c, d, e, f,g) => new ZlBiQcTaskDetailListOutput
|
|
{
|
|
mo_task_code = a.mo_task_code,
|
|
equip_workline_name = c.name!=null ? c.name : d.FullName,
|
|
checktype = a.checktype,
|
|
create_time = a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
execuser = f.RealName,
|
|
}).OrderBy(a => a.create_time).ToListAsync();
|
|
|
|
result.mo_task_count = mo_task_count;
|
|
result.qc_all_count = qc_all_count;
|
|
result.qc_complete_count = qc_complete_count;
|
|
result.qc_ok_count = qc_ok_count;
|
|
result.qc_task_list = list;
|
|
result.qc_sj_task_list = detailList.Where(x=>x.checktype==WmsWareHouseConst.SHOUJIAN_ID).ToList();
|
|
result.qc_xj_task_list = detailList.Where(x=>x.checktype==WmsWareHouseConst.XUNJIAN_ID).ToList();
|
|
result.qc_mj_task_list = detailList.Where(x=>x.checktype==WmsWareHouseConst.MOJIAN_ID).ToList();
|
|
result.qc_lbjj_task_list = detailList.Where(x=>x.checktype==WmsWareHouseConst.LINGBUJIANZUIZHONGJIANYAN_ID).ToList();
|
|
return result;
|
|
}
|
|
}
|
|
} |