Authored by 周少峰

'activityList'

package com.yoho.activity.common.bo;
import com.yoho.queue.dal.model.BaseModel;
import java.util.Date;
public class ActPrizeProductBo extends BaseModel {
/**
*
*/
private static final long serialVersionUID = 1704484697194941946L;
private Integer id;
private Integer actId;
private String name;
private String price;
private Integer status;
private Integer startTime;
private Integer endTime;
private Integer limit;
private Integer sort;
private String coverImg;
private Date createTime;
private Integer isFull;
private Integer channel;
private String notice;
private String lotteryInfo;
private Integer lotteryTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getActId() {
return actId;
}
public void setActId(Integer actId) {
this.actId = actId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getStartTime() {
return startTime;
}
public void setStartTime(Integer startTime) {
this.startTime = startTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public Integer getLimit() {
return limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public String getCoverImg() {
return coverImg;
}
public void setCoverImg(String coverImg) {
this.coverImg = coverImg == null ? null : coverImg.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getIsFull() {
return isFull;
}
public void setIsFull(Integer isFull) {
this.isFull = isFull;
}
public Integer getChannel() {
return channel;
}
public void setChannel(Integer channel) {
this.channel = channel;
}
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice == null ? null : notice.trim();
}
public String getLotteryInfo() {
return lotteryInfo;
}
public void setLotteryInfo(String lotteryInfo) {
this.lotteryInfo = lotteryInfo == null ? null : lotteryInfo.trim();
}
public Integer getLotteryTime() {
return lotteryTime;
}
public void setLotteryTime(Integer lotteryTime) {
this.lotteryTime = lotteryTime;
}
}
\ No newline at end of file
... ...
... ... @@ -45,4 +45,7 @@ public class Constant {
//当天已经领取过
public final static int ORDER_SHARE_ALREADYDRAW_ERROR = 8;
// Yo!Luck 活动缓存前缀
public final static String YOLUCK_ACTIVITY_CACHE_PREFIX = "yh:yoluck:activity_cache_prefix_";
}
... ...
package com.yoho.activity.common.convert;
import com.yoho.activity.common.bo.ActPrizeProductBo;
import com.yoho.activity.common.vo.YoLuckReq;
import com.yoho.activity.dal.model.ActPrizeProduct;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
public class ActPrizeProductConvert {
/**
* 数据库对象转为bo对象返回
* @param db
* @return
*/
public static ActPrizeProductBo db2bo(ActPrizeProduct db){
if (db == null) {
return null;
}
ActPrizeProductBo bo=new ActPrizeProductBo();
BeanUtils.copyProperties(db, bo);
// 图片地址换成https
bo.setCoverImg(StringUtils.replace(db.getCoverImg(),"http:" , "https:"));
// 价格保留2位小数,添加人民币符号
StringBuilder priceBuffer = new StringBuilder();
bo.setPrice(priceBuffer.append("¥").append(String.valueOf(db.getPrice() / 100d)).toString());
return bo;
}
/**
* 请求对象转为数据库对象
* @param bo
* @return
*/
public static ActPrizeProduct bo2DalRequest(YoLuckReq bo) {
if (bo == null) {
return null;
}
ActPrizeProduct product = new ActPrizeProduct();
BeanUtils.copyProperties(bo, product);
return product;
}
}
... ...
package com.yoho.activity.common.enums;
public enum YoLockActivityListTypeEnum {
_0(0, "进行中"),
_1(1, "即将开始"),
_2(2, "已结束"),
_3(3, "已参加");
private YoLockActivityListTypeEnum(Integer status, String statusStr) {
this.type = status;
this.description = statusStr;
}
private Integer type;
private String description;
public Integer getType() {
return type;
}
public void setStatus(Integer type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
... ...
package com.yoho.activity.common.enums;
public enum YoLockActivityStatusEnum {
_1(1, "活动未开始"),
_2(2, "活动已开始"),
_3(3, "活动已结束"),
_4(4, "活动已开奖"),
_5(5, "人数未达到,活动失败");
private YoLockActivityStatusEnum(Integer status, String statusStr) {
this.status = status;
this.statusStr = statusStr;
}
private Integer status;
private String statusStr;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getStatusStr() {
return statusStr;
}
public void setStatusStr(String statusStr) {
this.statusStr = statusStr;
}
}
... ...
package com.yoho.activity.common.vo;
/**
* Created by sefon 2019-1-15 10:44:20
*/
public class YoLuckReq {
/**
*
*/
private Integer actId;
private Integer type = 0;
private Integer channel;
private Integer uid;
private Integer actPrizeId;
public Integer getActId() {
return actId;
}
public void setActId(Integer actId) {
this.actId = actId;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getChannel() {
return channel;
}
public void setChannel(Integer channel) {
this.channel = channel;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getActPrizeId() {
return actPrizeId;
}
public void setActPrizeId(Integer actPrizeId) {
this.actPrizeId = actPrizeId;
}
}
... ...
package com.yoho.activity.controller;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.ActPrizeProductBo;
import com.yoho.activity.service.IYoLuckService;
import com.yoho.error.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.tools.common.beans.page.PageRequest;
import com.yoho.activity.common.vo.YoLuckReq;
import javax.annotation.Resource;
import java.util.List;
/**
* 描述:Yo!luck 相关接口
*
* @author sefon 2019-1-11 10:36:20
*
*/
@Controller
// 保持和原项目相同路径
@RequestMapping("/YoLuckController")
public class YoLuckController {
static Logger log = LoggerFactory.getLogger(YearMemberBillController.class);
@Resource
IYoLuckService yoLuckService;
/**
* 0元购列表
* @return
* @throws ServiceException
*/
@RequestMapping("/list")
@ResponseBody
public List<ActPrizeProductBo> getActivityList(YoLuckReq request, PageRequest page) throws ServiceException {
log.info("Enter YoLuckController getActivityList YoLuckReq request = {}, PageRequest = {}", request, page);
return yoLuckService.actList(request, page);
}
/**
* 详情页
* @return
* @throws ServiceException
*/
/**
* 推荐列表
* @return
* @throws ServiceException
*/
/**
* 已参加用户
* @return
* @throws ServiceException
*/
@RequestMapping("/code/recent")
@ResponseBody
public ApiResponse activityUserList(@RequestParam(value="uid")int uid, @RequestParam(value="year")String year) throws ServiceException {
log.info("");
ApiResponse apiResponse = new ApiResponse();
log.info("");
return apiResponse;
}
/**
* 我的列表
* @return
* @throws ServiceException
*/
@RequestMapping("/list/mine")
@ResponseBody
public ApiResponse getUserActivityList(@RequestParam(value="uid")int uid, @RequestParam(value="year")String year) throws ServiceException {
log.info("");
ApiResponse apiResponse = new ApiResponse();
log.info("");
return apiResponse;
}
/**
* 获得分享码
* @return
* @throws ServiceException
*/
@RequestMapping("/code/gain")
@ResponseBody
public ApiResponse getShareCode(@RequestParam(value="uid")int uid, @RequestParam(value="year")String year) throws ServiceException {
log.info("");
ApiResponse apiResponse = new ApiResponse();
log.info("");
return apiResponse;
}
}
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.ActPrizeProductContent;
public interface ActPrizeProductContentMapper {
int deleteByPrimaryKey(Integer id);
int insert(ActPrizeProductContent record);
int insertSelective(ActPrizeProductContent record);
ActPrizeProductContent selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ActPrizeProductContent record);
int updateByPrimaryKeyWithBLOBs(ActPrizeProductContent record);
int updateByPrimaryKey(ActPrizeProductContent record);
}
\ No newline at end of file
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.ActPrizeProduct;
import com.yoho.tools.common.beans.page.PageModel;
import org.apache.ibatis.annotations.Param;
import java.util.*;
public interface ActPrizeProductMapper {
int deleteByPrimaryKey(Integer id);
int insert(ActPrizeProduct record);
int insertSelective(ActPrizeProduct record);
ActPrizeProduct selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ActPrizeProduct record);
int updateByPrimaryKey(ActPrizeProduct record);
List<ActPrizeProduct> selectActList(@Param("record") ActPrizeProduct record, @Param("page") PageModel page);
}
\ No newline at end of file
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.ActPrizeProductUser;
public interface ActPrizeProductUserMapper {
int deleteByPrimaryKey(Integer id);
int insert(ActPrizeProductUser record);
int insertSelective(ActPrizeProductUser record);
ActPrizeProductUser selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ActPrizeProductUser record);
int updateByPrimaryKey(ActPrizeProductUser record);
}
\ No newline at end of file
... ...
package com.yoho.activity.dal.model;
import com.yoho.queue.dal.model.BaseModel;
import java.util.Date;
public class ActPrizeProduct extends BaseModel {
private Integer id;
private Integer actId;
private String name;
private Long price;
private Integer status;
private Integer startTime;
private Integer endTime;
private Integer limit;
private Integer sort;
private String coverImg;
private Date createTime;
private Integer isFull;
private Integer channel;
private String notice;
private String lotteryInfo;
private Integer lotteryTime;
private Integer type;
private Integer uid;
private Integer nowTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getActId() {
return actId;
}
public void setActId(Integer actId) {
this.actId = actId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Long getPrice() {
return price;
}
public void setPrice(Long price) {
this.price = price;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getStartTime() {
return startTime;
}
public void setStartTime(Integer startTime) {
this.startTime = startTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public Integer getLimit() {
return limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public String getCoverImg() {
return coverImg;
}
public void setCoverImg(String coverImg) {
this.coverImg = coverImg == null ? null : coverImg.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getIsFull() {
return isFull;
}
public void setIsFull(Integer isFull) {
this.isFull = isFull;
}
public Integer getChannel() {
return channel;
}
public void setChannel(Integer channel) {
this.channel = channel;
}
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice == null ? null : notice.trim();
}
public String getLotteryInfo() {
return lotteryInfo;
}
public void setLotteryInfo(String lotteryInfo) {
this.lotteryInfo = lotteryInfo == null ? null : lotteryInfo.trim();
}
public Integer getLotteryTime() {
return lotteryTime;
}
public void setLotteryTime(Integer lotteryTime) {
this.lotteryTime = lotteryTime;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getNowTime() {
return nowTime;
}
public void setNowTime(Integer nowTime) {
this.nowTime = nowTime;
}
}
\ No newline at end of file
... ...
package com.yoho.activity.dal.model;
import com.yoho.queue.dal.model.BaseModel;
public class ActPrizeProductContent extends BaseModel {
private Integer id;
private Integer actId;
private Integer actPrizeId;
private Byte floorType;
private Integer sort;
private String content;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getActId() {
return actId;
}
public void setActId(Integer actId) {
this.actId = actId;
}
public Integer getActPrizeId() {
return actPrizeId;
}
public void setActPrizeId(Integer actPrizeId) {
this.actPrizeId = actPrizeId;
}
public Byte getFloorType() {
return floorType;
}
public void setFloorType(Byte floorType) {
this.floorType = floorType;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
... ...
package com.yoho.activity.dal.model;
import com.yoho.queue.dal.model.BaseModel;
import java.util.Date;
public class ActPrizeProductUser extends BaseModel {
private Integer id;
private Integer actId;
private Integer actPrizeId;
private Integer uid;
private String userName;
private String userThumb;
private String unionId;
private String prizeCode;
private Byte isShareTake;
private Integer shareUid;
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getActId() {
return actId;
}
public void setActId(Integer actId) {
this.actId = actId;
}
public Integer getActPrizeId() {
return actPrizeId;
}
public void setActPrizeId(Integer actPrizeId) {
this.actPrizeId = actPrizeId;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName == null ? null : userName.trim();
}
public String getUserThumb() {
return userThumb;
}
public void setUserThumb(String userThumb) {
this.userThumb = userThumb == null ? null : userThumb.trim();
}
public String getUnionId() {
return unionId;
}
public void setUnionId(String unionId) {
this.unionId = unionId == null ? null : unionId.trim();
}
public String getPrizeCode() {
return prizeCode;
}
public void setPrizeCode(String prizeCode) {
this.prizeCode = prizeCode == null ? null : prizeCode.trim();
}
public Byte getIsShareTake() {
return isShareTake;
}
public void setIsShareTake(Byte isShareTake) {
this.isShareTake = isShareTake;
}
public Integer getShareUid() {
return shareUid;
}
public void setShareUid(Integer shareUid) {
this.shareUid = shareUid;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
<?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.yoho.activity.dal.ActPrizeProductContentMapper">
<resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.ActPrizeProductContent">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="act_id" jdbcType="INTEGER" property="actId" />
<result column="act_prize_id" jdbcType="INTEGER" property="actPrizeId" />
<result column="floor_type" jdbcType="TINYINT" property="floorType" />
<result column="sort" jdbcType="INTEGER" property="sort" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.yoho.activity.dal.model.ActPrizeProductContent">
<result column="content" jdbcType="LONGVARCHAR" property="content" />
</resultMap>
<sql id="Base_Column_List">
id, act_id, act_prize_id, floor_type, sort
</sql>
<sql id="Blob_Column_List">
content
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from act_prize_product_content
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from act_prize_product_content
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.activity.dal.model.ActPrizeProductContent">
insert into act_prize_product_content (id, act_id, act_prize_id,
floor_type, sort, content
)
values (#{id,jdbcType=INTEGER}, #{actId,jdbcType=INTEGER}, #{actPrizeId,jdbcType=INTEGER},
#{floorType,jdbcType=TINYINT}, #{sort,jdbcType=INTEGER}, #{content,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.activity.dal.model.ActPrizeProductContent">
insert into act_prize_product_content
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="actId != null">
act_id,
</if>
<if test="actPrizeId != null">
act_prize_id,
</if>
<if test="floorType != null">
floor_type,
</if>
<if test="sort != null">
sort,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="actId != null">
#{actId,jdbcType=INTEGER},
</if>
<if test="actPrizeId != null">
#{actPrizeId,jdbcType=INTEGER},
</if>
<if test="floorType != null">
#{floorType,jdbcType=TINYINT},
</if>
<if test="sort != null">
#{sort,jdbcType=INTEGER},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.activity.dal.model.ActPrizeProductContent">
update act_prize_product_content
<set>
<if test="actId != null">
act_id = #{actId,jdbcType=INTEGER},
</if>
<if test="actPrizeId != null">
act_prize_id = #{actPrizeId,jdbcType=INTEGER},
</if>
<if test="floorType != null">
floor_type = #{floorType,jdbcType=TINYINT},
</if>
<if test="sort != null">
sort = #{sort,jdbcType=INTEGER},
</if>
<if test="content != null">
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.yoho.activity.dal.model.ActPrizeProductContent">
update act_prize_product_content
set act_id = #{actId,jdbcType=INTEGER},
act_prize_id = #{actPrizeId,jdbcType=INTEGER},
floor_type = #{floorType,jdbcType=TINYINT},
sort = #{sort,jdbcType=INTEGER},
content = #{content,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.activity.dal.model.ActPrizeProductContent">
update act_prize_product_content
set act_id = #{actId,jdbcType=INTEGER},
act_prize_id = #{actPrizeId,jdbcType=INTEGER},
floor_type = #{floorType,jdbcType=TINYINT},
sort = #{sort,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
<?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.yoho.activity.dal.ActPrizeProductMapper">
<resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.ActPrizeProduct">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="act_id" jdbcType="INTEGER" property="actId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="start_time" jdbcType="INTEGER" property="startTime" />
<result column="end_time" jdbcType="INTEGER" property="endTime" />
<result column="limit" jdbcType="INTEGER" property="limit" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="is_full" jdbcType="TINYINT" property="isFull" />
<result column="channel" jdbcType="INTEGER" property="channel" />
<result column="notice" jdbcType="VARCHAR" property="notice" />
<result column="lottery_info" jdbcType="VARCHAR" property="lotteryInfo" />
<result column="lottery_time" jdbcType="INTEGER" property="lotteryTime" />
</resultMap>
<sql id="Base_Column_List">
id, act_id, name, price, status, start_time, end_time, limit, sort, cover_img, create_time,
is_full, channel, notice, lottery_info, lottery_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from act_prize_product
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from act_prize_product
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
insert into act_prize_product (id, act_id, name,
price, status, start_time,
end_time, limit, sort,
cover_img, create_time, is_full,
channel, notice, lottery_info,
lottery_time)
values (#{id,jdbcType=INTEGER}, #{actId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{price,jdbcType=DECIMAL}, #{status,jdbcType=TINYINT}, #{startTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{limit,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER},
#{coverImg,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{isFull,jdbcType=TINYINT},
#{channel,jdbcType=INTEGER}, #{notice,jdbcType=VARCHAR}, #{lotteryInfo,jdbcType=VARCHAR},
#{lotteryTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
insert into act_prize_product
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="actId != null">
act_id,
</if>
<if test="name != null">
name,
</if>
<if test="price != null">
price,
</if>
<if test="status != null">
status,
</if>
<if test="startTime != null">
start_time,
</if>
<if test="endTime != null">
end_time,
</if>
<if test="limit != null">
limit,
</if>
<if test="sort != null">
sort,
</if>
<if test="coverImg != null">
cover_img,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="isFull != null">
is_full,
</if>
<if test="channel != null">
channel,
</if>
<if test="notice != null">
notice,
</if>
<if test="lotteryInfo != null">
lottery_info,
</if>
<if test="lotteryTime != null">
lottery_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="actId != null">
#{actId,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="price != null">
#{price,jdbcType=DECIMAL},
</if>
<if test="status != null">
#{status,jdbcType=TINYINT},
</if>
<if test="startTime != null">
#{startTime,jdbcType=INTEGER},
</if>
<if test="endTime != null">
#{endTime,jdbcType=INTEGER},
</if>
<if test="limit != null">
#{limit,jdbcType=INTEGER},
</if>
<if test="sort != null">
#{sort,jdbcType=INTEGER},
</if>
<if test="coverImg != null">
#{coverImg,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="isFull != null">
#{isFull,jdbcType=TINYINT},
</if>
<if test="channel != null">
#{channel,jdbcType=INTEGER},
</if>
<if test="notice != null">
#{notice,jdbcType=VARCHAR},
</if>
<if test="lotteryInfo != null">
#{lotteryInfo,jdbcType=VARCHAR},
</if>
<if test="lotteryTime != null">
#{lotteryTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
update act_prize_product
<set>
<if test="actId != null">
act_id = #{actId,jdbcType=INTEGER},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="price != null">
price = #{price,jdbcType=DECIMAL},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
<if test="startTime != null">
start_time = #{startTime,jdbcType=INTEGER},
</if>
<if test="endTime != null">
end_time = #{endTime,jdbcType=INTEGER},
</if>
<if test="limit != null">
limit = #{limit,jdbcType=INTEGER},
</if>
<if test="sort != null">
sort = #{sort,jdbcType=INTEGER},
</if>
<if test="coverImg != null">
cover_img = #{coverImg,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="isFull != null">
is_full = #{isFull,jdbcType=TINYINT},
</if>
<if test="channel != null">
channel = #{channel,jdbcType=INTEGER},
</if>
<if test="notice != null">
notice = #{notice,jdbcType=VARCHAR},
</if>
<if test="lotteryInfo != null">
lottery_info = #{lotteryInfo,jdbcType=VARCHAR},
</if>
<if test="lotteryTime != null">
lottery_time = #{lotteryTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
update act_prize_product
set act_id = #{actId,jdbcType=INTEGER},
name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=DECIMAL},
status = #{status,jdbcType=TINYINT},
start_time = #{startTime,jdbcType=INTEGER},
end_time = #{endTime,jdbcType=INTEGER},
limit = #{limit,jdbcType=INTEGER},
sort = #{sort,jdbcType=INTEGER},
cover_img = #{coverImg,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
is_full = #{isFull,jdbcType=TINYINT},
channel = #{channel,jdbcType=INTEGER},
notice = #{notice,jdbcType=VARCHAR},
lottery_info = #{lotteryInfo,jdbcType=VARCHAR},
lottery_time = #{lotteryTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<sql id="selectActListSQL">
<if test="record.type == 1 and record.nowTime != null">
and status > 0 and start_time > #{record.nowTime}
</if>
<if test="record.type == 2 and record.nowTime != null">
and status > 1 or end_time &lt; #{record.nowTime} or is_full > 0
</if>
<if test="record.type == 0 and record.nowTime != null">
and status = 1 and start_time &lt;= #{record.nowTime} and end_time >= #{record.nowTime} and is_full = 0
</if>
<if test="record.channel != null">
and channel = #{record.channel}
</if>
</sql>
<select id="selectActList" resultMap="BaseResultMap">
select * from act_prize_product where 1=1
<include refid="selectActListSQL" />
order by sort desc
limit #{page.startIndex}, #{page.pageSize}
</select>
</mapper>
\ No newline at end of file
... ...
<?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.yoho.activity.dal.ActPrizeProductUserMapper">
<resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.ActPrizeProductUser">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="act_id" jdbcType="INTEGER" property="actId" />
<result column="act_prize_id" jdbcType="INTEGER" property="actPrizeId" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="user_name" jdbcType="VARCHAR" property="userName" />
<result column="user_thumb" jdbcType="VARCHAR" property="userThumb" />
<result column="union_id" jdbcType="VARCHAR" property="unionId" />
<result column="prize_code" jdbcType="VARCHAR" property="prizeCode" />
<result column="is_share_take" jdbcType="TINYINT" property="isShareTake" />
<result column="share_uid" jdbcType="INTEGER" property="shareUid" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, act_id, act_prize_id, uid, user_name, user_thumb, union_id, prize_code, is_share_take,
share_uid, create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from act_prize_product_user
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from act_prize_product_user
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.activity.dal.model.ActPrizeProductUser">
insert into act_prize_product_user (id, act_id, act_prize_id,
uid, user_name, user_thumb,
union_id, prize_code, is_share_take,
share_uid, create_time)
values (#{id,jdbcType=INTEGER}, #{actId,jdbcType=INTEGER}, #{actPrizeId,jdbcType=INTEGER},
#{uid,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{userThumb,jdbcType=VARCHAR},
#{unionId,jdbcType=VARCHAR}, #{prizeCode,jdbcType=VARCHAR}, #{isShareTake,jdbcType=TINYINT},
#{shareUid,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.yoho.activity.dal.model.ActPrizeProductUser">
insert into act_prize_product_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="actId != null">
act_id,
</if>
<if test="actPrizeId != null">
act_prize_id,
</if>
<if test="uid != null">
uid,
</if>
<if test="userName != null">
user_name,
</if>
<if test="userThumb != null">
user_thumb,
</if>
<if test="unionId != null">
union_id,
</if>
<if test="prizeCode != null">
prize_code,
</if>
<if test="isShareTake != null">
is_share_take,
</if>
<if test="shareUid != null">
share_uid,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="actId != null">
#{actId,jdbcType=INTEGER},
</if>
<if test="actPrizeId != null">
#{actPrizeId,jdbcType=INTEGER},
</if>
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
<if test="userName != null">
#{userName,jdbcType=VARCHAR},
</if>
<if test="userThumb != null">
#{userThumb,jdbcType=VARCHAR},
</if>
<if test="unionId != null">
#{unionId,jdbcType=VARCHAR},
</if>
<if test="prizeCode != null">
#{prizeCode,jdbcType=VARCHAR},
</if>
<if test="isShareTake != null">
#{isShareTake,jdbcType=TINYINT},
</if>
<if test="shareUid != null">
#{shareUid,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.activity.dal.model.ActPrizeProductUser">
update act_prize_product_user
<set>
<if test="actId != null">
act_id = #{actId,jdbcType=INTEGER},
</if>
<if test="actPrizeId != null">
act_prize_id = #{actPrizeId,jdbcType=INTEGER},
</if>
<if test="uid != null">
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="userName != null">
user_name = #{userName,jdbcType=VARCHAR},
</if>
<if test="userThumb != null">
user_thumb = #{userThumb,jdbcType=VARCHAR},
</if>
<if test="unionId != null">
union_id = #{unionId,jdbcType=VARCHAR},
</if>
<if test="prizeCode != null">
prize_code = #{prizeCode,jdbcType=VARCHAR},
</if>
<if test="isShareTake != null">
is_share_take = #{isShareTake,jdbcType=TINYINT},
</if>
<if test="shareUid != null">
share_uid = #{shareUid,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.activity.dal.model.ActPrizeProductUser">
update act_prize_product_user
set act_id = #{actId,jdbcType=INTEGER},
act_prize_id = #{actPrizeId,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
user_name = #{userName,jdbcType=VARCHAR},
user_thumb = #{userThumb,jdbcType=VARCHAR},
union_id = #{unionId,jdbcType=VARCHAR},
prize_code = #{prizeCode,jdbcType=VARCHAR},
is_share_take = #{isShareTake,jdbcType=TINYINT},
share_uid = #{shareUid,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -16,6 +16,7 @@
<project-name>yohobuy-activity</project-name>
<project-version>1.0.0-SNAPSHOT</project-version>
<yoho.service.model.version>1.0.0-SNAPSHOT</yoho.service.model.version>
<yohobuy-tools-version>0.0.1-SNAPSHOT</yohobuy-tools-version>
</properties>
<dependencyManagement>
... ... @@ -60,6 +61,11 @@
<dependencies>
<dependency>
<groupId>com.yoho.tools</groupId>
<artifactId>yohobuy-tools-common</artifactId>
<version>${yohobuy-tools-version}</version>
</dependency>
<dependency>
<groupId>com.yoho.common</groupId>
<artifactId>error-code</artifactId>
</dependency>
... ...
/**
*
*/
package com.yoho.activity.service;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.ActPrizeProductBo;
import com.yoho.activity.common.vo.YoLuckReq;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.page.PageRequest;
import java.util.List;
/**
* 描述:Yo!Luck 相关接口
* @author sefon 2019-1-15 12:15:11
*/
public interface IYoLuckService {
/**
* 元购列表
* @param request
* @param page
* @return
* @throws Exception
*/
public List<ActPrizeProductBo> actList(YoLuckReq request, PageRequest page) throws ServiceException;
}
... ...
package com.yoho.activity.service.impl;
import com.yoho.activity.common.bo.ActPrizeProductBo;
import com.yoho.activity.common.convert.ActPrizeProductConvert;
import com.yoho.activity.common.redis.CacheKeyHelper;
import com.yoho.activity.common.vo.YoLuckReq;
import com.yoho.activity.dal.model.ActPrizeProduct;
import com.yoho.activity.service.IYoLuckService;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.page.PageRequest;
import com.yoho.tools.common.redis.RedisValueHelper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.activity.dal.ActPrizeProductMapper;
import com.yoho.activity.common.enums.YoLockActivityStatusEnum;
import com.yoho.activity.common.enums.YoLockActivityListTypeEnum;
import com.yoho.activity.common.constatns.Constant;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class YoLuckServiceImpl implements IYoLuckService {
private static Logger log = LoggerFactory.getLogger(YoLuckServiceImpl.class);
@Resource
private ActPrizeProductMapper actPrizeProductMapper;
@Autowired
RedisValueHelper redisValueHelper;
@Redis("yohoNoSyncRedis")
YHValueOperations yhValueOperations;
/**
* 活动列表
* @param request
* @param page
* @return
* @throws ServiceException
*/
@Override
public List<ActPrizeProductBo> actList(YoLuckReq request, PageRequest page) throws ServiceException {
log.info("Enter YoLuckController getActivityList YoLuckReq request = {}, PageRequest = {}", request, page);
List<ActPrizeProductBo> resultList = new ArrayList<>();
do {
// 缓存
RedisKeyBuilder listCacheKey = getCacheKey(request, page);
String value = yhValueOperations.get(listCacheKey);
List<ActPrizeProductBo> redisResultList = CacheKeyHelper.string2Value(value, List.class);
if (CollectionUtils.isNotEmpty(redisResultList)) {
resultList = redisResultList;
log.warn("getActivityList with result from redis.");
break;
}
// 数据库
ActPrizeProduct record = ActPrizeProductConvert.bo2DalRequest(request);
record.setNowTime(DateUtil.getCurrentTimeSecond());
List<ActPrizeProduct> list = actPrizeProductMapper.selectActList(record, page.toPageModel());
if (CollectionUtils.isEmpty(list)) {
log.warn("getActivityList with result is empty.");
break;
}
ActPrizeProductBo itemBo = null;
for (ActPrizeProduct item : list) {
itemBo = ActPrizeProductConvert.db2bo(item);
itemBo.setStatus(getActivityStatus(itemBo));
resultList.add(itemBo);
}
// 存缓存
try {
yhValueOperations.set(listCacheKey, CacheKeyHelper.value2String(resultList), 10, TimeUnit.SECONDS);
} catch (Exception e) {
log.warn("setActivityList redis cache fail err={}.", e);
}
} while (false);
return resultList;
}
/**
* 获取活动的状态
* @param bo
* @return
*/
private Integer getActivityStatus(ActPrizeProductBo bo) {
// 默认活动已经开始,正在进行中
Integer status = YoLockActivityStatusEnum._2.getStatus();
Integer nowTime = DateUtil.getCurrentTimeSecond();
if (bo.getStatus() == 2) { // 已经开奖
status = YoLockActivityStatusEnum._4.getStatus();
} else { // 未开奖
if (nowTime > bo.getEndTime()) {
// 时间已过结束时间
status = YoLockActivityStatusEnum._3.getStatus();
} else if (nowTime > bo.getEndTime()) {
// 时间未到结束时间
status = YoLockActivityStatusEnum._1.getStatus();
}
}
return status;
}
/**
* 获取活动列表缓存key
* @param request
* @param page
* @return
*/
private RedisKeyBuilder getCacheKey(YoLuckReq request, PageRequest page){
return RedisKeyBuilder.newInstance().appendFixed(Constant.YOLUCK_ACTIVITY_CACHE_PREFIX).appendVar(request.getType()).appendFixed(":").appendVar(page.toString());
}
}
... ...
... ... @@ -24,4 +24,15 @@ datasources:
- com.yoho.lottery.dal.WeixinBindPrizeMapper
- com.yoho.lottery.dal.LotteryPrizeMapper
yoho_activity_platform:
servers:
- 192.168.102.219:3306
- 192.168.102.219:3306
username: yh_test
password: 9nm0icOwt6bMHjMusIfMLw==
daos:
- com.yoho.activity.dal.ActPrizeProductMapper
- com.yoho.activity.dal.ActPrizeProductContentMapper
- com.yoho.activity.dal.ActPrizeProductUserMapper
readOnlyInSlave: true
\ No newline at end of file
... ...