فهرست منبع

1、接口基本开发完毕,其他细节,待和数据库接入后修复。

jessie 5 سال پیش
والد
کامیت
85ceb544be

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

@@ -39,7 +39,7 @@ public class BaseController {
         // id 等同于plateCodeId
         // 返回 HisInfo
         // todo 告诉我是上周预测 上周实际 本周预测,再去查询。返回行业信息啥的。
-        return ResultBody.ok().data(hisService.hisFind(ids));
+        return ResultBody.ok().data(searchService.hisFind(ids));
     }
 
     @ApiOperation("下周预测(未来7天预测)接口")

+ 1 - 1
src/main/java/com/pavis/ai/app/fda/controller/NewsController.java

@@ -72,6 +72,6 @@ public class NewsController {
     public ResultBody searchHot(){
         // 返回List<HotSearch>
         // 展示搜索次数最多的行业id或者行业名称。
-        return ResultBody.ok().data(searchService.searchHot());
+        return ResultBody.ok().data(newsService.searchHot());
     }
 }

+ 54 - 14
src/main/java/com/pavis/ai/app/fda/form/TestCommon.java

@@ -1,5 +1,6 @@
 package com.pavis.ai.app.fda.form;
 
+import com.alibaba.fastjson.JSON;
 import com.pavis.ai.app.fda.form.his.IndustryDetail;
 import com.pavis.ai.app.fda.form.his.IndustryDetailsInfo;
 import com.pavis.ai.app.fda.form.inc.IncInfo;
@@ -8,23 +9,24 @@ import com.pavis.ai.app.fda.form.news.NewsList;
 import com.pavis.ai.app.fda.form.search.HotSearch;
 import com.pavis.ai.app.fda.model.NewsInfo;
 import lombok.*;
+import lombok.extern.slf4j.Slf4j;
 
 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.util.*;
+import java.util.stream.Stream;
 
 /**
  * @author guanhuijuan
  * @create 2020-07-16 16:23
  * @desc
  **/
