wangbo 4 年之前
父节点
当前提交
5a37caebfb

+ 53 - 8
operation_manager/src/main/java/com/huaxu/order/controller/WorkOrderStatisticsController.java

@@ -24,6 +24,7 @@ import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.util.*;
 
 @RestController
@@ -49,6 +50,7 @@ public class WorkOrderStatisticsController {
             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int statsType,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
+        LocalDate localDate = LocalDate.now();
         //同比日期
         String sameStartDate = null, sameEndDate = null;
         //环比日期
@@ -74,7 +76,12 @@ public class WorkOrderStatisticsController {
         } else if (statsType == 2) {
             startDate = String.format("%s-01", startDate);
             endDate = String.format("%s-01", endDate);
-            endDate = subMonth(endDate,1);
+            if(isCurrentMonth(endDate)==true){
+                endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+            }
+            else {
+                endDate = subMonth(endDate, 1);
+            }
         }
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
@@ -168,6 +175,7 @@ public class WorkOrderStatisticsController {
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
         int maintainerCount = 0;
+        LocalDate localDate = LocalDate.now();
         Map<String,Object> result = new HashMap<>();
         List<Map<String, Object>> statistics = new ArrayList<>(), average =new ArrayList<>();
         //根据用户编号,获取用户的权限
@@ -193,7 +201,12 @@ public class WorkOrderStatisticsController {
                 maintainerCount = userCenterClient.findMaintainerCount(endDate);
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+                if(isCurrentMonth(endDate)==true){
+                    endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 break;
         }
         workOrderManageDto.setStartDate(startDate);
@@ -230,6 +243,7 @@ public class WorkOrderStatisticsController {
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
         //根据用户编号,获取用户的权限
+        LocalDate localDate = LocalDate.now();
         LoginUser loginUser = UserUtil.getCurrentUser();
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
         workOrderManageDto.setTenantId(loginUser.getTenantId());
@@ -249,7 +263,12 @@ public class WorkOrderStatisticsController {
             case 2:
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+                if(isCurrentMonth(endDate)==true){
+                    endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 break;
         }
         workOrderManageDto.setStartDate(startDate);
@@ -267,10 +286,8 @@ public class WorkOrderStatisticsController {
             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int statsType,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
-
-        List<Integer> idList = new ArrayList<>();
+        LocalDate localDate = LocalDate.now();
         List<Map<String,Object>> statistics = new ArrayList<Map<String, Object>>();
-
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
         switch (statsType) {
             case 0:
@@ -284,7 +301,12 @@ public class WorkOrderStatisticsController {
             case 2:
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+                if(isCurrentMonth(endDate)==true){
+                    endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 break;
         }
         workOrderManageDto.setScenesId(scenesId);
@@ -308,6 +330,7 @@ public class WorkOrderStatisticsController {
             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int statsType,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
+        LocalDate localDate = LocalDate.now();
         Map<String, Object> result = new HashMap<>();
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
@@ -327,7 +350,12 @@ public class WorkOrderStatisticsController {
         } else if (statsType == 2) {
             startDate = String.format("%s-01", startDate);
             endDate = String.format("%s-01", endDate);
-            endDate = subMonth(endDate,1);
+            if(isCurrentMonth(endDate)==true){
+                endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+            }
+            else {
+                endDate = subMonth(endDate, 1);
+            }
         }
         workOrderManageDto.setStartDate(startDate);
         workOrderManageDto.setEndDate(endDate);
@@ -421,4 +449,21 @@ public class WorkOrderStatisticsController {
         String reStr = sdf.format(dt1);
         return reStr;
     }
+
+    /**
+     * 日期是否当前月份
+     */
+    public boolean isCurrentMonth(String date) throws ParseException {
+        LocalDate localDate = LocalDate.now();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date dt = sdf.parse(date);
+        Calendar rightNow = Calendar.getInstance();
+        rightNow.setTime(dt);
+        int y = rightNow.get(Calendar.YEAR);
+        int m =rightNow.get(Calendar.MONTH)+1;
+        if( y== localDate.getYear() &&  m == localDate.getMonthValue()){
+            return true;
+        }
+        return false;
+    }
 }

+ 40 - 3
sms_water/src/main/java/com/huaxu/controller/SceneController.java

@@ -24,6 +24,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.ui.ModelMap;
 
 import java.io.IOException;
+import java.rmi.registry.LocateRegistry;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -254,7 +255,12 @@ public class SceneController {
             case 2:
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+                if(isCurrentMonth(endDate)==true){
+                    endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 days = differentDaysByMillisecond(startDate,endDate);
                 break;
         }
@@ -310,6 +316,7 @@ public class SceneController {
             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int statsType,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
+        LocalDate localDate = LocalDate.now();
         SceneEntity sceneEntity = new SceneEntity();
         sceneEntity.setId(Long.parseLong(String.valueOf(id)));
         switch (statsType) {
@@ -324,7 +331,13 @@ public class SceneController {
             case 2:
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+
+                if(isCurrentMonth(endDate)==true){
+                    endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 break;
         }
         List<Map<String,Object>> list = new ArrayList<>();
@@ -357,6 +370,7 @@ public class SceneController {
             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int statsType,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
+        LocalDate localDate = LocalDate.now();
         SceneEntity sceneEntity = new SceneEntity();
         sceneEntity.setId(Long.parseLong(String.valueOf(id)));
         switch (statsType) {
@@ -371,7 +385,12 @@ public class SceneController {
             case 2:
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
-                endDate = subMonth(endDate,1);
+                if(isCurrentMonth(endDate)==true){
+                   endDate = String.format("%s-%s", endDate.substring(0,7),localDate.getDayOfMonth()+1);
+                }
+                else {
+                    endDate = subMonth(endDate, 1);
+                }
                 break;
         }
         List<Map<String,Object>> list = sceneService.selectAlarmLable(sceneEntity,startDate,endDate,sort);
@@ -390,6 +409,7 @@ public class SceneController {
         return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
     }
 
+
     public int differentDaysByMillisecond(String date1,String date2) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date dt1 = sdf.parse(date1);
@@ -399,6 +419,23 @@ public class SceneController {
     }
 
 
+    /**
+     * 日期是否当前月份
+     */
+    public boolean isCurrentMonth(String date) throws ParseException {
+        LocalDate localDate = LocalDate.now();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date dt = sdf.parse(date);
+        Calendar rightNow = Calendar.getInstance();
+        rightNow.setTime(dt);
+        int y = rightNow.get(Calendar.YEAR);
+        int m =rightNow.get(Calendar.MONTH)+1;
+        if( y== localDate.getYear() &&  m == localDate.getMonthValue()){
+            return true;
+        }
+        return false;
+    }
+
     /**
      * 日期增加一年
      */

+ 5 - 0
sms_water/src/main/java/com/huaxu/service/SceneService.java

@@ -500,6 +500,8 @@ public class SceneService extends ServiceImpl<SceneMapper, SceneEntity> {
         return result;
     }
 
+
+
     public List<Map<String,Object>> selectAlarmLable(@Param("scene") SceneEntity sceneEntity, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("sort") int sort){
         return sceneMapper.selectAlarmLable(sceneEntity, startDate, endDate, sort);
     }
@@ -508,6 +510,9 @@ public class SceneService extends ServiceImpl<SceneMapper, SceneEntity> {
         return sceneMapper.selectAlarmDeviceIdBySenceId(id);
     }
 
+
+
+
     public int differentDaysByMillisecond(String date1,String date2) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date dt1 = sdf.parse(date1);