|
@@ -13,15 +13,20 @@ 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;
|
|
@@ -47,11 +52,14 @@ public class TargetManagementService {
|
|
|
|
|
|
private final HighReportDao reportDao;
|
|
|
|
|
|
+ private final RedisLikeService redis;
|
|
|
+
|
|
|
@Autowired
|
|
|
- public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao) {
|
|
|
+ public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao, RedisLikeService redis) {
|
|
|
this.dao = dao;
|
|
|
this.zbZdDao = zbZdDao;
|
|
|
this.reportDao = reportDao;
|
|
|
+ this.redis = redis;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -288,7 +296,7 @@ public class TargetManagementService {
|
|
|
* @param: [dto]
|
|
|
* @return: ResultVo<Map<String,Object>>
|
|
|
**/
|
|
|
- public ResultVo<Map<String, Object>> targetSqlExecuteById(TargetManagement dto) {
|
|
|
+ public ResultVo<List<Map<String, Object>>> targetSqlExecuteById(TargetManagement dto) {
|
|
|
ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
|
|
|
ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
|
|
|
|
|
@@ -296,38 +304,74 @@ public class TargetManagementService {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "计算-分子或分母指标都不存在,请联系管理员!");
|
|
|
}
|
|
|
|
|
|
- HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
|
|
|
-
|
|
|
- // 计算结果
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
- 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);
|
|
|
+ if(null == dto.getStartTime() || null == dto.getEndTime()){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "查询时间不存在,请检查!");
|
|
|
}
|
|
|
|
|
|
- if (StringUtil.notBlank(child)) {
|
|
|
- resultMap.put("r1", child);
|
|
|
- } else {
|
|
|
- resultMap.put("r1", "无");
|
|
|
- }
|
|
|
- if (StringUtil.notBlank(mom)) {
|
|
|
- resultMap.put("r2", mom);
|
|
|
- resultMap.put("r3", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 2));
|
|
|
- } else {
|
|
|
- resultMap.put("r2", "无");
|
|
|
+ // 处理时间(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("r3", child);
|
|
|
+ resultMap.put("childResult", child);
|
|
|
} else {
|
|
|
- resultMap.put("r3", "无");
|
|
|
+ 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(resultMap);
|
|
|
+ return ResultVoUtil.success(list);
|
|
|
}
|
|
|
|
|
|
public ResultVo<Map<String, Object>> targetSqlSave(TargetManagement dto) {
|
|
@@ -602,16 +646,82 @@ public class TargetManagementService {
|
|
|
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());
|
|
|
+ return ResultVoUtil.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
}
|