添加项目文件。
This commit is contained in:
83
MoviconWebApi/API/ClearDataApi/Data.cs
Normal file
83
MoviconWebApi/API/ClearDataApi/Data.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using MoviconWebApi.Entities;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataApi
|
||||
{
|
||||
public static class Data
|
||||
{
|
||||
internal static async Task<List<ClearDataResponse>?> GetClearData(ClearDataRequest request, IFreeSql freeSql)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 构建查询
|
||||
var query = freeSql.Select<ClearData>();
|
||||
|
||||
// 根据设备编号过滤
|
||||
if (!string.IsNullOrWhiteSpace(request.DeviceCode))
|
||||
{
|
||||
query = query.Where(x => x.DeviceCode == request.DeviceCode);
|
||||
}
|
||||
|
||||
// 根据开始时间过滤
|
||||
if (!string.IsNullOrWhiteSpace(request.StartTime) && DateTime.TryParse(request.StartTime, out DateTime startTime))
|
||||
{
|
||||
query = query.Where(x => x.CreateTime >= startTime);
|
||||
}
|
||||
|
||||
// 根据结束时间过滤
|
||||
if (!string.IsNullOrWhiteSpace(request.EndTime) && DateTime.TryParse(request.EndTime, out DateTime endTime))
|
||||
{
|
||||
query = query.Where(x => x.CreateTime <= endTime);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
query = query.OrderByDescending(x => x.CreateTime);
|
||||
|
||||
// 执行查询并映射到响应模型
|
||||
var result = await query.ToListAsync(x => new ClearDataResponse
|
||||
{
|
||||
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}");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
100
MoviconWebApi/API/ClearDataApi/Endpoint.cs
Normal file
100
MoviconWebApi/API/ClearDataApi/Endpoint.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Azure;
|
||||
using Azure.Core;
|
||||
using FastEndpoints;
|
||||
using MoviconWebApi.API.ClearDataQrApi;
|
||||
using MoviconWebApi.Common;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取清洗数据端点
|
||||
/// </summary>
|
||||
public class Endpoint : Endpoint<ClearDataRequest, ApiResponse<List<ClearDataResponse>>>
|
||||
{
|
||||
private readonly IFreeSql _freeSql;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数,注入FreeSql实例
|
||||
/// </summary>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
public Endpoint(IFreeSql freeSql)
|
||||
{
|
||||
_freeSql = freeSql;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
// 配置路由,支持GET和POST两种方式
|
||||
//Post("/cleardata/list");
|
||||
Get("/cleardata/listbycode");
|
||||
|
||||
// 允许匿名访问(根据实际需求可以改为需要认证)
|
||||
AllowAnonymous();
|
||||
|
||||
// 配置摘要信息(用于Swagger文档)
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "获取清洗数据列表";
|
||||
s.Description = "根据设备编号、开始时间、结束时间查询清洗数据";
|
||||
s.Response< ApiResponse<List<ClearDataResponse>>>(200, "成功返回清洗数据列表");
|
||||
s.Response(404, "未找到数据");
|
||||
s.Response(500, "服务器内部错误");
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ClearDataRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 调用Data层方法获取数据
|
||||
var dataList = await Data.GetClearData(request, _freeSql);
|
||||
|
||||
if (dataList == null || dataList.Count == 0)
|
||||
{
|
||||
// 未找到数据,返回404
|
||||
//await Send.NotFoundAsync(ct);
|
||||
//Response = dataList ?? new List<ClearDataQrResponse>();
|
||||
|
||||
//await Send.OkAsync(new List<ClearDataResponse>(), ct);
|
||||
|
||||
// 没有数据
|
||||
Response = ApiResponse<List<ClearDataResponse>>.Success(
|
||||
new List<ClearDataResponse>(),
|
||||
"暂无数据"
|
||||
);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//await Send.OkAsync(dataList, ct);
|
||||
|
||||
// 现在的代码
|
||||
Response = ApiResponse<List<ClearDataResponse>>.Success(
|
||||
dataList,
|
||||
"查询成功"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录错误日志
|
||||
Logger.LogError(ex, "获取清洗数据失败");
|
||||
|
||||
// 返回错误响应
|
||||
Response = ApiResponse<List<ClearDataResponse>>.Error(
|
||||
"500",
|
||||
"服务器内部错误"
|
||||
);
|
||||
|
||||
//// 记录错误日志
|
||||
//Logger.LogError(ex, "获取清洗数据失败");
|
||||
|
||||
//// 返回500错误
|
||||
//await Send.ErrorsAsync(500, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
33
MoviconWebApi/API/ClearDataApi/Mapper.cs
Normal file
33
MoviconWebApi/API/ClearDataApi/Mapper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Azure.Core;
|
||||
using FastEndpoints;
|
||||
using MoviconWebApi.Entities;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataApi
|
||||
{
|
||||
public class Mapper : Mapper<ClearDataRequest, ClearDataResponse, ClearData>
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求体映射为数据库实体
|
||||
/// </summary>
|
||||
/// <param name="r"></param>
|
||||
/// <returns></returns>
|
||||
public override ClearData ToEntity(ClearDataRequest r)
|
||||
{
|
||||
return new ClearData()
|
||||
{
|
||||
AgentTank_Level = "",
|
||||
};
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 数据库实体类映射为返回体,我这里返回体就是一个string,就没必要用
|
||||
///// </summary>
|
||||
///// <param name="e"></param>
|
||||
///// <returns></returns>
|
||||
//public override async Task<ClearDataResponse> FromEntityAsync(ClearData Model )
|
||||
//{
|
||||
// return await base.FromEntityAsync(Model,new CancellationToken());
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
61
MoviconWebApi/API/ClearDataApi/Models.cs
Normal file
61
MoviconWebApi/API/ClearDataApi/Models.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataApi
|
||||
{
|
||||
public class ClearDataRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备编号
|
||||
/// </summary>
|
||||
public string? DeviceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public string? StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public string? EndTime { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class ClearDataResponse
|
||||
{
|
||||
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; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string? CreateTime { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user