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

Commit 8cf4d3cd authored by jiangxiulong's avatar jiangxiulong

Merge remote-tracking branch 'origin/jxl_city_active' into pre

# Conflicts:
#	liquidnet-bus-common/liquidnet-common-service-base/src/main/java/com/liquidnet/service/base/constant/MQConst.java
#	liquidnet-bus-service/liquidnet-service-sweet/docu/redis_queue_create.txt
parents 97b0ec2d 3580e7ad
...@@ -83,6 +83,7 @@ public class MQConst { ...@@ -83,6 +83,7 @@ public class MQConst {
SWEET_REMIND_INSERT_DRAW("sweet:stream:rk.remindInsert", "group.remindInsert", "提醒记录"), SWEET_REMIND_INSERT_DRAW("sweet:stream:rk.remindInsert", "group.remindInsert", "提醒记录"),
SWEET_APPLET_USER_INSERT_DRAW("sweet:stream:rk.sweetAppletUserInsert", "group.sweetAppletUserInsert", "小程序登录记录用户解密后信息"), SWEET_APPLET_USER_INSERT_DRAW("sweet:stream:rk.sweetAppletUserInsert", "group.sweetAppletUserInsert", "小程序登录记录用户解密后信息"),
SWEET_TEMPLATE_MSG("sweet:stream:rk.sweetTemplateMsg", "group.sweetTemplateMsg", "发送模版消息"), SWEET_TEMPLATE_MSG("sweet:stream:rk.sweetTemplateMsg", "group.sweetTemplateMsg", "发送模版消息"),
SWEET_CITY_VOTE_DRAW("sweet:stream:rk.cityVote", "group.cityVote", "用户投票记录"),
; ;
private final String key; private final String key;
......
...@@ -5,12 +5,12 @@ import feign.hystrix.FallbackFactory; ...@@ -5,12 +5,12 @@ import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Component @Component
@FeignClient(name = "liquidnet-service-platform", @FeignClient(name = "liquidnet-service-platform",
contextId = "FeignPlatformAlipayBackClient", path = "", contextId = "FeignPlatformAlipayBackClient", path = "",
url = "", url = "${liquidnet.service.platform.url}",
// url = "",
fallback = FallbackFactory.Default.class) fallback = FallbackFactory.Default.class)
public interface FeignPlatformAlipayBackClient { public interface FeignPlatformAlipayBackClient {
......
package com.liquidnet.service.feign.sweet.task;
import com.liquidnet.service.base.ResponseDto;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
@Component
@FeignClient(name = "liquidnet-service-sweet",
contextId = "FeignSweetTaskActivityClient", path = "",
url = "${liquidnet.service.sweet.url}",
fallback = FallbackFactory.Default.class)
public interface FeignSweetTaskActivityClient {
@GetMapping("sweet/sweetCityVote/setStatList")
ResponseDto<Boolean> setStatList();
}
...@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping;
@Component @Component
@FeignClient(name = "liquidnet-service-sweet", @FeignClient(name = "liquidnet-service-sweet",
contextId = "FeignSweetWechatClient", path = "", contextId = "FeignSweetWechatClient", path = "",
url = "", url = "${liquidnet.service.sweet.url}",
fallback = FallbackFactory.Default.class) fallback = FallbackFactory.Default.class)
public interface FeignSweetWechatClient { public interface FeignSweetWechatClient {
......
package com.liquidnet.service.consumer.sweet.config;
import com.liquidnet.service.consumer.sweet.receiver.ConsumerCityVoteRdsReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.time.Duration;
import static com.liquidnet.service.base.constant.MQConst.SweetQueue.SWEET_CITY_VOTE_DRAW;
@Configuration
public class ConsumerCityVoteRedisStreamConfig {
@Autowired
ConsumerCityVoteRdsReceiver consumerCityVoteRdsReceiver;
private StreamMessageListenerContainer<String, MapRecord<String, String, String>> buildStreamMessageListenerContainer(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
return StreamMessageListenerContainer.create(factory, options);
}
/**
* 缺票登记
*
* @param listenerContainer
* @param t
* @return
*/
private Subscription receiveSqlCityVote(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
return listenerContainer.receiveAutoAck(
Consumer.from(SWEET_CITY_VOTE_DRAW.getGroup(), SWEET_CITY_VOTE_DRAW.name() + t),
StreamOffset.create(SWEET_CITY_VOTE_DRAW.getKey(), ReadOffset.lastConsumed()), consumerCityVoteRdsReceiver
);
}
/* —————————————————————————— | —————————————————————————— | —————————————————————————— */
/* -------------------------------------------------------- | 缺票登记 */
@Bean
public Subscription subscriptionSqlCityVote(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlCityVote(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlCityVote2(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlCityVote(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlCityVote3(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlCityVote(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
/* -------------------------------------------------------- | */
}
package com.liquidnet.service.consumer.sweet.receiver;
import com.liquidnet.service.base.constant.MQConst;
import org.springframework.stereotype.Component;
@Component
public class ConsumerCityVoteRdsReceiver extends AbstractSqlRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.SweetQueue.SWEET_CITY_VOTE_DRAW.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.SweetQueue.SWEET_CITY_VOTE_DRAW.getGroup();
}
}
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.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* sweet
*/
@Component
public class SweetCityVoteTaskHandler {
private static final Logger log = LoggerFactory.getLogger(SweetCityVoteTaskHandler.class);
@Autowired
private FeignSweetTaskActivityClient feignSweetTaskActivityClient;
@XxlJob(value = "sev-sweet:cityVoteStat")
public ReturnT<String> cityVoteStatHandler() {
try {
feignSweetTaskActivityClient.setStatList().getData();
log.info("cityVoteStatHandler:结果:success");
return ReturnT.SUCCESS;
} catch (Exception e) {
return ReturnT.FAIL;
}
}
}
package com.liquidnet.service.executor.main.handler; package com.liquidnet.service.executor.main.handler;
import com.liquidnet.service.feign.sweet.task.FeignSweetTaskActivityClient;
import com.liquidnet.service.feign.sweet.task.FeignSweetWechatClient; import com.liquidnet.service.feign.sweet.task.FeignSweetWechatClient;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
...@@ -18,6 +19,9 @@ public class SweetWechatTaskHandler { ...@@ -18,6 +19,9 @@ public class SweetWechatTaskHandler {
@Autowired @Autowired
private FeignSweetWechatClient feignSweetWechatClient; private FeignSweetWechatClient feignSweetWechatClient;
/*@Autowired
private FeignSweetTaskActivityClient feignSweetTaskActivityClient;*/
@XxlJob(value = "sev-sweet:sendMsg") @XxlJob(value = "sev-sweet:sendMsg")
public ReturnT<String> sendWechatMsgHandler() { public ReturnT<String> sendWechatMsgHandler() {
try { try {
...@@ -29,4 +33,15 @@ public class SweetWechatTaskHandler { ...@@ -29,4 +33,15 @@ public class SweetWechatTaskHandler {
} }
} }
/*@XxlJob(value = "sev-sweet:cityVoteStat")
public ReturnT<String> cityVoteStatHandler() {
try {
feignSweetTaskActivityClient.setStatList().getData();
log.info("cityVoteStatHandler:结果:success");
return ReturnT.SUCCESS;
} catch (Exception e) {
return ReturnT.FAIL;
}
}*/
} }
...@@ -480,6 +480,45 @@ CREATE TABLE `sweet_answer` ...@@ -480,6 +480,45 @@ CREATE TABLE `sweet_answer`
COLLATE utf8mb4_unicode_ci COLLATE utf8mb4_unicode_ci
ROW_FORMAT = DYNAMIC COMMENT '答题表'; ROW_FORMAT = DYNAMIC COMMENT '答题表';
-- 城市投票表
drop TABLE if exists `sweet_city_vote`;
CREATE TABLE `sweet_city_vote`
(
`mid` bigint unsigned NOT NULL AUTO_INCREMENT,
`vote_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'vote_id',
`phone` varchar(11) NOT NULL DEFAULT '' COMMENT '手机号',
`openId` varchar(255) NOT NULL DEFAULT '' COMMENT 'openId',
`unionId` varchar(255) NOT NULL DEFAULT '' COMMENT 'unionId',
`city_code` varchar(255) NOT NULL DEFAULT '' COMMENT '城市代码',
`city_name` varchar(255) NOT NULL DEFAULT '' COMMENT '城市名称',
`day_time` varchar(255) NOT NULL DEFAULT '' COMMENT '投票天',
`created_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`mid`),
KEY `sweet_city_vote_vote_id` (`vote_id`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci
ROW_FORMAT = DYNAMIC COMMENT '城市投票表';
drop TABLE if exists `sweet_city_vote_stat`;
CREATE TABLE `sweet_city_vote_stat`
(
`mid` bigint unsigned NOT NULL AUTO_INCREMENT,
`stat_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'stat_id',
`city_code` varchar(255) NOT NULL DEFAULT '' COMMENT '城市代码',
`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 '手动增加投票数量',
`created_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`mid`),
KEY `sweet_city_vote_stat_stat_id` (`stat_id`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci
ROW_FORMAT = DYNAMIC COMMENT '城市投票统计表';
-- 提醒记录 -- 提醒记录
drop TABLE if exists `sweet_remind`; drop TABLE if exists `sweet_remind`;
CREATE TABLE `sweet_remind` CREATE TABLE `sweet_remind`
......
...@@ -27,4 +27,8 @@ XGROUP CREATE sweet:stream:rk.sweetAppletUserInsert group.sweetAppletUserInsert ...@@ -27,4 +27,8 @@ XGROUP CREATE sweet:stream:rk.sweetAppletUserInsert group.sweetAppletUserInsert
-- 发送模版消息 -- -- 发送模版消息 --
XADD sweet:stream:rk.sweetTemplateMsg * 0 0 XADD sweet:stream:rk.sweetTemplateMsg * 0 0
XGROUP CREATE sweet:stream:rk.sweetTemplateMsg group.sweetTemplateMsg 0 XGROUP CREATE sweet:stream:rk.sweetTemplateMsg group.sweetTemplateMsg 0
\ No newline at end of file
-- 用户投票记录 --
XADD sweet:stream:rk.cityVote * 0 0
XGROUP CREATE sweet:stream:rk.cityVote group.cityVote 0
\ No newline at end of file
...@@ -24,6 +24,10 @@ public class SweetConstant { ...@@ -24,6 +24,10 @@ public class SweetConstant {
public final static String REDIS_KEY_SWEET_WECHAT_USER_INFO_STR="sweet:wechatUser:unionIdStr:"; public final static String REDIS_KEY_SWEET_WECHAT_USER_INFO_STR="sweet:wechatUser:unionIdStr:";
public final static String REDIS_KEY_SWEET_WECHAT_USER_UNIONID="sweet:wechatUser:openId:"; public final static String REDIS_KEY_SWEET_WECHAT_USER_UNIONID="sweet:wechatUser:openId:";
public final static String REDIS_KEY_SWEET_ANSWER_PHONE="sweet:answer:phone:"; 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_STAT_UPDATE_TIME="sweet:cityVote:updateTime";
// public enum ManualPosition { // public enum ManualPosition {
// artist("艺人","artist"), // artist("艺人","artist"),
......
package com.liquidnet.service.sweet.controller;
import com.liquidnet.service.base.ResponseDto;
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.*;
import javax.validation.Valid;
import java.util.List;
/**
* <p>
* 城市投票表 前端控制器
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
@Api(tags = "城市投票")
@RestController
@RequestMapping("/sweetCityVote")
public class SweetCityVoteController {
@Autowired
private ISweetCityVoteService sweetCityVoteService;
@GetMapping("statList")
@ApiOperation("城市投票排名")
@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")
@ApiOperation("用户投票记录")
public ResponseDto createVote(@Valid @RequestBody SweetCityVoteParam param) {
return sweetCityVoteService.createVote(param);
}
@GetMapping("setStatList")
@ApiOperation("统计投票排名")
public ResponseDto setStatList() {
return sweetCityVoteService.setStatList();
}
}
package com.liquidnet.service.sweet.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel
public class SweetCityVoteStatDto implements Serializable ,Cloneable{
private static final long serialVersionUID = -3159959399631688127L;
@ApiModelProperty("城市代码")
private String cityCode;
@ApiModelProperty("城市名称")
private String cityName;
@ApiModelProperty("真实投票数量")
private Integer voteNum;
@ApiModelProperty("手动增加投票数量")
private Integer manualVoteNum;
@ApiModelProperty("总投票数")
private Integer totalNum;
private static final SweetCityVoteStatDto obj = new SweetCityVoteStatDto();
public static SweetCityVoteStatDto getNew() {
try {
return (SweetCityVoteStatDto) obj.clone();
} catch (CloneNotSupportedException e) {
return new SweetCityVoteStatDto();
}
}
}
package com.liquidnet.service.sweet.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 城市投票表
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SweetCityVote implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "mid", type = IdType.AUTO)
private Long mid;
/**
* vote_id
*/
private String voteId;
/**
* 手机号
*/
private String phone;
/**
* openId
*/
@TableField("openId")
private String openId;
/**
* unionId
*/
@TableField("unionId")
private String unionId;
/**
* 城市代码
*/
private String cityCode;
/**
* 城市名称
*/
private String cityName;
/**
* 投票天
*/
private String dayTime;
/**
* 创建时间
*/
private LocalDateTime createdAt;
/**
* 更新时间
*/
private LocalDateTime updatedAt;
private static final SweetCityVote obj = new SweetCityVote();
public static SweetCityVote getNew() {
try {
return (SweetCityVote) obj.clone();
} catch (CloneNotSupportedException e) {
return new SweetCityVote();
}
}
}
package com.liquidnet.service.sweet.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 城市投票统计表
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SweetCityVoteStat implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "mid", type = IdType.AUTO)
private Long mid;
/**
* stat_id
*/
private String statId;
/**
* 城市代码
*/
private String cityCode;
/**
* 城市名称
*/
private String cityName;
/**
* 真实投票数量
*/
private Integer voteNum;
/**
* 手动增加投票数量
*/
private Integer manualVoteNum;
/**
* 创建时间
*/
private LocalDateTime createdAt;
/**
* 更新时间
*/
private LocalDateTime updatedAt;
}
package com.liquidnet.service.sweet.mapper;
import com.liquidnet.service.sweet.entity.SweetCityVote;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 城市投票表 Mapper 接口
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
public interface SweetCityVoteMapper extends BaseMapper<SweetCityVote> {
}
package com.liquidnet.service.sweet.mapper;
import com.liquidnet.service.sweet.dto.SweetCityVoteStatDto;
import com.liquidnet.service.sweet.entity.SweetCityVoteStat;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* <p>
* 城市投票统计表 Mapper 接口
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
public interface SweetCityVoteStatMapper extends BaseMapper<SweetCityVoteStat> {
List<SweetCityVoteStatDto> getStatList();
}
package com.liquidnet.service.sweet.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@ApiModel(value = "SweetCityVoteParam", description = "用户投票记录入参")
@Data
public class SweetCityVoteParam implements java.io.Serializable {
private static final long serialVersionUID = -2626425843975309892L;
@ApiModelProperty(position = 10, required = true, value = "手机号", example = "15811009011")
@NotBlank(message = "phone不能为空")
private String phone;
@ApiModelProperty(position = 11, required = true, value = "unionId", example = "unionId")
@NotBlank(message = "unionId不能为空")
private String unionId;
@ApiModelProperty(position = 12, required = true, value = "城市代码", example = "10001")
@NotBlank(message = "cityCode不能为空")
private String cityCode;
@ApiModelProperty(position = 13, required = true, value = "城市名称", example = "北京")
@NotBlank(message = "cityName不能为空")
private String cityName;
}
package com.liquidnet.service.sweet.service;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.entity.SweetCityVote;
import com.baomidou.mybatisplus.extension.service.IService;
import com.liquidnet.service.sweet.param.SweetCityVoteParam;
import com.liquidnet.service.sweet.vo.SweetCItyVoteStatVo;
import java.util.List;
/**
* <p>
* 城市投票表 服务类
* </p>
*
* @author jiangxiulong
* @since 2021-09-15
*/
public interface ISweetCityVoteService extends IService<SweetCityVote> {
ResponseDto createVote(SweetCityVoteParam param);
ResponseDto setStatList();
ResponseDto<List<SweetCItyVoteStatVo>> getList(String phone, String unionId);
}
package com.liquidnet.service.sweet.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.sweet.dto.SweetCityVoteStatDto;
import com.liquidnet.service.sweet.entity.SweetCityVote;
import com.liquidnet.service.sweet.mapper.SweetCityVoteMapper;
import com.liquidnet.service.sweet.mapper.SweetCityVoteStatMapper;
import com.liquidnet.service.sweet.param.SweetCityVoteParam;
import com.liquidnet.service.sweet.service.ISweetCityVoteService;
import com.liquidnet.service.sweet.utils.ObjectUtil;
import com.liquidnet.service.sweet.utils.QueueUtils;
import com.liquidnet.service.sweet.utils.RedisDataUtils;
import com.liquidnet.service.sweet.vo.SweetCItyVoteStatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
/**
* <p>
* 答题表 服务实现类
* </p>
*
* @author jiangxiulong
* @since 2021-08-12
*/
@Service
public class SweetCityVoteServiceImpl extends ServiceImpl<SweetCityVoteMapper, SweetCityVote> implements ISweetCityVoteService {
@Autowired
private RedisDataUtils redisDataUtils;
@Autowired
QueueUtils queueUtils;
@Autowired
private SweetCityVoteStatMapper sweetCityVoteStatMapper;
@Override
public ResponseDto getList(String phone, String unionId) {
List<SweetCItyVoteStatVo> sweetCityVoteStatList = redisDataUtils.getSweetCityVoteStatList();
SweetCityVoteParam userVote = redisDataUtils.getUserVote(phone, unionId);
if (!CollectionUtils.isEmpty(sweetCityVoteStatList)) {
for (SweetCItyVoteStatVo info : sweetCityVoteStatList) {
if (null == userVote) {
info.setIsVote(1);
} else if (userVote.getCityCode().equals(info.getCityCode())) {
info.setIsVote(2);
} else {
info.setIsVote(3);
}
}
}
HashMap<String, Object> stringObjectHashMap = CollectionUtil.mapStringObject();
stringObjectHashMap.put("list", sweetCityVoteStatList);
stringObjectHashMap.put("userVote", userVote);
stringObjectHashMap.put("statUpdateTime", redisDataUtils.getSweetCityVoteStatUpdateTime());
return ResponseDto.success(stringObjectHashMap);
}
@Override
public ResponseDto createVote(SweetCityVoteParam param) {
SweetCityVoteParam userVote = redisDataUtils.getUserVote(param.getPhone(), param.getUnionId());
if (null != userVote) {
return ResponseDto.failure("已经投过票啦~");
}
SweetCityVote aNew = SweetCityVote.getNew();
aNew.setVoteId(IDGenerator.nextSnowId());
aNew.setPhone(param.getPhone());
String sweetWechatOpenId = redisDataUtils.getSweetWechatOpenId(param.getUnionId());
aNew.setOpenId(sweetWechatOpenId);
aNew.setUnionId(param.getUnionId());
aNew.setCityCode(param.getCityCode());
aNew.setCityName(param.getCityName());
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlsDataA = CollectionUtil.linkedListObjectArr();
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)
});
Integer cityVoteNum = redisDataUtils.getSweetCityVote(aNew.getCityCode());
if (cityVoteNum > 0) { // 已有 incr
sqls.add(SqlMapping.get("sweet_city_vote_stat.update"));
sqlsDataB.add(new Object[]{
LocalDateTime.now(), aNew.getCityCode()
});
} else { // insert
sqls.add(SqlMapping.get("sweet_city_vote_stat.insert"));
sqlsDataB.add(new Object[]{
IDGenerator.nextSnowId(), aNew.getCityCode(), aNew.getCityName(), 1
});
}
queueUtils.sendMsgByRedis(MQConst.SweetQueue.SWEET_CITY_VOTE_DRAW.getKey(),
SqlMapping.gets(sqls, sqlsDataA, sqlsDataB));
redisDataUtils.incrSweetCityVote(aNew.getCityCode());
redisDataUtils.setUserVote(param.getPhone(), param.getUnionId(), param);
return ResponseDto.success();
}
public ResponseDto setStatList() {
List<SweetCityVoteStatDto> list = sweetCityVoteStatMapper.getStatList();
if (!CollectionUtils.isEmpty(list)) {
ArrayList<SweetCItyVoteStatVo> newList = ObjectUtil.getSweetCItyVoteStatVoList();
list.forEach(r -> newList.add(SweetCItyVoteStatVo.getNew().copy(r)));
redisDataUtils.setSweetCityVoteStatList(newList);
}
redisDataUtils.setSweetCityVoteStatUpdateTime();
return ResponseDto.success();
}
}
...@@ -7,8 +7,10 @@ import com.liquidnet.service.sweet.dto.SweetManualArtistListDto; ...@@ -7,8 +7,10 @@ import com.liquidnet.service.sweet.dto.SweetManualArtistListDto;
import com.liquidnet.service.sweet.dto.SweetManualArtistListMDSKDto; import com.liquidnet.service.sweet.dto.SweetManualArtistListMDSKDto;
import com.liquidnet.service.sweet.entity.SweetManualShop; import com.liquidnet.service.sweet.entity.SweetManualShop;
import com.liquidnet.service.sweet.entity.SweetManualShopMdsk; import com.liquidnet.service.sweet.entity.SweetManualShopMdsk;
import com.liquidnet.service.sweet.vo.SweetCItyVoteStatVo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class ObjectUtil { public class ObjectUtil {
private static final ArrayList<SweetManualAppletDto> sweetManualAppletDtoList = new ArrayList<>(); private static final ArrayList<SweetManualAppletDto> sweetManualAppletDtoList = new ArrayList<>();
...@@ -18,6 +20,7 @@ public class ObjectUtil { ...@@ -18,6 +20,7 @@ public class ObjectUtil {
private static final ArrayList<SweetManualAppletMDSKDto> sweetManualAppletMDSKDtoList = new ArrayList<>(); private static final ArrayList<SweetManualAppletMDSKDto> sweetManualAppletMDSKDtoList = new ArrayList<>();
private static final ArrayList<SweetManualArtistListMDSKDto> sweetManualArtistListMDSKDtoList = new ArrayList<>(); private static final ArrayList<SweetManualArtistListMDSKDto> sweetManualArtistListMDSKDtoList = new ArrayList<>();
private static final ArrayList<SweetManualShopMdsk> sweetManualShopMDSKList = new ArrayList<>(); private static final ArrayList<SweetManualShopMdsk> sweetManualShopMDSKList = new ArrayList<>();
private static final ArrayList<SweetCItyVoteStatVo> sweetCItyVoteStatVoList = new ArrayList<>();
public static ArrayList<SweetManualAppletDto> getSweetManualAppletDtoList() { public static ArrayList<SweetManualAppletDto> getSweetManualAppletDtoList() {
return (ArrayList<SweetManualAppletDto>)sweetManualAppletDtoList.clone(); return (ArrayList<SweetManualAppletDto>)sweetManualAppletDtoList.clone();
...@@ -43,4 +46,8 @@ public class ObjectUtil { ...@@ -43,4 +46,8 @@ public class ObjectUtil {
public static ArrayList<SweetManualShopMdsk> getSweetManualShopMdskList() { public static ArrayList<SweetManualShopMdsk> getSweetManualShopMdskList() {
return (ArrayList<SweetManualShopMdsk>)sweetManualShopMDSKList.clone(); return (ArrayList<SweetManualShopMdsk>)sweetManualShopMDSKList.clone();
} }
public static ArrayList<SweetCItyVoteStatVo> getSweetCItyVoteStatVoList() {
return (ArrayList<SweetCItyVoteStatVo>)sweetCItyVoteStatVoList.clone();
}
} }
...@@ -13,10 +13,8 @@ import com.liquidnet.service.sweet.dto.SweetManualArtistListDto; ...@@ -13,10 +13,8 @@ import com.liquidnet.service.sweet.dto.SweetManualArtistListDto;
import com.liquidnet.service.sweet.dto.SweetManualArtistStageListDto; import com.liquidnet.service.sweet.dto.SweetManualArtistStageListDto;
import com.liquidnet.service.sweet.entity.*; import com.liquidnet.service.sweet.entity.*;
import com.liquidnet.service.sweet.mapper.*; import com.liquidnet.service.sweet.mapper.*;
import com.liquidnet.service.sweet.vo.SweetAnswerVo; import com.liquidnet.service.sweet.param.SweetCityVoteParam;
import com.liquidnet.service.sweet.vo.SweetArtistsRelationVo; import com.liquidnet.service.sweet.vo.*;
import com.liquidnet.service.sweet.vo.SweetPrizeVo;
import com.liquidnet.service.sweet.vo.SweetRemindVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -24,9 +22,6 @@ import org.springframework.stereotype.Component; ...@@ -24,9 +22,6 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import static com.liquidnet.service.sweet.constant.SweetConstant.REDIS_KEY_SWEET_LUCK_DRAW_PRESENT_MOBILE;
import static com.liquidnet.service.sweet.constant.SweetConstant.REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS;
@Component @Component
@Slf4j @Slf4j
public class RedisDataUtils { public class RedisDataUtils {
...@@ -350,6 +345,19 @@ public class RedisDataUtils { ...@@ -350,6 +345,19 @@ public class RedisDataUtils {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USER_INFO.concat(unionid); String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USER_INFO.concat(unionid);
return (SweetWechatUser) redisUtil.get(redisKey); return (SweetWechatUser) redisUtil.get(redisKey);
} }
public String getSweetWechatOpenId(String unionid) {
if (unionid.isEmpty()) {
return "";
}
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USER_INFO.concat(unionid);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return "";
} else {
SweetWechatUser sweetWechatUser = (SweetWechatUser) redisUtil.get(redisKey);
return sweetWechatUser.getOpenId();
}
}
public String getSweetWechatUserStr(String unionid) { public String getSweetWechatUserStr(String unionid) {
if (unionid.isEmpty()) { if (unionid.isEmpty()) {
...@@ -477,10 +485,63 @@ public class RedisDataUtils { ...@@ -477,10 +485,63 @@ public class RedisDataUtils {
String redisKey = SweetConstant.REDIS_KEY_SWEET_ANSWER_PHONE.concat(sweetAnswerVo.getPhone()); String redisKey = SweetConstant.REDIS_KEY_SWEET_ANSWER_PHONE.concat(sweetAnswerVo.getPhone());
redisUtil.set(redisKey, sweetAnswerVo); redisUtil.set(redisKey, sweetAnswerVo);
} }
public SweetAnswerVo getSweetAnswer(String phone) { public SweetAnswerVo getSweetAnswer(String phone) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_ANSWER_PHONE.concat(phone); String redisKey = SweetConstant.REDIS_KEY_SWEET_ANSWER_PHONE.concat(phone);
SweetAnswerVo sweetAnswerVo = (SweetAnswerVo) redisUtil.get(redisKey); SweetAnswerVo sweetAnswerVo = (SweetAnswerVo) redisUtil.get(redisKey);
return sweetAnswerVo; return sweetAnswerVo;
} }
// 投票
public void setSweetCityVoteStatList(List<SweetCItyVoteStatVo> sweetCItyVoteStatVo) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST;
redisUtil.set(redisKey, sweetCItyVoteStatVo);
}
public List<SweetCItyVoteStatVo> getSweetCityVoteStatList() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_LIST;
Object obj = redisUtil.get(redisKey);
List<SweetCItyVoteStatVo> sweetCityVoteStatList = ObjectUtil.getSweetCItyVoteStatVoList();
if (null != obj) {
sweetCityVoteStatList = (List<SweetCItyVoteStatVo>) redisUtil.get(redisKey);
}
return sweetCityVoteStatList;
}
public void incrSweetCityVote(String cityCode) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(cityCode);
redisUtil.incr(redisKey, 1);
}
public Integer getSweetCityVote(String cityCode) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_CITY_CODE.concat(cityCode);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return 0;
} else {
return (Integer) obj;
}
}
public void setUserVote(String phone, String openId, SweetCityVoteParam param) {
String redisKey = 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);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return null;
} else {
return (SweetCityVoteParam) obj;
}
}
public void setSweetCityVoteStatUpdateTime() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME;
redisUtil.set(redisKey, DateUtil.getNowTime());
}
public String getSweetCityVoteStatUpdateTime() {
String redisKey = SweetConstant.REDIS_KEY_SWEET_CITY_VOTE_STAT_UPDATE_TIME;
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return "";
} else {
return (String) obj;
}
}
} }
package com.liquidnet.service.sweet.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.liquidnet.service.sweet.dto.SweetCityVoteStatDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public class SweetCItyVoteStatVo implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
/*@TableId(value = "mid", type = IdType.AUTO)
private Long mid;
@ApiModelProperty("vote_id")
private String statId;*/
@ApiModelProperty("城市代码")
private String cityCode;
@ApiModelProperty("城市名称")
private String cityName;
/*@ApiModelProperty("真实投票数量")
private Integer voteNum;
@ApiModelProperty("手动增加投票数量")
private Integer manualVoteNum;*/
@ApiModelProperty("总投票数")
private Integer totalNum;
@ApiModelProperty("当前用户是否投了当前城市 1没投 2投了")
private Integer isVote;
/*@ApiModelProperty("创建时间")
private LocalDateTime createdAt;
@ApiModelProperty("更新时间")
private LocalDateTime updatedAt;*/
private static final SweetCItyVoteStatVo obj = new SweetCItyVoteStatVo();
public static SweetCItyVoteStatVo getNew() {
try {
return (SweetCItyVoteStatVo) obj.clone();
} catch (CloneNotSupportedException e) {
return new SweetCItyVoteStatVo();
}
}
public SweetCItyVoteStatVo copy(SweetCityVoteStatDto source) {
if (null == this) return this;
this.setCityCode(source.getCityCode());
this.setCityName(source.getCityName());
// this.setVoteNum(source.getVoteNum());
// this.setManualVoteNum(source.getManualVoteNum());
this.setTotalNum(source.getTotalNum());
return this;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.liquidnet.service.sweet.mapper.SweetCityVoteStatMapper">
<resultMap id="getListResult" type="com.liquidnet.service.sweet.dto.SweetCityVoteStatDto">
<result column="city_code" property="cityCode"/>
<result column="city_name" property="cityName"/>
<result column="vote_num" property="voteNum"/>
<result column="manual_vote_num" property="manualVoteNum"/>
<result column="total_num" property="totalNum"/>
</resultMap>
<select id="getStatList" resultMap="getListResult">
select
*, (vote_num + manual_vote_num) as total_num
from sweet_city_vote_stat
ORDER BY total_num DESC
</select>
</mapper>
...@@ -48,4 +48,8 @@ sweet_user.update=UPDATE sweet_wechat_user SET is_cancel = ?, updated_at = ? WH ...@@ -48,4 +48,8 @@ sweet_user.update=UPDATE sweet_wechat_user SET is_cancel = ?, updated_at = ? WH
# --------------------------提醒记录-------------------------- # --------------------------提醒记录--------------------------
sweet_remind.insert=INSERT INTO sweet_remind (remind_id,openId,unionId,performancesId) VALUES (?,?,?,?) sweet_remind.insert=INSERT INTO sweet_remind (remind_id,openId,unionId,performancesId) VALUES (?,?,?,?)
# --------------------------小程序登录记录用户解密后信息-------------------------- # --------------------------小程序登录记录用户解密后信息--------------------------
sweet_applet_user.insert=INSERT INTO sweet_applet_user (user_id,openId,unionId,getPhoneNumber,getPurePhoneNumber,getCountryCode,type) VALUES (?,?,?,?,?,?,?) sweet_applet_user.insert=INSERT INTO sweet_applet_user (user_id,openId,unionId,getPhoneNumber,getPurePhoneNumber,getCountryCode,type) VALUES (?,?,?,?,?,?,?)
\ No newline at end of file # --------------------------用户投票记录--------------------------
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 = ?
\ 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