-@Getter
-@Setter
-@NoArgsConstructor
-@Builder
+
+@Slf4j
 public class TestCommon {
 
     public static Float toInitFloat(){
@@ -40,7 +42,9 @@ public class TestCommon {
      */
     public static String getWeek(){
         LocalDateTime now = LocalDateTime.now();
-        return now.toLocalDate().toString();
+        String currWeek = now.toLocalDate().toString();
+        log.info("currWeekFriday获取本周的实际日期:{}",currWeek);
+        return currWeek;
     }
 
     /**
@@ -50,7 +54,9 @@ public class TestCommon {
     public static String currWeekFriday(){
         LocalDate today = LocalDate.now();
         LocalDate toweekFriday = today.with(DayOfWeek.FRIDAY);
-        return toweekFriday.toString();
+        String currFriday = toweekFriday.toString();
+        log.info("currWeekFriday获取本周的周五的日期:{}",currFriday);
+        return currFriday;
     }
 
     /**
@@ -58,10 +64,42 @@ public class TestCommon {
      * @return
      */
     public static String getNextWeek(){
-        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-        LocalDate localDate = LocalDate.parse(LocalDateTime.now().toString(), pattern);
+        // DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        // LocalDate localDate = LocalDate.parse(LocalDateTime.now().with(DayOfWeek.FRIDAY).toString(), pattern);
+        LocalDate today = LocalDate.now();
+        LocalDate localDate = today.with(DayOfWeek.FRIDAY);
         LocalDate todayOfLastWeek = localDate.plusDays(7);
-        return todayOfLastWeek.toString();
+        String next = todayOfLastWeek.toString();
+        log.info("getNextWeek获取下一周的日期:{}",next);
+        return next;
+    }
+
+
+
+
+    /**
+     * 获取一周内或者下周的每一天的日期。
+     * @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;
     }
 
     /**
@@ -70,6 +108,7 @@ 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();
@@ -78,10 +117,8 @@ public class TestCommon {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LocalDate localDate = LocalDate.parse(date, pattern);
         // LocalDate now = LocalDate.now().plusDays(10);
-        System.out.println("当前日期: " + localDate + " " + localDate.getDayOfWeek());
         // 求这个日期上一周的周一、周日
-        // 求这个日期上一周的周一、周日
-        LocalDate todayOfLastWeek = localDate.minusDays(7);
+        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);
@@ -91,13 +128,16 @@ public class TestCommon {
         String sunday = sundayLocal.toString();
         String friday = fridayLocal.toString();
         String lastFriday = lastFridayLocal.toString();
-        System.out.println("当前日期:" + localDate + " 上一周的周一:" + mondayLocal + " " + mondayLocal.getDayOfWeek());
-        System.out.println("当前日期:" + localDate + " 上一周的周日:" + sundayLocal + " " + sundayLocal.getDayOfWeek());
         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);
         return map;
     }
 

+ 5 - 0
src/main/java/com/pavis/ai/app/fda/form/search/HotSearch.java

@@ -23,6 +23,11 @@ public class HotSearch {
      * 行业名称
      */
     private String plateName;
+
+    /**
+     * 搜索次数
+     */
+    private Integer searchNum;
     // /**
     //  * 相当于板块代码。
     //  */

+ 16 - 0
src/main/java/com/pavis/ai/app/fda/service/NewsService.java

@@ -2,6 +2,7 @@ package com.pavis.ai.app.fda.service;
 
 import com.pavis.ai.app.fda.form.news.NewsDetailInfo;
 import com.pavis.ai.app.fda.form.news.NewsList;
+import com.pavis.ai.app.fda.form.search.HotSearch;
 import com.pavis.ai.app.fda.form.search.SearchInfo;
 import com.pavis.ai.app.fda.model.NewsInfo;
 
@@ -33,4 +34,19 @@ public interface NewsService {
      * @return
      */
     List<NewsInfo> createNews(NewsList newsList);
+
+    /**
+     * 搜索热点top10
+     *
+     * @return
+     */
+    List<HotSearch> searchHot();
+
+    /**
+     * 搜索统计。
+     * @param plateId
+     * @param plateName
+     */
+    void searchCount(String plateId, String plateName);
+
 }

+ 12 - 4
src/main/java/com/pavis/ai/app/fda/service/SearchService.java

@@ -16,21 +16,23 @@ public interface SearchService {
 
     /**
      * 根据板块、股票搜索
+     *
      * @param searchInfo
      * @return
      */
-   List<IncInfo> search(SearchInfo searchInfo);
+    List<IncInfo> search(SearchInfo searchInfo);
 
-   void searchCount(String plateId,String plateName);
 
     /**
-     * 搜索热点top10
+     * 根据行业id查询进入详情接口
+     * @param ids
      * @return
      */
-   List<HotSearch> searchHot();
+    IndustryDetailsInfo hisFind(List<String> ids);
 
     /**
      * 未来7天预测数据查询接口
+     *
      * @param ids
      * @return
      */
@@ -38,36 +40,42 @@ public interface SearchService {
 
     /**
      * 涨幅表-上周历史数据
+     *
      * @return
      */
     List<IncInfo> incLastWeek();
 
     /**
      * 涨幅表-预测下周
+     *
      * @return
      */
     List<IncInfo> incNextWeekPred();
 
     /**
      * 涨幅表-预测上周
+     *
      * @return
      */
     List<IncInfo> incLastWeekPred();
 
     /**
      * 涨幅表-上周历史数据
+     *
      * @return
      */
     List<IncInfo> decLastWeek();
 
     /**
      * 涨幅表-预测下周
+     *
      * @return
      */
     List<IncInfo> decNextWeekPred();
 
     /**
      * 涨幅表-预测上周
+     *
      * @return
      */
     List<IncInfo> decLastWeekPred();

+ 88 - 0
src/main/java/com/pavis/ai/app/fda/service/impl/NewsServiceImpl.java

@@ -7,9 +7,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.pavis.ai.app.fda.common.utils.DateUtils;
 import com.pavis.ai.app.fda.form.news.NewsDetailInfo;
 import com.pavis.ai.app.fda.form.news.NewsList;
+import com.pavis.ai.app.fda.form.search.HotSearch;
 import com.pavis.ai.app.fda.form.search.SearchInfo;
 import com.pavis.ai.app.fda.mapper.NewsInfoMapper;
+import com.pavis.ai.app.fda.mapper.SearchCountMapper;
 import com.pavis.ai.app.fda.model.NewsInfo;
+import com.pavis.ai.app.fda.model.SearchCount;
 import com.pavis.ai.app.fda.service.NewsService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -32,6 +35,10 @@ public class NewsServiceImpl implements NewsService {
     @Autowired
     private NewsInfoMapper newsInfoMapper;
 
+    @Autowired
+    private SearchCountMapper searchCountMapper;
+
+
     @Override
     public List<NewsList> newsList() {
         QueryWrapper<NewsInfo> newsInfoQueryWrapper = new QueryWrapper<>();
@@ -59,6 +66,7 @@ public class NewsServiceImpl implements NewsService {
         // 注意是哪个id
         QueryWrapper queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("news_id", searchInfo.getSearchParam());
+        queryWrapper.orderByDesc("news_date");
         List<NewsInfo> newsInfos = newsInfoMapper.selectList(queryWrapper);
 
         List<NewsList> newsLists = new ArrayList<>();
@@ -89,12 +97,92 @@ public class NewsServiceImpl implements NewsService {
         return newsInfos;
     }
 
+    @Override
+    public List<HotSearch> searchHot() {
+        QueryWrapper<SearchCount> searchCountQueryWrapper = new QueryWrapper<>();
+        searchCountQueryWrapper.orderByDesc("search_num");
+        searchCountQueryWrapper.isNotNull("id");
+        List<SearchCount> searchCounts = searchCountMapper.selectList(searchCountQueryWrapper);
+        HotSearch hotSearch;
+        List<HotSearch> hotSearches = new ArrayList<>();
+        for (SearchCount searchCount : searchCounts) {
+            hotSearch = new HotSearch();
+            BeanUtils.copyProperties(searchCount, hotSearch);
+            hotSearch.setSearchNum(Integer.valueOf(searchCount.getSearchNum()));
+            hotSearches.add(hotSearch);
+        }
+        List<HotSearch> newsSortList = hotSearches.stream()
+                .sorted(Comparator.comparing(HotSearch::getSearchNum).reversed())
+                .collect(Collectors.toList());
+        return newsSortList;
+
+        // List<HotSearch> hotSearches = new ArrayList<>();
+        // // 07-23 日期加七天。
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0422","交运物流",TestCommon.toInitFloat(),true));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0738","多元金融",Float.valueOf("0.0"),false));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK450","港口水运",Float.valueOf("0.0"),false));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0734","珠宝首饰",TestCommon.toInitFloat(),true));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0471","化纤行业",TestCommon.toInitFloat(),true));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0485","旅游酒店",TestCommon.toInitFloat(),true));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0475","银行",TestCommon.toInitFloat(),false));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0473","券商信托",TestCommon.toInitFloat(),false));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0474","保险",Float.valueOf("0.0"),true));
+        // hotSearches.add(TestCommon.toInitHotSearch("BK0478","有色金属",Float.valueOf("0.0"),true));
+        // return hotSearches;
+    }
+
+    @Override
+    public void searchCount(String plateId, String plateName) {
+        QueryWrapper<SearchCount> searchCountQueryWrapper = new QueryWrapper<>();
+        searchCountQueryWrapper.lambda()
+                .eq(SearchCount::getPlateId,plateId);
+        List<SearchCount> searchCounts = searchCountMapper.selectList(searchCountQueryWrapper);
+        if (searchCounts.size() > 0){
+            // 已存在,直接+1;
+            for (SearchCount searchCount : searchCounts) {
+                String num = String.valueOf(Integer.valueOf(searchCount.getSearchNum()) + 1);
+                searchCount.setSearchNum(num);
+                searchCountMapper.updateById(searchCount);
+            }
+        }else {
+            // 新数据新增。
+            SearchCount searchCount;
+            searchCount = new SearchCount();
+            searchCount.setPlateId(plateId);
+            searchCount.setPlateName(plateName);
+            searchCount.setSearchNum("1");
+            searchCountMapper.insert(searchCount);
+        }
+
+    }
+
+
+
+
+    /**
+     * 解析图片url。
+     * @param newsUrl
+     * @return
+     */
     public List<String> dealUrl(String newsUrl){
         String url = StringUtils.remove(StringUtils.remove(newsUrl,"["),"]");
         List<String> urls = new ArrayList<>(Arrays.asList(StringUtils.remove(url,"\"").split(",")));
         return urls;
     }
 
