Authored by ping

Merge branch 'userDay'

Showing 28 changed files with 1404 additions and 77 deletions
@@ -13,3 +13,4 @@ controller/target/ @@ -13,3 +13,4 @@ controller/target/
13 *.iml 13 *.iml
14 *.class 14 *.class
15 other/ 15 other/
  16 +target/
@@ -73,6 +73,29 @@ public class SendCouponHelper { @@ -73,6 +73,29 @@ public class SendCouponHelper {
73 return result; 73 return result;
74 } 74 }
75 75
  76 + /**
  77 + * 发送有货币
  78 + *
  79 + * @param uid
  80 + * @param num
  81 + * @return
  82 + */
  83 + public boolean sendYOHOBi(int uid, int num, int type) {
  84 + YohoCoinRecordReq req = buildYohoCoinCostReq(uid, num, type);
  85 + final String serviceName = "users.addRecord";
  86 + boolean result = false;
  87 + try {
  88 + log.info("BrandActivityServiceImpl sendYOHOBi req------ is {}", req);
  89 + CommonRspBO rspBO = serviceCaller.call(serviceName, req, CommonRspBO.class);
  90 + if (rspBO != null && rspBO.getCode() == 200) {
  91 + result = true;
  92 + }
  93 + } catch (Exception e) {
  94 + log.warn("in method sendYOHOBIEvent ,invoke {} occurs error,detail is {}", serviceName, e);
  95 + }
  96 + return result;
  97 + }
  98 +
76 // 构造参数 99 // 构造参数
77 private YohoCoinRecordReq buildYohoCoinCostReq(int uid, int num) { 100 private YohoCoinRecordReq buildYohoCoinCostReq(int uid, int num) {
78 YohoCoinRecordReq req = new YohoCoinRecordReq(); 101 YohoCoinRecordReq req = new YohoCoinRecordReq();
@@ -93,4 +116,26 @@ public class SendCouponHelper { @@ -93,4 +116,26 @@ public class SendCouponHelper {
93 req.setHistory(yohoCoinLogReqBO); 116 req.setHistory(yohoCoinLogReqBO);
94 return req; 117 return req;
95 } 118 }
  119 +
  120 + // 构造参数
  121 + private YohoCoinRecordReq buildYohoCoinCostReq(int uid, int num, int type) {
  122 + YohoCoinRecordReq req = new YohoCoinRecordReq();
  123 +
  124 + YohoCoinCostReqBO yohoCoinCostReq = new YohoCoinCostReqBO();
  125 + yohoCoinCostReq.setUid(uid);
  126 + yohoCoinCostReq.setNum(num);
  127 + yohoCoinCostReq.setType(Byte.valueOf(String.valueOf(type)));// 抽奖送币
  128 + yohoCoinCostReq.setParams("{}");
  129 + yohoCoinCostReq.setOrderCode("0");
  130 + req.setCost(yohoCoinCostReq);
  131 +
  132 + YohoCoinLogReqBO yohoCoinLogReqBO = new YohoCoinLogReqBO();
  133 + yohoCoinLogReqBO.setUid(uid);
  134 + yohoCoinLogReqBO.setChangeNum(Short.valueOf(String.valueOf(num)));
  135 + yohoCoinLogReqBO.setChangeType(Byte.valueOf(String.valueOf(type)));
  136 + yohoCoinLogReqBO.setChangeParams("{}");
  137 + req.setHistory(yohoCoinLogReqBO);
  138 + return req;
  139 + }
  140 +
96 } 141 }
@@ -16,7 +16,8 @@ public enum CacheKeyEnum { @@ -16,7 +16,8 @@ public enum CacheKeyEnum {
16 DRAWLINE_ACTIVITYBO("yh:act_activitybo:", "drawline.activitybo.redisSwitch", "drawline.activitybo.redisExpire", "限购排队活动信息(BO)"), 16 DRAWLINE_ACTIVITYBO("yh:act_activitybo:", "drawline.activitybo.redisSwitch", "drawline.activitybo.redisExpire", "限购排队活动信息(BO)"),
17 DRAWLINE_QUEUELIST("yh:act_queuelist:", "drawline.queuelist.redisSwitch", "drawline.queuelist.redisExpire", "活动排队列表"), 17 DRAWLINE_QUEUELIST("yh:act_queuelist:", "drawline.queuelist.redisSwitch", "drawline.queuelist.redisExpire", "活动排队列表"),
18 DRAWLINE_USERACTIVITY("yh:act_useractivity:", "drawline.useractivity.redisSwitch", "drawline.useractivity.redisExpire", "活动排队列表"), 18 DRAWLINE_USERACTIVITY("yh:act_useractivity:", "drawline.useractivity.redisSwitch", "drawline.useractivity.redisExpire", "活动排队列表"),
19 - DRAWLINE_LUCKYUSERLIST("yh:act_luckyuser:", "drawline.luckyuserlist.redisSwitch", "drawline.luckyuserlist.redisExpire", "中奖用户信息列表"); 19 + DRAWLINE_LUCKYUSERLIST("yh:act_luckyuser:", "drawline.luckyuserlist.redisSwitch", "drawline.luckyuserlist.redisExpire", "中奖用户信息列表"),
  20 + USERDAY_DRAWPRIZENUM("yh:act_userday:drawPrizeNum", "userday.drawPrizeNum.redisSwitch", "userday.drawPrizeNum.redisExpire", "会员日虚拟参与抽奖人数");
20 21
21 // 缓存的key 22 // 缓存的key
22 private String cacheKey; 23 private String cacheKey;
@@ -280,6 +280,32 @@ public class RedisValueCache { @@ -280,6 +280,32 @@ public class RedisValueCache {
280 } 280 }
281 } 281 }
282 282
  283 + /**
  284 + * 清除
  285 + *
  286 + * @param cacheEnum
  287 + * 缓存开关的枚举
  288 + * @param obj
  289 + * key的后缀
  290 + *
  291 + */
  292 + public Long increment(CacheKeyEnum cacheEnum, Object obj, long delta, long timeout, TimeUnit unit) {
  293 + logger.debug("Enter increment valueOperation redis value. cacheEnum is {}, obj is {}, delta is {}, timeout is {}, unit is {}", cacheEnum, obj, delta, timeout, unit);
  294 + try {
  295 + String cacheKey = CacheKeyHelper.getCacheKeyAndCheck(cacheEnum, obj);
  296 + // 如果获取的key为空,则说明缓存开关是关闭的
  297 + if (StringUtils.isEmpty(cacheKey)) {
  298 + return null;
  299 + }
  300 + Long result = yhValueOperations.increment(cacheKey, delta);
  301 + yHRedisTemplate.longExpire(cacheKey, timeout, unit);
  302 + return result;
  303 + } catch (Exception e) {
  304 + logger.warn("Redis exception. value redis increment . cacheEnum is {}, obj is {}, exception msg is {}", cacheEnum, obj, e.getMessage());
  305 + }
  306 + return null;
  307 + }
  308 +
