根据新需求更改
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using MoviconWebApi.Entities;
|
||||
using MoviconWebApi.Entities;
|
||||
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace MoviconWebApi.API.ClearDataQrApi
|
||||
/// <param name="request">查询请求参数</param>
|
||||
/// <param name="freeSql">FreeSql实例</param>
|
||||
/// <returns>清洗数据列表</returns>
|
||||
public static async Task<List<ClearDataQrResponse>> GetClearDataByQr(
|
||||
public static async Task<(List<ClearDataQrResponse> Data, long Total)> GetClearDataByQr(
|
||||
ClearDataQrRequest request,
|
||||
IFreeSql freeSql)
|
||||
{
|
||||
@@ -34,11 +34,19 @@ namespace MoviconWebApi.API.ClearDataQrApi
|
||||
query = query.Where(x => x.part_qrid == request.PartQRCode);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
query = query.OrderByDescending(x => x.CreateTime);
|
||||
// 统计总数
|
||||
var total = await query.CountAsync();
|
||||
|
||||
// 执行查询并映射到响应模型
|
||||
var result = await query.ToListAsync(x => new ClearDataQrResponse
|
||||
// 参数兜底
|
||||
var pageNo = request.PageNo <= 0 ? 1 : request.PageNo;
|
||||
var pageSize = request.PageSize <= 0 ? 100 : request.PageSize;
|
||||
if (pageSize > 100) pageSize = 100;
|
||||
|
||||
// 按创建时间降序排序 + 分页 + 映射
|
||||
var result = await query
|
||||
.OrderByDescending(x => x.CreateTime)
|
||||
.Page(pageNo, pageSize)
|
||||
.ToListAsync(x => new ClearDataQrResponse
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceName = x.DeviceName,
|
||||
@@ -71,7 +79,7 @@ namespace MoviconWebApi.API.ClearDataQrApi
|
||||
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
|
||||
return result;
|
||||
return (result ?? new List<ClearDataQrResponse>(), total);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Azure;
|
||||
using Azure;
|
||||
using FastEndpoints;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MoviconWebApi.Common;
|
||||
@@ -36,18 +36,29 @@ namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataList = await Data.GetClearDataByQr(request, _freeSql);
|
||||
// 参数兜底
|
||||
if (request.PageNo <= 0) request.PageNo = 1;
|
||||
if (request.PageSize <= 0) request.PageSize = 100;
|
||||
if (request.PageSize > 100) request.PageSize = 100;
|
||||
|
||||
if (dataList == null || dataList.Count == 0)
|
||||
var result = await Data.GetClearDataByQr(request, _freeSql);
|
||||
var dataList = result.Item1;
|
||||
var total = result.Item2;
|
||||
|
||||
var resp = ApiResponse<List<ClearDataQrResponse>>.Success(
|
||||
dataList ?? new List<ClearDataQrResponse>(),
|
||||
(dataList != null && dataList.Count > 0) ? "请求成功" : "暂无数据");
|
||||
|
||||
resp.pagination = new MoviconWebApi.Common.Pagination
|
||||
{
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Success(
|
||||
new List<ClearDataQrResponse>(), "暂无数据");// "暂无数据"
|
||||
}
|
||||
else
|
||||
{
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Success(
|
||||
dataList, "查询成功");// "查询成功"
|
||||
}
|
||||
total = total,
|
||||
count = dataList?.Count ?? 0,
|
||||
pageNo = request.PageNo,
|
||||
totalPage = request.PageSize > 0 ? (int)Math.Ceiling((double)total / request.PageSize) : 0,
|
||||
pageSize = request.PageSize
|
||||
};
|
||||
|
||||
Response = resp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -57,7 +68,8 @@ namespace MoviconWebApi.API.ClearDataQrApi
|
||||
Logger.LogError(ex, "根据二维码查询清洗数据失败");
|
||||
Response = ApiResponse<List<ClearDataQrResponse>>.Error(
|
||||
"500",
|
||||
"服务器内部错误"
|
||||
"服务器内部错误",
|
||||
new List<ClearDataQrResponse>()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
namespace MoviconWebApi.API.ClearDataQrApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 清洗数据二维码查询请求模型
|
||||
@@ -14,6 +14,16 @@
|
||||
/// 部件二维码
|
||||
/// </summary>
|
||||
public string? PartQRCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前页码(从1开始)
|
||||
/// </summary>
|
||||
public int PageNo { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 分页大小
|
||||
/// </summary>
|
||||
public int PageSize { get; set; } = 100;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user