|
@@ -5,7 +5,6 @@ import com.jjt.biz.service.*;
|
|
import com.jjt.biz.vo.BizAccessVO;
|
|
import com.jjt.biz.vo.BizAccessVO;
|
|
import com.jjt.biz.vo.BizTypeVO;
|
|
import com.jjt.biz.vo.BizTypeVO;
|
|
import com.jjt.biz.vo.HlScoreVO;
|
|
import com.jjt.biz.vo.HlScoreVO;
|
|
-import com.jjt.biz.vo.ScoreVO;
|
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
import com.jjt.common.core.controller.BaseController;
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
import com.jjt.common.core.page.TableDataInfo;
|
|
import com.jjt.common.core.page.TableDataInfo;
|
|
@@ -19,11 +18,15 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
|
|
+import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -83,28 +86,120 @@ public class IndexController extends BaseController {
|
|
|
|
|
|
@ApiOperation("应用健康趋势-按月")
|
|
@ApiOperation("应用健康趋势-按月")
|
|
@GetMapping("/hl/month/{date}")
|
|
@GetMapping("/hl/month/{date}")
|
|
- public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") String date) {
|
|
|
|
|
|
+ public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") Date date) {
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
- int year = Integer.parseInt(date.split("-")[0]);
|
|
|
|
- int month = Integer.parseInt(date.split("-")[1]);
|
|
|
|
- LocalDate localDate = LocalDate.of(year, month, 1);
|
|
|
|
- for (int i = 0; i < MODEL_NAMES.length; i++) {
|
|
|
|
|
|
+ HlScore search = new HlScore();
|
|
|
|
+ search.setHlType("2");
|
|
|
|
+ LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
+ Map<String, Object> params = new HashMap<>(16);
|
|
|
|
+ params.put("beginTime", localDate.with(TemporalAdjusters.firstDayOfMonth()) + " 00:00:00");
|
|
|
|
+ params.put("endTime", localDate.with(TemporalAdjusters.lastDayOfMonth()) + " 23:59:59");
|
|
|
|
+ search.setParams(params);
|
|
|
|
+ List<HlScore> list = scoreService.selectHlScoreList(search);
|
|
|
|
+ Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
|
|
|
|
+
|
|
|
|
+ int len = 0;
|
|
|
|
+ List<String> standTime = new ArrayList<>();
|
|
|
|
+ for (Long modelId : resultMap.keySet()) {
|
|
Map<String, Object> map = new HashMap<>(16);
|
|
Map<String, Object> map = new HashMap<>(16);
|
|
- map.put("name", MODEL_NAMES[i]);
|
|
|
|
|
|
+ BizModel model = bizModelService.selectBizModelByModelId(modelId);
|
|
|
|
+ map.put("name", model.getModelName());
|
|
List<String> times = new ArrayList<>();
|
|
List<String> times = new ArrayList<>();
|
|
List<Float> scores = new ArrayList<>();
|
|
List<Float> scores = new ArrayList<>();
|
|
- for (int j = 0; j < localDate.lengthOfMonth(); j++) {
|
|
|
|
- times.add((j + 1) + "");
|
|
|
|
- Float score = Float.valueOf(new Random().nextInt(50) + 50);
|
|
|
|
- scores.add(score);
|
|
|
|
|
|
+ List<HlScore> scoreList = resultMap.get(modelId);
|
|
|
|
+ scoreList = scoreList.stream().sorted(Comparator.comparing(HlScore::getHlDate)).collect(Collectors.toList());
|
|
|
|
+ scoreList.forEach(hs -> {
|
|
|
|
+ times.add(DateUtils.parseDateToStr("dd", hs.getHlDate()));
|
|
|
|
+ if (hs.getHlScore() != null) {
|
|
|
|
+ scores.add(hs.getHlScore().floatValue());
|
|
|
|
+ } else {
|
|
|
|
+ scores.add(100f);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (scoreList.size() > len) {
|
|
|
|
+ len = scoreList.size();
|
|
|
|
+ standTime = times;
|
|
}
|
|
}
|
|
|
|
+
|
|
map.put("time", times);
|
|
map.put("time", times);
|
|
map.put("score", scores);
|
|
map.put("score", scores);
|
|
result.add(map);
|
|
result.add(map);
|
|
}
|
|
}
|
|
|
|
+ standTime(standTime, result);
|
|
return success(result);
|
|
return success(result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation("应用健康趋势-按年")
|
|
|
|
+ @GetMapping("/hl/year/{date}")
|
|
|
|
+ public AjaxResult hlYear(@ApiParam(value = "时间 yyyy", required = true) @PathVariable("date") String date) {
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
+ String sql = "SELECT a.model_name,b.hy,b.hm,b.score from biz_model a,(SELECT model_id,year(hl_date) hy,month(hl_date) hm,AVG(ifnull(hl_score,100)) score" +
|
|
|
|
+ " FROM hl_score t WHERE hl_type=2 AND year(hl_date)=? GROUP BY model_id,hy,hm) b WHERE a.model_id=b.model_id order by hm";
|
|
|
|
+ List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, date);
|
|
|
|
+ Map<String, List<Map<String, Object>>> resultMap = list.stream().collect(Collectors.groupingBy(map -> (String) map.get("model_name")));
|
|
|
|
+ int len = 0;
|
|
|
|
+ List<String> standTime = new ArrayList<>();
|
|
|
|
+ for (String name : resultMap.keySet()) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
|
+ map.put("name", name);
|
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
|
+ List<Float> scores = new ArrayList<>();
|
|
|
|
+ List<Map<String, Object>> detailList = resultMap.get(name);
|
|
|
|
+ detailList.forEach(m -> {
|
|
|
|
+ Integer hm = (Integer) m.get("hm");
|
|
|
|
+ BigDecimal score = (BigDecimal) m.get("score");
|
|
|
|
+ score = score.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
+ times.add(hm + "");
|
|
|
|
+ scores.add(score.floatValue());
|
|
|
|
+ });
|
|
|
|
+ if (detailList.size() > len) {
|
|
|
|
+ len = detailList.size();
|
|
|
|
+ standTime = times;
|
|
|
|
+ }
|
|
|
|
+ map.put("time", times);
|
|
|
|
+ map.put("score", scores);
|
|
|
|
+ result.add(map);
|
|
|
|
+ }
|
|
|
|
+ standTime(standTime, result);
|
|
|
|
+ return success(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 补数据
|
|
|
|
+ *
|
|
|
|
+ * @param standTime
|
|
|
|
+ * @param result
|
|
|
|
+ */
|
|
|
|
+ private void standTime(List<String> standTime, List<Map<String, Object>> result) {
|
|
|
|
+ for (Map<String, Object> map : result) {
|
|
|
|
+ // 创建一个新的 times 和 scores 列表,以确保它们与标准时间序列对齐
|
|
|
|
+ List<String> alignedTimes = new ArrayList<>();
|
|
|
|
+ List<Float> alignedScores = new ArrayList<>();
|
|
|
|
+ // 使用一个Map来存储原始数据,以便快速查找
|
|
|
|
+ Map<String, Float> timeScoreMap = new HashMap<>();
|
|
|
|
+ List<String> times = (List<String>) map.get("time");
|
|
|
|
+ List<Float> scores = (List<Float>) map.get("score");
|
|
|
|
+ for (int i = 0; i < times.size(); i++) {
|
|
|
|
+ timeScoreMap.put(times.get(i), scores.get(i));
|
|
|
|
+ }
|
|
|
|
+ // 遍历标准时间序列,并根据需要添加空值或实际值
|
|
|
|
+ for (String time : standTime) {
|
|
|
|
+ alignedTimes.add(time);
|
|
|
|
+ // 添加时间
|
|
|
|
+ Float score = timeScoreMap.getOrDefault(time, 100F);
|
|
|
|
+ // 如果没有对应的分数,则添加0.0f
|
|
|
|
+ alignedScores.add(score);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新原有的 times 和 scores 列表
|
|
|
|
+ times.clear();
|
|
|
|
+ times.addAll(alignedTimes);
|
|
|
|
+ scores.clear();
|
|
|
|
+ scores.addAll(alignedScores);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@ApiOperation("应用健康趋势-按天")
|
|
@ApiOperation("应用健康趋势-按天")
|
|
@GetMapping("/hl/day/{date}")
|
|
@GetMapping("/hl/day/{date}")
|
|
public AjaxResult hlDay(@ApiParam(value = "时间(yyyy-mm-dd", required = true) @PathVariable("date") Date date) {
|
|
public AjaxResult hlDay(@ApiParam(value = "时间(yyyy-mm-dd", required = true) @PathVariable("date") Date date) {
|
|
@@ -115,18 +210,19 @@ public class IndexController extends BaseController {
|
|
params.put("beginTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 00:00:00");
|
|
params.put("beginTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 00:00:00");
|
|
params.put("endTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 23:59:59");
|
|
params.put("endTime", DateUtils.parseDateToStr("yyyy-MM-dd", date) + " 23:59:59");
|
|
search.setParams(params);
|
|
search.setParams(params);
|
|
-
|
|
|
|
|
|
+ int len = 0;
|
|
|
|
+ List<String> standTime = new ArrayList<>();
|
|
List<HlScore> list = scoreService.selectHlScoreList(search);
|
|
List<HlScore> list = scoreService.selectHlScoreList(search);
|
|
Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
|
|
Map<Long, List<HlScore>> resultMap = list.stream().collect(Collectors.groupingBy(HlScore::getModelId));
|
|
for (Long modelId : resultMap.keySet()) {
|
|
for (Long modelId : resultMap.keySet()) {
|
|
Map<String, Object> map = new HashMap<>(16);
|
|
Map<String, Object> map = new HashMap<>(16);
|
|
- ScoreVO vo = new ScoreVO();
|
|
|
|
BizModel model = bizModelService.selectBizModelByModelId(modelId);
|
|
BizModel model = bizModelService.selectBizModelByModelId(modelId);
|
|
map.put("name", model.getModelName());
|
|
map.put("name", model.getModelName());
|
|
List<String> times = new ArrayList<>();
|
|
List<String> times = new ArrayList<>();
|
|
List<Float> scores = new ArrayList<>();
|
|
List<Float> scores = new ArrayList<>();
|
|
List<HlScore> scoreList = resultMap.get(modelId);
|
|
List<HlScore> scoreList = resultMap.get(modelId);
|
|
scoreList = scoreList.stream().sorted(Comparator.comparing(HlScore::getHlDate)).collect(Collectors.toList());
|
|
scoreList = scoreList.stream().sorted(Comparator.comparing(HlScore::getHlDate)).collect(Collectors.toList());
|
|
|
|
+
|
|
scoreList.forEach(hs -> {
|
|
scoreList.forEach(hs -> {
|
|
times.add(DateUtils.parseDateToStr("HH:mm", hs.getHlDate()));
|
|
times.add(DateUtils.parseDateToStr("HH:mm", hs.getHlDate()));
|
|
if (hs.getHlScore() != null) {
|
|
if (hs.getHlScore() != null) {
|
|
@@ -135,10 +231,18 @@ public class IndexController extends BaseController {
|
|
scores.add(100f);
|
|
scores.add(100f);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ if (scoreList.size() > len) {
|
|
|
|
+ len = scoreList.size();
|
|
|
|
+ standTime = times;
|
|
|
|
+ }
|
|
|
|
+
|
|
map.put("time", times);
|
|
map.put("time", times);
|
|
map.put("score", scores);
|
|
map.put("score", scores);
|
|
result.add(map);
|
|
result.add(map);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ standTime(standTime, result);
|
|
return success(result);
|
|
return success(result);
|
|
}
|
|
}
|
|
|
|
|