Commit ff0a869f by lcx

数据录入校验,保存同步数据

parent c5254965
...@@ -250,6 +250,9 @@ public AutoMapperConfigs() ...@@ -250,6 +250,9 @@ public AutoMapperConfigs()
CreateMap<ag_secondallot, IssuedPromptResponse>() CreateMap<ag_secondallot, IssuedPromptResponse>()
.ReverseMap(); .ReverseMap();
CreateMap<ex_result, ex_result_gather>()
.ReverseMap();
} }
} }
} }
...@@ -42,5 +42,13 @@ public class ex_result_gather ...@@ -42,5 +42,13 @@ public class ex_result_gather
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
public DateTime CreateTime { get; set; } public DateTime CreateTime { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 1 未通过 2 通过
/// </summary>
public int States { get; set; }
} }
} }
...@@ -37,6 +37,11 @@ public class EmployeeService : IAutoInjection ...@@ -37,6 +37,11 @@ public class EmployeeService : IAutoInjection
private readonly PerforPerapramounthideRepository _hideRepository; private readonly PerforPerapramounthideRepository _hideRepository;
private readonly PerforExresultgatherRepository exresultgatherRepository; private readonly PerforExresultgatherRepository exresultgatherRepository;
private readonly PerforImheaderRepository imheaderRepository; private readonly PerforImheaderRepository imheaderRepository;
private readonly PerforPerdeptdicRepository perdeptdicRepository;
private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository;
private readonly PerforExresultRepository exresultRepository;
private ILogger<EmployeeService> logger; private ILogger<EmployeeService> logger;
public EmployeeService( public EmployeeService(
...@@ -57,6 +62,11 @@ public class EmployeeService : IAutoInjection ...@@ -57,6 +62,11 @@ public class EmployeeService : IAutoInjection
PerforPerapramounthideRepository hideRepository, PerforPerapramounthideRepository hideRepository,
PerforExresultgatherRepository exresultgatherRepository, PerforExresultgatherRepository exresultgatherRepository,
PerforImheaderRepository imheaderRepository, PerforImheaderRepository imheaderRepository,
PerforPerdeptdicRepository perdeptdicRepository,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository,
PerforExresultRepository exresultRepository,
ILogger<EmployeeService> logger) ILogger<EmployeeService> logger)
{ {
_mapper = mapper; _mapper = mapper;
...@@ -76,6 +86,11 @@ public class EmployeeService : IAutoInjection ...@@ -76,6 +86,11 @@ public class EmployeeService : IAutoInjection
_hideRepository = hideRepository; _hideRepository = hideRepository;
this.exresultgatherRepository = exresultgatherRepository; this.exresultgatherRepository = exresultgatherRepository;
this.imheaderRepository = imheaderRepository; this.imheaderRepository = imheaderRepository;
this.perdeptdicRepository = perdeptdicRepository;
this.exmoduleRepository = exmoduleRepository;
this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository;
this.exresultRepository = exresultRepository;
this.logger = logger; this.logger = logger;
} }
...@@ -1235,7 +1250,7 @@ public void SaveGatherHands(int allotId, SaveGatherData request) ...@@ -1235,7 +1250,7 @@ public void SaveGatherHands(int allotId, SaveGatherData request)
} }
} }
exresultgatherRepository.Execute($@"delete from ex_result_gather where allotid = @allotid and source like '%{request.Source}%' and category = '{request.Category}' ",new { allotId }); exresultgatherRepository.Execute($@"delete from ex_result_gather where allotid = @allotid and source like '%{request.Source}%' and category = '{request.Category}' ", new { allotId });
exresultgatherRepository.AddRange(depts.ToArray()); exresultgatherRepository.AddRange(depts.ToArray());
} }
...@@ -1310,6 +1325,148 @@ public GatherResponse GetGather(int allotId, PersonParamsRequest request) ...@@ -1310,6 +1325,148 @@ public GatherResponse GetGather(int allotId, PersonParamsRequest request)
#endregion #endregion
#region 录入校验
public bool CheckGatherData(int allotId)
{
try
{
var allot = perallotRepository.GetEntity(w => w.ID == allotId);
if (allot == null) throw new PerformanceException("绩效记录不存在");
var data = exresultgatherRepository.GetEntities(w => w.AllotId == allotId);
if (data == null || !data.Any()) throw new PerformanceException("录入数据为空");
SetDataStatesAndRemark(data, 2, string.Empty);
var departments = perdeptdicRepository.GetEntities(w => w.HospitalId == allot.HospitalId);
if (departments != null && departments.Any())
{
var notExistsDeptData = data.Where(w => !departments.Select(t => t.Department).Contains(w.Department));
if (notExistsDeptData != null && notExistsDeptData.Any())
SetDataStatesAndRemark(notExistsDeptData, 1, "科室字典中不存在科室[{0}]", t => t.Department);
}
var employees = peremployeeRepository.GetEntities(w => w.AllotId == allotId);
if (employees != null && employees.Any())
{
var notExistNameData = data.Where(w => !employees.Select(t => t.DoctorName).Contains(w.DoctorName) && !string.IsNullOrEmpty(w.DoctorName));
if (notExistNameData != null && notExistNameData.Any())
SetDataStatesAndRemark(notExistNameData, 1, "人员字典中不存在医生名称[{0}]", t => t.DoctorName);
var notExistNumberData = data.Where(w => !employees.Select(t => t.PersonnelNumber).Contains(w.PersonnelNumber) && !string.IsNullOrEmpty(w.PersonnelNumber));
if (notExistNumberData != null && notExistNumberData.Any())
SetDataStatesAndRemark(notExistNumberData, 1, "人员字典中不存在工号[{0}]", t => t.PersonnelNumber);
}
var sheets = perforPersheetRepository.GetEntities(w => w.AllotID == allotId);
if (sheets != null && sheets.Any())
{
var notExistsSourceData = data.Where(w => !sheets.Select(t => t.SheetName).Contains(w.Source));
if (notExistsSourceData != null && notExistsSourceData.Any())
SetDataStatesAndRemark(notExistsSourceData, 1, "来源中不存在名称[{0}]", t => t.Source);
}
exresultgatherRepository.UpdateRange(data.ToArray());
AddCategoryToConfig(data, allot.HospitalId);
return data.Any(w => w.States == 1);
}
catch (Exception ex)
{
logger.LogError(ex.Message);
throw new PerformanceException("校验失败");
}
}
private static void SetDataStatesAndRemark(IEnumerable<ex_result_gather> data, int states, string remark, Func<ex_result_gather, string> func = null)
{
if (new int[] { 1, 2 }.Contains(states)) return;
if (data == null || !data.Any()) return;
foreach (var item in data)
{
if (func != null)
remark = string.Format(remark, func.Invoke(item));
item.States = states;
item.Remark = (!string.IsNullOrEmpty(item.Remark) && item.Remark.Length > 0) ? item.Remark + ", " + remark : remark;
}
}
private void AddCategoryToConfig(List<ex_result_gather> data, int hospitalId)
{
if (data == null || !data.Any(w => w.States == 2)) return;
data = data.Where(w => w.States == 2).ToList();
var modules = exmoduleRepository.GetEntities(w => w.HospitalId == hospitalId && w.SheetType != (int)SheetType.Income);
if (modules == null || !modules.Any()) return;
var items = exitemRepository.GetEntities(w => modules.Select(t => t.Id).Distinct().Contains(w.ModuleId ?? 0));
if (items == null || !items.Any()) return;
try
{
var insertList = new List<ex_item>();
foreach (var module in modules)
{
var categories = data.Where(t => t.Source == module.ModuleName)?.Select(t => t.Category).Distinct();
if (categories == null || !categories.Any()) continue;
var moduleItems = items.Where(w => w.ModuleId == module.Id)?.Select(t => t.ItemName).Distinct();
if (moduleItems == null || !moduleItems.Any()) continue;
var exceptCategories = categories.Except(moduleItems);
if (exceptCategories == null || !exceptCategories.Any()) continue;
insertList.AddRange(exceptCategories.Select(t => new ex_item
{
ModuleId = module.Id,
ItemName = t,
ReadOnly = 0
}));
}
if (insertList != null && insertList.Any())
{
exitemRepository.AddRange(insertList.ToArray());
}
var speacialCategories = data.Where(t => t.Source.Contains("特殊核算单元"))?.Select(t => new { t.Category, t.Department }).Distinct();
if (speacialCategories == null || !speacialCategories.Any()) return;
var specials = exspecialRepository.GetEntities(w => w.HospitalId == hospitalId);
if (specials == null || !specials.Any()) return;
var list = speacialCategories.Where(w => !specials.Select(t => t.Target + t.Department).Contains(w.Category + w.Department));
if (list == null || !list.Any()) return;
exspecialRepository.AddRange(list.Select(t => new ex_special
{
HospitalId = hospitalId,
Department = t.Department,
Target = t.Category
}).ToArray());
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
}
public void SyncDataToResult(int allotId)
{
var data = exresultgatherRepository.GetEntities(w => w.AllotId == allotId);
if (data == null || !data.Any() || data.Any(w => w.States == 1)) return;
var syncData = _mapper.Map<List<ex_result>>(data);
exresultRepository.AddRange(syncData.ToArray());
}
#endregion
} }
public class ComparisonConfig public class ComparisonConfig
......
...@@ -21,6 +21,7 @@ public class ExtractService : IAutoInjection ...@@ -21,6 +21,7 @@ public class ExtractService : IAutoInjection
private readonly PerSheetService perSheetService; private readonly PerSheetService perSheetService;
private readonly CostTransferDataWrite costTransfer; private readonly CostTransferDataWrite costTransfer;
private readonly DictionaryService dictionaryService; private readonly DictionaryService dictionaryService;
private readonly EmployeeService employeeService;
private readonly CustomDataWrite customDataWrite; private readonly CustomDataWrite customDataWrite;
private readonly PerforPerallotRepository perallotRepository; private readonly PerforPerallotRepository perallotRepository;
private readonly PerforCollectdataRepository collectdataRepository; private readonly PerforCollectdataRepository collectdataRepository;
...@@ -28,6 +29,7 @@ public class ExtractService : IAutoInjection ...@@ -28,6 +29,7 @@ public class ExtractService : IAutoInjection
private readonly PerforPeremployeeRepository peremployeeRepository; private readonly PerforPeremployeeRepository peremployeeRepository;
private readonly PerforPerdeptdicRepository perdeptdicRepository; private readonly PerforPerdeptdicRepository perdeptdicRepository;
private readonly PerforCofdrugtypefactorRepository drugtypefactorRepository; private readonly PerforCofdrugtypefactorRepository drugtypefactorRepository;
private readonly PerforExresultRepository exresultRepository;
public ExtractService( public ExtractService(
ILogger<ExtractService> logger, ILogger<ExtractService> logger,
...@@ -37,13 +39,15 @@ public class ExtractService : IAutoInjection ...@@ -37,13 +39,15 @@ public class ExtractService : IAutoInjection
PerSheetService perSheetService, PerSheetService perSheetService,
CostTransferDataWrite costTransfer, CostTransferDataWrite costTransfer,
DictionaryService dictionaryService, DictionaryService dictionaryService,
EmployeeService employeeService,
CustomDataWrite customDataWrite, CustomDataWrite customDataWrite,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
PerforCollectdataRepository collectdataRepository, PerforCollectdataRepository collectdataRepository,
PerforExtypeRepository extypeRepository, PerforExtypeRepository extypeRepository,
PerforPeremployeeRepository peremployeeRepository, PerforPeremployeeRepository peremployeeRepository,
PerforPerdeptdicRepository perdeptdicRepository, PerforPerdeptdicRepository perdeptdicRepository,
PerforCofdrugtypefactorRepository drugtypefactorRepository PerforCofdrugtypefactorRepository drugtypefactorRepository,
PerforExresultRepository exresultRepository
) )
{ {
this.logger = logger; this.logger = logger;
...@@ -53,6 +57,7 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository ...@@ -53,6 +57,7 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository
this.perSheetService = perSheetService; this.perSheetService = perSheetService;
this.costTransfer = costTransfer; this.costTransfer = costTransfer;
this.dictionaryService = dictionaryService; this.dictionaryService = dictionaryService;
this.employeeService = employeeService;
this.customDataWrite = customDataWrite; this.customDataWrite = customDataWrite;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
this.collectdataRepository = collectdataRepository; this.collectdataRepository = collectdataRepository;
...@@ -60,6 +65,7 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository ...@@ -60,6 +65,7 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository
this.peremployeeRepository = peremployeeRepository; this.peremployeeRepository = peremployeeRepository;
this.perdeptdicRepository = perdeptdicRepository; this.perdeptdicRepository = perdeptdicRepository;
this.drugtypefactorRepository = drugtypefactorRepository; this.drugtypefactorRepository = drugtypefactorRepository;
this.exresultRepository = exresultRepository;
} }
/// <summary> /// <summary>
...@@ -92,7 +98,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName, ...@@ -92,7 +98,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
queryService.ClearHistoryData(allot.ID, groupName, isSingle); queryService.ClearHistoryData(allot.ID, groupName, isSingle);
var data = queryService.Handler(hospitalId, allot, groupName, isSingle, ref dict); employeeService.SyncDataToResult(allotId);
var data = exresultRepository.GetEntities(t => t.AllotId == allotId && t.IsDelete == 0);
data.AddRange(queryService.Handler(hospitalId, allot, groupName, isSingle, ref dict));
var standData = StandDataFormat(hospitalId, data); var standData = StandDataFormat(hospitalId, data);
dictionaryService.Handler(hospitalId, allot, groupName, isSingle); dictionaryService.Handler(hospitalId, allot, groupName, isSingle);
......
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