Commit b53eca2a by 李承祥

bug -- 部分列头无法获取

parent f118e442
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Services; using Performance.Services;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -21,17 +24,20 @@ public class TemplateController : Controller ...@@ -21,17 +24,20 @@ public class TemplateController : Controller
private HospitalService hospitalService; private HospitalService hospitalService;
private IHostingEnvironment evn; private IHostingEnvironment evn;
private ClaimService claim; private ClaimService claim;
private Application application;
public TemplateController(TemplateService templateService, public TemplateController(TemplateService templateService,
HospitalService hospitalService, HospitalService hospitalService,
ExtractService extractService, ExtractService extractService,
IHostingEnvironment evn, IHostingEnvironment evn,
ClaimService claim) ClaimService claim,
IOptions<Application> options)
{ {
this.templateService = templateService; this.templateService = templateService;
this.extractService = extractService; this.extractService = extractService;
this.hospitalService = hospitalService; this.hospitalService = hospitalService;
this.evn = evn; this.evn = evn;
this.claim = claim; this.claim = claim;
this.application = options.Value;
} }
/// <summary> /// <summary>
...@@ -80,7 +86,7 @@ public ApiResponse Import([FromForm] IFormCollection form) ...@@ -80,7 +86,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
}; };
if (templateService.InsertFirst(template)) if (templateService.InsertFirst(template))
{ {
templateService.SendEmail(path, $"{hospital.HosName}首次上传模板", "上传成功"); templateService.SendEmail(application.Receiver.ToList(), path, $"{hospital.HosName}首次上传模板", "上传成功");
} }
} }
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
...@@ -95,7 +101,16 @@ public ApiResponse Import([FromForm] IFormCollection form) ...@@ -95,7 +101,16 @@ public ApiResponse Import([FromForm] IFormCollection form)
[HttpPost] [HttpPost]
public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Delete"), FromBody]HospitalRequest request) public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Delete"), FromBody]HospitalRequest request)
{ {
var hospital = hospitalService.GetHopital(request.ID);
if (hospital == null)
return new ApiResponse(ResponseType.Fail, "hospitalid不存在");
var filePath = extractService.ExtractData(request.ID); var filePath = extractService.ExtractData(request.ID);
if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath))
{
var user = claim.At(request.Token);
templateService.SendEmail(new List<string> { user.Mail }, filePath, $"{hospital.HosName}提取数据", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。");
}
return new ApiResponse(ResponseType.OK, "OK", filePath); return new ApiResponse(ResponseType.OK, "OK", filePath);
} }
} }
......
...@@ -93,8 +93,8 @@ public string ExtractData(int hospitalId) ...@@ -93,8 +93,8 @@ public string ExtractData(int hospitalId)
FileHelper.CreateDirectory(dpath); FileHelper.CreateDirectory(dpath);
string path = Path.Combine(dpath, $"绩效数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx"); string path = Path.Combine(dpath, $"绩效数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx");
//根据SHEET页信息,列头信息,创建EXCEL文件 //根据SHEET页信息,列头信息,创建EXCEL文件
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospitalId)) if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospitalId, out string filepath))
return dpath; return filepath;
throw new PerformanceException("绩效数据提取失败"); throw new PerformanceException("绩效数据提取失败");
} }
...@@ -109,7 +109,7 @@ public string ExtractData(int hospitalId) ...@@ -109,7 +109,7 @@ public string ExtractData(int hospitalId)
/// <param name="sheetList"></param> /// <param name="sheetList"></param>
/// <param name="hospitalConfig"></param> /// <param name="hospitalConfig"></param>
/// <param name="hospitalId"></param> /// <param name="hospitalId"></param>
private bool WriteExcel(string newpath, string originalPath, List<PerSheet> sheetList, sys_hospitalconfig hospitalConfig, int hospitalId) private bool WriteExcel(string newpath, string originalPath, List<PerSheet> sheetList, sys_hospitalconfig hospitalConfig, int hospitalId, out string filepath)
{ {
if (string.IsNullOrEmpty(originalPath)) if (string.IsNullOrEmpty(originalPath))
throw new PerformanceException($"{originalPath}文件路径无效"); throw new PerformanceException($"{originalPath}文件路径无效");
...@@ -123,25 +123,10 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee ...@@ -123,25 +123,10 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
{ {
var importSheet = workbook.GetSheet(sheet.SheetName); var importSheet = workbook.GetSheet(sheet.SheetName);
if (importSheet == null) continue; if (importSheet == null) continue;
//var importSheet = workbook.CreateSheet(sheet.SheetName); if (sheet.PerHeader == null) continue;
//创建列头
//foreach (var pointRow in sheet.PerHeader.Select(t => t.PointRow).Distinct().OrderBy(t => t))
//{
// var importRow = importSheet.CreateRow(pointRow);
// //写入单元格
// foreach (var perHeader in sheet.PerHeader.Where(t => t.PointRow == pointRow))
// {
// importRow.CreateCell(perHeader.PointCell).SetCellValue(perHeader.CellValue);
// //设置合并单元格
// if (perHeader.IsMerge)
// {
// var cellRange = new CellRangeAddress(perHeader.PointRow, perHeader.PointRow + perHeader.MergeRow, perHeader.PointCell, perHeader.PointCell + perHeader.MergeCell);
// importSheet.AddMergedRegion(cellRange);
// }
// }
//}
var maxHeaderRowNumber = sheet.PerHeader.Max(t => t.PointRow); var maxHeaderRowNumber = sheet.PerHeader.Max(t => t.PointRow);
sheet.PerHeader.ForEach(t => sheet.PerHeader?.ForEach(t =>
{ {
if (t.IsHasChildren) if (t.IsHasChildren)
{ {
...@@ -221,6 +206,7 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee ...@@ -221,6 +206,7 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
} }
using (FileStream file = new FileStream(newpath, FileMode.Create)) using (FileStream file = new FileStream(newpath, FileMode.Create))
workbook.Write(file); workbook.Write(file);
filepath = newpath;
return true; return true;
} }
...@@ -234,6 +220,10 @@ private List<PerSheet> GetRepositoryData(int allotId) ...@@ -234,6 +220,10 @@ private List<PerSheet> GetRepositoryData(int allotId)
List<PerSheet> sheetList = new List<PerSheet>(); List<PerSheet> sheetList = new List<PerSheet>();
//获取最近一次绩效 //获取最近一次绩效
var perSheetList = perforPersheetRepository.GetEntities(t => t.AllotID == allotId); var perSheetList = perforPersheetRepository.GetEntities(t => t.AllotID == allotId);
if (perSheetList == null || perSheetList.Count == 0)
return sheetList;
foreach (var sheet in perSheetList) foreach (var sheet in perSheetList)
{ {
PerSheet perSheet = new PerSheet() PerSheet perSheet = new PerSheet()
...@@ -246,9 +236,18 @@ private List<PerSheet> GetRepositoryData(int allotId) ...@@ -246,9 +236,18 @@ private List<PerSheet> GetRepositoryData(int allotId)
perSheet.PerHeader = AutoMapper.Mapper.Map<List<PerHeader>>(perHeadList); perSheet.PerHeader = AutoMapper.Mapper.Map<List<PerHeader>>(perHeadList);
if (SheetType.Employee == (SheetType)sheet.SheetType) if (SheetType.Employee == (SheetType)sheet.SheetType)
{ {
var employeeList = perforImemployeeRepository.GetEntities(t => t.AllotID == sheet.ID); perSheet.PerHeader = GetHeader((SheetType)sheet.SheetType);
var employeeList = perforImemployeeRepository.GetEntities(t => t.AllotID == sheet.AllotID);
var perEmployeeList = AutoMapper.Mapper.Map<List<PerDataEmployee>>(employeeList); var perEmployeeList = AutoMapper.Mapper.Map<List<PerDataEmployee>>(employeeList);
perSheet.PerData = perEmployeeList.ConvertAll(new Converter<PerDataEmployee, IPerData>(m => m)); perSheet.PerData = perEmployeeList?.ConvertAll(new Converter<PerDataEmployee, IPerData>(m => m));
}
else if (SheetType.SpecialUnit == (SheetType)sheet.SheetType)
{
perSheet.PerHeader = GetHeader((SheetType)sheet.SheetType);
}
else if (SheetType.AccountBasic == (SheetType)sheet.SheetType)
{
perSheet.PerHeader = GetHeader((SheetType)sheet.SheetType);
} }
sheetList.Add(perSheet); sheetList.Add(perSheet);
} }
...@@ -310,7 +309,7 @@ public dynamic Verify(string obj) ...@@ -310,7 +309,7 @@ public dynamic Verify(string obj)
try try
{ {
//判断值是否为double类型 //判断值是否为double类型
if (!string.IsNullOrEmpty(obj) && Regex.Match(obj.Trim(), @"([1-9]\d*\.?\d*)|(0\.\d*[1-9])|0").ToString() == obj.Trim()) if (!string.IsNullOrEmpty(obj) && Regex.Match(obj.Trim(), @"([1-9]\d*\.?\d*)|(0\.\d*[1-9]?\d*)|0").ToString() == obj.Trim())
return ConvertHelper.To<double>(obj); return ConvertHelper.To<double>(obj);
//判断值是否为日期格式 //判断值是否为日期格式
else if (!string.IsNullOrEmpty(obj) && Regex.Match(obj.Trim(), @"(19|20)\d{2}(-|/)[01]?\d(-|/)[0123]?\d( [012]?\d\:\d{2}\:\d{2})?").ToString() == obj.Trim()) else if (!string.IsNullOrEmpty(obj) && Regex.Match(obj.Trim(), @"(19|20)\d{2}(-|/)[01]?\d(-|/)[0123]?\d( [012]?\d\:\d{2}\:\d{2})?").ToString() == obj.Trim())
...@@ -323,5 +322,94 @@ public dynamic Verify(string obj) ...@@ -323,5 +322,94 @@ public dynamic Verify(string obj)
return obj; return obj;
} }
} }
#region 获取列头
/// <summary>
/// 获取列头
/// </summary>
/// <param name="sheetType">sheet页类型</param>
/// <returns></returns>
public List<PerHeader> GetHeader(SheetType sheetType)
{
Dictionary<string, List<int>> keyValues = new Dictionary<string, List<int>>();
if (SheetType.Employee == sheetType)
{
keyValues = new Dictionary<string, List<int>>
{
{ "核算单元分类",new List<int> { 1, 1, 0, 1 } },
{ "核算单元", new List<int> { 1, 1, 1, 1 } },
{ "绩效基数核算参考对象", new List<int> { 1, 1, 2, 1 } },
{ "医生姓名", new List<int> { 1, 1, 3, 1 } },
{ "职称", new List<int> { 1, 1, 4, 1 } },
{ "岗位系数", new List<int> { 1, 1, 5, 1 } },
{ "参加工作时间", new List<int> { 1, 1, 6, 1 } },
{ "考核得分率", new List<int> { 1, 1, 7, 1 } },
{ "出勤率", new List<int> { 1, 1, 8, 1 } },
{ "核算单元医生数", new List<int> { 1, 1, 9, 1 } },
{ "工作量绩效", new List<int> { 1, 1, 10, 1 } },
{ "其他绩效", new List<int> { 1, 1, 11, 1 } },
{ "医院奖罚", new List<int> { 1, 1, 12, 1 } },
{ "调节系数", new List<int> { 1, 1, 13, 1 } },
{ "发放系数", new List<int> { 1, 1, 14, 1 } },
};
}
else if (SheetType.AccountBasic == sheetType)
{
keyValues = new Dictionary<string, List<int>>
{
{ "核算单元",new List<int> { 1, 2, 0, 1 } },
{ "科室", new List<int> { 1, 2, 1, 1 } },
{ "医生组", new List<int> { 8, 1, 2, 1 } },
{ "护理组", new List<int> { 8, 1, 3, 1 } },
{ "核算单元医生数量", new List<int> { 1, 1, 2, 2 } },
{ "基础系数", new List<int> { 1, 1, 3, 2 } },
{ "倾斜系数", new List<int> { 1, 1, 4, 2 } },
{ "其他绩效1", new List<int> { 1, 1, 5, 2 } },
{ "考核得分率", new List<int> { 1, 1, 6, 2 } },
{ "医院奖罚", new List<int> { 1, 1, 7, 2 } },
{ "其他绩效2", new List<int> { 1, 1, 8, 2 } },
{ "调节系数", new List<int> { 1, 1, 9, 2 } },
{ "核算单元护士数量", new List<int> { 1, 1, 10, 2 } },
{ "基础系数?", new List<int> { 1, 1, 11, 2 } },
{ "倾斜系数?", new List<int> { 1, 1, 12, 2 } },
{ "其他绩效1?", new List<int> { 1, 1, 13, 2 } },
{ "考核得分率?", new List<int> { 1, 1, 14, 2 } },
{ "医院奖罚?", new List<int> { 1, 1, 15, 2 } },
{ "其他绩效2?", new List<int> { 1, 1, 16, 2 } },
{ "调节系数?", new List<int> { 1, 1, 17, 2 } },
};
}
else if (SheetType.SpecialUnit == sheetType)
{
keyValues = new Dictionary<string, List<int>>
{
{ "科室",new List<int> { 1, 1, 0, 1 } },
{ "人数", new List<int> { 1, 1, 1, 1 } },
{ "量化指标", new List<int> { 1, 1, 2, 1 } },
{ "数量", new List<int> { 1, 1, 3, 1 } },
{ "量化指标绩效分值", new List<int> { 1, 1, 4, 1 } },
{ "考核得分率", new List<int> { 1, 1, 5, 1 } },
{ "医院奖罚", new List<int> { 1, 1, 6, 1 } },
{ "其他绩效", new List<int> { 1, 1, 7, 1 } },
{ "调节系数", new List<int> { 1, 1, 8, 1 } },
};
}
List<PerHeader> header = new List<PerHeader>();
foreach (var item in keyValues.Keys)
{
header.Add(new PerHeader
{
CellValue = item.Replace("?", ""),
IsTotal = 0,
MergeCell = keyValues[item][0],
MergeRow = keyValues[item][1],
PointCell = keyValues[item][2],
PointRow = keyValues[item][3]
});
}
return header;
}
#endregion
} }
} }
...@@ -12,13 +12,11 @@ namespace Performance.Services ...@@ -12,13 +12,11 @@ namespace Performance.Services
{ {
public class TemplateService : IAutoInjection public class TemplateService : IAutoInjection
{ {
private Application application;
private IEmailService emailService; private IEmailService emailService;
private PerforPerfirstRepository PerforPerfirstRepository; private PerforPerfirstRepository PerforPerfirstRepository;
public TemplateService(IOptions<Application> options, IEmailService emailService, public TemplateService(IEmailService emailService,
PerforPerfirstRepository PerforPerfirstRepository) PerforPerfirstRepository PerforPerfirstRepository)
{ {
this.application = options.Value;
this.emailService = emailService; this.emailService = emailService;
this.PerforPerfirstRepository = PerforPerfirstRepository; this.PerforPerfirstRepository = PerforPerfirstRepository;
} }
...@@ -40,11 +38,11 @@ public bool InsertFirst(per_first first) ...@@ -40,11 +38,11 @@ public bool InsertFirst(per_first first)
/// <param name="path"></param> /// <param name="path"></param>
/// <param name="subject"></param> /// <param name="subject"></param>
/// <param name="body"></param> /// <param name="body"></param>
public void SendEmail(string path, string subject, string body) public void SendEmail(List<string> receiver, string path, string subject, string body)
{ {
var message = new EmailMessage var message = new EmailMessage
{ {
To = application.Receiver.ToList(), To = receiver,
Attachments = new List<string> { path }, Attachments = new List<string> { path },
DisplayName = "溯直健康", DisplayName = "溯直健康",
Subject = subject, Subject = subject,
......
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