+    /**
+     * 初始化新闻信息。
+     * @param newsId
+     * @param newsToEnterpriseId
+     * @param newsUrl
+     * @param newsTitle
+     * @param newsFrom
+     * @param newsMiniContent
+     * @param newsContent
+     * @param newsDate
+     * @param newsTag
+     * @return
+     */
     public NewsInfo toInitNewsInfo(String newsId,String newsToEnterpriseId,String newsUrl,String newsTitle,String newsFrom,String newsMiniContent,
                                    String newsContent,String newsDate,String newsTag){
         NewsInfo newsInfo = NewsInfo.builder()

+ 225 - 145
src/main/java/com/pavis/ai/app/fda/service/impl/SearchServiceImpl.java

@@ -15,12 +15,10 @@ import com.pavis.ai.app.fda.mapper.IndustryStockMapper;
 import com.pavis.ai.app.fda.mapper.SearchCountMapper;
 import com.pavis.ai.app.fda.model.IndustryInfo;
 import com.pavis.ai.app.fda.model.IndustryPlate;
-import com.pavis.ai.app.fda.model.IndustryStock;
 import com.pavis.ai.app.fda.model.SearchCount;
 import com.pavis.ai.app.fda.service.NewsService;
 import com.pavis.ai.app.fda.service.SearchService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -47,124 +45,106 @@ public class SearchServiceImpl implements SearchService {
     @Autowired
     private IndustryStockMapper industryStockMapper;
 
-    @Autowired
-    private SearchCountMapper searchCountMapper;
 
-    @private NewsService newsService;
+    @Autowired
+    private NewsService newsService;
 
     @Override
     public List<IncInfo> search(SearchInfo searchInfo) {
-        QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper();
-        industryInfoQueryWrapper.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());
-        List<IndustryInfo> industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
-        System.err.println(JSON.toJSONString(industryInfos));
-        List<IncInfo> incInfos = new ArrayList<>();
-
-        for (IndustryInfo industryInfo : industryInfos) {
-            // 记录搜索次数
-            searchCount(industryInfo.getPlateId(),industryInfo.getPlateName());
-            QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
-            industryPlateQueryWrapper.lambda()
-                    .eq(IndustryPlate::getPlateId,industryInfo.getPlateId());
-            List<IndustryPlate> industryPlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
-            IncInfo incInfo;
-            for (IndustryPlate industryPlate : industryPlates) {
-                incInfo = IncInfo.builder()
-                        .industryId(industryPlate.getPlateId())
-                        .industryName(industryInfo.getPlateName())
-                        .industryValue(TestCommon.toInitFloat())
-                        // todo 后期需要改。
-                        .industryTag(industryPlate.getPlateDate().equals("2010-01-10") ? true : false)
-                        .build();
-                incInfos.add(incInfo);
-            }
-            QueryWrapper<IndustryStock> industryStockQueryWrapper = new QueryWrapper<>();
-            industryStockQueryWrapper.lambda()
-                    .eq(IndustryStock::getStockId,industryInfo.getPlateId());
-            List<IndustryStock> industryStocks = industryStockMapper.selectList(industryStockQueryWrapper);
-            // IncInfo incInfo;
-            for (IndustryStock industryStock : industryStocks) {
-                incInfo = IncInfo.builder()
-                        .industryId(industryStock.getStockId())
-                        .industryName(industryInfo.getStockName())
-                        .industryValue(TestCommon.toInitFloat())
-                        .industryTag(true)
-                        .build();
-                incInfos.add(incInfo);
-            }
-        }
-        return incInfos;
+        return toIncInfos(true,false,false,true,searchInfo);
+        // QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper();
+        // industryInfoQueryWrapper.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());
+        // List<IndustryInfo> industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+        // System.err.println(JSON.toJSONString(industryInfos));
+        // List<IncInfo> incInfos = new ArrayList<>();
+        //
+        // for (IndustryInfo industryInfo : industryInfos) {
+        //     // 记录搜索次数
+        //     searchCount(industryInfo.getPlateId(),industryInfo.getPlateName());
+        //     // 根据行业id进行查询。
+        //     QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+        //     industryPlateQueryWrapper.lambda()
+        //             .eq(IndustryPlate::getPlateId,industryInfo.getPlateId());
+        //     List<IndustryPlate> industryPlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+        //     IncInfo incInfo;
+        //     for (IndustryPlate industryPlate : industryPlates) {
+        //         incInfo = IncInfo.builder()
+        //                 .industryId(industryPlate.getPlateId())
+        //                 .industryName(industryInfo.getPlateName())
+        //                 .industryValue(TestCommon.toInitFloat())
+        //                 // todo 后期需要改。
+        //                 .industryTag(industryPlate.getPlateDate().equals("2010-01-10") ? true : false)
+        //                 .build();
+        //         incInfos.add(incInfo);
+        //     }
+        //     QueryWrapper<IndustryStock> industryStockQueryWrapper = new QueryWrapper<>();
+        //     industryStockQueryWrapper.lambda()
+        //             .eq(IndustryStock::getStockId,industryInfo.getPlateId());
+        //     List<IndustryStock> industryStocks = industryStockMapper.selectList(industryStockQueryWrapper);
+        //     // IncInfo incInfo;
+        //     for (IndustryStock industryStock : industryStocks) {
+        //         incInfo = IncInfo.builder()
+        //                 .industryId(industryStock.getStockId())
+        //                 .industryName(industryInfo.getStockName())
+        //                 .industryValue(TestCommon.toInitFloat())
+        //                 .industryTag(true)
+        //                 .build();
+        //         incInfos.add(incInfo);
+        //     }
+        // }
+        // return incInfos;
     }
 
-    @Override
-    public void searchCount(String plateId, String plateName) {
-        QueryWrapper<SearchCount> searchCountQueryWrapper = new QueryWrapper<>();
-        searchCountQueryWrapper.lambda()
-                .eq(SearchCount::getPlateId,plateId);
-        List<SearchCount> searchCounts = searchCountMapper.selectList(searchCountQueryWrapper);
-        if (searchCounts.size() > 0){
-            // 已存在,直接+1;
-            for (SearchCount searchCount : searchCounts) {
-                String num = String.valueOf(Integer.valueOf(searchCount.getSearchNum()) + 1);
-                searchCount.setSearchNum(num);
-                searchCountMapper.updateById(searchCount);
-            }
-        }else {
-            // 新数据新增。
-            SearchCount searchCount;
-            searchCount = new SearchCount();
-            searchCount.setPlateId(plateId);
-            searchCount.setPlateName(plateName);
-            searchCount.setSearchNum("1");
-            searchCountMapper.insert(searchCount);
-        }
-
-    }
 
     @Override
-    public List<HotSearch> searchHot() {
-        QueryWrapper<SearchCount> searchCountQueryWrapper = new QueryWrapper<>();
-        searchCountQueryWrapper.orderByDesc("search_num");
-        searchCountQueryWrapper.isNotNull("id");
-        List<SearchCount> searchCounts = searchCountMapper.selectList(searchCountQueryWrapper);
-        HotSearch hotSearch;
-        List<HotSearch> hotSearches = new ArrayList<>();
-        for (SearchCount searchCount : searchCounts) {
-            hotSearch = new HotSearch();
-            BeanUtils.copyProperties(searchCount, hotSearch);
-            hotSearches.add(hotSearch);
-        }
-        return hotSearches;
-
-        // List<HotSearch> hotSearches = new ArrayList<>();
-        // // 07-23 日期加七天。
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0422","交运物流",TestCommon.toInitFloat(),true));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0738","多元金融",Float.valueOf("0.0"),false));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK450","港口水运",Float.valueOf("0.0"),false));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0734","珠宝首饰",TestCommon.toInitFloat(),true));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0471","化纤行业",TestCommon.toInitFloat(),true));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0485","旅游酒店",TestCommon.toInitFloat(),true));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0475","银行",TestCommon.toInitFloat(),false));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0473","券商信托",TestCommon.toInitFloat(),false));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0474","保险",Float.valueOf("0.0"),true));
-        // hotSearches.add(TestCommon.toInitHotSearch("BK0478","有色金属",Float.valueOf("0.0"),true));
-        // return hotSearches;
+    public IndustryDetailsInfo hisFind(List<String> ids) {
+        return toDetailsByPlateId(ids,false);
     }
 
     @Override
     public IndustryDetailsInfo predictFind(List<String> ids) {
-        for (String id : ids) {
-            // 上周的每一天,下周的每一天。
-            // toIncInfos();
-        }
+        return toDetailsByPlateId(ids,true);
+
+        // List<IndustryDetail> industryDetails = new ArrayList<>();
+        //
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0422","2020-07-17",
+        //         null,TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0738","2020-06-22",
+        //         null,TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK450","2020-05-22",
+        //         null,TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0734","2020-04-22",
+        //         null,TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0471","2020-03-22",
+        //         null,TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0422","2020-07-10",
+        //         TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0738","2020-06-15",
+        //         TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK450","2020-05-15",
+        //         TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0734","2020-04-15",
+        //         TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // industryDetails.add(TestCommon.toInitIndustryDetail("BK0471","2020-03-15",
+        //         TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // SearchInfo searchInfo = SearchInfo.builder()
+        //         .searchParam(ids.get(0))
+        //         .build();
+        // List<NewsList> newsLists = newsService.newsDetails(searchInfo);
+        // IndustryDetailsInfo industryInfo = IndustryDetailsInfo.builder()
+        //         .actuals(industryDetails)
+        //         .news(newsLists)
+        //         .tag(true)
+        //         .build();
+
         // List<IndustryInfo> hisInfos = new ArrayList<>();
         // // 07-23 日期加七天。
         // hisInfos.add(TestCommon.toInitIndustryDetail("8370003","2020-07-17",Float.valueOf(""),43.27F));
@@ -175,32 +155,61 @@ public class SearchServiceImpl implements SearchService {
         // hisInfos.add(TestCommon.toInitIndustryDetail("8370008","2020-07-22",Float.valueOf(""),45.27F));
         // hisInfos.add(TestCommon.toInitIndustryDetail("8370009","2020-07-23",Float.valueOf(""),46.27F));
         // return hisInfos;
+        // return industryInfo;
+    }
+
+    /**
+     * 根据行业id获取详情或者未来七天预测接口
+     * @param ids
+     * @param detailsFlag
+     * @return
+     */
+    public IndustryDetailsInfo toDetailsByPlateId(List<String> ids,Boolean detailsFlag){
+        // todo 根据id进入详情,计算值。包含下周预测。
         List<IndustryDetail> industryDetails = new ArrayList<>();
+        for (String id : ids) {
+            // 上周的每一天,下周的每一天。
+            // toIncInfos();
+            // 1、根据plateid、platename查询出该行业的所有信息。按照日期倒序排序,获取该时间,然后得出该时间的一周内每天的数据。
+            // 实际数据也即本周数据。
+            QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+            industryPlateQueryWrapper.lambda()
+                    .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));
+                }
+            }
+            // 创建detail列表
+            for (IndustryPlate industryPlate : industryPlates) {
+                industryDetails.add(toIndustryDetail(industryPlate));
+            }
+        }
 
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0422","2020-07-17",
-                null,TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0738","2020-06-22",
-                null,TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK450","2020-05-22",
-                null,TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0734","2020-04-22",
-                null,TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0471","2020-03-22",
-                null,TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0422","2020-07-10",
-                TestCommon.toInitFloat(),TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0738","2020-06-15",
-                TestCommon.toInitFloat(),TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK450","2020-05-15",
-                TestCommon.toInitFloat(),TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0734","2020-04-15",
-                TestCommon.toInitFloat(),TestCommon.toInitFloat()));
-        industryDetails.add(TestCommon.toInitIndustryDetail("BK0471","2020-03-15",
-                TestCommon.toInitFloat(),TestCommon.toInitFloat()));
+        // 4、附带新闻数据。
         SearchInfo searchInfo = SearchInfo.builder()
                 .searchParam(ids.get(0))
                 .build();
         List<NewsList> newsLists = newsService.newsDetails(searchInfo);
