记录异常

parent d30ad5a2
using Dapper;
using MassTransit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MySql.Data.MySqlClient;
using Performance.DtoModels;
......@@ -16,10 +17,12 @@ namespace Performance.Services
public class DapperService : IAutoInjection
{
private readonly IOptions<AppConnection> _options;
private readonly ILogger<DapperService> _logger;
public DapperService(IOptions<AppConnection> options)
public DapperService(IOptions<AppConnection> options, ILogger<DapperService> logger)
{
_options = options;
_logger = logger;
}
#region 数据静态存储
......@@ -57,8 +60,10 @@ public void FreezeAllot(int allotId)
i++;
} while (QueryDiff(allotId) < -50 && i <= 3);
}
catch
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
void HanderFreeze(int allotId)
......@@ -101,8 +106,9 @@ public void SecondUseTempRestore()
}
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
......@@ -124,8 +130,9 @@ public void ClearAllot()
connection.Execute(sql, commandTimeout: 60 * 60);
}
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
......@@ -133,46 +140,52 @@ public void ClearAllot()
public void SyncDataToResult(int allotId)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
try
{
string sql = $@"call proc_sync_datatoresult({allotId})";
connection.Execute(sql, commandTimeout: 60 * 60);
}
catch (Exception)
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
public void PerEmployeeBackup(int allotId)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
try
{
string sql = $@"call proc_per_employee_backup({allotId})";
connection.Execute(sql, commandTimeout: 60 * 60);
}
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
#region 数据提取
public IEnumerable<per_dept_dic> GetAccountBasicAccountingUnit(int hospitalId)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
try
{
string sql = @"select * from
(
select distinct
......@@ -189,13 +202,15 @@ from per_dept_dic
where ifnull(accountingunit, '无')<>'无'
order by unittype,accountingunit;";
return connection.Query<per_dept_dic>(sql, new { hospitalId }, commandTimeout: 60 * 60);
}
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
public IEnumerable<DeptdicResponse> GetDepartments(int allotId)
{
......@@ -243,8 +258,9 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
return result.OrderBy(w => w.IsVerify).ThenByDescending(t => t.CreateTime).ThenBy(t => t.Department);
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
......@@ -258,23 +274,26 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
/// <param name="allotId"></param>
public void RestoreSecondAllot()
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
try
{
string sql = $@"call proc_restore_secondallot()";
connection.Execute(sql, commandTimeout: 60 * 60);
}
catch (Exception)
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
public IEnumerable<dynamic> QuerySecondPrintHead(int allotId, string unitType, string accountingUnit)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
......@@ -283,9 +302,17 @@ public IEnumerable<dynamic> QuerySecondPrintHead(int allotId, string unitType, s
return connection.Query(sql, new { allotId, unitType = unitType.Replace("行政后勤", "行政工勤"), accountingUnit }, commandTimeout: 60 * 60);
}
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
public IEnumerable<dynamic> QuerySecondPrintRow(int allotId, string unitType, string accountingUnit)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
......@@ -293,8 +320,16 @@ public IEnumerable<dynamic> QuerySecondPrintRow(int allotId, string unitType, st
return connection.Query(sql, new { allotId, unitType = unitType.Replace("行政后勤", "行政工勤"), accountingUnit }, commandTimeout: 60 * 60);
}
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
public IEnumerable<dynamic> QueryTableStructure(string tableName)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
......@@ -303,19 +338,35 @@ public IEnumerable<dynamic> QueryTableStructure(string tableName)
return connection.Query(sql, new { tableName }, commandTimeout: 60 * 60);
}
}
public IEnumerable<dynamic> QueryView(string viewName,int allotID)
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
public IEnumerable<dynamic> QueryView(string viewName, int allotID)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
string sql = $@"select * from {viewName} where allotID = @allotID";
return connection.Query(sql,new { allotID }, commandTimeout: 60 * 60);
return connection.Query(sql, new { allotID }, commandTimeout: 60 * 60);
}
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
public int UpdateAllotStates(int allotId, int states, string remark, int generate = 0)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
......@@ -324,5 +375,11 @@ public int UpdateAllotStates(int allotId, int states, string remark, int generat
return connection.Execute(sql, new { allotId, states, remark, generate }, commandTimeout: 60 * 60);
}
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
}
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