添加项目文件。
This commit is contained in:
293
MoviconWebApi/API/ClearDataQrApi/Data.cs
Normal file
293
MoviconWebApi/API/ClearDataQrApi/Data.cs
Normal file
@@ -0,0 +1,293 @@
|
||||
using MoviconWebApi.Entities;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 清洗数据二维码查询数据访问层
|
||||
/// </summary>
|
||||
public static class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据设备编号和部件二维码查询清洗数据
|
||||
/// </summary>
|
||||
/// <param name="request">查询请求参数</param>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
/// <returns>清洗数据列表</returns>
|
||||
public static async Task<List<ClearDataQrResponse>> GetClearDataByQr(
|
||||
ClearDataQrRequest request,
|
||||
IFreeSql freeSql)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用FreeSql的Fluent API构建查询
|
||||
var query = freeSql.Select<ClearData>();
|
||||
|
||||
// 添加设备编号条件
|
||||
if (!string.IsNullOrWhiteSpace(request.DeviceCode))
|
||||
{
|
||||
query = query.Where(x => x.DeviceCode == request.DeviceCode);
|
||||
}
|
||||
|
||||
// 添加部件二维码条件
|
||||
if (!string.IsNullOrWhiteSpace(request.PartQRCode))
|
||||
{
|
||||
query = query.Where(x => x.part_qrid == request.PartQRCode);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
query = query.OrderByDescending(x => x.CreateTime);
|
||||
|
||||
// 执行查询并映射到响应模型
|
||||
var result = await query.ToListAsync(x => new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceName = x.DeviceName,
|
||||
program_process = x.program_process,
|
||||
vehicle_model = x.vehicle_model,
|
||||
locomotive_number = x.locomotive_number,
|
||||
repair_process = x.repair_process,
|
||||
component_name = x.component_name,
|
||||
part_position = x.part_position,
|
||||
part_num = x.part_num,
|
||||
part_qrid = x.part_qrid,
|
||||
AgentTank_Level = x.AgentTank_Level,
|
||||
Test_CleaningAgentTankAdd = x.Test_CleaningAgentTankAdd,
|
||||
Test_CleaningAgentTankHeat = x.Test_CleaningAgentTankHeat,
|
||||
Test_FrameworkPerModelCleaningAgentUsage = x.Test_FrameworkPerModelCleaningAgentUsage,
|
||||
Test_FrameworkPerModelWaterUsage = x.Test_FrameworkPerModelWaterUsage,
|
||||
WaterTank_Temp = x.WaterTank_Temp,
|
||||
AgentTank_Temp = x.AgentTank_Temp,
|
||||
SoakingTank1_Temp = x.SoakingTank1_Temp,
|
||||
SoakingTank2_Temp = x.SoakingTank2_Temp,
|
||||
Test_ElectricSurveillance = x.Test_ElectricSurveillance,
|
||||
Test_FrameworkPerModelCleaningDuration = x.Test_FrameworkPerModelCleaningDuration,
|
||||
Test_FrameworkProgramProcess = x.Test_FrameworkProgramProcess,
|
||||
Test_FrameworkProgramProcessPercentage = x.Test_FrameworkProgramProcessPercentage,
|
||||
Test_SteamSurveillance = x.Test_SteamSurveillance,
|
||||
Test_WaterTankAdd = x.Test_WaterTankAdd,
|
||||
Test_WaterTankHeat = x.Test_WaterTankHeat,
|
||||
WaterTank_Level = x.WaterTank_Level,
|
||||
|
||||
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常(在生产环境中应使用适当的日志框架)
|
||||
Console.WriteLine($"查询清洗数据时出错: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询清洗数据
|
||||
/// </summary>
|
||||
/// <param name="request">分页查询请求参数</param>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
/// <returns>分页数据和总数</returns>
|
||||
public static async Task<(List<ClearDataQrResponse> Data, long Total)> GetClearDataPagedByQr(
|
||||
ClearDataQrPagedRequest request,
|
||||
IFreeSql freeSql)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用FreeSql的Fluent API构建查询
|
||||
var query = freeSql.Select<ClearData>();
|
||||
|
||||
// 添加设备编号条件
|
||||
if (!string.IsNullOrWhiteSpace(request.DeviceCode))
|
||||
{
|
||||
query = query.Where(x => x.DeviceCode == request.DeviceCode);
|
||||
}
|
||||
|
||||
// 添加部件二维码条件
|
||||
if (!string.IsNullOrWhiteSpace(request.PartQRCode))
|
||||
{
|
||||
query = query.Where(x => x.part_qrid == request.PartQRCode);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
query = query.OrderByDescending(x => x.CreateTime);
|
||||
|
||||
// 获取总数
|
||||
var total = await query.CountAsync();
|
||||
|
||||
// 分页查询并映射到响应模型
|
||||
var data = await query
|
||||
.Page(request.PageIndex, request.PageSize)
|
||||
.ToListAsync(x => new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceName = x.DeviceName,
|
||||
program_process = x.program_process,
|
||||
vehicle_model = x.vehicle_model,
|
||||
locomotive_number = x.locomotive_number,
|
||||
repair_process = x.repair_process,
|
||||
component_name = x.component_name,
|
||||
part_position = x.part_position,
|
||||
part_num = x.part_num,
|
||||
part_qrid = x.part_qrid,
|
||||
AgentTank_Level = x.AgentTank_Level,
|
||||
Test_CleaningAgentTankAdd = x.Test_CleaningAgentTankAdd,
|
||||
Test_CleaningAgentTankHeat = x.Test_CleaningAgentTankHeat,
|
||||
Test_FrameworkPerModelCleaningAgentUsage = x.Test_FrameworkPerModelCleaningAgentUsage,
|
||||
Test_FrameworkPerModelWaterUsage = x.Test_FrameworkPerModelWaterUsage,
|
||||
WaterTank_Temp = x.WaterTank_Temp,
|
||||
AgentTank_Temp = x.AgentTank_Temp,
|
||||
SoakingTank1_Temp = x.SoakingTank1_Temp,
|
||||
SoakingTank2_Temp = x.SoakingTank2_Temp,
|
||||
Test_ElectricSurveillance = x.Test_ElectricSurveillance,
|
||||
Test_FrameworkPerModelCleaningDuration = x.Test_FrameworkPerModelCleaningDuration,
|
||||
Test_FrameworkProgramProcess = x.Test_FrameworkProgramProcess,
|
||||
Test_FrameworkProgramProcessPercentage = x.Test_FrameworkProgramProcessPercentage,
|
||||
Test_SteamSurveillance = x.Test_SteamSurveillance,
|
||||
Test_WaterTankAdd = x.Test_WaterTankAdd,
|
||||
Test_WaterTankHeat = x.Test_WaterTankHeat,
|
||||
WaterTank_Level = x.WaterTank_Level,
|
||||
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
|
||||
return (data, total);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常(在生产环境中应使用适当的日志框架)
|
||||
Console.WriteLine($"分页查询清洗数据时出错: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新的清洗数据记录
|
||||
/// </summary>
|
||||
/// <param name="request">查询请求(可包含设备编号筛选)</param>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
/// <returns>最新的清洗数据记录,如果没有则返回null</returns>
|
||||
public static async Task<ClearDataQrResponse?> GetLatestClearData(
|
||||
ClearDataQrRequest request,
|
||||
IFreeSql freeSql)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用FreeSql的Fluent API构建查询
|
||||
var query = freeSql.Select<ClearData>();
|
||||
|
||||
// 添加设备编号条件(如果提供)
|
||||
if (!string.IsNullOrWhiteSpace(request.DeviceCode))
|
||||
{
|
||||
query = query.Where(x => x.DeviceCode == request.DeviceCode);
|
||||
}
|
||||
|
||||
// 添加部件二维码条件(如果提供)
|
||||
if (!string.IsNullOrWhiteSpace(request.PartQRCode))
|
||||
{
|
||||
query = query.Where(x => x.part_qrid == request.PartQRCode);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序,取第一条
|
||||
var result = await query
|
||||
.OrderByDescending(x => x.CreateTime)
|
||||
.Limit(1)
|
||||
.FirstAsync(x => new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceName = x.DeviceName,
|
||||
program_process = x.program_process,
|
||||
vehicle_model = x.vehicle_model,
|
||||
locomotive_number = x.locomotive_number,
|
||||
repair_process = x.repair_process,
|
||||
component_name = x.component_name,
|
||||
part_position = x.part_position,
|
||||
part_num = x.part_num,
|
||||
part_qrid = x.part_qrid,
|
||||
AgentTank_Level = x.AgentTank_Level,
|
||||
Test_CleaningAgentTankAdd = x.Test_CleaningAgentTankAdd,
|
||||
Test_CleaningAgentTankHeat = x.Test_CleaningAgentTankHeat,
|
||||
Test_FrameworkPerModelCleaningAgentUsage = x.Test_FrameworkPerModelCleaningAgentUsage,
|
||||
Test_FrameworkPerModelWaterUsage = x.Test_FrameworkPerModelWaterUsage,
|
||||
WaterTank_Temp = x.WaterTank_Temp,
|
||||
AgentTank_Temp = x.AgentTank_Temp,
|
||||
SoakingTank1_Temp = x.SoakingTank1_Temp,
|
||||
SoakingTank2_Temp = x.SoakingTank2_Temp,
|
||||
Test_ElectricSurveillance = x.Test_ElectricSurveillance,
|
||||
Test_FrameworkPerModelCleaningDuration = x.Test_FrameworkPerModelCleaningDuration,
|
||||
Test_FrameworkProgramProcess = x.Test_FrameworkProgramProcess,
|
||||
Test_FrameworkProgramProcessPercentage = x.Test_FrameworkProgramProcessPercentage,
|
||||
Test_SteamSurveillance = x.Test_SteamSurveillance,
|
||||
Test_WaterTankAdd = x.Test_WaterTankAdd,
|
||||
Test_WaterTankHeat = x.Test_WaterTankHeat,
|
||||
WaterTank_Level = x.WaterTank_Level,
|
||||
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常(在生产环境中应使用适当的日志框架)
|
||||
Console.WriteLine($"获取最新清洗数据时出错: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据部件二维码获取所有相关的清洗记录
|
||||
/// </summary>
|
||||
/// <param name="partQRCode">部件二维码</param>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
/// <returns>清洗数据列表</returns>
|
||||
public static async Task<List<ClearDataQrResponse>> GetClearDataByPartQRCode(
|
||||
string partQRCode,
|
||||
IFreeSql freeSql)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用FreeSql的Fluent API构建查询
|
||||
var result = await freeSql.Select<ClearData>()
|
||||
.Where(x => x.part_qrid == partQRCode)
|
||||
.OrderByDescending(x => x.CreateTime)
|
||||
.ToListAsync(x => new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceName = x.DeviceName,
|
||||
program_process = x.program_process,
|
||||
vehicle_model = x.vehicle_model,
|
||||
locomotive_number = x.locomotive_number,
|
||||
repair_process = x.repair_process,
|
||||
component_name = x.component_name,
|
||||
part_position = x.part_position,
|
||||
part_num = x.part_num,
|
||||
part_qrid = x.part_qrid,
|
||||
AgentTank_Level = x.AgentTank_Level,
|
||||
Test_CleaningAgentTankAdd = x.Test_CleaningAgentTankAdd,
|
||||
Test_CleaningAgentTankHeat = x.Test_CleaningAgentTankHeat,
|
||||
Test_FrameworkPerModelCleaningAgentUsage = x.Test_FrameworkPerModelCleaningAgentUsage,
|
||||
Test_FrameworkPerModelWaterUsage = x.Test_FrameworkPerModelWaterUsage,
|
||||
WaterTank_Temp = x.WaterTank_Temp,
|
||||
AgentTank_Temp = x.AgentTank_Temp,
|
||||
SoakingTank1_Temp = x.SoakingTank1_Temp,
|
||||
SoakingTank2_Temp = x.SoakingTank2_Temp,
|
||||
Test_ElectricSurveillance = x.Test_ElectricSurveillance,
|
||||
Test_FrameworkPerModelCleaningDuration = x.Test_FrameworkPerModelCleaningDuration,
|
||||
Test_FrameworkProgramProcess = x.Test_FrameworkProgramProcess,
|
||||
Test_FrameworkProgramProcessPercentage = x.Test_FrameworkProgramProcessPercentage,
|
||||
Test_SteamSurveillance = x.Test_SteamSurveillance,
|
||||
Test_WaterTankAdd = x.Test_WaterTankAdd,
|
||||
Test_WaterTankHeat = x.Test_WaterTankHeat,
|
||||
WaterTank_Level = x.WaterTank_Level,
|
||||
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常(在生产环境中应使用适当的日志框架)
|
||||
Console.WriteLine($"根据二维码查询清洗数据时出错: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user