Compare commits

..

No commits in common. "8ba22a343a7bbc6247a7bf0cf0440e23fe2ad4e0" and "062387e6a8a9789d85b1b0be95a71da047dbca6e" have entirely different histories.

13 changed files with 111 additions and 92 deletions

View File

@ -8,7 +8,6 @@ using Panda.DynamicWebApi;
using Panda.DynamicWebApi.Attributes;
using System.Diagnostics.CodeAnalysis;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc;
namespace IRaCIS.Core.Application
{
@ -18,8 +17,7 @@ namespace IRaCIS.Core.Application
#region 非泛型版本
[TypeFilter(typeof(UnifiedApiResultFilter))]
[Authorize, DynamicWebApi]
[Authorize, DynamicWebApi, UnifiedApiResultFilter]
public class BaseService : IBaseService, IDynamicWebApi
{
public IMapper _mapper { get; set; }
@ -85,8 +83,8 @@ namespace IRaCIS.Core.Application
}
[TypeFilter(typeof(UnifiedApiResultFilter))]
[Authorize, DynamicWebApi]
[Authorize, DynamicWebApi, UnifiedApiResultFilter]
public class BaseServiceTest<T> : IBaseServiceTest<T>, IDynamicWebApi where T : Entity
{
public IMapper _mapper { get; set; }

View File

@ -1,5 +1,4 @@
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
@ -35,10 +34,7 @@ namespace IRaCIS.Core.Application.Filter
{
var error = context.Exception as BusinessValidationFailedException;
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message, error!.Code,localizedInfo: $"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}"));
//warning 级别记录
//_logger.LogWarning($"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}");
context.Result = new JsonResult(ResponseOutput.NotOk(context.Exception.Message, error!.Code));
}
else if(context.Exception.GetType() == typeof(QueryBusinessObjectNotExistException))
{
@ -48,10 +44,12 @@ namespace IRaCIS.Core.Application.Filter
{
context.Result = new JsonResult(ResponseOutput.NotOk(_localizer["Project_ExceptionContactDeveloper"] + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/)
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException));
_logger.LogError(context.Exception.InnerException is null ? (context.Exception.Message + context.Exception.StackTrace) : (context.Exception.InnerException?.Message + context.Exception.InnerException?.StackTrace));
}
_logger.LogError(context.Exception.InnerException is null ? (context.Exception.Message + context.Exception.StackTrace) : (context.Exception.InnerException?.Message + context.Exception.InnerException?.StackTrace));
}
else
{

View File

@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Domain.Share;
using Microsoft.Extensions.Logging;
namespace IRaCIS.Application.Services.BusinessFilter
{
@ -11,12 +10,6 @@ namespace IRaCIS.Application.Services.BusinessFilter
/// </summary>
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
{
private readonly ILogger _logger;
public UnifiedApiResultFilter(ILogger<UnifiedApiResultFilter> logger)
{
_logger = logger;
}
/// <summary>
/// 异步版本
@ -38,11 +31,12 @@ namespace IRaCIS.Application.Services.BusinessFilter
var type = objectResult.Value?.GetType();
if (type != null && type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(ValueTuple<,>) || type.GetGenericTypeDefinition() == typeof(Tuple<,>)))
if ( type!=null&& type.IsGenericType&&(type.GetGenericTypeDefinition()==typeof(ValueTuple<,>)|| type.GetGenericTypeDefinition()==typeof(Tuple<,>)))
{
//报错
//var tuple = (object, object))objectResult.Value;
//var (val1, val2) = ((dynamic, dynamic))objectResult.Value;
//var apiResponse = ResponseOutput.Ok(val1, val2);
@ -62,19 +56,16 @@ namespace IRaCIS.Application.Services.BusinessFilter
objectResult.DeclaredType = apiResponse.GetType();
}
}
//如果是200 是IResponseOutput 记录下日志
else if (statusCode == 200 && (objectResult.Value is IResponseOutput))
//如果不是200 是IResponseOutput 不处理
else if (statusCode != 200 && (objectResult.Value is IResponseOutput))
{
var result = objectResult.Value as IResponseOutput;
_logger.LogWarning($"{result.LocalizedInfo}");
}
else if (statusCode != 200 && !(objectResult.Value is IResponseOutput))
else if(statusCode != 200&&!(objectResult.Value is IResponseOutput))
{
//---程序错误,请联系开发人员。
//---程序错误,请联系开发人员。
var apiResponse = ResponseOutput.NotOk(StaticData.International("UnifiedAPI_ProgramError"));
objectResult.Value = apiResponse;

View File

@ -53,9 +53,6 @@ namespace IRaCIS.Core.Application.Helper
jsonObject[item.Code] = item.Value;
StaticData.En_US_Dic[item.Code] = item.Value;
//日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[item.Code] = item.Description;
}
}
else
@ -74,7 +71,7 @@ namespace IRaCIS.Core.Application.Helper
}
}
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN,string description)
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN)
{
VerifyFolder();
@ -97,9 +94,6 @@ namespace IRaCIS.Core.Application.Helper
jsonObject[key] = value;
StaticData.En_US_Dic[key] = value;
//日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[key] = description;
}
else
{
@ -123,8 +117,7 @@ namespace IRaCIS.Core.Application.Helper
{
t.Code,
t.Value,
t.ValueCN,
t.Description
t.ValueCN
}).ToListAsync();
//组织成json 文件
@ -138,9 +131,6 @@ namespace IRaCIS.Core.Application.Helper
{
StaticData.En_US_Dic[tojsonItem.Code] = tojsonItem.Value;
StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN;
//日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[tojsonItem.Code] = tojsonItem.Description;
}
File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic));

