153 lines
7.6 KiB
C#
153 lines
7.6 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.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;
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |