浏览代码

1、按照行业id名称搜索时,记录搜索的次数。

jessie 5 年之前
父节点
当前提交
d018cb9afd

+ 5 - 4
src/main/java/com/pavis/ai/app/fda/common/utils/DateUtils.java

@@ -84,6 +84,7 @@ public class DateUtils {
                 week = "7";
                 break;
         }
+        log.info("curr:{}",week);
         return week;
     }
 
@@ -160,7 +161,7 @@ public class DateUtils {
             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));
+            log.info("获取周五和上周五 map:{}", JSON.toJSONString(map));
             return map;
         }else {
             // 上周五和上上周五
@@ -172,7 +173,7 @@ public class DateUtils {
             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));
+            log.info("获取上周五和上上周五 map:{}", JSON.toJSONString(map));
             return map;
         }
     }
@@ -195,7 +196,7 @@ public class DateUtils {
                 // 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));
+            log.info("6-7 每一天:{}",JSON.toJSONString(map));
             return map;
         }else {
             // 上周:
@@ -210,7 +211,7 @@ public class DateUtils {
             }
             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));
+            log.info("1-5每一天:{}",JSON.toJSONString(map));
             return map;
         }
     }

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

@@ -55,7 +55,7 @@ public class NewsController {
         return ResultBody.ok().data(newsService.createNews(newsList));
     }
 
