Authored by mingdan.ge

消息分享+公众号消息推送

package com.yoho.unions.helper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* 公众号消息推送
* Created by mingdan.ge on 2018/9/19.
*/
@Component
public class SendMessageHelper {
static Logger log = LoggerFactory.getLogger(SendMessageHelper.class);
//模版ID
static Map<Integer, String> keyMap = new HashMap<Integer, String>(){{
put(1,"AyIBF3VgCkk4V4s4NIuNmjcIe5IUeufmlMXv0oxcj74");//每日新产生佣金提醒
put(2,"9nUlr41s8vvOgKZ-xA5_VV_Gqs-868_KxdRzDziYTa4");//提现打款提醒
put(3,"6pqy58jRZ8v7VuJ2QzJOGIvelwm-M2l5H_5Sq8nYaOE");//可结算提醒
}};
public <T> void sendMessage(int uid,int type,T value) {
log.info("sendMessage enter,uid is {},type is {},value is {}.",uid,type,value);
String key = keyMap.get(type);
if (key == null) {
log.info("sendMessage end,type error,uid is {},type is {},value is {}.",uid,type,value);
return;
}
try {
System.out.println(key);
} catch (Exception e) {
log.error("sendMessage error,e is {}.",e);
}
}
}
... ...
... ... @@ -34,6 +34,8 @@ public interface UnionShareOrdersMapper {
List<UnionShareOrders> selectAllListByUids(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("uid") Integer uid,@Param("orderCode") String orderCode);
List<UnionShareOrdersUidBo> selectUidList(@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrdersUidBo> selectUidAmountList(@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrdersUidBo> selectUidSettlementList(@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrders> selectListByOrderUidForActivity(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("orderUid") Integer orderUid,@Param("promoteUid") Integer promoteUid);
... ...
... ... @@ -16,6 +16,8 @@ public class UnionShareMessage extends BaseBO {
private String url;
private int type;
private int someKey;
private int shareFlag;
private int priority;
... ... @@ -108,6 +110,22 @@ public class UnionShareMessage extends BaseBO {
this.shareFlag = shareFlag;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getSomeKey() {
return someKey;
}
public void setSomeKey(int someKey) {
this.someKey = someKey;
}
@Override
public String toString() {
return "UnionShareMessage{" +
... ... @@ -115,6 +133,8 @@ public class UnionShareMessage extends BaseBO {
", content='" + content + '\'' +
", image='" + image + '\'' +
", url=" + url +
", type=" + type +
", someKey=" + someKey +
", shareFlag=" + shareFlag +
", priority=" + priority +
", startTime='" + startTime + '\'' +
... ...
... ... @@ -6,6 +6,8 @@
<result column="content" property="content" jdbcType="VARCHAR" />
<result column="image" property="image" jdbcType="VARCHAR" />
<result column="url" property="url" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="some_key" property="someKey" jdbcType="INTEGER" />
<result column="share_flag" property="shareFlag" jdbcType="INTEGER" />
<result column="priority" property="priority" jdbcType="INTEGER" />
<result column="start_time" property="startTime" jdbcType="INTEGER" />
... ... @@ -14,7 +16,7 @@
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, content, image, url, share_flag,priority, start_time, end_time,
id, content, image, url, type,some_key,share_flag,priority, start_time, end_time,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -28,9 +30,9 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionShareMessage" >
insert into union_share_message (content, image, url, share_flag,priority, start_time, end_time,
insert into union_share_message (content, image, url, type,some_key,share_flag,priority, start_time, end_time,
create_time, update_time)
values (#{content,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{shareFlag,jdbcType=INTEGER}, #{priority,jdbcType=INTEGER},
values (#{content,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{someKey,jdbcType=INTEGER}, #{shareFlag,jdbcType=INTEGER}, #{priority,jdbcType=INTEGER},
#{startTime,jdbcType=INTEGER}, #{endTime,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}
)
... ... @@ -48,6 +50,12 @@
<if test="url != null" >
url = #{url,jdbcType=VARCHAR},
</if>
<if test="type != null" >
type = #{type,jdbcType=INTEGER},
</if>
<if test="someKey != null" >
some_key = #{someKey,jdbcType=INTEGER},
</if>
<if test="shareFlag != null" >
share_flag = #{shareFlag,jdbcType=INTEGER},
</if>
... ...
... ... @@ -391,6 +391,30 @@
</if>
group by promote_uid,order_uid
</select>
<select id="selectUidAmountList" resultType="com.yoho.service.model.union.bo.UnionShareOrdersUidBo">
select promote_uid as promoteUid,sum(amount) as amount,count(order_code) as num
from union_share_orders
where status in(10,20,30,40)
<if test="beginTime != null" >
and order_time &gt;= #{beginTime}
</if>
<if test="endTime != null" >
and order_time &lt;= #{endTime}
</if>
group by promote_uid
</select>
<select id="selectUidSettlementList" resultType="com.yoho.service.model.union.bo.UnionShareOrdersUidBo">
select promote_uid as promoteUid,sum(amount) as amount,count(order_code) as num
from union_share_orders
where status =20
<if test="beginTime != null" >
and update_time &gt;= #{beginTime}
</if>
<if test="endTime != null" >
and update_time &lt;= #{endTime}
</if>
group by promote_uid
</select>
<select id="selectListByOrderUidForActivity" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -33,6 +33,10 @@ public interface IUnionShareService {
void dealWithWaitActivity(UnionShareOrdersActivity activity);
void sendUidAoumtMessage(Integer startTime, Integer endTime);
void sendUidSettlementMessage(Integer startTime, Integer endTime);
PageUnionShareOrderRspBO queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO);
/**
* 提现结算单状态变更
... ...
... ... @@ -22,6 +22,7 @@ import javax.annotation.Resource;
import com.yoho.service.model.union.bo.*;
import com.yoho.service.model.union.request.*;
import com.yoho.service.model.union.response.*;
import com.yoho.unions.helper.SendMessageHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.common.collect.Maps;
... ... @@ -130,6 +131,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
UnionShareBigDataClickMapper unionShareBigDataClickMapper;
@Autowired
UnionShareMessageMapper unionShareMessageMapper;
@Autowired
SendMessageHelper sendMessageHelper;
@Resource
RedisValueCache redisValueCache;
@Resource
... ... @@ -860,6 +864,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 自动通过某时间段的申请
* */
@Override
@Database(ForceMaster = true)
public void passUserApply(Integer startTime, Integer endTime){
logger.info("passUserApply.startTime is {},endTime is {}.",startTime,endTime);
UnionShareUserApplyListReqBo req = new UnionShareUserApplyListReqBo();
... ... @@ -1686,6 +1691,31 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return ;
}
/**
* 发送每日新产生佣金提醒
* */
public void sendUidAoumtMessage(Integer startTime, Integer endTime) {
logger.info("sendUidAoumtMessage enter,startTime is {},endTime is {}.",startTime,endTime);
List<UnionShareOrdersUidBo> uids=unionShareOrdersMapper.selectUidAmountList(startTime, endTime);
if (CollectionUtils.isEmpty(uids)) {
return;
}
logger.info("sendUidAoumtMessage,startTime is {},endTime is {},uids is {}.",startTime,endTime,uids);
uids.forEach(u->sendMessageHelper.sendMessage(u.getPromoteUid(),1,u));
}
/**
* 发送可结算佣金提醒
* */
public void sendUidSettlementMessage(Integer startTime, Integer endTime) {
logger.info("sendUidSettlementMessage enter,startTime is {},endTime is {}.",startTime,endTime);
List<UnionShareOrdersUidBo> uids=unionShareOrdersMapper.selectUidSettlementList(startTime, endTime);
if (CollectionUtils.isEmpty(uids)) {
return;
}
logger.info("sendUidSettlementMessage,startTime is {},endTime is {},uids is {}.",startTime,endTime,uids);
uids.forEach(u->sendMessageHelper.sendMessage(u.getPromoteUid(),3,u));
}
//查询已结束等待发放奖励的普通额外返活动
@Override
public List<UnionShareOrdersActivity> queryWaitActivity() {
... ... @@ -2438,6 +2468,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//更新关联订单状态
unionShareOrdersMapper.updateStatusByCode(bo.getSettlementCode(), ShareOrdersStatusEnum.SETTLE.getCode(), ShareOrdersStatusEnum.HAS_SETTLE.getCode(), updateReq.getUpdateTime());
//todo 发送打款公众号消息
sendMessageHelper.sendMessage(bo.getPromoteUid(),2,bo);
//清缓存
clearShareOrderRedis(unionShareSettlement.getPromoteUid());
}
... ...
package com.yoho.unions.server.task;
import com.yoho.error.utils.LocalhostIpFetcher;
import com.yoho.service.model.union.bo.CpsMessageTaskBo;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.server.service.IUnionShareService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 每日新产生佣金提醒
* Created by mingdan.ge on 2018/9/19.
*/
@Component
public class CpsOrdersSumMessageTask {
private Logger logger = LoggerFactory.getLogger(CpsOrdersSumMessageTask.class);
@Autowired
IUnionShareService unionShareService;
@Resource
RedisValueCache redisValueCache;
private static String TASK_KEY = "yh:union:share:CpsOrdersSumMessageTask:";
// @Scheduled(cron = "0 0/5 * * * ?")
@Scheduled(cron = "0 0 10 * * ?")
public void run() {
//绑定已处理状态
CpsMessageTaskBo bo = new CpsMessageTaskBo();
bo.setIp(LocalhostIpFetcher.fetchLocalIP());
bo.setTime(Long.toString(System.currentTimeMillis()));
CpsMessageTaskBo cacheBo=redisValueCache.get(TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
if (cacheBo != null) {
logger.info("other get task,it is {}.this is {}.",cacheBo,bo);
}
redisValueCache.set(TASK_KEY+DateUtil.getToday("yyyyMMdd"),bo,2, TimeUnit.DAYS);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.warn("thread sleep error,e is {}",e);
}
cacheBo=redisValueCache.get(TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
if (cacheBo == null) {
logger.error("redis error.");
return;
}
if (!cacheBo.getIp().equals(bo.getIp()) || !cacheBo.getTime().equals(bo.getTime())) {
logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
return;
}
//昨日
int startTime=DateUtil.getLastDayInt(1);
int endTime= DateUtil.getLastDayInt(0);
unionShareService.sendUidAoumtMessage(startTime,endTime);
}
}
... ...
package com.yoho.unions.server.task;
import com.yoho.error.utils.LocalhostIpFetcher;
import com.yoho.service.model.union.bo.CpsMessageTaskBo;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.server.service.IUnionShareService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 每月20号和28号会有erp推送过来的订单可结算状态,发送相关公众号消息
* Created by mingdan.ge on 2018/9/19.
*/
@Component
public class CpsSettlementMessageTask {
private Logger logger = LoggerFactory.getLogger(CpsSettlementMessageTask.class);
@Autowired
IUnionShareService unionShareService;
@Resource
RedisValueCache redisValueCache;
private static String SETTLEMENT_TASK_KEY = "yh:union:share:CpsSettlementMessageTask:";
@Scheduled(cron = "0 0 10 20,28 * ?")
public void run(){
//竞争任务处理者
CpsMessageTaskBo bo = new CpsMessageTaskBo();
bo.setIp(LocalhostIpFetcher.fetchLocalIP());
bo.setTime(Long.toString(System.currentTimeMillis()));
CpsMessageTaskBo cacheBo=redisValueCache.get(SETTLEMENT_TASK_KEY+ DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
if (cacheBo != null) {
logger.info("other get task,it is {}.this is {}.",cacheBo,bo);
}
redisValueCache.set(SETTLEMENT_TASK_KEY+DateUtil.getToday("yyyyMMdd"),bo,2, TimeUnit.DAYS);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.warn("thread sleep error,e is {}",e);
}
cacheBo=redisValueCache.get(SETTLEMENT_TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
if (cacheBo == null) {
logger.error("redis error.");
return;
}
if (!cacheBo.getIp().equals(bo.getIp()) || !cacheBo.getTime().equals(bo.getTime())) {
logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
return;
}
//今天更新的数据
int startTime=DateUtil.getLastDayInt(0);
int endTime= DateUtil.getLastDayInt(-1);
unionShareService.sendUidSettlementMessage(startTime,endTime);
}
}
... ...