+
         IndustryDetailsInfo industryInfo = IndustryDetailsInfo.builder()
                 .actuals(industryDetails)
                 .news(newsLists)
@@ -209,49 +218,107 @@ public class SearchServiceImpl implements SearchService {
         return industryInfo;
     }
 
+    /**
+     * 创建每一天的close、pred值。
+     * @param industryPlate
+     * @return
+     */
+    public IndustryDetail toIndustryDetail(IndustryPlate industryPlate){
+        IndustryDetail industryDetail = IndustryDetail.builder()
+                    .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);
+        QueryWrapper<IndustryPlate> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(IndustryPlate::getPlateId,id)
+                .between(IndustryPlate::getPlateDate,monday,sunday);
+        List<IndustryPlate> industryPlates = industryPlateMapper.selectList(queryWrapper);
+        return industryPlates;
+    }
+
     @Override
     public List<IncInfo> incLastWeek() {
-        return toIncInfos(true,false,false);
+        return toIncInfos(true,false,false,false,null);
         // return TestCommon.getIncList();
     }
 
     @Override
     public List<IncInfo> incNextWeekPred() {
-        return toIncInfos(true,false,true);
+        return toIncInfos(true,false,true,false,null);
     }
 
     @Override
     public List<IncInfo> incLastWeekPred() {
-        return toIncInfos(true,true,false);
+        return toIncInfos(true,true,false,false,null);
     }
 
     @Override
     public List<IncInfo> decLastWeek() {
-        return toIncInfos(false,false,false);
+        return toIncInfos(false,false,false,false,null);
     }
 
     @Override
     public List<IncInfo> decNextWeekPred() {
-        return toIncInfos(false,false,true);
+        return toIncInfos(false,false,true,false,null);
     }
 
     @Override
     public List<IncInfo> decLastWeekPred() {
-        return toIncInfos(false,true,false);
+        return toIncInfos(false,true,false,false,null);
     }
 
 
-    public List<IncInfo> toIncInfos(Boolean tag,Boolean lastTag,Boolean nextTag){
-        QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
-        // 涨幅跌幅。上周周五的close-上上上周五的close >0涨 <0跌
-        // industryInfoQueryWrapper.eq("tag",tag);
-        industryInfoQueryWrapper.isNotNull("id");
-        List<IndustryInfo> industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+    /**
+     * 涨幅/跌幅的实际/预测榜方法。
+     * @param tag
+     * @param lastTag
+     * @param nextTag
+     * @param ifIncDec
+     * @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);
+        }else {
+            QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
+            // 涨幅跌幅。上周周五的close-上上上周五的close >0涨 <0跌
+            // industryInfoQueryWrapper.eq("tag",tag);
+            industryInfoQueryWrapper.isNotNull("id");
+            industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+        }
 
         IncInfo incInfo;
         List<IncInfo> incInfos = new ArrayList<>();
         for (IndustryInfo industryInfo : industryInfos) {
-            Map<String,Object> actualMap = TestCommon.calWeek(TestCommon.getWeek(),false);
+            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());
@@ -292,6 +359,10 @@ public class SearchServiceImpl implements SearchService {
         log.info("sort info:{}",JSON.toJSONString(sortLists));
         // 去除跌幅榜或者涨幅榜。
         log.info("tag :{}",tag);
+        if (ifIncDec.equals(true)){
+            log.info("涨跌幅:{}",JSON.toJSONString(sortLists));
+            return sortLists;
+        }
         if (tag.equals(true)){
             // 涨幅:
             sortLists.removeIf(s -> s.getIndustryTag().equals(false));
@@ -342,10 +413,13 @@ public class SearchServiceImpl implements SearchService {
         log.info("calLastWeekActual 上周五:{}",friday);
         log.info("calLastWeekActual 上上周五:{}",lastFriday);
         List<IndustryPlate> industryPlatesLast = getClose(plateId,lastFriday);
-        Float close = industryPlates.get(0).getPlateClose();
-        Float lastClose = industryPlatesLast.get(0).getPlateClose();
-        Float value = close - lastClose;
-        return value;
+        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;
     }
 
     /**
@@ -388,6 +462,12 @@ public class SearchServiceImpl implements SearchService {
         return value;
     }
 
+    /**
+     * 获取N周五的收盘价。
+     * @param plateId
+     * @param friday
+     * @return
+     */
     public List<IndustryPlate> getClose(String plateId,String friday){
         log.info("sel industryplate:{}",plateId +"," + friday);
         QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();

+ 29 - 6
src/test/java/com/pavis/ai/app/fda/FdaApplicationTests.java

@@ -1,5 +1,6 @@
 package com.pavis.ai.app.fda;
 
+import com.alibaba.fastjson.JSON;
 import com.pavis.ai.app.fda.common.utils.DateUtils;
 import com.pavis.ai.app.fda.form.TestCommon;
 import com.pavis.ai.app.fda.mapper.IndustryPlateMapper;
@@ -17,10 +18,10 @@ 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.util.ArrayList;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
+import java.util.stream.Stream;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -35,6 +36,12 @@ public class FdaApplicationTests {
         System.out.println(floatBounded);
     }
 
+    @Test
+    public void test(){
+        System.err.println(JSON.toJSONString(TestCommon.calWeek("",true)));
+        System.err.println(JSON.toJSONString(TestCommon.calWeek("2020-07-16",false)));
+    }
+
     @Test
     public void testLocal(){
         LocalDate today = LocalDate.now();
@@ -46,6 +53,10 @@ public class FdaApplicationTests {
 
     @Test
     public void t(){
+
+
+//         return list;
+
         LocalDateTime now = LocalDateTime.now();
         System.err.println(now.toLocalDate().toString());
         String dayAfterTommorrow = "2020-07-14";
@@ -62,6 +73,8 @@ public class FdaApplicationTests {
 
         System.out.println("当前日期:" + localDate + " 上一周的周五:" + friday + " " + friday.getDayOfWeek());
         System.out.println("当前日期:" + localDate + " 上上一周的周五:" + lastFriday + " " + lastFriday.getDayOfWeek());
+
+
         // System.err.println(now.getDayOfWeek().getValue());
         // int num= LocalDate.of(2020, 07, 14).getDayOfWeek().getValue();
         // System.err.println(num);
@@ -79,8 +92,6 @@ public class FdaApplicationTests {
         String dayAfterTommorrow = "2020-07-17";
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LocalDate localDate = LocalDate.parse(dayAfterTommorrow, pattern);
-        // LocalDate now = LocalDate.now().plusDays(10);
-        System.out.println("当前日期: " + localDate + " " + localDate.getDayOfWeek());
         // 求这个日期上一周的周一、周日
         LocalDate todayOfLastWeek = localDate.minusDays(7);
         LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
@@ -93,7 +104,19 @@ public class FdaApplicationTests {
         System.out.println("当前日期:" + localDate + " 上一周的周五:" + friday + " " + friday.getDayOfWeek());
         System.out.println("当前日期:" + localDate + " 上上一周的周五:" + lastFriday + " " + lastFriday.getDayOfWeek());
 
-
+        List<String> list = new ArrayList<>();
+        System.err.println(ChronoUnit.DAYS.between(monday, sunday));
+        long distance = ChronoUnit.DAYS.between(monday, sunday);
+        if (distance < 1) {
+            // return list;
+            System.err.println(JSON.toJSONString(list));
+        }
+        Map<String,Object> map = new HashMap<>();
+        Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> list.add(f.toString()));
+        Stream.iterate(monday, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> map.put(f.getDayOfWeek().toString(),f.toString()));
+        System.err.println(JSON.toJSONString(list));
+        System.err.println();
+        System.err.println(JSON.toJSONString(map));
     }
 
     @Autowired