|
|
@@ -0,0 +1,45 @@
|
|
|
+package com.finikes.oc.vote.controller;
|
|
|
+
|
|
|
+import com.finikes.oc.BaseDTO;
|
|
|
+import com.finikes.oc.vote.dao.ChoiceDao;
|
|
|
+import com.finikes.oc.vote.dao.VoteDao;
|
|
|
+import com.finikes.oc.vote.dto.OptionSummary;
|
|
|
+import com.finikes.oc.vote.dto.VoteStatisticsResponseDTO;
|
|
|
+import com.finikes.oc.vote.entity.Vote;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+public class VoteStatisticsController {
|
|
|
+ @Autowired
|
|
|
+ private ChoiceDao choiceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VoteDao voteDao;
|
|
|
+
|
|
|
+ @GetMapping("/vote/statis")
|
|
|
+ public BaseDTO statistics(@RequestParam("voteId") String voteId) {
|
|
|
+ int _voteId = Integer.parseInt(voteId);
|
|
|
+ Vote vote = voteDao.selectByPrimaryKey(_voteId);
|
|
|
+ List<Integer> voteIds = new ArrayList<>();
|
|
|
+ voteIds.add(_voteId);
|
|
|
+ List<OptionSummary> sums = choiceDao.selectByVoteIds(voteIds);
|
|
|
+
|
|
|
+ VoteStatisticsResponseDTO dto = new VoteStatisticsResponseDTO();
|
|
|
+ dto.setContent(vote.getContent());
|
|
|
+ dto.setTitle(vote.getTitle());
|
|
|
+ for (OptionSummary sum : sums) {
|
|
|
+ VoteStatisticsResponseDTO.OptionPoll optionPoll = new VoteStatisticsResponseDTO.OptionPoll();
|
|
|
+ optionPoll.setPoll(String.valueOf(sum.getQuantity()));
|
|
|
+ optionPoll.setValue(sum.getValue());
|
|
|
+ dto.getOptions().add(optionPoll);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new BaseDTO().setContent(dto);
|
|
|
+ }
|
|
|
+}
|