Merge remote-tracking branch 'origin/master'
commit
bc2dd64a65
@ -0,0 +1,84 @@
|
|||||||
|
package com.sztzjy.fund_investment.controller;
|
||||||
|
|
||||||
|
import com.sztzjy.fund_investment.annotation.AnonymousAccess;
|
||||||
|
import com.sztzjy.fund_investment.entity.TopicRecord;
|
||||||
|
import com.sztzjy.fund_investment.entity.Topics;
|
||||||
|
import com.sztzjy.fund_investment.entity.TopicsExample;
|
||||||
|
import com.sztzjy.fund_investment.mapper.TopicRecordMapper;
|
||||||
|
import com.sztzjy.fund_investment.mapper.TopicsMapper;
|
||||||
|
import com.sztzjy.fund_investment.service.TopicService;
|
||||||
|
import com.sztzjy.fund_investment.util.ResultEntity;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2023/11/14
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/topics")
|
||||||
|
@Api(tags = "学生端--知识测评答题")
|
||||||
|
public class TopicController {
|
||||||
|
@Autowired
|
||||||
|
private TopicsMapper topicsMapper;
|
||||||
|
@Autowired
|
||||||
|
private TopicService topicService;
|
||||||
|
@Autowired
|
||||||
|
private TopicRecordMapper topicRecordMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author xcj
|
||||||
|
* @Date 2023/11/14
|
||||||
|
*/
|
||||||
|
@GetMapping("getRandomTopic")
|
||||||
|
@ApiOperation("知识测评、项目估值、项目尽调,答题页面返回随机6条数据")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity<List<Topics>> getRandomTopic(@ApiParam("题目来源模块") @RequestParam String module) {
|
||||||
|
TopicsExample topicsExample = new TopicsExample();
|
||||||
|
topicsExample.createCriteria().andModuleEqualTo(module);
|
||||||
|
List<Topics> topics = topicsMapper.selectByExampleWithBLOBs(topicsExample);
|
||||||
|
//随机取6道题目
|
||||||
|
Collections.shuffle(topics);
|
||||||
|
int size = Math.min(6, topics.size());
|
||||||
|
List<Topics> randomTopics = topics.subList(0, size);
|
||||||
|
for (Topics randomTopic : randomTopics) {
|
||||||
|
randomTopic.setAnswer(null);
|
||||||
|
}
|
||||||
|
return new ResultEntity<>(randomTopics);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
@PostMapping("getRightScore")
|
||||||
|
@ApiOperation("知识测评、项目估值、项目尽调,判断答案对错并返回得分")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity<List<String>> getRightScore(@ApiParam("需要ID和用户填写的答案") @RequestBody List<Topics> topics, @RequestParam String flowId) {
|
||||||
|
return topicService.getRightScore(topics, flowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
@PostMapping("getTopicRecord")
|
||||||
|
@ApiOperation("知识测评、项目估值、项目尽调,回显答题记录")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity <List<TopicRecord>> getTopicRecord(@ApiParam("getRightScore返回的ID集合")@RequestParam List<String> ids) {
|
||||||
|
List<TopicRecord>list= new ArrayList<>();
|
||||||
|
for (String id : ids) {
|
||||||
|
TopicRecord topicRecord = topicRecordMapper.selectByPrimaryKey(id);
|
||||||
|
list.add(topicRecord);
|
||||||
|
}
|
||||||
|
return new ResultEntity<>(list);
|
||||||
|
}
|
||||||
|
}
|
@ -1,48 +0,0 @@
|
|||||||
package com.sztzjy.fund_investment.controller;
|
|
||||||
|
|
||||||
import com.sztzjy.fund_investment.annotation.AnonymousAccess;
|
|
||||||
import com.sztzjy.fund_investment.entity.Topics;
|
|
||||||
import com.sztzjy.fund_investment.entity.TopicsExample;
|
|
||||||
import com.sztzjy.fund_investment.mapper.TopicsMapper;
|
|
||||||
import com.sztzjy.fund_investment.util.ResultEntity;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import io.swagger.annotations.ApiParam;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author xcj
|
|
||||||
* @Date 2023/11/14
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/topics")
|
|
||||||
@Api(tags = "学生端--知识测评答题")
|
|
||||||
public class topicController {
|
|
||||||
@Autowired
|
|
||||||
private TopicsMapper topicsMapper;
|
|
||||||
|
|
||||||
/* 知识测评答题
|
|
||||||
* @author xcj
|
|
||||||
* @Date 2023/11/14
|
|
||||||
*/
|
|
||||||
@GetMapping("getRandomTopic")
|
|
||||||
@ApiOperation("知识测评答题页面返回随机6条数据")
|
|
||||||
@AnonymousAccess
|
|
||||||
public ResultEntity<List<Topics>> getRandomTopic(@ApiParam("题目来源模块") @RequestParam String module) {
|
|
||||||
TopicsExample topicsExample =new TopicsExample();
|
|
||||||
topicsExample.createCriteria().andModuleEqualTo(module);
|
|
||||||
List<Topics> topics = topicsMapper.selectByExampleWithBLOBs(topicsExample);
|
|
||||||
//随机取6道题目
|
|
||||||
Collections.shuffle(topics);
|
|
||||||
int size = Math.min(6, topics.size());
|
|
||||||
List<Topics> randomTopics = topics.subList(0, size);
|
|
||||||
return new ResultEntity<>(randomTopics);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.sztzjy.fund_investment.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
public interface PerformanceScoreService {
|
||||||
|
void calculateScoreByModule(String methodName, Integer score, String flowId);
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.sztzjy.fund_investment.service;
|
||||||
|
|
||||||
|
import com.sztzjy.fund_investment.entity.Topics;
|
||||||
|
import com.sztzjy.fund_investment.util.ResultEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
public interface TopicService {
|
||||||
|
ResultEntity<List<String>> getRightScore(List<Topics> topics,String flowId);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.sztzjy.fund_investment.service.serviceImpl;
|
||||||
|
|
||||||
|
import com.sztzjy.fund_investment.entity.PerformanceScore;
|
||||||
|
import com.sztzjy.fund_investment.entity.PerformanceScoreExample;
|
||||||
|
import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper;
|
||||||
|
import com.sztzjy.fund_investment.service.PerformanceScoreService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class PerformanceScoreServiceImpl implements PerformanceScoreService {
|
||||||
|
@Autowired
|
||||||
|
private PerformanceScoreMapper performanceScoreMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/* 计分方法
|
||||||
|
* @author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
@Override // 实体类字段名 分数 流程ID
|
||||||
|
public void calculateScoreByModule(String methodName, Integer score, String flowId) {
|
||||||
|
PerformanceScoreExample performanceScoreExample = new PerformanceScoreExample();
|
||||||
|
performanceScoreExample.createCriteria().andFlowIdEqualTo(flowId);
|
||||||
|
List<PerformanceScore> performanceScores = performanceScoreMapper.selectByExample(performanceScoreExample);
|
||||||
|
PerformanceScore performanceScore = performanceScores.get(0);
|
||||||
|
performanceScore.set(methodName,score);
|
||||||
|
performanceScoreMapper.updateByPrimaryKey(performanceScore);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
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.PerformanceScore;
|
||||||
|
import com.sztzjy.fund_investment.entity.PerformanceScoreExample;
|
||||||
|
import com.sztzjy.fund_investment.entity.TopicRecord;
|
||||||
|
import com.sztzjy.fund_investment.entity.Topics;
|
||||||
|
import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper;
|
||||||
|
import com.sztzjy.fund_investment.mapper.TopicRecordMapper;
|
||||||
|
import com.sztzjy.fund_investment.mapper.TopicsMapper;
|
||||||
|
import com.sztzjy.fund_investment.service.PerformanceScoreService;
|
||||||
|
import com.sztzjy.fund_investment.service.TopicService;
|
||||||
|
import com.sztzjy.fund_investment.util.ResultEntity;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2023/11/15
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TopicServiceImpl implements TopicService {
|
||||||
|
@Autowired
|
||||||
|
private TopicsMapper topicsMapper;
|
||||||
|
@Autowired
|
||||||
|
private PerformanceScoreService performanceScoreService;
|
||||||
|
@Autowired
|
||||||
|
private TopicRecordMapper topicRecordMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultEntity<List<String>> getRightScore(List<Topics> topics, String flowId) {
|
||||||
|
int score = 0;
|
||||||
|
List<String>list =new ArrayList<>();
|
||||||
|
for (Topics topic : topics) {
|
||||||
|
String userAnswer = topic.getAnswer();
|
||||||
|
String topicId = topic.getTopicId();
|
||||||
|
Topics topicsData = topicsMapper.selectByPrimaryKey(topicId);
|
||||||
|
String rightAnswer = topicsData.getAnswer();
|
||||||
|
String topicType = topicsData.getTopicType();
|
||||||
|
if (topicType.equals(Constant.MULTIPLECHOICE)) {
|
||||||
|
// 将用户选择的答案和正确答案转换为字符数组或集合
|
||||||
|
char[] userAnswerArray = userAnswer.toCharArray();
|
||||||
|
char[] rightAnswerArray = rightAnswer.toCharArray();
|
||||||
|
|
||||||
|
// 检查答案长度是否相等
|
||||||
|
if (userAnswerArray.length != rightAnswerArray.length) {
|
||||||
|
// 答案长度不相等,答案错误跳过循环
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查每个选项是否同时存在于用户答案和正确答案中
|
||||||
|
boolean isCorrect = true;
|
||||||
|
for (char c : rightAnswerArray) {
|
||||||
|
if (!containsChar(userAnswerArray, c)) {
|
||||||
|
isCorrect = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isCorrect) {
|
||||||
|
// 答案正确
|
||||||
|
score = score + 1; // 设置得分为1或其他适当的值
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (userAnswer.equals(rightAnswer)) {
|
||||||
|
score = score + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加到答题记录表
|
||||||
|
TopicRecord topicRecord =new TopicRecord();
|
||||||
|
String recordId = IdUtil.simpleUUID();
|
||||||
|
topicRecord.setId(recordId);
|
||||||
|
topicRecord.setTopicId(topicId);
|
||||||
|
topicRecord.setUserAnswer(userAnswer);
|
||||||
|
topicRecord.setAnswer(rightAnswer);
|
||||||
|
topicRecord.setFlowId(flowId);
|
||||||
|
topicRecord.setTopicContent(topic.getTopicContent());
|
||||||
|
topicRecordMapper.insert(topicRecord);
|
||||||
|
list.add(recordId);
|
||||||
|
}
|
||||||
|
//六道题总分最多五分
|
||||||
|
if (score >= 5) {
|
||||||
|
score = 5;
|
||||||
|
}
|
||||||
|
// 调用计分方法
|
||||||
|
performanceScoreService.calculateScoreByModule("knowledgeAssessmentScore", score, flowId);
|
||||||
|
String strScore = String.valueOf(score);
|
||||||
|
list.add(strScore);
|
||||||
|
return new ResultEntity<>(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查字符数组是否包含指定字符
|
||||||
|
private boolean containsChar(char[] array, char c) {
|
||||||
|
for (char element : array) {
|
||||||
|
if (element == c) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue