Commit 363c649c by 杨林龙

1.50.0 开发1.50.0需求版本 优化用户行为列表返回结果

1 parent f1c3ff63
......@@ -393,24 +393,28 @@ public class RiskAssessmentService {
String sn = basicDeviceDTO.get().getSn();
List<UserBehaviorWeekDTO> userBehaviorWeekDTOList = deviceJourneyMapper.statisticsDeviceJourneyWithWeek(sn);
// 获取最大的周数
Integer maxWeekNum = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekNum).max(Integer::compareTo).orElse(0);
Integer maxWeekInt = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekInt).max(Integer::compareTo).orElse(0);
// 获取最小的周数
Integer minWeekNum = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekNum).min(Integer::compareTo).orElse(0);
Integer minWeekInt = userBehaviorWeekDTOList.stream().map(UserBehaviorWeekDTO::getWeekInt).min(Integer::compareTo).orElse(0);
// 如果数据不满一周 则按照每日数量进行统计
if (Objects.equals(maxWeekNum, minWeekNum)) {
if (Objects.equals(maxWeekInt, minWeekInt)) {
userBehaviorInformationVO.setStatisticsType(2);
List<UserBehaviorDayDTO> userBehaviorDayDTOList = deviceJourneyMapper.statisticsDeviceJourneyWithDay(sn);
userBehaviorInformationVO.setUserBehaviorDayDTOList(getUserBehaviorDayList(userBehaviorDayDTOList, minWeekNum, maxWeekNum));
// 获取最大的天数
Integer maxDayInt = userBehaviorDayDTOList.stream().map(UserBehaviorDayDTO::getDayInt).max(Integer::compareTo).orElse(0);
// 获取最小的天数
Integer minDayInt = userBehaviorDayDTOList.stream().map(UserBehaviorDayDTO::getDayInt).min(Integer::compareTo).orElse(0);
userBehaviorInformationVO.setUserBehaviorDayDTOList(getUserBehaviorDayList(userBehaviorDayDTOList, minDayInt, maxDayInt));
return userBehaviorInformationVO;
}
// 如果最多的周数减去18周 和最小的周进行对比
userBehaviorInformationVO.setStatisticsType(1);
int num = maxWeekNum - 18;
if (minWeekNum > num) {
userBehaviorInformationVO.setUserBehaviorWeekDTOList(getUserBehaviorWeekList(userBehaviorWeekDTOList, minWeekNum, maxWeekNum));
int num = maxWeekInt - 18;
if (minWeekInt > num) {
userBehaviorInformationVO.setUserBehaviorWeekDTOList(getUserBehaviorWeekList(userBehaviorWeekDTOList, minWeekInt, maxWeekInt));
} else {
userBehaviorInformationVO.setUserBehaviorWeekDTOList(getUserBehaviorWeekList(userBehaviorWeekDTOList.stream().filter(vo -> vo.getWeekNum() >= num).collect(Collectors.toList()), num, maxWeekNum));
userBehaviorInformationVO.setUserBehaviorWeekDTOList(getUserBehaviorWeekList(userBehaviorWeekDTOList.stream().filter(vo -> vo.getWeekNum() >= num).collect(Collectors.toList()), num, maxWeekInt));
}
}
return userBehaviorInformationVO;
......@@ -427,11 +431,11 @@ public class RiskAssessmentService {
return userBehaviorWeekNewList;
}
private List<UserBehaviorDayDTO> getUserBehaviorDayList(List<UserBehaviorDayDTO> userBehaviorWeekDTOList, Integer minWeekNum, Integer maxWeekNum) {
private List<UserBehaviorDayDTO> getUserBehaviorDayList(List<UserBehaviorDayDTO> userBehaviorWeekDTOList, Integer minDayInt, Integer maxDayInt) {
List<UserBehaviorDayDTO> userBehaviorDayNewList = Lists.newArrayList();
Map<Integer, Integer> userBehaviorDayDTOMap = userBehaviorWeekDTOList.stream().collect(Collectors.toMap(UserBehaviorDayDTO::getDayInt, UserBehaviorDayDTO::getDayNum, (o, n) -> n));
log.info("userBehaviorDayDTOMap===" + JSONUtil.toJsonStr(userBehaviorDayDTOMap));
for (int i = minWeekNum; i < maxWeekNum + 1; i++) {
for (int i = minDayInt; i < maxDayInt + 1; i++) {
Integer dayNum = userBehaviorDayDTOMap.getOrDefault(i, 0);
userBehaviorDayNewList.add(new UserBehaviorDayDTO(i, dayNum));
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!