109 lines
3.9 KiB
C#
109 lines
3.9 KiB
C#
using DOAN.Model.MES.order;
|
||
using DOAN.Model.MES.product;
|
||
using DOAN.Model.MES.quality.FQC;
|
||
using DOAN.Model.MES.SmartScreen.Quality.Dto;
|
||
using DOAN.Service.MES.SmartScreen.Order.IService;
|
||
using DOAN.Service.MES.SmartScreen.Quality.IService;
|
||
using Infrastructure.Attribute;
|
||
using NPOI.SS.Formula.Functions;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace DOAN.Service.MES.SmartScreen.Quality
|
||
{
|
||
/// <summary>
|
||
/// 质量大屏Service业务层处理
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(IQualitySmartService), ServiceLifetime = LifeTime.Transient)]
|
||
public class QualitySmartService : BaseService<QcFinishedproductDefectCollection>, IQualitySmartService
|
||
{
|
||
public QualityScreenHeadDto GetQualityScreenHead()
|
||
{
|
||
QualityScreenHeadDto qualityScreenHeadDto = new QualityScreenHeadDto();
|
||
// 当前日期
|
||
DateTime now = DateTime.Now;
|
||
// 当前月份的第一天 00:00:00
|
||
DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1);
|
||
// 当前月份的最后一天 23:59:59
|
||
DateTime lastDayOfMonth = new DateTime(now.Year, now.Month, 1)
|
||
.AddMonths(1)
|
||
.AddSeconds(-1);
|
||
// 计算本周周一(第一天)
|
||
int daysUntilMonday = ((int)now.DayOfWeek - (int)DayOfWeek.Monday + 7) % 7;
|
||
DateTime startOfWeek = now.AddDays(-daysUntilMonday);
|
||
// 计算本周周日(最后一天)23:59:59
|
||
DateTime endOfWeek = startOfWeek.AddDays(6).Date
|
||
.AddHours(23)
|
||
.AddMinutes(59)
|
||
.AddSeconds(59);
|
||
var response = Queryable().ToList();
|
||
|
||
qualityScreenHeadDto.MonthFQC = response.Where(o => o.CheckDatetime >= firstDayOfMonth && o.CheckDatetime <= lastDayOfMonth).Sum(o=>o.Number);
|
||
qualityScreenHeadDto.WeekFQC= response.Where(o => o.CheckDatetime >= startOfWeek && o.CheckDatetime <= endOfWeek).Sum(o => o.Number);
|
||
return qualityScreenHeadDto;
|
||
}
|
||
|
||
public List<QualitySmartScreenDto> GetQualitySmartScreenForWeek()
|
||
{
|
||
// 获取当前日期
|
||
DateTime now = DateTime.Now;
|
||
|
||
// 计算本周周一(第一天)
|
||
int daysUntilMonday = ((int)now.DayOfWeek - (int)DayOfWeek.Monday + 7) % 7;
|
||
DateTime startOfWeek = now.AddDays(-daysUntilMonday);
|
||
|
||
// 计算本周周日(最后一天)23:59:59
|
||
DateTime endOfWeek = startOfWeek.AddDays(6).Date
|
||
.AddHours(23)
|
||
.AddMinutes(59)
|
||
.AddSeconds(59);
|
||
|
||
// 使用 SqlSugar 进行联表查询和分组统计
|
||
var result = Context.Queryable<QcFinishedproductDefectCollection>()
|
||
.LeftJoin<ProWorkorder>((defect, work) => defect.Workorder == work.Workorder)
|
||
.Where((defect, work) => defect.CheckDatetime >= startOfWeek && defect.CheckDatetime <= endOfWeek)
|
||
.GroupBy((defect, work) => new { work.StoveCode, defect.DefectName })
|
||
.Select((defect, work) => new QualitySmartScreenDto
|
||
{
|
||
StoveCode = work.StoveCode,
|
||
DefectName = defect.DefectName,
|
||
Number = SqlFunc.AggregateSum(defect.Number)
|
||
})
|
||
.ToList();
|
||
|
||
return result;
|
||
}
|
||
|
||
public List<QualitySmartScreenDto> GetQualitySmartScreenForMonth()
|
||
{
|
||
// 获取当前日期
|
||
DateTime now = DateTime.Now;
|
||
// 当前月份的第一天 00:00:00
|
||
DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1);
|
||
// 当前月份的最后一天 23:59:59
|
||
DateTime lastDayOfMonth = new DateTime(now.Year, now.Month, 1)
|
||
.AddMonths(1)
|
||
.AddSeconds(-1);
|
||
|
||
|
||
// 使用 SqlSugar 进行联表查询和分组统计
|
||
var result = Context.Queryable<QcFinishedproductDefectCollection>()
|
||
.LeftJoin<ProWorkorder>((defect, work) => defect.Workorder == work.Workorder)
|
||
.Where((defect, work) => defect.CheckDatetime >= firstDayOfMonth && defect.CheckDatetime <= lastDayOfMonth)
|
||
.GroupBy((defect, work) => new { work.StoveCode, defect.DefectName })
|
||
.Select((defect, work) => new QualitySmartScreenDto
|
||
{
|
||
StoveCode = work.StoveCode,
|
||
DefectName = defect.DefectName,
|
||
Number = SqlFunc.AggregateSum(defect.Number)
|
||
})
|
||
.ToList();
|
||
|
||
return result;
|
||
}
|
||
}
|
||
}
|