fix: persist teacher scores for score details
parent
06bae933f2
commit
40498fac1d
@ -0,0 +1,28 @@
|
|||||||
|
package com.sztzjy.linkCommerce.config;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/** Keeps existing deployments compatible with teacher-entered scores. */
|
||||||
|
@Component
|
||||||
|
public class TeachingClassTeacherScoreSchemaInitializer {
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public TeachingClassTeacherScoreSchemaInitializer(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void initialize() {
|
||||||
|
jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS teaching_class_teacher_score (" +
|
||||||
|
"teaching_class_id varchar(64) NOT NULL," +
|
||||||
|
"student_user_id varchar(64) NOT NULL," +
|
||||||
|
"teacher_score decimal(5,2) NOT NULL," +
|
||||||
|
"scored_by varchar(64) NOT NULL," +
|
||||||
|
"update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
|
||||||
|
"PRIMARY KEY (teaching_class_id, student_user_id)" +
|
||||||
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.sztzjy.linkCommerce.entity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class TeachingClassTeacherScore {
|
||||||
|
private String teachingClassId;
|
||||||
|
private String studentUserId;
|
||||||
|
private BigDecimal teacherScore;
|
||||||
|
private String scoredBy;
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
public String getTeachingClassId() { return teachingClassId; }
|
||||||
|
public void setTeachingClassId(String teachingClassId) { this.teachingClassId = teachingClassId; }
|
||||||
|
public String getStudentUserId() { return studentUserId; }
|
||||||
|
public void setStudentUserId(String studentUserId) { this.studentUserId = studentUserId; }
|
||||||
|
public BigDecimal getTeacherScore() { return teacherScore; }
|
||||||
|
public void setTeacherScore(BigDecimal teacherScore) { this.teacherScore = teacherScore; }
|
||||||
|
public String getScoredBy() { return scoredBy; }
|
||||||
|
public void setScoredBy(String scoredBy) { this.scoredBy = scoredBy; }
|
||||||
|
public Date getUpdateTime() { return updateTime; }
|
||||||
|
public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.sztzjy.linkCommerce.mapper;
|
||||||
|
|
||||||
|
import com.sztzjy.linkCommerce.entity.TeachingClassTeacherScore;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TeachingClassTeacherScoreMapper {
|
||||||
|
TeachingClassTeacherScore selectByClassAndStudent(@Param("teachingClassId") String teachingClassId,
|
||||||
|
@Param("studentUserId") String studentUserId);
|
||||||
|
int upsert(TeachingClassTeacherScore record);
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sztzjy.linkCommerce.mapper.TeachingClassTeacherScoreMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.sztzjy.linkCommerce.entity.TeachingClassTeacherScore">
|
||||||
|
<id column="teaching_class_id" property="teachingClassId" />
|
||||||
|
<id column="student_user_id" property="studentUserId" />
|
||||||
|
<result column="teacher_score" property="teacherScore" />
|
||||||
|
<result column="scored_by" property="scoredBy" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="selectByClassAndStudent" resultMap="BaseResultMap">
|
||||||
|
select teaching_class_id, student_user_id, teacher_score, scored_by, update_time
|
||||||
|
from teaching_class_teacher_score
|
||||||
|
where teaching_class_id = #{teachingClassId}
|
||||||
|
and student_user_id = #{studentUserId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="upsert" parameterType="com.sztzjy.linkCommerce.entity.TeachingClassTeacherScore">
|
||||||
|
insert into teaching_class_teacher_score
|
||||||
|
(teaching_class_id, student_user_id, teacher_score, scored_by, update_time)
|
||||||
|
values
|
||||||
|
(#{teachingClassId}, #{studentUserId}, #{teacherScore}, #{scoredBy}, current_timestamp)
|
||||||
|
on duplicate key update
|
||||||
|
teacher_score = values(teacher_score),
|
||||||
|
scored_by = values(scored_by),
|
||||||
|
update_time = current_timestamp
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue