Ver código fonte

finikes alpha 3 for yufei

finikes 2 anos atrás
pai
commit
9ab15a6364

+ 32 - 10
src/main/java/com/finikes/oc/vote/controller/VoteController.java

@@ -1,8 +1,10 @@
 package com.finikes.oc.vote.controller;
 
 import com.finikes.oc.vote.ApiResponse;
+import com.finikes.oc.vote.dao.VoteActivityDao;
 import com.finikes.oc.vote.dto.*;
 import com.finikes.oc.vote.service.VoteService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
@@ -17,6 +19,9 @@ public class VoteController {
 
     private final VoteService voteService;
 
+    @Autowired
+    private VoteActivityDao voteActivityDao;
+
     public VoteController(VoteService voteService) {
         this.voteService = voteService;
     }
@@ -27,7 +32,7 @@ public class VoteController {
      * @param dto 投票活动创建数据传输对象
      * @return 接口返回对象
      */
-    @PutMapping("vote_activity/")
+    @PutMapping("/vote_activity")
     public ApiResponse<Integer> createVoteActivity(@RequestBody @Valid VoteActivityCreateDto dto) {
         int voteActivityId = voteService.createVoteActivity(dto);
         return ApiResponse.successful(voteActivityId);
@@ -39,7 +44,7 @@ public class VoteController {
      * @param dto 投票活动创建数据传输对象
      * @return 接口返回对象
      */
-    @PostMapping("vote_activity/")
+    @PostMapping("/vote_activity")
     public ApiResponse<Integer> updateVoteActivity(@RequestBody @Valid VoteActivityUpdateDto dto) {
         voteService.updateVoteActivity(dto);
         return ApiResponse.successful();
@@ -55,8 +60,8 @@ public class VoteController {
      * @param endTime      结束时间
      * @return 接口返回对象
      */
-    @GetMapping("vote_activities/section/")
-    public ApiResponse<List<VoteActivityViewDto>> searchVoteActivity(
+    @GetMapping("/vote_activities/section")
+    public ApiResponse<VoteActivitiesSearchResponse> searchVoteActivity(
             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
             @RequestParam(value = "pageCapacity", defaultValue = "10") int pageCapacity,
             @RequestParam(value = "key", required = false) String key,
@@ -70,7 +75,24 @@ public class VoteController {
         dto.setEndTime(endTime);
 
         List<VoteActivityViewDto> list = voteService.searchVoteActivity(dto);
-        return ApiResponse.successful(list);
+
+        int count = 0;
+        if (dto.getStartTime() == null || dto.getEndTime() == null) {
+            count = voteActivityDao.countByTitleAndStartTimeAndEndTime(dto.getKey(),
+                    null, null);
+        } else {
+            count = voteActivityDao.countByTitleAndStartTimeAndEndTime(dto.getKey(),
+                    dto.getStartTime().getTime(), dto.getEndTime().getTime());
+        }
+
+        int pageQuantity = count / pageCapacity;
+        if (count % pageCapacity > 0) {
+            pageQuantity++;
+        }
+        VoteActivitiesSearchResponse response = new VoteActivitiesSearchResponse();
+        response.setPageQuantity(pageQuantity);
+        response.setVoteActivityViewDtos(list);
+        return ApiResponse.successful(response);
     }
 
     /**
@@ -79,7 +101,7 @@ public class VoteController {
      * @param dto 投票创建数据传输对象
      * @return 接口返回对象
      */
-    @PutMapping("vote/")
+    @PutMapping("/vote")
     public ApiResponse<Integer> createVote(@RequestBody @Valid VoteCreateDto dto) {
         int voteId = voteService.createVote(dto);
         return ApiResponse.successful(voteId);
@@ -91,7 +113,7 @@ public class VoteController {
      * @param dto 投票更新数据传输对象
      * @return 接口返回对象
      */
-    @PostMapping("vote/")
+    @PostMapping("/vote")
     public ApiResponse<Integer> createVote(@RequestBody @Valid VoteUpdateDto dto) {
         voteService.updateVote(dto);
         return ApiResponse.successful();
@@ -103,7 +125,7 @@ public class VoteController {
      * @param activityId 投票活动 ID
      * @return 接口返回对象
      */
-    @GetMapping("votes/")
+    @GetMapping("/votes")
     public ApiResponse<List<VoteViewDto>> searchVote(@RequestParam("activityId") Integer activityId) {
         List<VoteViewDto> votes = voteService.searchVotes(activityId);
         return ApiResponse.successful(votes);
@@ -115,7 +137,7 @@ public class VoteController {
      * @param dto 投票数据传输对象
      * @return 接口返回对象
      */
-    @PutMapping("choice/")
+    @PutMapping("/choice")
     public ApiResponse<Void> choice(@RequestBody @Valid ChoiceDto dto) {
         voteService.madeChoice(dto);
         return ApiResponse.successful();
@@ -127,7 +149,7 @@ public class VoteController {
      * @param dto 代理投票数据传输对象
      * @return 接口返回对象
      */
-    @PutMapping("choise/delegation")
+    @PutMapping("/choice/delegation")
     public ApiResponse<Void> choiceDelegation(@RequestBody @Valid ChoiceDelegationDto dto) {
         voteService.madeChoiceDelegation(dto);
         return ApiResponse.successful();

+ 4 - 1
src/main/java/com/finikes/oc/vote/dao/VoteActivityDao.java

@@ -11,6 +11,9 @@ public interface VoteActivityDao extends BaseDao<VoteActivity, Integer> {
 
     List<VoteActivity> selectByTitleAndStartTimeAndEndTime(@Param("title") String title,
                                                            @Param("startTime") Long startTime,
-                                                           @Param("endTime")  Long time);
+                                                           @Param("endTime") Long time);
 
+    int countByTitleAndStartTimeAndEndTime(@Param("title") String title,
+                                           @Param("startTime") Long startTime,
+                                           @Param("endTime") Long time);
 }

+ 24 - 0
src/main/java/com/finikes/oc/vote/dto/VoteActivitiesSearchResponse.java

@@ -0,0 +1,24 @@
+package com.finikes.oc.vote.dto;
+
+import java.util.List;
+
+public class VoteActivitiesSearchResponse {
+    private int pageQuantity;
+    private List<VoteActivityViewDto> voteActivityViewDtos;
+
+    public int getPageQuantity() {
+        return pageQuantity;
+    }
+
+    public void setPageQuantity(int pageQuantity) {
+        this.pageQuantity = pageQuantity;
+    }
+
+    public List<VoteActivityViewDto> getVoteActivityViewDtos() {
+        return voteActivityViewDtos;
+    }
+
+    public void setVoteActivityViewDtos(List<VoteActivityViewDto> voteActivityViewDtos) {
+        this.voteActivityViewDtos = voteActivityViewDtos;
+    }
+}

+ 11 - 0
src/main/resources/mapper/VoteActivityMapper.xml

@@ -39,4 +39,15 @@
         FROM t_vote_activity
         WHERE id = #{primaryKey}
     </delete>
+
+    <select id="countByTitleAndStartTimeAndEndTime" resultType="java.lang.Integer">
+        SELECT count(1)
+        FROM t_vote_activity WHERE 1 = 1
+        <if test="#{title != ''}">
+            AND title like CONCAT('%', #{title})
+        </if>
+        <if test="startTime != null and endTime != null">
+            AND start_time &gt;= #{startTime} AND start_time &lt;= #{endTime}
+        </if>
+    </select>
 </mapper>