Commit 7d0ef571 7d0ef5712e8394b37157b38ab5fed9164e2a5309 by xianghan

1.优化任务处理过程

1 parent c177b36a
Showing 22 changed files with 339 additions and 98 deletions
......@@ -5,7 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author XiangHan
......@@ -15,7 +17,7 @@ public interface CouponHistoryRepository extends JpaRepository<CouponHistory, Lo
Long countByUserId(Long userId);
Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now);
Long countByUserIdAndExpireTimeBefore(Long userId, Date now);
Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime);
Long countByUserIdAndExpireTimeBetween(Long userId, Date now, Date expireTime);
}
......
......@@ -3,6 +3,7 @@ package com.topdraw.business.module.coupon.history.service;
import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
......
......@@ -2,6 +2,7 @@ package com.topdraw.business.module.coupon.history.service.impl;
import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import com.topdraw.business.module.coupon.history.domain.CouponHistoryBuilder;
import com.topdraw.util.LocalDateTimeUtil;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.coupon.history.repository.CouponHistoryRepository;
import com.topdraw.business.module.coupon.history.service.CouponHistoryService;
......@@ -12,7 +13,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/**
* @author XiangHan
......@@ -49,12 +54,13 @@ public class CouponHistoryServiceImpl implements CouponHistoryService {
@Override
public Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now) {
return this.couponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now);
return this.couponHistoryRepository.countByUserIdAndExpireTimeBefore(userId, LocalDateTimeUtil.LocalDateTime2Date(now));
}
@Override
public Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime) {
return this.couponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime);
return this.couponHistoryRepository.countByUserIdAndExpireTimeBetween(userId, LocalDateTimeUtil.LocalDateTime2Date(now)
, LocalDateTimeUtil.LocalDateTime2Date(expireTime));
}
}
......
......@@ -34,7 +34,7 @@ public class CouponServiceImpl implements CouponService {
Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL);
Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new);
ValidationUtil.isNull(coupon.getId(),"Coupon","id",id);
// ValidationUtil.isNull(coupon.getId(),"Coupon","id",id);
return this.couponMapper.toDto(coupon);
}
......
......@@ -30,7 +30,7 @@ public class Member implements Serializable {
private String platformAccount;
/** 会员过期时间 */
@Column(name = "vip_expire_time", nullable = false)
@Column(name = "vip_expire_time")
private Timestamp vipExpireTime;
/** 主键 */
......@@ -41,15 +41,15 @@ public class Member implements Serializable {
private Long id;
/** 标识 */
@Column(name = "code", nullable = false)
@Column(name = "code")
private String code;
/** 类型 1:大屏;2:小屏 */
@Column(name = "`type`", nullable = false)
@Column(name = "`type`")
private Integer type;
/** 状态 0:不可用;1:可用 */
@Column(name = "`status`", nullable = false)
@Column(name = "`status`")
private Integer status;
/** 昵称 base64 */
......@@ -61,7 +61,7 @@ public class Member implements Serializable {
private String description;
/** 性别 0:女;1:男;-1:未知 */
@Column(name = "gender", nullable = false)
@Column(name = "gender")
private Integer gender;
/** 生日 */
......@@ -81,11 +81,11 @@ public class Member implements Serializable {
private String tags;
/** 是否会员 0:非会员;1:会员 */
@Column(name = "vip", nullable = false)
@Column(name = "vip")
private Integer vip;
/** 会员等级(对应level表的level字段,非id) */
@Column(name = "`level`", nullable = false)
@Column(name = "`level`")
private Integer level;
/** 成长值 */
......
......@@ -3,7 +3,11 @@ package com.topdraw.business.module.member.repository;
import com.topdraw.business.module.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
......@@ -18,4 +22,25 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
List<Member> findByUserIptvId(Long id);
Optional<Member> findByIdOrCode(Long id,String code);
@Modifying
@Query(value = "UPDATE `uc_member` SET `user_iptv_id` = ?2, `update_time` = ?3 , `bind_iptv_platform_type`= 0, " +
"`bind_iptv_time`=?3 WHERE `id` = ?1", nativeQuery = true)
void updateUserIptvIdById(Long id, Long userIptvId, LocalDateTime now);
@Modifying
@Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, `level` = :#{#resources.level} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void updateExpAndLevel(@Param("resources") Member member);
@Modifying
@Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `due_points` = :#{#resources.duePoints} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void updatePointAndDuePoint(@Param("resources") Member resources);
@Modifying
@Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, `due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " +
" WHERE `id` = :#{#resources.id}", nativeQuery = true)
void doUpdateMemberCoupon(@Param("resources") Member member);
}
......
......@@ -115,15 +115,40 @@ public class MemberServiceImpl implements MemberService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public MemberDTO doUpdateMemberExpAndLevel(Member resources) {
MemberDTO memberDTO = this.update(resources);
this.redisUtils.doLock("member::code" + resources.getCode());
try {
MemberDTO memberDTO = this.findById(resources.getId());
if (Objects.nonNull(memberDTO)) {
this.memberRepository.updateExpAndLevel(resources);
}
return memberDTO;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("member::code" + resources.getCode());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public MemberDTO doUpdateMemberCoupon(Member member) {
MemberDTO memberDTO = this.update(member);
// MemberDTO memberDTO = this.update(member);
this.redisUtils.doLock("member::code" + member.getCode());
try {
MemberDTO memberDTO = this.findById(member.getId());
if (Objects.nonNull(memberDTO)) {
this.memberRepository.doUpdateMemberCoupon(member);
}
return memberDTO;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("member::code" + member.getCode());
}
}
@Override
......@@ -188,21 +213,24 @@ public class MemberServiceImpl implements MemberService {
@Transactional(rollbackFor = Exception.class)
public MemberDTO doUpdateMemberPoints(Member resources) {
try {
this.redisUtils.doLock("member::update::code" + resources.getCode());
this.redisUtils.doLock("member::code" + resources.getCode());
Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new);
ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
/*ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
member.copy(resources);
Member _member = this.save(member);
Member _member = this.save(member);*/
MemberDTO memberDTO = this.findById(resources.getId());
if (Objects.nonNull(memberDTO)) {
this.memberRepository.updatePointAndDuePoint(resources);
}
return this.memberMapper.toDto(_member);
return memberDTO;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("member::update::code" + resources.getCode());
this.redisUtils.doUnLock("member::code" + resources.getCode());
}
}
......
......@@ -5,8 +5,16 @@ public enum RightType {
POINTS,
/**成长值*/
EXP,
/**优惠券*/
/**优惠券*/
COUPON,
/**活动机会*/
ACTIVITYCHANCE,
/**积分商品*/
POINTGOODS,
/**IPTV产品包*/
IPTVPRODUCT,
/**IPTV观影权益 */
IPTVVIEW,
/**权益统称*/
RIGHTS
......
......@@ -7,6 +7,7 @@ import com.topdraw.business.module.task.service.dto.TaskDTO;
import com.topdraw.business.process.domian.TempIptvUser;
import com.topdraw.business.process.service.TaskOperationService;
import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria;
import com.topdraw.common.IResultInfo;
import com.topdraw.common.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -36,9 +37,16 @@ public class TaskOperationController {
@PostMapping(value = "/dealTask")
@ApiOperation("事件处理")
@AnonymousAccess
public void dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) {
public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) {
log.info("事件处理,开始,参数 ==>> {}", criteria);
long l = System.currentTimeMillis();
// 任务处理
this.taskOperationService.dealTask(criteria.getContent());
long l2 = System.currentTimeMillis();
log.info("事件处理,结束,总耗时 ==>> {}", (l2-l));
return ResultInfo.success();
}
/**
......
......@@ -14,18 +14,20 @@ import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
@Service
@Slf4j
public class CouponOperationServiceImpl implements CouponOperationService {
@Autowired
......@@ -40,9 +42,6 @@ public class CouponOperationServiceImpl implements CouponOperationService {
MemberService memberService;
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private RedisUtils redisUtils;
// 过期阀值(默认一个月)
......@@ -97,24 +96,26 @@ public class CouponOperationServiceImpl implements CouponOperationService {
Long memberId = tempCoupon.getMemberId();
Integer rightsAmount = tempCoupon.getRightsAmount();
try {
this.redisUtils.doLock("refreshMemberCoupon:" + memberId.toString());
// 1.历史总优惠券数量
Long historyCouponCount = this.getTotalHistoryCoupon(memberId);
// 1.当前总优惠券数量
Long totalCouponCount = this.getTotalCoupon(historyCouponCount,rightsAmount);
Long totalCouponCount = this.getTotalCoupon(historyCouponCount, rightsAmount);
// 2.获取已过期的优惠券数量
Long expireCouponCount = this.getTotalExpireCoupon(memberId);
// 3.即将过期的优惠券数量
Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId,EXPIRE_FACTOR_DAY);
Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId, EXPIRE_FACTOR_DAY);
// 4.当前优惠券数量 = 总优惠券-已过期的优惠券
Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount);
Long currentCoupon = this.getCurrentCoupon(totalCouponCount, expireCouponCount);
this.redisUtils.doLock("right::member::id::" + memberId.toString());
// 5.更新用户信息(优惠券数量、即将过期的优惠券数量)
this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("refreshMemberCoupon:" + memberId.toString());
this.redisUtils.doUnLock("right::member::id::" + memberId.toString());
}
}
......@@ -133,8 +134,9 @@ public class CouponOperationServiceImpl implements CouponOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
// BeanUtils.copyProperties(memberDTO,member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setCouponAmount(currentCoupon);
member.setDueCouponAmount(expireSoonCouponCount);
member.setUpdateTime(TimestampUtil.now());
......@@ -178,7 +180,7 @@ public class CouponOperationServiceImpl implements CouponOperationService {
* @return
*/
private Long getTotalExpireCoupon(Long userId) {
return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId,LocalDateTime.now());
return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId, LocalDateTime.now());
}
......
......@@ -8,8 +8,6 @@ import com.topdraw.business.module.member.level.service.MemberLevelService;
import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.points.available.domain.PointsAvailable;
import com.topdraw.business.module.points.detail.domain.PointsDetail;
import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.domian.TempExp;
......@@ -17,16 +15,13 @@ import com.topdraw.util.IdWorker;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
......@@ -34,6 +29,7 @@ import java.util.Objects;
*
*/
@Service
@Slf4j
public class ExpOperationServiceImpl implements ExpOperationService {
@Autowired
......@@ -46,9 +42,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberService memberService;
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private RedisUtils redisUtils;
@AsyncMqSend
......@@ -83,23 +76,27 @@ public class ExpOperationServiceImpl implements ExpOperationService {
*/
private void refresh(TempExp tempExp) {
try {
this.redisUtils.doLock("uc-refresh-exp:" + tempExp.getMemberId());
// 原始积分
// 原始经验值
long originExp = this.getExpByMemberId(tempExp);
// 总积分
log.info("----获取会员当前原始经验值 ==>> {}", originExp);
// 总经验值
long totalExp = this.calculateTotalExp(originExp, tempExp);
// 1.添加成长值记录
// this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp));
log.info("----计算总经验值 ==>> {}", totalExp);
this.redisUtils.doLock("right::member::id::" + tempExp.getMemberId());
// 2.更新成长值与等级
log.info("----更新会员经验值与对应等级 ==>> {}", totalExp);
this.refreshMemberExpAndLevel(tempExp, totalExp);
log.info("----保存经验值历史 ");
this.doInsertExpDetail(tempExp, originExp, totalExp);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("uc-refresh-exp:" + tempExp.getMemberId());
this.redisUtils.doUnLock("right::member::id::" + tempExp.getMemberId());
}
}
......@@ -151,8 +148,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
// BeanUtils.copyProperties(memberDTO, member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setExp(totalExp);
member.setLevel(level);
member.setUpdateTime(TimestampUtil.now());
......
......@@ -139,6 +139,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints);
// 5.即将过期的积分
long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
// 6.更新会员积分信息
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
......@@ -319,9 +321,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start1");
for (TempPoints tempPoints : tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start");
this.refresh(tempPoints);
}
}
......@@ -445,10 +445,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
Long memberId = tempPoints.getMemberId();
log.info("----------->> 会员id ===>>>>" + memberId);
try {
this.redisUtils.doLock("member::id::" + memberId.toString());
// 1.可用总积分
Long currentPoints = this.findAvailablePointsByMemberId(memberId);
log.info("----------->> 可用总积分 --->>>> {}", currentPoints);
log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints);
// 2.计算总积分
Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints);
......@@ -466,6 +466,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints);
this.redisUtils.doLock("right::member::id::" + memberId.toString());
// 6.更新会员的总积分
log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints);
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
......@@ -474,7 +476,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
e.printStackTrace();
throw e;
} finally {
this.redisUtils.doUnLock("member::id::" + memberId.toString());
this.redisUtils.doUnLock("right::member::id::" + memberId.toString());
}
}
......@@ -528,9 +530,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0);
// BeanUtils.copyProperties(memberDTO, member);
member.setId(memberDTO.getId());
member.setCode(memberDTO.getCode());
member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0);
member.setDuePoints(duePoints);
member.setUpdateTime(TimestampUtil.now());
try {
......
......@@ -79,6 +79,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
// 2.创建权益历史对象
List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap);
if (!CollectionUtils.isEmpty(rightsList)) {
log.info("异步保存权益领取历史开始 ==>> [{}]", rightsList);
// 3.保存权益历史
this.doInsertTrRightHistory(rightsList);
}
......@@ -195,23 +196,85 @@ public class RightsOperationServiceImpl implements RightsOperationService {
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
log.info(Thread.currentThread().getName() + "=========>> end");
});*/
this.threadPoolTaskExecutor.execute(() -> {
List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS);
if (!CollectionUtils.isEmpty(tempPointsList)) {
log.info("发放积分开始 ==>> [{}]", tempPointsList);
long l = System.currentTimeMillis();
// 积分
this.grantPoint(tempPointsList);
long l2 = System.currentTimeMillis();
log.info("发放积分结束,总耗时 ==>> {}", (l2 - l));
}
});
this.threadPoolTaskExecutor.execute(()-> {
List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP);
if (!CollectionUtils.isEmpty(tempExpList)) {
log.info("发放成长值开始 ==>> [{}]", tempExpList);
long l = System.currentTimeMillis();
// 成长值
this.grantExp(tempExpList);
long l2 = System.currentTimeMillis();
log.info("发放成长值结束,总耗时 ==>> {}", (l2 - l));
}
});
this.threadPoolTaskExecutor.execute(()-> {
List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON);
if (!CollectionUtils.isEmpty(tempCouponList)) {
log.info("发放优惠券开始 ==>> [{}]", tempCouponList);
long l = System.currentTimeMillis();
// 优惠券
this.grantCoupon(tempCouponList);
long l2 = System.currentTimeMillis();
log.info("发放优惠券结束,总耗时 ==>> {}", (l2 - l));
}
});
// 其他权益
this.threadPoolTaskExecutor.execute(()-> {
log.info("发放其他权益开始 ==>> [{}]", tempRightsMap);
this.grantOtherRight(tempRightsMap);
log.info("发放其他权益结束 ==>> [{}]", tempRightsMap);
});
}
private void grantOtherRight(Map<RightType, Object> tempRightsMap) {
Set<RightType> rightTypes = tempRightsMap.keySet();
if (Objects.nonNull(rightTypes) && CollectionUtils.isEmpty(rightTypes)) {
for (RightType rightType : rightTypes) {
switch (rightType) {
// 活动机会
case ACTIVITYCHANCE:
break;
// 积分商品
case POINTGOODS:
break;
// IPTV产品包
case IPTVPRODUCT:
break;
// IPTV观影权益
case IPTVVIEW:
break;
default:
break;
}
}
}
}
......
......@@ -212,37 +212,59 @@ public class TaskOperationServiceImpl implements TaskOperationService {
DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
Integer event = dataSyncMsg.getEvent();
DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg();
String msgData1 = dataSyncMsg.getMsgData();
DataSyncMsg.MsgData msgData = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
String memberCode = msgData.getMemberCode();
Long memberId = msgData.getMemberId();
long l = System.currentTimeMillis();
if (StringUtils.isNotBlank(memberCode)) {
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
memberId = memberDTO.getId();
}
log.info("获取会员信息 ==>> {}", memberDTO);
// 检查当前会员的黑名单状态
boolean b = this.validatedMemberBlackStatus(memberId);
boolean b = this.validatedMemberBlackStatus(memberDTO);
log.info("会员信息 ==>> {} || 会员id ==>> {} || 黑名单状态 ==>> {}", memberDTO, memberDTO.getId(), memberDTO.getBlackStatus());
if (!b) {
return ResultInfo.forbidden("会员已被加入黑名单");
}
memberId = memberDTO.getId();
}
// 1.通过任务标识获取任务模板,通过模板参数获取具体的模板
TaskTemplate taskTemplate = this.getTaskTemplate(event, dataSyncMsg);
log.info("获取任务模板 taskTemplate ==>> {} ", taskTemplate);
// 2.通过任务模板获取对应的任务列表
List<Task> taskList = this.loadListTaskByTaskTemplate(taskTemplate, dataSyncMsg);
log.info("获取任务 taskList ==>> [{}] ", taskList);
// 4.判断当前用户是否满足任务完成条件
boolean checkResult = this.checkTaskCompletion(memberId, taskList, event, msgData);
log.info("检查当前会员的任务完成情况 ==>> {} , true:未完成", checkResult);
if (checkResult) {
// 5.权益区分(积分、权益、成长值)
Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId, taskList, msgData, dataSyncMsg);
log.info("获取当前任务对应的权益 tempRightsMap ==>> {} ", tempRightsMap);
// 6.风控检查
boolean result = this.checkRiskManagement(memberId,tempRightsMap);
boolean result = this.checkRiskManagement(memberId, tempRightsMap);
log.info("针对各项权益检查当前会员是否达到风控值 ==>> {},true:已达到风控指标 ", result);
if (result) throw new BadRequestException("发放失败,已达风控上限");
long l1 = System.currentTimeMillis();
log.info("各项检查总耗时 ==>> {}", (l1-l));
// 7.权益发放
log.info("下发开始 ==>> {}", tempRightsMap);
long l2 = System.currentTimeMillis();
this.grantRight(tempRightsMap);
long l3 = System.currentTimeMillis();
log.info("下发结束,总耗时 ==>> {}", (l3-l2));
}
return ResultInfo.success();
......@@ -264,12 +286,10 @@ public class TaskOperationServiceImpl implements TaskOperationService {
/**
* 验证会员信息
* @param memberId
* @param memberDTO
* @return
*/
private boolean validatedMemberBlackStatus(Long memberId) {
log.info("validatedMember -->>【memberId】 -->> " + memberId);
MemberDTO memberDTO = this.memberService.findById(memberId);
private boolean validatedMemberBlackStatus(MemberDTO memberDTO) {
Long blackStatus = memberDTO.getBlackStatus();
if (Objects.nonNull(blackStatus) && blackStatus == 1) {
log.error("validatedMember -->> 会员已被加入黑名单 【blackStatus】 -->> " + blackStatus);
......@@ -395,7 +415,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// TODO 权益1发放的策略
Integer rightsSendStrategy = task.getRightsSendStrategy();
// 权益分类
this.getTempRightType(memberDTO,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList);
this.getTempRightType(memberDTO,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList,map);
}
// 权益2
......@@ -405,7 +425,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// TODO 权益2发放的策略
Integer rightsSendStrategy = task.getRightsSendStrategy();
// 权权益分类
this.getTempRightType(memberDTO,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList);
this.getTempRightType(memberDTO,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList,map);
}
// 权益3
......@@ -415,16 +435,16 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// TODO 权益3发放的策略
Integer rightsSendStrategy = task.getRightsSendStrategy();
// 权益分类
this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList);
this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList,map);
}
// 优惠券
if (!CollectionUtils.isEmpty(tempCouponList)) {
/*if (!CollectionUtils.isEmpty(tempCouponList)) {
map.put(RightType.COUPON,tempCouponList);
}
}*/
// 权益
if (!CollectionUtils.isEmpty(rightsList)) {
/*if (!CollectionUtils.isEmpty(rightsList)) {
map.put(RightType.RIGHTS,rightsList);
}
}*/
return map;
}
......@@ -448,7 +468,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* @param rightsList
*/
private void getTempRightType(MemberDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList,
List<TempRights> rightsList) {
List<TempRights> rightsList,Map<RightType,Object> map) {
Long memberId = memberDTO.getId();
String nickname = memberDTO.getNickname();
......@@ -461,20 +481,61 @@ public class TaskOperationServiceImpl implements TaskOperationService {
TempRights tempRights = this.tmpRightsBuild(memberId,memberCode,rightsAmount,rightsDTO);
rightsList.add(tempRights);
if (!CollectionUtils.isEmpty(rightsList)) {
map.put(RightType.RIGHTS,rightsList);
}
// 权益类型
String type = rightsDTO.getEntityType();
switch (type) {
// 优惠券
case "1":
Long entityId = rightsDTO.getEntityId();
if (Objects.nonNull(entityId)) {
CouponDTO couponDTO = this.findCouponById(entityId);
if (Objects.nonNull(couponDTO)) {
Long entityId1 = rightsDTO.getEntityId();
if (Objects.nonNull(entityId1)) {
CouponDTO couponDTO = this.findCouponById(entityId1);
if (Objects.nonNull(couponDTO.getId())) {
// 优惠券
TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname);
tempCouponList.add(tempCoupon);
if (!CollectionUtils.isEmpty(tempCouponList)) {
map.put(RightType.COUPON,tempCouponList);
}
}
}
break;
// 观影券
case "2":
Long entityId2 = rightsDTO.getEntityId();
if (Objects.nonNull(entityId2)) {
CouponDTO couponDTO = this.findCouponById(entityId2);
if (Objects.nonNull(couponDTO.getId())) {
// 优惠券
TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname);
tempCouponList.add(tempCoupon);
if (!CollectionUtils.isEmpty(tempCouponList)) {
map.put(RightType.COUPON,tempCouponList);
}
}
}
break;
// 活动参与机会
case "3":
map.put(RightType.ACTIVITYCHANCE, tempRights);
break;
// 积分商品
case "4":
map.put(RightType.POINTGOODS, tempRights);
break;
// IPTV产品包
case "5":
map.put(RightType.IPTVPRODUCT, tempRights);
break;
// IPTV观影权益
case "6":
map.put(RightType.IPTVVIEW, tempRights);
break;
default:
break;
}
......@@ -911,8 +972,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
private List<Task> pickUpTask(List<Task> taskList,DataSyncMsg dataSyncMsg,Integer type) {
List<Task> taskList1 = new ArrayList<>();
DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg();
String msgData1 = dataSyncMsg.getMsgData();
DataSyncMsg.MsgData msgData = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
if (Objects.nonNull(msgData.getParam())) {
......@@ -1042,8 +1103,9 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* @param event 任务
* @return TaskTemplate 任务模板
*/
private TaskTemplate getTaskTemplate(Integer event, DataSyncMsg msgData) {
DataSyncMsg.MsgData msg = msgData.getMsg();
private TaskTemplate getTaskTemplate(Integer event, DataSyncMsg dataSyncMsg) {
String msgData1 = dataSyncMsg.getMsgData();
DataSyncMsg.MsgData msg = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
if (Objects.nonNull(msg.getParam())) {
......
......@@ -28,7 +28,7 @@ public class DataSyncMsg implements Serializable {
// 发送时间
private LocalDateTime time;
// 消息体
private MsgData msg;
private String msgData;
/**
* 消息体
......
package com.topdraw.util;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class LocalDateTimeUtil {
......@@ -16,6 +19,11 @@ public class LocalDateTimeUtil {
return now+" 23:59:59";
}
public static Date LocalDateTime2Date(LocalDateTime now){
Date date = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
return date;
}
public static void main(String[] args) {
String end = todayEnd();
System.out.println("end ==>> "+end);
......
......@@ -45,7 +45,7 @@ spring:
hibernate:
# 生产环境设置成 none,避免程序运行时自动更新数据库结构
ddl-auto: none
show-sql: true
show-sql: false
servlet:
multipart:
file-size-threshold: 2KB
......@@ -69,7 +69,7 @@ spring:
# publisher-confirms: true #如果对异步消息需要回调必须设置为true
host: 122.112.214.149 # rabbitmq的连接地址
port: 5672 # rabbitmq的连接端口号
virtual-host: member_center_small_chongshu # rabbitmq的虚拟hosthhh
virtual-host: member_center_small_sichuan # rabbitmq的虚拟hosthhh
username: guest # rabbitmq的用户名
password: guest # rabbitmq的密码
publisher-confirms: true #如果对异步消息需要回调必须设置为true
......
......@@ -64,7 +64,7 @@
<!--监控sql日志输出 -->
<logger name="jdbc.sqlonly" level="OFF" additivity="false">
<logger name="jdbc.sqlonly" level="INFO" additivity="false">
<appender-ref ref="console" />
<appender-ref ref="info" />
</logger>
......
......@@ -10,6 +10,9 @@ import com.topdraw.business.module.member.service.MemberService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class CouponServiceTest extends BaseTest {
@Autowired
......@@ -28,6 +31,18 @@ public class CouponServiceTest extends BaseTest {
System.out.println(couponHistoryDTO);
}
@Test
public void countByUserIdAndExpireTimeBefore(){
CouponDTO couponDTO = this.couponService.findById(1L);
System.out.println(couponDTO);
CouponDTO testvxv = this.couponService.getByCode("testvxv");
System.out.println(testvxv);
Long l = this.couponHistoryService.countByUserIdAndExpireTimeBefore(1L, LocalDateTime.now());
System.out.println(l);
}
@Test
public void findHistoryBy(){
CouponHistoryDTO couponHistoryDTO = this.couponHistoryService.findById(130L);
......
......@@ -26,7 +26,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void wechatShare() {
try {
String s = "{\"evt\":\"WECHATSHARE\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"shareCount\\\":2}\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"shareCount\\\":2}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -40,7 +40,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void completeMemberInfo() {
try {
String s = "{\"evt\":\"completeMemberInfo\",\"event\":7,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1, " +
"\"msg\":{\"memberCode\":\"1530105170425733120\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -54,7 +54,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void activity() {
try {
String s = "{\"evt\":\"ACTIVITY\",\"event\":3,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"ACTIVITY\\\":3}\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"ACTIVITY\\\":3}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -68,7 +68,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void order() {
try {
String s = "{\"evt\":\"order\",\"event\":4,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":2," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"GOODS\\\":3}\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"GOODS\\\":3}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -82,7 +82,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void viewing() {
try {
String s = "{\"evt\":\"VIEWING\",\"event\":2,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"playDuration\\\":10}\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"playDuration\\\":10}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -96,7 +96,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void play() {
try {
String s = "{\"evt\":\"PLAY\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"playDuration\\\":60}\"}}";
"\"msgData\":{\"memberCode\":\"1537253277861699584\",\"param\":\"{\\\"playDuration\\\":60}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
String s1 = JSON.toJSONString(pointsQueryCriteria);
......@@ -110,7 +110,7 @@ public class TaskOperationControllerTest extends BaseTest {
public void sign() {
try {
String s = "{\"evt\":\"SIGN\",\"event\":6,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msg\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"SIGN\\\":11}\"}}";
"\"msgData\":{\"memberCode\":\"1530105170425733120\",\"param\":\"{\\\"SIGN\\\":11}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
this.taskOperationController.dealTask(pointsQueryCriteria);
......@@ -119,6 +119,18 @@ public class TaskOperationControllerTest extends BaseTest {
}
}
@Test
public void login() {
try {
String s = "{\"evt\":\"LOGIN\",\"event\":1,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
"\"msgData\":{\"memberCode\":\"1537253315610435584\",\"param\":\"{\\\"CONTINUE_LOGIN\\\":2}\"}}";
TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
pointsQueryCriteria.setContent(s);
this.taskOperationController.dealTask(pointsQueryCriteria);
} catch (Exception e) {
e.printStackTrace();
}
}
......
......@@ -26,7 +26,7 @@ public class TaskOperationServiceTest extends BaseTest {
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
// dataSyncMsg.setMsgData(msgData);
String s = JSON.toJSONString(dataSyncMsg);
this.taskOperationService.dealTask(s);
......
......@@ -28,7 +28,7 @@ public class MqTest extends BaseTest {
msgData.setMemberId(1L);
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
// dataSyncMsg.setMsgData(msgData);
String s = JSON.toJSONString(dataSyncMsg);
amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s);
}
......