update 解决dapper结果无法转为小写的问题

This commit is contained in:
2021-05-20 15:26:28 +08:00
parent 6cbb663e97
commit 4ec43c220e
3 changed files with 43 additions and 31 deletions

View File

@@ -4075,7 +4075,7 @@
<summary>
删除字典值 id数组传入
</summary>
<param name="input"></param>
<param name="idList"></param>
<returns></returns>
</member>
<member name="M:Ewide.Core.Service.SysDictDataService.UpdateDictData(Ewide.Core.Service.UpdateDictDataInput)">

View File

@@ -1,15 +1,11 @@
using System;
using Dapper;
using Furion.DatabaseAccessor;
using Mapster;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Mapster;
namespace Ewide.Core.Extension
{
@@ -44,6 +40,13 @@ namespace Ewide.Core.Extension
return orderStr;
}
private static string PageSqlBuilder(string sql, PageInputBase input)
{
var orderStr = OrderBuilder(input);
var r = "SELECT * FROM (" + sql + ") T " + (string.IsNullOrEmpty(orderStr) ? string.Empty : "ORDER BY " + orderStr) + " LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString();
return r;
}
public static Task<PagedList<T>> ToPageData<T>(this IQueryable<T> source, PageInputBase input) where T : new()
{
return source.OrderBy(OrderBuilder<T>(input)).ToPagedListAsync(input.PageNo, input.PageSize);
@@ -54,31 +57,26 @@ namespace Ewide.Core.Extension
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>()).ToPagedListAsync(input.PageNo, input.PageSize);
}
public static Task<IEnumerable<dynamic>> QueryPageData(this IDapperRepository source, string sql, PageInputBase input, object param = null, System.Data.IDbTransaction transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null)
public static Task<IEnumerable<dynamic>> QueryPageData(this IDapperRepository source, string sql, PageInputBase input, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return source.QueryAsync(PageSqlBuild(sql,input),
return source.QueryAsync(
PageSqlBuilder(sql, input),
param: param,
transaction: transaction,
commandTimeout: commandTimeout,
commandType: commandType
);
}
public static Task<IEnumerable<T>> QueryPageData<T>(this IDapperRepository source, string sql, PageInputBase input, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return source.QueryAsync<T>(
PageSqlBuilder(sql, input),
param: param,
transaction: transaction,
commandTimeout: commandTimeout,
commandType: commandType
);
}
public static Task<IEnumerable<T>> QueryPageData<T>(this IDapperRepository source, string sql, PageInputBase input, object param = null, System.Data.IDbTransaction transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null)
{
return source.QueryAsync<T>(sql,
param: param,
transaction: transaction,
commandTimeout: commandTimeout,
commandType: commandType
);
}
private static string PageSqlBuild(string sql , PageInputBase input)
{
var orderStr = OrderBuilder(input);
var r = "SELECT * FROM (" + sql + ") T " + (string.IsNullOrEmpty(orderStr) ? string.Empty : "Order by " + orderStr) + " LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString();
return r;
}
}
}

View File

@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Ewide.Core
{
@@ -17,6 +18,19 @@ namespace Ewide.Core
[SkipScan, UnifyModel(typeof(XnRestfulResult<>))]
public class XnRestfulResultProvider : IUnifyResultProvider
{
private IActionResult DisplayJson(object data)
{
return new ContentResult
{
Content = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(),
DateFormatString = "yyyy-MM-dd HH:mm:ss"
}),
ContentType = "application/json"
};
}
/// <summary>
/// 异常返回值
/// </summary>
@@ -27,7 +41,7 @@ namespace Ewide.Core
// 解析异常信息
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = StatusCode,
Success = false,
@@ -93,7 +107,7 @@ namespace Ewide.Core
else if (context.Result is EmptyResult) data = null;
else return null;
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = context.Result is EmptyResult ? StatusCodes.Status204NoContent : StatusCodes.Status200OK, // 处理没有返回值情况 204
Success = true,
@@ -114,7 +128,7 @@ namespace Ewide.Core
/// <returns></returns>
public IActionResult OnValidateFailed(ActionExecutingContext context, ModelStateDictionary modelStates, IEnumerable<ValidateFailedModel> validationResults, string validateFailedMessage)
{
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = StatusCodes.Status400BadRequest,
Success = false,