| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- 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.TargetManagementDao;
- 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.TableGroupInfo;
- import thyyxxk.webserver.entity.highreport.ZbReportResult;
- 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;
- @Autowired
- public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao, RedisLikeService redis) {
- this.dao = dao;
- this.zbZdDao = zbZdDao;
- this.reportDao = reportDao;
- this.redis = redis;
- }
- /**
- * @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), 2));
- } 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) {
- e.printStackTrace();
- 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){
- // 查不到给他默认报表分组类型
- info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_KS.getCode(), dto.getLevel());
- }
- 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.size() == 0){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标结果记录不存在,请检查!");
- }
- UserInfo user = redis.getUserInfoByCode(TokenUtil.getTokenUserId());
- for (ZbReportResult result : list) {
- result.setOp(user.getName() != null ? user.getName().trim() : user.getName());
- 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);
- }
- }
|