-    @ApiOperation("根据行业id搜索")
+    @ApiOperation("根据行业id或者行业名称搜索")
     @ApiOperationSupport(order = 3)
     @PostMapping("/search")
     public ResultBody search(@RequestBody SearchInfo searchInfo){

+ 4 - 2
src/main/java/com/pavis/ai/app/fda/service/impl/NewsServiceImpl.java

@@ -87,8 +87,10 @@ public class NewsServiceImpl implements NewsService {
     @Override
     public List<HotSearch> searchHot() {
         QueryWrapper<SearchCount> searchCountQueryWrapper = new QueryWrapper<>();
-        searchCountQueryWrapper.orderByDesc("search_num");
-        searchCountQueryWrapper.isNotNull("id");
+        searchCountQueryWrapper.lambda()
+                .isNotNull(SearchCount::getId)
+                .orderByDesc(SearchCount::getSearchNum)
+                .last("limit 0,10");
         List<SearchCount> searchCounts = searchCountMapper.selectList(searchCountQueryWrapper);
         HotSearch hotSearch;
         List<HotSearch> hotSearches = new ArrayList<>();

+ 84 - 39
src/main/java/com/pavis/ai/app/fda/service/impl/SearchServiceImpl.java

@@ -870,9 +870,27 @@ public class SearchServiceImpl implements SearchService {
     //             .orderByDesc(IndustryPlate::getPlateDate);
     //     return industryPlateMapper.selectList(industryPlateQueryWrapper);
     // }
+
+    /**
+     * 实际榜排序。
+     * @return
+     */
     public List<IndustryPlateRes> getNewest() {
         QueryWrapper<IndustryPlateRes> industryPlateResQueryWrapper = new QueryWrapper<>();
         industryPlateResQueryWrapper.lambda()
+                .isNotNull(IndustryPlateRes::getPlateClose)
+                .orderByDesc(IndustryPlateRes::getPlateDate);
+        return industryPlateResMapper.selectList(industryPlateResQueryWrapper);
+    }
+
+    /**
+     * 预测榜排序。
+     * @return
+     */
+    public List<IndustryPlateRes> getNewestByPred() {
+        QueryWrapper<IndustryPlateRes> industryPlateResQueryWrapper = new QueryWrapper<>();
+        industryPlateResQueryWrapper.lambda()
+                .isNull(IndustryPlateRes::getPlateClose)
                 .orderByDesc(IndustryPlateRes::getPlateDate);
         return industryPlateResMapper.selectList(industryPlateResQueryWrapper);
     }
@@ -884,22 +902,35 @@ public class SearchServiceImpl implements SearchService {
      */
     public List<IncInfo> lastWeekActual(Boolean incOrDec){
         // 1、根据日期倒序拿到数据库中的最新日期
-        Map<String,Object> actualMap = toDate();
+        Map<String,Object> actualMap = toDate(true);
         // 1、根据当前日期判断是否是周六,是 本周的和上周的数据。否则上周和上上周的数据。
+        // String lastFriday = actualMap.get("friday").toString();
+        // String friday = DateUtils.getEverydayByActual(lastFriday).get("MONDAY").toString();
+        // todo 此处需要修改。
         String friday = actualMap.get("friday").toString();
         String lastFriday = actualMap.get("lastFriday").toString();
         // 2、查询涨跌幅的实际榜。涨幅 倒叙排序取前十。跌幅 正序排序取前十。根据closeup值。
         List<IndustryPlateRes> plateResList = new ArrayList<>();
         if (incOrDec.equals(true)){
             // 涨幅。
-            plateResList = toActualIncOrDec(incOrDec,friday,lastFriday);
+            if (DateUtils.checkDate(friday,lastFriday).equals(true)) {
+                plateResList = toActualIncOrDec(incOrDec,lastFriday,friday);
+            }else {
+                plateResList = toActualIncOrDec(incOrDec,friday,lastFriday);
+            }
+
             // 3、返回数据创建。
             List<IncInfo> incInfos = toBackActualIncInfos(plateResList);
             List<IncInfo> finalIncInfos = incInfos.stream().filter(s->s.getIndustryValue() > 0.0F)
                     .collect(Collectors.toList());
             return finalIncInfos;
         }else {
-            plateResList = toActualIncOrDec(incOrDec,friday,lastFriday);
+            if (DateUtils.checkDate(friday,lastFriday).equals(true)) {
+                plateResList = toActualIncOrDec(incOrDec,lastFriday,friday);
+            }else {
+                plateResList = toActualIncOrDec(incOrDec,friday,lastFriday);
+            }
+
             // 3、返回数据创建。
             List<IncInfo> incInfos = toBackActualIncInfos(plateResList);
             List<IncInfo> finalIncInfos = incInfos.stream().filter(s->s.getIndustryValue() < 0.0F)
@@ -912,10 +943,18 @@ public class SearchServiceImpl implements SearchService {
      * 取日期。
      * @return
      */
-    public Map<String,Object> toDate(){
+    public Map<String,Object> toDate(Boolean actualOrPred){
         // 1、根据日期倒序拿到数据库中的最新日期
-        List<IndustryPlateRes> datePlates = getNewest();
+        List<IndustryPlateRes> datePlates = new ArrayList<>();
+        if (actualOrPred.equals(true)){
+            // 实际
+            datePlates = getNewest();
+        }else {
+            // 预测
+            datePlates = getNewestByPred();
+        }
         String date = datePlates.size() > 0 ? datePlates.get(0).getPlateDate() : TestCommon.getWeek();
+        log.info("sql 最新日期:{}",date);
         // 1.1 根据当前日期判断是否是周六,是 本周的和上周的数据。否则上周和上上周的数据。
         Map<String,Object> actualMap = DateUtils.getFridayOrLastFriday(date);
         return actualMap;
@@ -932,37 +971,17 @@ public class SearchServiceImpl implements SearchService {
         QueryWrapper<IndustryPlateRes> queryWrapper = new QueryWrapper<>();
         if (incOrDec.equals(true)){
             // 涨幅
-            if (DateUtils.checkDate(friday,lastFriday).equals(true)) {
-                queryWrapper.lambda()
-                        .orderByDesc(IndustryPlateRes::getPlateCloseUp)
-                        .groupBy(IndustryPlateRes::getPlateId)
-                        .between(IndustryPlateRes::getPlateDate,lastFriday,friday)
-                        .eq(IndustryPlateRes::getPlateCloseUp,null)
-                        .last("limit 0,10");
-            }else {
-                queryWrapper.lambda()
-                        .orderByDesc(IndustryPlateRes::getPlateCloseUp)
-                        .groupBy(IndustryPlateRes::getPlateId)
-                        .between(IndustryPlateRes::getPlateDate,friday,lastFriday)
-                        .eq(IndustryPlateRes::getPlateCloseUp,null)
-                        .last("limit 0,10");
-            }
+            queryWrapper.lambda()
+                    .orderByDesc(IndustryPlateRes::getPlateCloseUp)
+                    .groupBy(IndustryPlateRes::getPlateId)
+                    .between(IndustryPlateRes::getPlateDate,friday,lastFriday)
+                    .last("limit 0,10");
         }else {
-            if (DateUtils.checkDate(friday,lastFriday).equals(true)) {
-                queryWrapper.lambda()
-                        .orderByAsc(IndustryPlateRes::getPlateCloseUp)
-                        .groupBy(IndustryPlateRes::getPlateId)
-                        .between(IndustryPlateRes::getPlateDate,lastFriday,friday)
-                        .eq(IndustryPlateRes::getPlateCloseUp,null)
-                        .last("limit 0,10");
-            }else {
-                queryWrapper.lambda()
-                        .orderByAsc(IndustryPlateRes::getPlateCloseUp)
-                        .groupBy(IndustryPlateRes::getPlateId)
-                        .between(IndustryPlateRes::getPlateDate,friday,lastFriday)
-                        .eq(IndustryPlateRes::getPlateCloseUp,null)
-                        .last("limit 0,10");
-            }
+            queryWrapper.lambda()
+                    .orderByAsc(IndustryPlateRes::getPlateCloseUp)
+                    .groupBy(IndustryPlateRes::getPlateId)
+                    .between(IndustryPlateRes::getPlateDate,friday,lastFriday)
+                    .last("limit 0,10");
         }
         List<IndustryPlateRes> plates = industryPlateResMapper.selectList(queryWrapper);
         log.info("toActualIncOrDec plates:{}",JSON.toJSONString(plates));
@@ -976,18 +995,41 @@ public class SearchServiceImpl implements SearchService {
      */
     public List<IncInfo> weekPred(Boolean incOrDec,Boolean lastOrNext){
         // 1、根据日期倒序拿到数据库中的最新日期
-        List<IndustryPlateRes> datePlates = getNewest();
+        List<IndustryPlateRes> datePlates = getNewestByPred();
         String date = datePlates.size() > 0 ? datePlates.get(0).getPlateDate() : TestCommon.getWeek();
         // 2、检索出符合要求的数据。
         List<IndustryPlateRes> plates = new ArrayList<>();
         if(lastOrNext.equals(true)){
+            log.info("上周预测...");
             // 上周预测。
             Map<String, Object> map = DateUtils.getFridayOrLastFriday(date);
-            plates = toPredLastOrNext(incOrDec,map.get("friday").toString(),map.get("lastFriday").toString());
+            String friday = map.get("friday").toString();
+            String lastFriday = map.get("lastFriday").toString();
+            if (DateUtils.checkDate(friday,lastFriday).equals(true)) {
+                plates = toPredLastOrNext(incOrDec,lastFriday,friday);
+            }else {
+                plates = toPredLastOrNext(incOrDec,friday,lastFriday);
+            }
+
+            // todo 需要修改。
+            // String lastFriday = map.get("lastFriday").toString();
+            // String friday = DateUtils.getEverydayByActual(lastFriday).get("MONDAY").toString();
+            // plates = toPredLastOrNext(incOrDec,friday,lastFriday);
 
         }else {
+            log.info("下周预测...");
             Map<String, Object> map = DateUtils.getEverydayOfNexWeek(date);
-            plates = toPredLastOrNext(incOrDec,map.get("friday").toString(),map.get("nextFriday").toString());
+            String friday = map.get("friday").toString();
+            String nextFriday = map.get("nextFriday").toString();
+            if (DateUtils.checkDate(friday,nextFriday).equals(true)) {
+                plates = toPredLastOrNext(incOrDec,nextFriday,friday);
+            }else {
+                plates = toPredLastOrNext(incOrDec,friday,nextFriday);
+            }
+            // todo 需要修改。
+            // String lastFriday = map.get("nextFriday").toString();
+            // String friday = DateUtils.getEverydayByActual(lastFriday).get("MONDAY").toString();
+            // plates = toPredLastOrNext(incOrDec,friday,lastFriday);
         }
         // 3、创建返回值。
         if (incOrDec.equals(true)){
@@ -1230,7 +1272,7 @@ public class SearchServiceImpl implements SearchService {
      */
     public List<IncInfo> toSearch(SearchInfo searchInfo){
         // 1、根据日期倒序拿到数据库中的最新日期
-        Map<String,Object> actualMap = toDate();
+        Map<String,Object> actualMap = toDate(true);
         // 1、根据当前日期判断是否是周六,是 本周的和上周的数据。否则上周和上上周的数据。
         String friday = actualMap.get("friday").toString();
         String lastFriday = actualMap.get("lastFriday").toString();
@@ -1241,6 +1283,8 @@ public class SearchServiceImpl implements SearchService {
         }else {
             plates = toSearchQuery(searchInfo,friday,lastFriday);
         }
+        // 热点搜索数据更新。
+        newsService.searchCount(searchInfo.getSearchParam(),searchInfo.getSearchParam());
 
         // 3、创建返回s数据。
         return toSearchBackIncInfos(plates);
@@ -1285,6 +1329,7 @@ public class SearchServiceImpl implements SearchService {
                 .orderByDesc(IndustryPlateRes::getPlateDate)
                 .groupBy(IndustryPlateRes::getPlateId)
                 .between(IndustryPlateRes::getPlateDate,friday,lastFriday)
+                // .eq(IndustryPlateRes::getPlateDate,friday)
                 .last("limit 0,10")
                 .or()
                 .like(IndustryPlateRes::getPlateId,searchInfo.getSearchParam())

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

@@ -52,6 +52,18 @@ public class LocalDateTest {
     // 2、预测帮:查找close为空的。
     // 3、date上周 上上周测试。
     // 4、数据截取。
+    @Test
+    public void testDate(){
+        String date = "2020-07-03";
+        Map<String,Object> actualMap = DateUtils.getFridayOrLastFriday(date);
+        System.err.println(JSON.toJSONString(actualMap));
+        String everyDate = actualMap.get("friday").toString();
+        System.err.println();
+        DateUtils.getEverydayByActual(everyDate);
+        System.err.println();
+        DateUtils.getEverydayByActual(actualMap.get("lastFriday").toString());
+    }
+
 
     @Test
     public void testUpdateIPlateName(){