Authored by chenchao

add message center

... ... @@ -32,7 +32,9 @@ public class DateUtil {
public static final String MM_dd_yyyy = "MM/dd/yyyy";
private static final String MM_dd_yyyy_HH_mm = "MM/dd/yyyy HH:mm";
private static final String MM_dd_yyyy_HH_mm_ss = "MM/dd/yyyy HH:mm:ss";
public static final String yyyyMMdd = "yyyyMMdd", yyyyMMddHHmm = "yyyyMMddHHmm",
public static final String yyyyMMdd = "yyyyMMdd",
yyyyMMddHH = "yyyyMMddHH",
yyyyMMddHHmm = "yyyyMMddHHmm",
yyyyMMddHHmmss = "yyyyMMddHHmmss";
public static final String yyyy_MM_dd_HH_mm_SS = "yyyy-MM-dd HH:mm:ss";
public static final String yyyy_MM_dd_HH_mm = "yyyy-MM-dd HH:mm";
... ...
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.NoticeCase;
public interface NoticeCaseMapper {
int deleteByPrimaryKey(Integer id);
int insert(NoticeCase record);
int insertSelective(NoticeCase record);
NoticeCase selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(NoticeCase record);
int updateByPrimaryKey(NoticeCase record);
NoticeCase selectByMetaKey(String metaKey);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.Notice;
public interface NoticeMapper {
int deleteByPrimaryKey(Long id);
int insert(Notice record);
int insertSelective(Notice record);
Notice selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Notice record);
int updateByPrimaryKey(Notice record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.NoticeRule;
public interface NoticeRuleMapper {
int deleteByPrimaryKey(Integer id);
int insert(NoticeRule record);
int insertSelective(NoticeRule record);
NoticeRule selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(NoticeRule record);
int updateByPrimaryKey(NoticeRule record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class Notice {
private Long id;
private Integer uid;
private String bizKey;
private Integer caseId;
private Integer ruleId;
private Short method;
private Integer limitQuantity;
private Integer quantity;
private String updateDtp;
private Integer timeUnitRegion;
private Short timeUnit;
private Integer updateTime;
private Integer createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getBizKey() {
return bizKey;
}
public void setBizKey(String bizKey) {
this.bizKey = bizKey == null ? null : bizKey.trim();
}
public Integer getCaseId() {
return caseId;
}
public void setCaseId(Integer caseId) {
this.caseId = caseId;
}
public Integer getRuleId() {
return ruleId;
}
public void setRuleId(Integer ruleId) {
this.ruleId = ruleId;
}
public Short getMethod() {
return method;
}
public void setMethod(Short method) {
this.method = method;
}
public Integer getLimitQuantity() {
return limitQuantity;
}
public void setLimitQuantity(Integer limitQuantity) {
this.limitQuantity = limitQuantity;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public String getUpdateDtp() {
return updateDtp;
}
public void setUpdateDtp(String updateDtp) {
this.updateDtp = updateDtp == null ? null : updateDtp.trim();
}
public Integer getTimeUnitRegion() {
return timeUnitRegion;
}
public void setTimeUnitRegion(Integer timeUnitRegion) {
this.timeUnitRegion = timeUnitRegion;
}
public Short getTimeUnit() {
return timeUnit;
}
public void setTimeUnit(Short timeUnit) {
this.timeUnit = timeUnit;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class NoticeCase {
private Integer id;
private String metaKey;
private String title;
private String ruleIds;
private String rules;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMetaKey() {
return metaKey;
}
public void setMetaKey(String metaKey) {
this.metaKey = metaKey == null ? null : metaKey.trim();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
public String getRuleIds() {
return ruleIds;
}
public void setRuleIds(String ruleIds) {
this.ruleIds = ruleIds == null ? null : ruleIds.trim();
}
public String getRules() {
return rules;
}
public void setRules(String rules) {
this.rules = rules == null ? null : rules.trim();
}
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class NoticeRule {
private Integer id;
private Integer caseId;
private Short method;
private Integer quantity;
private Integer timeUnitRegion;
private Short timeUnit;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCaseId() {
return caseId;
}
public void setCaseId(Integer caseId) {
this.caseId = caseId;
}
public Short getMethod() {
return method;
}
public void setMethod(Short method) {
this.method = method;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public Integer getTimeUnitRegion() {
return timeUnitRegion;
}
public void setTimeUnitRegion(Integer timeUnitRegion) {
this.timeUnitRegion = timeUnitRegion;
}
public Short getTimeUnit() {
return timeUnit;
}
public void setTimeUnit(Short timeUnit) {
this.timeUnit = timeUnit;
}
}
\ 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.yohoufo.dal.order.NoticeCaseMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.NoticeCase">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="meta_key" jdbcType="VARCHAR" property="metaKey" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="rule_ids" jdbcType="VARCHAR" property="ruleIds" />
<result column="rules" jdbcType="VARCHAR" property="rules" />
</resultMap>
<sql id="Base_Column_List">
id, meta_key, title, rule_ids, rules
</sql>
<select id="selectByMetaKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from notice_case
where meta_key = #{metaKey,jdbcType=VARCHAR}
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from notice_case
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from notice_case
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.NoticeCase" useGeneratedKeys="true">
insert into notice_case (meta_key, title, rule_ids,
rules)
values (#{metaKey,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{ruleIds,jdbcType=VARCHAR},
#{rules,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.NoticeCase" useGeneratedKeys="true">
insert into notice_case
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="metaKey != null">
meta_key,
</if>
<if test="title != null">
title,
</if>
<if test="ruleIds != null">
rule_ids,
</if>
<if test="rules != null">
rules,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="metaKey != null">
#{metaKey,jdbcType=VARCHAR},
</if>
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="ruleIds != null">
#{ruleIds,jdbcType=VARCHAR},
</if>
<if test="rules != null">
#{rules,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.NoticeCase">
update notice_case
<set>
<if test="metaKey != null">
meta_key = #{metaKey,jdbcType=VARCHAR},
</if>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="ruleIds != null">
rule_ids = #{ruleIds,jdbcType=VARCHAR},
</if>
<if test="rules != null">
rules = #{rules,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.NoticeCase">
update notice_case
set meta_key = #{metaKey,jdbcType=VARCHAR},
title = #{title,jdbcType=VARCHAR},
rule_ids = #{ruleIds,jdbcType=VARCHAR},
rules = #{rules,jdbcType=VARCHAR}
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.yohoufo.dal.order.NoticeMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.Notice">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="biz_key" jdbcType="VARCHAR" property="bizKey" />
<result column="case_id" jdbcType="INTEGER" property="caseId" />
<result column="rule_id" jdbcType="INTEGER" property="ruleId" />
<result column="method" jdbcType="SMALLINT" property="method" />
<result column="limit_quantity" jdbcType="INTEGER" property="limitQuantity" />
<result column="quantity" jdbcType="INTEGER" property="quantity" />
<result column="update_dtp" jdbcType="VARCHAR" property="updateDtp" />
<result column="time_unit_region" jdbcType="INTEGER" property="timeUnitRegion" />
<result column="time_unit" jdbcType="SMALLINT" property="timeUnit" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, uid, biz_key, case_id, rule_id, method, limit_quantity, quantity, update_dtp,
time_unit_region, time_unit, update_time, create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from notice
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from notice
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.Notice" useGeneratedKeys="true">
insert into notice (uid, biz_key, case_id,
rule_id, method, limit_quantity,
quantity, update_dtp, time_unit_region,
time_unit, update_time, create_time
)
values (#{uid,jdbcType=INTEGER}, #{bizKey,jdbcType=VARCHAR}, #{caseId,jdbcType=INTEGER},
#{ruleId,jdbcType=INTEGER}, #{method,jdbcType=SMALLINT}, #{limitQuantity,jdbcType=INTEGER},
#{quantity,jdbcType=INTEGER}, #{updateDtp,jdbcType=VARCHAR}, #{timeUnitRegion,jdbcType=INTEGER},
#{timeUnit,jdbcType=SMALLINT}, #{updateTime,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.Notice" useGeneratedKeys="true">
insert into notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">
uid,
</if>
<if test="bizKey != null">
biz_key,
</if>
<if test="caseId != null">
case_id,
</if>
<if test="ruleId != null">
rule_id,
</if>
<if test="method != null">
method,
</if>
<if test="limitQuantity != null">
limit_quantity,
</if>
<if test="quantity != null">
quantity,
</if>
<if test="updateDtp != null">
update_dtp,
</if>
<if test="timeUnitRegion != null">
time_unit_region,
</if>
<if test="timeUnit != null">
time_unit,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
<if test="bizKey != null">
#{bizKey,jdbcType=VARCHAR},
</if>
<if test="caseId != null">
#{caseId,jdbcType=INTEGER},
</if>
<if test="ruleId != null">
#{ruleId,jdbcType=INTEGER},
</if>
<if test="method != null">
#{method,jdbcType=SMALLINT},
</if>
<if test="limitQuantity != null">
#{limitQuantity,jdbcType=INTEGER},
</if>
<if test="quantity != null">
#{quantity,jdbcType=INTEGER},
</if>
<if test="updateDtp != null">
#{updateDtp,jdbcType=VARCHAR},
</if>
<if test="timeUnitRegion != null">
#{timeUnitRegion,jdbcType=INTEGER},
</if>
<if test="timeUnit != null">
#{timeUnit,jdbcType=SMALLINT},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.Notice">
update notice
<set>
<if test="uid != null">
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="bizKey != null">
biz_key = #{bizKey,jdbcType=VARCHAR},
</if>
<if test="caseId != null">
case_id = #{caseId,jdbcType=INTEGER},
</if>
<if test="ruleId != null">
rule_id = #{ruleId,jdbcType=INTEGER},
</if>
<if test="method != null">
method = #{method,jdbcType=SMALLINT},
</if>
<if test="limitQuantity != null">
limit_quantity = #{limitQuantity,jdbcType=INTEGER},
</if>
<if test="quantity != null">
quantity = #{quantity,jdbcType=INTEGER},
</if>
<if test="updateDtp != null">
update_dtp = #{updateDtp,jdbcType=VARCHAR},
</if>
<if test="timeUnitRegion != null">
time_unit_region = #{timeUnitRegion,jdbcType=INTEGER},
</if>
<if test="timeUnit != null">
time_unit = #{timeUnit,jdbcType=SMALLINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.Notice">
update notice
set uid = #{uid,jdbcType=INTEGER},
biz_key = #{bizKey,jdbcType=VARCHAR},
case_id = #{caseId,jdbcType=INTEGER},
rule_id = #{ruleId,jdbcType=INTEGER},
method = #{method,jdbcType=SMALLINT},
limit_quantity = #{limitQuantity,jdbcType=INTEGER},
quantity = #{quantity,jdbcType=INTEGER},
update_dtp = #{updateDtp,jdbcType=VARCHAR},
time_unit_region = #{timeUnitRegion,jdbcType=INTEGER},
time_unit = #{timeUnit,jdbcType=SMALLINT},
update_time = #{updateTime,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</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.yohoufo.dal.order.NoticeRuleMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.NoticeRule">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="case_id" jdbcType="INTEGER" property="caseId" />
<result column="method" jdbcType="SMALLINT" property="method" />
<result column="quantity" jdbcType="INTEGER" property="quantity" />
<result column="time_unit_region" jdbcType="INTEGER" property="timeUnitRegion" />
<result column="time_unit" jdbcType="SMALLINT" property="timeUnit" />
</resultMap>
<sql id="Base_Column_List">
id, case_id, method, quantity, time_unit_region, time_unit
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from notice_rule
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from notice_rule
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.NoticeRule" useGeneratedKeys="true">
insert into notice_rule (case_id, method, quantity,
time_unit_region, time_unit)
values (#{caseId,jdbcType=INTEGER}, #{method,jdbcType=SMALLINT}, #{quantity,jdbcType=INTEGER},
#{timeUnitRegion,jdbcType=INTEGER}, #{timeUnit,jdbcType=SMALLINT})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.NoticeRule" useGeneratedKeys="true">
insert into notice_rule
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="caseId != null">
case_id,
</if>
<if test="method != null">
method,
</if>
<if test="quantity != null">
quantity,
</if>
<if test="timeUnitRegion != null">
time_unit_region,
</if>
<if test="timeUnit != null">
time_unit,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="caseId != null">
#{caseId,jdbcType=INTEGER},
</if>
<if test="method != null">
#{method,jdbcType=SMALLINT},
</if>
<if test="quantity != null">
#{quantity,jdbcType=INTEGER},
</if>
<if test="timeUnitRegion != null">
#{timeUnitRegion,jdbcType=INTEGER},
</if>
<if test="timeUnit != null">
#{timeUnit,jdbcType=SMALLINT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.NoticeRule">
update notice_rule
<set>
<if test="caseId != null">
case_id = #{caseId,jdbcType=INTEGER},
</if>
<if test="method != null">
method = #{method,jdbcType=SMALLINT},
</if>
<if test="quantity != null">
quantity = #{quantity,jdbcType=INTEGER},
</if>
<if test="timeUnitRegion != null">
time_unit_region = #{timeUnitRegion,jdbcType=INTEGER},
</if>
<if test="timeUnit != null">
time_unit = #{timeUnit,jdbcType=SMALLINT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.NoticeRule">
update notice_rule
set case_id = #{caseId,jdbcType=INTEGER},
method = #{method,jdbcType=SMALLINT},
quantity = #{quantity,jdbcType=INTEGER},
time_unit_region = #{timeUnitRegion,jdbcType=INTEGER},
time_unit = #{timeUnit,jdbcType=SMALLINT}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yohoufo-fore-parent</artifactId>
<groupId>com.yohoufo.fore</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yohoufo-fore-msg-center</artifactId>
<name>yohoufo-fore-msg-center</name>
<dependencies>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-dal</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.ufo.model</groupId>
<artifactId>order-ufo-model</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-inboxclient</artifactId>
</dependency>
</dependencies>
</project>
... ...
package com.yohoufo.msg.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.slf4j.helpers.MessageFormatter;
/**
* Created by chenchao on 2018/10/16.
*/
public class CacheKeyBuilder {
public enum KeyTemp{
BASE_NOTICE_CASE("ufo:msg:notice:case:","metaKey:{}"),
LOWER_PRICE_NOTICE_SELLER("ufo:msg:lowerPrice:seller:","uid:{}:storageId:{}case:{}:method:{}:dtp{}:num");
private String fix;
private String placeHolder;
KeyTemp(String fix, String placeHolder) {
this.fix = fix;
this.placeHolder = placeHolder;
}
public String fillPlaceHolder(Object[] args){
if (placeHolder == null){
return null;
}
return MessageFormatter.arrayFormat(placeHolder, args).getMessage();
}
public RedisKeyBuilder builderKey(Object[] args){
String appendPart = fillPlaceHolder(args);
return new RedisKeyBuilder().appendFixed(fix).appendVar(appendPart);
}
}
public static RedisKeyBuilder lowerPriceNoticeSellerKey(int uid, int storageId, Integer caseId, Short method, String dtp){
return KeyTemp.LOWER_PRICE_NOTICE_SELLER.builderKey(new Object[]{uid, storageId, caseId, method, dtp});
}
public static RedisKeyBuilder baseNoticeCaseKey(String metaKey){
return KeyTemp.BASE_NOTICE_CASE.builderKey(new Object[]{metaKey});
}
}
... ...
package com.yohoufo.msg.cache;
/**
* Created by chao.chen on 2018/12/5.
*/
public interface ExpiredTime {
int CASE_EXPIRED_TIME = 300;
}
... ...
package com.yohoufo.msg.config;
/**
* Created by chao.chen on 2018/12/5.
*/
public interface CaseIdConfig {
String LOWER_PRICE_NOTICE_SELLER = "LOWER_PRICE_NOTICE_SELLER";
}
... ...
package com.yohoufo.msg.constants;
import java.util.HashMap;
import java.util.Map;
/**
* 时间单位,1:秒,2:分钟,3:小时,4:天,5:周,6:月,7:年
* Created by chao.chen on 2018/12/5.
*/
public enum TimeUnitEnum {
SECOND((short)1),
MIN((short)2),
HOUR((short)3),
DAY((short)4),
WEEK((short)5),
MONTH((short)6),
YEAR((short)7);
short code;
TimeUnitEnum(short code) {
this.code = code;
}
public short getCode() {
return code;
}
private static Map<Short,TimeUnitEnum> cache;
static {
cache = new HashMap<>(values().length);
for(TimeUnitEnum tu: values()){
cache.put(tu.code, tu);
}
}
public static TimeUnitEnum getByCode(Short code){
return cache.get(code);
}
}
... ...
package com.yohoufo.msg.model;
import com.yohoufo.dal.order.model.NoticeCase;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* Created by chao.chen on 2018/12/5.
*/
@Data
public class NoticeCaseNode {
private Integer id;
private Integer uid;
private String bizKey;
private NoticeCase noticeCase;
private Map<Integer, NoticeRuleNode> noticeRuleNodeMap;
}
... ...
package com.yohoufo.msg.model;
import com.yohoufo.dal.order.model.Notice;
import lombok.Data;
/**
* Created by chao.chen on 2018/12/5.
*/
@Data
public class NoticeNode {
private Integer id;
private Integer uid;
private String bizKey;
private Integer caseId;
private Integer ruleId;
private Notice notice;
}
... ...
package com.yohoufo.msg.model;
import com.yohoufo.dal.order.model.NoticeRule;
import lombok.Data;
/**
* Created by chao.chen on 2018/12/5.
*/
@Data
public class NoticeRuleNode {
private Integer id;
private NoticeRule noticeRule;
private NoticeNode noticeNode;
}
... ...
package com.yohoufo.msg.service.impl;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.NoticeRule;
import com.yohoufo.msg.cache.CacheKeyBuilder;
import com.yohoufo.msg.config.CaseIdConfig;
import com.yohoufo.msg.constants.TimeUnitEnum;
import com.yohoufo.msg.model.NoticeCaseNode;
import com.yohoufo.msg.model.NoticeRuleNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by chao.chen on 2018/12/5.
*/
@Service
public class MsgService {
@Autowired
private NoticeCaseService noticeCaseService;
@Autowired
private CacheClient cacheClient;
private Map<Short,String> getTimeUnitPartten(Date date, List<TimeUnitEnum> tueList){
return tueList.parallelStream().collect(Collectors.toMap(TimeUnitEnum::getCode, tue->{
String fmtp = null;
switch (tue){
case HOUR:
fmtp = DateUtil.format(date, DateUtil.yyyyMMddHH);
break;
}
return fmtp;
}));
}
public void noticeSellerWhenLowerPrice(List<Integer> uidList, int storageId){
NoticeCaseNode ncNode = noticeCaseService.getNoticeCaseNode(CaseIdConfig.LOWER_PRICE_NOTICE_SELLER);
Map<Integer, NoticeRuleNode> noticeRuleNodeMap = ncNode.getNoticeRuleNodeMap();
Integer caseId = ncNode.getId();
Date now = new Date();
Map<Short,String> tupMap = this.getTimeUnitPartten(now, Arrays.asList(TimeUnitEnum.HOUR, TimeUnitEnum.DAY));
for(Map.Entry<Integer, NoticeRuleNode> nrEntry : noticeRuleNodeMap.entrySet()){
NoticeRuleNode nrNode = nrEntry.getValue();
NoticeRule pnr = nrNode.getNoticeRule();
Short method = pnr.getMethod();
Short timeUnit = pnr.getTimeUnit();
TimeUnitEnum tue = TimeUnitEnum.getByCode(timeUnit);
if (tue == null){
continue;
}
for(Integer uid :uidList) {
String dtp = tupMap.get(tue.getCode());
CacheKeyBuilder.lowerPriceNoticeSellerKey(uid, storageId, caseId, method, dtp);
}
}
}
}
... ...
package com.yohoufo.msg.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.NoticeCaseMapper;
import com.yohoufo.dal.order.model.NoticeCase;
import com.yohoufo.dal.order.model.NoticeRule;
import com.yohoufo.msg.cache.CacheKeyBuilder;
import com.yohoufo.msg.cache.ExpiredTime;
import com.yohoufo.msg.model.NoticeCaseNode;
import com.yohoufo.msg.model.NoticeRuleNode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Created by chao.chen on 2018/12/5.
*/
@Service
public class NoticeCaseService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CacheClient cacheClient;
@Autowired
private NoticeCaseMapper noticeCaseMapper;
public NoticeCaseNode getNoticeCaseNode(String metaKey){
RedisKeyBuilder rkb = CacheKeyBuilder.baseNoticeCaseKey(metaKey);
NoticeCaseNode ncn = cacheClient.get(rkb, NoticeCaseNode.class);
if (Objects.nonNull(ncn)){
return ncn;
}
NoticeCase noticeCase = noticeCaseMapper.selectByMetaKey(metaKey);
if (Objects.isNull(noticeCase)){
logger.warn("in getNoticeCaseNode selectByMetaKey is none, metaKey {}", metaKey );
throw new UfoServiceException(501, "推送规则配置错误");
}
ncn = new NoticeCaseNode();
ncn.setId(noticeCase.getId());
ncn.setNoticeCase(noticeCase);
//
String rulesStr = noticeCase.getRules();
List<NoticeRule> noticeRules = null;
if (StringUtils.isNotBlank(rulesStr)){
try {
noticeRules = JSONObject.parseObject(rulesStr, new TypeReference<List<NoticeRule>>(){});
}catch (Exception ex){
logger.warn("in getNoticeCaseNode parse rulesStr {} fail metaKey {}", rulesStr, metaKey );
throw new UfoServiceException(501, "推送规则配置错误");
}
}
Map<Integer, NoticeRuleNode> noticeRuleNodeMap;
if(CollectionUtils.isEmpty(noticeRules)){
logger.warn("in getNoticeCaseNode parse rulesStr {} get noticeRules is empty metaKey {}", rulesStr, metaKey );
throw new UfoServiceException(501, "推送规则配置错误");
}
noticeRuleNodeMap = noticeRules.parallelStream().collect(Collectors.toMap(NoticeRule::getId, nr -> {
NoticeRuleNode nrn = new NoticeRuleNode();
nrn.setId(nr.getId());
nrn.setNoticeRule(nr);
return nrn;
}));
ncn.setNoticeRuleNodeMap(noticeRuleNodeMap);
//
cacheClient.setEx(rkb, ncn, ExpiredTime.CASE_EXPIRED_TIME);
return ncn;
}
}
... ...
package com.yohoufo.msg.service.impl;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.msg.model.NoticeCaseNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chao.chen on 2018/12/5.
*/
@Service
public class NoticeService {
@Autowired
private CacheClient cacheClient;
public void addByCase(NoticeCaseNode ncNode){
}
}
... ...
... ... @@ -43,10 +43,7 @@
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rest-client-simple</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-dal</artifactId>
</dependency>
<dependency>
... ...
... ... @@ -17,7 +17,10 @@ public class SellerService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
/**
/**更低出价提醒
* 1)当有新卖家出价成功或调价成功时,给所有正在出售该sku(尺码)的其他卖家推送一条消息(push+消息盒子)
*2)同一卖家的同一SKU 1小时内仅推送一条提醒(最先推送的那条)
*3)同一卖家的同一SKU一天最多接收8条消息提醒
* 需要考虑的是发布和变价是个不间断的操作,若高并发必影响调用者处理速度
* 还好,我已经把这个定义成非核心功能,可以异步实现
* @param whoReducePrice
... ... @@ -31,6 +34,11 @@ public class SellerService {
//TODO finish blow step
// step 1: 找到所有出售中 & 指定storageId的skup &不是whoReducePrice这个uid & 价格高于lowerSalePrice(seller_order_goods表)集合 --> one sq1
// step 2:消息或短信 给所有的用户(多么贴心,也许以后可以干掉毒,然后收费^v^)
// step 2.1 超过多少数量 使用多线程并行处理
// step 2.1 超过多少数量 使用多线程并行处理(实际上是对用户分组)
// step 2.2 根据消息发送规则 对单个用户发送的消息数量做限制
//使用redis的过期时间做倒计时,一小时 key(单个用户:场景:告知方式:时间标记:) uid:{}:storageId:{}case:{}:method:{}:dtp{}:num
//dtp 为时间标记 小时:yyyyMMddHH,天:yyyyMMdd
//倒计时 需要考虑跨天,计算当前日期的最后一秒
}
}
... ...
... ... @@ -126,6 +126,7 @@
<module>web</module>
<module>deploy</module>
<module>inbox</module>
<module>msg-center</module>
</modules>
... ...