Authored by mingdan.ge

cps4期 马甲用户随机增

... ... @@ -14,9 +14,11 @@ public enum ShareOrdersKeyEnum {
SETTLEMENT_LIST("yh:union:share:settlementList:","key:{}:page:{}:limit:{}",600,"提现列表"),
UNION_TYPE("yh:union:share:unionType:","key:{}",600,"用户登录时获取对应的渠道号"),
RECENTLY_ORDER_LIMIT_TEN("yh:union:share:recentlyOrderLimitTen:","key:{}",600,"用户前台获取个人推广近期订单(10个)"),
ACTIVITY_ING_LIST("yh:union:share:activity:ing:list",null,120,"进行中的活动"),
ACTIVITY("yh:union:share:activity:","type:{}:id:{}",120,"活动"),
ORDER_STATISTICS_INFO("yh:union:share:statisticsInfo:","uid:{}:queryTimeType:{}",600,"统计数据"),
RANK_LIST("yh:union:share:ranklist:","type:{}:start:{}:limit:{}",600,"达人排行榜"),
RANK_INFO("yh:union:share:rank:","uid:{}type:{}:",600,"个人排行");
RANK_INFO("yh:union:share:rank:","date:{}:type:{}",300,"个人排行");
private String preKey;
... ...
... ... @@ -102,6 +102,8 @@
<value>/UnionShareRest/resetApply</value>
<value>/UnionShareRest/queryActivityOrder</value>
<value>/UnionShareRest/queryRank</value>
<value>/UnionShareRest/addVirtual</value>
<value>/UnionShareRest/clearActivity</value>
<value>/UnionShareRest/getStatisticsInfo</value>
</list>
... ...
... ... @@ -17,6 +17,7 @@ public interface UnionShareOrdersMonthMapper {
UnionShareOrdersMonth selectByPrimaryKey(Integer id);
List<UnionShareOrdersMonth> selectVirtualMonthData(@Param("date") int date);
List<UnionShareOrdersMonth> selectMonthData(@Param("date") int date, @Param("promoteUid") Integer promoteUid, @Param("type") Integer type);
List<UninoShareIncomeBo> selectMonthRankList(@Param("date") int date, @Param("start") Integer start, @Param("size") Integer size);
List<UninoShareIncomeBo> selectTotalRankList(@Param("start") Integer start, @Param("size") Integer size);
... ...
... ... @@ -32,6 +32,13 @@
where uid = #{promoteUid,jdbcType=INTEGER} and date=#{date,jdbcType=INTEGER} and type=#{type,jdbcType=INTEGER}
order by id desc
</select>
<select id="selectVirtualMonthData" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_orders_month
where date=#{date,jdbcType=INTEGER} and type=2
limit 100
</select>
<select id="selectMonthRankList" resultType="com.yoho.service.model.union.bo.UninoShareIncomeBo" >
select amount ,uid,nickname,image,order_num as orderNum
from union_share_orders_month
... ...
... ... @@ -67,7 +67,6 @@ public class UnionShareOrderConsumer implements YhConsumer {
//清达人相关redis
int date = Integer.valueOf(com.yoho.unions.common.utils.DateUtil.getToday("yyyyMMdd"));
redisHashCache.delete(ShareOrdersKeyEnum.RANK_LIST.getPreKey(),date);
redisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),date);
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! obj is {}, e {}",o,e.getMessage());
}
... ...
... ... @@ -328,6 +328,27 @@ public class UnionShareRest {
return result;
}
/**
* 后台操作向redis塞待执行任务
* */
@RequestMapping("/addVirtual")
@ResponseBody
public UnionResponse addVirtual(){
log.info("UnionShareRest.addVirtual.");
unionShareService.setVirtualAddToRedis();
return new UnionResponse(200, "addVirtual success");
}
/**
* 清活动缓存
* */
@RequestMapping("/clearActivity")
@ResponseBody
public UnionResponse clearActivity(int activityId){
log.info("UnionShareRest.addVirtual.");
unionShareService.clearActivityCache(activityId);
return new UnionResponse(200, "addVirtual success");
}
/**
* 查询社交媒体基本参数
... ...
... ... @@ -176,6 +176,11 @@ public interface IUnionShareService {
void dealWithVirtualUserTask(UnionShareVirtualAddBo bo);
/**
* 后台操作向redis塞待执行任务
* */
void setVirtualAddToRedis();
/**
* 查询用户绑定银行卡信息
* @param parm
* @return
... ... @@ -223,4 +228,6 @@ public interface IUnionShareService {
* @return
*/
PageResponseBO<UnionShareOrdersMonth> queryUnionShareOrdersMonthList(UnionShareOrdersMonthReqBO req);
void clearActivityCache(int activityId);
}
... ...
... ... @@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yoho.service.model.response.UserInfoRspBO;
import com.yoho.unions.common.redis.RedisTemplate;
import com.yoho.unions.helper.UserServiceHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -144,6 +145,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
UnionShareBigDataClickMapper unionShareBigDataClickMapper;
@Resource
RedisValueCache redisValueCache;
@Resource
RedisTemplate redisTemplate;
@Resource( name = "yhProducer")
private YhProducer yhProducer;
@Resource(name = "core-config-reader")
... ... @@ -175,7 +178,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
private String USER_SETTLEMENT_HISTORYSETTLEAMOUNT = "historySettleAmount";
private String USER_SETTLEMENT_HASSETTLEMENT = "hasSettlement";
private String USER_SETTLEMENT_BANKCARD = "bankCard";
//马甲随机增预操作key
private static String VIRTUAL_ADD_KEY = "yh:union:share:virtual:add";
private static final byte STATISTICS_QUERY_TIME_YESTERDAY = 1;
private static final byte STATISTICS_QUERY_TIME_CURRENT_MONTH = 2;
... ... @@ -967,6 +973,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return null;
}
UnionShareOrdersActivity activity=queryActivity(activityLog.getActivityId());
if (activity == null) {
return null;
}
UnionShareOrdersActivityLogsBo activityLogBo = new UnionShareOrdersActivityLogsBo();
activityLogBo.setStatus(unionShareOrders.getStatus());
activityLogBo.setStatusStr(ShareOrdersStatusEnum.getOtherDescByCode(unionShareOrders.getStatus()));
... ... @@ -1103,12 +1112,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
*/
@Override
public UninoShareIncomeRankBo queryRank(UninoShareIncomeRankReqBo req){
logger.info("queryRank,req is {}",req);
UninoShareIncomeRankBo result = new UninoShareIncomeRankBo();
//每月一号0-8点排行榜关闭
Calendar now = Calendar.getInstance();
// int monthday=configReader.getInt(UNION_CPS_RANK_MONTHDAY,1);
// int hour=configReader.getInt(UNION_CPS_RANK_HOUR,8);
if (now.get(Calendar.DAY_OF_MONTH) == 1 && now.get(Calendar.HOUR_OF_DAY) < 8) {
logger.info("queryRank end");
return result;
}
//查询排行榜
... ... @@ -1116,6 +1127,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (req.getUid() != null) {
//查询用户的数据
logger.info("queryRank,getRankInfo,req is {}",req);
UninoShareIncomeBo rankInfo=getRankInfo(req.getUid(), date, req.getType());
if (rankInfo == null) {
//可能是zk开关关闭
... ... @@ -1123,6 +1135,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
BeanUtils.copyProperties(rankInfo,result);
}
logger.info("queryRank,queryRankList,req is {}",req);
UninoShareIncomeRankBo rankList = queryRankList(date, req.getType(), req.getPage(), req.getSize());
if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
result.setRankList(rankList.getRankList());
... ... @@ -1132,50 +1145,63 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
// 获取排行榜数据
private UninoShareIncomeRankBo queryRankList(int date,Integer type,int page,int size){
logger.info("queryRankList,date is {},type is {},page is {},size is {}.",date,type,page,size);
//查询zk中cps达人排行开关
if (!configReader.getBoolean(UNION_CPS_RANK_LIST_SWITCH, true)) {
logger.info("queryRankList end,zk close,date is {},type is {},page is {},size is {}.",date,type,page,size);
return null;
}
//date 具体到日:20180814
int start = page > 1 ? (page - 1) * size : 0;
UninoShareIncomeRankBo cacheRank=getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, type.toString(), "" + start, "" + size);
if (cacheRank != null && CollectionUtils.isNotEmpty(cacheRank.getRankList().getList())) {
if (cacheRank != null && cacheRank.getRankList()!=null) {
logger.info("queryRankList,date is {},type is {},page is {},size is {}.get cache {}",date,type,page,size,cacheRank);
return cacheRank;
}
PageResponseBO<UninoShareIncomeBo> pagelist = new PageResponseBO<>();
if(start>0||size<RANK_LIST_MAX_NUM){
cacheRank = getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, "" + type, "" + 0, "" + RANK_LIST_MAX_NUM);
logger.info("queryRankList,date is {},type is {},page is {},size is {}.get ranklist cache {}",date,type,page,size,cacheRank);
}
PageResponseBO<UninoShareIncomeBo> ranklist = new PageResponseBO<>();
PageResponseBO<UninoShareIncomeBo> ranklist;
if (cacheRank == null||CollectionUtils.isEmpty(cacheRank.getRankList().getList())) {
ranklist = queryRankListFromSql(date, type, RANK_LIST_MAX_NUM);
}else {
ranklist = cacheRank.getRankList();
}
if (ranklist == null||CollectionUtils.isEmpty(ranklist.getList())) {
return null;
}
pagelist = new PageResponseBO<>();
int toIndex = start + size - 1;
int toIndex = start + size;
if (toIndex > ranklist.getList().size()) {
toIndex = ranklist.getList().size();
}
pagelist.setList(ranklist.getList().subList(start, toIndex));
if (start < toIndex) {
pagelist.setList(ranklist.getList().subList(start, toIndex));
}
List<UninoShareIncomeBo> uninoShareIncomeBos = ranklist.getList().subList(start, start);
pagelist.setPage(page > 1 ?page:1);
pagelist.setSize(size);
pagelist.setTotal(pagelist.getList().size());
pagelist.setTotal(ranklist.getList().size());
UninoShareIncomeRankBo uninoShareIncomeRankBo = new UninoShareIncomeRankBo(pagelist);
logger.info("queryRankList,date is {},type is {},page is {},size is {}.add to redis {}",date,type,page,size,uninoShareIncomeRankBo);
addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,uninoShareIncomeRankBo,""+type,""+start,""+size);
return uninoShareIncomeRankBo;
}
//获取用户达人排行个人信息
private UninoShareIncomeBo getRankInfo(Integer uid,int date,Integer type) {
logger.info("getRankInfo,uid is {},date is {},type is {}",uid,date,type);
//查询zk中cps达人排行个人信息开关
if (!configReader.getBoolean(UNION_CPS_RANK_INFO_SWITCH, true)) {
logger.info("getRankInfo end,zk close,uid is {},date is {},type is {}",uid,date,type);
return null;
}
UninoShareIncomeBo rankInfo = getFromRedis(ShareOrdersKeyEnum.RANK_INFO,date,UninoShareIncomeBo.class,uid.toString(), type.toString());
UninoShareIncomeBo rankInfo = getFromRedis(ShareOrdersKeyEnum.RANK_INFO,uid,UninoShareIncomeBo.class,""+date, type.toString());
if (rankInfo != null) {
logger.info("getRankInfo,uid is {},date is {},type is {},get cache",uid,date,type,rankInfo);
return rankInfo;
}
//
... ... @@ -1183,6 +1209,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
for (UninoShareIncomeBo bo : rankList.getRankList().getList()) {
if (bo.getUid() == uid) {
logger.info("getRankInfo,uid is {},date is {},type is {},addToRedis {}",uid,date,type,bo);
addToRedis(ShareOrdersKeyEnum.RANK_INFO,uid,bo,""+date, type.toString());
return bo;
}
}
... ... @@ -1193,18 +1221,23 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
amount = new BigDecimal(0);
}
rankInfo.setAmount(amount);
DecimalFormat df = new DecimalFormat("0.00");
rankInfo.setAmountStr("¥"+df.format(rankInfo.getAmount()));
// DecimalFormat df = new DecimalFormat("0.00");
// rankInfo.setAmountStr("¥"+df.format(rankInfo.getAmount()));
rankInfo.setAmountStr("¥"+rankInfo.getAmount());
logger.info("getRankInfo,uid is {},date is {},type is {},getUserInfoFromUic",uid,date,type);
UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(uid);
if (userInfoRspBO != null) {
rankInfo.setImage(userInfoRspBO.getHeadIco());
rankInfo.setNickname(userInfoRspBO.getNickname());
}
addToRedis(ShareOrdersKeyEnum.RANK_INFO,date,rankInfo,uid.toString(), type.toString());
rankInfo.setUid(uid);
logger.info("getRankInfo,uid is {},date is {},type is {},addToRedis {}",uid,date,type,rankInfo);
addToRedis(ShareOrdersKeyEnum.RANK_INFO,uid,rankInfo,""+date, type.toString());
return rankInfo;
}
private PageResponseBO<UninoShareIncomeBo> queryRankListFromSql(int date,int type,int maxSize) {
logger.info("queryRankListFromSql,date is {},type is {},maxSize is {}",date,type,maxSize);
List<UninoShareIncomeBo> list;
int monthDate = date / 100;//date 具体到日:20180814
if (type==1) {//1-本月,2-全部
... ... @@ -1215,11 +1248,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (CollectionUtils.isEmpty(list)) {
return null;
}
DecimalFormat df = new DecimalFormat("0.00");
// DecimalFormat df = new DecimalFormat("0.00");
for (int i = 0; i < list.size(); i++) {
UninoShareIncomeBo uninoShareIncomeBo = list.get(i);
uninoShareIncomeBo.setRankNum(i+1);
uninoShareIncomeBo.setAmountStr("¥"+df.format(uninoShareIncomeBo.getAmount()));
// uninoShareIncomeBo.setAmountStr("¥"+df.format(uninoShareIncomeBo.getAmount()));
uninoShareIncomeBo.setAmountStr("¥"+uninoShareIncomeBo.getAmount());
}
PageResponseBO<UninoShareIncomeBo> pageList = new PageResponseBO<>();
pageList.setList(list);
... ... @@ -1227,6 +1261,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
pageList.setSize(list.size());
pageList.setTotal(list.size());
addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,new UninoShareIncomeRankBo(pageList),""+type,"0",""+RANK_LIST_MAX_NUM);
logger.info("queryRankListFromSql,date is {},type is {},maxSize is {},pageList is {}",date,type,maxSize,pageList);
return pageList;
}
... ... @@ -1302,6 +1337,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 获取订单参与的满单返活动返利单
* */
private UnionShareOrders getRelatedActivityOrder(UnionShareOrders unionShareOrders) {
logger.info("getRelatedActivityOrder,unionShareOrders is {}.",unionShareOrders);
UnionShareOrdersActivity activity = queryActivity(unionShareOrders.getExtraActivityId());
if (null == activity || activity.getType() != 3) {
return null;
... ... @@ -1318,6 +1354,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 获取订单参与的满单返活动日志
* */
private UnionShareOrdersActivityLogs getRelatedActivityLogs(UnionShareOrders unionShareOrders) {
logger.info("getRelatedActivityLogs,unionShareOrders is {}.",unionShareOrders);
UnionShareOrders activityOrder = getRelatedActivityOrder(unionShareOrders);
if (null == activityOrder) {
return null;
... ... @@ -1326,6 +1363,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
private UnionShareOrdersActivityLogs getLogsByOrderId(int orderId) {
logger.info("getLogsByOrderId,orderId is {}.",orderId);
List<UnionShareOrdersActivityLogs> activityLogs=unionShareOrdersActivityLogsMapper.selectByOrderId(orderId);
if (CollectionUtils.isEmpty(activityLogs)) {
return null;
... ... @@ -1337,7 +1375,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 判断是否需要重新处理订单相关的满单返活动
* */
private void rehandExtraActivity(UnionShareOrders unionShareOrders) {
logger.info("rehandExtraActivity,unionShareOrders is {}.",unionShareOrders);
//判断满返是否作废,若作废,查询是否满足该活动其他门槛条件
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(unionShareOrders);
if (null == activityLog) {
... ... @@ -1345,8 +1383,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
List<String> orderCodeList = Arrays.stream(activityLog.getOrders().split(",")).collect(Collectors.toList());
// 获取参与此活动的有效订单
logger.info("rehandExtraActivity,unionShareOrders is {},selectListByOrderCodesForActivity,orderCodeList is {}.",unionShareOrders,orderCodeList);
List<UnionShareOrders> orderList = unionShareOrdersMapper.selectListByOrderCodesForActivity(orderCodeList);
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityItemId());
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityId(),activityLog.getActivityItemId());
if (orderList.size() <item.getOrderMinNum()) {
reJoinExtraActivity(activityLog);
}
... ... @@ -1354,6 +1393,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//把活动参与日志状态作废
private void invalidActivityLog(int logId,int now) {
logger.info("invalidActivityLog,logId is {},now is {}.",logId,now);
UnionShareOrdersActivityLogs updatelogs = new UnionShareOrdersActivityLogs();
updatelogs.setId(logId);
updatelogs.setStatus(0);//类型:1-有效,0-作废
... ... @@ -1362,6 +1402,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
private boolean reJoinExtraActivity(UnionShareOrdersActivityLogs activityLog){
logger.info("reJoinExtraActivity,activityLog is {}",activityLog);
int now = DateUtil.getCurrentTimeSecond();
//作废已参加的满单活动
invalidActivityLog(activityLog.getId(), now);
... ... @@ -1381,6 +1422,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 尝试更新订单参与的,满返活动单的状态
* */
private boolean changeExtraActivityStatus(UnionShareOrders unionShareOrders) {
logger.info("changeExtraActivityStatus,unionShareOrders is {}.",unionShareOrders);
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(unionShareOrders);
if (null == activityLog) {
return false;
... ... @@ -1388,6 +1430,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
int now = DateUtil.getCurrentTimeSecond();
List<String> orderCodeList = Arrays.stream(activityLog.getOrders().split(",")).collect(Collectors.toList());
// 获取参与此活动的有效订单
logger.info("changeExtraActivityStatus,unionShareOrders is {},selectListByOrderCodesForActivity orderCodeList is {}.",unionShareOrders,orderCodeList);
List<UnionShareOrders> orderList = unionShareOrdersMapper.selectListByOrderCodesForActivity(orderCodeList);
for(UnionShareOrders order :orderList ) {
if (order.getStatus().equals(ShareOrdersStatusEnum.PAY.getCode())) {
... ... @@ -1395,12 +1438,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return false;
}
}
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityItemId());
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityId(),activityLog.getActivityItemId());
if (orderList.size() < item.getOrderMinNum()) {
//订单有效数不符合参加的满单活动,warn
return reJoinExtraActivity(activityLog);
}
//更新满返单状态为可结算
logger.info("changeExtraActivityStatus,try to change status,unionShareOrders is {}.",unionShareOrders);
unionShareOrdersMapper.updateStatusById(activityLog.getOrderId(), ShareOrdersStatusEnum.PAY.getCode(), ShareOrdersStatusEnum.CAN_SETTLE.getCode(), now);
//清缓存
return true;
... ... @@ -1410,20 +1454,25 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//处理已结束等待发放奖励的活动
@Override
public void dealWithWaitActivity(UnionShareOrdersActivity activity) {
logger.info("dealWithWaitActivity,activity is {}",activity);
//奖励发放进度:0-未发放,1-发放中,2-已发放
int updateNum = unionShareOrdersActivityMapper.updateStatusById(activity.getId(), 0, 1, DateUtil.getCurrentTimeSecond());
if (updateNum == 0) {
//活动无需处理
logger.info("dealWithWaitActivity end,deal null,activity is {}",activity);
return;
}
int minNum = queryActivityItemMinNum(activity.getId());
//查询可以参与活动的uid组
logger.info("dealWithWaitActivity,activity is {},selectUidList",activity);
List<UnionShareOrdersUidBo> uids=unionShareOrdersMapper.selectUidList(activity.getStartTime(), activity.getEndTime(), minNum);
logger.info("dealWithWaitActivity,activity is {},selectUidList, uids is {}",activity,uids);
uids.forEach(u->{
joinExtraActivity(u.getOrderUid(), u.getPromoteUid(), activity.getId());
});
//发放完成
logger.info("dealWithWaitActivity over,activity is {},begin to change status to 2.",activity);
unionShareOrdersActivityMapper.updateStatusById(activity.getId(), 1, 2, DateUtil.getCurrentTimeSecond());
return ;
}
... ... @@ -1431,42 +1480,72 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//查询已结束等待发放奖励的活动
@Override
public List<UnionShareOrdersActivity> queryWaitActivity() {
//todo 读写缓存
logger.info("queryWaitActivity.");
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectWaitListByDate(DateUtil.getCurrentTimeSecond());
return activities;
}
//查询进行中的活动
private List<UnionShareOrdersActivity> queryActivity() {
//todo 读写缓存
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
logger.info("queryActivity.");
List<UnionShareOrdersActivity> activities = redisValueCache.get(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey(), List.class);
if (CollectionUtils.isNotEmpty(activities)) {
logger.info("queryActivity.get chache {}",activities);
return activities;
}
activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
if (CollectionUtils.isEmpty(activities)) {
return new ArrayList<>();
}
logger.info("queryActivity.add to redis.value is {}",activities);
redisValueCache.set(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey(),activities,ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getCacheTime(),TimeUnit.SECONDS);
return activities;
}
//获取某时间段可参与活动的单数
private List<UnionShareOrders> queryUidActivity(int orderUid,int promoteUid,int beginTime,int endTime) {
//todo 读写缓存
logger.info("queryUidActivity,orderUid is {},promoteUid is {},beginTime is {},endTime is {}.",orderUid,promoteUid,beginTime,endTime);
List<UnionShareOrders> orders = unionShareOrdersMapper.selectListByOrderUidForActivity(beginTime, endTime, orderUid,promoteUid);
return orders;
}
//获取某时间段可参与活动的单数
//查询分享人和下单人关联订单参与的满单返活动单
private UnionShareOrders queryOrderActivity(int orderUid,int promoteUid,int activityId) {
//todo 读写缓存
logger.info("queryOrderActivity,orderUid is {},promoteUid is {},activityId is {}",orderUid,promoteUid,activityId);
UnionShareOrders activityOrder = unionShareOrdersMapper.selectActivityOrderByUid(activityId, orderUid,promoteUid);
return activityOrder;
}
private UnionShareOrdersActivity queryActivity(Integer activityId) {
logger.info("queryActivity,activityId is {}",activityId);
if (activityId == null || activityId == 0) {
return null;
}
//todo 读写缓存
UnionShareOrdersActivity activity = unionShareOrdersActivityMapper.selectByPrimaryKey(activityId);
UnionShareOrdersActivity activity = getFromRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,UnionShareOrdersActivity.class,"activity","0");
if (activity != null) {
logger.info("queryActivity,activityId is {},get cache {}",activityId,activity);
return activity;
}
activity = unionShareOrdersActivityMapper.selectByPrimaryKey(activityId);
if (activity == null) {
return null;
}
logger.info("queryActivity,activityId is {},add to redis, value is {}",activityId,activity);
addToRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,activity,"activity","0");
return activity;
}
private UnionShareOrdersActivityItem queryActivityItem(int activityItemId) {
//todo 读写缓存
UnionShareOrdersActivityItem item = unionShareOrdersActivityItemMapper.selectByPrimaryKey(activityItemId);
private UnionShareOrdersActivityItem queryActivityItem(int activityId,Integer activityItemId) {
logger.info("queryActivityItem,activityItemId is {}",activityItemId);
UnionShareOrdersActivityItem item = getFromRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,UnionShareOrdersActivityItem.class,"item",activityItemId.toString());
if (item != null) {
logger.info("queryActivityItem,activityItemId is {},get cache {}",activityItemId,item);
return item;
}
item = unionShareOrdersActivityItemMapper.selectByPrimaryKey(activityItemId);
if (item == null) {
return null;
}
logger.info("queryActivityItem,activityItemId is {},add to redis, value is {}",activityItemId,item);
addToRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,item,"item",activityItemId.toString());
return item;
}
... ... @@ -1474,8 +1553,18 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 查询满x单返活动条目(正常状态)
* */
private List<UnionShareOrdersActivityItem> queryActivityItemList(int activityId) {
//todo 读写缓存
List<UnionShareOrdersActivityItem> items = unionShareOrdersActivityItemMapper.selectByActivityId(activityId);
logger.info("queryActivityItemList,activityId is {}",activityId);
List<UnionShareOrdersActivityItem> items = getFromRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,List.class,"list","0");
if (CollectionUtils.isNotEmpty(items)) {
logger.info("queryActivityItemList,activityId is {},get chache {}",activityId,items);
return items;
}
items = unionShareOrdersActivityItemMapper.selectByActivityId(activityId);
if (CollectionUtils.isEmpty(items)) {
return new ArrayList<>();
}
logger.info("queryActivityItemList,activityId is {},add to redis.value is {}",activityId,items);
addToRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,items,"list","0");
return items;
}
... ... @@ -1483,18 +1572,34 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 查询满x单返活动条目(正常状态)最低满单数
* */
private Integer queryActivityItemMinNum(int activityId) {
logger.info("queryActivityItemMinNum,activityId is {}",activityId);
Integer num = getFromRedis(ShareOrdersKeyEnum.ACTIVITY, activityId, Integer.class, "min", "0");
if (num != null) {
return num;
}
//todo 读写缓存
return unionShareOrdersActivityItemMapper.selectMinNumByActivityId(activityId);
num = unionShareOrdersActivityItemMapper.selectMinNumByActivityId(activityId);
if (num == null) {
//不该出现此情况
logger.info("queryActivityItemMinNum,can not find min,activityId is {}",activityId);
num = 1;
}
addToRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,num,"num","0");
return num;
}
@Override
public void clearActivityCache(int activityId) {
//todo 清除某活动缓存
redisTemplate.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey());
redisHashCache.delete(ShareOrdersKeyEnum.ACTIVITY.getPreKey(),activityId);
}
/**
* 参加满x单额外返活动
* */
public boolean joinExtraActivity(int orderUid ,int promoteUid ,int activityId){
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
UnionShareOrdersActivity activity = queryActivity(activityId);
if (null == activity || activity.getType() != 3) {
return false;
... ... @@ -1561,6 +1666,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* 参加加倍返活动
* */
private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity) {
logger.info("participateActivity,order is {},activity is {}",order,activity);
//1、判断是否符合活动条件
//1.1 活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
if (activity.getType() == 3) {
... ... @@ -1572,6 +1678,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//活动为新人专享,但是订单不是首单
return false;
}
//1.3 是否活动期间
int now = DateUtil.getCurrentTimeSecond();
if (activity.getStartTime() > now || activity.getEndTime() < now) {
return false;
}
//2、参加活动
//2.1 返利金额计算
BigDecimal extraAmount = activity.getAmount();
... ... @@ -1602,6 +1713,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
log.setStatus(1);
log.setOrders(order.getOrderCode());
log.setId(null);
logger.info("participateActivity,order is {},activity is {},log is {}",order,activity,log);
unionShareOrdersActivityLogsMapper.insertSelective(log);
//3 更新订单返利金额
... ... @@ -1611,6 +1723,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
updateOrder.setExtraAmount(order.getExtraAmount());
updateOrder.setActivityId(activity.getId());
updateOrder.setActivityName(activity.getActivityName());
logger.info("participateActivity,order is {},activity is {},updateOrder is {}",order,activity,updateOrder);
unionShareOrdersMapper.updateByPrimaryKeySelective(updateOrder);
//4、返回
... ... @@ -2155,13 +2268,15 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
@Override
@Database(ForceMaster = true)
public void updateMonthData(int promoteUid, Set<String> date){
logger.info("updateMonthData promoteUid is {},dates is {}.",promoteUid,date);
date.forEach(d->{
updateOneMonthData(promoteUid, d);
});
redisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),promoteUid);
}
private void updateOneMonthData(int promoteUid, String date){
//todo
logger.info("updateOneMonthData promoteUid is {},date is {}.",promoteUid,date);
Integer dateInt = Integer.valueOf(date);
Calendar time = Calendar.getInstance();
time.setTime(DateUtil.stringToDate(date, "yyyyMM"));
... ... @@ -2169,14 +2284,17 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
time.add(Calendar.DAY_OF_MONTH,1);
int endTime=((int) time.getTimeInMillis()/1000)-1;
UnionShareOrdersMonth unionShareOrdersMonth = getMonthData(promoteUid,dateInt);
//查询cps订单表中此月的预估收益
UnionShareOrdersMonth month=unionShareOrdersMapper.selectMonthData(promoteUid, beginTime, endTime);
if (month == null|| month.getAmount()==null) {
if (unionShareOrdersMonth != null) {
//月预估收益清了
//此月预估收益为空,需要清了旧的此月预估数据
logger.info("updateOneMonthData promoteUid is {},date is {}.need to delete data",promoteUid,date);
deleteMonthData(unionShareOrdersMonth.getId());
}
return;
}
logger.info("updateOneMonthData,getUserInfoFromUic, promoteUid is {},date is {}.",promoteUid,date);
UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(promoteUid);
if (userInfoRspBO != null) {
month.setImage(userInfoRspBO.getHeadIco());
... ... @@ -2187,17 +2305,20 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
month.setUpdateTime(DateUtil.getCurrentTimeSecond());
if (unionShareOrdersMonth != null) {
//月预估收益更新
logger.info("updateOneMonthData,updateByUidAndMonth, promoteUid is {},date is {},update data is {}.",promoteUid,date,month);
int result=unionShareOrdersMonthMapper.updateByUidAndMonth(month);
if (result > 0) {
return;
}
}
month.setCreateTime(month.getUpdateTime());
logger.info("updateOneMonthData,insertSelective, promoteUid is {},date is {},insert data is {}.",promoteUid,date,month);
unionShareOrdersMonthMapper.insertSelective(month);
}
private UnionShareOrdersMonth getMonthData(int promoteUid, int date) {
logger.info("getMonthData promoteUid is {},date is {}.",promoteUid,date);
List<UnionShareOrdersMonth> unionShareOrdersMonth = unionShareOrdersMonthMapper.selectMonthData(date, promoteUid,1);
if (unionShareOrdersMonth == null ) {
return null;
... ... @@ -2209,6 +2330,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
private void deleteMonthData(int id) {
logger.info("deleteMonthData id is {}.",id);
unionShareOrdersMonthMapper.deleteByPrimaryKey(id);
}
... ... @@ -2217,7 +2339,38 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* */
@Override
public void dealWithVirtualUserTask(UnionShareVirtualAddBo bo){
//todo
// 查询当月100个马甲用户随机增0-499
int date = Integer.valueOf(DateUtil.getToday("yyyyMMdd"));
List<UnionShareOrdersMonth> unionShareOrdersMonths = unionShareOrdersMonthMapper.selectVirtualMonthData(date/100);
if (CollectionUtils.isEmpty(unionShareOrdersMonths)) {
logger.info("dealWithVirtualUserTask end.Virtual data is null.bo is {},today is {}",bo,date);
return;
}
logger.info("dealWithVirtualUserTask.bo is {},today is {},deal num is {}",bo,date,unionShareOrdersMonths.size());
unionShareOrdersMonths.forEach(un->{
int i = new Random().nextInt(499);
if (i == 0) {
return;
}
un.setAmount(un.getOrderAmount().add(new BigDecimal(i)));
un.setUpdateTime(DateUtil.getCurrentTimeSecond());
unionShareOrdersMonthMapper.updateByPrimaryKeySelective(un);
});
logger.info("dealWithVirtualUserTask.bo is {},today is {},clear redis",bo,date);
redisTemplate.delete(VIRTUAL_ADD_KEY);
redisHashCache.delete(ShareOrdersKeyEnum.RANK_LIST.getPreKey(),date);
logger.info("dealWithVirtualUserTask.bo is {},today is {},clear redis end",bo,date);
}
//后台操作向redis塞待执行任务
@Override
public void setVirtualAddToRedis() {
logger.info("setVirtualAddToRedis.");
int date = Integer.valueOf(DateUtil.getToday("yyyyMMdd"));
UnionShareVirtualAddBo addBo = new UnionShareVirtualAddBo();
addBo.setDate(date);
addBo.setTime(DateUtil.getCurrentTimeSecond());
logger.info("setVirtualAddToRedis.add to redis,addBo is {}",addBo);
redisValueCache.set(VIRTUAL_ADD_KEY,addBo,50,TimeUnit.HOURS);
}
//todo 后台操作向redis塞待执行任务
}
... ...
... ... @@ -25,7 +25,7 @@ public class CpsOrderExtraActivityTask {
IUnionShareService unionShareService;
// 每天08:30执行
@Scheduled(cron = "* 30 8 * * ?")
@Scheduled(cron = "0 30 8 * * ?")
public void run() {
logger.info("start giving out extra rewards");
//查询已结束未发放奖励的满x单返活动
... ...
... ... @@ -32,16 +32,18 @@ public class CpsVirtualUserTask {
private static String VIRTUAL_ADD_KEY = "yh:union:share:virtual:add";
// 每天07:30执行
@Scheduled(cron = "* 30 7 * * ?")
@Scheduled(cron = "1 55 7 * * ?")
// @Scheduled(cron = "10/25 59 14 * * ?")
public void run() {
logger.info("CpsVirtualUserTask.run,query redis for virtual.");
//查询是否有随机增是预操作
UnionShareVirtualAddBo addBo=redisValueCache.get(VIRTUAL_ADD_KEY, UnionShareVirtualAddBo.class);
if (addBo == null) {
logger.info("CpsVirtualUserTask.run,query redis for virtual end.does not need");
return;
}
logger.info("CpsVirtualUserTask.run,start to deal with {}.",addBo);
//todo 随机增当月数据
//随机增当月数据
unionShareService.dealWithVirtualUserTask(addBo);
}
... ...
... ... @@ -136,6 +136,23 @@
batchImportDialog();
}
});
$("#randomButton").linkbutton({
onClick : function() {
$.get(contextPath + "/UnionShareRest/addVirtual", function (res) {
$.messager.progress("close");
if (res.code == 200) {
$.messager.show({
title: "提示",
msg: "将于早上八点增加马甲用户的预估收入",
height: 120
});
} else {
$.messager.alert("失败", res.message, "error");
}
}, "json");
}
});
function batchImportDialog() {
var div = $("<div id='batchImportDialogDiv'>").appendTo($(document.body));
... ...