Commit cc033ddf authored by Ryan Loong's avatar Ryan Loong

fix 点名次数增加失败的bug

parent 19b4f820
...@@ -125,8 +125,6 @@ ...@@ -125,8 +125,6 @@
<generatedKey column="id" sqlStatement="MySql" identity="true"/> <generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table> </table>
<table tableName="student_info"> <table tableName="student_info">
<!-- 配置需要进行增量操作的列名称(英文半角逗号分隔) -->
<property name="incrementColumns" value="call_times"/>
<generatedKey column="id" sqlStatement="MySql" identity="true"/> <generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table> </table>
</context> </context>
......
...@@ -3,8 +3,6 @@ package cn.exploring.engine.server.db.domain; ...@@ -3,8 +3,6 @@ package cn.exploring.engine.server.db.domain;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class StudentInfo { public class StudentInfo {
/** /**
...@@ -104,14 +102,6 @@ public class StudentInfo { ...@@ -104,14 +102,6 @@ public class StudentInfo {
*/ */
private Boolean deleted; private Boolean deleted;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table student_info
*
* @mbg.generated
*/
protected final Map<String, Object> incrementColumnsInfoMap = new HashMap<>();
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column student_info.id * This method returns the value of the database column student_info.id
...@@ -426,17 +416,6 @@ public class StudentInfo { ...@@ -426,17 +416,6 @@ public class StudentInfo {
return new StudentInfo.Builder(); return new StudentInfo.Builder();
} }
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student_info
*
* @mbg.generated
*/
public StudentInfo increment(Increment.Item increment) {
this.incrementColumnsInfoMap.put(increment.getColumn().value(), increment);
return this;
}
/** /**
* This class was generated by MyBatis Generator. * This class was generated by MyBatis Generator.
* This class corresponds to the database table student_info * This class corresponds to the database table student_info
...@@ -878,64 +857,4 @@ public class StudentInfo { ...@@ -878,64 +857,4 @@ public class StudentInfo {
return this.getEscapedColumnName(); return this.getEscapedColumnName();
} }
} }
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table student_info
*
* @mbg.generated
*/
public enum Increment {
callTimes(Column.callTimes);
private final Column column;
Increment(Column column) {
this.column = column;
}
public Column getColumn() {
return this.column;
}
public Increment.Item inc(Object value) {
return new Increment.Item(this.column, "+", value);
}
public Increment.Item dec(Object value) {
return new Increment.Item(this.column, "-", value);
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table student_info
*
* @mbg.generated
*/
class Item {
private Column column;
private String operate;
private Object value;
public Column getColumn() {
return this.column;
}
public String getOperate() {
return this.operate;
}
public Object getValue() {
return this.value;
}
public Item(Column column, String operate, Object value) {
this.column = column;
this.operate = operate;
this.value = value;
}
}
}
} }
\ No newline at end of file
...@@ -396,9 +396,15 @@ public class StudentInfoService { ...@@ -396,9 +396,15 @@ public class StudentInfoService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void increaseCallTimeByPrimaryKey(Integer id) { public void increaseCallTimeByPrimaryKey(Integer id) {
studentInfoMapper.updateByPrimaryKeySelective( StudentInfo studentInfo = selectByPrimaryKey(id);
StudentInfo.builder().id(id).updateTime(LocalDateTime.now()).build().increment(StudentInfo.Increment.callTimes.inc(1)), Integer callTimes = studentInfo.getCallTimes();
StudentInfo.Column.callTimes, StudentInfo.Column.updateTime studentInfo.setCallTimes(callTimes + 1);
); studentInfo.setUpdateTime(LocalDateTime.now());
int i = studentInfoMapper.updateByExampleSelective(studentInfo,
new StudentInfoExample().createCriteria().andDeletedEqualTo(StudentInfo.NOT_DELETED).andIdEqualTo(id).andCallTimesEqualTo(callTimes).example(),
StudentInfo.Column.updateTime, StudentInfo.Column.callTimes);
if (i <= 0) {
throw new RuntimeException("更新点名次数失败");
}
} }
} }
...@@ -318,17 +318,7 @@ ...@@ -318,17 +318,7 @@
<choose> <choose>
<when test="selective != null and selective.length &gt; 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
<choose> ${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
<when test="'call_times'.toString() == column.value and record.incrementColumnsInfoMap.call_times != null">
${column.escapedColumnName} = ${column.escapedColumnName} ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}
</when>
<when test="'call_times'.toString() == column.value">
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=INTEGER}
</when>
<otherwise>
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
</otherwise>
</choose>
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
...@@ -348,14 +338,9 @@ ...@@ -348,14 +338,9 @@
<if test="record.head != null"> <if test="record.head != null">
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
</if> </if>
<choose> <if test="record.callTimes != null">
<when test="record.incrementColumnsInfoMap.call_times != null"> call_times = #{record.callTimes,jdbcType=INTEGER},
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}, </if>
</when>
<when test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</when>
</choose>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -383,14 +368,7 @@ ...@@ -383,14 +368,7 @@
class_id = #{record.classId,jdbcType=INTEGER}, class_id = #{record.classId,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
<choose> call_times = #{record.callTimes,jdbcType=INTEGER},
<when test="record.incrementColumnsInfoMap.call_times != null">
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER},
</when>
<otherwise>
call_times = #{record.callTimes,jdbcType=INTEGER},
</otherwise>
</choose>
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT} deleted = #{record.deleted,jdbcType=BIT}
...@@ -408,17 +386,7 @@ ...@@ -408,17 +386,7 @@
<choose> <choose>
<when test="selective != null and selective.length &gt; 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
<choose> ${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
<when test="'call_times'.toString() == column.value and record.incrementColumnsInfoMap.call_times != null">
${column.escapedColumnName} = ${column.escapedColumnName} ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}
</when>
<when test="'call_times'.toString() == column.value">
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=INTEGER}
</when>
<otherwise>
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
</otherwise>
</choose>
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
...@@ -435,14 +403,9 @@ ...@@ -435,14 +403,9 @@
<if test="record.head != null"> <if test="record.head != null">
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
</if> </if>
<choose> <if test="record.callTimes != null">
<when test="record.incrementColumnsInfoMap.call_times != null"> call_times = #{record.callTimes,jdbcType=INTEGER},
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}, </if>
</when>
<when test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</when>
</choose>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -467,14 +430,7 @@ ...@@ -467,14 +430,7 @@
class_id = #{classId,jdbcType=INTEGER}, class_id = #{classId,jdbcType=INTEGER},
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
head = #{head,jdbcType=VARCHAR}, head = #{head,jdbcType=VARCHAR},
<choose> call_times = #{callTimes,jdbcType=INTEGER},
<when test="_parameter.incrementColumnsInfoMap.call_times != null">
call_times = call_times ${_parameter.incrementColumnsInfoMap.call_times.operate} #{_parameter.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER},
</when>
<otherwise>
call_times = #{callTimes,jdbcType=INTEGER},
</otherwise>
</choose>
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT} deleted = #{deleted,jdbcType=BIT}
...@@ -684,17 +640,7 @@ ...@@ -684,17 +640,7 @@
<choose> <choose>
<when test="selective != null and selective.length &gt; 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
<choose> ${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
<when test="'call_times'.toString() == column.value and record.incrementColumnsInfoMap.call_times != null">
${column.escapedColumnName} = ${column.escapedColumnName} ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}
</when>
<when test="'call_times'.toString() == column.value">
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=INTEGER}
</when>
<otherwise>
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
</otherwise>
</choose>
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
...@@ -714,14 +660,9 @@ ...@@ -714,14 +660,9 @@
<if test="record.head != null"> <if test="record.head != null">
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
</if> </if>
<choose> <if test="record.callTimes != null">
<when test="record.incrementColumnsInfoMap.call_times != null"> call_times = #{record.callTimes,jdbcType=INTEGER},
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}, </if>
</when>
<when test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</when>
</choose>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -745,17 +686,7 @@ ...@@ -745,17 +686,7 @@
<choose> <choose>
<when test="selective != null and selective.length &gt; 0"> <when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=","> <foreach collection="selective" item="column" separator=",">
<choose> ${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
<when test="'call_times'.toString() == column.value and record.incrementColumnsInfoMap.call_times != null">
${column.escapedColumnName} = ${column.escapedColumnName} ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}
</when>
<when test="'call_times'.toString() == column.value">
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=INTEGER}
</when>
<otherwise>
${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}
</otherwise>
</choose>
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
...@@ -775,14 +706,9 @@ ...@@ -775,14 +706,9 @@
<if test="record.head != null"> <if test="record.head != null">
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
</if> </if>
<choose> <if test="record.callTimes != null">
<when test="record.incrementColumnsInfoMap.call_times != null"> call_times = #{record.callTimes,jdbcType=INTEGER},
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER}, </if>
</when>
<when test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</when>
</choose>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -928,14 +854,7 @@ ...@@ -928,14 +854,7 @@
class_id = #{classId,jdbcType=INTEGER}, class_id = #{classId,jdbcType=INTEGER},
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
head = #{head,jdbcType=VARCHAR}, head = #{head,jdbcType=VARCHAR},
<choose> call_times = #{callTimes,jdbcType=INTEGER},
<when test="_parameter.incrementColumnsInfoMap.call_times != null">
call_times = call_times ${_parameter.incrementColumnsInfoMap.call_times.operate} #{_parameter.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER},
</when>
<when test="callTimes != null">
call_times = #{callTimes,jdbcType=INTEGER},
</when>
</choose>
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
...@@ -956,14 +875,7 @@ ...@@ -956,14 +875,7 @@
class_id = #{record.classId,jdbcType=INTEGER}, class_id = #{record.classId,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
<choose> call_times = #{record.callTimes,jdbcType=INTEGER},
<when test="record.incrementColumnsInfoMap.call_times != null">
call_times = call_times ${record.incrementColumnsInfoMap.call_times.operate} #{record.incrementColumnsInfoMap.call_times.value,jdbcType=INTEGER},
</when>
<when test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</when>
</choose>
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment