瀏覽代碼

1、bug修复。

jessie 5 年之前
父節點
當前提交
ceb4b7bb08

+ 220 - 0
src/main/java/com/pavis/ai/app/fda/common/utils/DateUtils.java

@@ -1,13 +1,22 @@
 package com.pavis.ai.app.fda.common.utils;
 
+import com.alibaba.fastjson.JSON;
 import com.pavis.ai.app.fda.common.config.constants.Constants;
+import lombok.extern.slf4j.Slf4j;
 import org.joda.time.DateTime;
 
+import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAdjusters;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Stream;
 
+@Slf4j
 public class DateUtils {
 
     public static String now() {
@@ -35,4 +44,215 @@ public class DateUtils {
         float excTime=(float)(endTime-startTime);
         return excTime + "ms";
     }
+
+    /**
+     * 根据日期得出是周几。
+     * @param date
+     * @return
+     */
+    public static String getWeekNameByDate(String date){
+        if (date.equals("")){
+            // 当前日期的周。
+            LocalDateTime now = LocalDateTime.now();
+            date = now.toLocalDate().toString();
+        }
+        // String date = "2020-07-06";
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.parse(date, pattern);
+        String weekName = localDate.getDayOfWeek().toString();
+        String week = "";
+        switch (weekName){
+            case "MONDAY":
+                week = "1";
+                break;
+            case "TUESDAY":
+                week = "2";
+                break;
+            case "WEDNESDAY":
+                week = "3";
+                break;
+            case "THURSDAY":
+                week = "4";
+                break;
+            case "FRIDAY":
+                week = "5";
+                break;
+            case "SATURDAY":
+                week = "6";
+                break;
+            case "SUNDAY":
+                week = "7";
+                break;
+        }
+        return week;
+    }
+
+    /**
+     * 初始化今天日期,返回LocalDate。
+     * @return
+     */
+    public static LocalDate currDate(){
+        return LocalDate.now();
+    }
+
+    /**
+     * 获取今天的实际日期。
+     * @return
+     */
+    public static String getActualCurrDate(){
+        LocalDateTime now = LocalDateTime.now();
+        String currWeek = now.toLocalDate().toString();
+        log.info("getActualCurrDate获取今天实际日期:{}",currWeek);
+        return currWeek;
+    }
+
+    /**
+     * 获取本周的周五日期。date=""
+     * 获取指定日期的周五的日期。date="2020-07-06"
+     * @return
+     */
+    public static String getFridayOfThisWeek(String date){
+        if (date.equals("")){
+            // true 表示获取今天的日期
+            LocalDate toweekFriday = currDate().with(DayOfWeek.FRIDAY);
+            String currFriday = toweekFriday.toString();
+            log.info("getFridayOfThisWeek获取本周的周五日期:{}",currFriday);
+            return currFriday;
+        }else {
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate toweekFriday = localDate.with(DayOfWeek.FRIDAY);
+            String currFriday = toweekFriday.toString();
+            log.info("getFridayOfThisWeek获取本周的周五日期:{}",currFriday);
+            return currFriday;
+        }
+    }
+
+    /**
+     * 获取下一周的任意一天,默认周一。
+     * @return String
+     */
+    public static String getDayOfNextWeek(){
+        LocalDate localDate = currDate().with(DayOfWeek.FRIDAY);
+        LocalDate todayOfLastWeek = localDate.plusDays(7);
+        LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+        String next = monday.toString();
+        log.info("getDayOfNextWeek获取下一周的日期:{}",monday);
+        return next;
+    }
+
+    /**
+     * 获取周五和上周五的数据。
+     * 获取上周五和上上周五的数据。
+     * @param date
+     * @return
+     */
+    public static Map<String,Object> getFridayOrLastFriday(String date){
+        Map<String,Object> map = new HashMap<>();
+        String week = DateUtils.getWeekNameByDate(date);
+        if (week.equals("6") || week.equals("7")){
+            // 本周周五和上周五
+            String currFriday = DateUtils.getFridayOfThisWeek(date);
+            map.put("friday",currFriday);
+            // 上上周五
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(currFriday, pattern);
+            LocalDate todayOfLastWeek = localDate.minusDays(7);
+            LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+            map.put("lastFriday",fridayLocal.toString());
+            log.info("friday map:{}", JSON.toJSONString(map));
+            return map;
+        }else {
+            // 上周五和上上周五
+            // 指定日期的周。
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate todayOfLastWeek = localDate.minusDays(7);
+            LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+            LocalDate lastFridayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SATURDAY)).minusDays(1);
+            map.put("friday",fridayLocal.toString());
+            map.put("lastFriday",lastFridayLocal.toString());
+            log.info("friday map:{}", JSON.toJSONString(map));
+            return map;
+        }
+    }
+
+    /**
+     * searchinfo 获取该时间的实际每一天。
+     * @return
+     */
+    public static Map<String,Object> getEverydayByActual(String date){
+        Map<String,Object> map = new HashMap<>();
+        String week = DateUtils.getWeekNameByDate(date);
+        if (week.equals("6") || week.equals("7")){
+            // 本周:
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+            System.err.println("if:"+JSON.toJSONString(map));
+            return map;
+        }else {
+            // 上周:
+            Map<String,Object> lastMap = DateUtils.getFridayOrLastFriday(date);
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(lastMap.get("friday").toString(), pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+
+            System.err.println("else:"+JSON.toJSONString(map));
+            return map;
+        }
+    }
+
+    /**
+     * 获取下周的每一天。下周的周五,本周的周五。
+     * @param date
+     * @return
+     */
+    public static Map<String,Object> getEverydayOfNexWeek(String date){
+        Map<String,Object> map = new HashMap<>();
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.parse(date, pattern);
+        map.put("friday",getFridayOfThisWeek(date));
+        // 求这个日期下一周的周一、周日
+        LocalDate todayOfLastWeek = localDate.plusDays(7);
+        LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+        LocalDate sunday = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+        LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+        map.put("monday",monday.toString());
+        map.put("sunday",sunday.toString());
+        map.put("nextFriday",fridayLocal.toString());
+        log.info("下周的每天:{}",JSON.toJSONString(map));
+        return map;
+    }
+
+
+
+
+    /**
+     * 判断日期大小。
+     * @param friday
+     * @param lastFriday
+     * @return
+     */
+    public static Boolean checkDate(String friday,String lastFriday){
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.parse(friday, pattern);
+        LocalDate LastLocalDate = LocalDate.parse(lastFriday, pattern);
+        System.err.println(localDate.compareTo(LastLocalDate));
+        int res = localDate.compareTo(LastLocalDate);
+        return res > 0 ? true : false;
+    }
+
 }

