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

Commit d570e0fb authored by jiangxiulong's avatar jiangxiulong

投票活动增加type

parent bbc0faea
......@@ -5,6 +5,7 @@ import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Component
@FeignClient(name = "liquidnet-service-sweet",
......@@ -14,6 +15,6 @@ import org.springframework.web.bind.annotation.GetMapping;
public interface FeignSweetTaskActivityClient {
@GetMapping("sweet/sweetCityVote/setStatList")
ResponseDto<Boolean> setStatList();
ResponseDto<Boolean> setStatList(@RequestParam("type") Integer type);
}
......@@ -2,6 +2,7 @@ package com.liquidnet.service.executor.main.handler;
import com.liquidnet.service.feign.sweet.task.FeignSweetTaskActivityClient;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -21,7 +22,9 @@ public class SweetCityVoteTaskHandler {
@XxlJob(value = "sev-sweet:cityVoteStat")
public ReturnT<String> cityVoteStatHandler() {
try {
Boolean data = feignSweetTaskActivityClient.setStatList().getData();
String jobParam = XxlJobHelper.getJobParam();//执行参数
log.info("jobParam = " + Integer.parseInt(jobParam));
Boolean data = feignSweetTaskActivityClient.setStatList(Integer.parseInt(jobParam)).getData();
log.info("cityVoteStatHandler:结果:{}", data);
ReturnT<String> success = ReturnT.SUCCESS;
success.setMsg(String.valueOf(data));
......
......@@ -490,6 +490,7 @@ CREATE TABLE `sweet_city_vote`
`phone` varchar(11) NOT NULL DEFAULT '' COMMENT '手机号',
`openId` varchar(255) NOT NULL DEFAULT '' COMMENT 'openId',
`unionId` varchar(255) NOT NULL DEFAULT '' COMMENT 'unionId',
`type` tinyint NOT NULL DEFAULT 1 COMMENT '活动类型 1新裤子 2莫宰羊',
`city_code` varchar(255) NOT NULL DEFAULT '' COMMENT '城市代码',
`city_name` varchar(255) NOT NULL DEFAULT '' COMMENT '城市名称',
`day_time` varchar(255) NOT NULL DEFAULT '' COMMENT '投票天',
......@@ -511,6 +512,7 @@ CREATE TABLE `sweet_city_vote_stat`
`city_name` varchar(255) NOT NULL DEFAULT '' COMMENT '城市名称',
`vote_num` int NOT NULL DEFAULT 0 COMMENT '真实投票数量',
`manual_vote_num` int NOT NULL DEFAULT 0 COMMENT '手动增加投票数量',
`type` tinyint NOT NULL DEFAULT 1 COMMENT '活动类型 1新裤子 2莫宰羊',
`created_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`mid`),
......
......@@ -26,7 +26,8 @@ public class SweetConstant {
public final static String REDIS_KEY_SWEET_ANSWER_PHONE="sweet:answer:phone:";
public final static String REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST="sweet:cityVote:StatList";
public final static String REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE="sweet:cityVote:cityCode:";
public final static String REDIS_KEY_SWEET_CITY_VOTE_USER="sweet:cityVote:user:";
public final static String REDIS_KEY_SWEET_CITY_VOTE="sweet:cityVote";
public final static String REDIS_KEY_SWEET_CITY_VOTE_USER=":user:";
public final static String REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME="sweet:cityVote:updateTime";
public final static String REDIS_KEY_SWEET_WECHAT_USER_INFO_MODERNSKY="sweet:wechatUser:modernsky:unionId:";
......
......@@ -35,13 +35,15 @@ public class SweetCityVoteController {
@ApiOperation("城市投票排名")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "phone", value = "手机号", required = true),
@ApiImplicitParam(type = "query", dataType = "String", name = "unionId", value = "unionId", required = true)
@ApiImplicitParam(type = "query", dataType = "String", name = "unionId", value = "unionId", required = true),
@ApiImplicitParam(type = "query", dataType = "Integer", name = "type", value = "活动类型 1新裤子 2莫宰羊", required = true)
})
public ResponseDto<List<SweetCItyVoteStatVo>> getList(
@RequestParam String phone,
@RequestParam String unionId
@RequestParam String unionId,
@RequestParam Integer type
) {
return sweetCityVoteService.getList(phone, unionId);
return sweetCityVoteService.getList(phone, unionId, type);
}
@PostMapping("createVote")
......@@ -52,8 +54,8 @@ public class SweetCityVoteController {
@GetMapping("setStatList")
@ApiOperation("统计投票排名")
public ResponseDto setStatList() {
return sweetCityVoteService.setStatList();
public ResponseDto setStatList(@RequestParam Integer type) {
return sweetCityVoteService.setStatList(type);
}
}
......@@ -27,6 +27,9 @@ public class SweetCityVoteStatDto implements Serializable ,Cloneable{
@ApiModelProperty("总投票数")
private Integer totalNum;
@ApiModelProperty("type")
private Integer type;
private static final SweetCityVoteStatDto obj = new SweetCityVoteStatDto();
public static SweetCityVoteStatDto getNew() {
......
......@@ -47,6 +47,11 @@ public class SweetCityVote implements Serializable {
@TableField("unionId")
private String unionId;
/**
* 活动类型 1新裤子 2莫宰羊
*/
private Integer type;
/**
* 城市代码
*/
......
......@@ -49,6 +49,11 @@ public class SweetCityVoteStat implements Serializable {
*/
private Integer manualVoteNum;
/**
* type
*/
private Integer type;
/**
* 创建时间
*/
......
......@@ -16,5 +16,5 @@ import java.util.List;
*/
public interface SweetCityVoteStatMapper extends BaseMapper<SweetCityVoteStat> {
List<SweetCityVoteStatDto> getStatList();
List<SweetCityVoteStatDto> getStatList(Integer type);
}
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel(value = "SweetCityVoteParam", description = "用户投票记录入参")
......@@ -29,4 +30,8 @@ public class SweetCityVoteParam implements Serializable {
@NotBlank(message = "cityName不能为空")
private String cityName;
@ApiModelProperty(position = 14, required = true, value = "活动类型 1新裤子 2莫宰羊", example = "1")
@NotNull(message = "type不能为空")
private Integer type;
}
......@@ -20,7 +20,7 @@ public interface ISweetCityVoteService extends IService<SweetCityVote> {
ResponseDto createVote(SweetCityVoteParam param);
ResponseDto setStatList();
ResponseDto setStatList(Integer type);
ResponseDto<List<SweetCItyVoteStatVo>> getList(String phone, String unionId);
ResponseDto<List<SweetCItyVoteStatVo>> getList(String phone, String unionId, Integer type);
}
......@@ -46,9 +46,9 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
private SweetCityVoteStatMapper sweetCityVoteStatMapper;
@Override
public ResponseDto getList(String phone, String unionId) {
List<SweetCItyVoteStatVo> sweetCityVoteStatList = redisDataUtils.getSweetCityVoteStatList();
SweetCityVoteParam userVote = redisDataUtils.getUserVote(phone, unionId);
public ResponseDto getList(String phone, String unionId, Integer type) {
List<SweetCItyVoteStatVo> sweetCityVoteStatList = redisDataUtils.getSweetCityVoteStatList(type);
SweetCityVoteParam userVote = redisDataUtils.getUserVote(phone, unionId, type);
if (!CollectionUtils.isEmpty(sweetCityVoteStatList)) {
for (SweetCItyVoteStatVo info : sweetCityVoteStatList) {
if (null == userVote) {
......@@ -64,14 +64,14 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
HashMap<String, Object> stringObjectHashMap = CollectionUtil.mapStringObject();
stringObjectHashMap.put("list", sweetCityVoteStatList);
stringObjectHashMap.put("userVote", userVote);
stringObjectHashMap.put("statUpdateTime", redisDataUtils.getSweetCityVoteStatUpdateTime());
stringObjectHashMap.put("statUpdateTime", redisDataUtils.getSweetCityVoteStatUpdateTime(type));
return ResponseDto.success(stringObjectHashMap);
}
@Override
public ResponseDto createVote(SweetCityVoteParam param) {
SweetCityVoteParam userVote = redisDataUtils.getUserVote(param.getPhone(), param.getUnionId());
SweetCityVoteParam userVote = redisDataUtils.getUserVote(param.getPhone(), param.getUnionId(), param.getType());
if (null != userVote) {
return ResponseDto.failure("已经投过票啦~");
}
......@@ -83,6 +83,7 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
aNew.setUnionId(param.getUnionId());
aNew.setCityCode(param.getCityCode());
aNew.setCityName(param.getCityName());
aNew.setType(param.getType());
LinkedList<String> sqls = CollectionUtil.linkedListString();
......@@ -90,38 +91,38 @@ public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, S
LinkedList<Object[]> sqlsDataB = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("sweet_city_vote.insert"));
sqlsDataA.add(new Object[]{
aNew.getVoteId(), aNew.getPhone(), sweetWechatOpenId, aNew.getUnionId(), aNew.getCityCode(), aNew.getCityName(), DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyyMMdd)
aNew.getVoteId(), aNew.getPhone(), sweetWechatOpenId, aNew.getUnionId(), aNew.getType(), aNew.getCityCode(), aNew.getCityName(), DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyyMMdd)
});
Integer cityVoteNum = redisDataUtils.getSweetCityVote(aNew.getCityCode());
Integer cityVoteNum = redisDataUtils.getSweetCityVote(aNew.getCityCode(), aNew.getType());
if (cityVoteNum > 0) { // 已有 incr
sqls.add(SqlMapping.get("sweet_city_vote_stat.update"));
sqlsDataB.add(new Object[]{
LocalDateTime.now(), aNew.getCityCode()
LocalDateTime.now(), aNew.getCityCode(), aNew.getType()
});
} else { // insert
sqls.add(SqlMapping.get("sweet_city_vote_stat.insert"));
sqlsDataB.add(new Object[]{
IDGenerator.nextSnowId(), aNew.getCityCode(), aNew.getCityName(), 1
IDGenerator.nextSnowId(), aNew.getCityCode(), aNew.getCityName(), 1, aNew.getType()
});
}
queueUtils.sendMsgByRedis(MQConst.SweetQueue.SWEET_CITY_VOTE_DRAW.getKey(),
SqlMapping.gets(sqls, sqlsDataA, sqlsDataB));
redisDataUtils.incrSweetCityVote(aNew.getCityCode());
redisDataUtils.incrSweetCityVote(aNew.getCityCode(), aNew.getType());
redisDataUtils.setUserVote(param.getPhone(), param.getUnionId(), param);
return ResponseDto.success();
}
public ResponseDto setStatList() {
List<SweetCityVoteStatDto> list = sweetCityVoteStatMapper.getStatList();
public ResponseDto setStatList(Integer type) {
List<SweetCityVoteStatDto> list = sweetCityVoteStatMapper.getStatList(type);
if (!CollectionUtils.isEmpty(list)) {
ArrayList<SweetCItyVoteStatVo> newList = ObjectUtil.getSweetCItyVoteStatVoList();
list.forEach(r -> newList.add(SweetCItyVoteStatVo.getNew().copy(r)));
redisDataUtils.setSweetCityVoteStatList(newList);
redisDataUtils.setSweetCityVoteStatList(newList, type);
}
redisDataUtils.setSweetCityVoteStatUpdateTime();
redisDataUtils.setSweetCityVoteStatUpdateTime(type);
return ResponseDto.success();
}
}
......@@ -492,12 +492,12 @@ public class RedisDataUtils {
}
// 投票
public void setSweetCityVoteStatList(List<SweetCItyVoteStatVo> sweetCItyVoteStatVo) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST;
public void setSweetCityVoteStatList(List<SweetCItyVoteStatVo> sweetCItyVoteStatVo, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST.concat(String.valueOf(type));
redisUtil.set(redisKey, sweetCItyVoteStatVo);
}
public List<SweetCItyVoteStatVo> getSweetCityVoteStatList() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST;
public List<SweetCItyVoteStatVo> getSweetCityVoteStatList(Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST.concat(String.valueOf(type));
Object obj = redisUtil.get(redisKey);
List<SweetCItyVoteStatVo> sweetCityVoteStatList = ObjectUtil.getSweetCItyVoteStatVoList();
if (null != obj) {
......@@ -505,12 +505,12 @@ public class RedisDataUtils {
}
return sweetCityVoteStatList;
}
public void incrSweetCityVote(String cityCode) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(cityCode);
public void incrSweetCityVote(String cityCode, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(String.valueOf(type)).concat(cityCode);
redisUtil.incr(redisKey, 1);
}
public Integer getSweetCityVote(String cityCode) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(cityCode);
public Integer getSweetCityVote(String cityCode, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(String.valueOf(type)).concat(cityCode);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return 0;
......@@ -519,11 +519,13 @@ public class RedisDataUtils {
}
}
public void setUserVote(String phone, String openId, SweetCityVoteParam param) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(openId);
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE.concat(String.valueOf(param.getType()))
.concat(SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER).concat(phone).concat("-").concat(openId);
redisUtil.set(redisKey, param);
}
public SweetCityVoteParam getUserVote(String phone, String openId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER.concat(phone).concat("-").concat(openId);
public SweetCityVoteParam getUserVote(String phone, String openId, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE.concat(String.valueOf(type))
.concat(SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_USER).concat(phone).concat("-").concat(openId);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return null;
......@@ -531,12 +533,12 @@ public class RedisDataUtils {
return (SweetCityVoteParam) obj;
}
}
public void setSweetCityVoteStatUpdateTime() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME;
public void setSweetCityVoteStatUpdateTime(Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME.concat(String.valueOf(type));
redisUtil.set(redisKey, DateUtil.getNowTime());
}
public String getSweetCityVoteStatUpdateTime() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME;
public String getSweetCityVoteStatUpdateTime(Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME.concat(String.valueOf(type));
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return "";
......
......@@ -37,6 +37,9 @@ public class SweetCItyVoteStatVo implements Serializable, Cloneable {
@ApiModelProperty("当前用户是否投了当前城市 1没投 2投了")
private Integer isVote;
@ApiModelProperty("type")
private Integer type;
/*@ApiModelProperty("创建时间")
private LocalDateTime createdAt;
......
......@@ -8,12 +8,18 @@
<result column="vote_num" property="voteNum"/>
<result column="manual_vote_num" property="manualVoteNum"/>
<result column="total_num" property="totalNum"/>
<result column="type" property="type"/>
</resultMap>
<select id="getStatList" resultMap="getListResult">
select
*, (vote_num + manual_vote_num) as total_num
from sweet_city_vote_stat
<where>
<if test="type != ''">
AND type=${type}
</if>
</where>
ORDER BY total_num DESC
</select>
</mapper>
......@@ -50,8 +50,8 @@ sweet_remind.insert=INSERT INTO sweet_remind (remind_id,openId,unionId,performan
# --------------------------小程序登录记录用户解密后信息--------------------------
sweet_applet_user.insert=INSERT INTO sweet_applet_user (user_id,openId,unionId,getPhoneNumber,getPurePhoneNumber,getCountryCode,type) VALUES (?,?,?,?,?,?,?)
# --------------------------用户投票记录--------------------------
sweet_city_vote.insert=INSERT INTO sweet_city_vote (vote_id,phone,openId,unionId,city_code,city_name,day_time) VALUES (?,?,?,?,?,?,?)
sweet_city_vote_stat.insert=INSERT INTO sweet_city_vote_stat (stat_id,city_code,city_name,vote_num) VALUES (?,?,?,?)
sweet_city_vote_stat.update=UPDATE sweet_city_vote_stat SET vote_num = IFNULL(vote_num, 0) + 1, updated_at = ? WHERE city_code = ?
sweet_city_vote.insert=INSERT INTO sweet_city_vote (vote_id,phone,openId,unionId,type,city_code,city_name,day_time) VALUES (?,?,?,?,?,?,?,?)
sweet_city_vote_stat.insert=INSERT INTO sweet_city_vote_stat (stat_id,city_code,city_name,vote_num,type) VALUES (?,?,?,?,?)
sweet_city_vote_stat.update=UPDATE sweet_city_vote_stat SET vote_num = IFNULL(vote_num, 0) + 1, updated_at = ? WHERE city_code = ? AND type = ?
# --------------------------防疫答题--------------------------
sweet_antigenic_question.insert=INSERT INTO sweet_antigenic_question (question_id,type,openId,unionId,nickname,address,phone,urgent_phone,keyword1,keyword11,keyword2,keyword3,keyword4,keyword5,keyword6,keyword7) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
\ No newline at end of file
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