Commit e9062ff7 by 钟博

职称加载、重新加载

parent bb491167
...@@ -28,27 +28,38 @@ public class SubsidyController : ControllerBase ...@@ -28,27 +28,38 @@ public class SubsidyController : ControllerBase
public async Task<ApiResponse> GetAllot() public async Task<ApiResponse> GetAllot()
{ {
var allots = await _service.GetAllot(); var allots = await _service.GetAllot();
return new ApiResponse(Status.Ok, allots); return new ApiResponse(Status.Ok, allots);
} }
// 职称查询 // 职称查询
[HttpGet("{allotId}/jobtitle")] [HttpGet("{allotId}/jobtitle/{hospitalId}")]
public async Task<ApiResponse> GetJobTitle(int allotId) public async Task<ApiResponse> GetJobTitle(int allotId, int hospitalId)
{ {
throw new NotImplementedException(); _service.GetHrpJobTitle(allotId, hospitalId,false);
var jobTitle = await _service.GetJobTitle(allotId, hospitalId);
return new ApiResponse(Status.Ok, jobTitle);
} }
// 重新查询职称 // 重新查询职称
[HttpPost("{allotId}/reset-jobtitle")] [HttpPost("{allotId}/reset-jobtitle/{hospitalId}")]
public async Task ResetJobTitle(int allotId) public async Task<ApiResponse> ResetJobTitle(int allotId, int hospitalId)
{ {
throw new NotImplementedException(); // 调取配置的SQL语句
// 执行SQL 获取结果
// 将结果存储到sub_subsidy中
// 查询sub_subsidy表职称去重
// 将去重数据插入sub_jobtitle
_service.GetHrpJobTitle(allotId, hospitalId,true);
var jobTitle = await _service.GetJobTitle(allotId, hospitalId);
return new ApiResponse(Status.Ok, jobTitle);
} }
// 职称标准保存 // 职称标准保存
[HttpPost("{allotId}/jobtitle")] [HttpPost("{allotId}/jobtitle")]
public async Task SaveJobTitle(int allotId) public async Task SaveJobTitle(int allotId,List<sub_jobtitle> jobtitles)
{ {
_service.SaveJobTitle(allotId,jobtitles);
throw new NotImplementedException(); throw new NotImplementedException();
} }
......
...@@ -13,8 +13,8 @@ public enum Status ...@@ -13,8 +13,8 @@ public enum Status
public enum DatabaseType public enum DatabaseType
{ {
MySQL, MySQL=1,
SqlServer, SqlServer=2,
Oracle, Oracle=3,
} }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.Subsidy.Services
{
public class ex_config
{
public int Id { get; set; }
public int HospitalId { get; set; }
public string DbSource { get; set; }
public string DbName { get; set; }
public string DbUser { get; set; }
public string DbPassword { get; set; }
public int DataBaseType { get; set; }
public string Remark { get; set; }
}
}
namespace Performance.Subsidy.Services namespace Performance.Subsidy.Services
{ {
public class ex_script { } public class ex_script
{
public int Id { get; set; }
public string ExecScript { get; set; }
public int ConfigId { get; set; }
public int IsEnable { get; set; }
public string Remark { get; set; }
}
} }
using Dapper; using Dapper;
using Microsoft.Extensions.Configuration;
using Performance.Subsidy.Services.Repository; using Performance.Subsidy.Services.Repository;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using AutoMapper;
using System;
namespace Performance.Subsidy.Services namespace Performance.Subsidy.Services
{ {
public class SubsidyService public class SubsidyService
{ {
private readonly ConnectionFactory _factory; private readonly ConnectionFactory _factory;
private readonly ConnectionStringBuilder builder;
private readonly int _commandTimeout; private readonly int _commandTimeout;
public SubsidyService( public SubsidyService(
ConnectionFactory factory) ConnectionFactory factory,
ConnectionStringBuilder builder)
{ {
_factory = factory; _factory = factory;
this.builder = builder;
_commandTimeout = 60 * 5; _commandTimeout = 60 * 5;
} }
public async Task<IEnumerable<view_allot>> GetAllot() public async Task<IEnumerable<view_allot>> GetAllot()
{ {
return await _factory.CreateDefault().QueryAsync<view_allot>("SELECT * FROM view_allot"); return await _factory.CreateDefault().QueryAsync<view_allot>("SELECT * FROM view_allot;");
}
public void GetAllot(int allotId)
{
var allot = _factory.CreateDefault().Query<view_allot>($@"select * frrom view_allot where AllotID=@allotId;", new { allotId });
if (allot == null || !allot.Any()) throw new Exception("allotId无效");
}
public async Task<IEnumerable<sub_jobtitle>> GetJobTitle(int allotId, int hospitalId)
{
var jobTitleSql = $@"select * from sub_jobtitle where AllotID=@allotId;";
var jobTitles = _factory.CreateDefault().Query<sub_jobtitle>(jobTitleSql, new { allotId });
if (jobTitles != null || jobTitles.Any()) return jobTitles;
jobTitles = _factory.CreateDefault().Query<sub_jobtitle>($@"SELECT DISTINCT JobTitle FROM db_performance_subsidy.sub_subsidy where AllotID=@allotId;", new { allotId }).Select(t => new sub_jobtitle { JobTitle = t.JobTitle, BasicPerforFee = t.BasicPerforFee ?? 0 });
var allotOder = _factory.CreateDefault().Query<view_allot>($@"SELECT * from view_allot a WHERE a.HospitalId=@HospitalId ORDER BY a.`Year`,a.`Month`;", new { hospitalId }).ToList();
if (!allotOder.Any()) return jobTitles;
var allot = allotOder.FirstOrDefault(t => t.AllotId == allotId);
if (allot == null) throw new Exception("有问题");
var index = allotOder.IndexOf(allot);
if (index == 0) return jobTitles;
var prevAllot = allotOder[index - 1];
var jobTitle = _factory.CreateDefault().Query<sub_jobtitle>(jobTitleSql, new { prevAllot.AllotId });
return jobTitle.Select(t => new sub_jobtitle { JobTitle = t.JobTitle, BasicPerforFee = t.BasicPerforFee ?? 0 }) ?? jobTitles;
}
public void GetHrpJobTitle(int allotId, int hospitalId, bool isRefresh)
{
var config = _factory.CreateDefault().QueryFirst<ex_config>("select * from ex_config where hospitalId=@hospitalId", new { hospitalId });
var connectionString = builder.GetConnectionString(config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword);
var connection = _factory.Create(config.DataBaseType, connectionString);
var hrp = _factory.CreateDefault().QueryFirst<ex_script>("select * from ex_script;");
var res = connection.Query<sub_subsidy>(hrp.ExecScript, commandTimeout: _commandTimeout);
var subsidy = _factory.CreateDefault().Query<sub_subsidy>("select * from sub_subsidy where AllotID=@allotId;", new { allotId });
if (subsidy.Any() && isRefresh == false) return;
//删除:在点击重新加载时删除记录重新插入
_factory.CreateDefault().Execute("delete from sub_subsidy where AllotID=@allotId;delete from sub_jobtitle where AllotID=@allotId;", new { allotId });
var jobtitle = res.Select(t => new { t.AllotID, t.JobTitle }).Distinct();
var sql = $@"insert into sub_jobtitle(AllotID,JobTitle,BasicPerforFee) values (@allotId,@JobTitle,@BasicPerforFee);";
_factory.CreateDefault().Execute(sql, jobtitle);
sql = $@"insert into sub_subsidy (AllotID,Department,PersonnelNumber,PersonnelName,JobTitle,Attendance) values (@allotId,@Department,@PersonnelNumber,@PersonnelName,@JobTitle,@Attendance);";
var exmper = res.ToList().Select(t => new
{
AllotID = allotId,
t.Department,
t.PersonnelNumber,
t.PersonnelName,
t.JobTitle,
t.Attendance
});
var i = _factory.CreateDefault().Execute(sql, exmper);
}
#region zb
/*
public bool SaveJobTitle(int allotId, List<sub_jobtitle> jobtitles)
{
GetAllot(allotId);
var sql = $@"update sub_jobtitle set BasicPerforFee =@BasicPerforFee where AllotID=@allotId and JobTitle=@JobTitle;";
var result = jobtitles.Select(t => new { AllotID = allotId, t.JobTitle, t.BasicPerforFee });
_factory.CreateDefault().Execute(sql, result);
_factory.CreateDefault().Execute($@"call proc_performance_subsidy(@AllotId);", new { allotId });
return true;
} }
public async Task<IEnumerable<sub_jobtitle>> GetJobTitle(int allotId) public IEnumerable<sub_subsidy> GetJobTitle(int allotId)
{ {
return await _factory.CreateDefault().QueryAsync<sub_jobtitle>("SELECT * FROM sub_jobtitle WHERE AllotID=@allotId", new { allotId }); GetAllot(allotId);
var subsidy = _factory.CreateDefault().Query<sub_subsidy>($@"select * from sub_subsidy where AllotId=@allotId", new { allotId });
return subsidy;
}
public bool SaveSubsidy(int allotId, List<sub_subsidy> subsidys)
{
GetAllot(allotId);
var result = subsidys.Select(t => new { AllotId = allotId, t.RealAmount, t.PersonnelNumber });
_factory.CreateDefault().Execute(@$"update sub_subsidy set RealAmount=@RealAmount where AllotID=@AllotID and PersonnelNumber=@PersonnelNumber;",result);
_factory.CreateDefault().Execute($@"call proc_performance_sync(@allotId);", new { allotId });
return true;
} }
*/
#endregion
} }
} }
...@@ -23,17 +23,17 @@ public IDbConnection CreateDefault() ...@@ -23,17 +23,17 @@ public IDbConnection CreateDefault()
return new MySqlConnection(_connectionString); return new MySqlConnection(_connectionString);
} }
public IDbConnection Create(DatabaseType type, string connectionString) public IDbConnection Create(int type, string connectionString)
{ {
try try
{ {
switch (type) switch (type)
{ {
case DatabaseType.MySQL: case (int)DatabaseType.MySQL:
return new MySqlConnection(connectionString); return new MySqlConnection(connectionString);
case DatabaseType.SqlServer: case (int)DatabaseType.SqlServer:
return new SqlConnection(connectionString); return new SqlConnection(connectionString);
case DatabaseType.Oracle: case (int)DatabaseType.Oracle:
return new OracleConnection(connectionString); return new OracleConnection(connectionString);
default: default:
throw new ArgumentException("DatabaseType类型不支持"); throw new ArgumentException("DatabaseType类型不支持");
......
...@@ -17,18 +17,18 @@ public ConnectionStringBuilder(IOptions<ConnectionStringTemplates> options) ...@@ -17,18 +17,18 @@ public ConnectionStringBuilder(IOptions<ConnectionStringTemplates> options)
_options = options; _options = options;
} }
public string GetConnectionString(DatabaseType type, string ip, string database, string uid, string pwd) public string GetConnectionString(int type, string ip, string database, string uid, string pwd)
{ {
switch (type) switch (type)
{ {
case DatabaseType.MySQL: case (int)DatabaseType.MySQL:
return string.Format(_options.Value.MySQLTemplates, ip, database, uid, pwd); return string.Format(_options.Value.MySQLTemplates, ip, database, uid, pwd);
case DatabaseType.SqlServer: case (int)DatabaseType.SqlServer:
return string.Format(_options.Value.MySQLTemplates, ip, database, uid, pwd); return string.Format(_options.Value.SqlServerTemplates, ip, database, uid, pwd);
case DatabaseType.Oracle: case (int)DatabaseType.Oracle:
return string.Format(_options.Value.MySQLTemplates, ip, database, uid, pwd); return string.Format(_options.Value.OracleTemplates, ip, database, uid, pwd);
default: default:
throw new ArgumentException("DatabaseType类型不支持"); throw new ArgumentException("DatabaseType类型不支持");
......
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