记得上下班打卡 | git大法好,push需谨慎

Commit 17f7c342 authored by jiangxiulong's avatar jiangxiulong

isVote

parent c1f7c4a1
...@@ -6,6 +6,8 @@ import com.liquidnet.service.sweet.param.SweetCityVoteParam; ...@@ -6,6 +6,8 @@ import com.liquidnet.service.sweet.param.SweetCityVoteParam;
import com.liquidnet.service.sweet.service.ISweetCityVoteService; import com.liquidnet.service.sweet.service.ISweetCityVoteService;
import com.liquidnet.service.sweet.vo.SweetCItyVoteStatVo; import com.liquidnet.service.sweet.vo.SweetCItyVoteStatVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -31,8 +33,15 @@ public class SweetCityVoteController { ...@@ -31,8 +33,15 @@ public class SweetCityVoteController {
@GetMapping("statList") @GetMapping("statList")
@ApiOperation("城市投票排名") @ApiOperation("城市投票排名")
public ResponseDto<List<SweetCItyVoteStatVo>> getList() { @ApiImplicitParams({
return sweetCityVoteService.getList(); @ApiImplicitParam(type = "query", dataType = "String", name = "phone", value = "手机号", required = true),
@ApiImplicitParam(type = "query", dataType = "String", name = "unionId", value = "unionId", required = true)
})
public ResponseDto<List<SweetCItyVoteStatVo>> getList(
@RequestParam String phone,
@RequestParam String unionId
) {
return sweetCityVoteService.getList(phone, unionId);
} }
@PostMapping("createVote") @PostMapping("createVote")
......
...@@ -18,9 +18,9 @@ import java.util.List; ...@@ -18,9 +18,9 @@ import java.util.List;
*/ */
public interface ISweetCityVoteService extends IService<SweetCityVote> { public interface ISweetCityVoteService extends IService<SweetCityVote> {
ResponseDto<List<SweetCItyVoteStatVo>> getList();
ResponseDto createVote(SweetCityVoteParam param); ResponseDto createVote(SweetCityVoteParam param);
ResponseDto setStatList(); ResponseDto setStatList();
ResponseDto<List<SweetCItyVoteStatVo>> getList(String phone, String unionId);
} }
...@@ -52,15 +52,23 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S ...@@ -52,15 +52,23 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
private SweetCityVoteStatMapper sweetCityVoteStatMapper; private SweetCityVoteStatMapper sweetCityVoteStatMapper;
@Override @Override
public ResponseDto<List<SweetCItyVoteStatVo>> getList() { public ResponseDto<List<SweetCItyVoteStatVo>> getList(String phone, String unionId) {
List<SweetCItyVoteStatVo> sweetCityVoteStatList = redisDataUtils.getSweetCityVoteStatList(); List<SweetCItyVoteStatVo> sweetCityVoteStatList = redisDataUtils.getSweetCityVoteStatList();
String userVote = redisDataUtils.getUserVote(phone, unionId);
for (SweetCItyVoteStatVo info : sweetCityVoteStatList) {
if (userVote.isEmpty() || !userVote.equals(info.getCityCode())) {
info.setIsVote(1);
} else {
info.setIsVote(2);
}
}
return ResponseDto.success(sweetCityVoteStatList); return ResponseDto.success(sweetCityVoteStatList);
} }
@Override @Override
public ResponseDto createVote(SweetCityVoteParam param) { public ResponseDto createVote(SweetCityVoteParam param) {
Boolean userVote = redisDataUtils.getUserVote(param.getPhone(), param.getUnionId()); String userVote = redisDataUtils.getUserVote(param.getPhone(), param.getUnionId());
if (userVote) { if (!userVote.isEmpty()) {
return ResponseDto.failure("已经投过票啦~"); return ResponseDto.failure("已经投过票啦~");
} }
SweetCityVote aNew = SweetCityVote.getNew(); SweetCityVote aNew = SweetCityVote.getNew();
...@@ -95,7 +103,7 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S ...@@ -95,7 +103,7 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
redisDataUtils.incrSweetCityVote(aNew.getCityCode()); redisDataUtils.incrSweetCityVote(aNew.getCityCode());
redisDataUtils.setUserVote(param.getPhone(), param.getUnionId()); redisDataUtils.setUserVote(param.getPhone(), param.getUnionId(), param.getCityCode());
return ResponseDto.success(); return ResponseDto.success();
} }
......
...@@ -504,17 +504,17 @@ public class RedisDataUtils { ...@@ -504,17 +504,17 @@ public class RedisDataUtils {
return (Integer) obj; return (Integer) obj;
} }
} }
public void setUserVote(String phone, String unionId) { public void setUserVote(String phone, String unionId, String cityCode) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(unionId); String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(unionId);
redisUtil.set(redisKey, 1); redisUtil.set(redisKey, cityCode);
} }
public Boolean getUserVote(String phone, String unionId) { public String getUserVote(String phone, String unionId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(unionId); String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(unionId);
Object obj = redisUtil.get(redisKey); Object obj = redisUtil.get(redisKey);
if (null == obj) { if (null == obj) {
return false; return "";
} else { } else {
return true; return (String) obj;
} }
} }
} }
...@@ -34,6 +34,9 @@ public class SweetCItyVoteStatVo implements Serializable, Cloneable { ...@@ -34,6 +34,9 @@ public class SweetCItyVoteStatVo implements Serializable, Cloneable {
@ApiModelProperty("总投票数") @ApiModelProperty("总投票数")
private Integer totalNum; private Integer totalNum;
@ApiModelProperty("当前用户是否投了当前城市 1没投 2投了")
private Integer isVote;
/*@ApiModelProperty("创建时间") /*@ApiModelProperty("创建时间")
private LocalDateTime createdAt; private LocalDateTime createdAt;
......
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