283 public static void main(String[] args) { 309 public static void main(String[] args) {
284 String str = "12345"; 310 String str = "12345";
285 String jsonStr = JSON.toJSONString(str); 311 String jsonStr = JSON.toJSONString(str);
  1 +package com.yoho.activity.controller;
  2 +
  3 +import com.yoho.activity.common.ApiResponse;
  4 +import com.yoho.activity.service.IUserdayLeaveWordsService;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Controller;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.ResponseBody;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * 会员日,留言
  16 + */
  17 +@Controller
  18 +@RequestMapping("/UserdayLeaveWordsController")
  19 +public class UserdayLeaveWordsController {
  20 +
  21 + private static final Logger log = LoggerFactory.getLogger(UserdayLeaveWordsController.class);
  22 +
  23 + @Autowired
  24 + IUserdayLeaveWordsService userdayLeaveWordsService;
  25 +
  26 + /**
  27 + * 查询留言列表
  28 + *
  29 + * @param uid
  30 + * @return
  31 + * @throws Exception
  32 + */
  33 + @RequestMapping("/queryLeaveWordsList")
  34 + @ResponseBody
  35 + public ApiResponse queryLeaveWordsList(int uid) throws Exception {
  36 + log.debug("enter queryLeaveWordsList. param uid={}", uid);
  37 + List<String> contentList = userdayLeaveWordsService.queryLeaveWordsList(uid);
  38 + return new ApiResponse(contentList);
  39 + }
  40 +
  41 + /**
  42 + * 新增留言
  43 + *
  44 + * @param uid
  45 + * @return
  46 + * @throws Exception
  47 + */
  48 + @RequestMapping("/addLeaveWords")
  49 + @ResponseBody
  50 + public ApiResponse addLeaveWords(int uid, String nick_name, String content) throws Exception {
  51 + log.debug("enter addLeaveWords. param uid={}, nick_name={}, content={}", uid, nick_name, content);
  52 + int drawNum = userdayLeaveWordsService.addLeaveWords(uid, nick_name, content);
  53 + return new ApiResponse(drawNum);
  54 + }
  55 +
  56 +}
  1 +package com.yoho.activity.controller;
  2 +
  3 +import java.util.List;
  4 +
  5 +import org.apache.commons.collections.CollectionUtils;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Controller;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.ResponseBody;
  12 +
  13 +import com.yoho.activity.common.ApiResponse;
  14 +import com.yoho.activity.service.IUserdayPrizeLogService;
  15 +import com.yoho.service.model.activity.userday.response.UserdayPrizeLogResponseBO;
  16 +
  17 +/**
  18 + * 会员日,中奖纪录
  19 + */
  20 +@Controller
  21 +@RequestMapping("/UserdayPrizeLogController")
  22 +public class UserdayPrizeLogController {
  23 +
  24 + private static final Logger log = LoggerFactory.getLogger(UserdayPrizeLogController.class);
  25 +
  26 + @Autowired
  27 + IUserdayPrizeLogService userdayPrizeLogService;
  28 +
  29 + /**
  30 + * 用户抽奖
  31 + * @param uid
  32 + * @param prize_type
  33 + * @return
  34 + * @throws Exception
  35 + */
  36 + @RequestMapping("/addPrizeLog")
  37 + @ResponseBody
  38 + public ApiResponse addPrizeLog(int uid, int prize_type) throws Exception {
  39 + log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  40 + int result = userdayPrizeLogService.addPrizeLog(uid, prize_type);
  41 + return new ApiResponse(result);
  42 + }
  43 +
  44 + /**
  45 + * 查询是否抽过奖
  46 + * @param uid
  47 + * @param prize_type
  48 + * @return
  49 + * @throws Exception
  50 + */
  51 + @RequestMapping("/existsPrizeLog")
  52 + @ResponseBody
  53 + public ApiResponse existsPrizeLog(int uid, int prize_type) throws Exception {
  54 + log.info("enter existsPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  55 + boolean result = userdayPrizeLogService.existsPrizeLog(uid, prize_type);
  56 + return new ApiResponse(result);
  57 + }
  58 +
  59 + /**
  60 + * 查询中奖纪录
  61 + * @param uid
  62 + * @param prize_type
  63 + * @return
  64 + * @throws Exception
  65 + */
  66 + @RequestMapping("/queryPrizeLog")
  67 + @ResponseBody
  68 + public ApiResponse queryPrizeLog(int uid, int prize_type) throws Exception {
  69 + log.info("enter queryPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  70 + List<UserdayPrizeLogResponseBO> list = userdayPrizeLogService.queryPrizeLog(uid, prize_type);
  71 + if (CollectionUtils.isEmpty(list)) {
  72 + log.warn("queryPrizeLog error. result is empty");
  73 + }
  74 + return new ApiResponse(list);
  75 + }
  76 +
  77 + /**
  78 + * 查询参与抽奖人数
  79 + * @param prize_type
  80 + * @return
  81 + * @throws Exception
  82 + */
  83 + @RequestMapping("/queryPrizeLogNum")
  84 + @ResponseBody
  85 + public ApiResponse queryPrizeLogNum(int prize_type) throws Exception {
  86 + log.info("enter queryPrizeLogNum. param prize_type={}", prize_type);
  87 + int num = userdayPrizeLogService.queryPrizeLogNum(prize_type);
  88 + return new ApiResponse(num);
  89 + }
  90 +
  91 +}
  1 +package com.yoho.activity.controller;
  2 +
  3 +import com.yoho.activity.common.ApiResponse;
  4 +import com.yoho.activity.common.utils.DateUtils;
  5 +import com.yoho.activity.service.IUserdaySigninService;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.beans.factory.annotation.Value;
  10 +import org.springframework.stereotype.Controller;
  11 +import org.springframework.web.bind.annotation.RequestMapping;
  12 +import org.springframework.web.bind.annotation.ResponseBody;
  13 +
  14 +/**
  15 + * 会员日,签到
  16 + */
  17 +@Controller
  18 +@RequestMapping("/UserdaySigninController")
  19 +public class UserdaySigninController {
  20 +
  21 + private static final Logger log = LoggerFactory.getLogger(UserdaySigninController.class);
  22 +
  23 + @Autowired
  24 + IUserdaySigninService userdaySigninService;
  25 +
  26 + @Value("${userday.open.day}")
  27 + String userdayDay;
  28 +
  29 + @RequestMapping("/signin")
  30 + @ResponseBody
  31 + public ApiResponse signin(int uid) throws Exception {
  32 + log.info("enter signin. param uid={}", uid);
  33 + userdaySigninService.signin(uid);
  34 + return new ApiResponse("");
  35 + }
  36 +
  37 + @RequestMapping("/isUserday")
  38 + @ResponseBody
  39 + public ApiResponse isUserday() throws Exception {
  40 + log.info("enter isUserday.");
  41 + String day = DateUtils.getToday("dd");
  42 + return new ApiResponse(day.equals(userdayDay));
  43 + }
  44 +
  45 +}
  1 +package com.yoho.userday.dal;
  2 +
  3 +import com.yoho.userday.dal.model.UserdayLeaveWords;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface IUserdayLeaveWordsDAO {
  9 +
  10 + int deleteByPrimaryKey(Integer id);
  11 +
  12 + int insert(UserdayLeaveWords record);
  13 +
  14 + int insertSelective(UserdayLeaveWords record);
  15 +
  16 + UserdayLeaveWords selectByPrimaryKey(Integer id);
  17 +
  18 + int updateByPrimaryKeySelective(UserdayLeaveWords record);
  19 +
  20 + int updateByPrimaryKey(UserdayLeaveWords record);
  21 +
  22 + List<UserdayLeaveWords> selectLeaveWordsList(@Param("uid") int uid);
  23 +
  24 +}
  1 +package com.yoho.userday.dal;
  2 +
  3 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface IUserdayPrizeLogDAO {
  9 + int deleteByPrimaryKey(Integer id);
  10 +
  11 + int insert(UserdayPrizeLog record);
  12 +
  13 + int insertSelective(UserdayPrizeLog record);
  14 +
  15 + UserdayPrizeLog selectByPrimaryKey(Integer id);
  16 +
  17 + int updateByPrimaryKeySelective(UserdayPrizeLog record);
  18 +
  19 + int updateByPrimaryKey(UserdayPrizeLog record);
  20 +
  21 + UserdayPrizeLog selectByUidForLeaveWords(Integer uid);
  22 +
  23 + int insertLog(UserdayPrizeLog userdayPrizeLog);
  24 +
  25 + List<UserdayPrizeLog> selectByUidAndPrizeType(@Param("uid") int uid, @Param("prizeType") int prizeType);
  26 +
  27 + int selectNumByPrizeType(@Param("prizeType") int prize_type);
  28 +}
  1 +package com.yoho.userday.dal.model;
  2 +
  3 +import com.yoho.queue.dal.model.BaseModel;
  4 +
  5 +public class UserdayLeaveWords extends BaseModel {
  6 + /**
  7 + *
  8 + */
  9 + private static final long serialVersionUID = 942434561096687953L;
  10 +
  11 + private Integer id;
  12 +
  13 + private Integer uid;
  14 +
  15 + private String nickName;
  16 +
  17 + private String content;
  18 +
  19 + private Integer createTime;
  20 +
  21 + public UserdayLeaveWords() {
  22 + }
  23 +
  24 + public UserdayLeaveWords(Integer uid, String nickName, String content, Integer createTime) {
  25 + this.uid = uid;
  26 + this.nickName = nickName;
  27 + this.content = content;
  28 + this.createTime = createTime;
  29 + }
  30 +
  31 + public Integer getId() {
  32 + return id;
  33 + }
  34 +
  35 + public void setId(Integer id) {
  36 + this.id = id;
  37 + }
  38 +
  39 + public Integer getUid() {
  40 + return uid;
  41 + }
  42 +
  43 + public void setUid(Integer uid) {
  44 + this.uid = uid;
  45 + }
  46 +
  47 + public String getNickName() {
  48 + return nickName;
  49 + }
  50 +
  51 + public void setNickName(String nickName) {
  52 + this.nickName = nickName == null ? null : nickName.trim();
  53 + }
  54 +
  55 + public String getContent() {
  56 + return content;
  57 + }
  58 +
  59 + public void setContent(String content) {
  60 + this.content = content == null ? null : content.trim();
  61 + }
  62 +
  63 + public Integer getCreateTime() {
  64 + return createTime;
  65 + }
  66 +
  67 + public void setCreateTime(Integer createTime) {
  68 + this.createTime = createTime;
  69 + }
  70 +
  71 +}
  1 +package com.yoho.userday.dal.model;
  2 +
  3 +import com.yoho.queue.dal.model.BaseModel;
  4 +
  5 +public class UserdayPrizeLog extends BaseModel {
  6 + /**
  7 + *
  8 + */
  9 + private static final long serialVersionUID = 5461693433522015877L;
  10 +
  11 + private Integer id;
  12 +
  13 + private Integer uid;
  14 +
  15 + // 奖品类型:1-有货币,2-优惠券
  16 + private Integer prizeType;
  17 +
  18 + // 奖品值:prizeType为1时即有货币数量,为2时即优惠券id
  19 + private Integer prizeValue;
  20 +
  21 + private Integer winningDate;
  22 +
  23 + private Integer createTime;
  24 +
  25 + public UserdayPrizeLog() {
  26 + }
  27 +
  28 + public UserdayPrizeLog(Integer uid, Integer prizeType, Integer prizeValue, Integer createTime) {
  29 + this.uid = uid;
  30 + this.prizeType = prizeType;
  31 + this.prizeValue = prizeValue;
  32 + this.createTime = createTime;
  33 + }
  34 +
  35 + public Integer getId() {
  36 + return id;
  37 + }
  38 +
  39 + public void setId(Integer id) {
  40 + this.id = id;
  41 + }
  42 +
  43 + public Integer getUid() {
  44 + return uid;
  45 + }
  46 +
  47 + public void setUid(Integer uid) {
  48 + this.uid = uid;
  49 + }
  50 +
  51 + public Integer getPrizeType() {
  52 + return prizeType;
  53 + }
  54 +
  55 + public void setPrizeType(Integer prizeType) {
  56 + this.prizeType = prizeType;
  57 + }
  58 +
  59 + public Integer getPrizeValue() {
  60 + return prizeValue;
  61 + }
  62 +
  63 + public void setPrizeValue(Integer prizeValue) {
  64 + this.prizeValue = prizeValue;
  65 + }
  66 +
  67 + public Integer getWinningDate() {
  68 + return winningDate;
  69 + }
  70 +
  71 + public void setWinningDate(Integer winningDate) {
  72 + this.winningDate = winningDate;
  73 + }
  74 +
  75 + public Integer getCreateTime() {
  76 + return createTime;
  77 + }
  78 +
  79 + public void setCreateTime(Integer createTime) {
  80 + this.createTime = createTime;
  81 + }
  82 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  2 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.userday.dal.IUserdayLeaveWordsDAO">
  4 + <resultMap id="BaseResultMap" type="com.yoho.userday.dal.model.UserdayLeaveWords">
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="uid" property="uid" jdbcType="INTEGER" />
  7 + <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
  8 + <result column="content" property="content" jdbcType="VARCHAR" />
  9 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  10 + </resultMap>
  11 + <sql id="Base_Column_List">
  12 + id, uid, nick_name, content, create_time
  13 + </sql>
  14 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  15 + select
  16 + <include refid="Base_Column_List" />
  17 + from userday_leave_words
  18 + where id = #{id,jdbcType=INTEGER}
  19 + </select>
  20 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  21 + delete from userday_leave_words
  22 + where id = #{id,jdbcType=INTEGER}
  23 + </delete>
  24 + <insert id="insert" parameterType="com.yoho.userday.dal.model.UserdayLeaveWords">
  25 + insert into userday_leave_words (id, uid, nick_name,
  26 + content, create_time)
  27 + values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{nickName,jdbcType=VARCHAR},
  28 + #{content,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER})
  29 + </insert>
  30 + <insert id="insertSelective" parameterType="com.yoho.userday.dal.model.UserdayLeaveWords">
  31 + insert into userday_leave_words
  32 + <trim prefix="(" suffix=")" suffixOverrides=",">
  33 + <if test="id != null">
  34 + id,
  35 + </if>
  36 + <if test="uid != null">
  37 + uid,
  38 + </if>
  39 + <if test="nickName != null">
  40 + nick_name,
  41 + </if>
  42 + <if test="content != null">
  43 + content,
  44 + </if>
  45 + <if test="createTime != null">
  46 + create_time,
  47 + </if>
  48 + </trim>
  49 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  50 + <if test="id != null">
  51 + #{id,jdbcType=INTEGER},
  52 + </if>
  53 + <if test="uid != null">
  54 + #{uid,jdbcType=INTEGER},
  55 + </if>
  56 + <if test="nickName != null">
  57 + #{nickName,jdbcType=VARCHAR},
  58 + </if>
  59 + <if test="content != null">
  60 + #{content,jdbcType=VARCHAR},
  61 + </if>
  62 + <if test="createTime != null">
  63 + #{createTime,jdbcType=INTEGER},
  64 + </if>
  65 + </trim>
  66 + </insert>
  67 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.userday.dal.model.UserdayLeaveWords">
  68 + update userday_leave_words
  69 + <set>
  70 + <if test="uid != null">
  71 + uid = #{uid,jdbcType=INTEGER},
  72 + </if>
  73 + <if test="nickName != null">
  74 + nick_name = #{nickName,jdbcType=VARCHAR},
  75 + </if>
  76 + <if test="content != null">
  77 + content = #{content,jdbcType=VARCHAR},
  78 + </if>
  79 + <if test="createTime != null">
  80 + create_time = #{createTime,jdbcType=INTEGER},
  81 + </if>
  82 + </set>
  83 + where id = #{id,jdbcType=INTEGER}
  84 + </update>
  85 + <update id="updateByPrimaryKey" parameterType="com.yoho.userday.dal.model.UserdayLeaveWords">
  86 + update userday_leave_words
  87 + set uid = #{uid,jdbcType=INTEGER},
  88 + nick_name = #{nickName,jdbcType=VARCHAR},
  89 + content = #{content,jdbcType=VARCHAR},
  90 + create_time = #{createTime,jdbcType=INTEGER}
  91 + where id = #{id,jdbcType=INTEGER}
  92 + </update>
  93 +
  94 +
  95 + <select id="selectLeaveWordsList" resultMap="BaseResultMap">
  96 + select <include refid="Base_Column_List" /> from userday_leave_words where uid =#{uid} order by create_time desc
  97 + </select>
  98 +
  99 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  2 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.userday.dal.IUserdayPrizeLogDAO">
  4 + <resultMap id="BaseResultMap" type="com.yoho.userday.dal.model.UserdayPrizeLog">
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="uid" property="uid" jdbcType="INTEGER" />
  7 + <result column="prize_type" property="prizeType" jdbcType="INTEGER" />
  8 + <result column="prize_value" property="prizeValue" jdbcType="INTEGER" />
  9 + <result column="winning_date" property="winningDate" jdbcType="INTEGER" />
  10 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  11 + </resultMap>
  12 + <sql id="Base_Column_List">
  13 + id, uid, prize_type, prize_value, winning_date, create_time
  14 + </sql>
  15 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  16 + select
  17 + <include refid="Base_Column_List" />
  18 + from userday_prize_log
  19 + where id = #{id,jdbcType=INTEGER}
  20 + </select>
  21 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  22 + delete from userday_prize_log
  23 + where id = #{id,jdbcType=INTEGER}
  24 + </delete>
  25 + <insert id="insert" parameterType="com.yoho.userday.dal.model.UserdayPrizeLog">
  26 + insert into userday_prize_log (id, uid, prize_type,
  27 + prize_value, winning_date, create_time
  28 + )
  29 + values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{prizeType,jdbcType=INTEGER},
  30 + #{prizeValue,jdbcType=INTEGER}, #{winningDate,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}
  31 + )
  32 + </insert>
  33 + <insert id="insertSelective" parameterType="com.yoho.userday.dal.model.UserdayPrizeLog">
  34 + insert into userday_prize_log
  35 + <trim prefix="(" suffix=")" suffixOverrides=",">
  36 + <if test="id != null">
  37 + id,
  38 + </if>
  39 + <if test="uid != null">
  40 + uid,
  41 + </if>
  42 + <if test="prizeType != null">
  43 + prize_type,
  44 + </if>
  45 + <if test="prizeValue != null">
  46 + prize_value,
  47 + </if>
  48 + <if test="winningDate != null">
  49 + winning_date,
  50 + </if>
  51 + <if test="createTime != null">
  52 + create_time,
  53 + </if>
  54 + </trim>
  55 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  56 + <if test="id != null">
  57 + #{id,jdbcType=INTEGER},
  58 + </if>
  59 + <if test="uid != null">
  60 + #{uid,jdbcType=INTEGER},
  61 + </if>
  62 + <if test="prizeType != null">
  63 + #{prizeType,jdbcType=INTEGER},
  64 + </if>
  65 + <if test="prizeValue != null">
  66 + #{prizeValue,jdbcType=INTEGER},
  67 + </if>
  68 + <if test="winningDate != null">
  69 + #{winningDate,jdbcType=INTEGER},
  70 + </if>
  71 + <if test="createTime != null">
  72 + #{createTime,jdbcType=INTEGER},
  73 + </if>
  74 + </trim>
  75 + </insert>
  76 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.userday.dal.model.UserdayPrizeLog">
  77 + update userday_prize_log
  78 + <set>
  79 + <if test="uid != null">
  80 + uid = #{uid,jdbcType=INTEGER},
  81 + </if>
  82 + <if test="prizeType != null">
  83 + prize_type = #{prizeType,jdbcType=INTEGER},
  84 + </if>
  85 + <if test="prizeValue != null">
  86 + prize_value = #{prizeValue,jdbcType=INTEGER},
  87 + </if>
  88 + <if test="winningDate != null">
  89 + winning_date = #{winningDate,jdbcType=INTEGER},
  90 + </if>
  91 + <if test="createTime != null">
  92 + create_time = #{createTime,jdbcType=INTEGER},
  93 + </if>
  94 + </set>
  95 + where id = #{id,jdbcType=INTEGER}
  96 + </update>
  97 + <update id="updateByPrimaryKey" parameterType="com.yoho.userday.dal.model.UserdayPrizeLog">
  98 + update userday_prize_log
  99 + set uid = #{uid,jdbcType=INTEGER},
  100 + prize_type = #{prizeType,jdbcType=INTEGER},
  101 + prize_value = #{prizeValue,jdbcType=INTEGER},
  102 + winning_date = #{winningDate,jdbcType=INTEGER},
  103 + create_time = #{createTime,jdbcType=INTEGER}
  104 + where id = #{id,jdbcType=INTEGER}
  105 + </update>
  106 +
  107 + <select id="selectByUidForLeaveWords" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  108 + select
  109 + <include refid="Base_Column_List" />
  110 + from userday_prize_log
  111 + where uid = #{uid,jdbcType=INTEGER} and prize_type = 2 and winning_date = UNIX_TIMESTAMP(CURRENT_DATE()) limit 1
  112 + </select>
  113 + <select id="selectByUidAndPrizeType" resultMap="BaseResultMap">
  114 + select
  115 + <include refid="Base_Column_List" />
  116 + from userday_prize_log
  117 + where uid = #{uid,jdbcType=INTEGER} and prize_type = #{prizeType,jdbcType=INTEGER} and winning_date = UNIX_TIMESTAMP(CURRENT_DATE())
  118 + ORDER BY create_time DESC
  119 + </select>
  120 + <select id="selectNumByPrizeType" resultType="java.lang.Integer">
  121 + select IFNULL(COUNT(DISTINCT uid), 0) from userday_prize_log where prize_type = #{prizeType,jdbcType=INTEGER}
  122 + </select>
  123 +
  124 + <insert id="insertLog" parameterType="com.yoho.userday.dal.model.UserdayPrizeLog">
  125 + insert into userday_prize_log (uid, prize_type,
  126 + prize_value, winning_date, create_time
  127 + )
  128 + values (#{uid,jdbcType=INTEGER}, #{prizeType,jdbcType=INTEGER},
  129 + #{prizeValue,jdbcType=INTEGER}, UNIX_TIMESTAMP(CURRENT_DATE()), #{createTime,jdbcType=INTEGER}
  130 + )
  131 + </insert>
  132 +</mapper>
  1 +package com.yoho.activity.service;
  2 +
  3 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 会员日,抽奖
  9 + */
  10 +public interface IUserdayDrawPrizeService {
  11 +
  12 + int drawPrize(int uid) throws Exception;
  13 +
  14 + boolean existsPrizeLog(List<UserdayPrizeLog> userdayPrizeLogList);
  15 +}
  1 +package com.yoho.activity.service;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + * 会员日,留言
  7 + */
  8 +public interface IUserdayLeaveWordsService {
  9 +
  10 + List<String> queryLeaveWordsList(int uid) throws Exception;
  11 +
  12 + int addLeaveWords(int uid, String nick_name, String content) throws Exception;
  13 +}
  1 +package com.yoho.activity.service;
  2 +
  3 +import java.util.List;
  4 +
  5 +import com.yoho.service.model.activity.userday.response.UserdayPrizeLogResponseBO;
  6 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  7 +
  8 +/**
  9 + * 会员日,中奖记录
  10 + */
  11 +public interface IUserdayPrizeLogService {
  12 +
  13 + UserdayPrizeLog queryPrizeLogForLeaveWords(int uid) throws Exception;
  14 +
  15 + int addPrizeLog(int uid, int prize_type) throws Exception;
  16 +
  17 + boolean existsPrizeLog(int uid, int prize_type) throws Exception;
  18 +
  19 + /**
  20 + * 查询中奖纪录
  21 + * @param uid
  22 + * @param prize_type
  23 + * @return
  24 + * @throws Exception
  25 + */
  26 + List<UserdayPrizeLogResponseBO> queryPrizeLog(int uid, int prize_type) throws Exception;
  27 +
  28 + int queryPrizeLogNum(int prize_type);
  29 +}
  1 +package com.yoho.activity.service;
  2 +
  3 +/**
  4 + * 会员日,签到
  5 + */
  6 +public interface IUserdaySigninService {
  7 +
  8 + void signin(int uid) throws Exception;
  9 +
  10 +}
  1 +package com.yoho.activity.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.activity.common.helper.SendCouponHelper;
  5 +import com.yoho.activity.service.IUserdayDrawPrizeService;
  6 +import com.yoho.error.exception.ServiceException;
  7 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.beans.factory.annotation.Value;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import java.util.List;
  15 +import java.util.Random;
  16 +
  17 +/**
  18 + * 会员日,抽奖
  19 + */
  20 +@Service
  21 +public class UserdayDrawCouponServiceImpl implements IUserdayDrawPrizeService {
  22 +
  23 + private static final Logger log = LoggerFactory.getLogger(UserdayDrawCouponServiceImpl.class);
  24 +
  25 + @Autowired
  26 + private SendCouponHelper sendCouponHelper;
  27 +
  28 + @Value("${userday.coupon}")
  29 + private String prizeConpon;
  30 +
  31 + @Override
  32 + public int drawPrize(int uid) throws Exception {
  33 + log.info("enter drawPrize. param uid={}", uid);
  34 +
  35 + // (1)校验uid
  36 + if (1 > uid) {
  37 + throw new ServiceException(401, "参数不合法");
  38 + }
  39 +
  40 + // (2)根据中奖规则获取优惠券id
  41 + int couponId;
  42 + int random = new Random().nextInt(100);
  43 + if (994 < random) {
  44 + couponId = 20;
  45 + } else {
  46 + couponId = 10;
  47 + }
  48 + log.info("drawPrize: draw prize complete. uid={}, couponId={}, random={}", uid, couponId, random);
  49 +
  50 + // (3)发送优惠券
  51 + if (0 < couponId) {
  52 + JSONObject j = JSONObject.parseObject(prizeConpon);
  53 + sendCouponHelper.sendCoupon(j.getString(String.valueOf(couponId)), uid);
  54 + }
  55 +
  56 + // (4)返回
  57 + return couponId;
  58 +
  59 +
  60 + }
  61 +
  62 + @Override
  63 + public boolean existsPrizeLog(List<UserdayPrizeLog> userdayPrizeLogList) {
  64 + log.debug("enter existsPrizeLog.");
  65 +
  66 + // 返回
  67 + if (null != userdayPrizeLogList && 0 < userdayPrizeLogList.size()) {
  68 + return true;
  69 + }
  70 + return false;
  71 + }
  72 +
  73 +}
  1 +package com.yoho.activity.service.impl;
  2 +
  3 +import com.yoho.activity.common.helper.SendCouponHelper;
  4 +import com.yoho.activity.service.IUserdayDrawPrizeService;
  5 +import com.yoho.core.rest.client.ServiceCaller;
  6 +import com.yoho.error.exception.ServiceException;
  7 +import com.yoho.service.model.request.YohoCoinLogReqBO;
  8 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import javax.annotation.Resource;
  15 +import java.util.List;
  16 +import java.util.Random;
  17 +
  18 +/**
  19 + * 会员日,抽奖
  20 + */
  21 +@Service
  22 +public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService {
  23 +
  24 + private static final Logger log = LoggerFactory.getLogger(UserdayDrawYohoCoinServiceImpl.class);
  25 +
  26 + @Autowired
  27 + private SendCouponHelper sendCouponHelper;
  28 + @Resource
  29 + ServiceCaller serviceCaller;
  30 +
  31 + @Override
  32 + public int drawPrize(int uid) throws Exception {
  33 + log.info("enter drawPrize. param uid={}", uid);
  34 +
  35 + // (1)校验uid
  36 + if (1 > uid) {
  37 + throw new ServiceException(401, "参数不合法");
  38 + }
  39 +
  40 + // (2)判断有货币数量是否足够抽奖
  41 + YohoCoinLogReqBO yohoCoinLogReqBO = new YohoCoinLogReqBO();
  42 + yohoCoinLogReqBO.setUid(uid);
  43 + int num = serviceCaller.call("users.getYohoCoinNum", yohoCoinLogReqBO, Integer.class);
  44 + if (20 > num) {
  45 + throw new ServiceException(402, "有货币数量不足");
  46 + }
  47 +
  48 + // (3)消耗有货币用于抽奖
  49 + sendCouponHelper.sendYOHOBi(uid, -20, 12);
  50 +
  51 + // (4)根据中奖规则获取有货币数量
  52 + int yohoCoinNum = 0;
  53 + int random = new Random().nextInt(1000);
  54 + if (999 == random) {
  55 + yohoCoinNum = 1000;
  56 + } else if (993 < random) {
  57 + yohoCoinNum = 200;
  58 + } else if (983 < random) {
  59 + yohoCoinNum = 100;
  60 + } else if (883 < random) {
  61 + yohoCoinNum = 50;
  62 + } else if (483 < random) {
  63 + yohoCoinNum = 20;
  64 + }
  65 + log.info("drawPrize: draw prize complete. uid={}, yohoCoinNum={}, random={}", uid, yohoCoinNum, random);
  66 +
  67 + // (5)发送有货币
  68 + if (0 < yohoCoinNum) {
  69 + sendCouponHelper.sendYOHOBi(uid, yohoCoinNum, 6);
  70 + }
  71 +
  72 + // (6)返回
  73 + return yohoCoinNum;
  74 + }
  75 +
  76 + @Override
  77 + public boolean existsPrizeLog(List<UserdayPrizeLog> userdayPrizeLogList) {
  78 + log.debug("enter existsPrizeLog.");
  79 +
  80 + // (1)校验userdayPrizeLogList
  81 + if (null == userdayPrizeLogList || 0 == userdayPrizeLogList.size()) {
  82 + return false;
  83 + }
  84 +
  85 + // (2)循环列表判断是否中奖
  86 + for (UserdayPrizeLog userdayPrizeLog : userdayPrizeLogList) {
  87 + if (null == userdayPrizeLog || null == userdayPrizeLog.getPrizeValue()) {
  88 + continue;
  89 + }
  90 + if (0 < userdayPrizeLog.getPrizeValue()) {
  91 + return true;
  92 + }
  93 + }
  94 + return false;
  95 + }
  96 +
  97 +}
  1 +package com.yoho.activity.service.impl;
  2 +
  3 +import com.yoho.activity.service.IUserdayLeaveWordsService;
  4 +import com.yoho.activity.service.IUserdayPrizeLogService;
  5 +import com.yoho.core.common.utils.DateUtil;
  6 +import com.yoho.error.exception.ServiceException;
  7 +import com.yoho.userday.dal.IUserdayLeaveWordsDAO;
  8 +import com.yoho.userday.dal.model.UserdayLeaveWords;
  9 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  10 +import org.apache.commons.lang3.StringEscapeUtils;
  11 +import org.apache.commons.lang3.StringUtils;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * 会员日,留言
  22 + */
  23 +@Service
  24 +public class UserdayLeaveWordsServiceImpl implements IUserdayLeaveWordsService {
  25 +
  26 + private static final Logger log = LoggerFactory.getLogger(UserdayLeaveWordsServiceImpl.class);
  27 +
  28 + @Autowired
  29 + private IUserdayLeaveWordsDAO userdayLeaveWordsDAO;
  30 + @Autowired
  31 + private IUserdayPrizeLogService userdayPrizeLogService;
  32 +
  33 + @Override
  34 + public List<String> queryLeaveWordsList(int uid) throws Exception {
  35 + log.info("enter queryLeaveWordsList. param uid={}", uid);
  36 +
  37 + // (1)uid 校验
  38 + if (0 > uid) {
  39 + throw new ServiceException(401, "参数不合法");
  40 + }
  41 +
  42 + // (2)查询列表
  43 + //查询自己的留言
  44 + List<UserdayLeaveWords> userdayLeaveWordsList = userdayLeaveWordsDAO.selectLeaveWordsList(uid);
  45 + if (userdayLeaveWordsList == null) {
  46 + userdayLeaveWordsList = new ArrayList<>();
  47 + }
  48 + //查询公共留言
  49 + userdayLeaveWordsList.addAll(userdayLeaveWordsDAO.selectLeaveWordsList(0));
  50 +
  51 + // (3)组装数据并返回
  52 + List<String> result = new ArrayList<>();
  53 + for (UserdayLeaveWords userdayLeaveWords : userdayLeaveWordsList) {
  54 + if (null == userdayLeaveWords) {
  55 + continue;
  56 + }
  57 + result.add(new StringBuilder("用户").append(userdayLeaveWords.getNickName()).append(":").append(userdayLeaveWords.getContent()).toString());
  58 + }
  59 + return result;
  60 + }
  61 +
  62 + @Override
  63 + public int addLeaveWords(int uid, String nick_name, String content) throws Exception {
  64 + log.info("enter addLeaveWords. param uid={}, nick_name={}, content={}", uid, nick_name, content);
  65 +
  66 + // (1)参数校验:uid, nick_name, content
  67 + if (1 > uid || StringUtils.isBlank(nick_name) || StringUtils.isBlank(content)) {
  68 + throw new ServiceException(401, "参数不合法");
  69 + }
  70 +
  71 + // (2)nick_name模糊化
  72 + nick_name = blurNickName(nick_name);
  73 +
  74 + // (3)保存记录
  75 + UserdayLeaveWords userdayLeaveWords = new UserdayLeaveWords(uid, nick_name, StringEscapeUtils.escapeHtml4(content), DateUtil.currentTimeSeconds());
  76 + userdayLeaveWordsDAO.insertSelective(userdayLeaveWords);
  77 +
  78 + // (4)查询用户中奖记录,获取用户剩余中奖记录
  79 + UserdayPrizeLog userdayPrizeLog = userdayPrizeLogService.queryPrizeLogForLeaveWords(uid);
  80 + if (null == userdayPrizeLog) {
  81 + return 1;
  82 + } else {
  83 + return 0;
  84 + }
  85 + }
  86 +
  87 + private String blurNickName(String nick_name) {
  88 + if (StringUtils.isBlank(nick_name)) {
  89 + return nick_name;
  90 + }
  91 + if (nick_name.contains("*")) {
  92 + return nick_name;
  93 + }
  94 + if (nick_name.matches("\\d{11}")) {
  95 + return nick_name.substring(0, 3) + "****" + nick_name.substring(7);
  96 + }
  97 + if (2 == nick_name.length()) {
  98 + return nick_name.substring(0, 1) + "*";
  99 + }
  100 + if (3 == nick_name.length()) {
  101 + return nick_name.substring(0, 1) + "*" + nick_name.substring(2);
  102 + }
  103 + if (4 == nick_name.length()) {
  104 + return nick_name.substring(0, 1) + "**" + nick_name.substring(3);
  105 + }
  106 + if (4 < nick_name.length()) {
  107 + return nick_name.substring(0, 1) + "****" + nick_name.substring(nick_name.length() - 1);
  108 + }
  109 + return nick_name;
  110 + }
  111 +
  112 + public static void main(String[] args) {
  113 + UserdayLeaveWordsServiceImpl u = new UserdayLeaveWordsServiceImpl();
  114 + System.out.println(u.blurNickName(" "));
  115 + System.out.println(u.blurNickName("啊"));
  116 + System.out.println(u.blurNickName("保存"));
  117 + System.out.println(u.blurNickName("第二份"));
  118 + System.out.println(u.blurNickName("改时间看"));
  119 + System.out.println(u.blurNickName("里卖弄拍去"));
  120 + System.out.println(u.blurNickName("12365984521"));
  121 +
  122 + }
  123 +
  124 +}
  1 +package com.yoho.activity.service.impl;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.List;
  5 +import java.util.Map;
  6 +
  7 +import javax.annotation.Resource;
  8 +
  9 +import com.yoho.activity.common.redis.CacheKeyEnum;
  10 +import com.yoho.activity.common.redis.RedisValueCache;
  11 +import org.apache.commons.collections.CollectionUtils;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.BeanUtils;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.beans.factory.annotation.Value;
  17 +import org.springframework.stereotype.Service;
  18 +
  19 +import com.yoho.activity.common.utils.DateUtils;
  20 +import com.yoho.activity.service.IUserdayDrawPrizeService;
  21 +import com.yoho.activity.service.IUserdayPrizeLogService;
  22 +import com.yoho.core.common.utils.DateUtil;
  23 +import com.yoho.error.exception.ServiceException;
  24 +import com.yoho.service.model.activity.userday.response.UserdayPrizeLogResponseBO;
  25 +import com.yoho.userday.dal.IUserdayPrizeLogDAO;
  26 +import com.yoho.userday.dal.model.UserdayPrizeLog;
  27 +
  28 +/**
  29 + * 会员日,中奖记录
  30 + */
  31 +@Service
  32 +public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService {
  33 +
  34 + private static final Logger log = LoggerFactory.getLogger(UserdayPrizeLogServiceImpl.class);
  35 +
  36 + @Autowired
  37 + private IUserdayPrizeLogDAO userdayPrizeLogDAO;
  38 + @Resource(name = "userdayDrawPrizeService")
  39 + Map<Integer, IUserdayDrawPrizeService> userdayDrawPrizeServiceMap;
  40 + @Resource
  41 + RedisValueCache redisValueCache;
  42 +
  43 + @Value("${userday.open.day}")
  44 + String userdayOpenDay;
  45 +
  46 + @Override
  47 + public UserdayPrizeLog queryPrizeLogForLeaveWords(int uid) throws Exception {
  48 + log.info("enter queryPrizeLogForLeaveWords. param uid={}", uid);
  49 +
  50 + // (1)校验uid
  51 + if (1 > uid) {
  52 + throw new ServiceException(401, "参数不合法");
  53 + }
  54 +
  55 + return userdayPrizeLogDAO.selectByUidForLeaveWords(uid);
  56 + }
  57 +
  58 + @Override
  59 + public int addPrizeLog(int uid, int prize_type) throws Exception {
  60 + log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  61 +
  62 + // (1)校验uid, prize_type
  63 + if (1 > uid || 1 > prize_type) {
  64 + throw new ServiceException(401, "参数不合法");
  65 + }
  66 + IUserdayDrawPrizeService userdayDrawPrizeService = userdayDrawPrizeServiceMap.get(prize_type);
  67 + if (null == userdayDrawPrizeService) {
  68 + throw new ServiceException(401, "参数不合法");
  69 + }
  70 +
  71 + // (2)校验当天是否是会员日
  72 + String dateStr = DateUtil.getcurrentDate();
  73 + if (!userdayOpenDay.equals(dateStr.substring(8, 10))) {
  74 + throw new ServiceException(403, "非会员日,不允许抽奖");
  75 + }
  76 +
  77 + // (3)是否参加过疯狂大转盘
  78 + if (2 == prize_type) {
  79 + List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
  80 + if (null != userdayPrizeLogList && 0 < userdayPrizeLogList.size()) {
  81 + throw new ServiceException(406, "您今天已经参加过疯狂大转盘");
  82 + }
  83 + }
  84 +
  85 + // (4)获取奖品值
  86 + int prize_value = userdayDrawPrizeService.drawPrize(uid);
  87 +
  88 + // (5)保存抽奖日志
  89 + UserdayPrizeLog userdayPrizeLog = new UserdayPrizeLog(uid, prize_type, prize_value, DateUtil.currentTimeSeconds());
  90 + userdayPrizeLogDAO.insertLog(userdayPrizeLog);
  91 +
  92 + return prize_value;
  93 + }
  94 +
  95 + @Override
  96 + public boolean existsPrizeLog(int uid, int prize_type) throws Exception {
  97 + log.info("enter existsPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  98 +
  99 + // (1)校验uid, prize_type
  100 + if (1 > uid || 1 > prize_type) {
  101 + throw new ServiceException(401, "参数不合法");
  102 + }
  103 + IUserdayDrawPrizeService userdayDrawPrizeService = userdayDrawPrizeServiceMap.get(prize_type);
  104 + if (null == userdayDrawPrizeService) {
  105 + throw new ServiceException(401, "参数不合法");
  106 + }
  107 +
  108 + // (2)查询当天中奖日志
  109 + List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
  110 +
  111 + // (3)返回
  112 + return userdayDrawPrizeService.existsPrizeLog(userdayPrizeLogList);
  113 + }
  114 +
  115 + @Override
  116 + public List<UserdayPrizeLogResponseBO> queryPrizeLog(int uid, int prize_type) throws Exception {
  117 + log.info("enter queryPrizeLog. param uid={}, prize_type={}", uid, prize_type);
  118 +
  119 + // (1)校验uid, prize_type
  120 + if (1 > uid || 1 > prize_type) {
  121 + throw new ServiceException(401, "参数不合法");
  122 + }
  123 +
  124 + // (2)查询当天中奖日志
  125 + List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
  126 + if (CollectionUtils.isEmpty(userdayPrizeLogList)) {
  127 + return null;
  128 + }
  129 + List<UserdayPrizeLogResponseBO> list = new ArrayList<>(userdayPrizeLogList.size());
  130 + UserdayPrizeLogResponseBO bo = null;
  131 + for (UserdayPrizeLog dal : userdayPrizeLogList) {
  132 + bo = new UserdayPrizeLogResponseBO();
  133 + BeanUtils.copyProperties(dal, bo);
  134 + bo.setWinningTime(DateUtils.long2DateStr(((long) bo.getCreateTime()) * 1000, "HH:mm"));
  135 + list.add(bo);
  136 + }
  137 +
  138 + // (3)返回
  139 + return list;
  140 + }
  141 +
  142 + @Override
  143 + public int queryPrizeLogNum(int prize_type) {
  144 + log.info("enter queryPrizeLogNum. param prize_type={}", prize_type);
  145 + int realNum = userdayPrizeLogDAO.selectNumByPrizeType(prize_type);
  146 + Integer virtualNum = redisValueCache.get(CacheKeyEnum.USERDAY_DRAWPRIZENUM, "", Integer.class);
  147 + return realNum + (null == virtualNum ? 0 : virtualNum);
  148 + }
  149 +
  150 +}
  1 +package com.yoho.activity.service.impl;
  2 +
  3 +import com.yoho.activity.common.helper.SendCouponHelper;
  4 +import com.yoho.activity.service.IUserdaySigninService;
  5 +import com.yoho.core.common.utils.DateUtil;
  6 +import com.yoho.core.redis.YHValueOperations;
  7 +import com.yoho.error.exception.ServiceException;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.beans.factory.annotation.Value;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import javax.annotation.Resource;
  15 +import java.util.concurrent.TimeUnit;
  16 +
  17 +/**
  18 + * 会员日,签到
  19 + */
  20 +@Service
  21 +public class UserdaySigninServiceImpl implements IUserdaySigninService {
  22 +
  23 + private static final Logger log = LoggerFactory.getLogger(UserdaySigninServiceImpl.class);
  24 +
  25 + @Autowired
  26 + private SendCouponHelper sendCouponHelper;
  27 +
  28 + @Resource(name = "yhValueOperations")
  29 + YHValueOperations<String, String> yhValueOperations;
  30 +
  31 + @Value("${userday.open.day}")
  32 + String userdayOpenDay;
  33 +
  34 + @Override
  35 + public void signin(int uid) throws Exception {
  36 + log.info("enter signin. param uid={}", uid);
  37 +
  38 + // (1)校验uid
  39 + if (1 > uid) {
  40 + throw new ServiceException(401, "参数不合法");
  41 + }
  42 +
  43 + // (2)校验当天是否是会员日
  44 + String dateStr = DateUtil.getcurrentDate();
  45 + if (!userdayOpenDay.equals(dateStr.substring(8, 10))) {
  46 + throw new ServiceException(403, "非会员日,不允许签到");
  47 + }
  48 +
  49 + // (3)校验用户是否已经签到
  50 + String key = "yh:activity:userday:" + uid + "_" + dateStr;
  51 + String s = yhValueOperations.get(key);
  52 + if ("1".equals(s)) {
  53 + throw new ServiceException(405, "您已领取过");
  54 + }
  55 +
  56 + // (4)发送有货币,完成签到
  57 + sendCouponHelper.sendYOHOBi(uid, 100, 5);
  58 +
  59 + // (5)redis记录用户签到记录
  60 + yhValueOperations.set(key, "1", 31, TimeUnit.DAYS);
  61 + }
  62 +
  63 +}
  1 +package com.yoho.activity.service.timer;
  2 +
  3 +import com.yoho.activity.common.redis.CacheKeyEnum;
  4 +import com.yoho.activity.common.redis.RedisValueCache;
  5 +import com.yoho.core.common.utils.DateUtil;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Value;
  9 +import org.springframework.scheduling.annotation.Scheduled;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import javax.annotation.Resource;
  13 +import java.util.concurrent.TimeUnit;
  14 +
  15 +/**
  16 + * 会员日:每分钟增加抽奖人数定时任务
  17 + */
  18 +@Component
  19 +public class UserdayDrawPrizeNumTimer {
  20 +
  21 + private static final Logger log = LoggerFactory.getLogger(UserdayDrawPrizeNumTimer.class);
  22 +
  23 + @Resource
  24 + RedisValueCache redisValueCache;
  25 + @Value("${userday.open.day}")
  26 + String userdayOpenDay;
  27 +
  28 + @Scheduled(fixedDelay = 60 * 1000)
  29 + public void run() {
  30 + log.info("UserdayDrawPrizeNumTimer run.");
  31 +
  32 + // (1)校验当天是否是会员日
  33 + String dateStr = DateUtil.getcurrentDate();
  34 + if (!userdayOpenDay.equals(dateStr.substring(8, 10))) {
  35 + return;
  36 + }
  37 + redisValueCache.increment(CacheKeyEnum.USERDAY_DRAWPRIZENUM, "", 10, 2, TimeUnit.MINUTES);
  38 + }
  39 +
  40 +}
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" 2 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
3 - xsi:schemaLocation="http://www.springframework.org/schema/beans 3 + xsi:schemaLocation="http://www.springframework.org/schema/beans
4 http://www.springframework.org/schema/beans/spring-beans.xsd"> 4 http://www.springframework.org/schema/beans/spring-beans.xsd">
5 - <!-- secutity configs -->  
6 - <bean id="securityConfigMap" class="org.springframework.beans.factory.config.YamlMapFactoryBean">  
7 - <property name="resources">  
8 - <list>  
9 - <value>classpath:security-key.yml</value>  
10 - </list>  
11 - </property>  
12 - </bean> 5 + <!-- secutity configs -->
  6 + <bean id="securityConfigMap" class="org.springframework.beans.factory.config.YamlMapFactoryBean">
  7 + <property name="resources">
  8 + <list>
  9 + <value>classpath:security-key.yml</value>
  10 + </list>
  11 + </property>
  12 + </bean>
13 13
14 - <bean id="securityInterceptor" class="com.yoho.activity.common.interceptor.SecurityInterceptor">  
15 - <property name="keyConfigMap" ref="securityConfigMap" />  
16 - <property name="isDebugEnable" value="${is_debug_enable:true}" />  
17 - <property name="excludeUrls">  
18 - <list>  
19 - <value>/LuckyUserNoticeRest/noticeByActId/</value>  
20 - <value>/LuckyDrawHandlerRest/luckyDraw/</value>  
21 - <value>.+/CocacolaController/.+</value>  
22 - <value>.+/CouponActivityController/.+</value>  
23 - <value>.+/staticFileManage/.+</value>  
24 - <value>.+/TencentMktController/.+</value>  
25 - <value>.+/ActVoteResultController/.+</value>  
26 - <value>.+/favorite/.+</value>  
27 - <value>.+/brandDraw/.+</value>  
28 - </list>  
29 - </property>  
30 - <property name="excludeMethods">  
31 - <list>  
32 - <value>app.drawline.sendAwardToLuckyUser</value>  
33 - <value>app.drawline.executeAddWhiteUser</value>  
34 - <value>app.drawline.executeAddVirtualUser</value>  
35 - </list>  
36 - </property>  
37 - </bean> 14 + <bean id="securityInterceptor" class="com.yoho.activity.common.interceptor.SecurityInterceptor">
  15 + <property name="keyConfigMap" ref="securityConfigMap" />
  16 + <property name="isDebugEnable" value="${is_debug_enable:true}" />
  17 + <property name="excludeUrls">
  18 + <list>
  19 + <value>/LuckyUserNoticeRest/noticeByActId/</value>
  20 + <value>/LuckyDrawHandlerRest/luckyDraw/</value>
  21 + <value>.+/CocacolaController/.+</value>
  22 + <value>.+/CouponActivityController/.+</value>
  23 + <value>.+/staticFileManage/.+</value>
  24 + <value>.+/TencentMktController/.+</value>
  25 + <value>.+/ActVoteResultController/.+</value>
  26 + <value>.+/favorite/.+</value>
  27 + <value>.+/brandDraw/.+</value>
  28 + </list>
  29 + </property>
  30 + <property name="excludeMethods">
  31 + <list>
  32 + <value>app.drawline.sendAwardToLuckyUser</value>
  33 + <value>app.drawline.executeAddWhiteUser</value>
  34 + <value>app.drawline.executeAddVirtualUser</value>
  35 + </list>
  36 + </property>
  37 + </bean>
38 </beans> 38 </beans>
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 -<beans xmlns="http://www.springframework.org/schema/beans"  
3 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
4 - xmlns:context="http://www.springframework.org/schema/context"  
5 - xmlns:mvc="http://www.springframework.org/schema/mvc"  
6 - xsi:schemaLocation="http://www.springframework.org/schema/beans 2 +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
  4 + xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
  5 + xsi:schemaLocation="http://www.springframework.org/schema/beans
7 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 6 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
8 http://www.springframework.org/schema/context 7 http://www.springframework.org/schema/context
9 http://www.springframework.org/schema/context/spring-context-3.1.xsd 8 http://www.springframework.org/schema/context/spring-context-3.1.xsd
@@ -12,44 +11,46 @@ @@ -12,44 +11,46 @@
12 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc
13 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 12 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
14 13
15 -  
16 - <context:component-scan base-package="com.yoho" />  
17 14
18 - <mvc:annotation-driven />  
19 - <!-- 装在properties文件 -->  
20 - <context:property-placeholder location="classpath*:config.properties,classpath*:zookeeper.properties" /> 15 + <context:component-scan base-package="com.yoho" />
  16 +
  17 + <mvc:annotation-driven />
  18 + <!-- 装在properties文件 -->
  19 + <context:property-placeholder location="classpath*:config.properties" />
21 <!-- <bean id="restServiceBeanRegistry" class="com.yoho.core.rest.spring.RestServiceBeanRegistry"> 20 <!-- <bean id="restServiceBeanRegistry" class="com.yoho.core.rest.spring.RestServiceBeanRegistry">
22 <property name="registry" ref="serviceRegistry"></property> 21 <property name="registry" ref="serviceRegistry"></property>
23 </bean> --> 22 </bean> -->
24 - <bean id="serviceGlobalExceptionHandler" class="com.yoho.error.exception.handler.ServiceGlobalExceptionHandler"/>  
25 -  
26 - <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->  
27 - <bean  
28 - class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
29 - <property name="messageConverters">  
30 - <list>  
31 - <ref bean="stringConverter" />  
32 - <ref bean="jsonConverter" />  
33 - </list>  
34 - </property>  
35 - </bean>  
36 -  
37 - <bean id="stringConverter"  
38 - class="org.springframework.http.converter.StringHttpMessageConverter">  
39 - <property name="supportedMediaTypes">  
40 - <list>  
41 - <value>text/plain;charset=UTF-8</value>  
42 - </list>  
43 - </property>  
44 - </bean>  
45 -  
46 - <!-- 输出对象转JSON支持 -->  
47 - <bean id="jsonConverter"  
48 - class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
49 - </bean>  
50 -  
51 - <mvc:interceptors>  
52 - <ref bean="securityInterceptor" />  
53 - <ref bean="threadProfileInterceptor"/>  
54 - </mvc:interceptors> 23 + <bean id="serviceGlobalExceptionHandler" class="com.yoho.error.exception.handler.ServiceGlobalExceptionHandler" />
  24 +
  25 + <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
  26 + <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  27 + <property name="messageConverters">
  28 + <list>
  29 + <ref bean="stringConverter" />
  30 + <ref bean="jsonConverter" />
  31 + </list>
  32 + </property>
  33 + </bean>
  34 +
  35 + <bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
  36 + <property name="supportedMediaTypes">
  37 + <list>
  38 + <value>text/plain;charset=UTF-8</value>
  39 + </list>
  40 + </property>
  41 + </bean>
  42 +
  43 + <!-- 输出对象转JSON支持 -->
  44 + <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"></bean>
  45 +
  46 + <util:map id="userdayDrawPrizeService" key-type="java.lang.Integer"
  47 + value-type="com.yoho.activity.service.IUserdayDrawPrizeService">
  48 + <entry key="1" value-ref="userdayDrawYohoCoinServiceImpl"></entry>
  49 + <entry key="2" value-ref="userdayDrawCouponServiceImpl"></entry>
  50 + </util:map>
  51 +
  52 + <mvc:interceptors>
  53 + <ref bean="securityInterceptor" />
  54 + <ref bean="threadProfileInterceptor" />
  55 + </mvc:interceptors>
55 </beans> 56 </beans>
@@ -26,7 +26,7 @@ redis.proxy.auth= @@ -26,7 +26,7 @@ redis.proxy.auth=
26 execute.timetask.host=192.168.90.9 26 execute.timetask.host=192.168.90.9
27 27
28 #zkAddress 28 #zkAddress
29 -zkAddress=192.168.102.211:2181 29 +zkAddress=192.168.102.205:2181
30 # web context 30 # web context
31 web.context=activity 31 web.context=activity
32 32
@@ -70,3 +70,8 @@ tencentmkt.shareUrl=http://service.yoho.cn/activity/tencentMkt/index.html @@ -70,3 +70,8 @@ tencentmkt.shareUrl=http://service.yoho.cn/activity/tencentMkt/index.html
70 rabbit_host=192.168.102.162:32810 70 rabbit_host=192.168.102.162:32810
71 rabbit_user=yoho 71 rabbit_user=yoho
72 rabbit_password=yoho 72 rabbit_password=yoho
  73 +
  74 +
  75 +userday.coupon={"20":"14146", "10":"14144"}
  76 +userday.open.day=18
  77 +userday.drawPrizeNum.redisSwitch=true
@@ -18,6 +18,8 @@ @@ -18,6 +18,8 @@
18 <property name="orderShare.recevied.maxNum" defaultValue="5" description="每个分享最多老用户领取优惠券个数" /> 18 <property name="orderShare.recevied.maxNum" defaultValue="5" description="每个分享最多老用户领取优惠券个数" />
19 <property name="orderShare.shareUrl" defaultValue="http://m.yohobuy.com/coupon/index" description="订单分享的链接地址" /> 19 <property name="orderShare.shareUrl" defaultValue="http://m.yohobuy.com/coupon/index" description="订单分享的链接地址" />
20 <property name="tencentmkt.shareUrl" defaultValue="http://service.yoho.cn/activity/tencentMkt/index.html" description="市场活动推广的链接地址" /> 20 <property name="tencentmkt.shareUrl" defaultValue="http://service.yoho.cn/activity/tencentMkt/index.html" description="市场活动推广的链接地址" />
  21 + <property name="userday.open.day" defaultValue="28" description="会员日活动,的日期" />
  22 + <property name="userday.coupon" defaultValue="{\&quot;20\&quot;:\&quot;14146\&quot;, \&quot;10\&quot;:\&quot;14144\&quot;}" description="会员日活动,优惠券id" />
21 </group> 23 </group>
22 <script> 24 <script>
23 <generate template="META-INF/autoconf/databases.yml" destfile="WEB-INF/classes/databases.yml" /> 25 <generate template="META-INF/autoconf/databases.yml" destfile="WEB-INF/classes/databases.yml" />
@@ -63,4 +63,8 @@ tencentmkt.shareUrl=${tencentmkt.shareUrl} @@ -63,4 +63,8 @@ tencentmkt.shareUrl=${tencentmkt.shareUrl}
63 63
64 rabbit_host=${rabbit_host} 64 rabbit_host=${rabbit_host}
65 rabbit_user=${rabbit_user} 65 rabbit_user=${rabbit_user}
66 -rabbit_password =${rabbit_password}  
  66 +rabbit_password =${rabbit_password}
  67 +
  68 +userday.coupon=${userday.coupon}
  69 +userday.open.day=${userday.open.day}
  70 +userday.drawPrizeNum.redisSwitch=true