新增部分表字段,新建flow中间表关联user ID和流程ID

master
xiaoCJ 1 year ago
parent 6367195df6
commit 679a0e0f93

@ -16,6 +16,8 @@ public class Constant {
*/
public static final String BASIC = "Basic";
public static final String TOFQUESTIONS = "判断题";
public static final String SINGLECHOICE = "单选题";
public static final String MULTIPLECHOICE = "多选题";
}

@ -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);
}
}

@ -1,5 +1,6 @@
package com.sztzjy.fund_investment.entity;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import io.swagger.annotations.ApiModelProperty;
@ -54,6 +55,32 @@ public class PerformanceScore {
@ApiModelProperty("投资报告得分")
private BigDecimal investmentReportScore;
@ApiModelProperty("总成绩")
private BigDecimal totalScore;
public void set(String methodName, Object value) {
try {
Method method = getClass().getMethod("set" + Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1),value.getClass());
method.invoke(this, value);
} catch (Exception e) {
e.printStackTrace();
}
}
public Object get(String methodName) {
Object result = null;
try {
Method method = getClass().getMethod("get" + Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1));
result = method.invoke(this);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public String getId() {
return id;
}
@ -173,4 +200,12 @@ public class PerformanceScore {
public void setInvestmentReportScore(BigDecimal investmentReportScore) {
this.investmentReportScore = investmentReportScore;
}
public BigDecimal getTotalScore() {
return totalScore;
}
public void setTotalScore(BigDecimal totalScore) {
this.totalScore = totalScore;
}
}

@ -1034,6 +1034,66 @@ public class PerformanceScoreExample {
addCriterion("investment_report_score not between", value1, value2, "investmentReportScore");
return (Criteria) this;
}
public Criteria andTotalScoreIsNull() {
addCriterion("total_score is null");
return (Criteria) this;
}
public Criteria andTotalScoreIsNotNull() {
addCriterion("total_score is not null");
return (Criteria) this;
}
public Criteria andTotalScoreEqualTo(BigDecimal value) {
addCriterion("total_score =", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreNotEqualTo(BigDecimal value) {
addCriterion("total_score <>", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreGreaterThan(BigDecimal value) {
addCriterion("total_score >", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreGreaterThanOrEqualTo(BigDecimal value) {
addCriterion("total_score >=", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreLessThan(BigDecimal value) {
addCriterion("total_score <", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreLessThanOrEqualTo(BigDecimal value) {
addCriterion("total_score <=", value, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreIn(List<BigDecimal> values) {
addCriterion("total_score in", values, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreNotIn(List<BigDecimal> values) {
addCriterion("total_score not in", values, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("total_score between", value1, value2, "totalScore");
return (Criteria) this;
}
public Criteria andTotalScoreNotBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("total_score not between", value1, value2, "totalScore");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

@ -21,6 +21,9 @@ public class TopicRecord {
@ApiModelProperty("正确答案")
private String answer;
@ApiModelProperty("题干")
private String topicContent;
public String getId() {
return id;
}
@ -60,4 +63,12 @@ public class TopicRecord {
public void setAnswer(String answer) {
this.answer = answer == null ? null : answer.trim();
}
public String getTopicContent() {
return topicContent;
}
public void setTopicContent(String topicContent) {
this.topicContent = topicContent == null ? null : topicContent.trim();
}
}

@ -453,6 +453,76 @@ public class TopicRecordExample {
addCriterion("answer not between", value1, value2, "answer");
return (Criteria) this;
}
public Criteria andTopicContentIsNull() {
addCriterion("topic_content is null");
return (Criteria) this;
}
public Criteria andTopicContentIsNotNull() {
addCriterion("topic_content is not null");
return (Criteria) this;
}
public Criteria andTopicContentEqualTo(String value) {
addCriterion("topic_content =", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentNotEqualTo(String value) {
addCriterion("topic_content <>", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentGreaterThan(String value) {
addCriterion("topic_content >", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentGreaterThanOrEqualTo(String value) {
addCriterion("topic_content >=", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentLessThan(String value) {
addCriterion("topic_content <", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentLessThanOrEqualTo(String value) {
addCriterion("topic_content <=", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentLike(String value) {
addCriterion("topic_content like", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentNotLike(String value) {
addCriterion("topic_content not like", value, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentIn(List<String> values) {
addCriterion("topic_content in", values, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentNotIn(List<String> values) {
addCriterion("topic_content not in", values, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentBetween(String value1, String value2) {
addCriterion("topic_content between", value1, value2, "topicContent");
return (Criteria) this;
}
public Criteria andTopicContentNotBetween(String value1, String value2) {
addCriterion("topic_content not between", value1, value2, "topicContent");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

@ -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);
}

@ -4,5 +4,5 @@ package com.sztzjy.fund_investment.service;
* @Author xcj
* @Date 2023/11/14
*/
public interface trainingReportService {
public interface TrainingReportService {
}

@ -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;
}
}

@ -7,6 +7,6 @@ import org.springframework.stereotype.Service;
* @Date 2023/11/14
*/
@Service
public class trainingReportService {
public class TrainingReportService {
}

@ -37,20 +37,20 @@
</javaClientGenerator>
<!-- 需要生成的表 -->
<table tableName="allotment_object" domainObjectName="AllotmentObject" />
<table tableName="flow" domainObjectName="Flow" />
<table tableName="fundraising" domainObjectName="Fundraising" />
<table tableName="inquiry_participation" domainObjectName="InquiryParticipation" />
<table tableName="issuance_info" domainObjectName="IssuanceInfo" />
<table tableName="issuance_parameter_input" domainObjectName="IssuanceParameterInput" />
<table tableName="performance_score" domainObjectName="PerformanceScore" />
<table tableName="profit_distribution" domainObjectName="ProfitDistribution" />
<table tableName="profit_management" domainObjectName="ProfitManagement" />
<table tableName="question_answer" domainObjectName="QuestionAnswer" />
<table tableName="sys_topics" domainObjectName="Topics" />
<!-- <table tableName="allotment_object" domainObjectName="AllotmentObject" />-->
<!-- <table tableName="flow" domainObjectName="Flow" />-->
<!-- <table tableName="fundraising" domainObjectName="Fundraising" />-->
<!-- <table tableName="inquiry_participation" domainObjectName="InquiryParticipation" />-->
<!-- <table tableName="issuance_info" domainObjectName="IssuanceInfo" />-->
<!-- <table tableName="issuance_parameter_input" domainObjectName="IssuanceParameterInput" />-->
<!-- <table tableName="performance_score" domainObjectName="PerformanceScore" />-->
<!-- <table tableName="profit_distribution" domainObjectName="ProfitDistribution" />-->
<!-- <table tableName="profit_management" domainObjectName="ProfitManagement" />-->
<!-- <table tableName="question_answer" domainObjectName="QuestionAnswer" />-->
<!-- <table tableName="sys_topics" domainObjectName="Topics" />-->
<table tableName="topic_record" domainObjectName="TopicRecord" />
<table tableName="training_report" domainObjectName="TrainingReport" />
<table tableName="user_table" domainObjectName="UserTable" />
<!-- <table tableName="training_report" domainObjectName="TrainingReport" />-->
<!-- <table tableName="user_table" domainObjectName="UserTable" />-->
</context>

@ -7,6 +7,7 @@
<result column="flow_id" jdbcType="VARCHAR" property="flowId" />
<result column="user_answer" jdbcType="VARCHAR" property="userAnswer" />
<result column="answer" jdbcType="VARCHAR" property="answer" />
<result column="topic_content" jdbcType="VARCHAR" property="topicContent" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -67,7 +68,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, topic_id, flow_id, user_answer, answer
id, topic_id, flow_id, user_answer, answer, topic_content
</sql>
<select id="selectByExample" parameterType="com.sztzjy.fund_investment.entity.TopicRecordExample" resultMap="BaseResultMap">
select
@ -101,9 +102,11 @@
</delete>
<insert id="insert" parameterType="com.sztzjy.fund_investment.entity.TopicRecord">
insert into topic_record (id, topic_id, flow_id,
user_answer, answer)
user_answer, answer, topic_content
)
values (#{id,jdbcType=VARCHAR}, #{topicId,jdbcType=VARCHAR}, #{flowId,jdbcType=VARCHAR},
#{userAnswer,jdbcType=VARCHAR}, #{answer,jdbcType=VARCHAR})
#{userAnswer,jdbcType=VARCHAR}, #{answer,jdbcType=VARCHAR}, #{topicContent,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.sztzjy.fund_investment.entity.TopicRecord">
insert into topic_record
@ -123,6 +126,9 @@
<if test="answer != null">
answer,
</if>
<if test="topicContent != null">
topic_content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -140,6 +146,9 @@
<if test="answer != null">
#{answer,jdbcType=VARCHAR},
</if>
<if test="topicContent != null">
#{topicContent,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.sztzjy.fund_investment.entity.TopicRecordExample" resultType="java.lang.Long">
@ -166,6 +175,9 @@
<if test="record.answer != null">
answer = #{record.answer,jdbcType=VARCHAR},
</if>
<if test="record.topicContent != null">
topic_content = #{record.topicContent,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -177,7 +189,8 @@
topic_id = #{record.topicId,jdbcType=VARCHAR},
flow_id = #{record.flowId,jdbcType=VARCHAR},
user_answer = #{record.userAnswer,jdbcType=VARCHAR},
answer = #{record.answer,jdbcType=VARCHAR}
answer = #{record.answer,jdbcType=VARCHAR},
topic_content = #{record.topicContent,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -197,6 +210,9 @@
<if test="answer != null">
answer = #{answer,jdbcType=VARCHAR},
</if>
<if test="topicContent != null">
topic_content = #{topicContent,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -205,7 +221,8 @@
set topic_id = #{topicId,jdbcType=VARCHAR},
flow_id = #{flowId,jdbcType=VARCHAR},
user_answer = #{userAnswer,jdbcType=VARCHAR},
answer = #{answer,jdbcType=VARCHAR}
answer = #{answer,jdbcType=VARCHAR},
topic_content = #{topicContent,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
Loading…
Cancel
Save