|
@@ -15,10 +15,8 @@ import com.bizmatics.mhfire.service.util.Arith;
|
|
|
import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author yq
|
|
@@ -27,15 +25,42 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> implements AlertService {
|
|
|
|
|
|
+ private static final String[] ALERT_TYPE = {"火灾","社会救助","抢险救援"};
|
|
|
|
|
|
@Override
|
|
|
- public List<AlertStatisticsVO> getAlertStatisticsByHouse() {
|
|
|
+ public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse() {
|
|
|
Date date = new Date();
|
|
|
Date startTime = DateUtils.getDayStartTime(date);
|
|
|
- return enhanceList(baseMapper.getCountByHorse(startTime, date));
|
|
|
+ Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByHorse(startTime, date));
|
|
|
+ perfect(typeMap,24);
|
|
|
+ return typeMap;
|
|
|
}
|
|
|
|
|
|
- public List<AlertStatisticsVO> enhanceList(List<Map<String,Object>> mapList){
|
|
|
+ public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times){
|
|
|
+ for (String type:ALERT_TYPE) {
|
|
|
+ if (!typeMap.containsKey(type)){
|
|
|
+ typeMap.put(type,new ArrayList<>());
|
|
|
+ }
|
|
|
+ perfectDate(typeMap.get(type), times);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void perfectDate(List<AlertStatisticsVO> list,Integer times){
|
|
|
+ for (int i = 1; i < times; i++) {
|
|
|
+ int finalI = i;
|
|
|
+ if (list.stream().noneMatch(asv->Integer.parseInt(asv.getMonth()) == finalI)){
|
|
|
+ AlertStatisticsVO asv = new AlertStatisticsVO();
|
|
|
+ asv.setMonth(Integer.toString(i));
|
|
|
+ asv.setNumber(0);
|
|
|
+ list.add(asv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getMonth())));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, List<AlertStatisticsVO>> enhanceList(List<Map<String,Object>> mapList){
|
|
|
List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
for (Map<String, Object> map:mapList) {
|
|
|
AlertStatisticsVO alertStatisticsVo = new AlertStatisticsVO();
|
|
@@ -45,22 +70,26 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
|
|
|
alertStatisticsVo.setType(map.get("aType").toString());
|
|
|
list.add(alertStatisticsVo);
|
|
|
}
|
|
|
- return list;
|
|
|
+ return list.stream().collect(Collectors.groupingBy(AlertStatisticsVO::getType));
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<AlertStatisticsVO> getAlertStatisticsByMonth() {
|
|
|
+ public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth() {
|
|
|
Date date = new Date();
|
|
|
Date startTime = DateUtils.getDayStartTime(date);
|
|
|
- return enhanceList(baseMapper.getCountByMonth(startTime, date));
|
|
|
+ Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByMonth(startTime, date));
|
|
|
+ perfect(typeMap,12);
|
|
|
+ return typeMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonPage<Alert> page(Integer current, Integer size, Date startTime, Date endTime) {
|
|
|
IPage<Alert> page = new Page<>(current, size);
|
|
|
LambdaQueryWrapper<Alert> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.between(Alert::getDcsj,startTime,endTime);
|
|
|
+ if (null != startTime && null != endTime){
|
|
|
+ queryWrapper.between(Alert::getDcsj,startTime,endTime);
|
|
|
+ }
|
|
|
page = this.page(page, queryWrapper);
|
|
|
return this.ToCommonPage(page);
|
|
|
}
|
|
@@ -68,9 +97,9 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
|
|
|
@Override
|
|
|
public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
|
|
|
List<AlertStatisticsVO> list = new ArrayList<>();
|
|
|
- list.add(getAsV(startTime, endTime, "火灾"));
|
|
|
- list.add(getAsV(startTime, endTime, "社会救援"));
|
|
|
- list.add(getAsV(startTime, endTime, "抢险救援"));
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[0]));
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[1]));
|
|
|
+ list.add(getAsV(startTime, endTime, ALERT_TYPE[2]));
|
|
|
int sum = list.stream().mapToInt(AlertStatisticsVO::getNumber).sum();
|
|
|
list.forEach(alertStatisticsVO -> {
|
|
|
if (0 == sum){
|