TargetManagementService.java 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. package thyyxxk.webserver.service.targetmanagement;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.jetbrains.annotations.NotNull;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import thyyxxk.webserver.config.exception.ExceptionEnum;
  7. import thyyxxk.webserver.dao.his.highreport.HighReportDao;
  8. import thyyxxk.webserver.dao.his.targetmanagement.TableDisplayInfoDao;
  9. import thyyxxk.webserver.dao.his.targetmanagement.TableGroupInfoDao;
  10. import thyyxxk.webserver.dao.his.targetmanagement.TargetManagementDao;
  11. import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleDao;
  12. import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleScoreDao;
  13. import thyyxxk.webserver.dao.his.targetmanagement.ZbZdBaseInfoDao;
  14. import thyyxxk.webserver.entity.ResultVo;
  15. import thyyxxk.webserver.entity.highreport.HighReportDto;
  16. import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
  17. import thyyxxk.webserver.entity.highreport.ReportType;
  18. import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
  19. import thyyxxk.webserver.entity.highreport.TableGroupInfo;
  20. import thyyxxk.webserver.entity.highreport.ZbReportCycle;
  21. import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;
  22. import thyyxxk.webserver.entity.highreport.ZbReportResult;
  23. import thyyxxk.webserver.entity.highreport.ZbReportScoreDto;
  24. import thyyxxk.webserver.entity.highreport.ZdReportType;
  25. import thyyxxk.webserver.entity.login.UserInfo;
  26. import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
  27. import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
  28. import thyyxxk.webserver.entity.targetmanagement.ZbZdBaseInfo;
  29. import thyyxxk.webserver.service.redislike.RedisLikeService;
  30. import thyyxxk.webserver.utils.DateUtil;
  31. import thyyxxk.webserver.utils.DecimalUtil;
  32. import thyyxxk.webserver.utils.ReportUtil;
  33. import thyyxxk.webserver.utils.ResultVoUtil;
  34. import thyyxxk.webserver.utils.StringUtil;
  35. import thyyxxk.webserver.utils.TargetDictTreeUtil;
  36. import thyyxxk.webserver.utils.TokenUtil;
  37. import java.math.BigDecimal;
  38. import java.util.ArrayList;
  39. import java.util.Comparator;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. import java.util.Map;
  43. import java.util.stream.Collectors;
  44. /**
  45. * @Description: 指标管理
  46. * @Author: hsh
  47. * @CreateTime: 2023-05-30 16:52
  48. * @Version: 1.0
  49. */
  50. @Service
  51. @Slf4j
  52. public class TargetManagementService {
  53. private final TargetManagementDao dao;
  54. private final ZbZdBaseInfoDao zbZdDao;
  55. private final HighReportDao reportDao;
  56. private final RedisLikeService redis;
  57. private final TableGroupInfoDao tableDao;
  58. private final TableDisplayInfoDao displayDao;
  59. private final ZbReportCycleDao cycleDao;
  60. private final ZbReportCycleScoreDao scoreDao;
  61. @Autowired
  62. public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao,
  63. RedisLikeService redis, TableGroupInfoDao tableDao, TableDisplayInfoDao displayDao,
  64. ZbReportCycleDao cycleDao, ZbReportCycleScoreDao scoreDao) {
  65. this.dao = dao;
  66. this.zbZdDao = zbZdDao;
  67. this.reportDao = reportDao;
  68. this.redis = redis;
  69. this.tableDao = tableDao;
  70. this.displayDao = displayDao;
  71. this.cycleDao = cycleDao;
  72. this.scoreDao = scoreDao;
  73. }
  74. /**
  75. * @description: 查询指标字典基本信息
  76. * @author: hsh
  77. * @date: 2023/5/30 17:27
  78. * @param: [dto]
  79. * @return: ResultVo<List<ZbZdBaseInfo>>
  80. **/
  81. public ResultVo<List<ZbZdBaseInfo>> selectTargetDict(TargetManagement dto) {
  82. List<ZbZdBaseInfo> list = zbZdDao.selectZbZdBaseInfo(dto);
  83. return ResultVoUtil.success(list);
  84. }
  85. /**
  86. * @description: 根据id查询指标字典基本信息
  87. * @author: hsh
  88. * @date: 2023/7/5 10:58
  89. * @param: [dto]
  90. * @return: ResultVo<ZbZdBaseInfo>
  91. **/
  92. public ResultVo<ZbZdBaseInfo> selectTargetDictById(TargetManagement dto) {
  93. ZbZdBaseInfo info = zbZdDao.selectZbZdBaseInfoById(dto);
  94. return ResultVoUtil.success(info);
  95. }
  96. /**
  97. * @description: 查询指标树
  98. * @author: hsh
  99. * @date: 2023/6/2 11:11
  100. * @param: [dto]
  101. * @return: ResultVo<List<TargetDictTree>>
  102. **/
  103. public ResultVo<List<TargetDictTree>> selectTargetDictTree(TargetManagement dto) {
  104. List<TargetDictTree> zbList = zbZdDao.selectTargetDictTree(dto);
  105. // 组装指标树
  106. List<TargetDictTree> list = assemblyTargetDictTree(zbList);
  107. return ResultVoUtil.success(list);
  108. }
  109. /**
  110. * @description: 组装指标字典树
  111. * @author: hsh
  112. * @date: 2023/6/2 9:37
  113. * @param: [list, zbList]
  114. * @return: void
  115. **/
  116. private List<TargetDictTree> assemblyTargetDictTree(@NotNull List<TargetDictTree> zbList) {
  117. // 创建树形结构(数据集合作为参数)
  118. TargetDictTreeUtil treeBuild = new TargetDictTreeUtil(zbList);
  119. // 原查询结果转换树形结构
  120. return treeBuild.buildTree();
  121. }
  122. public ResultVo<Map<String, Object>> saveTargetDict(ZbZdBaseInfo dto) {
  123. // 验证sql是否有问题
  124. String msg = sqlCheckAndVerify(dto);
  125. // 补充责任科室以及责任人
  126. if(StringUtil.notBlank(msg)){
  127. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
  128. }
  129. TargetManagement target = new TargetManagement();
  130. target.setId(dto.getId());
  131. target.setPid(dto.getPid());
  132. ZbZdBaseInfo zdBaseInfo = zbZdDao.selectZbZdBaseInfoById(target);
  133. int num;
  134. if(zdBaseInfo != null){
  135. num = zbZdDao.updateZbZdBaseInfo(dto);
  136. } else {
  137. num = zbZdDao.saveZbZdBaseInfo(dto);
  138. }
  139. if(num > 0){
  140. Map<String, Object> m = new HashMap<>();
  141. m.put("1", "保存指标字典成功!");
  142. return ResultVoUtil.success(m);
  143. } else {
  144. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标字典失败!");
  145. }
  146. }
  147. /**
  148. * @description: 更新指标字典数据
  149. * @author: hsh
  150. * @date: 2023/6/2 9:29
  151. * @param: [dto]
  152. * @return: ResultVo<Map<String,Object>>
  153. **/
  154. public ResultVo<Map<String, Object>> updateTargetDict(ZbZdBaseInfo dto) {
  155. // 验证sql是否有问题
  156. String msg = sqlCheckAndVerify(dto);
  157. if(StringUtil.notBlank(msg)){
  158. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg);
  159. }
  160. int num = zbZdDao.updateZbZdBaseInfo(dto);
  161. if(num > 0){
  162. return ResultVoUtil.success(ExceptionEnum.SUCCESS, "更新指标字典成功!");
  163. } else {
  164. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "更新指标字典失败");
  165. }
  166. }
  167. /**
  168. * @description: 验证查询sql是否正确
  169. * @author: hsh
  170. * @date: 2023/5/31 10:11
  171. * @param: [dto]
  172. * @return: String 错误信息
  173. **/
  174. private String sqlCheckAndVerify(@NotNull ZbZdBaseInfo dto) {
  175. String sqlChild = dto.getCalcChild();
  176. String sqlMom = dto.getCalcMom();
  177. String message = "";
  178. if(StringUtil.isBlank(dto.getId())){
  179. message = "id不存在,请检查!";
  180. }
  181. if(StringUtil.isBlank(dto.getName())){
  182. message = "指标名称不存在,请检查!";
  183. }
  184. if(StringUtil.isBlank(dto.getPid())){
  185. message = "父id不存在,请检查!";
  186. }
  187. if(dto.getScore() == null || dto.getScore().doubleValue() < 0){
  188. message = "指标总分不存在或者小于0,请检查!";
  189. }
  190. String isLeaf = dto.getIsLeaf();
  191. if("1".equals(isLeaf)){
  192. // 叶子节点要求填写责任科室,责任人
  193. if(StringUtil.isBlank(dto.getDeptCode())){
  194. message = "责任科室未选择,请检查!";
  195. }
  196. if(StringUtil.isBlank(dto.getOpId())){
  197. message = "责任人未选择,请检查!";
  198. }
  199. if(StringUtil.isBlank(dto.getDefinition())){
  200. message = "指标定义不存在,请检查!";
  201. }
  202. if(StringUtil.isBlank(dto.getMethod())){
  203. message = "指标评审方法不存在,请检查!";
  204. }
  205. if(StringUtil.isBlank(dto.getScoreRule())){
  206. message = "指标计分细则不存在,请检查!";
  207. }
  208. if(StringUtil.notBlank(sqlChild)){
  209. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
  210. message = "保存指标字典失败,分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild);
  211. }
  212. }
  213. if(StringUtil.notBlank(sqlMom)){
  214. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom))){
  215. message = "保存指标字典失败,分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom);
  216. }
  217. }
  218. }
  219. return message;
  220. }
  221. /**
  222. * @description: 查询分子分母指标报表结果
  223. * @author: hsh
  224. * @date: 2023/7/6 9:31
  225. * @param: [dto]
  226. * @return: ResultVo<Map<String,Object>>
  227. **/
  228. public ResultVo<Map<String, Object>> targetSqlExecute(TargetManagement dto) {
  229. String sqlChild = dto.getCalcChild();
  230. String sqlMom = dto.getCalcMom();
  231. if(StringUtil.isBlank(sqlChild)){
  232. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "计算-分子sql不存在,请检查!");
  233. } else {
  234. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
  235. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
  236. }
  237. }
  238. if(StringUtil.notBlank(sqlMom)){
  239. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom))){
  240. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlMom));
  241. }
  242. }
  243. // 转换sql的查询条件
  244. Map<String, ReportBaseInfo> map = ReportUtil.assertReportForTarget(dto);
  245. ReportBaseInfo r1 = map.get("calcChild");
  246. ReportBaseInfo r2 = map.get("calcMom");
  247. // 转换查询dto
  248. HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
  249. // 计算结果
  250. Map<String, Object> resultMap = new HashMap<>();
  251. String child = null;
  252. String mom = null;
  253. if(r1 != null){
  254. String childSql = ReportUtil.callSqlFormat(d, r1.getBaseSql(), r1.getGatherSql(), null, null, null);
  255. child = dao.targetSqlExecute(childSql);
  256. }
  257. if(r2 != null){
  258. String momSql = ReportUtil.callSqlFormat(d, r2.getBaseSql(), r2.getGatherSql(), null, null, null);
  259. mom = dao.targetSqlExecute(momSql);
  260. }
  261. if (StringUtil.notBlank(child)) {
  262. resultMap.put("r1", child);
  263. } else {
  264. resultMap.put("r1", "无");
  265. }
  266. if (StringUtil.notBlank(mom)) {
  267. resultMap.put("r2", mom);
  268. if(StringUtil.notBlank(child)){
  269. resultMap.put("r3", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 4));
  270. } else {
  271. resultMap.put("r3", "无");
  272. }
  273. } else {
  274. resultMap.put("r2", "无");
  275. if (StringUtil.notBlank(child)) {
  276. resultMap.put("r3", child);
  277. } else {
  278. resultMap.put("r3", "无");
  279. }
  280. }
  281. return ResultVoUtil.success(resultMap);
  282. }
  283. /**
  284. * @description: 根据id查询分子分母指标报表结果
  285. * @author: hsh
  286. * @date: 2023/7/6 9:30
  287. * @param: [dto]
  288. * @return: ResultVo<Map<String,Object>>
  289. **/
  290. public ResultVo<List<Map<String, Object>>> targetSqlExecuteById(TargetManagement dto) {
  291. ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
  292. ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
  293. if(null == reportChild && null == reportMom){
  294. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "计算-分子或分母指标都不存在,请联系管理员!");
  295. }
  296. if(null == dto.getStartTime() || null == dto.getEndTime()){
  297. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "查询时间不存在,请检查!");
  298. }
  299. // 处理时间(1.时间跨度需要一年一年查询结果; 2.查询时间格式为年月日时分秒: yyyy-MM-DD 24H:mm:ss)
  300. int start = Integer.parseInt(dto.getStartTime());
  301. int end = Integer.parseInt(dto.getEndTime());
  302. // 超过4年只选择4年数据查询
  303. int endIndex = start + 3;
  304. List<Map<String, Object>> list = new ArrayList<>();
  305. for(int i = start; i <= end; i++){
  306. Map<String, Object> resultMap = new HashMap<>();
  307. if(i > endIndex){
  308. break;
  309. }
  310. int s = i - start + 1;
  311. String ks = i + "-01-01 00:00:00";
  312. String js = i + "-12-31 23:59:59";
  313. dto.setStartTime(ks);
  314. dto.setEndTime(js);
  315. HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
  316. // 计算结果
  317. String child = null;
  318. String mom = null;
  319. if(reportChild != null){
  320. String childSql = ReportUtil.callSqlFormat(d, reportChild.getBaseSql(), reportChild.getGatherSql(), null, null, null);
  321. child = dao.targetSqlExecute(childSql);
  322. }
  323. if(reportMom != null){
  324. String momSql = ReportUtil.callSqlFormat(d, reportMom.getBaseSql(), reportMom.getGatherSql(), null, null, null);
  325. mom = dao.targetSqlExecute(momSql);
  326. }
  327. resultMap.put("id", dto.getId());
  328. resultMap.put("pid", dto.getPid());
  329. resultMap.put("index", s);
  330. // 数据统计来源(1:sql统计;2:手动填写输入。)
  331. resultMap.put("dataType", "1");
  332. // 统计年份
  333. resultMap.put("year", i);
  334. resultMap.put("childLabel", i + "年分子结果");
  335. resultMap.put("momLabel", i + "年分母结果");
  336. resultMap.put("calcLabel", i + "年分子/分母的结果");
  337. if (StringUtil.notBlank(child)) {
  338. resultMap.put("childResult", child);
  339. } else {
  340. resultMap.put("childResult", "无");
  341. }
  342. if (StringUtil.notBlank(mom)) {
  343. resultMap.put("momResult", mom);
  344. if(StringUtil.notBlank(child)){
  345. resultMap.put("calcResult", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 4));
  346. } else {
  347. resultMap.put("calcResult", "无");
  348. }
  349. } else {
  350. resultMap.put("momResult", "无");
  351. if (StringUtil.notBlank(child)) {
  352. resultMap.put("calcResult", child);
  353. } else {
  354. resultMap.put("calcResult", "无");
  355. }
  356. }
  357. list.add(resultMap);
  358. }
  359. return ResultVoUtil.success(list);
  360. }
  361. public ResultVo<Map<String, Object>> targetSqlSave(TargetManagement dto) {
  362. String sqlChild = dto.getCalcChild();
  363. String sqlMom = dto.getCalcMom();
  364. if(StringUtil.notBlank(sqlChild)) {
  365. if (!sqlChild.contains("/") && !(sqlChild.contains("select") || sqlChild.contains("SELECT"))) {
  366. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子sql语句不合法,请检查!");
  367. }
  368. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
  369. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分子" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
  370. }
  371. }
  372. if(StringUtil.notBlank(sqlMom)){
  373. if (!sqlMom.contains("/") && !(sqlMom.contains("select") || sqlMom.contains("SELECT"))) {
  374. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母sql语句不合法,请检查!");
  375. }
  376. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild))){
  377. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "分母" + ReportUtil.sqlCheckAndVerifyByKeyword(sqlChild));
  378. }
  379. }
  380. try {
  381. int num = 0;
  382. // 获取指标字典sql信息
  383. Map<String, ReportBaseInfo> map = ReportUtil.assertReportForTarget(dto);
  384. // 查询指标字典是否以及存在分子分母的sql指标报表信息
  385. ZbZdBaseInfo info = zbZdDao.selectZbZdBaseInfoById(dto);
  386. if(null != map.get("calcChild")){
  387. // 已经配置分子sql指标报表信息
  388. ReportBaseInfo r1 = map.get("calcChild");
  389. // 更新分子指标报表的sql信息
  390. if(StringUtil.notBlank(info.getChildId())){
  391. dao.deleteReportBaseInfoById(r1.getReportId());
  392. } else {
  393. // 保存分子指标报表的id
  394. zbZdDao.updateZbZdBaseInfoCalcId(dto.getId(), dto.getPid() ,r1.getReportId(), null);
  395. }
  396. num += dao.insert(r1);
  397. }
  398. if(null != map.get("calcMom")){
  399. ReportBaseInfo r2 = map.get("calcMom");
  400. if(StringUtil.notBlank(info.getMomId())){
  401. dao.deleteReportBaseInfoById(r2.getReportId());
  402. } else {
  403. // 保存分母指标报表的id
  404. zbZdDao.updateZbZdBaseInfoCalcId(dto.getId(), dto.getPid(), null, r2.getReportId());
  405. }
  406. num += dao.insert(r2);
  407. }
  408. Map<String, Object> resultMap = new HashMap<>();
  409. if(num == 0){
  410. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标sql以及报表失败!");
  411. }
  412. resultMap.put("cg", "保存指标sql以及报表成功!");
  413. return ResultVoUtil.success(resultMap);
  414. } catch (Exception e) {
  415. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标sql以及报表失败!");
  416. }
  417. }
  418. /**
  419. * @description: 根据id和父id删除指标字典
  420. * @author: hsh
  421. * @date: 2023/6/21 11:05
  422. * @param: [dto]
  423. * @return: ResultVo<Map<String,Object>>
  424. **/
  425. public ResultVo<Map<String, Object>> deleteTargetDictById(TargetManagement dto) {
  426. if(StringUtil.isBlank(dto.getId())){
  427. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
  428. }
  429. if(StringUtil.isBlank(dto.getPid())){
  430. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
  431. }
  432. Map<String, Object> resultMap = new HashMap<>();
  433. int num = zbZdDao.deleteTargetDictById(dto.getId(), dto.getPid());
  434. if(num == 0){
  435. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标字典失败!");
  436. }
  437. resultMap.put("cg", "删除指标字典成功!");
  438. return ResultVoUtil.success(resultMap);
  439. }
  440. /**
  441. * @description: 查询指标字典的分子分母sql
  442. * @author: hsh
  443. * @date: 2023/6/30 15:19
  444. * @param: [dto]
  445. * @return: ResultVo<Map<String,Object>>
  446. **/
  447. public ResultVo<Map<String, Object>> selectTargetSql(TargetManagement dto) {
  448. if (StringUtil.isBlank(dto.getId())) {
  449. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
  450. }
  451. if (StringUtil.isBlank(dto.getPid())) {
  452. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
  453. }
  454. Map<String, Object> resultMap = new HashMap<>();
  455. ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
  456. ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
  457. resultMap.put("reportChild", reportChild);
  458. resultMap.put("reportMom", reportMom);
  459. return ResultVoUtil.success(resultMap);
  460. }
  461. /**
  462. * @description: 查询指标字典的分子分母sql的详细内容
  463. * @author: hsh
  464. * @date: 2023/6/30 15:20
  465. * @param: [dto]
  466. * @return: ResultVo<Map<String,Object>>
  467. **/
  468. public ResultVo<Map<String, Object>> selectTargetSqlDetail(TargetManagement dto) {
  469. if (StringUtil.isBlank(dto.getId())) {
  470. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
  471. }
  472. if (StringUtil.isBlank(dto.getPid())) {
  473. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "父id不存在,请检查!");
  474. }
  475. Map<String, Object> resultMap = new HashMap<>();
  476. ReportBaseInfo reportBaseInfo = dao.selectReportBaseInfoById(dto.getId(), dto.getPid());
  477. if (reportBaseInfo == null) {
  478. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询指标不存在!");
  479. }
  480. resultMap.put("report", reportBaseInfo);
  481. return ResultVoUtil.success(resultMap);
  482. }
  483. /**
  484. * @description: 查询指标报表数据
  485. * @author: hsh
  486. * @date: 2023/7/7 10:19
  487. * @param: [dto]
  488. * @return: ResultVo<List<Map<String, Object>>>
  489. **/
  490. public ResultVo<List<Map<String, Object>>> selectReportDictTree(HighReportDto dto){
  491. // 查询所有使用的指标报表数据
  492. List<ReportBaseInfo> list = reportDao.selectReportDictTree();
  493. // 查询指标类型
  494. List<ZdReportType> reportTypes = reportDao.selectReportType();
  495. Map<String, ZdReportType> typeMap = new HashMap<>();
  496. for (ZdReportType zdReport : reportTypes) {
  497. typeMap.put(zdReport.getReportType(), zdReport);
  498. }
  499. Map<String, List<ReportBaseInfo>> reportMap = list.stream().collect(Collectors.groupingBy(ReportBaseInfo::getReportType));
  500. List<Map<String, Object>> resultList = new ArrayList<>();
  501. Map<String, Object> rootMap = new HashMap<>();
  502. rootMap.put("id", "zbJc");
  503. rootMap.put("pid", "0");
  504. rootMap.put("label", "指标监测");
  505. List<Map<String, Object>> rootChildList = new ArrayList<>();
  506. for(Map.Entry<String, List<ReportBaseInfo>> entry: reportMap.entrySet()){
  507. Map<String, Object> map = new HashMap<>();
  508. List<ReportBaseInfo> l = entry.getValue();
  509. String type = entry.getKey();
  510. String reportName = typeMap.get(type) == null ? "" : typeMap.get(type).getReportLabel();
  511. if(StringUtil.notBlank(reportName)){
  512. map.put("id", type);
  513. map.put("pid", "zbJc");
  514. map.put("label", reportName);
  515. map.put("sort", typeMap.get(type).getSort());
  516. } else {
  517. map.put("id", type);
  518. map.put("label", ReportType.QT.getName());
  519. map.put("sort", "999");
  520. }
  521. map.put("pid", "zbJc");
  522. List<Map<String, Object>> child = AssertReportTree(l, type);
  523. map.put("children", child);
  524. rootChildList.add(map);
  525. }
  526. rootMap.put("children", rootChildList.stream().sorted(Comparator.comparingInt(e -> Integer.parseInt(String.valueOf(e.get("sort"))))).collect(Collectors.toList()));
  527. resultList.add(rootMap);
  528. return ResultVoUtil.success(resultList);
  529. }
  530. /**
  531. * @description: 组装指标报表树数据
  532. * @author: hsh
  533. * @date: 2023/7/7 11:34
  534. * @param: [list, type]
  535. * @return: List<Map<String, Object>>
  536. **/
  537. private List<Map<String, Object>> AssertReportTree(List<ReportBaseInfo> list, String type) {
  538. List<Map<String, Object>> resultList = new ArrayList<>();
  539. for(ReportBaseInfo info : list){
  540. Map<String, Object> map = new HashMap<>();
  541. map.put("id", info.getReportId());
  542. map.put("pid", type);
  543. map.put("label", info.getReportName());
  544. resultList.add(map);
  545. }
  546. return resultList;
  547. }
  548. /**
  549. * @description: 根据报表id作废指标报表
  550. * @author: hsh
  551. * @date: 2023/7/7 16:13
  552. * @param: [dto]
  553. * @return: ResultVo<Map<String,Object>>
  554. **/
  555. public ResultVo<Map<String, Object>> deleteReportDictById(TargetManagement dto) {
  556. if (StringUtil.isBlank(dto.getId())) {
  557. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id不存在,请检查!");
  558. }
  559. Map<String, Object> resultMap = new HashMap<>();
  560. int num = reportDao.updateReportDictById(dto.getId());
  561. if (num == 0) {
  562. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "作废指标报表失败!");
  563. }
  564. resultMap.put("cg", "作废指标报表成功!");
  565. return ResultVoUtil.success(resultMap);
  566. }
  567. /**
  568. * @description: 查询指标报表信息
  569. * @author: hsh
  570. * @date: 2023/7/7 16:52
  571. * @param: [dto]
  572. * @return: ResultVo<List<ReportBaseInfo>>
  573. **/
  574. public ResultVo<List<ReportBaseInfo>> selectReportDict(HighReportDto dto) {
  575. List<ReportBaseInfo> list = reportDao.selectReportDict(dto);
  576. return ResultVoUtil.success(list);
  577. }
  578. /**
  579. * @description: 查询指标报表类型字典信息
  580. * @author: hsh
  581. * @date: 2023/7/11 16:26
  582. * @param: []
  583. * @return: ResultVo<List<ZdReportType>>
  584. **/
  585. public ResultVo<List<ZdReportType>> selectReportType() {
  586. List<ZdReportType> list = reportDao.selectReportType();
  587. return ResultVoUtil.success(list);
  588. }
  589. /**
  590. * @description: 查询报表sql统计总计结果,用来验证报表sql是否编写正确
  591. * @author: hsh
  592. * @date: 2023/7/12 16:52
  593. * @param: [dto]
  594. * @return: ResultVo<Map<String,Object>>
  595. **/
  596. public ResultVo<Map<String, Object>> reportSqlExecute(TargetManagement dto){
  597. if(StringUtil.isBlank(dto.getBaseSql())){
  598. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "基础sql不存在,请检查!");
  599. }
  600. if(StringUtil.isBlank(dto.getGatherSql())){
  601. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "聚合sql不存在,请检查!");
  602. }
  603. if(StringUtil.notBlank(ReportUtil.sqlCheckAndVerifyByKeyword(dto.getBaseSql()))){
  604. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, ReportUtil.sqlCheckAndVerifyByKeyword(dto.getBaseSql()));
  605. }
  606. Map<String, Object> resultMap = new HashMap<>();
  607. HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
  608. String calcSql = ReportUtil.callSqlFormat(d, dto.getBaseSql(), dto.getGatherSql(), null, null, null);
  609. String result = dao.targetSqlExecute(calcSql);
  610. if(StringUtil.notBlank(result)){
  611. resultMap.put("r1", result);
  612. } else {
  613. resultMap.put("r1", "无");
  614. }
  615. return ResultVoUtil.success(resultMap);
  616. }
  617. /**
  618. * @description: 查询报表分组类型
  619. * @author: hsh
  620. * @date: 2023/7/19 15:25
  621. * @param: [dto]
  622. * @return: ResultVo<TableGroupInfo>
  623. **/
  624. public ResultVo<TableGroupInfo> selectReportLevel(HighReportDto dto){
  625. TableGroupInfo info = reportDao.selectTableGroupInfoByLevel(dto.getReportId(), dto.getLevel());
  626. if(info == null){
  627. // 查不到给他默认报表分组类型
  628. if(ReportType.GROUP_KS.getCode().equals(dto.getLevel())) {
  629. info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_KS.getCode(), dto.getLevel());
  630. } else if(ReportType.GROUP_ZB.getCode().equals(dto.getLevel())) {
  631. info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_ZB.getCode(), dto.getLevel());
  632. }
  633. }
  634. if(null == info){
  635. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标分组配置不存在,请检查!");
  636. }
  637. return ResultVoUtil.success(info);
  638. }
  639. /**
  640. * @description: 保存指标结果
  641. * @author: hsh
  642. * @date: 2023/7/19 15:27
  643. * @param: [list]
  644. * @return: ResultVo<Map<String,Object>>
  645. **/
  646. public ResultVo<Map<String, Object>> saveTargetReportResult(List<ZbReportResult> list){
  647. Map<String, Object> resultMap = new HashMap<>();
  648. if(list == null || list.isEmpty()){
  649. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标结果记录不存在,请检查!");
  650. }
  651. UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
  652. for (ZbReportResult result : list) {
  653. result.setOp(user.getName() != null ? user.getName().trim() : null);
  654. result.setOpId(user.getCodeRs());
  655. result.setOpTime(DateUtil.now());
  656. // 入库或更新操作
  657. int n = updateAndSaveTargetReportResult(result);
  658. if (n <= 0) {
  659. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标结果失败!");
  660. }
  661. }
  662. resultMap.put("cg", "保存指标结果成功");
  663. return ResultVoUtil.success(resultMap);
  664. }
  665. /**
  666. * @description: 先删后保存数据
  667. * @author: hsh
  668. * @date: 2023/7/21 10:06
  669. * @param: [result]
  670. * @return: int
  671. **/
  672. private int updateAndSaveTargetReportResult(ZbReportResult result) {
  673. if(result == null){
  674. return 0;
  675. }
  676. ZbReportResult r = reportDao.selectReportResultByYear(result.getId(), result.getPid(), result.getYear());
  677. if(r != null){
  678. reportDao.deleteReportResultById(result.getId(), result.getPid(), result.getYear());
  679. }
  680. return reportDao.saveTargetReportResult(result);
  681. }
  682. /**
  683. * @description: 查询指标报表结果
  684. * @author: hsh
  685. * @date: 2023/7/21 11:21
  686. * @param: [dto]
  687. * @return: ResultVo<List<ZbReportResult>>
  688. **/
  689. public ResultVo<List<ZbReportResult>> selectTargetReportResult(TargetManagement dto) {
  690. List<ZbReportResult> list = reportDao.selectReportResultById(dto.getId(), dto.getPid(), dto.getStartTime(), dto.getEndTime());
  691. return ResultVoUtil.success(list);
  692. }
  693. /**
  694. * @description: 保存/更新指标报表基本信息
  695. * @author: hsh
  696. * @date: 2023/7/27 9:55
  697. * @param: [info]
  698. * @return: ResultVo<Map<String,Object>>
  699. **/
  700. public ResultVo<Map<String, Object>> saveReportBaseInfo(ReportBaseInfo info) {
  701. Map<String, Object> resultMap = new HashMap<>();
  702. if(info == null || StringUtil.isBlank(info.getReportId())){
  703. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报表详情为空,保存指标详情失败!");
  704. }
  705. ReportBaseInfo report = reportDao.selectReportPortalMenu(info.getReportId(), null, null);
  706. if (report != null) {
  707. reportDao.deleteReportBaseInfoById(info.getReportId());
  708. }
  709. int n = dao.insert(info);
  710. if (n <= 0) {
  711. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标详情失败!");
  712. }
  713. resultMap.put("cg", "保存指标详情成功!");
  714. return ResultVoUtil.success(resultMap);
  715. }
  716. /**
  717. * @description: 保存/更新指标分组信息
  718. * @author: hsh
  719. * @date: 2023/9/26 16:19
  720. * @param: [info]
  721. * @return: ResultVo<Map<String,Object>>
  722. **/
  723. public ResultVo<Map<String, Object>> saveTableGroupInfo(TableGroupInfo info) {
  724. Map<String, Object> resultMap = new HashMap<>();
  725. if(info == null || StringUtil.isBlank(info.getReportId())){
  726. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标分组信息为空,保存指标分组信息失败!");
  727. }
  728. if(ReportType.GROUP_KS.getCode().equals(info.getReportId()) || ReportType.GROUP_ZB.getCode().equals(info.getReportId())){
  729. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标固定分组信息不允许修改/删除!");
  730. }
  731. TableGroupInfo table = reportDao.selectTableGroupInfo(info.getReportId(), null);
  732. if (table != null) {
  733. reportDao.deleteTableGroupInfoById(info.getReportId());
  734. }
  735. int n = tableDao.insert(info);
  736. if (n <= 0) {
  737. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标分组信息失败!");
  738. }
  739. resultMap.put("cg", "保存指标详情成功!");
  740. return ResultVoUtil.success(resultMap);
  741. }
  742. public ResultVo<List<Map<String, Object>>> selectReportLevelDict() {
  743. List<Map<String, Object>> list = tableDao.selectReportLevelDict();
  744. return ResultVoUtil.success(list);
  745. }
  746. /**
  747. * @Description 查询指标报表的所有id以及名称
  748. * @Author hsh
  749. * @param reportType 指标报表类型
  750. * @return list
  751. * @Date 2024/4/8 10:15
  752. */
  753. public ResultVo<List<Map<String, Object>>> selectTargetZbReportId(String reportType) {
  754. List<Map<String, Object>> list = dao.selectTargetZbReportId(reportType);
  755. return ResultVoUtil.success(list);
  756. }
  757. /**
  758. * @Description 查询指标报表详情配置
  759. * @Author hsh
  760. * @param info 指标报表信息
  761. * @return list
  762. * @Date 2024/4/8 10:16
  763. */
  764. public ResultVo<List<TableDisplayInfo>> selectTableDisplay(ReportBaseInfo info) {
  765. return ResultVoUtil.success(displayDao.selectTableDisplayByReportId(info.getReportId(), "patient"));
  766. }
  767. /**
  768. * @Description 更新指标报表详情配置信息
  769. * @Author hsh
  770. * @param info 指标报表详情配置信息
  771. * @return map
  772. * @Date 2024/4/8 10:16
  773. */
  774. public ResultVo<Map<String, Object>> saveTableDisplay(TableDisplayInfo info){
  775. if(null == info || info.getReportId() == null || info.getLevelId() == null || info.getProp() == null){
  776. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标报表详情配置信息不存在,请检查!");
  777. }
  778. Map<String, Object> resultMap = new HashMap<>();
  779. String reportId = info.getReportId();
  780. String levelId = info.getLevelId();
  781. String prop = info.getProp();
  782. TableDisplayInfo displayInfo = displayDao.selectTableDisplayByProp(reportId, levelId, prop);
  783. int num;
  784. try{
  785. if(null != displayInfo){
  786. num = displayDao.updateTableDisplayByProp(info);
  787. } else {
  788. num = displayDao.insert(info);
  789. }
  790. if(num == 0){
  791. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标报表详情配置失败!");
  792. }
  793. resultMap.put("cg", "保存指标报表详情配置成功!");
  794. return ResultVoUtil.success(resultMap);
  795. } catch(Exception e){
  796. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标报表详情配置失败!");
  797. }
  798. }
  799. /**
  800. * @Description 根据指标报表详情配置prop删除指标报表详情配置信息
  801. * @Author hsh
  802. * @param reportId,levelId,prop 报表id,报表等级id,报表配置prop属性
  803. * @return map
  804. * @Date 2024/4/8 10:17
  805. */
  806. public ResultVo<Map<String, Object>> delTableDisplayByProp(String reportId, String levelId, String prop) {
  807. if(reportId == null || levelId == null || prop == null){
  808. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标报表详情配置信息不存在,请检查!");
  809. }
  810. Map<String, Object> resultMap = new HashMap<>();
  811. try{
  812. int num = displayDao.delTableDisplayByProp(reportId, levelId, prop);
  813. if(num == 0){
  814. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标报表详情配置信息失败!");
  815. }
  816. resultMap.put("cg", "删除指标报表详情配置信息成功!");
  817. return ResultVoUtil.success(resultMap);
  818. } catch(Exception e){
  819. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除指标报表详情配置信息失败!");
  820. }
  821. }
  822. /**
  823. * @Description 查询指标年度周期明细
  824. * @Author hsh
  825. * @return list 指标年度周期明细
  826. * @Date 2024/8/15 9:41
  827. */
  828. public ResultVo<List<ZbReportCycle>> selectScoreCycle(){
  829. List<ZbReportCycle> list = cycleDao.selectScoreCycle();
  830. return ResultVoUtil.success(list);
  831. }
  832. /**
  833. * @Description 更新指标周期得分
  834. * @Author hsh
  835. * @param score 指标周期得分详情
  836. * @return map
  837. * @Date 2024/8/15 10:19
  838. */
  839. public ResultVo<Map<String, Object>> updateTargetReportScore(ZbReportCycleScore score){
  840. Map<String, Object> resultMap = new HashMap<>();
  841. String id = score.getId();
  842. String reportCycle = score.getReportCycle();
  843. if(StringUtil.isBlank(id) || StringUtil.isBlank(reportCycle)){
  844. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标id或年度周期信息不全,请检查!");
  845. }
  846. ZbReportCycleScore s = scoreDao.selectZbReportCycleScoreByReportCycle(id, reportCycle);
  847. UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
  848. score.setAuthorId(user.getCode().trim());
  849. score.setAuthorName(user.getName().trim());
  850. int num;
  851. if(null != s){
  852. num = scoreDao.updateTargetReportScoreById(score);
  853. } else {
  854. num = scoreDao.insert(score);
  855. }
  856. if(num > 0){
  857. resultMap.put("cg", "更新指标周期得分成功!");
  858. }
  859. return ResultVoUtil.success(resultMap);
  860. }
  861. /**
  862. * @Description 查询指标周期得分
  863. * @Author hsh
  864. * @param score 指标周期得分参数
  865. * @return score 指标周期得分
  866. * @Date 2024/8/15 15:47
  867. */
  868. public ResultVo<ZbReportCycleScore> selectTargetReportScore(ZbReportCycleScore score){
  869. String id = score.getId();
  870. String reportCycle = score.getReportCycle();
  871. if(StringUtil.isBlank(id) || StringUtil.isBlank(reportCycle)){
  872. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标id或年度周期信息不全,请检查!");
  873. }
  874. ZbReportCycleScore zbScore = scoreDao.selectZbReportCycleScoreByReportCycle(id, reportCycle);
  875. return ResultVoUtil.success(zbScore);
  876. }
  877. /**
  878. * @Description 查询计算指标得分的权限
  879. * @Author hsh
  880. * @return map
  881. * @Date 2024/8/15 16:54
  882. */
  883. public ResultVo<Map<String, Object>> selectScoreCyclePermissions(){
  884. Map<String, Object> resultMap = new HashMap<>();
  885. String permissions = scoreDao.selectScoreCyclePermissions();
  886. if("N".equals(permissions)){
  887. // 不做计算指标得分的权限限制
  888. resultMap.put("permissions", 0);
  889. } else {
  890. UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
  891. String code = user.getCode().trim();
  892. if(permissions.contains(code)){
  893. // 有权限计算指标得分
  894. resultMap.put("permissions", 1);
  895. } else {
  896. // 没有权限计算指标得分
  897. resultMap.put("permissions", 2);
  898. }
  899. }
  900. return ResultVoUtil.success(resultMap);
  901. }
  902. /**
  903. * @Description 查询指标得分情况
  904. * @Author hsh
  905. * @param dto 指标信息
  906. * @return list
  907. * @Date 2024/8/27 16:12
  908. */
  909. public ResultVo<List<Map<String, Object>>> selectTargetDictScoreById(ZbReportScoreDto dto){
  910. String pid = dto.getPid();
  911. String reportCycle = dto.getReportCycle();
  912. if(StringUtil.isBlank(pid) || StringUtil.isBlank(reportCycle)){
  913. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标pid或年度周期信息不全,请检查!");
  914. }
  915. List<Map<String, Object>> list = scoreDao.selectTargetDictScoreByPid(pid, reportCycle);
  916. // 根据pid以及时间查询报表结果
  917. List<ZbReportResult> resultList = reportDao.selectReportResultByPid(pid, dto.getStartTime(), dto.getEndTime());
  918. Map<String, List<ZbReportResult>> resultMap = resultList.stream().collect(Collectors.groupingBy(ZbReportResult::getId, Collectors.toList()));
  919. for (Map<String, Object> map : list){
  920. String id = String.valueOf(map.get("id"));
  921. List<ZbReportResult> results = resultMap.get(id);
  922. if(null != results && !results.isEmpty()){
  923. for(ZbReportResult r : results){
  924. map.put("t_" + r.getYear(), r.getCalcResult());
  925. }
  926. } else {
  927. String s = dto.getStartTime();
  928. int year = Integer.parseInt(s);
  929. for(int j = 0; j < 4; j++){
  930. int f = year + j;
  931. map.put("t_" + f, "");
  932. }
  933. }
  934. }
  935. return ResultVoUtil.success(list);
  936. }
  937. /**
  938. * @Description 根据指标年度周期查询指标章节总分以及得分
  939. * @Author hsh
  940. * @param dto 指标年度周期
  941. * @return list
  942. * @Date 2024/8/30 8:58
  943. */
  944. public ResultVo<Map<String, Object>> selectTargetTotalScoreInfo(ZbReportScoreDto dto){
  945. String reportCycle = dto.getReportCycle();
  946. if(StringUtil.isBlank(reportCycle)){
  947. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有年度周期,请检查!");
  948. }
  949. Map<String, Object> resultMap = new HashMap<>();
  950. // 查询第二级指标(pid是B)
  951. List<Map<String, Object>> resultList = new ArrayList<>();
  952. List<ZbZdBaseInfo> ls = zbZdDao.selectTargetDictScoreBySecond("B");
  953. // 拼接总分
  954. Map<String, Object> m1 = new HashMap<>();
  955. // 拼接名字
  956. List<Map<String, Object>> mc = new ArrayList<>();
  957. m1.put("name", "总分");
  958. List<BigDecimal> zf = new ArrayList<>();
  959. for (ZbZdBaseInfo zb : ls){
  960. Map<String, Object> m2 = new HashMap<>();
  961. zf.add(zb.getScore());
  962. m2.put(zb.getId(), zb.getName());
  963. mc.add(m2);
  964. }
  965. m1.put("data", zf);
  966. resultList.add(m1);
  967. resultMap.put("mc", mc);
  968. // 查询得分
  969. List<ZbReportCycleScore> list = scoreDao.selectTargetDictScoreByReportCycle(reportCycle);
  970. if(null == list || list.isEmpty()){
  971. // 没有得分就只显示总分
  972. Map<String, Object> m3 = new HashMap<>();
  973. m3.put("name", "得分");
  974. m3.put("data", new int[]{0, 0, 0, 0, 0});
  975. resultList.add(m3);
  976. resultMap.put("infoData", resultList);
  977. return ResultVoUtil.success(resultMap);
  978. }
  979. BigDecimal B1 = BigDecimal.ZERO;
  980. BigDecimal B2 = BigDecimal.ZERO;
  981. BigDecimal B3 = BigDecimal.ZERO;
  982. BigDecimal B4 = BigDecimal.ZERO;
  983. BigDecimal B5 = BigDecimal.ZERO;
  984. for (ZbReportCycleScore score : list){
  985. String pid = score.getPid();
  986. String s = score.getReportScore();
  987. if(StringUtil.isBlank(s)){
  988. s = "0";
  989. }
  990. if(pid.startsWith("B1")){
  991. B1 = DecimalUtil.add(B1, new BigDecimal(s));
  992. } else if(pid.startsWith("B2")){
  993. B2 = DecimalUtil.add(B2, new BigDecimal(s));
  994. } else if(pid.startsWith("B3")){
  995. B3 = DecimalUtil.add(B3, new BigDecimal(s));
  996. } else if(pid.startsWith("B4")){
  997. B4 = DecimalUtil.add(B4, new BigDecimal(s));
  998. } else if(pid.startsWith("B5")){
  999. B5 = DecimalUtil.add(B5, new BigDecimal(s));
  1000. }
  1001. }
  1002. // 拼接得分
  1003. Map<String, Object> m3 = new HashMap<>();
  1004. m3.put("name", "得分");
  1005. List<BigDecimal> df = new ArrayList<>();
  1006. df.add(B1);
  1007. df.add(B2);
  1008. df.add(B3);
  1009. df.add(B4);
  1010. df.add(B5);
  1011. m3.put("data", df);
  1012. resultList.add(m3);
  1013. resultMap.put("infoData", resultList);
  1014. return ResultVoUtil.success(resultMap);
  1015. }
  1016. }