Bladeren bron

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/main/resources/mapper/zcustom/unit/LargeIssueMapper.xml
zhanghao 1 maand geleden
bovenliggende
commit
cdf386d9dd

+ 7 - 0
src/main/java/com/project/zcustom/exception/GlobalExceptionHandler.java

@@ -1,5 +1,6 @@
 package com.project.zcustom.exception;
 
+import cn.dev33.satoken.exception.NotLoginException;
 import com.project.zcustom.controller.core.AjaxResult;
 import org.springframework.web.bind.MissingServletRequestParameterException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -20,6 +21,12 @@ public class GlobalExceptionHandler {
         return AjaxResult.error(message);
     }
 
+    @ExceptionHandler(NotLoginException.class)
+    public AjaxResult handleMissingParams(NotLoginException ex) {
+        String message = "未登录,请登录!";
+        return AjaxResult.error(401,message);
+    }
+
     @ExceptionHandler(ServiceException.class)
     public AjaxResult serviceException(ServiceException ex) {
         return AjaxResult.error(ex.getMessage());

+ 43 - 17
src/main/java/com/project/zcustom/service/service/smart/impl/PlatBuildingServiceImpl.java

@@ -12,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -29,7 +32,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getPowerAndWaterMonth();
         if (StringUtils.isEmpty(json)){
-            return null;
+            return resultList;
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -49,7 +52,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getAirCondition();
         if (StringUtils.isEmpty(json)){
-            return null;
+            return resultList;
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -71,7 +74,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getTarget();
         if (StringUtils.isEmpty(json)){
-            return null;
+            return resultList;
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -102,7 +105,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.useElectricity();
         if (StringUtils.isEmpty(json)){
-            return null;
+            return resultList;
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -119,15 +122,17 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
 
     public Map<String, Object> greenElectricity(){
-
+        Map<String, Object> data = new HashMap<>();
         String json = platBuildingMapper.greenElectricity();
         if (StringUtils.isEmpty(json)){
-            return null;
+            data.put("publicEnergy", 0);
+            data.put("grennEnergy", 0);
+            return data;
         }
         JSONObject jsonObject = JSONObject.parseObject(json);
         String publicEnergy = jsonObject.getString("publicEnergy");
         String grennEnergy = jsonObject.getString("grennEnergy");
-        Map<String, Object> data = new HashMap<>();
+
         data.put("publicEnergy", publicEnergy);
         data.put("grennEnergy", grennEnergy);
         return data;
@@ -137,7 +142,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         List<Map<String, Object>> resultList = new ArrayList<>();
         String json = platBuildingMapper.carbon();
         if (json == null || json.isEmpty()) {
-            return null;
+            return resultList;
         }
         JSONObject jsonObject = JSONObject.parseObject(json);
         JSONArray dataArray = jsonObject.getJSONArray("data");
@@ -157,7 +162,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         Map<String, Object> res = new HashMap<>();
         String json = platBuildingMapper.energyYear();
         if (json == null || json.isEmpty()) {
-            return null;
+            return res;
         }
         JSONObject dataObject = JSONObject.parseObject(json);
         String yearTotal = dataObject.getString("yearTotal");
@@ -183,7 +188,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         Map<String, Object> res = new HashMap<>();
         String json = platBuildingMapper.powerYear();
         if (json == null || json.isEmpty()) {
-            return null;
+            return res;
         }
         JSONObject dataObject = JSONObject.parseObject(json);
         String yearTotal = dataObject.getString("yearTotal");
@@ -209,7 +214,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         Map<String, Object> res = new HashMap<>();
         String json = platBuildingMapper.waterYear();
         if (json == null || json.isEmpty()) {
-            return null;
+            return res;
         }
         JSONObject dataObject = JSONObject.parseObject(json);
         String yearTotal = dataObject.getString("yearTotal");
@@ -234,8 +239,11 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
     public Map<String, Object> frequency(){
         Map<String, Object> map = new HashMap<>();
         String json = platBuildingMapper.frequency();
-        if (json == null || json.isEmpty()) {
-            return null;
+        if ( StringUtils.isBlank(json)) {
+            map.put("xList", this.getLastSixMonths());
+            Integer[] patrolArray = {0,0,0,0,0,0};
+            map.put("yList", patrolArray);
+            return map;
         }
         List<String> xList = new ArrayList<>();
         List<String> yList = new ArrayList<>();
@@ -255,15 +263,19 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
     public Map<String, Object> patrol(){
         String json = platBuildingMapper.patrol();
-        if (json == null || json.isEmpty()) {
-            return null;
+        Map<String, Object> data = new HashMap<>();
+        if (StringUtils.isBlank(json)) {
+            Integer[] patrolArray = {0,0,0,0,0,0};
+            data.put("patrolArray", patrolArray);
+            data.put("monthArray", this.getLastSixMonths());
+            return data;
         }
         JSONObject jsonObject = JSONObject.parseObject(json);
         JSONArray dataArray = jsonObject.getJSONArray("data");
         JSONObject dataItem = dataArray.getJSONObject(0);
         JSONArray patrolArray = dataItem.getJSONArray("data");
         JSONArray monthArray = jsonObject.getJSONArray("xAxis");
-        Map<String, Object> data = new HashMap<>();
+
         data.put("patrolArray", patrolArray.toJavaList(Double.class));
         data.put("monthArray", monthArray.toJavaList(String.class));
         return data;
@@ -273,7 +285,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         List<Map<String, Object>> resultList = new ArrayList<>();
         String json = platBuildingMapper.patrolPoint();
         if (json == null || json.isEmpty()) {
-            return null;
+            return resultList;
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -435,4 +447,18 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         }
         return list;
     }
+
+    private  String[] getLastSixMonths() {
+        LocalDate currentDate = LocalDate.now();
+        // 自定义格式化模式,确保月份没有前导零并附加“月”字
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M'月'");
+        String[] monthsArray = new String[6];
+
+        for (int i = 0; i < 6; i++) {
+            LocalDate firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth());
+            monthsArray[5 - i] = firstDayOfMonth.format(formatter);
+            currentDate = currentDate.minusMonths(1);
+        }
+        return monthsArray;
+    }
 }

+ 6 - 7
src/main/resources/mapper/zcustom/unit/LargeIssueMapper.xml

@@ -140,13 +140,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 LEFT JOIN large_plat_project b ON a.project_id = b.id
                 LEFT JOIN large_plat_app_org c ON b.app_org = c.app_org
         WHERE
-            a.del_flag = 0
-          AND b.del_flag = 0
-          AND c.del_flag = '0'
-          AND (
-            DATE( a.create_time ) BETWEEN DATE( CURDATE() - 7 )
-            AND CURDATE()
-            )
+        a.del_flag = 0
+        AND b.del_flag = 0
+        AND c.del_flag = '0'
+        AND (
+        DATE( a.create_time ) BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE()
+        )
         <if test="appOrg != '10001'">AND ( c.app_parent_org = #{appOrg} OR c.app_org = #{appOrg} )</if>
         order by a.create_time desc
     </select>