diff --git a/DOAN.Admin.WebApi/Controllers/MES/BI/product/PlanAchievementRateController.cs b/DOAN.Admin.WebApi/Controllers/MES/BI/product/PlanAchievementRateController.cs new file mode 100644 index 0000000..62e016f --- /dev/null +++ b/DOAN.Admin.WebApi/Controllers/MES/BI/product/PlanAchievementRateController.cs @@ -0,0 +1,46 @@ +using DOAN.Model.MES.product.Dto; +using DOAN.Service.MES.BI.IService; +using DOAN.Service.MES.product.IService; +using Microsoft.AspNetCore.Mvc; + +namespace DOAN.WebApi.Controllers.MES.BI.product +{ + + [AllowAnonymous] + [Route("mes/BI/planAchievementRate")] + public class PlanAchievementRateController : BaseController + { + private readonly IProPlanAchievementrateService IPlanAchievementRate; + + public PlanAchievementRateController(IProPlanAchievementrateService _iPlanAchievementRate) + { + _iPlanAchievementRate = IPlanAchievementRate; + } + + + [HttpGet("gettoday")] + public IActionResult GetTodayList() + { + var response = IPlanAchievementRate.GetTodayList(); + return SUCCESS(response); + } + [HttpGet("getyesterday")] + public IActionResult GetYesterdayList() + { + var response = IPlanAchievementRate.GetYesterdayList(); + return SUCCESS(response); + } + + + [HttpGet("getmonth")] + public IActionResult GetMonth() + { + var response = IPlanAchievementRate.GetListByMonth(); + return SUCCESS(response); + } + + + + + } +} diff --git a/DOAN.Service/MES/product/IService/IProPlanAchievementrateService.cs b/DOAN.Service/MES/product/IService/IProPlanAchievementrateService.cs index af35ee9..0424e9e 100644 --- a/DOAN.Service/MES/product/IService/IProPlanAchievementrateService.cs +++ b/DOAN.Service/MES/product/IService/IProPlanAchievementrateService.cs @@ -24,5 +24,13 @@ namespace DOAN.Service.MES.product.IService int UpdateProPlanAchievementrate(ProPlanAchievementrate parm); + + + List GetTodayList(); + + List GetYesterdayList(); + + List GetListByMonth(); + } } diff --git a/DOAN.Service/MES/product/ProPlanAchievementrateService.cs b/DOAN.Service/MES/product/ProPlanAchievementrateService.cs index f8e4dfa..4c47d01 100644 --- a/DOAN.Service/MES/product/ProPlanAchievementrateService.cs +++ b/DOAN.Service/MES/product/ProPlanAchievementrateService.cs @@ -12,6 +12,7 @@ using System.Linq; using Microsoft.AspNetCore.Http; using Infrastructure; using static System.Runtime.InteropServices.JavaScript.JSType; +using Mapster; namespace DOAN.Service.MES.product { /// @@ -48,22 +49,22 @@ namespace DOAN.Service.MES.product /// public PagedInfo GetListByMonth(ProPlanAchievementrateQueryDto2 parm) { - (DateTime FirstDay, DateTime LastDay) Handlemonth= GetFirstAndLastDayOfMonth(parm.SearchYearMonth); - var predicate = Expressionable.Create() - .AndIF(!string.IsNullOrEmpty(parm.Project), it => it.Project.Contains(parm.Project)) - .And(it=>it.RecordDate>= Handlemonth.FirstDay&& it.RecordDate<= Handlemonth.LastDay) - ; + (DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(parm.SearchYearMonth); + var predicate = Expressionable.Create() + .AndIF(!string.IsNullOrEmpty(parm.Project), it => it.Project.Contains(parm.Project)) + .And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay) + ; var response = Queryable() .Where(predicate.ToExpression()) - .GroupBy(it=>it.Project) - .Select(it=>new ProPlanAchievementrate() + .GroupBy(it => it.Project) + .Select(it => new ProPlanAchievementrate() { - Project=parm.Project, - AgroupPlanNum=SqlFunc.AggregateSum(it.AgroupPlanNum??0), - AgroupProductNum= SqlFunc.AggregateSum(it.AgroupProductNum ?? 0), - AgroupCompletionRate= SqlFunc.AggregateAvg(it.AgroupCompletionRate), + Project = it.Project, + AgroupPlanNum = SqlFunc.AggregateSum(it.AgroupPlanNum ?? 0), + AgroupProductNum = SqlFunc.AggregateSum(it.AgroupProductNum ?? 0), + AgroupCompletionRate = SqlFunc.AggregateAvg(it.AgroupCompletionRate), BgroupPlanNum = SqlFunc.AggregateSum(it.BgroupPlanNum ?? 0), BgroupProductNum = SqlFunc.AggregateSum(it.BgroupProductNum ?? 0), BgroupCompletionRate = SqlFunc.AggregateAvg(it.BgroupCompletionRate), @@ -119,7 +120,7 @@ namespace DOAN.Service.MES.product /// public ProPlanAchievementrate AddProPlanAchievementrate(ProPlanAchievementrate model) { - + return Context.Insertable(model).IgnoreColumns(it => new { it.Id }).ExecuteReturnEntity(); } @@ -169,5 +170,72 @@ namespace DOAN.Service.MES.product return Update(model, true); } + + + public List GetTodayList() + { + DateTime today = DateTime.Today; + var response = Queryable() + .Where(it => it.RecordDate == today) + .ToList() + .Adapt, List>() + ; + return response; + } + + public List GetYesterdayList() + { + DateTime yesterday = DateTime.Today.AddDays(-1); + var response = Queryable() + .Where(it => it.RecordDate == yesterday) + .ToList() + .Adapt, List>() + ; + return response; + } + + public List GetListByMonth() + { + (DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(DateTime.Today); + var predicate = Expressionable.Create() + + .And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay) + ; + + var response = Queryable() + + .Where(predicate.ToExpression()) + .GroupBy(it => it.Project) + .Select(it => new ProPlanAchievementrate() + { + Project = it.Project, + AgroupPlanNum = SqlFunc.AggregateSum(it.AgroupPlanNum ?? 0), + AgroupProductNum = SqlFunc.AggregateSum(it.AgroupProductNum ?? 0), + AgroupCompletionRate = SqlFunc.AggregateAvg(it.AgroupCompletionRate), + BgroupPlanNum = SqlFunc.AggregateSum(it.BgroupPlanNum ?? 0), + BgroupProductNum = SqlFunc.AggregateSum(it.BgroupProductNum ?? 0), + BgroupCompletionRate = SqlFunc.AggregateAvg(it.BgroupCompletionRate), + SummaryActualNum = SqlFunc.AggregateSum(it.SummaryActualNum ?? 0), + SummaryPlanNum = SqlFunc.AggregateSum(it.SummaryPlanNum ?? 0), + SummaryPlanAchievementRate = SqlFunc.AggregateAvg(it.SummaryPlanAchievementRate), + DownQuality = SqlFunc.AggregateSum(it.DownQuality ?? 0), + DownSuppler = SqlFunc.AggregateSum(it.DownSuppler ?? 0), + DownDeviceFailure = SqlFunc.AggregateSum(it.DownDeviceFailure ?? 0), + DownDeviceDebug = SqlFunc.AggregateSum(it.DownDeviceDebug ?? 0), + DownLogisticsWaitMaterial = SqlFunc.AggregateSum(it.DownLogisticsWaitMaterial ?? 0), + DownLackMaterial = SqlFunc.AggregateSum(it.DownLackMaterial ?? 0), + + DownInjection = SqlFunc.AggregateSum(it.DownInjection ?? 0), + DownAssembly = SqlFunc.AggregateSum(it.DownAssembly ?? 0), + AllLineStopTime = SqlFunc.AggregateSum(it.AllLineStopTime ?? 0), + + RecordDate = Handlemonth.FirstDay + }) + .ToList() + .Adapt, List>(); + + return response; + } + } } \ No newline at end of file