update 解决dapper结果无法转为小写的问题
This commit is contained in:
@@ -4075,7 +4075,7 @@
|
|||||||
<summary>
|
<summary>
|
||||||
删除字典值 id数组传入
|
删除字典值 id数组传入
|
||||||
</summary>
|
</summary>
|
||||||
<param name="input"></param>
|
<param name="idList"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Ewide.Core.Service.SysDictDataService.UpdateDictData(Ewide.Core.Service.UpdateDictDataInput)">
|
<member name="M:Ewide.Core.Service.SysDictDataService.UpdateDictData(Ewide.Core.Service.UpdateDictDataInput)">
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
using System;
|
using Dapper;
|
||||||
|
using Furion.DatabaseAccessor;
|
||||||
|
using Mapster;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Dynamic.Core;
|
using System.Linq.Dynamic.Core;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapper;
|
|
||||||
using Furion.DatabaseAccessor;
|
|
||||||
using Furion.DatabaseAccessor.Extensions;
|
|
||||||
using Mapster;
|
|
||||||
|
|
||||||
namespace Ewide.Core.Extension
|
namespace Ewide.Core.Extension
|
||||||
{
|
{
|
||||||
@@ -44,6 +40,13 @@ namespace Ewide.Core.Extension
|
|||||||
return orderStr;
|
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()
|
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);
|
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);
|
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,
|
param: param,
|
||||||
transaction: transaction,
|
transaction: transaction,
|
||||||
commandTimeout: commandTimeout,
|
commandTimeout: commandTimeout,
|
||||||
commandType: commandType
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Ewide.Core
|
namespace Ewide.Core
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,19 @@ namespace Ewide.Core
|
|||||||
[SkipScan, UnifyModel(typeof(XnRestfulResult<>))]
|
[SkipScan, UnifyModel(typeof(XnRestfulResult<>))]
|
||||||
public class XnRestfulResultProvider : IUnifyResultProvider
|
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>
|
||||||
/// 异常返回值
|
/// 异常返回值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,7 +41,7 @@ namespace Ewide.Core
|
|||||||
// 解析异常信息
|
// 解析异常信息
|
||||||
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
|
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
|
||||||
|
|
||||||
return new JsonResult(new XnRestfulResult<object>
|
return DisplayJson(new XnRestfulResult<object>
|
||||||
{
|
{
|
||||||
Code = StatusCode,
|
Code = StatusCode,
|
||||||
Success = false,
|
Success = false,
|
||||||
@@ -93,7 +107,7 @@ namespace Ewide.Core
|
|||||||
else if (context.Result is EmptyResult) data = null;
|
else if (context.Result is EmptyResult) data = null;
|
||||||
else return 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
|
Code = context.Result is EmptyResult ? StatusCodes.Status204NoContent : StatusCodes.Status200OK, // 处理没有返回值情况 204
|
||||||
Success = true,
|
Success = true,
|
||||||
@@ -114,7 +128,7 @@ namespace Ewide.Core
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IActionResult OnValidateFailed(ActionExecutingContext context, ModelStateDictionary modelStates, IEnumerable<ValidateFailedModel> validationResults, string validateFailedMessage)
|
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,
|
Code = StatusCodes.Status400BadRequest,
|
||||||
Success = false,
|
Success = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user