+ 8 - 0
src/main/java/com/pavis/ai/app/fda/controller/BaseController.java

@@ -32,6 +32,14 @@ public class BaseController {
     @Autowired
     private SearchService searchService;
 
+    // @ApiOperation("根据行业id查询详情接口")
+    // @ApiOperationSupport(order = 1)
+    // @GetMapping("/his/hushen")
+    // public ResultBody closeHushenSum(){
+    //
+    //     return ResultBody.ok().data(searchService.hisFind(null));
+    // }
+
     @ApiOperation("根据行业id查询详情接口")
     @ApiOperationSupport(order = 1)
     @PostMapping("/his/find")

+ 34 - 29
src/main/java/com/pavis/ai/app/fda/form/TestCommon.java

@@ -29,6 +29,10 @@ import java.util.stream.Stream;
 @Slf4j
 public class TestCommon {
 
+    /**
+     * 返回随机的float数据。
+     * @return
+     */
     public static Float toInitFloat(){
         float min = 1f;
         float max = 100f;
@@ -108,36 +112,37 @@ public class TestCommon {
      * @return
      */
     public static Map<String,Object> calWeek(String date,Boolean minusOrPlus){
-        log.info("开始获取calweek上一周、下一周数据:{}",date);
-        if (date.equals("")){
-            LocalDateTime now = LocalDateTime.now();
-            date = now.toLocalDate().toString();
-        }
-
-        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-        LocalDate localDate = LocalDate.parse(date, pattern);
-        // LocalDate now = LocalDate.now().plusDays(10);
-        // 求这个日期上一周的周一、周日
-        LocalDate todayOfLastWeek = minusOrPlus ? localDate : localDate.minusDays(7);
-        LocalDate mondayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
-        LocalDate sundayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
-        LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
-        LocalDate lastFridayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SATURDAY)).minusDays(1);
-
-        String monday = mondayLocal.toString();
-        String sunday = sundayLocal.toString();
-        String friday = fridayLocal.toString();
-        String lastFriday = lastFridayLocal.toString();
+        // log.info("开始获取calweek上一周、下一周数据:{}",date);
+        // if (date.equals("")){
+        //     LocalDateTime now = LocalDateTime.now();
+        //     date = now.toLocalDate().toString();
+        // }
+        //
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse(date, pattern);
+        // System.err.println(localDate.toString());
+        // // LocalDate now = LocalDate.now().plusDays(10);
+        // // 求这个日期上一周的周一、周日
+        // LocalDate todayOfLastWeek = minusOrPlus ? localDate : localDate.minusDays(7);
+        // LocalDate mondayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+        // LocalDate sundayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+        // LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+        // LocalDate lastFridayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SATURDAY)).minusDays(1);
+        //
+        // String monday = mondayLocal.toString();
+        // String sunday = sundayLocal.toString();
+        // String friday = fridayLocal.toString();
+        // String lastFriday = lastFridayLocal.toString();
         Map<String,Object> map = new HashMap<>();
-        map.put("monday",monday);
-        map.put("sunday",sunday);
-        map.put("friday",friday);
-        map.put("lastFriday",lastFriday);
-        log.info("当前日期:{}",localDate);
-        log.info("上周的周一:{}",localDate);
-        log.info("上周的周日:{}",localDate);
-        log.info("上周的周五:{}",localDate);
-        log.info("上上周的周五:{}",localDate);
+        // map.put("monday",monday);
+        // map.put("sunday",sunday);
+        // map.put("friday",friday);
+        // map.put("lastFriday",lastFriday);
+        // log.info("当前日期:{}",localDate);
+        // log.info("上周的周一:{}",mondayLocal);
+        // log.info("上周的周日:{}",sundayLocal);
+        // log.info("上周的周五:{}",fridayLocal);
+        // log.info("上上周的周五:{}",lastFridayLocal);
         return map;
     }
 

+ 5 - 0
src/main/java/com/pavis/ai/app/fda/model/IndustryPlate.java

@@ -24,6 +24,11 @@ public class IndustryPlate {
      */
     private String plateId;
 
+    /**
+     * 行业名称
+     */
+    private String plateName;
+
     /**
      * 时间
      */

+ 242 - 158
src/main/java/com/pavis/ai/app/fda/service/impl/SearchServiceImpl.java

@@ -2,6 +2,7 @@ package com.pavis.ai.app.fda.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.pavis.ai.app.fda.common.utils.DateUtils;
 import com.pavis.ai.app.fda.form.TestCommon;
 import com.pavis.ai.app.fda.form.his.IndustryDetail;
 import com.pavis.ai.app.fda.form.his.IndustryDetailsInfo;
@@ -51,7 +52,7 @@ public class SearchServiceImpl implements SearchService {
 
     @Override
     public List<IncInfo> search(SearchInfo searchInfo) {
-        return toIncInfos(true,false,false,true,searchInfo);
+        return toIncInfos(true, false, false, true, searchInfo);
         // QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper();
         // industryInfoQueryWrapper.lambda()
         //         .eq(IndustryInfo::getPlateId, searchInfo.getSearchParam())
@@ -103,15 +104,14 @@ public class SearchServiceImpl implements SearchService {
         // return incInfos;
     }
 
-
     @Override
     public IndustryDetailsInfo hisFind(List<String> ids) {
-        return toDetailsByPlateId(ids,false);
+        return toDetailsByPlateId(ids, false);
     }
 
     @Override
     public IndustryDetailsInfo predictFind(List<String> ids) {
-        return toDetailsByPlateId(ids,true);
+        return toDetailsByPlateId(ids, true);
 
         // List<IndustryDetail> industryDetails = new ArrayList<>();
         //
@@ -160,11 +160,12 @@ public class SearchServiceImpl implements SearchService {
 
     /**
      * 根据行业id获取详情或者未来七天预测接口
+     *
      * @param ids
      * @param detailsFlag
      * @return
      */
-    public IndustryDetailsInfo toDetailsByPlateId(List<String> ids,Boolean detailsFlag){
+    public IndustryDetailsInfo toDetailsByPlateId(List<String> ids, Boolean detailsFlag) {
         // todo 根据id进入详情,计算值。包含下周预测。
         List<IndustryDetail> industryDetails = new ArrayList<>();
         for (String id : ids) {
@@ -174,36 +175,50 @@ public class SearchServiceImpl implements SearchService {
             // 实际数据也即本周数据。
             QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
             industryPlateQueryWrapper.lambda()
-                    .eq(IndustryPlate::getPlateId,id)
+                    .eq(IndustryPlate::getPlateId, id)
                     .orderByDesc(IndustryPlate::getPlateDate);
-            List<IndustryPlate> selIndustryPlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
-            String date = selIndustryPlates.get(0).getPlateDate();
-            log.info("实际数据日期:{}",date);
-            // 2、下周预测,根据改时间获取下一周的周一至周日的每天的预测值。
-            Map<String,Object> weekMap = TestCommon.getEveryday(date,false);
-            String monday = weekMap.get("MONDAY").toString();
-            String sunday = weekMap.get("SUNDAY").toString();
-            List<IndustryPlate> industryPlates = toIndustryPlates(id,monday,sunday);
-            log.info("实际:{}",JSON.toJSONString(industryPlates));
-            System.err.println(detailsFlag);
-            // 3、下周预测放上面,实际数据放下面。
-            if (detailsFlag.equals(true)){
-                System.err.println("if");
-                Map<String,Object> nextWeekMap = TestCommon.getEveryday(date,true);
-                String nextMonday = nextWeekMap.get("MONDAY").toString();
-                String nextSunday = nextWeekMap.get("SUNDAY").toString();
-                List<IndustryPlate> nextIndustryPlates = toIndustryPlates(id,nextMonday,nextSunday);
-                log.info("预测:{}",JSON.toJSONString(nextIndustryPlates));
-                for (IndustryPlate nextIndustryPlate : nextIndustryPlates) {
-                    industryDetails.add(toIndustryDetail(nextIndustryPlate));
+            List<IndustryPlate> datePlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+            if (datePlates.size() > 0) {
+                // String date = datePlates.get(0).getPlateDate();
+                String date = datePlates.size() > 0 ? datePlates.get(0).getPlateDate() : TestCommon.getWeek();
+                // 从这天开始算:周一至周五的数据。
+                log.info("实际数据日期:{}", date);
+                // 2、下周预测,根据改时间获取下一周的周一至周日的每天的预测值。
+                Map<String, Object> weekMap = DateUtils.getEverydayByActual(date);
+                // todo
+                String monday = weekMap.get("MONDAY").toString();
+                String sunday = weekMap.get("SUNDAY").toString();
+                List<IndustryPlate> industryPlates = toIndustryPlates(id, monday, sunday);
+                System.err.println(detailsFlag);
+                // 3、下周预测放上面,实际数据放下面。
+                List<IndustryPlate> nextIndustryPlates = new ArrayList<>();
+                if (detailsFlag.equals(true)) {
+                    System.err.println("if");
+                    Map<String, Object> nextWeekMap = DateUtils.getEverydayOfNexWeek(date);
+                    String nextMonday = nextWeekMap.get("monday").toString();
+                    String nextSunday = nextWeekMap.get("sunday").toString();
+                    nextIndustryPlates = toIndustryPlates(id, nextMonday, nextSunday);
+                    log.info("预测:{}", JSON.toJSONString(nextIndustryPlates));
+                    for (IndustryPlate nextIndustryPlate : nextIndustryPlates) {
+                        industryDetails.add(toIndustryDetail(nextIndustryPlate));
+                    }
+                }
+                if (nextIndustryPlates.size() > 0 && detailsFlag.equals(true)){
+                    // 创建detail列表
+                    log.info("实际:{}", JSON.toJSONString(industryPlates));
+                    for (IndustryPlate industryPlate : industryPlates) {
+                        industryDetails.add(toIndustryDetail(industryPlate));
+                    }
+                }
+                if (detailsFlag.equals(false)){
+                    // 创建detail列表
+                    log.info("实际:{}", JSON.toJSONString(industryPlates));
+                    for (IndustryPlate industryPlate : industryPlates) {
+                        industryDetails.add(toIndustryDetail(industryPlate));
+                    }
                 }
-            }
-            // 创建detail列表
-            for (IndustryPlate industryPlate : industryPlates) {
-                industryDetails.add(toIndustryDetail(industryPlate));
             }
         }
-
         // 4、附带新闻数据。
         SearchInfo searchInfo = SearchInfo.builder()
                 .searchParam(ids.get(0))
@@ -220,70 +235,83 @@ public class SearchServiceImpl implements SearchService {
 
     /**
      * 创建每一天的close、pred值。
+     *
      * @param industryPlate
      * @return
      */
-    public IndustryDetail toIndustryDetail(IndustryPlate industryPlate){
+    public IndustryDetail toIndustryDetail(IndustryPlate industryPlate) {
         IndustryDetail industryDetail = IndustryDetail.builder()
-                    .industryId(industryPlate.getPlateId())
-                    .industryDate(industryPlate.getPlateDate())
-                    .close(industryPlate.getPlateClose())
-                    .pred(industryPlate.getPlateClosePred())
-                    .build();
+                .industryId(industryPlate.getPlateId())
+                .industryDate(industryPlate.getPlateDate())
+                .close(industryPlate.getPlateClose())
+                .pred(industryPlate.getPlateClosePred())
+                .build();
         return industryDetail;
     }
 
     /**
      * 根据plateid、周一至周日的期间获取每一天的close pred值。
+     *
      * @param id
      * @param monday
      * @param sunday
      * @return
      */
-    public List<IndustryPlate> toIndustryPlates(String id,String monday,String sunday){
-        log.info("详情查询:{}",id + ",monday:" + monday + ",sunday:" + sunday);
+    public List<IndustryPlate> toIndustryPlates(String id, String monday, String sunday) {
+        log.info("详情查询:{}", id + ",monday:" + monday + ",sunday:" + sunday);
         QueryWrapper<IndustryPlate> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda()
-                .eq(IndustryPlate::getPlateId,id)
-                .between(IndustryPlate::getPlateDate,monday,sunday);
+        if (DateUtils.checkDate(monday,sunday).equals(true)){
+            queryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId, id)
+                    .orderByDesc(IndustryPlate::getPlateDate)
+                    .between(IndustryPlate::getPlateDate, sunday,monday );
+        }else {
+            System.err.println("else else");
+            queryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId, id)
+                    .orderByDesc(IndustryPlate::getPlateDate)
+                    .between(IndustryPlate::getPlateDate, monday, sunday);
+        }
+
         List<IndustryPlate> industryPlates = industryPlateMapper.selectList(queryWrapper);
         return industryPlates;
     }
 
     @Override
     public List<IncInfo> incLastWeek() {
-        return toIncInfos(true,false,false,false,null);
+        return toIncInfos(true, false, false, false, null);
         // return TestCommon.getIncList();
     }
 
     @Override
     public List<IncInfo> incNextWeekPred() {
-        return toIncInfos(true,false,true,false,null);
+        return toIncInfos(true, false, true, false, null);
     }
 
     @Override
     public List<IncInfo> incLastWeekPred() {
-        return toIncInfos(true,true,false,false,null);
+        return toIncInfos(true, true, false, false, null);
     }
 
     @Override
     public List<IncInfo> decLastWeek() {
-        return toIncInfos(false,false,false,false,null);
+        return toIncInfos(false, false, false, false, null);
     }
 
     @Override
     public List<IncInfo> decNextWeekPred() {
-        return toIncInfos(false,false,true,false,null);
+        return toIncInfos(false, false, true, false, null);
     }
 
     @Override
     public List<IncInfo> decLastWeekPred() {
-        return toIncInfos(false,true,false,false,null);
+        return toIncInfos(false, true, false, false, null);
     }
 
 
     /**
      * 涨幅/跌幅的实际/预测榜方法。
+     *
      * @param tag
      * @param lastTag
      * @param nextTag
@@ -291,108 +319,153 @@ public class SearchServiceImpl implements SearchService {
      * @param searchInfo
      * @return
      */
-    public List<IncInfo> toIncInfos(Boolean tag,Boolean lastTag,Boolean nextTag,Boolean ifIncDec,SearchInfo searchInfo){
-        List<IndustryInfo> industryInfos = new ArrayList<>();
-        // 根据行业id搜索。
-        if (ifIncDec.equals(true)){
-            QueryWrapper<IndustryInfo> queryWrapper = new QueryWrapper();
-            queryWrapper.lambda()
-                    .eq(IndustryInfo::getPlateId, searchInfo.getSearchParam())
-                    .orderByDesc(IndustryInfo::getOperateTime)
-                    .or()
-                    .like(IndustryInfo::getPlateName, searchInfo.getSearchParam())
-                    .or()
-                    .eq(IndustryInfo::getStockId, searchInfo.getSearchParam())
-                    .or()
-                    .like(IndustryInfo::getStockName, searchInfo.getSearchParam());
-            industryInfos = industryInfoMapper.selectList(queryWrapper);
+    public List<IncInfo> toIncInfos(Boolean tag, Boolean lastTag, Boolean nextTag, Boolean ifIncDec, SearchInfo searchInfo) {
+        // 跌幅 上周实际榜:
+        // 1、拿到数据库中倒叙排序的最新的日期。根据当前日期判断是否是周六,是 本周的和上周的数据。否则上周和上上周的数据。
+        List<IndustryPlate> datePlates = getNewest();
+        String date = datePlates.size() > 0 ? datePlates.get(0).getPlateDate() : TestCommon.getWeek();
+        Map<String,Object> actualMap = DateUtils.getFridayOrLastFriday(date);
+        String friday = actualMap.get("friday").toString();
+        String lastFriday = actualMap.get("lastFriday").toString();
+        // 2、去plate查询数据,周五的数据-上周五的数据。根据value倒叙排序,涨幅倒叙 跌幅就是正序。
+        List<IndustryPlate> plates = new ArrayList<>();
+        if (ifIncDec.equals(true)) {
+            plates = searchIndustryPlate(searchInfo,friday,lastFriday);
         }else {
-            QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
-            // 涨幅跌幅。上周周五的close-上上上周五的close >0涨 <0跌
-            // industryInfoQueryWrapper.eq("tag",tag);
-            industryInfoQueryWrapper.isNotNull("id");
-            industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+            plates = findIndustryPlate(true, null,friday , lastFriday);
         }
 
+        // 3、tag涨跌true/false过滤
         IncInfo incInfo;
         List<IncInfo> incInfos = new ArrayList<>();
-        for (IndustryInfo industryInfo : industryInfos) {
-            Map<String,Object> actualMap = ifIncDec ? TestCommon.calWeek(TestCommon.getWeek(),true) :
-                    TestCommon.calWeek(TestCommon.getWeek(),false);
-            List<IndustryPlate> plates = findIndustryPlate(true,industryInfo.getPlateId(),actualMap.get("monday").toString(),actualMap.get("sunday").toString());
-            QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
-            industryPlateQueryWrapper.eq("plate_id",industryInfo.getPlateId());
-            if (lastTag){
-                Map<String,Object> map = TestCommon.calWeek(TestCommon.getWeek(),false);
-                plates = findIndustryPlate(false,industryInfo.getPlateId(),map.get("monday").toString(),map.get("sunday").toString() );
-            }
-            if (nextTag){
-                Map<String,Object> map = TestCommon.calWeek(TestCommon.getNextWeek(),true);
-                plates = findIndustryPlate(false,industryInfo.getPlateId(),map.get("monday").toString(),map.get("sunday").toString() );
+        QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+        industryPlateQueryWrapper.eq("plate_id", null);
+        if (lastTag) {
+            // Map<String, Object> map = TestCommon.calWeek(date, false);
+            Map<String, Object> map = DateUtils.getFridayOrLastFriday(date);
+            plates = findIndustryPlate(false, null, map.get("friday").toString(), map.get("lastFriday").toString());
+        }
+        if (nextTag) {
+            // Map<String, Object> map = TestCommon.calWeek(date, true);
+            Map<String, Object> map = DateUtils.getEverydayOfNexWeek(date);
+            plates = findIndustryPlate(false, null, map.get("friday").toString(), map.get("lastFriday").toString());
+        }
+        // List<IndustryPlate> plates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+        // 此处去重。
+        // List<IndustryPlate> distinctPlatesList = plates.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
+        //         new TreeSet<>(Comparator.comparing(t -> t.getPlateId()))), ArrayList::new));
+        log.info("plates:{}",JSON.toJSONString(plates));
+        for (IndustryPlate plate : plates) {
+            Float value = calLastWeekActual(date,plate.getPlateId());
+            if (lastTag) {
+                value = calLastWeekPred(date,plate.getPlateId());
             }
-            // List<IndustryPlate> plates = industryPlateMapper.selectList(industryPlateQueryWrapper);
-            for (IndustryPlate plate : plates) {
-                Float value = calLastWeekActual(plate.getPlateId());
-                if (lastTag){
-                    value = calLastWeekPred(plate.getPlateId());
-                }
-                if (nextTag){
-                    value = calNextWeekPred(plate.getPlateId());
-                }
-                Boolean industryTag = value > 0.0 ? true : false;
-                log.info("plateId:{}",plate.getPlateId());
-                log.info("value:{}",value);
-                log.info("industryTag:{}",industryTag);
-                incInfo = IncInfo.builder()
-                        .industryId(plate.getPlateId())
-                        .industryName(industryInfo.getPlateName())
-                        .industryValue(value)
-                        .industryTag(industryTag)
-                        .build();
-                incInfos.add(incInfo);
+            if (nextTag) {
+                value = calNextWeekPred(date,plate.getPlateId());
             }
+            Boolean industryTag = value > 0.0 ? true : false;
+            log.info("plateId:{}", plate.getPlateId());
+            log.info("value:{}", value);
+            log.info("industryTag:{}", industryTag);
+            QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
+            industryInfoQueryWrapper.lambda()
+                    .eq(IndustryInfo::getPlateId, plate.getPlateId());
+            // List<IndustryInfo> infos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+            incInfo = IncInfo.builder()
+                    .industryId(plate.getPlateId())
+                    .industryName(plate.getPlateName())
+                    .industryValue(value)
+                    .industryTag(industryTag)
+                    .build();
+            incInfos.add(incInfo);
         }
-        // 排序 排序值: 上周周五的close-上上上周五的close >0涨 <0跌
-        List<IncInfo> sortLists = incInfos.stream()
+        // 排序:涨幅倒序-跌幅正序。 排序值: 上周周五的close-上上上周五的close >0涨 <0跌
+        List<IncInfo> sortLists = tag.equals(true) ? incInfos.stream()
                 .sorted(Comparator.comparing(IncInfo::getIndustryValue).reversed())
+                .collect(Collectors.toList()) : incInfos.stream()
+                .sorted(Comparator.comparing(IncInfo::getIndustryValue))
                 .collect(Collectors.toList());
-        log.info("sort info:{}",JSON.toJSONString(sortLists));
+        log.info("sort info:{}", JSON.toJSONString(sortLists));
         // 去除跌幅榜或者涨幅榜。
-        log.info("tag :{}",tag);
-        if (ifIncDec.equals(true)){
-            log.info("涨跌幅:{}",JSON.toJSONString(sortLists));
+        log.info("tag :{}", tag);
+        if (ifIncDec.equals(true)) {
+            log.info("涨跌幅:{}", JSON.toJSONString(sortLists));
             return sortLists;
         }
-        if (tag.equals(true)){
+        if (tag.equals(true)) {
             // 涨幅:
             sortLists.removeIf(s -> s.getIndustryTag().equals(false));
-            log.info("涨幅:{}",JSON.toJSONString(sortLists));
+            log.info("涨幅:{}", JSON.toJSONString(sortLists));
             return sortLists;
-        }else{
+        } else {
             // 跌幅。
             // List<IncInfo> finalIncInfos = sortLists.stream().filter(s->s.getIndustryTag() && s.getIndustryTag() == true)
             //         .collect(Collectors.toList());
             // return finalIncInfos;
             sortLists.removeIf(s -> s.getIndustryTag().equals(true));
-            log.info("跌幅:{}",JSON.toJSONString(sortLists));
+            log.info("跌幅:{}", JSON.toJSONString(sortLists));
             return sortLists;
         }
     }
 
+    /**
+     * 根据行业id或者行业名称进行搜索.
+     * @param searchInfo
+     * @param friday
+     * @param lastFriday
+     * @return
+     */
+    public List<IndustryPlate> searchIndustryPlate(SearchInfo searchInfo,String friday,String lastFriday){
+        List<IndustryPlate> plates = new ArrayList<>();
+        // 涨跌均存在。根据行业id查询进来的。
+        QueryWrapper<IndustryPlate> queryWrapper = new QueryWrapper();
+        System.err.println(searchInfo.getSearchParam());
+        if (DateUtils.checkDate(friday,lastFriday).equals(true)){
+            queryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId, searchInfo.getSearchParam())
+                    .orderByDesc(IndustryPlate::getPlateDate)
+                    .groupBy(IndustryPlate::getPlateId)
+                    .between(IndustryPlate::getPlateDate, lastFriday, friday)
+                    .or()
+                    .like(IndustryPlate::getPlateName, searchInfo.getSearchParam());
+        }else {
+            queryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId, searchInfo.getSearchParam())
+                    .orderByDesc(IndustryPlate::getPlateDate)
+                    .groupBy(IndustryPlate::getPlateId)
+                    .between(IndustryPlate::getPlateDate, friday, lastFriday)
+                    .or()
+                    .like(IndustryPlate::getPlateName, searchInfo.getSearchParam());
+        }
+        plates = industryPlateMapper.selectList(queryWrapper);
+        log.info("search plates:{}",JSON.toJSONString(plates));
+        return plates;
+    }
+
     /**
      * 查询,上周实际,上周预测,下周预测。
+     *
      * @param just
      * @param plateId
-     * @param monday
-     * @param sunday
+     * @param friday
+     * @param lastFriday
      * @return
      */
-    public List<IndustryPlate> findIndustryPlate(Boolean just,String plateId,String monday,String sunday){
+    public List<IndustryPlate> findIndustryPlate(Boolean just, String plateId, String friday, String lastFriday) {
         QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
-        industryPlateQueryWrapper.between("plate_date",monday,sunday);
-        industryPlateQueryWrapper.eq("plate_id",plateId);
-        if (just.equals(false)){
-            industryPlateQueryWrapper.between("plate_date",monday,sunday);
+        if (DateUtils.checkDate(friday,lastFriday).equals(true)){
+            industryPlateQueryWrapper.between("plate_date", lastFriday, friday);
+        }else {
+            industryPlateQueryWrapper.between("plate_date", friday, lastFriday);
+        }
+        industryPlateQueryWrapper.groupBy("plate_id");
+        industryPlateQueryWrapper.isNotNull("plate_id");
+        if (just.equals(false)) {
+            if (DateUtils.checkDate(friday,lastFriday).equals(true)){
+                industryPlateQueryWrapper.between("plate_date", lastFriday, friday);
+            }else {
+                industryPlateQueryWrapper.between("plate_date", friday, lastFriday);
+            }
         }
         List<IndustryPlate> plates = industryPlateMapper.selectList(industryPlateQueryWrapper);
         return plates;
@@ -400,83 +473,94 @@ public class SearchServiceImpl implements SearchService {
 
     /**
      * 上周实际榜。
+     *
      * @param plateId
      * @return
      */
-    public Float calLastWeekActual(String plateId){
-        Map<String,Object> map = TestCommon.calWeek("",true);
+    public Float calLastWeekActual(String date,String plateId) {
+        Map<String, Object> map = DateUtils.getFridayOrLastFriday(date);
         // b本周实际拿的是预测的数据,pred。
         // 上周实际榜:上周周五的close-上上周周五的close
         String friday = map.get("friday").toString();
-        List<IndustryPlate> industryPlates = getClose(plateId,friday);
+        List<IndustryPlate> industryPlates = getClose(plateId, friday);
         String lastFriday = map.get("lastFriday").toString();
-        log.info("calLastWeekActual 上周五:{}",friday);
-        log.info("calLastWeekActual 上上周五:{}",lastFriday);
-        List<IndustryPlate> industryPlatesLast = getClose(plateId,lastFriday);
-        if (industryPlates.size() > 0 && industryPlatesLast.size() > 0){
-            Float close = industryPlates.get(0).getPlateClose();
-            Float lastClose = industryPlatesLast.get(0).getPlateClose();
-            Float value = close - lastClose;
-            return value;
-        }
-        return 0.0F;
+        List<IndustryPlate> industryPlatesLast = getClose(plateId, lastFriday);
+        return getCloseValue(industryPlates,industryPlatesLast);
     }
 
     /**
      * 上周预测榜。
-     *    上周预测:上周五的pred-上上周无的pred
+     * 上周预测:上周五的pred-上上周无的pred
+     *
      * @param plateId
      * @return
      */
-    public Float calLastWeekPred(String plateId){
-        Map<String,Object> map = TestCommon.calWeek("",true);
+    public Float calLastWeekPred(String date,String plateId) {
+        Map<String, Object> map = DateUtils.getFridayOrLastFriday(date);
         String friday = map.get("friday").toString();
         String lastFriday = map.get("lastFriday").toString();
-        log.info("calLastWeekPred 上周五:{}",friday);
-        log.info("calLastWeekPred 上上周五:{}",lastFriday);
-        List<IndustryPlate> industryPlates = getClose(plateId,friday);
-        List<IndustryPlate> industryPlatesLast = getClose(plateId,lastFriday);
-        Float pred = industryPlates.get(0).getPlateClosePred();
-        Float lastPred = industryPlatesLast.get(0).getPlateClosePred();
-        Float value = pred - lastPred;
-        return value;
+        List<IndustryPlate> industryPlatesLast = getClose(plateId, lastFriday);
+        List<IndustryPlate> industryPlates = getClose(plateId, friday);
+        return getPredValue(industryPlates,industryPlatesLast);
     }
 
     /**
      * 下周预测榜
-     *    下周预测:这周周五的pred-上周周五的pred。
+     * 下周预测:这周周五的pred-上周周五的pred。
+     *  计算方式:下周预测-本周预测啊
      * @param plateId
      * @return
      */
-    public Float calNextWeekPred(String plateId){
-        Map<String,Object> map = TestCommon.calWeek("",true);
-        String friday = TestCommon.currWeekFriday();
-        String lastFriday = map.get("friday").toString();
-        log.info("calNextWeekPred 本周五:{}",friday);
-        log.info("calNextWeekPred 上周五:{}",lastFriday);
-        List<IndustryPlate> industryPlates = getClose(plateId,friday);
-        List<IndustryPlate> industryPlatesLast = getClose(plateId,lastFriday);
-        Float pred = industryPlates.get(0).getPlateClosePred();
-        Float lastPred = industryPlatesLast.get(0).getPlateClosePred();
+    public Float calNextWeekPred(String date,String plateId) {
+        Map<String, Object> map = DateUtils.getEverydayOfNexWeek(date);
+        String nextFriday = map.get("nextFriday").toString();
+        String friday = map.get("friday").toString();
+        List<IndustryPlate> industryPlatesNext = getClose(plateId, nextFriday);
+        List<IndustryPlate> industryPlates = getClose(plateId, friday);
+        return getPredValue(industryPlatesNext,industryPlates);
+    }
+
+    public Float getCloseValue(List<IndustryPlate> industryPlates,List<IndustryPlate> industryPlatesLast){
+        Float close = industryPlates.size() > 0 ? industryPlates.get(0).getPlateClose() : 0.0F;
+        Float lastClose = industryPlatesLast.size() > 0 ? industryPlatesLast.get(0).getPlateClose() : 1.0F;
+        Float value = close - lastClose;
+        return value;
+    }
+
+    public Float getPredValue(List<IndustryPlate> industryPlates,List<IndustryPlate> industryPlatesLast){
+        Float pred = industryPlates.size() > 0 ? industryPlates.get(0).getPlateClosePred() : 0.0F;
+        Float lastPred = industryPlatesLast.size() > 0 ? industryPlatesLast.get(0).getPlateClosePred() : 1.0F;
         Float value = pred - lastPred;
         return value;
     }
 
     /**
      * 获取N周五的收盘价。
+     *
      * @param plateId
      * @param friday
      * @return
      */
-    public List<IndustryPlate> getClose(String plateId,String friday){
-        log.info("sel industryplate:{}",plateId +"," + friday);
+    public List<IndustryPlate> getClose(String plateId, String friday) {
+        log.info("getClose() industryplate:{}", plateId + "," + friday);
         QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
         industryPlateQueryWrapper.lambda()
-                .eq(IndustryPlate::getPlateId,plateId)
-                .eq(IndustryPlate::getPlateDate,friday);
+                .eq(IndustryPlate::getPlateId, plateId)
+                .eq(IndustryPlate::getPlateDate, friday);
         List<IndustryPlate> industryPlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
-        log.info("plates:{}",JSON.toJSONString(industryPlates));
+        log.info("plates:{}", JSON.toJSONString(industryPlates));
         return industryPlates;
     }
 
+    /**
+     * 获取数据库中最新的日期。
+     *
+     * @return
+     */
+    public List<IndustryPlate> getNewest() {
+        QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+        industryPlateQueryWrapper.lambda()
+                .orderByDesc(IndustryPlate::getPlateDate);
+        return industryPlateMapper.selectList(industryPlateQueryWrapper);
+    }
 }

+ 5 - 2
src/main/resources/application-dev.yml

@@ -1,9 +1,12 @@
 spring:
   datasource:
-    url: jdbc:mysql://192.168.1.73/fda_test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
+#    url: jdbc:mysql://192.168.1.73/fda_test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
+    url: jdbc:mysql://192.168.1.73/fda-test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
+#    url: jdbc:mysql://192.168.1.60/fda?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
     driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
     password: root
+#    password: fdaprivacy
 #  rabbitmq:
 #    host: 192.168.1.73
 #    port: 5672
@@ -26,7 +29,7 @@ logging:
   level:
     org.springframework.cloud: debug
     org.springframework.boot: debug
-    com.pavis.ai.app.cr.mapper: trace
+    com.pavis.ai.app.cr.mapper: debug
 #security:
 #  oauth2:
 #    client:

+ 336 - 0
src/test/java/com/pavis/ai/app/fda/LocalDateTest.java

@@ -0,0 +1,336 @@
+package com.pavis.ai.app.fda;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.pavis.ai.app.fda.common.utils.DateUtils;
+import com.pavis.ai.app.fda.form.TestCommon;
+import com.pavis.ai.app.fda.form.inc.IncInfo;
+import com.pavis.ai.app.fda.mapper.IndustryPlateMapper;
+import com.pavis.ai.app.fda.model.IndustryInfo;
+import com.pavis.ai.app.fda.model.IndustryPlate;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAdjusters;
+import java.time.temporal.WeekFields;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-18 12:17
+ * @desc
+ **/
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@Slf4j
+public class LocalDateTest {
+
+    @Autowired
+    private IndustryPlateMapper industryPlateMapper;
+
+    @Test
+    public void tes(){
+        DateUtils.getEverydayOfNexWeek("2020-07-03");
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse(date, pattern);
+        // localDate.with(TemporalAdjusters.next(DayOfWeek.of(2)));
+        DateUtils.getEverydayOfNexWeek("2020-06-29");
+        DateUtils.getEverydayOfNexWeek("2020-07-05");
+        DateUtils.getEverydayOfNexWeek("2020-06-22");
+    }
+
+    @Test
+    public void next(){
+
+        DateUtils.getEverydayOfNexWeek("2020-07-03");
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse(date, pattern);
+        // localDate.with(TemporalAdjusters.next(DayOfWeek.of(2)));
+        DateUtils.getEverydayOfNexWeek("2020-06-29");
+        DateUtils.getEverydayOfNexWeek("2020-07-05");
+        DateUtils.getEverydayOfNexWeek("2020-06-22");
+    }
+
+    @Test
+    public void testNext(){
+        Map<String,Object> map = new HashMap<>();
+        String date = "2020-07-04";
+        String week = DateUtils.getWeekNameByDate(date);
+        if (week.equals("6") || week.equals("7")){
+            // 本周:
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+            System.err.println("if:"+JSON.toJSONString(map));
+        }else {
+            // 上周:
+            Map<String,Object> lastMap = DateUtils.getFridayOrLastFriday(date);
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(lastMap.get("friday").toString(), pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+
+            System.err.println("else:"+JSON.toJSONString(map));
+        }
+    }
+
+    @Test
+    public void test(){
+        Map<String,Object> map = new HashMap<>();
+        String date = "2020-07-04";
+        TestCommon.getEveryday("2020-07-03",false);
+        TestCommon.getEveryday("2020-07-03",true);
+        String week = DateUtils.getWeekNameByDate(date);
+        if (week.equals("6") || week.equals("7")){
+            // 本周:
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+            System.err.println("if:"+JSON.toJSONString(map));
+        }else {
+            // 上周:
+            Map<String,Object> lastMap = DateUtils.getFridayOrLastFriday(date);
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(lastMap.get("friday").toString(), pattern);
+            LocalDate sunday = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+            LocalDate monday = localDate.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+            long distance = ChronoUnit.DAYS.between(monday, sunday);
+            if (distance < 1) {
+                // return map;
+            }
+            Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+
+            System.err.println("else:"+JSON.toJSONString(map));
+        }
+    }
+
+    @Test
+    public void test2(){
+        System.err.println(getFridayOrLastFriday("",true));
+        System.err.println(getFridayOrLastFriday("2020-07-06",true));
+        System.err.println(getFridayOrLastFriday("2020-07-17",true));
+        System.err.println(getFridayOrLastFriday("2020-07-14",true));
+        System.err.println();
+        System.err.println();
+        System.err.println();
+        System.err.println(getFridayOrLastFriday("",false));
+        System.err.println(getFridayOrLastFriday("2020-07-06",false));
+        System.err.println(getFridayOrLastFriday("2020-07-17",false));
+        System.err.println(getFridayOrLastFriday("2020-07-14",false));
+
+        String friday = "2020-07-03";
+        String lastFriday = "2020-06-26";
+        QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+        if (DateUtils.checkDate(friday,lastFriday).equals(true)){
+            industryPlateQueryWrapper.between("plate_date", lastFriday, friday);
+        }else {
+            industryPlateQueryWrapper.between("plate_date", friday, lastFriday);
+        }
+        industryPlateQueryWrapper.groupBy("plate_id");
+        industryPlateQueryWrapper.isNotNull("plate_id");
+        List<IndustryPlate> plates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+        System.err.println(plates.size());
+
+    }
+
+    public static Map<String,Object> getFridayOrLastFriday(String date,Boolean lastOrNext){
+        Map<String,Object> map = new HashMap<>();
+        String week = DateUtils.getWeekNameByDate(date);
+        if (week.equals("6") || week.equals("7")){
+            // 本周周五和上周五
+            String currFriday = DateUtils.getFridayOfThisWeek(date);
+            map.put("friday",currFriday);
+            // 上上周五
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(currFriday, pattern);
+            LocalDate todayOfLastWeek = lastOrNext.equals(true) ? localDate.minusDays(7) : localDate.plusDays(7);
+            LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+            map.put("lastFriday",fridayLocal.toString());
+            log.info("friday map:{}", JSON.toJSONString(map));
+            return map;
+        }else {
+            // 上周五和上上周五
+            // 指定日期的周。
+            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate localDate = LocalDate.parse(date, pattern);
+            LocalDate todayOfLastWeek = lastOrNext.equals(true) ? localDate.minusDays(7) : localDate.plusDays(7);
+            LocalDate fridayLocal = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)).minusDays(1);
+            LocalDate lastFridayLocal = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SATURDAY)).minusDays(1);
+            map.put("friday",fridayLocal.toString());
+            map.put("lastFriday",lastFridayLocal.toString());
+            log.info("friday map:{}", JSON.toJSONString(map));
+            return map;
+        }
+    }
+
+    @Test
+    public void test1(){
+        // 获取今天的实际日期。
+        // getActualCurrDate();
+        // 获取本周周五的日期。
+        // getFridayOfThisWeek();
+
+        // getDayOfNextWeek();
+
+        // getEveryday("2020-07-18",true);
+        // TestCommon.calWeek("2020-07-06",false);
+        //
+        // String date = "2020-07-06";
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse(date, pattern);
+        // System.err.println(DateUtils.getFridayOfThisWeek(date));
+        // System.err.println(DateUtils.getFridayOfThisWeek(""));
+
+        // System.err.println(DateUtils.getFridayOrLastFriday(""));
+        // System.err.println(DateUtils.getFridayOrLastFriday("2020-07-06"));
+        // System.err.println(DateUtils.getFridayOrLastFriday("2020-07-17"));
+        // System.err.println(DateUtils.getFridayOrLastFriday("2020-07-14"));
+
+        System.err.println(DateUtils.checkDate("2020-06-26","2020-07-03"));
+        System.err.println(DateUtils.checkDate("2020-07-03","2020-06-26"));
+        List<IncInfo> incInfos = new ArrayList<>();
+        incInfos.add(IncInfo.builder().industryValue(1F).build());
+        incInfos.add(IncInfo.builder().industryValue(7F).build());
+        incInfos.add(IncInfo.builder().industryValue(66F).build());
+        incInfos.add(IncInfo.builder().industryValue(15F).build());
+        //年龄升序
+        List<IncInfo> sortLists = incInfos.stream()
+                .sorted(Comparator.comparing(IncInfo::getIndustryValue))
+                .collect(Collectors.toList());
+        System.err.println("升序:"+ JSON.toJSONString(sortLists));
+        //年龄降序
+        // List<IncInfo> sortLists = incInfos.stream()
+        //         .sorted(Comparator.comparing(IncInfo::getIndustryValue).reversed())
+        //         .collect(Collectors.toList());
+        List<IncInfo> sortListss = incInfos.stream()
+                .sorted(Comparator.comparing(IncInfo::getIndustryValue).reversed())
+                .collect(Collectors.toList());
+        System.err.println("降序序:"+ JSON.toJSONString(sortListss));
+    }
+
+    /**
+     * 获取一周内或者下周的每一天的日期。
+     * @param date
+     * @return
+     */
+    public static Map<String,Object> getEveryday(String date, Boolean nextFlag){
+        Map<String,Object> map = new HashMap<>();
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.parse(date, pattern);
+        // 求这个日期上一周的周一、周日
+        LocalDate todayOfLastWeek = localDate.minusDays(7);
+        if (nextFlag.equals(true)){
+            todayOfLastWeek = todayOfLastWeek.plusDays(7);
+        }
+        LocalDate sunday = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
+        LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+        long distance = ChronoUnit.DAYS.between(monday, sunday);
+        if (distance < 1) {
+            return map;
+        }
+        Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+        log.info("getEveryday获取一周内每天的日期:{}", JSON.toJSONString(map));
+        return map;
+    }
+
+
+    /**
+     * 获取下一周的任意一天,默认周一。
+     * @return String
+     */
+    public static String getDayOfNextWeek(){
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse("2020-07-18", pattern);
+        LocalDate localDate = currDate().with(DayOfWeek.FRIDAY);
+        LocalDate todayOfLastWeek = localDate.plusDays(7);
+        LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
+        String next = monday.toString();
+        log.info("getNextWeek获取下一周的日期:{}",monday);
+        return next;
+    }
+
+
+    public static LocalDate currDate(){
+        return LocalDate.now();
+    }
+    /**
+     * 获取本周的周五日期。
+     * @return
+     */
+    public static String getFridayOfThisWeek(){
+        LocalDate toweekFriday = currDate().with(DayOfWeek.FRIDAY);
+        String currFriday = toweekFriday.toString();
+        log.info("getFridayOfThisWeek获取本周的周五日期:{}",currFriday);
+        return currFriday;
+    }
+
+    /**
+     * 获取今天的实际日期。
+     * @return
+     */
+    public static String getActualCurrDate(){
+        LocalDateTime now = LocalDateTime.now();
+        String currWeek = now.toLocalDate().toString();
+        log.info("getActualCurrDate获取今天实际日期:{}",currWeek);
+        return currWeek;
+    }
+
+
+    // List<IndustryInfo> industryInfos = new ArrayList<>();
+    // // 根据行业id搜索。
+    //     if (ifIncDec.equals(true)) {
+    //     QueryWrapper<IndustryInfo> queryWrapper = new QueryWrapper();
+    //     queryWrapper.lambda()
+    //             .eq(IndustryInfo::getPlateId, searchInfo.getSearchParam())
+    //             .orderByDesc(IndustryInfo::getOperateTime)
+    //             .or()
+    //             .like(IndustryInfo::getPlateName, searchInfo.getSearchParam())
+    //             .or()
+    //             .eq(IndustryInfo::getStockId, searchInfo.getSearchParam())
+    //             .or()
+    //             .like(IndustryInfo::getStockName, searchInfo.getSearchParam());
+    //     industryInfos = industryInfoMapper.selectList(queryWrapper);
+    //     // 转换为industryPlate
+    //     // List<IndustryPlate> industryPlates = new ArrayList<>();
+    //     // IndustryPlate industryPlate;
+    //     // for (IndustryInfo industryInfo : industryInfos) {
+    //     //     industryPlate = IndustryPlate.builder()
+    //     //             .plateId(in)
+    //     //             .build();
+    //     // }
+    // } else {
+    //     QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
+    //     // 涨幅跌幅。上周周五的close-上上上周五的close >0涨 <0跌
+    //     // industryInfoQueryWrapper.eq("tag",tag);
+    //     industryInfoQueryWrapper.isNotNull("id");
+    //     industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+    // }
+}