添加项目文件。
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
257
MoviconWebApi/API/ClearDataQrApi/Endpoint.cs
Normal file
257
MoviconWebApi/API/ClearDataQrApi/Endpoint.cs
Normal file
@@ -0,0 +1,257 @@
|
||||
using Azure;
|
||||
using FastEndpoints;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MoviconWebApi.Common;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据设备编号和部件二维码查询清洗数据端点
|
||||
/// </summary>
|
||||
public class GetByQrEndpoint : Endpoint<ClearDataQrRequest, ApiResponse<List<ClearDataQrResponse>>>
|
||||
{
|
||||
private readonly IFreeSql _freeSql;
|
||||
|
||||
public GetByQrEndpoint(IFreeSql freeSql)
|
||||
{
|
||||
_freeSql = freeSql;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/cleardata-qr/list");
|
||||
AllowAnonymous();
|
||||
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "根据设备编号和部件二维码查询清洗数据";
|
||||
s.Description = "可以通过设备编号、部件二维码或两者组合查询清洗数据";
|
||||
s.Response<ApiResponse<List<ClearDataQrResponse>>>(200, "成功返回清洗数据列表");
|
||||
s.Response(404, "未找到数据");
|
||||
s.Response(500, "服务器内部错误");
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ClearDataQrRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataList = await Data.GetClearDataByQr(request, _freeSql);
|
||||
|
||||
if (dataList == null || dataList.Count == 0)
|
||||
{
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Success(
|
||||
new List<ClearDataQrResponse>(), "暂无数据");// "暂无数据"
|
||||
}
|
||||
else
|
||||
{
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Success(
|
||||
dataList, "查询成功");// "查询成功"
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Logger.LogError(ex, "根据二维码查询清洗数据失败");
|
||||
//await Send.ErrorsAsync(500, ct);
|
||||
|
||||
Logger.LogError(ex, "根据二维码查询清洗数据失败");
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Error(
|
||||
"500",
|
||||
"服务器内部错误"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询清洗数据端点
|
||||
/// </summary>
|
||||
public class GetPagedByQrEndpoint : Endpoint<ClearDataQrPagedRequest, ClearDataQrPagedResponse>
|
||||
{
|
||||
private readonly IFreeSql _freeSql;
|
||||
|
||||
public GetPagedByQrEndpoint(IFreeSql freeSql)
|
||||
{
|
||||
_freeSql = freeSql;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/cleardata-qr/paged");
|
||||
AllowAnonymous();
|
||||
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "分页查询清洗数据";
|
||||
s.Description = "根据设备编号和部件二维码分页查询清洗数据";
|
||||
s.Response<ClearDataQrPagedResponse>(200, "成功返回分页数据");
|
||||
s.Response(500, "服务器内部错误");
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ClearDataQrPagedRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证分页参数
|
||||
if (request.PageIndex < 1)
|
||||
request.PageIndex = 1;
|
||||
if (request.PageSize < 1)
|
||||
request.PageSize = 20;
|
||||
if (request.PageSize > 100)
|
||||
request.PageSize = 100;
|
||||
|
||||
// 调用Data层方法,获取元组返回值
|
||||
var (data, total) = await Data.GetClearDataPagedByQr(request, _freeSql);
|
||||
|
||||
// 构建响应对象
|
||||
Response = new ClearDataQrPagedResponse
|
||||
{
|
||||
Items = data,
|
||||
TotalCount = total,
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "分页查询清洗数据失败");
|
||||
await Send.ErrorsAsync(500, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新清洗数据端点
|
||||
/// </summary>
|
||||
public class GetLatestByQrEndpoint : Endpoint<ClearDataQrRequest, ClearDataQrResponse>
|
||||
{
|
||||
private readonly IFreeSql _freeSql;
|
||||
|
||||
public GetLatestByQrEndpoint(IFreeSql freeSql)
|
||||
{
|
||||
_freeSql = freeSql;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/cleardata-qr/latest");
|
||||
AllowAnonymous();
|
||||
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "获取最新的清洗数据";
|
||||
s.Description = "根据设备编号和部件二维码获取最新的一条清洗数据";
|
||||
s.Response<ClearDataQrResponse>(200, "成功返回最新清洗数据");
|
||||
s.Response(404, "未找到数据");
|
||||
s.Response(500, "服务器内部错误");
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ClearDataQrRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 调用重构后的方法,直接传递request对象
|
||||
var latestData = await Data.GetLatestClearData(request, _freeSql);
|
||||
|
||||
if (latestData == null)
|
||||
{
|
||||
//await Send.NotFoundAsync(ct);
|
||||
Response = latestData ?? new ClearDataQrResponse();
|
||||
}
|
||||
else
|
||||
{
|
||||
Response = latestData;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "获取最新清洗数据失败");
|
||||
await Send.ErrorsAsync(500, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据部件二维码获取所有清洗记录端点
|
||||
/// </summary>
|
||||
public class GetByPartQrCodeRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 部件二维码(必填)
|
||||
/// </summary>
|
||||
public string PartQRCode { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class GetByPartQrCodeEndpoint : Endpoint<GetByPartQrCodeRequest, List<ClearDataQrResponse>>
|
||||
{
|
||||
private readonly IFreeSql _freeSql;
|
||||
|
||||
public GetByPartQrCodeEndpoint(IFreeSql freeSql)
|
||||
{
|
||||
_freeSql = freeSql;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/cleardata-qr/by-qrcode/{PartQRCode}");
|
||||
AllowAnonymous();
|
||||
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "根据部件二维码获取所有清洗记录";
|
||||
s.Description = "仅根据部件二维码查询该部件的所有清洗历史记录";
|
||||
s.Response<List<ClearDataQrResponse>>(200, "成功返回清洗数据列表");
|
||||
s.Response(400, "请求参数错误");
|
||||
s.Response(404, "未找到数据");
|
||||
s.Response(500, "服务器内部错误");
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetByPartQrCodeRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证参数
|
||||
if (string.IsNullOrWhiteSpace(request.PartQRCode))
|
||||
{
|
||||
AddError("PartQRCode", "部件二维码不能为空");
|
||||
await Send.ErrorsAsync(400, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用重构后的方法
|
||||
var dataList = await Data.GetClearDataByPartQRCode(request.PartQRCode, _freeSql);
|
||||
|
||||
if (dataList == null || dataList.Count == 0)
|
||||
{
|
||||
//await Send.NotFoundAsync(ct);
|
||||
Response = dataList ?? new List<ClearDataQrResponse>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Response = dataList;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "根据部件二维码查询清洗数据失败");
|
||||
await Send.ErrorsAsync(500, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
99
MoviconWebApi/API/ClearDataQrApi/Mapper.cs
Normal file
99
MoviconWebApi/API/ClearDataQrApi/Mapper.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据映射器
|
||||
/// </summary>
|
||||
public static class Mapper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将数据库实体映射到响应模型
|
||||
/// </summary>
|
||||
/// <param name="entity">数据库实体</param>
|
||||
/// <returns>响应模型</returns>
|
||||
public static ClearDataQrResponse ToResponse(dynamic entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
|
||||
var response = new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = entity.DeviceCode?.ToString(),
|
||||
DeviceName = entity.DeviceName?.ToString(),
|
||||
program_process = entity.program_process?.ToString(),
|
||||
vehicle_model = entity.vehicle_model?.ToString(),
|
||||
locomotive_number = entity.locomotive_number?.ToString(),
|
||||
repair_process = entity.repair_process?.ToString(),
|
||||
component_name = entity.component_name?.ToString(),
|
||||
part_position = entity.part_position?.ToString(),
|
||||
part_num = entity.part_num?.ToString(),
|
||||
part_qrid = entity.part_qrid?.ToString(),
|
||||
Test_FrameworkPerModelCleaningDuration = entity.Test_FrameworkPerModelCleaningDuration?.ToString(),
|
||||
Test_FrameworkPerModelCleaningAgentUsage = entity.Test_FrameworkPerModelCleaningAgentUsage?.ToString(),
|
||||
Test_FrameworkPerModelWaterUsage = entity.Test_FrameworkPerModelWaterUsage?.ToString(),
|
||||
WaterTank_Temp = entity.WaterTank_Temp?.ToString(),
|
||||
AgentTank_Temp = entity.AgentTank_Temp?.ToString(),
|
||||
SoakingTank1_Temp = entity.SoakingTank1_Temp?.ToString(),
|
||||
SoakingTank2_Temp = entity.SoakingTank2_Temp?.ToString()
|
||||
};
|
||||
|
||||
// 处理时间字段
|
||||
if (entity.CreateTime != null)
|
||||
{
|
||||
if (entity.CreateTime is DateTime dt)
|
||||
{
|
||||
response.CreateTime = dt.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
else
|
||||
{
|
||||
response.CreateTime = entity.CreateTime.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化日期时间
|
||||
/// </summary>
|
||||
/// <param name="dateTimeString">日期时间字符串</param>
|
||||
/// <returns>格式化后的字符串</returns>
|
||||
public static string FormatDateTime(string dateTimeString)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dateTimeString))
|
||||
return dateTimeString;
|
||||
|
||||
if (DateTime.TryParse(dateTimeString, out DateTime dateTime))
|
||||
{
|
||||
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
return dateTimeString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析数值类型
|
||||
/// </summary>
|
||||
/// <param name="value">原始值</param>
|
||||
/// <returns>数值或null</returns>
|
||||
public static double? ParseDouble(object value)
|
||||
{
|
||||
if (value == null) return null;
|
||||
|
||||
if (value is double d)
|
||||
return d;
|
||||
|
||||
if (value is float f)
|
||||
return f;
|
||||
|
||||
if (value is decimal dec)
|
||||
return (double)dec;
|
||||
|
||||
if (value is int i)
|
||||
return i;
|
||||
|
||||
if (double.TryParse(value.ToString(), out double result))
|
||||
return result;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
109
MoviconWebApi/API/ClearDataQrApi/Models.cs
Normal file
109
MoviconWebApi/API/ClearDataQrApi/Models.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 清洗数据二维码查询请求模型
|
||||
/// </summary>
|
||||
public class ClearDataQrRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备编号
|
||||
/// </summary>
|
||||
public string? DeviceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部件二维码
|
||||
/// </summary>
|
||||
public string? PartQRCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清洗数据响应模型
|
||||
/// </summary>
|
||||
public class ClearDataQrResponse
|
||||
{
|
||||
public string? DeviceCode { get; set; }
|
||||
public string? DeviceName { get; set; }
|
||||
public string? program_process { get; set; }
|
||||
public string? vehicle_model { get; set; }
|
||||
public string? locomotive_number { get; set; }
|
||||
public string? repair_process { get; set; }
|
||||
public string? component_name { get; set; }
|
||||
public string? part_position { get; set; }
|
||||
public string? part_num { get; set; }
|
||||
public string? part_qrid { get; set; }
|
||||
public string? Test_FrameworkProgramProcessPercentage { get; set; }
|
||||
public string? Test_FrameworkProgramProcess { get; set; }
|
||||
public string? Test_FrameworkPerModelCleaningDuration { get; set; }
|
||||
public string? Test_FrameworkPerModelCleaningAgentUsage { get; set; }
|
||||
public string? Test_FrameworkPerModelWaterUsage { get; set; }
|
||||
public string? WaterTank_Temp { get; set; }
|
||||
public string? AgentTank_Temp { get; set; }
|
||||
public string? WaterTank_Level { get; set; }
|
||||
public string? AgentTank_Level { get; set; }
|
||||
public string? SoakingTank1_Temp { get; set; }
|
||||
public string? SoakingTank2_Temp { get; set; }
|
||||
public string? Test_WaterTankHeat { get; set; }
|
||||
public string? Test_WaterTankAdd { get; set; }
|
||||
public string? Test_CleaningAgentTankHeat { get; set; }
|
||||
public string? Test_CleaningAgentTankAdd { get; set; }
|
||||
public string? Test_ElectricSurveillance { get; set; }
|
||||
public string? Test_SteamSurveillance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public string? CreateTime { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询请求模型
|
||||
/// </summary>
|
||||
public class ClearDataQrPagedRequest : ClearDataQrRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 页码(从1开始)
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 每页数据量
|
||||
/// </summary>
|
||||
public int PageSize { get; set; } = 20;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分页响应模型
|
||||
/// </summary>
|
||||
public class ClearDataQrPagedResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据列表
|
||||
/// </summary>
|
||||
public List<ClearDataQrResponse> Items { get; set; } = new List<ClearDataQrResponse>();
|
||||
|
||||
/// <summary>
|
||||
/// 总记录数
|
||||
/// </summary>
|
||||
public long TotalCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前页码
|
||||
/// </summary>
|
||||
public int PageIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 每页数量
|
||||
/// </summary>
|
||||
public int PageSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
public int TotalPages => PageSize > 0 ? (int)Math.Ceiling((double)TotalCount / PageSize) : 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user