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

Commit 17f7c342 authored by jiangxiulong's avatar jiangxiulong

isVote

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