12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106 |
- package thyyxxk.webserver.service.targetmanagement;
- import lombok.extern.slf4j.Slf4j;
- import org.jetbrains.annotations.NotNull;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.dao.his.highreport.HighReportDao;
- import thyyxxk.webserver.dao.his.targetmanagement.TableDisplayInfoDao;
- import thyyxxk.webserver.dao.his.targetmanagement.TableGroupInfoDao;
- import thyyxxk.webserver.dao.his.targetmanagement.TargetManagementDao;
- import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleDao;
- import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleScoreDao;
- import thyyxxk.webserver.dao.his.targetmanagement.ZbZdBaseInfoDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.highreport.HighReportDto;
- import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
- import thyyxxk.webserver.entity.highreport.ReportType;
- import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
- import thyyxxk.webserver.entity.highreport.TableGroupInfo;
- import thyyxxk.webserver.entity.highreport.ZbReportCycle;
- import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;
- import thyyxxk.webserver.entity.highreport.ZbReportResult;
- import thyyxxk.webserver.entity.highreport.ZbReportScoreDto;
- import thyyxxk.webserver.entity.highreport.ZdReportType;
- import thyyxxk.webserver.entity.login.UserInfo;
- import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
- import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
- import thyyxxk.webserver.entity.targetmanagement.ZbZdBaseInfo;
- import thyyxxk.webserver.service.redislike.RedisLikeService;
- import thyyxxk.webserver.utils.DateUtil;
- import thyyxxk.webserver.utils.DecimalUtil;
- import thyyxxk.webserver.utils.ReportUtil;
- import thyyxxk.webserver.utils.ResultVoUtil;
- import thyyxxk.webserver.utils.StringUtil;
- import thyyxxk.webserver.utils.TargetDictTreeUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @Description: 指标管理
- * @Author: hsh
- * @CreateTime: 2023-05-30 16:52
- * @Version: 1.0
- */
- @Service
- @Slf4j
- public class TargetManagementService {
- private final TargetManagementDao dao;
- private final ZbZdBaseInfoDao zbZdDao;
- private final HighReportDao reportDao;
- private final RedisLikeService redis;
- private final TableGroupInfoDao tableDao;
- private final TableDisplayInfoDao displayDao;
- private final ZbReportCycleDao cycleDao;
- private final ZbReportCycleScoreDao scoreDao;
- @Autowired
- public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao,
- RedisLikeService redis, TableGroupInfoDao tableDao, TableDisplayInfoDao displayDao,
- ZbReportCycleDao cycleDao, ZbReportCycleScoreDao scoreDao) {
- this.dao = dao;
- this.zbZdDao = zbZdDao;
- this.reportDao = reportDao;
- this.redis = redis;
- this.tableDao = tableDao;
- this.displayDao = displayDao;
- this.cycleDao = cycleDao;
- this.scoreDao = scoreDao;
- }
- /**
- * @description: 查询指标字典基本信息
- * @author: hsh
- * @date: 2023/5/30 17:27
- * @param: [dto]
- * @return: ResultVo<List<ZbZdBaseInfo>>
- **/
- public ResultVo<List<ZbZdBaseInfo>> selectTargetDict(TargetManagement dto) {
- List<ZbZdBaseInfo> list = zbZdDao.selectZbZdBaseInfo(dto);
- return ResultVoUtil.success(list);
- }
- /**
- * @description: 根据id查询指标字典基本信息
- * @author: hsh
- * @date: 2023/7/5 10:58
- * @param: [dto]
- * @return: ResultVo<ZbZdBaseInfo>
- **/
- public ResultVo<ZbZdBaseInfo> selectTargetDictById(TargetManagement dto) {
- ZbZdBaseInfo info = zbZdDao.selectZbZdBaseInfoById(dto);
- return ResultVoUtil.success(info);
- }
- /**
- * @description: 查询指标树
- * @author: hsh
- * @date: 2023/6/2 11:11
- * @param: [dto]
- * @return: ResultVo<List<TargetDictTree>>
- **/
- public ResultVo<List<TargetDictTree>> selectTargetDictTree(TargetManagement dto) {
- List<TargetDictTree> zbList = zbZdDao.selectTargetDictTree(dto);
- // 组装指标树
- List<TargetDictTree> list = assemblyTargetDictTree(zbList);
- return ResultVoUtil.success(list);
- }
- /**
- * @description: 组装指标字典树
- * @author: hsh
- * @date: 2023/6/2 9:37
- * @param: [list, zbList]
- * @return: void
- **/
- private List<TargetDictTree> assemblyTargetDictTree(@NotNull List<TargetDictTree> zbList) {
- // 创建树形结构(数据集合作为参数)
- TargetDictTreeUtil treeBuild = new TargetDictTreeUtil(zbList);
- // 原查询结果转换树形结构
- return treeBuild.buildTree();
- }
- public ResultVo<Map<String, Object>> saveTargetDict(ZbZdBaseInfo dto) {
- // 验证sql是否有问题
- String msg = sqlCheckAndVerify(dto);
- // 补充责任科室以及责任人
- if(StringUtil.notBlank(msg)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
- }
- TargetManagement target = new TargetManagement();
- target.setId(dto.getId());
- target.setPid(dto.getPid());
- ZbZdBaseInfo zdBaseInfo = zbZdDao.selectZbZdBaseInfoById(target);
- int num;
- if(zdBaseInfo != null){
- num = zbZdDao.updateZbZdBaseInfo(dto);
- } else {
- num = zbZdDao.saveZbZdBaseInfo(dto);
- }
- if(num > 0){
- Map<String, Object> m = new HashMap<>();
- m.put("1", "保存指标字典成功!");
- return ResultVoUtil.success(m);
- } else {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标字典失败!");
- }
- }
- /**
- * @description: 更新指标字典数据
- * @author: hsh
- * @date: 2023/6/2 9:29
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> updateTargetDict(ZbZdBaseInfo dto) {
- // 验证sql是否有问题
- String msg = sqlCheckAndVerify(dto);
- if(StringUtil.notBlank(msg)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
- }
- int num = zbZdDao.updateZbZdBaseInfo(dto);
- if(num > 0){
- return ResultVoUtil.success(ExceptionEnum.SUCCESS, "更新指标字典成功!");
- } else {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "更新指标字典失败");
- }
- }
- /**
- * @description: 验证查询sql是否正确
- * @author: hsh
- * @date: 2023/5/31 10:11
- * @param: [dto]
- * @return: String 错误信息
- **/
- private String sqlCheckAndVerify(@NotNull ZbZdBaseInfo dto) {
- String sqlChild = dto.getCalcChild();
- String sqlMom = dto.getCalcMom();
- String message = "";
- if(StringUtil.isBlank(dto.getId())){
- message = "id不存在,请检查!";
- }
- if(StringUtil.isBlank(dto.getName())){
- message = "指标名称不存在,请检查!";
- }
- if(StringUtil.isBlank(dto.getPid())){
- message = "父id不存在,请检查!";
- }
- if(dto.getScore() == null || dto.getScore().doubleValue() < 0){
- message = "指标总分不存在或者小于0,请检查!";
- }
- String isLeaf = dto.getIsLeaf();
- if("1".equals(isLeaf)){
- // 叶子节点要求填写责任科室,责任人
- if(StringUtil.isBlank(dto.getDeptCode())){
- message = "责任科室未选择,请检查!";
- }
- if(StringUtil.isBlank(dto.getOpId())){
- message = "责任人未选择,请检查!";
- }
- if(StringUtil.isBlank(dto.getDefinition())){
- message = "指标定义不存在,请检查!";
- }
- if(StringUtil.isBlank(dto.getMethod())){
- message = "指标评审方法不存在,请检查!";
- }
- if(StringUtil.isBlank(dto.getScoreRule())){
- message = "指标计分细则不存在,请检查!";
- }
- if(StringUtil.notBlank(sqlChild)){
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
- message = "保存指标字典失败,分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild);
- }
- }
- if(StringUtil.notBlank(sqlMom)){
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom))){
- message = "保存指标字典失败,分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom);
- }
- }
- }
- return message;
- }
- /**
- * @description: 查询分子分母指标报表结果
- * @author: hsh
- * @date: 2023/7/6 9:31
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> targetSqlExecute(TargetManagement dto) {
- String sqlChild = dto.getCalcChild();
- String sqlMom = dto.getCalcMom();
- if(StringUtil.isBlank(sqlChild)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "计算-分子sql不存在,请检查!");
- } else {
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
- }
- }
- if(StringUtil.notBlank(sqlMom)){
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom))){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom));
- }
- }
- // 转换sql的查询条件
- Map<String, ReportBaseInfo> map = ReportUtil.assertReportForTarget(dto);
- ReportBaseInfo r1 = map.get("calcChild");
- ReportBaseInfo r2 = map.get("calcMom");
- // 转换查询dto
- HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
- // 计算结果
- Map<String, Object> resultMap = new HashMap<>();
- String child = null;
- String mom = null;
- if(r1 != null){
- String childSql = ReportUtil.callSqlFormat(d, r1.getBaseSql(), r1.getGatherSql(), null, null, null);
- child = dao.targetSqlExecute(childSql);
- }
- if(r2 != null){
- String momSql = ReportUtil.callSqlFormat(d, r2.getBaseSql(), r2.getGatherSql(), null, null, null);
- mom = dao.targetSqlExecute(momSql);
- }
- if (StringUtil.notBlank(child)) {
- resultMap.put("r1", child);
- } else {
- resultMap.put("r1", "无");
- }
- if (StringUtil.notBlank(mom)) {
- resultMap.put("r2", mom);
- if(StringUtil.notBlank(child)){
- resultMap.put("r3", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 4));
- } else {
- resultMap.put("r3", "无");
- }
- } else {
- resultMap.put("r2", "无");
- if (StringUtil.notBlank(child)) {
- resultMap.put("r3", child);
- } else {
- resultMap.put("r3", "无");
- }
- }
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 根据id查询分子分母指标报表结果
- * @author: hsh
- * @date: 2023/7/6 9:30
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<List<Map<String, Object>>> targetSqlExecuteById(TargetManagement dto) {
- ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
- ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
- if(null == reportChild && null == reportMom){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "计算-分子或分母指标都不存在,请联系管理员!");
- }
- if(null == dto.getStartTime() || null == dto.getEndTime()){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "查询时间不存在,请检查!");
- }
- // 处理时间(1.时间跨度需要一年一年查询结果; 2.查询时间格式为年月日时分秒: yyyy-MM-DD 24H:mm:ss)
- int start = Integer.parseInt(dto.getStartTime());
- int end = Integer.parseInt(dto.getEndTime());
- // 超过4年只选择4年数据查询
- int endIndex = start + 3;
- List<Map<String, Object>> list = new ArrayList<>();
- for(int i = start; i <= end; i++){
- Map<String, Object> resultMap = new HashMap<>();
- if(i > endIndex){
- break;
- }
- int s = i - start + 1;
- String ks = i + "-01-01 00:00:00";
- String js = i + "-12-31 23:59:59";
- dto.setStartTime(ks);
- dto.setEndTime(js);
- HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
- // 计算结果
- String child = null;
- String mom = null;
- if(reportChild != null){
- String childSql = ReportUtil.callSqlFormat(d, reportChild.getBaseSql(), reportChild.getGatherSql(), null, null, null);
- child = dao.targetSqlExecute(childSql);
- }
- if(reportMom != null){
- String momSql = ReportUtil.callSqlFormat(d, reportMom.getBaseSql(), reportMom.getGatherSql(), null, null, null);
- mom = dao.targetSqlExecute(momSql);
- }
- resultMap.put("id", dto.getId());
- resultMap.put("pid", dto.getPid());
- resultMap.put("index", s);
- // 数据统计来源(1:sql统计;2:手动填写输入。)
- resultMap.put("dataType", "1");
- // 统计年份
- resultMap.put("year", i);
- resultMap.put("childLabel", i + "年分子结果");
- resultMap.put("momLabel", i + "年分母结果");
- resultMap.put("calcLabel", i + "年分子/分母的结果");
- if (StringUtil.notBlank(child)) {
- resultMap.put("childResult", child);
- } else {
- resultMap.put("childResult", "无");
- }
- if (StringUtil.notBlank(mom)) {
- resultMap.put("momResult", mom);
- if(StringUtil.notBlank(child)){
- resultMap.put("calcResult", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 4));
- } else {
- resultMap.put("calcResult", "无");
- }
- } else {
- resultMap.put("momResult", "无");
- if (StringUtil.notBlank(child)) {
- resultMap.put("calcResult", child);
- } else {
- resultMap.put("calcResult", "无");
- }
- }
- list.add(resultMap);
- }
- return ResultVoUtil.success(list);
- }
- public ResultVo<Map<String, Object>> targetSqlSave(TargetManagement dto) {
- String sqlChild = dto.getCalcChild();
- String sqlMom = dto.getCalcMom();
- if(StringUtil.notBlank(sqlChild)) {
- if (!sqlChild.contains("/") && !(sqlChild.contains("select") || sqlChild.contains("SELECT"))) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子sql语句不合法,请检查!");
- }
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
- }
- }
- if(StringUtil.notBlank(sqlMom)){
- if (!sqlMom.contains("/") && !(sqlMom.contains("select") || sqlMom.contains("SELECT"))) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母sql语句不合法,请检查!");
- }
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
- }
- }
- try {
- int num = 0;
- // 获取指标字典sql信息
- Map<String, ReportBaseInfo> map = ReportUtil.assertReportForTarget(dto);
- // 查询指标字典是否以及存在分子分母的sql指标报表信息
- ZbZdBaseInfo info = zbZdDao.selectZbZdBaseInfoById(dto);
- if(null != map.get("calcChild")){
- // 已经配置分子sql指标报表信息
- ReportBaseInfo r1 = map.get("calcChild");
- // 更新分子指标报表的sql信息
- if(StringUtil.notBlank(info.getChildId())){
- dao.deleteReportBaseInfoById(r1.getReportId());
- } else {
- // 保存分子指标报表的id
- zbZdDao.updateZbZdBaseInfoCalcId(dto.getId(), dto.getPid() ,r1.getReportId(), null);
- }
- num += dao.insert(r1);
- }
- if(null != map.get("calcMom")){
- ReportBaseInfo r2 = map.get("calcMom");
- if(StringUtil.notBlank(info.getMomId())){
- dao.deleteReportBaseInfoById(r2.getReportId());
- } else {
- // 保存分母指标报表的id
- zbZdDao.updateZbZdBaseInfoCalcId(dto.getId(), dto.getPid(), null, r2.getReportId());
- }
- num += dao.insert(r2);
- }
- Map<String, Object> resultMap = new HashMap<>();
- if(num == 0){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标sql以及报表失败!");
- }
- resultMap.put("cg", "保存指标sql以及报表成功!");
- return ResultVoUtil.success(resultMap);
- } catch (Exception e) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标sql以及报表失败!");
- }
- }
- /**
- * @description: 根据id和父id删除指标字典
- * @author: hsh
- * @date: 2023/6/21 11:05
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> deleteTargetDictById(TargetManagement dto) {
- if(StringUtil.isBlank(dto.getId())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
- }
- if(StringUtil.isBlank(dto.getPid())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- int num = zbZdDao.deleteTargetDictById(dto.getId(), dto.getPid());
- if(num == 0){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标字典失败!");
- }
- resultMap.put("cg", "删除指标字典成功!");
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 查询指标字典的分子分母sql
- * @author: hsh
- * @date: 2023/6/30 15:19
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> selectTargetSql(TargetManagement dto) {
- if (StringUtil.isBlank(dto.getId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
- }
- if (StringUtil.isBlank(dto.getPid())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
- ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
- resultMap.put("reportChild", reportChild);
- resultMap.put("reportMom", reportMom);
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 查询指标字典的分子分母sql的详细内容
- * @author: hsh
- * @date: 2023/6/30 15:20
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> selectTargetSqlDetail(TargetManagement dto) {
- if (StringUtil.isBlank(dto.getId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
- }
- if (StringUtil.isBlank(dto.getPid())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- ReportBaseInfo reportBaseInfo = dao.selectReportBaseInfoById(dto.getId(), dto.getPid());
- if (reportBaseInfo == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询指标不存在!");
- }
- resultMap.put("report", reportBaseInfo);
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 查询指标报表数据
- * @author: hsh
- * @date: 2023/7/7 10:19
- * @param: [dto]
- * @return: ResultVo<List<Map<String, Object>>>
- **/
- public ResultVo<List<Map<String, Object>>> selectReportDictTree(HighReportDto dto){
- // 查询所有使用的指标报表数据
- List<ReportBaseInfo> list = reportDao.selectReportDictTree();
- // 查询指标类型
- List<ZdReportType> reportTypes = reportDao.selectReportType();
- Map<String, ZdReportType> typeMap = new HashMap<>();
- for (ZdReportType zdReport : reportTypes) {
- typeMap.put(zdReport.getReportType(), zdReport);
- }
- Map<String, List<ReportBaseInfo>> reportMap = list.stream().collect(Collectors.groupingBy(ReportBaseInfo::getReportType));
- List<Map<String, Object>> resultList = new ArrayList<>();
- Map<String, Object> rootMap = new HashMap<>();
- rootMap.put("id", "zbJc");
- rootMap.put("pid", "0");
- rootMap.put("label", "指标监测");
- List<Map<String, Object>> rootChildList = new ArrayList<>();
- for(Map.Entry<String, List<ReportBaseInfo>> entry: reportMap.entrySet()){
- Map<String, Object> map = new HashMap<>();
- List<ReportBaseInfo> l = entry.getValue();
- String type = entry.getKey();
- String reportName = typeMap.get(type) == null ? "" : typeMap.get(type).getReportLabel();
- if(StringUtil.notBlank(reportName)){
- map.put("id", type);
- map.put("pid", "zbJc");
- map.put("label", reportName);
- map.put("sort", typeMap.get(type).getSort());
- } else {
- map.put("id", type);
- map.put("label", ReportType.QT.getName());
- map.put("sort", "999");
- }
- map.put("pid", "zbJc");
- List<Map<String, Object>> child = AssertReportTree(l, type);
- map.put("children", child);
- rootChildList.add(map);
- }
- rootMap.put("children", rootChildList.stream().sorted(Comparator.comparingInt(e -> Integer.parseInt(String.valueOf(e.get("sort"))))).collect(Collectors.toList()));
- resultList.add(rootMap);
- return ResultVoUtil.success(resultList);
- }
- /**
- * @description: 组装指标报表树数据
- * @author: hsh
- * @date: 2023/7/7 11:34
- * @param: [list, type]
- * @return: List<Map<String, Object>>
- **/
- private List<Map<String, Object>> AssertReportTree(List<ReportBaseInfo> list, String type) {
- List<Map<String, Object>> resultList = new ArrayList<>();
- for(ReportBaseInfo info : list){
- Map<String, Object> map = new HashMap<>();
- map.put("id", info.getReportId());
- map.put("pid", type);
- map.put("label", info.getReportName());
- resultList.add(map);
- }
- return resultList;
- }
- /**
- * @description: 根据报表id作废指标报表
- * @author: hsh
- * @date: 2023/7/7 16:13
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> deleteReportDictById(TargetManagement dto) {
- if (StringUtil.isBlank(dto.getId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- int num = reportDao.updateReportDictById(dto.getId());
- if (num == 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "作废指标报表失败!");
- }
- resultMap.put("cg", "作废指标报表成功!");
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 查询指标报表信息
- * @author: hsh
- * @date: 2023/7/7 16:52
- * @param: [dto]
- * @return: ResultVo<List<ReportBaseInfo>>
- **/
- public ResultVo<List<ReportBaseInfo>> selectReportDict(HighReportDto dto) {
- List<ReportBaseInfo> list = reportDao.selectReportDict(dto);
- return ResultVoUtil.success(list);
- }
- /**
- * @description: 查询指标报表类型字典信息
- * @author: hsh
- * @date: 2023/7/11 16:26
- * @param: []
- * @return: ResultVo<List<ZdReportType>>
- **/
- public ResultVo<List<ZdReportType>> selectReportType() {
- List<ZdReportType> list = reportDao.selectReportType();
- return ResultVoUtil.success(list);
- }
- /**
- * @description: 查询报表sql统计总计结果,用来验证报表sql是否编写正确
- * @author: hsh
- * @date: 2023/7/12 16:52
- * @param: [dto]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> reportSqlExecute(TargetManagement dto){
- if(StringUtil.isBlank(dto.getBaseSql())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "基础sql不存在,请检查!");
- }
- if(StringUtil.isBlank(dto.getGatherSql())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "聚合sql不存在,请检查!");
- }
- if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(dto.getBaseSql()))){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, ReportUtil.sqlCheckAndVerifyByKeyword(dto.getBaseSql()));
- }
- Map<String, Object> resultMap = new HashMap<>();
- HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
- String calcSql = ReportUtil.callSqlFormat(d, dto.getBaseSql(), dto.getGatherSql(), null, null, null);
- String result = dao.targetSqlExecute(calcSql);
- if(StringUtil.notBlank(result)){
- resultMap.put("r1", result);
- } else {
- resultMap.put("r1", "无");
- }
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 查询报表分组类型
- * @author: hsh
- * @date: 2023/7/19 15:25
- * @param: [dto]
- * @return: ResultVo<TableGroupInfo>
- **/
- public ResultVo<TableGroupInfo> selectReportLevel(HighReportDto dto){
- TableGroupInfo info = reportDao.selectTableGroupInfoByLevel(dto.getReportId(), dto.getLevel());
- if(info == null){
- // 查不到给他默认报表分组类型
- if(ReportType.GROUP_KS.getCode().equals(dto.getLevel())) {
- info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_KS.getCode(), dto.getLevel());
- } else if(ReportType.GROUP_ZB.getCode().equals(dto.getLevel())) {
- info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_ZB.getCode(), dto.getLevel());
- }
- }
- if(null == info){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标分组配置不存在,请检查!");
- }
- return ResultVoUtil.success(info);
- }
- /**
- * @description: 保存指标结果
- * @author: hsh
- * @date: 2023/7/19 15:27
- * @param: [list]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> saveTargetReportResult(List<ZbReportResult> list){
- Map<String, Object> resultMap = new HashMap<>();
- if(list == null || list.isEmpty()){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标结果记录不存在,请检查!");
- }
- UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
- for (ZbReportResult result : list) {
- result.setOp(user.getName() != null ? user.getName().trim() : null);
- result.setOpId(user.getCodeRs());
- result.setOpTime(DateUtil.now());
- // 入库或更新操作
- int n = updateAndSaveTargetReportResult(result);
- if (n <= 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标结果失败!");
- }
- }
- resultMap.put("cg", "保存指标结果成功");
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 先删后保存数据
- * @author: hsh
- * @date: 2023/7/21 10:06
- * @param: [result]
- * @return: int
- **/
- private int updateAndSaveTargetReportResult(ZbReportResult result) {
- if(result == null){
- return 0;
- }
- ZbReportResult r = reportDao.selectReportResultByYear(result.getId(), result.getPid(), result.getYear());
- if(r != null){
- reportDao.deleteReportResultById(result.getId(), result.getPid(), result.getYear());
- }
- return reportDao.saveTargetReportResult(result);
- }
- /**
- * @description: 查询指标报表结果
- * @author: hsh
- * @date: 2023/7/21 11:21
- * @param: [dto]
- * @return: ResultVo<List<ZbReportResult>>
- **/
- public ResultVo<List<ZbReportResult>> selectTargetReportResult(TargetManagement dto) {
- List<ZbReportResult> list = reportDao.selectReportResultById(dto.getId(), dto.getPid(), dto.getStartTime(), dto.getEndTime());
- return ResultVoUtil.success(list);
- }
- /**
- * @description: 保存/更新指标报表基本信息
- * @author: hsh
- * @date: 2023/7/27 9:55
- * @param: [info]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> saveReportBaseInfo(ReportBaseInfo info) {
- Map<String, Object> resultMap = new HashMap<>();
- if(info == null || StringUtil.isBlank(info.getReportId())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报表详情为空,保存指标详情失败!");
- }
- ReportBaseInfo report = reportDao.selectReportPortalMenu(info.getReportId(), null, null);
- if (report != null) {
- reportDao.deleteReportBaseInfoById(info.getReportId());
- }
- int n = dao.insert(info);
- if (n <= 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标详情失败!");
- }
- resultMap.put("cg", "保存指标详情成功!");
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @description: 保存/更新指标分组信息
- * @author: hsh
- * @date: 2023/9/26 16:19
- * @param: [info]
- * @return: ResultVo<Map<String,Object>>
- **/
- public ResultVo<Map<String, Object>> saveTableGroupInfo(TableGroupInfo info) {
- Map<String, Object> resultMap = new HashMap<>();
- if(info == null || StringUtil.isBlank(info.getReportId())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标分组信息为空,保存指标分组信息失败!");
- }
- if(ReportType.GROUP_KS.getCode().equals(info.getReportId()) || ReportType.GROUP_ZB.getCode().equals(info.getReportId())){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标固定分组信息不允许修改/删除!");
- }
- TableGroupInfo table = reportDao.selectTableGroupInfo(info.getReportId(), null);
- if (table != null) {
- reportDao.deleteTableGroupInfoById(info.getReportId());
- }
- int n = tableDao.insert(info);
- if (n <= 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标分组信息失败!");
- }
- resultMap.put("cg", "保存指标详情成功!");
- return ResultVoUtil.success(resultMap);
- }
- public ResultVo<List<Map<String, Object>>> selectReportLevelDict() {
- List<Map<String, Object>> list = tableDao.selectReportLevelDict();
- return ResultVoUtil.success(list);
- }
- /**
- * @Description 查询指标报表的所有id以及名称
- * @Author hsh
- * @param reportType 指标报表类型
- * @return list
- * @Date 2024/4/8 10:15
- */
- public ResultVo<List<Map<String, Object>>> selectTargetZbReportId(String reportType) {
- List<Map<String, Object>> list = dao.selectTargetZbReportId(reportType);
- return ResultVoUtil.success(list);
- }
- /**
- * @Description 查询指标报表详情配置
- * @Author hsh
- * @param info 指标报表信息
- * @return list
- * @Date 2024/4/8 10:16
- */
- public ResultVo<List<TableDisplayInfo>> selectTableDisplay(ReportBaseInfo info) {
- return ResultVoUtil.success(displayDao.selectTableDisplayByReportId(info.getReportId(), "patient"));
- }
- /**
- * @Description 更新指标报表详情配置信息
- * @Author hsh
- * @param info 指标报表详情配置信息
- * @return map
- * @Date 2024/4/8 10:16
- */
- public ResultVo<Map<String, Object>> saveTableDisplay(TableDisplayInfo info){
- if(null == info || info.getReportId() == null || info.getLevelId() == null || info.getProp() == null){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标报表详情配置信息不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- String reportId = info.getReportId();
- String levelId = info.getLevelId();
- String prop = info.getProp();
- TableDisplayInfo displayInfo = displayDao.selectTableDisplayByProp(reportId, levelId, prop);
- int num;
- try{
- if(null != displayInfo){
- num = displayDao.updateTableDisplayByProp(info);
- } else {
- num = displayDao.insert(info);
- }
- if(num == 0){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标报表详情配置失败!");
- }
- resultMap.put("cg", "保存指标报表详情配置成功!");
- return ResultVoUtil.success(resultMap);
- } catch(Exception e){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标报表详情配置失败!");
- }
- }
- /**
- * @Description 根据指标报表详情配置prop删除指标报表详情配置信息
- * @Author hsh
- * @param reportId,levelId,prop 报表id,报表等级id,报表配置prop属性
- * @return map
- * @Date 2024/4/8 10:17
- */
- public ResultVo<Map<String, Object>> delTableDisplayByProp(String reportId, String levelId, String prop) {
- if(reportId == null || levelId == null || prop == null){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标报表详情配置信息不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- try{
- int num = displayDao.delTableDisplayByProp(reportId, levelId, prop);
- if(num == 0){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标报表详情配置信息失败!");
- }
- resultMap.put("cg", "删除指标报表详情配置信息成功!");
- return ResultVoUtil.success(resultMap);
- } catch(Exception e){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标报表详情配置信息失败!");
- }
- }
- /**
- * @Description 查询指标年度周期明细
- * @Author hsh
- * @return list 指标年度周期明细
- * @Date 2024/8/15 9:41
- */
- public ResultVo<List<ZbReportCycle>> selectScoreCycle(){
- List<ZbReportCycle> list = cycleDao.selectScoreCycle();
- return ResultVoUtil.success(list);
- }
- /**
- * @Description 更新指标周期得分
- * @Author hsh
- * @param score 指标周期得分详情
- * @return map
- * @Date 2024/8/15 10:19
- */
- public ResultVo<Map<String, Object>> updateTargetReportScore(ZbReportCycleScore score){
- Map<String, Object> resultMap = new HashMap<>();
- String id = score.getId();
- String reportCycle = score.getReportCycle();
- if(StringUtil.isBlank(id) || StringUtil.isBlank(reportCycle)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标id或年度周期信息不全,请检查!");
- }
- ZbReportCycleScore s = scoreDao.selectZbReportCycleScoreByReportCycle(id, reportCycle);
- UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
- score.setAuthorId(user.getCode().trim());
- score.setAuthorName(user.getName().trim());
- int num;
- if(null != s){
- num = scoreDao.updateTargetReportScoreById(score);
- } else {
- num = scoreDao.insert(score);
- }
- if(num > 0){
- resultMap.put("cg", "更新指标周期得分成功!");
- }
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @Description 查询指标周期得分
- * @Author hsh
- * @param score 指标周期得分参数
- * @return score 指标周期得分
- * @Date 2024/8/15 15:47
- */
- public ResultVo<ZbReportCycleScore> selectTargetReportScore(ZbReportCycleScore score){
- String id = score.getId();
- String reportCycle = score.getReportCycle();
- if(StringUtil.isBlank(id) || StringUtil.isBlank(reportCycle)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标id或年度周期信息不全,请检查!");
- }
- ZbReportCycleScore zbScore = scoreDao.selectZbReportCycleScoreByReportCycle(id, reportCycle);
- return ResultVoUtil.success(zbScore);
- }
- /**
- * @Description 查询计算指标得分的权限
- * @Author hsh
- * @return map
- * @Date 2024/8/15 16:54
- */
- public ResultVo<Map<String, Object>> selectScoreCyclePermissions(){
- Map<String, Object> resultMap = new HashMap<>();
- String permissions = scoreDao.selectScoreCyclePermissions();
- if("N".equals(permissions)){
- // 不做计算指标得分的权限限制
- resultMap.put("permissions", 0);
- } else {
- UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
- String code = user.getCode().trim();
- if(permissions.contains(code)){
- // 有权限计算指标得分
- resultMap.put("permissions", 1);
- } else {
- // 没有权限计算指标得分
- resultMap.put("permissions", 2);
- }
- }
- return ResultVoUtil.success(resultMap);
- }
- /**
- * @Description 查询指标得分情况
- * @Author hsh
- * @param dto 指标信息
- * @return list
- * @Date 2024/8/27 16:12
- */
- public ResultVo<List<Map<String, Object>>> selectTargetDictScoreById(ZbReportScoreDto dto){
- String pid = dto.getPid();
- String reportCycle = dto.getReportCycle();
- if(StringUtil.isBlank(pid) || StringUtil.isBlank(reportCycle)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标pid或年度周期信息不全,请检查!");
- }
- List<Map<String, Object>> list = scoreDao.selectTargetDictScoreByPid(pid, reportCycle);
- // 根据pid以及时间查询报表结果
- List<ZbReportResult> resultList = reportDao.selectReportResultByPid(pid, dto.getStartTime(), dto.getEndTime());
- Map<String, List<ZbReportResult>> resultMap = resultList.stream().collect(Collectors.groupingBy(ZbReportResult::getId, Collectors.toList()));
- for (Map<String, Object> map : list){
- String id = String.valueOf(map.get("id"));
- List<ZbReportResult> results = resultMap.get(id);
- if(null != results && !results.isEmpty()){
- for(ZbReportResult r : results){
- map.put("t_" + r.getYear(), r.getCalcResult());
- }
- } else {
- String s = dto.getStartTime();
- int year = Integer.parseInt(s);
- for(int j = 0; j < 4; j++){
- int f = year + j;
- map.put("t_" + f, "");
- }
- }
- }
- return ResultVoUtil.success(list);
- }
- /**
- * @Description 根据指标年度周期查询指标章节总分以及得分
- * @Author hsh
- * @param dto 指标年度周期
- * @return list
- * @Date 2024/8/30 8:58
- */
- public ResultVo<Map<String, Object>> selectTargetTotalScoreInfo(ZbReportScoreDto dto){
- String reportCycle = dto.getReportCycle();
- if(StringUtil.isBlank(reportCycle)){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有年度周期,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- // 查询第二级指标(pid是B)
- List<Map<String, Object>> resultList = new ArrayList<>();
- List<ZbZdBaseInfo> ls = zbZdDao.selectTargetDictScoreBySecond("B");
- // 拼接总分
- Map<String, Object> m1 = new HashMap<>();
- // 拼接名字
- List<Map<String, Object>> mc = new ArrayList<>();
- m1.put("name", "总分");
- List<BigDecimal> zf = new ArrayList<>();
- for (ZbZdBaseInfo zb : ls){
- Map<String, Object> m2 = new HashMap<>();
- zf.add(zb.getScore());
- m2.put(zb.getId(), zb.getName());
- mc.add(m2);
- }
- m1.put("data", zf);
- resultList.add(m1);
- resultMap.put("mc", mc);
- // 查询得分
- List<ZbReportCycleScore> list = scoreDao.selectTargetDictScoreByReportCycle(reportCycle);
- if(null == list || list.isEmpty()){
- // 没有得分就只显示总分
- Map<String, Object> m3 = new HashMap<>();
- m3.put("name", "得分");
- m3.put("data", new int[]{0, 0, 0, 0, 0});
- resultList.add(m3);
- resultMap.put("infoData", resultList);
- return ResultVoUtil.success(resultMap);
- }
- BigDecimal B1 = BigDecimal.ZERO;
- BigDecimal B2 = BigDecimal.ZERO;
- BigDecimal B3 = BigDecimal.ZERO;
- BigDecimal B4 = BigDecimal.ZERO;
- BigDecimal B5 = BigDecimal.ZERO;
- for (ZbReportCycleScore score : list){
- String pid = score.getPid();
- String s = score.getReportScore();
- if(StringUtil.isBlank(s)){
- s = "0";
- }
- if(pid.startsWith("B1")){
- B1 = DecimalUtil.add(B1, new BigDecimal(s));
- } else if(pid.startsWith("B2")){
- B2 = DecimalUtil.add(B2, new BigDecimal(s));
- } else if(pid.startsWith("B3")){
- B3 = DecimalUtil.add(B3, new BigDecimal(s));
- } else if(pid.startsWith("B4")){
- B4 = DecimalUtil.add(B4, new BigDecimal(s));
- } else if(pid.startsWith("B5")){
- B5 = DecimalUtil.add(B5, new BigDecimal(s));
- }
- }
- // 拼接得分
- Map<String, Object> m3 = new HashMap<>();
- m3.put("name", "得分");
- List<BigDecimal> df = new ArrayList<>();
- df.add(B1);
- df.add(B2);
- df.add(B3);
- df.add(B4);
- df.add(B5);
- m3.put("data", df);
- resultList.add(m3);
- resultMap.put("infoData", resultList);
- return ResultVoUtil.success(resultMap);
- }
- }
|