IntelligentRecognition/ah-jjsp-service/.svn/pristine/89/89d90e9d297b4bde34c1eca59ae...

124 lines
4.9 KiB
Plaintext
Raw Normal View History

2024-05-24 16:09:40 +08:00
package com.sercurityControl.proteam.dutyTask.service;
import com.securityControl.common.core.web.domain.AjaxResult;
import com.sercurityControl.proteam.dutyTask.domain.HistoryDto;
import com.sercurityControl.proteam.dutyTask.mapper.HistoryMapper;
import com.sercurityControl.proteam.util.DateTimeHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author 10488
* 综合展示 历史数据
*/
@Service("HistoryService")
@Slf4j
public class HistoryServiceImpl implements HistoryService {
@Resource(name = "HistoryMapper")
private HistoryMapper mapper;
@Override
public AjaxResult getHistoryByDateType(HistoryDto dto) {
String type = Objects.isNull(dto.getDateType()) ? "1" : dto.getDateType();
switch (type) {
case "2":
return getHistoryByWeek(dto);
case "3":
return getHistoryByMonth(dto);
default:
return getHistoryByDay(dto);
}
}
public AjaxResult getHistoryByDay(HistoryDto dto) {
Map<String, Object> map = new HashMap<>(3);
List<Integer> valueList = new ArrayList<>();
List<Integer> valueList2 = new ArrayList<>();
int num = 30;
String type = "3";
if(Objects.equals(dto.getType(),type)){
// 作业票
num = 7;
}
List<String> dateList = DateTimeHelper.getDateList(num);
dateList.forEach(date -> {
dto.setStartTime(date);
dto.setEndTime(date);
try {
List<Map<String, Object>> dataMap = mapper.getHistoryByDateType(dto);
valueList.add(Integer.parseInt(String.valueOf(dataMap.get(0).get("num"))));
valueList2.add(Integer.parseInt(String.valueOf(dataMap.get(1).get("num"))));
} catch (NumberFormatException e) {
log.error("历史记录-日",e);
valueList.add(0);
valueList2.add(0);
}
});
map.put("nameList", dateList);
map.put("valueList", valueList);
map.put("valueList2", valueList2);
return AjaxResult.success(map);
}
public AjaxResult getHistoryByWeek(HistoryDto dto) {
Map<String, Object> map = new HashMap<>(3);
List<String> timeList = com.securityControl.common.core.utils.aes.DateTimeHelper.getWeekList();
List<String> collect = timeList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
List<String> times = new ArrayList<>();
List<Integer> valueList = new ArrayList<>();
List<Integer> valueList2 = new ArrayList<>();
collect.forEach(time -> {
String startWeek = com.securityControl.common.core.utils.aes.DateTimeHelper.getWeekStartOrEndTime(time, true);
String endWeek = com.securityControl.common.core.utils.aes.DateTimeHelper.getWeekStartOrEndTime(time, false);
times.add(com.securityControl.common.core.utils.aes.DateTimeHelper.getWeekTimes(time));
dto.setStartTime(startWeek);
dto.setEndTime(endWeek);
try {
List<Map<String, Object>> dataMap = mapper.getHistoryByDateType(dto);
valueList.add(Integer.parseInt(String.valueOf(dataMap.get(0).get("num"))));
valueList2.add(Integer.parseInt(String.valueOf(dataMap.get(1).get("num"))));
} catch (Exception e) {
log.error("历史记录-周",e);
valueList.add(0);
valueList2.add(0);
}
});
map.put("nameList", times);
map.put("valueList", valueList);
map.put("valueList2", valueList2);
return AjaxResult.success(map);
}
public AjaxResult getHistoryByMonth(HistoryDto dto) {
Map<String, Object> map = new HashMap<>(3);
List<String> times = new ArrayList<>();
List<Integer> valueList = new ArrayList<>();
List<Integer> valueList2 = new ArrayList<>();
List<String> monthList = DateTimeHelper.getMonthList();
monthList.forEach(month -> {
String[] monthArr = month.split("~");
times.add(monthArr[0].substring(0, 7));
dto.setStartTime(monthArr[0]);
dto.setEndTime(monthArr[1]);
try {
List<Map<String, Object>> dataMap = mapper.getHistoryByDateType(dto);
valueList.add(Integer.parseInt(String.valueOf(dataMap.get(0).get("num"))));
valueList2.add(Integer.parseInt(String.valueOf(dataMap.get(1).get("num"))));
} catch (NumberFormatException e) {
log.error("历史记录-月",e);
valueList.add(0);
valueList2.add(0);
}
});
map.put("nameList", times);
map.put("valueList", valueList);
map.put("valueList2", valueList2);
return AjaxResult.success(map);
}
}