ソースを参照

1、新增沪深接口。

jessie 5 年 前
コミット
cf1a4e63c0

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

@@ -3,7 +3,6 @@ package com.pavis.ai.app.fda.controller;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.github.xiaoymin.knife4j.annotations.ApiSort;
 import com.pavis.ai.app.fda.common.http.ResultBody;
-import com.pavis.ai.app.fda.form.search.SearchInfo;
 import com.pavis.ai.app.fda.service.HisService;
 import com.pavis.ai.app.fda.service.SearchService;
 import io.swagger.annotations.Api;
@@ -32,13 +31,7 @@ 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));
-    // }
+
 
 
 
@@ -63,6 +56,13 @@ public class BaseController {
     }
 
 
+    @ApiOperation("沪深接口")
+    @ApiOperationSupport(order = 3)
+    @GetMapping("/his/hushen")
+    public ResultBody closeHushenSum(){
+        // 查询最近的close的sum和pred_close的值。
+        return ResultBody.ok().data(searchService.hisHushenSum());
+    }
 
     @ApiOperation("涨幅---上周实际榜分页")
     @ApiOperationSupport(order = 5)

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

@@ -36,21 +36,21 @@ public class NewsController {
 
     @ApiOperation("首页新闻列表,按时排序")
     @ApiOperationSupport(order = 1)
-    @GetMapping("/news/list")
+    @GetMapping("/list")
     public ResultBody newsList(){
         return ResultBody.ok().data(newsService.newsList());
     }
 
     @ApiOperation("根据点击的新闻id 查看具体新闻内容")
     @ApiOperationSupport(order = 2)
-    @PostMapping("/news/details")
+    @PostMapping("/details")
     public ResultBody newsDetails(@RequestBody SearchInfo searchInfo){
         return ResultBody.ok().data(newsService.newsDetails(searchInfo));
     }
 
     @ApiOperation("新闻数据创建接口")
     @ApiOperationSupport(order = 3)
-    @PostMapping("/news/create")
+    @PostMapping("/create")
     public ResultBody createDetails(@RequestBody NewsList newsList){
         return ResultBody.ok().data(newsService.createNews(newsList));
     }

+ 7 - 0
src/main/java/com/pavis/ai/app/fda/service/SearchService.java

@@ -1,5 +1,6 @@
 package com.pavis.ai.app.fda.service;
 
+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;
 import com.pavis.ai.app.fda.form.search.HotSearch;
@@ -40,6 +41,12 @@ public interface SearchService {
      */
     IndustryDetailsInfo predictFind(List<String> ids);
 
+    /**
+     * 沪深接口。
+     * @return
+     */
+    List<IndustryDetail> hisHushenSum();
+
     /**
      * 涨幅表-上周历史数据
      *

+ 0 - 4
src/main/java/com/pavis/ai/app/fda/service/impl/HisServiceImpl.java

@@ -42,9 +42,6 @@ public class HisServiceImpl implements HisService {
 
     @Override
     public IndustryDetailsInfo hisFind(List<String> ids) {
-        if (ids.size() == 1){
-
-        }
         IndustryDetailsInfo industryDetailsInfo = new IndustryDetailsInfo();
         List<IndustryDetailsInfo> industryDetailsInfos = new ArrayList<>();
         for (String id : ids) {
@@ -67,7 +64,6 @@ public class HisServiceImpl implements HisService {
                             TestCommon.toInitFloat(),TestCommon.toInitFloat());
                     industryDetails.add(industryDetail);
                 }
-
                 industryDetailsInfo = IndustryDetailsInfo.builder()
                         .actuals(industryDetails)
                         .news(newsLists)

+ 98 - 21
src/main/java/com/pavis/ai/app/fda/service/impl/SearchServiceImpl.java

@@ -166,6 +166,11 @@ public class SearchServiceImpl implements SearchService {
         // return industryInfo;
     }
 
+    @Override
+    public List<IndustryDetail> hisHushenSum() {
+        return toHisHushenSum();
+    }
+
     @Override
     public List<IncInfo> incLastWeek() {
         return toIncInfos(true, false, false, false, null);
@@ -197,6 +202,61 @@ public class SearchServiceImpl implements SearchService {
         return toIncInfos(false, true, false, false, null);
     }
 
+    /**
+     * 沪深接口。
+     * @return
+     */
+    public List<IndustryDetail> toHisHushenSum(){
+        QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+        industryPlateQueryWrapper.lambda()
+                .orderByDesc(IndustryPlate::getPlateDate)
+                .last("limit 0,10");
+
+        List<IndustryPlate> datePlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+        String date = datePlates.size() > 0 ? datePlates.get(0).getPlateDate() : TestCommon.getWeek();
+        log.info("实际数据日期:{}", date);
+        // 2、近五天数据日期计算。
+        Map<String, Object> weekMap = DateUtils.getEverydayByActual(date);
+        String monday = weekMap.get("MONDAY").toString();
+        String sunday = weekMap.get("SUNDAY").toString();
+        List<IndustryPlate> industryPlates = toIndustryPlates("", monday, sunday);
+        // 3、下周预测放上面,实际数据放下面。
+        // List<Float> closes = new ArrayList<>();
+        // List<Float> closePreds = new ArrayList<>();
+        // for (IndustryPlate industryPlate : industryPlates) {
+        //     closes.add(industryPlate.getPlateClose());
+        //     closePreds.add(industryPlate.getPlateClosePred());
+        // }
+        List<IndustryDetail> industryDetails = new ArrayList<>();
+        IndustryDetail industryDetail;
+        for (IndustryPlate industryPlate : industryPlates) {
+            QueryWrapper<IndustryPlate> queryWrapper = new QueryWrapper<>();
+            industryPlateQueryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId,industryPlate.getPlateId())
+                    .orderByDesc(IndustryPlate::getPlateDate)
+                    .last("limit 0,10");
+            List<IndustryPlate> sumIndustryPlates = industryPlateMapper.selectList(queryWrapper);
+            Double close = 0.0;
+            Double closePred = 0.0;
+            if (sumIndustryPlates.size() > 0){
+                close = sumIndustryPlates.stream().filter(s -> null != s.getPlateClose())
+                        .mapToDouble(IndustryPlate::getPlateClose).sum();
+                closePred = sumIndustryPlates.stream().filter(s -> null != s.getPlateClosePred())
+                        .mapToDouble(IndustryPlate::getPlateClosePred).sum();
+            }
+            industryDetail = IndustryDetail.builder()
+                    .industryId("")
+                    .industryDate(industryPlate.getPlateDate())
+                    .close(Float.valueOf(close.toString()))
+                    .pred(Float.valueOf(closePred.toString()))
+                    .build();
+
+            industryDetails.add(industryDetail);
+        }
+
+        return industryDetails;
+    }
+
     /**
      * 根据行业id获取详情或者未来七天预测接口
      *
@@ -228,11 +288,9 @@ public class SearchServiceImpl implements SearchService {
                 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();
@@ -298,20 +356,31 @@ public class SearchServiceImpl implements SearchService {
      */
     public List<IndustryPlate> toIndustryPlates(String id, String monday, String sunday) {
         log.info("详情查询:{}", id + ",monday:" + monday + ",sunday:" + sunday);
+
         QueryWrapper<IndustryPlate> queryWrapper = new QueryWrapper<>();
-        if (DateUtils.checkDate(monday,sunday).equals(true)){
-            queryWrapper.lambda()
-                    .eq(IndustryPlate::getPlateId, id)
-                    .orderByDesc(IndustryPlate::getPlateDate)
-                    .between(IndustryPlate::getPlateDate, sunday,monday );
+        if (id.equals("")){
+            if (DateUtils.checkDate(monday,sunday).equals(true)){
+                queryWrapper.lambda()
+                        .orderByDesc(IndustryPlate::getPlateDate)
+                        .between(IndustryPlate::getPlateDate, sunday,monday );
+            }else {
+                queryWrapper.lambda()
+                        .orderByDesc(IndustryPlate::getPlateDate)
+                        .between(IndustryPlate::getPlateDate, monday, sunday);
+            }
         }else {
-            System.err.println("else else");
-            queryWrapper.lambda()
-                    .eq(IndustryPlate::getPlateId, id)
-                    .orderByDesc(IndustryPlate::getPlateDate)
-                    .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 {
+                queryWrapper.lambda()
+                        .eq(IndustryPlate::getPlateId, id)
+                        .orderByDesc(IndustryPlate::getPlateDate)
+                        .between(IndustryPlate::getPlateDate, monday, sunday);
+            }
         }
-
         List<IndustryPlate> industryPlates = industryPlateMapper.selectList(queryWrapper);
         return industryPlates;
     }
@@ -439,7 +508,7 @@ public class SearchServiceImpl implements SearchService {
         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());
+            plates = findIndustryPlate(false, null, map.get("friday").toString(), map.get("nextFriday").toString());
         }
         // List<IndustryPlate> plates = industryPlateMapper.selectList(industryPlateQueryWrapper);
         // 此处去重。
@@ -461,10 +530,12 @@ public class SearchServiceImpl implements SearchService {
             QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
             industryInfoQueryWrapper.lambda()
                     .eq(IndustryInfo::getPlateId, plate.getPlateId());
-            // List<IndustryInfo> infos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+            List<IndustryInfo> infos = industryInfoMapper.selectList(industryInfoQueryWrapper);
             incInfo = IncInfo.builder()
                     .industryId(plate.getPlateId())
-                    .industryName(plate.getPlateName())
+                    // .industryName(plate.getPlateName())
+                    // todo 后期需要修改。
+                    .industryName(infos.get(0).getPlateName())
                     .industryValue(value)
                     .industryTag(industryTag)
                     .build();
@@ -510,13 +581,13 @@ public class SearchServiceImpl implements SearchService {
         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)
+                    .last("limit 0,10")
                     .or()
                     .like(IndustryPlate::getPlateName, searchInfo.getSearchParam());
         }else {
@@ -525,6 +596,7 @@ public class SearchServiceImpl implements SearchService {
                     .orderByDesc(IndustryPlate::getPlateDate)
                     .groupBy(IndustryPlate::getPlateId)
                     .between(IndustryPlate::getPlateDate, friday, lastFriday)
+                    .last("limit 0,10")
                     .or()
                     .like(IndustryPlate::getPlateName, searchInfo.getSearchParam());
         }
@@ -551,6 +623,7 @@ public class SearchServiceImpl implements SearchService {
         }
         industryPlateQueryWrapper.groupBy("plate_id");
         industryPlateQueryWrapper.isNotNull("plate_id");
+        industryPlateQueryWrapper.last("limit 0,10");
         if (just.equals(false)) {
             if (DateUtils.checkDate(friday,lastFriday).equals(true)){
                 industryPlateQueryWrapper.between("plate_date", lastFriday, friday);
@@ -612,15 +685,19 @@ public class SearchServiceImpl implements SearchService {
     }
 
     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 close = industryPlates.size() > 0 ? null != industryPlates.get(0).getPlateClose() ?
+                industryPlates.get(0).getPlateClose() : 0.0F : 0.0F;
+        Float lastClose = industryPlatesLast.size() > 0 ? null != industryPlatesLast.get(0).getPlateClose() ?
+                industryPlatesLast.get(0).getPlateClose() : 0.0F : 0.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 pred = industryPlates.size() > 0 ? null != industryPlates.get(0).getPlateClosePred() ?
+                industryPlates.get(0).getPlateClosePred() : 0.0F : 0.0F;
+        Float lastPred = industryPlatesLast.size() > 0 ? null != industryPlatesLast.get(0).getPlateClosePred() ?
+                industryPlatesLast.get(0).getPlateClosePred() : 0.0F : 0.0F;
         Float value = pred - lastPred;
         return value;
     }

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

@@ -1,7 +1,7 @@
 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.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

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

@@ -5,6 +5,7 @@ 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.IndustryInfoMapper;
 import com.pavis.ai.app.fda.mapper.IndustryPlateMapper;
 import com.pavis.ai.app.fda.model.IndustryInfo;
 import com.pavis.ai.app.fda.model.IndustryPlate;
@@ -39,6 +40,29 @@ public class LocalDateTest {
     @Autowired
     private IndustryPlateMapper industryPlateMapper;
 
+    @Autowired
+    private IndustryInfoMapper industryInfoMapper;
+
+    @Test
+    public void testUpdateIPlateName(){
+        QueryWrapper<IndustryInfo> industryInfoQueryWrapper = new QueryWrapper<>();
+        industryInfoQueryWrapper.lambda()
+                .isNotNull(IndustryInfo::getId)
+                .groupBy(IndustryInfo::getPlateId);
+        List<IndustryInfo> industryInfos = industryInfoMapper.selectList(industryInfoQueryWrapper);
+
+        for (IndustryInfo industryInfo : industryInfos) {
+            QueryWrapper<IndustryPlate> industryPlateQueryWrapper = new QueryWrapper<>();
+            industryPlateQueryWrapper.lambda()
+                    .eq(IndustryPlate::getPlateId,industryInfo.getPlateId());
+            List<IndustryPlate> industryPlates = industryPlateMapper.selectList(industryPlateQueryWrapper);
+            for (IndustryPlate industryPlate : industryPlates) {
+                industryPlate.setPlateName(industryInfo.getPlateName());
+                industryPlateMapper.updateById(industryPlate);
+            }
+        }
+    }
+
     @Test
     public void tes(){
         DateUtils.getEverydayOfNexWeek("2020-07-03");