日志

parent 079d5d4b
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentValidation.AspNetCore;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.Infrastructure;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Api.Controllers
{
[Route("api/[controller]")]
public class ModExtractController : Controller
{
private readonly ILogger<ModExtractController> logger;
private ModExtractService modExtractService;
private WebapiUrl url;
public ModExtractController(ModExtractService modExtractService,
public ModExtractController(
ILogger<ModExtractController> logger,
ModExtractService modExtractService,
IOptions<WebapiUrl> url)
{
this.logger = logger;
this.modExtractService = modExtractService;
this.url = url.Value;
}
......@@ -155,7 +160,7 @@ public ApiResponse AddItem([FromBody]ItemListRequest request)
[HttpPost]
public ApiResponse Items([FromBody]ModItemRequest request)
{
LogHelper.Information(url.HttpPost + "/modextract/items", "请求地址");
logger.LogInformation($"请求地址 {url.HttpPost}/modextract/items");
HttpHelper.HttpPost(url.HttpPost + "/modextract/items", JsonHelper.Serialize(request), true);
var list = modExtractService.Items(request.ModuleId.Value);
return new ApiResponse(ResponseType.OK, list);
......
......@@ -238,7 +238,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody]ExtractRequest r
request.Email = email;
//if (request.UseScheme == (int)UseTemplate.Config)
//{
LogHelper.Information("请求路径:" + url.HttpPost + "/extract/extract", "提取绩效数据");
logger.LogInformation("提取绩效数据请求路径:" + url.HttpPost + "/extract/extract");
HttpHelper.HttpPostNoRequest(url.HttpPost + "/extract/extract", JsonHelper.Serialize(request), true);
//}
//else
......@@ -307,14 +307,14 @@ public IActionResult DownFile([FromQuery]AllotRequest request)
[AllowAnonymous]
public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int hospitalId)
{
LogHelper.Information($"请求参数:allotId:{allotId} hospitalId:{hospitalId}", "保存提取文件");
logger.LogInformation($"保存提取文件请求参数:allotId:{allotId} hospitalId:{hospitalId}");
logger.LogInformation($"保存提取文件 参数:allotId:{allotId} hospitalId:{hospitalId}");
try
{
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
{
LogHelper.Error($"返回文件为空!", "保存提取文件");
logger.LogError($"返回文件为空!");
return new ApiResponse(ResponseType.Error, "上传文件无效");
}
......@@ -322,7 +322,7 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
LogHelper.Information($"保存路径:" + path, "保存提取文件");
logger.LogInformation($"保存提取文件保存路径:" + path);
using (var stream = file.OpenReadStream())
{
......@@ -330,7 +330,7 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
{
LogHelper.Error($"保存失败", "保存提取文件");
logger.LogError($"保存提取文件保存失败");
return new ApiResponse(ResponseType.Error, "保存失败");
}
}
......@@ -339,12 +339,12 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
allot.IsExtracting = 2;
if (string.IsNullOrEmpty(path) || !FileHelper.IsExistFile(path))
{
LogHelper.Information($"文件未保存成功,保存文件不存在!", "保存提取文件");
logger.LogInformation($"保存提取文件文件未保存成功,保存文件不存在!");
return new ApiResponse(ResponseType.Fail, "上传成功!");
}
if (!allotService.Update(allot))
{
LogHelper.Information($"更新文件路径失败!", "保存提取文件");
logger.LogInformation($"保存提取文件更新文件路径失败!");
return new ApiResponse(ResponseType.Fail, "上传成功!");
}
return new ApiResponse(ResponseType.OK, "上传成功!");
......@@ -352,7 +352,7 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
catch (Exception ex)
{
logger.LogInformation($"保存提取文件异常{ex.ToString()}");
LogHelper.Error($"保存失败:" + ex.ToString(), "保存提取文件");
logger.LogError($"保存提取文件保存失败:" + ex.ToString());
return new ApiResponse(ResponseType.Error, ex.Message);
}
}
......
......@@ -57,7 +57,6 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache, IHostingEnviron
context.Result = new ObjectResult(response);
var jsonData = JsonHelper.Serialize(context.Result);
_logger.LogInformation($"响应结果:{jsonData}");
LogHelper.Information($"请求地址:{context.HttpContext.Request.Path};响应结果:{jsonData}", "响应结果");
}
//记录response结果
......@@ -69,11 +68,10 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache, IHostingEnviron
if (executedContext.Result is ObjectResult)
{
LogHelper.Information(JsonHelper.Serialize(executedContext.Result), "响应结果");
_logger.LogInformation("响应结果" + JsonHelper.Serialize(executedContext.Result));
var objectResult = (ObjectResult)executedContext.Result;
var jsonData = JsonHelper.Serialize(objectResult.Value);
_logger.LogInformation($"响应结果:{jsonData}");
LogHelper.Information($"请求地址:{context.HttpContext.Request.Path};响应结果:{jsonData}", "响应结果");
_logger.LogInformation($"请求地址:{context.HttpContext.Request.Path};响应结果:{jsonData}");
}
}
}
......
......@@ -26,21 +26,21 @@ public Task OnExceptionAsync(ExceptionContext context)
_logger.LogWarning($"接口错误警告:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.Fail, context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Warning(JsonHelper.Serialize(response), "接口错误警告");
_logger.LogWarning("接口错误警告" + JsonHelper.Serialize(response));
}
else if (context.Exception is PerformanceTokenErrorException)
{
_logger.LogWarning($"Token Error:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.TokenError, context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Warning(JsonHelper.Serialize(response), "Token Error");
_logger.LogWarning("Token Error" + JsonHelper.Serialize(response));
}
else
{
_logger.LogError($"接口异常:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.Error, "接口内部异常", context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Error(JsonHelper.Serialize(response), "接口内部异常");
_logger.LogError("接口内部异常" + JsonHelper.Serialize(response));
}
return Task.CompletedTask;
}
......
......@@ -48,7 +48,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
LogHelper.Initialize(Configuration.GetSection("AppConnection:RedisConnectionString").Value, "MTEzMTAyMzEzNDYzMzY5MzE4NA");
//LogHelper.Initialize(Configuration.GetSection("AppConnection:RedisConnectionString").Value, "MTEzMTAyMzEzNDYzMzY5MzE4NA");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#region appsetting注入
......
......@@ -120,37 +120,35 @@ public void Index([FromBody]AllotRequest request)
[HttpPost]
public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request)
{
LogHelper.Information("请求参数:" + JsonHelper.Serialize(request), "提取绩效数据");
logger.LogInformation("请求参数:" + JsonHelper.Serialize(request));
logger.LogInformation("提取绩效数据请求参数:" + JsonHelper.Serialize(request));
//string filePath = newExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId);
string filePath = dfExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId);
if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath))
{
logger.LogInformation("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId = request.AllotId, hospitalId = request.HospitalId }));
LogHelper.Information("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId = request.AllotId, hospitalId = request.HospitalId }), "保存提取文件");
int i = 1;
while (i <= 5)
{
if (i == 5)
LogHelper.Information($"保存文件失败,已尝试执行五次,请联系开发人员!", "保存提取文件");
logger.LogInformation($"保存文件失败,已尝试执行五次,请联系开发人员!");
else
LogHelper.Information($"正在尝试第{i}次保存!", "保存提取文件");
logger.LogInformation($"正在尝试第{i}次保存!");
//保存文件
string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={request.AllotId}&hospitalId={request.HospitalId}", filePath);
LogHelper.Information("返回结果:" + JsonHelper.Serialize(retJson), "保存提取文件");
logger.LogInformation("保存提取文件返回结果:" + JsonHelper.Serialize(retJson));
logger.LogInformation(retJson);
var ret = JsonHelper.Deserialize<ApiResponse>(retJson);
if (ret != null && (int)ret.State == 1)
{
LogHelper.Information("保存成功!", "保存提取文件");
logger.LogInformation("保存提取文件保存成功!");
break;
}
i++;
}
}
else
LogHelper.Information($"提取文件不存在!", "保存提取文件");
logger.LogInformation($"保存提取文件提取文件不存在!");
}
#endregion
......
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.Infrastructure;
using Performance.Services;
......@@ -13,9 +14,13 @@ namespace Performance.Extract.Api.Controllers
[Route("api/[controller]")]
public class ModExtractController : Controller
{
private readonly ILogger<ModExtractController> logger;
private ModExtractService modExtractService;
public ModExtractController(ModExtractService modExtractService)
public ModExtractController(
ILogger<ModExtractController> logger,
ModExtractService modExtractService)
{
this.logger = logger;
this.modExtractService = modExtractService;
}
......@@ -59,7 +64,7 @@ public ApiResponse FeeSource([FromBody]ModModuleRequest request)
if (request.HospitalId == null || request.HospitalId.Value == 0)
return new ApiResponse(ResponseType.ParameterError, "HospitalId 参数错误!");
LogHelper.Information($"绩效考核项费用来源:{JsonHelper.Serialize(request)}", "请求参数");
logger.LogInformation($"请求参数绩效考核项费用来源:{JsonHelper.Serialize(request)}");
var list = modExtractService.FeeSource(request);
return new ApiResponse(ResponseType.OK, list);
}
......@@ -72,7 +77,7 @@ public ApiResponse FeeSource([FromBody]ModModuleRequest request)
[HttpPost]
public ApiResponse Items([FromBody]ModItemRequest request)
{
LogHelper.Information($"绩效收入模板配置项列表:{JsonHelper.Serialize(request)}", "请求参数");
logger.LogInformation($"绩效收入模板配置项列表:{JsonHelper.Serialize(request)}");
modExtractService.AddItems(request.ModuleId.Value);
return new ApiResponse(ResponseType.OK);
}
......
......@@ -26,21 +26,21 @@ public Task OnExceptionAsync(ExceptionContext context)
_logger.LogWarning($"接口错误警告:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.Fail, context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Warning(JsonHelper.Serialize(response), "接口错误警告");
_logger.LogWarning("接口错误警告" + JsonHelper.Serialize(response));
}
else if (context.Exception is PerformanceTokenErrorException)
{
_logger.LogWarning($"Token Error:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.TokenError, context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Warning(JsonHelper.Serialize(response), "Token Error");
_logger.LogWarning("Token Error" + JsonHelper.Serialize(response));
}
else
{
_logger.LogError($"接口异常:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.Error, "接口内部异常", context.Exception.Message);
context.Result = new ObjectResult(response);
LogHelper.Error(JsonHelper.Serialize(response), "接口内部异常");
_logger.LogError("接口内部异常" + JsonHelper.Serialize(response));
}
return Task.CompletedTask;
}
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper;
using FluentValidation;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Builder;
......@@ -23,6 +16,13 @@
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Performance.Extract.Api
{
......@@ -39,7 +39,7 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
LogHelper.Initialize(Configuration.GetSection("AppConnection:RedisConnectionString").Value, "MTEzMTAyMzEzNDYzMzY5MzE4NA");
//LogHelper.Initialize(Configuration.GetSection("AppConnection:RedisConnectionString").Value, "MTEzMTAyMzEzNDYzMzY5MzE4NA");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#region appsetting注入
......
using Performance.DtoModels;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
......@@ -12,6 +13,7 @@ namespace Performance.Services
{
public class ModExtractService : IAutoInjection
{
private readonly ILogger<ModExtractService> logger;
private PerforModextractRepository perforModextractRepository;
private PerforModitemRepository perforModitemRepository;
private PerforModmoduleRepository perforModmoduleRepository;
......@@ -20,7 +22,9 @@ public class ModExtractService : IAutoInjection
private PerforExtractRepository perforExtractRepository;
private PerforModdicRepository moddicRepository;
public ModExtractService(PerforModextractRepository perforModextractRepository,
public ModExtractService(
ILogger<ModExtractService> logger,
PerforModextractRepository perforModextractRepository,
PerforModitemRepository perforModitemRepository,
PerforModmoduleRepository perforModmoduleRepository,
PerforModspecialRepository perforModspecialRepository,
......@@ -28,6 +32,7 @@ public class ModExtractService : IAutoInjection
PerforExtractRepository perforExtractRepository,
PerforModdicRepository moddicRepository)
{
this.logger = logger;
this.perforModextractRepository = perforModextractRepository;
this.perforModitemRepository = perforModitemRepository;
this.perforModmoduleRepository = perforModmoduleRepository;
......@@ -425,13 +430,13 @@ public void AddItems(int moduleId)
var sqlconfig = moddicRepository.GetEntity(w => w.HospitalId == module.HospitalId && w.Type.Trim().ToLower() == "itemsql");
if (sqlconfig == null)
{
LogHelper.Information("医院配置信息未设置", "添加默认收费项");
logger.LogInformation("{0} 医院配置信息未设置", "添加默认收费项");
throw new PerformanceException($"医院配置信息未设置");
}
var hospitalConfig = perforHospitalconfigRepository.GetEntity(t => t.HospitalId == module.HospitalId && t.Id == sqlconfig.ConfigId);
if (hospitalConfig == null)
{
LogHelper.Information("医院配置信息未设置", "添加默认收费项");
logger.LogInformation("{0} 医院配置信息未设置", "添加默认收费项");
throw new PerformanceException($"医院配置信息未设置");
}
......@@ -450,7 +455,7 @@ public void AddItems(int moduleId)
ExtractId = module.ExtractId,
ReadOnly = 1
});
LogHelper.Information($"受影响行数{itemList.Count()}", "添加默认收费项");
logger.LogInformation($"添加默认收费项 受影响行数{itemList.Count()}");
perforModitemRepository.AddRange(itemList.ToArray());
module.IsGenerated = 1;
perforModmoduleRepository.Update(module);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment