|
|
@@ -1,11 +1,16 @@
|
|
|
package com.finikes.oc.vote.controller;
|
|
|
|
|
|
import com.finikes.oc.BaseDTO;
|
|
|
+import com.finikes.oc.estate.Houses;
|
|
|
+import com.finikes.oc.estate.entity.House;
|
|
|
import com.finikes.oc.vote.dao.ChoiceDao;
|
|
|
+import com.finikes.oc.vote.dao.VoteActivityDao;
|
|
|
import com.finikes.oc.vote.dao.VoteDao;
|
|
|
+import com.finikes.oc.vote.dto.HousesVoteStateDTO;
|
|
|
import com.finikes.oc.vote.dto.OptionSummary;
|
|
|
import com.finikes.oc.vote.dto.VoteStatisticsResponseDTO;
|
|
|
import com.finikes.oc.vote.entity.Vote;
|
|
|
+import com.finikes.oc.vote.entity.VoteActivity;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
@@ -22,6 +27,12 @@ public class VoteStatisticsController {
|
|
|
@Autowired
|
|
|
private VoteDao voteDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private VoteActivityDao voteActivityDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Houses houses;
|
|
|
+
|
|
|
@GetMapping("/vote/statis")
|
|
|
public BaseDTO statistics(@RequestParam("voteId") String voteId) {
|
|
|
int _voteId = Integer.parseInt(voteId);
|
|
|
@@ -42,4 +53,50 @@ public class VoteStatisticsController {
|
|
|
|
|
|
return new BaseDTO().setContent(dto);
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/vote/house/s/state")
|
|
|
+ public BaseDTO getHousesVoteState(@RequestParam("voteId") int voteId, @RequestParam("page") int page
|
|
|
+ , @RequestParam("pageCapacity") int pageCapacity, @RequestParam("state") int state) {
|
|
|
+ Vote vote = voteDao.selectByPrimaryKey(voteId);
|
|
|
+ VoteActivity voteActivity = voteActivityDao.selectByPrimaryKey(vote.getActivityId());
|
|
|
+ HousesVoteStateDTO dto = new HousesVoteStateDTO();
|
|
|
+ dto.setActivityTitle(voteActivity.getTitle());
|
|
|
+ dto.setVoteTitle(vote.getTitle());
|
|
|
+ if (state == 1) {
|
|
|
+ int total = voteDao.getHousesVoteNum(voteId);
|
|
|
+ int pageQuantity = total / pageCapacity;
|
|
|
+ if (total % pageCapacity > 0) {
|
|
|
+ pageQuantity++;
|
|
|
+ }
|
|
|
+ dto.setPageQuantity(String.valueOf(pageQuantity));
|
|
|
+ } else {
|
|
|
+ int total = voteDao.getHousesNotVoteNum(voteId);
|
|
|
+ int pageQuantity = total / pageCapacity;
|
|
|
+ if (total % pageCapacity > 0) {
|
|
|
+ pageQuantity++;
|
|
|
+ }
|
|
|
+ dto.setPageQuantity(String.valueOf(pageQuantity));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<House> houses = null;
|
|
|
+ int offset = (page - 1) * pageCapacity;
|
|
|
+ if (state == 1) {
|
|
|
+ houses = voteDao.getHousesVote(voteId, offset, pageCapacity);
|
|
|
+ } else {
|
|
|
+ houses = voteDao.getHousesNotVote(voteId, offset, pageCapacity);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (houses == null) {
|
|
|
+ houses = new ArrayList<>();// 避免空指针
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> houseNames = new ArrayList<>(houses.size());
|
|
|
+ for (House h : houses) {
|
|
|
+ // fixme 可以优化, 一次性在数据库取出多个房产的全名
|
|
|
+ houseNames.add(this.houses.getHouseFullName(h));
|
|
|
+ }
|
|
|
+ dto.setHouseNames(houseNames);
|
|
|
+
|
|
|
+ return new BaseDTO().setContent(dto);
|
|
|
+ }
|
|
|
}
|