Ver código fonte

设置平均值

yq 3 anos atrás
pai
commit
4653e7b401

+ 4 - 4
mhfire-mapping/src/main/resources/mapper/mysql/AlertMapper.xml

@@ -35,24 +35,24 @@
     </resultMap>
     <select id="getCountByHorse" resultType="java.util.Map">
         SELECT
-    HOUR(dcsj) monthTime,
+    HOUR(lasj) monthTime,
     COUNT(id) as aCount,
     ajlx as aType
     FROM
     `alert`
     WHERE
-    dcsj BETWEEN #{startTime} AND #{endTime}
+    lasj BETWEEN #{startTime} AND #{endTime}
     GROUP BY monthTime,ajlx
     </select>
     <select id="getCountByMonth" resultType="java.util.Map">
         SELECT
-    month(dcsj) monthTime,
+    month(lasj) monthTime,
     COUNT(id) as aCount,
     ajlx as aType
     FROM
     `alert`
     WHERE
-    dcsj BETWEEN #{startTime} AND #{endTime}
+    lasj BETWEEN #{startTime} AND #{endTime}
     GROUP BY monthTime,ajlx
     </select>
 

+ 8 - 8
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/AlertServiceImpl.java

@@ -31,23 +31,23 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse(Date startTime,Date endTime) {
         Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByHorse(startTime, endTime));
         int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(startTime, endTime);
-        perfect(typeMap,24,distanceOfTwoDate);
+        perfect(typeMap,24,distanceOfTwoDate,0);
         return typeMap;
     }
 
-    public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times,Integer subTime){
+    public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times,Integer subTime,Integer defaultTime){
         for (String type:ALERT_TYPE) {
             if (!typeMap.containsKey(type)){
                 typeMap.put(type,new ArrayList<>());
             }
-            perfectDate(typeMap.get(type), times,subTime);
+            perfectDate(typeMap.get(type), times,subTime,defaultTime);
         }
     }
 
-    public void perfectDate(List<AlertStatisticsVO> list,Integer times,Integer subTime){
-        for (int i = 1; i <= times; i++) {
+    public void perfectDate(List<AlertStatisticsVO> list,Integer times,Integer subTime,Integer defaultTime){
+        for (int i = defaultTime; i < times; i++) {
             int finalI = i;
-            AlertStatisticsVO alertStatisticsVO = list.stream()
+            list.stream()
                     .filter(asv -> Integer.parseInt(asv.getMonth()) == finalI)
                     .findFirst()
                     .map(asv -> {
@@ -59,9 +59,9 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
                         asv.setMonth(Integer.toString(finalI));
                         asv.setNumber(0);
                         asv.setAvg(0.00);
+                        list.add(asv);
                         return asv;
                     });
-            list.add(alertStatisticsVO);
         }
         list.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getMonth())));
     }
@@ -86,7 +86,7 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth(Date startTime,Date endTime) {
         Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByMonth(startTime, endTime));
         int distanceOfTwoDate =Integer.parseInt(DateUtils.getYear(endTime)) - Integer.parseInt(DateUtils.getYear(startTime)) + 1;
-        perfect(typeMap,12,distanceOfTwoDate);
+        perfect(typeMap,13,distanceOfTwoDate,1);
         return typeMap;
     }
 

+ 10 - 7
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/FireStatisticsServiceImpl.java

@@ -16,6 +16,7 @@ import com.bizmatics.mhfire.service.vo.FireBubbleVO;
 import com.bizmatics.mhfire.service.vo.FireLevelRatioVO;
 import com.bizmatics.mhfire.service.vo.FireUnitPoliceVO;
 import com.google.common.collect.Lists;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -81,14 +82,16 @@ public class FireStatisticsServiceImpl implements FireStatisticsService {
         for (List<FireStatisticsPO> listLimit:subSets) {
             String addressList = listLimit.stream().map(FireStatisticsPO::getAddress).collect(Collectors.joining("|"));
             List<LocateInfo> lonLat = GouldUtil.getLonLat(addressList);
-            for (FireStatisticsPO fireStatisticsPo:listLimit) {
-                fireStatisticsPo.setLatitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLatitude());
-                fireStatisticsPo.setLongitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLongitude());
-                fireStatisticsPo.setDistrict(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getDistrict());
-                fireStatisticsPo.setStreet(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getStreet());
-
+            if (CollectionUtils.isNotEmpty(lonLat)){
+                for (FireStatisticsPO fireStatisticsPo:listLimit) {
+                    fireStatisticsPo.setLatitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLatitude());
+                    fireStatisticsPo.setLongitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLongitude());
+                    fireStatisticsPo.setDistrict(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getDistrict());
+                    fireStatisticsPo.setStreet(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getStreet());
+
+                }
+                fireStatisticsMapper.updateList(listLimit);
             }
-            fireStatisticsMapper.updateList(listLimit);
         }
         return new CommonPage<>(list, page.getTotal(), page.getSize(), page.getCurrent());
     }

+ 13 - 5
mhfire-service/src/main/java/com/bizmatics/mhfire/service/util/GouldUtil.java

@@ -56,11 +56,19 @@ public class GouldUtil {
             if (arrNode.isArray()) {
                 for (JsonNode objNode : arrNode) {
                     LocateInfo locateInfo = new LocateInfo();
-                    String[] locations = StringUtils.split(objNode.get("location").asText(), ",");
-                    locateInfo.setLongitude(Double.parseDouble(locations[0]));
-                    locateInfo.setLatitude(Double.parseDouble(locations[1]));
-                    locateInfo.setDistrict(objNode.get("district").asText());
-                    locateInfo.setStreet(objNode.get("street").asText());
+                    String location = objNode.get("location").asText();
+                    if (StringUtils.isNotBlank(location) && !"[]".equals(location)){
+                        String[] locations = StringUtils.split(objNode.get("location").asText(), ",");
+                        locateInfo.setLongitude(Double.parseDouble(locations[0]));
+                        locateInfo.setLatitude(Double.parseDouble(locations[1]));
+                        locateInfo.setDistrict(objNode.get("district").asText());
+                        locateInfo.setStreet(objNode.get("street").asText());
+                    }else {
+                        locateInfo.setLongitude(0.00);
+                        locateInfo.setLatitude(0.00);
+                        locateInfo.setDistrict("");
+                        locateInfo.setStreet("");
+                    }
                     locateInfos.add(locateInfo);
                 }
             }