View File

@ -711,7 +711,7 @@ namespace IRaCIS.Core.Application.Service
IsHaveGeneratedTask = t.SubjectVisitTaskList.Any(c => c.IsSelfAnalysis == false && c.TrialReadingCriterionId == trialReadingCriterionId),
DoctorUserList = t.SubjectDoctorList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.IsConfirmed && t.ArmEnum <= Arm.DoubleReadingArm2).Select(t => new UserSimpleInfo()
DoctorUserList = t.SubjectDoctorList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId && t.IsConfirmed && t.ArmEnum<=Arm.DoubleReadingArm2).Select(t => new UserSimpleInfo()
{
UserId = t.Id,
FullName = t.DoctorUser.FullName,

View File

@ -184,7 +184,7 @@ namespace IRaCIS.Core.Application.Service
if (addOrEditInternationalization.InternationalizationType == 1)
{
await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, addOrEditInternationalization.Value, addOrEditInternationalization.ValueCN,addOrEditInternationalization.Description);
await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, addOrEditInternationalization.Value, addOrEditInternationalization.ValueCN);
}
else
{

View File

@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using IRaCIS.Core.Application.Auth;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Infrastructure;
namespace IRaCIS.Application.Services
{

View File

@ -10,7 +10,6 @@
<ItemGroup>
<ProjectReference Include="..\IRaCIS.Core.Domain.Share\IRaCIS.Core.Domain.Share.csproj" />
<ProjectReference Include="..\IRaCIS.Core.Infrastructure\IRaCIS.Core.Infrastructure.csproj" />
</ItemGroup>

View File

@ -12,8 +12,6 @@ public static class StaticData
public static Dictionary<string, string> Zh_CN_Dic = new Dictionary<string, string>();
public static Dictionary<string, string> Log_Locoalize_Dic = new Dictionary<string, string>();
public static readonly string En_US_Json = "en-US.json";
public static readonly string Zh_CN_Json = "zh-CN.json";

View File

@ -11,8 +11,6 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="SharpCompress" Version="0.37.2" />

View File

@ -1,5 +1,4 @@
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.Extensions.Localization;
using System;
namespace IRaCIS.Core.Infrastructure
@ -9,24 +8,15 @@ namespace IRaCIS.Core.Infrastructure
public ApiResponseCodeEnum Code { get; set; }
public string LocalizedKey { get; set; }=string.Empty;
public BusinessValidationFailedException()
public BusinessValidationFailedException()
{
}
public BusinessValidationFailedException(LocalizedString message, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed) : base(message)
{
Code = code;
LocalizedKey=message.Name;
}
public BusinessValidationFailedException(string message, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed) : base(message)
{
Code = code;
Code = code;
}
}
}
}

View File

@ -16,9 +16,6 @@
/// 消息
/// </summary>
string ErrorMessage { get; }
public string LocalizedInfo { get; set; }
}
/// <summary>
@ -33,4 +30,13 @@
T Data { get; set; }
}
//public interface IResponseOutput<T,T2> : IResponseOutput
//{
// /// <summary>
// /// 返回数据
// /// </summary>
// T Data { get; }
// T2 OtherInfo { get; }
//}
}

View File

