在CarouselBoardDto中添加StartTime和EndTime字段,支持传入时间范围查询 修改GetQualityStatisticsCarouselBoardData和GetWorkOrderCarouselBoardData方法,支持按传入时间范围或默认时间范围查询数据
275 lines
12 KiB
C#
275 lines
12 KiB
C#
using Aliyun.OSS;
|
||
using Infrastructure.Attribute;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Data;
|
||
using System.Globalization;
|
||
using System.Linq;
|
||
using ZR.Model.mes.carouselBoard;
|
||
using ZR.Model.mes.echarts;
|
||
using ZR.Model.MES.pro;
|
||
using ZR.Model.MES.qc;
|
||
using ZR.Model.MES.wms.Dto;
|
||
using ZR.Model.MES.wms;
|
||
using ZR.Service.MES.carouselBoard.IService;
|
||
using ZR.Service.MES.echarts.IService;
|
||
using ZR.Model.Business;
|
||
using ZR.Model.dc;
|
||
|
||
namespace ZR.Service.MES.carouselBoard
|
||
{
|
||
[AppService(ServiceType = typeof(ICarouselBoardService), ServiceLifetime = LifeTime.Transient)]
|
||
public class CarouselBoardService : BaseService<EchartsOptions>, ICarouselBoardService
|
||
{
|
||
public List<BlankInventoryCarouseDto> GetBlankInventoryCarouselBoardData(CarouselBoardQuery query)
|
||
{
|
||
// 构建查询条件
|
||
var predicate = Expressionable
|
||
.Create<WmBlankInventory>()
|
||
.And(it => it.Type == 1)
|
||
.ToExpression();
|
||
|
||
// 获取所有符合条件的毛坯库存记录,并按更新时间降序排列
|
||
var inventoryList = Context.Queryable<WmBlankInventory>()
|
||
.Where(predicate)
|
||
.OrderByDescending(it => it.UpdatedTime)
|
||
.ToList();
|
||
|
||
// 去重:获取所有唯一的毛坯号列表
|
||
var uniqueBlankNums = inventoryList
|
||
.GroupBy(it => it.BlankNum)
|
||
.Select(group => group.First())
|
||
.ToList();
|
||
|
||
// 构建返回结果
|
||
var response = new List<BlankInventoryCarouseDto>();
|
||
foreach (var inventory in uniqueBlankNums)
|
||
{
|
||
var dto = new BlankInventoryCarouseDto
|
||
{
|
||
Id = inventory.Id, // 主键
|
||
FkPaintId = inventory.FkPaintId, // 油漆id
|
||
BlankNum = inventory.BlankNum, // 毛坯号
|
||
Quantity = inventory.Quantity, // 库存数量
|
||
MaxNum = inventory.MaxNum, // 最大库存
|
||
MinNum = inventory.MinNum, // 最小库存
|
||
WarnNum = inventory.WarnNum, // 预警库存
|
||
Type = inventory.Type, // 类别
|
||
Status = inventory.Status, // 状态
|
||
Remark = inventory.Remark // 备注
|
||
};
|
||
|
||
// 直接查询当前毛坯号对应的物料信息(不使用字典缓存)
|
||
var material = Context.Queryable<WmMaterial>()
|
||
.Where(m => m.BlankNum == inventory.BlankNum && m.Type == 2 && m.Status == 1)
|
||
.First();
|
||
|
||
if (material != null)
|
||
{
|
||
dto.Description = !string.IsNullOrEmpty(material.Description)
|
||
? material.Description
|
||
: material.ProductName;
|
||
dto.Color = material.Color;
|
||
dto.Specification = material.Specification;
|
||
}
|
||
else
|
||
{
|
||
dto.Description = "此毛坯号不在物料清单内!";
|
||
}
|
||
|
||
response.Add(dto);
|
||
}
|
||
|
||
return response;
|
||
}
|
||
|
||
public List<DeviceAlarmCarouseDto> GetEquipmentAlarmCarouselBoardData(CarouselBoardQuery query)
|
||
{
|
||
List<DeviceAlarmCarouseDto> result = Context.Queryable<DeviceAlarmLog>()
|
||
.OrderByDescending(it => it.CreateTime)
|
||
.Select(it => new DeviceAlarmCarouseDto
|
||
{
|
||
Id = it.AlarmNo,
|
||
AlarmArea = it.Area,
|
||
AlarmType = it.AlarmCircuit,
|
||
AlarmContent = it.MessageText,
|
||
AlarmTime = it.AlarmTime,
|
||
Duration = it.Duration.Value,
|
||
HandleStatus = it.Status,
|
||
|
||
})
|
||
.ToList();
|
||
return result;
|
||
}
|
||
|
||
public DeviceLiveCarouseDto GetEquipmentLiveCarouselBoardData(CarouselBoardQuery query)
|
||
{
|
||
DeviceLiveCarouseDto result = Context.Queryable<DeviceUploadData>()
|
||
.OrderByDescending(it => it.CollectionTime)
|
||
.Select(it => new DeviceLiveCarouseDto
|
||
{
|
||
PrimerCycleTemperature = it.Value01,
|
||
PrimerCycleHumidity = it.Value02,
|
||
ColorCycleTemperature = it.Value03,
|
||
ColorCycleHumidity = it.Value04,
|
||
ClearCycleTemperature = it.Value05,
|
||
ClearCycleHumidity = it.Value06,
|
||
PureWaterConductivity = it.Value07,
|
||
MoistureDryingTemperature = it.Value08,
|
||
ClearDryingTemperature = it.Value09
|
||
})
|
||
.First();
|
||
return result;
|
||
}
|
||
|
||
public List<QualityStatisticsCarouseDto> GetQualityStatisticsCarouselBoardData(CarouselBoardQuery query)
|
||
{
|
||
// 确定查询时间范围
|
||
DateTime startTime, endTime;
|
||
if (query != null && query.StartTime.HasValue && query.EndTime.HasValue)
|
||
{
|
||
// 使用传入的时间范围
|
||
startTime = query.StartTime.Value;
|
||
endTime = query.EndTime.Value;
|
||
}
|
||
else
|
||
{
|
||
// 默认使用前一天和当天的数据
|
||
DateTime yesterday = DateTime.Today.AddDays(-1);
|
||
DateTime todayEnd = DateTime.Today.AddDays(1).AddMilliseconds(-1);
|
||
startTime = yesterday;
|
||
endTime = todayEnd;
|
||
}
|
||
|
||
List<QualityStatisticsCarouseDto> qualityStatistics = Context
|
||
.Queryable<QcQualityStatisticsFirst>()
|
||
.Where(it => it.Remark2 == 1) // 只获取有效的记录
|
||
.Where(it => it.StartTime >= startTime && it.StartTime <= endTime) // 筛选时间范围内的数据
|
||
.Select(it => new QualityStatisticsCarouseDto
|
||
{
|
||
Id = it.Id, // id
|
||
WorkorderId = it.WorkorderId, // 工单号
|
||
FinishedPartNumber = it.FinishedPartNumber, // 零件号
|
||
ProductDescription = it.ProductDescription, // 描述
|
||
Color = it.Color, // 颜色
|
||
RequireNumber = it.RequireNumber, // 生产投入数
|
||
Team = it.Team, // 班次
|
||
QualifiedNumber = it.QualifiedNumber, // 合格数
|
||
QualifiedRate = it.QualifiedRate, // 合格率
|
||
PaoguangTotal = it.PaoguangTotal, // 抛光总数
|
||
DamoTotal = it.DamoTotal, // 打磨总数
|
||
BaofeiTotal = it.BaofeiTotal, // 报废总数
|
||
StartTime = it.StartTime,
|
||
EndTime = it.EndTime,
|
||
})
|
||
.ToList();
|
||
return qualityStatistics;
|
||
}
|
||
|
||
public List<WorkOrderCarouseDto> GetWorkOrderCarouselBoardData(CarouselBoardQuery query)
|
||
{
|
||
// 查询条件构建
|
||
var queryable = Context.Queryable<ProWorkorder_v2>()
|
||
.Where(it => it.Remark3 == "是"); // 只获取有效的工单
|
||
|
||
if (query != null && query.StartTime.HasValue && query.EndTime.HasValue)
|
||
{
|
||
// 使用传入的时间范围进行查询
|
||
// 由于工单曲线上使用Year、Week、Date存储日期,需要进行转换处理
|
||
// 这里假设工单曲线上的Year、Week、Date组合可以映射到具体日期
|
||
|
||
// 找出时间范围内的所有日期
|
||
var dateRange = new List<DateTime>();
|
||
DateTime currentDate = query.StartTime.Value.Date;
|
||
DateTime endDate = query.EndTime.Value.Date;
|
||
|
||
while (currentDate <= endDate)
|
||
{
|
||
dateRange.Add(currentDate);
|
||
currentDate = currentDate.AddDays(1);
|
||
}
|
||
|
||
// 构建日期条件
|
||
var yearWeekDayConditions = dateRange.Select(date => new
|
||
{
|
||
Year = date.Year,
|
||
Week = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(
|
||
date,
|
||
CalendarWeekRule.FirstFourDayWeek,
|
||
DayOfWeek.Monday
|
||
),
|
||
Day = ((int)date.DayOfWeek == 0) ? 7 : (int)date.DayOfWeek
|
||
}).ToList();
|
||
|
||
// 使用OR条件连接不同日期的工单
|
||
var conditions = Expressionable.Create<ProWorkorder_v2>();
|
||
foreach (var yw in yearWeekDayConditions)
|
||
{
|
||
conditions.Or(it => it.Year == yw.Year && it.Week == yw.Week && it.Date == yw.Day);
|
||
}
|
||
|
||
queryable = queryable.Where(conditions.ToExpression());
|
||
}
|
||
else
|
||
{
|
||
// 默认使用前一天和当天的数据
|
||
DateTime yesterday = DateTime.Today.AddDays(-1);
|
||
DateTime today = DateTime.Today;
|
||
|
||
// 计算昨天的年、周、日信息
|
||
int yesterdayYear = yesterday.Year;
|
||
int yesterdayWeek = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(
|
||
yesterday,
|
||
CalendarWeekRule.FirstFourDayWeek,
|
||
DayOfWeek.Monday
|
||
);
|
||
int yesterdayDay = ((int)yesterday.DayOfWeek == 0) ? 7 : (int)yesterday.DayOfWeek;
|
||
|
||
// 计算今天的年、周、日信息
|
||
int todayYear = today.Year;
|
||
int todayWeek = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(
|
||
today,
|
||
CalendarWeekRule.FirstFourDayWeek,
|
||
DayOfWeek.Monday
|
||
);
|
||
int todayDay = ((int)today.DayOfWeek == 0) ? 7 : (int)today.DayOfWeek;
|
||
|
||
// 使用OR条件查询昨天和今天的工单
|
||
queryable = queryable.Where(it =>
|
||
(it.Year == yesterdayYear && it.Week == yesterdayWeek && it.Date == yesterdayDay) ||
|
||
(it.Year == todayYear && it.Week == todayWeek && it.Date == todayDay)
|
||
);
|
||
}
|
||
|
||
List<WorkOrderCarouseDto> workorders = queryable
|
||
.OrderBy(it => it.Sort) // 按序号排序
|
||
.Select(it => new WorkOrderCarouseDto
|
||
{
|
||
Id = it.Id, // 工单号
|
||
BlankNumber = it.BlankNumber, // 毛坯号
|
||
FinishedPartNumber = it.FinishedPartNumber, // 成品零件号
|
||
ProductDescription = it.ProductDescription, // 产品描述
|
||
Colour = it.Colour, // 颜色
|
||
Specifications = it.Specifications, // 规格
|
||
CodeNumber = it.CodeNumber, // 编码号
|
||
VehicleNumber = it.VehicleNumber, // 车数
|
||
PreviousNumber = it.PreviousNumber, // 上件数
|
||
CylinderNumber = it.CylinderNumber, // 双组号缸号
|
||
Remark1 = it.Remark1, // 备注1
|
||
Remark2 = it.Remark2, // 备注2
|
||
Remark3 = it.Remark3, // 备注3
|
||
Remark4 = it.Remark4, // 备注4
|
||
Sort = it.Sort, // 序号
|
||
ClientWorkorder = it.ClientWorkorder, // 客户工单号
|
||
Status = it.Status, // 状态
|
||
Year = it.Year, // 年
|
||
Week = it.Week, // 周
|
||
Date = it.Date // 日
|
||
})
|
||
.ToList();
|
||
|
||
return workorders;
|
||
}
|
||
}
|
||
}
|