From 6ce77a293d01112203645d08f89a8ecd12b0b71a Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Mon, 18 Dec 2023 14:03:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=80=E5=87=BA=E6=97=B6?= =?UTF-8?q?=E6=9C=BA=E8=A1=A8=EF=BC=8C=E5=AE=8C=E6=88=90=E6=8A=95=E8=B5=84?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E9=A1=B5=E9=9D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TopicController.java | 8 ++-- .../entity/query/TopicQuery.java | 14 +++++++ .../fund_investment/mapper/TopicsMapper.java | 3 ++ .../fund_investment/service/TopicService.java | 10 ++--- .../service/serviceImpl/TopicServiceImpl.java | 40 ++++++++++--------- src/main/resources/mappers/TopicsMapper.xml | 7 ++++ 6 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/sztzjy/fund_investment/entity/query/TopicQuery.java diff --git a/src/main/java/com/sztzjy/fund_investment/controller/TopicController.java b/src/main/java/com/sztzjy/fund_investment/controller/TopicController.java index 17503df..9afb801 100644 --- a/src/main/java/com/sztzjy/fund_investment/controller/TopicController.java +++ b/src/main/java/com/sztzjy/fund_investment/controller/TopicController.java @@ -67,8 +67,8 @@ public class TopicController { @ApiOperation("知识测评,项目估值,项目尽调,答题页面返回随机6条数据") @AnonymousAccess public ResultEntity> getRandomTopic(@ApiParam("题目来源模块:知识测评题库,项目尽调题库,项目估值题库") @RequestParam String module, - @RequestParam String flowId) { - return new ResultEntity>(topicService.getRandomTopic(module, flowId)); + @RequestParam String flowId,String schoolId) { + return new ResultEntity>(topicService.getRandomTopic(module, flowId,schoolId)); } @@ -79,8 +79,8 @@ public class TopicController { @PostMapping("getIPOTopicTwo") @ApiOperation("IPO页面弹窗2使用返回随机6条数据") @AnonymousAccess - public ResultEntity> getIPOTopicTwo(@RequestParam String flowId) { - return new ResultEntity>(topicService.getIPOTopicTwo(flowId)); + public ResultEntity> getIPOTopicTwo(@RequestParam String flowId,@RequestParam String schoolId) { + return new ResultEntity>(topicService.getIPOTopicTwo(flowId,schoolId)); } diff --git a/src/main/java/com/sztzjy/fund_investment/entity/query/TopicQuery.java b/src/main/java/com/sztzjy/fund_investment/entity/query/TopicQuery.java new file mode 100644 index 0000000..9688e3b --- /dev/null +++ b/src/main/java/com/sztzjy/fund_investment/entity/query/TopicQuery.java @@ -0,0 +1,14 @@ +package com.sztzjy.fund_investment.entity.query; + +import lombok.Data; + +/** + * @Author xcj + * @Date 2023/12/18 + */ +@Data +public class TopicQuery { + private String module; + private String schoolId; + private int count; +} diff --git a/src/main/java/com/sztzjy/fund_investment/mapper/TopicsMapper.java b/src/main/java/com/sztzjy/fund_investment/mapper/TopicsMapper.java index e04699e..009a57e 100644 --- a/src/main/java/com/sztzjy/fund_investment/mapper/TopicsMapper.java +++ b/src/main/java/com/sztzjy/fund_investment/mapper/TopicsMapper.java @@ -6,6 +6,7 @@ import com.sztzjy.fund_investment.entity.TopicsWithBLOBs; import java.util.List; +import com.sztzjy.fund_investment.entity.query.TopicQuery; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -42,4 +43,6 @@ public interface TopicsMapper { void insertBatch(List list); List getTopicsByCondition(@Param("schoolId") String schoolId, @Param("module") String module, @Param("topicContent") String topicContent); + + List selectRandomTopics(@Param("query") TopicQuery query); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/fund_investment/service/TopicService.java b/src/main/java/com/sztzjy/fund_investment/service/TopicService.java index 57a3b67..e444057 100644 --- a/src/main/java/com/sztzjy/fund_investment/service/TopicService.java +++ b/src/main/java/com/sztzjy/fund_investment/service/TopicService.java @@ -13,13 +13,13 @@ import java.util.List; * @Date 2023/11/15 */ public interface TopicService { - ResultEntity> getRightScore(List topics,String flowId); + ResultEntity> getRightScore(List topics, String flowId); - List getIPOTopicTwo(String flowId); + List getIPOTopicTwo(String flowId, String schoolId); - List getRandomTopic(String module,String flowId); + List getRandomTopic(String module, String flowId, String schoolId); - List getTopicRecord(String flowId,String module); + List getTopicRecord(String flowId, String module); - int importFile(MultipartFile file,String schoolId,String module); + int importFile(MultipartFile file, String schoolId, String module); } diff --git a/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/TopicServiceImpl.java b/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/TopicServiceImpl.java index ba7ef04..c4602af 100644 --- a/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/TopicServiceImpl.java +++ b/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/TopicServiceImpl.java @@ -3,6 +3,7 @@ package com.sztzjy.fund_investment.service.serviceImpl; import cn.hutool.core.util.IdUtil; import com.sztzjy.fund_investment.config.Constant; import com.sztzjy.fund_investment.entity.*; +import com.sztzjy.fund_investment.entity.query.TopicQuery; import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper; import com.sztzjy.fund_investment.mapper.TopicRecordMapper; import com.sztzjy.fund_investment.mapper.TopicsMapper; @@ -148,9 +149,9 @@ public class TopicServiceImpl implements TopicService { @Override public ResultEntity> getRightScore(List topics, String flowId) { String module1 = topics.get(0).getModule(); - List topicRecord1 = getTopicRecord(flowId,module1); - if (!topicRecord1.isEmpty()){ - return new ResultEntity>(HttpStatus.BAD_REQUEST,"请勿重复提交!"); + List topicRecord1 = getTopicRecord(flowId, module1); + if (!topicRecord1.isEmpty()) { + return new ResultEntity>(HttpStatus.BAD_REQUEST, "请勿重复提交!"); } int score = 0; List list = new ArrayList<>(); @@ -284,14 +285,16 @@ public class TopicServiceImpl implements TopicService { // } @Override - public List getRandomTopic(String module, String flowId) { + public List getRandomTopic(String module, String flowId, String schoolId) { List topicRecord = getTopicRecord(flowId, module); if (!topicRecord.isEmpty()) { return null; } - TopicsExample topicsExample = new TopicsExample(); - topicsExample.createCriteria().andModuleEqualTo(module); - List topics = topicsMapper.selectByExampleWithBLOBs(topicsExample); + TopicQuery topicQuery = new TopicQuery(); + topicQuery.setCount(6); + topicQuery.setModule(module); + topicQuery.setSchoolId(schoolId); + List topics = topicsMapper.selectRandomTopics(topicQuery); //随机取6道题目 Collections.shuffle(topics); int size = Math.min(6, topics.size()); @@ -320,15 +323,23 @@ public class TopicServiceImpl implements TopicService { * @Date 2023/11/21 IPO上市板块题目,IPO上市条件题目 */ @Override - public List getIPOTopicTwo(String flow) { + public List getIPOTopicTwo(String flow, String schoolId) { List IPOBKList = getTopicRecord(flow, Constant.IPOBK); List IPOTJList = getTopicRecord(flow, Constant.IPOTJ); if (!(IPOBKList.isEmpty()) || !(IPOTJList.isEmpty())) { return null; } int topicCountPerModule = 3; - List topics = getRandomTopicsByModule(Constant.IPOBK, topicCountPerModule); - List topics1 = getRandomTopicsByModule(Constant.IPOTJ, topicCountPerModule); + TopicQuery topicQuery = new TopicQuery(); + topicQuery.setCount(3); + topicQuery.setModule(Constant.IPOBK); + topicQuery.setSchoolId(schoolId); + List topics = topicsMapper.selectRandomTopics(topicQuery); + TopicQuery topicQuery1 = new TopicQuery(); + topicQuery1.setCount(3); + topicQuery1.setModule(Constant.IPOTJ); + topicQuery1.setSchoolId(schoolId); + List topics1 = topicsMapper.selectRandomTopics(topicQuery1); topics.addAll(topics1); // List list = toTopicsDtoList(topics); // list.addAll(toTopicsDtoList(topics1)); @@ -340,14 +351,7 @@ public class TopicServiceImpl implements TopicService { * @author xcj * @Date 2023/11/21 */ - private List getRandomTopicsByModule(String module, int count) { - TopicsExample topicsExample = new TopicsExample(); - topicsExample.createCriteria().andModuleEqualTo(module); - List topics = topicsMapper.selectByExampleWithBLOBs(topicsExample); - Collections.shuffle(topics); - int size = Math.min(count, topics.size()); - return topics.subList(0, size); - } + /* 选项转Map,对象转Dto返回 diff --git a/src/main/resources/mappers/TopicsMapper.xml b/src/main/resources/mappers/TopicsMapper.xml index 567aa6e..efff3fd 100644 --- a/src/main/resources/mappers/TopicsMapper.xml +++ b/src/main/resources/mappers/TopicsMapper.xml @@ -90,6 +90,13 @@ , analysis +