@ -1,7 +1,4 @@
using IRaCIS.Core.Domain.Share;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace IRaCIS.Core.Infrastructure.Extention
{
@ -10,10 +7,10 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// </summary>
public class ResponseOutput<T> : IResponseOutput<T>
{
/// <summary>
/// 是否成功标记
/// </summary>
public bool IsSuccess { get; private set; }
/// <summary>
/// 是否成功标记
/// </summary>
public bool IsSuccess { get; private set; }
public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK;
@ -28,20 +25,34 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
/// </summary>
[JsonProperty("Result")]
public T Data { get; set; }
public T Data { get; set; }
[JsonProperty("OtherInfo")]
public object OtherData { get; set; }
public string LocalizedInfo { get; set; }
public ResponseOutput<T> Ok(T data, object otherData, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
/// <summary>
/// 成功
/// </summary>
/// <param name="data">数据</param>
/// <param name="msg">消息</param>
//public ResponseOutput<T> Ok(T data, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
//{
// IsSuccess = true;
// Code = code;
// Data = data;
// ErrorMessage = msg;
// return this;
//}
public ResponseOutput<T> Ok(T data, object otherData, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
{
IsSuccess = true;
Code = code;
Data = data;
OtherData = otherData;
OtherData=otherData;
ErrorMessage = msg;
return this;
@ -53,13 +64,12 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// <param name="msg">提示消息</param>
/// <param name="data">数据</param>
/// <returns></returns>
public ResponseOutput<T> NotOk(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.OK, string localizedInfo = "")
public ResponseOutput<T> NotOk(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
{
IsSuccess = false;
Code = code;
Code = code;
ErrorMessage = msg;
Data = data;
LocalizedInfo = localizedInfo;
return this;
}
@ -67,6 +77,33 @@ namespace IRaCIS.Core.Infrastructure.Extention
}
//public class ResponseOutput<T, T2> : IResponseOutput<T, T2>
//{
// [JsonProperty("Result")]
// public T Data { get; private set; }
// public T2 OtherInfo { get; private set; }
// public bool IsSuccess { get; private set; }
// public ApiResponseCodeEnum Code { get; set; }
// public string ErrorMessage { get; private set; }
// public ResponseOutput<T, T2> Ok(T data, T2 otherInfo, string msg = "")
// {
// IsSuccess = true;
// Data = data;
// OtherInfo = otherInfo;
// ErrorMessage = msg;
// return this;
// }
//}
/// <summary>
/// 响应数据静态输出 为了代码简洁 不用每处都New
/// </summary>
@ -74,6 +111,23 @@ namespace IRaCIS.Core.Infrastructure.Extention
{
//public static IResponseOutput<T, T2> Ok<T, T2>(T data, T2 otherInfo, string msg = "")
//{
// return new ResponseOutput<T, T2>().Ok(data, otherInfo);
//}
/// <summary>
/// 成功 -----适合查询
/// </summary>
/// <param name="data">数据</param>
/// <param name="msg">消息</param>
/// <returns></returns>
//public static IResponseOutput<T> Ok<T>(T data = default, string msg = "")
//{
// return new ResponseOutput<T>().Ok(data, msg);
//}
public static IResponseOutput<T> Ok<T>(T data = default, object otherData = default, string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.OK)
{
return new ResponseOutput<T>().Ok(data, otherData, msg, code);
@ -93,11 +147,15 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// <param name="msg">消息</param>
/// <param name="data">数据</param>
/// <returns></returns>
public static IResponseOutput<T> NotOk<T>(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed, string localizedInfo = "")
public static IResponseOutput<T> NotOk<T>(string msg = "", T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
{
return new ResponseOutput<T>().NotOk(msg, data, code, localizedInfo);
return new ResponseOutput<T>().NotOk(msg, data, code);
}
//public static IResponseOutput<T> NotOk<T>( T data = default, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
//{
// return new ResponseOutput<T>().NotOk("", data, code);
//}
/// <summary>
/// 失败
@ -106,13 +164,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// <returns></returns>
public static IResponseOutput<string> NotOk(string msg = "", ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
{
return new ResponseOutput<string>().NotOk(msg, code: code);
}
public static IResponseOutput<string> NotOk(LocalizedString msg, ApiResponseCodeEnum code = ApiResponseCodeEnum.BusinessValidationFailed)
{
return new ResponseOutput<string>().NotOk(msg, code: code, localizedInfo: $"[{msg.Name}]:{StaticData.Log_Locoalize_Dic[msg.Name]}" );
return new ResponseOutput<string>().NotOk(msg,code:code);
}
public static IResponseOutput<string> DBNotExistIfNUll(object businessObject)
@ -120,7 +172,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
return new ResponseOutput<string>().NotOk($"The business object{businessObject.GetType().Name} does not exist in the database, or was deleted by someone else, or an incorrect parameter query caused");
}
/// <summary>
/// 根据布尔值返回结果 --适合删除
/// </summary>
@ -138,7 +190,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
/// <returns></returns>
public static IResponseOutput<T> Result<T>(bool success, T data = default)
{
return success ? Ok<T>(data) : NotOk<T>("Saved failed", data);
return success ? Ok<T>(data) : NotOk<T>("Saved failed",data);
}
///// <summary>