licailing 4 лет назад
Родитель
Сommit
68d574c642

+ 2 - 1
src/main/java/com/izouma/uwip/dto/PatentDTO.java

@@ -3,6 +3,8 @@ package com.izouma.uwip.dto;
 import com.izouma.uwip.domain.LogoPatent;
 import com.izouma.uwip.domain.Patent;
 import com.izouma.uwip.enums.ApplyStatus;
+import com.izouma.uwip.enums.CountryWorkflow;
+import com.izouma.uwip.enums.DomesticWorkflow;
 import com.izouma.uwip.enums.LogoWorkflow;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -26,7 +28,6 @@ public class PatentDTO {
         this.name = patent.getName();
         this.uwNo = patent.getUwNo();
         this.applyStatus = patent.getApplyStatus();
-
     }
 
     public PatentDTO(LogoPatent patent) {

+ 66 - 6
src/main/java/com/izouma/uwip/service/PatentService.java

@@ -1,5 +1,6 @@
 package com.izouma.uwip.service;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.izouma.uwip.domain.Handle;
@@ -21,10 +22,7 @@ import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -78,17 +76,23 @@ public class PatentService {
         return and;
     }
 
-    public void total() {
+    public Map<String, Object> total() {
+        Map<String, Object> map = new HashMap<>();
+
         List<Patent> patents = patentRepo.findAll();
         List<LogoPatent> logoPatents = logoPatentRepo.findAll();
 
         //总数
         int total = patents.size() + logoPatents.size();
+        map.put("total", total);
+
         //今天
         LocalDate now = LocalDate.now();
         long pToday = patents.stream().filter(patent -> patent.getCreatedAt().toLocalDate().equals(now)).count();
         long lToday = logoPatents.stream().filter(patent -> patent.getCreatedAt().toLocalDate().equals(now)).count();
         int today = (int) (pToday + lToday);
+        map.put("today", today);
+
         //进行中
         List<Patent> pInProgress = patents.stream()
                 .filter(patent -> !ApplyStatus.COMPLETED.equals(patent.getApplyStatus()))
@@ -96,12 +100,16 @@ public class PatentService {
         List<LogoPatent> lInProgress = logoPatents.stream()
                 .filter(patent -> !ApplyStatus.COMPLETED.equals(patent.getApplyStatus()))
                 .collect(Collectors.toList());
-
         int inProgress = pInProgress.size() + lInProgress.size();
+        map.put("inProgress", inProgress);
+
         //已结束
         int end = total - inProgress;
+        map.put("end", end);
+
         //代办案件列表
         List<PatentDTO> lAgent = lInProgress.stream().map(PatentDTO::new).collect(Collectors.toList());
+//        List<PatentDTO> pAgent = pInProgress.stream().map(PatentDTO::new).collect(Collectors.toList());
 
         //数据统计
         Map<ApplyStatus, List<Patent>> byPStatus = patents.stream()
@@ -109,10 +117,62 @@ public class PatentService {
 
         Map<ApplyStatus, List<LogoPatent>> byLStatus = logoPatents.stream()
                 .collect(Collectors.groupingBy(LogoPatent::getApplyStatus));
+        List<LogoPatent> applyLPatent = byLStatus.get(ApplyStatus.APPLY_STAGE);
+        List<Patent> applyPatent = byPStatus.get(ApplyStatus.APPLY_STAGE);
+        int apply = CollUtil.isEmpty(applyLPatent) ? 0 : applyLPatent.size() +
+                ((CollUtil.isEmpty(applyPatent)) ? 0 : applyPatent.size());
+
+        List<LogoPatent> grantLPatent = byLStatus.get(ApplyStatus.GRANT_STAGE);
+        List<Patent> grantPatent = byPStatus.get(ApplyStatus.GRANT_STAGE);
+        int grant = CollUtil.isEmpty(grantLPatent) ? 0 : grantLPatent.size() +
+                ((CollUtil.isEmpty(grantPatent)) ? 0 : grantPatent.size());
+
+        List<LogoPatent> reviewLPatent = byLStatus.get(ApplyStatus.REVIEW_STAGE);
+        List<Patent> reviewPatent = byPStatus.get(ApplyStatus.REVIEW_STAGE);
+        int review = CollUtil.isEmpty(reviewLPatent) ? 0 : reviewLPatent.size() +
+                ((CollUtil.isEmpty(reviewPatent)) ? 0 : reviewPatent.size());
+
+        List<LogoPatent> substantiveLPatent = byLStatus.get(ApplyStatus.SUBSTANTIVE_STAGE);
+        List<Patent> substantivePatent = byPStatus.get(ApplyStatus.SUBSTANTIVE_STAGE);
+        int substantive = CollUtil.isEmpty(substantiveLPatent) ? 0 : substantiveLPatent.size() +
+                ((CollUtil.isEmpty(substantivePatent)) ? 0 : substantivePatent.size());
+
+        map.put("apply", apply);
+        map.put("grant", grant);
+        map.put("review", review);
+        map.put("substantive", substantive);
+
 
         //本周数据对比
+        int dayOfWeek = now.getDayOfWeek().getValue() % 7;
+        Map<LocalDate, Integer> weekMap = getData(patents, logoPatents, now, dayOfWeek);
+        map.put("weekMap", weekMap);
 
+        //本月数据对比
+        int dayOfMonth = now.getDayOfMonth() - 1;
+        Map<LocalDate, Integer> monthMap = getData(patents, logoPatents, now, dayOfMonth);
+        map.put("monthMap", monthMap);
 
+        return map;
+    }
+
+    private Map<LocalDate, Integer> getData(List<Patent> patents, List<LogoPatent> logoPatents,
+                                            LocalDate now, int day) {
+        Map<LocalDate, Integer> map = new HashMap<>();
+        while (day >= 0) {
+            LocalDate weekStart = now.minusDays(day);
+
+            long pWeek = patents.stream()
+                    .filter(patent -> patent.getCreatedAt().toLocalDate().equals(weekStart))
+                    .count();
+            long lWeek = logoPatents.stream()
+                    .filter(patent -> patent.getCreatedAt().toLocalDate().equals(weekStart))
+                    .count();
+            day--;
+
+            map.put(weekStart, (int) (pWeek + lWeek));
+        }
+        return map;
     }
 
 

+ 16 - 0
src/test/java/com/izouma/uwip/service/PatentServiceTest.java

@@ -0,0 +1,16 @@
+package com.izouma.uwip.service;
+
+import com.izouma.uwip.ApplicationTests;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class PatentServiceTest extends ApplicationTests {
+
+    @Autowired
+    private PatentService patentService;
+
+    @Test
+    public void total() {
+        System.out.println(patentService.total());
+    }
+}