浏览代码

生成报告代码开发

lixing 3 年之前
父节点
当前提交
9cb63c93ad

+ 23 - 0
src/main/java/com/persagy/apm/energy/report/common/utils/DateUtils.java

@@ -288,6 +288,29 @@ public class DateUtils {
         return Date.from(lastMonthFirstDay.atStartOfDay(zoneId).toInstant());
     }
 
+    /**
+     * 判断日期1是否早于日期2
+     *
+     * @param date1 日期1
+     * @param date2 日期2
+     * @return 判断结果
+     * @author lixing
+     * @version V1.0 2021/5/31 10:44 上午
+     */
+    public static boolean compareDate(Date date1, Date date2) {
+        if (date1 == null) {
+            return false;
+        }
+        if (date2 == null) {
+            return true;
+        }
+        ZoneId zoneId = ZoneId.systemDefault();
+
+        LocalDate localDate1 = date1.toInstant().atZone(zoneId).toLocalDate();
+        LocalDate localDate2 = date2.toInstant().atZone(zoneId).toLocalDate();
+        return localDate1.isBefore(localDate2);
+    }
+
     public static void main(String[] args) {
 
         // 2020-02-01

+ 3 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java

@@ -3,6 +3,7 @@ package com.persagy.apm.energy.report.saasweb.service;
 import com.persagy.apm.energy.report.saasweb.model.vo.*;
 import io.swagger.annotations.Api;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -81,4 +82,6 @@ public interface ISaasWebService {
      * @version V1.0 2021/5/21 10:53 上午
      */
     List<PartitionVO> getAvailableAreas(String buildingType);
+
+    List<String> getComparableProjects(List<String> projectIds, Date month);
 }

+ 27 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java

@@ -3,6 +3,7 @@ package com.persagy.apm.energy.report.saasweb.service.impl;
 import com.google.common.collect.Maps;
 import com.persagy.apm.common.model.dto.PoemsFeignBaseDTO;
 import com.persagy.apm.common.response.PoemsFeignResponse;
+import com.persagy.apm.energy.report.common.utils.DateUtils;
 import com.persagy.apm.energy.report.saasweb.model.ConvertSaasWebTool;
 import com.persagy.apm.energy.report.saasweb.model.dto.QueryByProjectIdDTO;
 import com.persagy.apm.energy.report.saasweb.model.dto.QueryPartitionDTO;
@@ -10,6 +11,7 @@ import com.persagy.apm.energy.report.saasweb.model.dto.QueryProjectDTO;
 import com.persagy.apm.energy.report.saasweb.model.vo.*;
 import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
 import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.assertj.core.util.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +28,7 @@ import java.util.stream.Collectors;
  **/
 @Api(value = "运维平台service实现类")
 @Service
+@Slf4j
 public class SaasWebServiceImpl implements ISaasWebService {
     @Autowired
     SaasWebClientWrapper saasWebClientWrapper;
@@ -528,4 +531,28 @@ public class SaasWebServiceImpl implements ISaasWebService {
         }
         return result.doubleValue();
     }
+
+    @Override
+    public List<String> getComparableProjects(List<String> projectIds, Date month) {
+        if (CollectionUtils.isEmpty(projectIds)) {
+            return Lists.newArrayList();
+        }
+        List<String> result = new ArrayList<>();
+        for (String projectId : projectIds) {
+            SimpleProjectVO simpleProjectInfo = getSimpleProjectInfo(projectId);
+            String businessOpeningTime = simpleProjectInfo.getBusinessOpeningTime();
+            try {
+                Date openDate = DateUtils.str2Date(businessOpeningTime, DateUtils.SDFSECOND);
+                Date firstDayOfLastYear = DateUtils.getFirstDayOfLastYear(month);
+                // 如果开业时间早于去年,添加到结果集
+                if (DateUtils.compareDate(openDate, firstDayOfLastYear)) {
+                    result.add(projectId);
+                }
+            } catch (Exception e) {
+                log.error("时间转换异常", e);
+            }
+        }
+        return result;
+    }
+
 }