Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

finikes 2 жил өмнө
parent
commit
7713a1f033

+ 1 - 0
src/main/java/com/finikes/oc/vote/dao/VoteDao.java

@@ -12,4 +12,5 @@ public interface VoteDao extends BaseDao<Vote, Integer> {
 
     List<Vote> selectByVoteActivityId(@Param("voteActivityId") Integer voteActivityId);
 
+    int updateSelective(Vote entity);
 }

+ 0 - 13
src/main/java/com/finikes/oc/vote/dto/VoteUpdateDto.java

@@ -4,12 +4,8 @@ import javax.validation.constraints.*;
 import java.util.List;
 
 public class VoteUpdateDto {
-
     @NotNull
     private Integer id;
-
-    @NotNull
-    private Integer activityId;
     @NotBlank
     @Size(min = 1, max = 256)
     private String title;
@@ -23,7 +19,6 @@ public class VoteUpdateDto {
     public String toString() {
         return "VoteUpdateDto{" +
                 "id=" + id +
-                ", activityId=" + activityId +
                 ", title='" + title + '\'' +
                 ", content='" + content + '\'' +
                 ", options=" + options +
@@ -38,14 +33,6 @@ public class VoteUpdateDto {
         this.id = id;
     }
 
-    public Integer getActivityId() {
-        return activityId;
-    }
-
-    public void setActivityId(Integer activityId) {
-        this.activityId = activityId;
-    }
-
     public String getTitle() {
         return title;
     }

+ 6 - 6
src/main/java/com/finikes/oc/vote/service/VoteServiceImpl.java

@@ -135,17 +135,17 @@ public class VoteServiceImpl implements VoteService {
     @Transactional
     @Override
     public void updateVote(VoteUpdateDto dto) {
-        VoteActivity activity = voteActivityDao.selectByPrimaryKey(dto.getActivityId());
-        if (activity == null) {
-            throw new BusinessException("投票活动不存在");
-        }
-
         Vote vote = VoteMapper.INSTANCE.voteUpdateDtoToVote(dto);
-        int effectRow = voteDao.update(vote);
+        int effectRow = voteDao.updateSelective(vote);
         if (effectRow != 1) {
             throw new BusinessException("投票不存在");
         }
 
+        VoteActivity activity = voteActivityDao.selectByPrimaryKey(vote.getActivityId());
+        if (activity == null) {
+            throw new BusinessException("投票活动不存在");
+        }
+
         optionDao.deleteByVoteId(vote.getId());
 
         List<Option> options = dto.getOptions().stream()

+ 18 - 0
src/main/resources/mapper/VoteMapper.xml

@@ -12,6 +12,24 @@
         UPDATE t_vote SET activity_id = #{activityId}, sequence = #{sequence}, title = #{title}, content = #{content}
         WHERE id = #{id}
     </update>
+    <update id="updateSelective">
+        UPDATE t_vote
+        <set>
+            <if test="activityId != null">
+                activity_id = #{activityId},
+            </if>
+            <if test="sequence != null">
+                sequence = #{sequence},
+            </if>
+            <if test="title != null">
+                title = #{title},
+            </if>
+            <if test="content != null">
+                content = #{content},
+            </if>
+        </set>
+        WHERE id = #{id}
+    </update>
 
     <select id="selectByPrimaryKey" parameterType="integer" resultType="com.finikes.oc.vote.entity.Vote">
         SELECT id, activity_id, sequence, title, content