Commit 697ec438 697ec438fc3b1dfff9cf7a92684a67c608ee2a7f by xianghan

1.优化

1 parent 0642873b
......@@ -24,6 +24,9 @@ import java.time.LocalDateTime;
@Table(name="m_coupon_history")
public class CouponHistory implements Serializable {
@Transient
private String memberCode;
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -23,6 +23,9 @@ import java.io.Serializable;
@Table(name="uc_exp_detail")
public class ExpDetail implements Serializable {
@Transient
private String memberCode;
/** 主键 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -77,4 +77,18 @@ public interface MemberService {
* @param member 会员
*/
MemberDTO checkMember(Member member);
/**
*
* @param resources
* @return
*/
MemberDTO doUpdateMemberExpAndLevel(Member resources);
/**
*
* @param member
* @return
*/
MemberDTO doUpdateMemberCoupon(Member member);
}
......
......@@ -117,6 +117,18 @@ public class MemberServiceImpl implements MemberService {
}
@Override
public MemberDTO doUpdateMemberExpAndLevel(Member resources) {
MemberDTO memberDTO = this.update(resources);
return memberDTO;
}
@Override
public MemberDTO doUpdateMemberCoupon(Member member) {
MemberDTO memberDTO = this.update(member);
return memberDTO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public MemberDTO create(Member resources) {
......
......@@ -15,7 +15,7 @@ public interface ExpOperationService {
* 任务完成后自动发放成长值
* @param tempExpList
*/
void grantPointsThroughTempExp( List<TempExp> tempExpList);
void grantExpThroughTempExp( List<TempExp> tempExpList);
/**
* 系统手动发放优惠券
......
......@@ -36,7 +36,7 @@ public interface PointsOperationService {
* 积分发放,基于已获得的权益
* @param tempPointsList 已获得的权益
*/
void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList);
void grantPointsThroughTempPoint(List<TempPoints> tempPointsList);
/**
......
......@@ -4,6 +4,7 @@ import com.topdraw.aspect.AsyncMqSend;
import com.topdraw.business.module.coupon.history.domain.CouponHistory;
import com.topdraw.business.module.coupon.history.service.CouponHistoryService;
import com.topdraw.business.module.coupon.service.CouponService;
import com.topdraw.business.module.exp.detail.domain.ExpDetail;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
......@@ -13,6 +14,7 @@ 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 org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
......@@ -46,8 +48,13 @@ public class CouponOperationServiceImpl implements CouponOperationService {
// 过期阀值(默认一个月)
private static final Integer EXPIRE_FACTOR_DAY = 30;
@Override
@AsyncMqSend
public void asyncMemberCoupon(Member member) {}
@AsyncMqSend
public void asyncCouponHistory(CouponHistory couponHistory) {}
@Override
public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) {
// 优惠券领取、使用历史记录表
for (TempCoupon tempCoupon : tempCouponList) {
......@@ -131,7 +138,9 @@ public class CouponOperationServiceImpl implements CouponOperationService {
member.setCouponAmount(currentCoupon);
member.setDueCouponAmount(expireSoonCouponCount);
member.setUpdateTime(TimestampUtil.now());
this.memberOperationService.doUpdateMember(member);
this.memberOperationService.doUpdateMemberCoupon(member);
((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member);
}
private MemberDTO findMemberByMemberId(Long memberId) {
......@@ -194,11 +203,14 @@ public class CouponOperationServiceImpl implements CouponOperationService {
couponHistory.setCouponId(tempCoupon.getId());
couponHistory.setUserId(tempCoupon.getMemberId());
couponHistory.setCouponCode(tempCoupon.getCode());
couponHistory.setMemberCode(tempCoupon.getMemberCode());
couponHistory.setUserNickname(tempCoupon.getUserNickname());
couponHistory.setOrderDetailId(tempCoupon.getOrderId());
couponHistory.setReceiveTime(LocalDateTime.now());
couponHistory.setUseStatus(Objects.nonNull(couponHistory.getUseStatus()) ? couponHistory.getUseStatus():0);
this.couponHistoryService.create(couponHistory);
((CouponOperationServiceImpl) AopContext.currentProxy()).asyncCouponHistory(couponHistory);
}
......
......@@ -8,6 +8,8 @@ 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,6 +19,7 @@ import com.topdraw.utils.RedisUtils;
import com.topdraw.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
......@@ -33,8 +36,6 @@ import java.util.Objects;
@Service
public class ExpOperationServiceImpl implements ExpOperationService {
private static final Logger LOG = LoggerFactory.getLogger(ExpOperationServiceImpl.class);
@Autowired
ExpDetailService expDetailService;
@Autowired
......@@ -50,9 +51,13 @@ public class ExpOperationServiceImpl implements ExpOperationService {
@Autowired
private RedisUtils redisUtils;
@Override
@AsyncMqSend
public void grantPointsThroughTempExp(List<TempExp> tempExpList) {
public void asyncMemberExpAndLevel(Member member) {}
@AsyncMqSend
public void asyncExpDetail(ExpDetail expDetail) {}
@Override
public void grantExpThroughTempExp(List<TempExp> tempExpList) {
for (TempExp tempExp : tempExpList) {
this.refresh(tempExp);
}
......@@ -86,7 +91,7 @@ public class ExpOperationServiceImpl implements ExpOperationService {
// 1.添加成长值记录
// this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp));
// 2.更新成长值与等级
this.refreshMemberExpAndLevel(tempExp,totalExp);
this.refreshMemberExpAndLevel(tempExp, totalExp);
this.doInsertExpDetail(tempExp, originExp, totalExp);
......@@ -98,7 +103,7 @@ public class ExpOperationServiceImpl implements ExpOperationService {
}
}
private long calculateTotalExp(long originalExp,TempExp tempExp) {
private long calculateTotalExp(long originalExp, TempExp tempExp) {
Long rewardExp = tempExp.getRewardExp();
return rewardExp + originalExp;
}
......@@ -146,12 +151,14 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO,member);
BeanUtils.copyProperties(memberDTO, member);
member.setExp(totalExp);
member.setLevel(level);
member.setUpdateTime(TimestampUtil.now());
this.memberOperationService.doUpdateMember(member);
this.memberOperationService.doUpdateMemberExpAndLevel(member);
((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member);
}
private MemberDTO findMemberByMemberId(Long memberId) {
......@@ -212,6 +219,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
expDetail.setDescription("#");
}
this.expDetailService.create(expDetail);
((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail);
}
}
......
......@@ -12,6 +12,7 @@ import com.topdraw.business.module.points.detail.detailhistory.service.PointsDet
import com.topdraw.business.module.points.detail.domain.PointsDetail;
import com.topdraw.business.module.points.detail.service.PointsDetailService;
import com.topdraw.business.module.points.service.PointsService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.service.dto.CustomPointsResult;
import com.topdraw.business.process.service.member.MemberOperationService;
import com.topdraw.business.process.service.PointsOperationService;
......@@ -23,6 +24,7 @@ import com.topdraw.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
......@@ -44,17 +46,17 @@ import java.util.stream.Collectors;
public class PointsOperationServiceImpl implements PointsOperationService {
@Autowired
PointsService pointsService;
private PointsService pointsService;
@Autowired
PointsDetailService pointsDetailService;
private PointsDetailService pointsDetailService;
@Autowired
PointsAvailableService pointsAvailableService;
private PointsAvailableService pointsAvailableService;
@Autowired
PointsDetailHistoryService pointsDetailHistoryService;
private PointsDetailHistoryService pointsDetailHistoryService;
@Autowired
MemberOperationService memberOperationService;
private MemberOperationService memberOperationService;
@Autowired
MemberService memberService;
private MemberService memberService;
@Autowired
private RedisUtils redisUtils;
......@@ -67,9 +69,16 @@ public class PointsOperationServiceImpl implements PointsOperationService {
private static final String DELETE_AVAILABLE_POINTS = "delete";
private static final String INSERT_AVAILABLE_POINTS = "insert";
@AsyncMqSend
public void asyncMemberPoint(Member member) {}
@AsyncMqSend
public void asyncPointsAvailable(PointsAvailable pointsAvailable) {}
@AsyncMqSend
public void asyncPointsDetail(PointsDetail pointsDetail) {}
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsByManual(Long memberId,TempPoints tempPoints){
public void grantPointsByManual(Long memberId, TempPoints tempPoints){
if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) {
MemberDTO memberDTo = this.memberService.findById(memberId);
String memberCode = memberDTo.getCode();
......@@ -79,7 +88,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
}
@Override
@AsyncMqSend
public void grantPointsByManualByTempPoints(TempPoints tempPoints) {
if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) {
this.refresh(tempPoints);
......@@ -93,7 +101,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
@AsyncMqSend
public CustomPointsResult customPoints(TempPoints tempPoints) {
CustomPointsResult customPointsResult = new CustomPointsResult();
......@@ -121,15 +128,17 @@ public class PointsOperationServiceImpl implements PointsOperationService {
// 5.即将过期的积分
long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
// 6.更新会员积分信息
this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints);
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
customPointsResult.setResult(true);
customPointsResult.setPoint(totalPoints);
return customPointsResult;
} else {
customPointsResult.setResult(false);
customPointsResult.setPoint(currentPoints);
}
}catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -145,7 +154,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param customAvailablePointsMap
*/
private long doFreshTrPointsAvailableByAvailablePointsMap(
Map<String, List<PointsAvailableDTO>> customAvailablePointsMap,long currentPoints) {
Map<String, List<PointsAvailableDTO>> customAvailablePointsMap, long currentPoints) {
long totalCustomAvailablePoints = 0L;
if (customAvailablePointsMap != null) {
......@@ -290,8 +299,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
@AsyncMqSend()
public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){
public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start1");
for (TempPoints tempPoints : tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start");
......@@ -304,9 +312,12 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param memberId
*/
private void cleanInvalidAvailablePointsByMemberId(Long memberId) {
List<PointsAvailableDTO> pointsAvailableDTOS =
pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,LocalDateTime.now());
if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
//1.获取原始积分
for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
// 添加积分明细 uc_points_detail
......@@ -347,7 +358,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param memberId
* @param currentPoints
*/
private void doUpdateMemberPoints(Long memberId, long currentPoints,long soonExpirePoints) {
private void doUpdateMemberPoints(Long memberId, long currentPoints, long soonExpirePoints) {
Member member = new Member();
member.setId(memberId);
member.setPoints(currentPoints);
......@@ -404,27 +415,27 @@ public class PointsOperationServiceImpl implements PointsOperationService {
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);
log.info("----------->> 总积分(可用总积分+获得的积分) --->>> " + totalPoints);
log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints);
// 3.添加积分明细
this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints);
log.info("----------->> 添加积分明细 ");
log.info("----------->> 添加积分明细 --->>> ");
// 4.添加可用积分
this.doInsertTrPointsAvailable(tempPoints);
log.info("----------->> 添加可用积分 ");
log.info("----------->> 添加可用积分 -->>> ");
// 5.即将过期的积分
long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
log.info("----------->> 即将过期的积分 ------->>>>> " + soonExpirePoints);
log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints);
// 6.更新会员的总积分
log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>>" + totalPoints);
this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints);
log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints);
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
} catch (Exception e) {
e.printStackTrace();
......@@ -453,7 +464,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param memberId
* @return
*/
private long getSoonExpirePoints(Long memberId,TempPoints tempPoints) {
private long getSoonExpirePoints(Long memberId, TempPoints tempPoints) {
// 计算即将过期的天数
Integer factor = this.calculateExpireFactor(tempPoints);
if (Objects.isNull(factor)) {
......@@ -479,7 +490,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param memberId 会员Id
* @param currentPoints 当前总积分
*/
private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints,TempPoints tempPoints) {
private void freshMemberCurrentPoints(Long memberId, Long currentPoints, long duePoints) {
MemberDTO memberDTO = this.findMemberByMemberId(memberId);
......@@ -491,6 +502,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
member.setUpdateTime(TimestampUtil.now());
try {
this.memberOperationService.doUpdateMemberPoints(member);
((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member);
} catch (Exception e){
throw e;
}
......@@ -520,6 +533,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
this.pointsAvailableService.create4Custom(pointsAvailable);
((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable);
}
/**
......@@ -528,7 +542,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param tempPoints 积分
* @return Integer 总积分
*/
private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){
private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints, Long currentPoints, Long totalPoints){
PointsDetail pointsDetail = new PointsDetail();
BeanUtils.copyProperties(tempPoints,pointsDetail);
......@@ -549,6 +563,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
// 保存积分流水
this.pointsDetailService.create4Custom(pointsDetail);
((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail);
}
}
......
......@@ -37,22 +37,17 @@ public class RightsOperationServiceImpl implements RightsOperationService {
private static final Logger LOG = LoggerFactory.getLogger(RightsOperationServiceImpl.class);
@Autowired
RightsHistoryService rightsHistoryService;
private RightsHistoryService rightsHistoryService;
@Autowired
CouponOperationService couponOperationService;
private CouponOperationService couponOperationService;
@Autowired
RightsService rightsService;
private RightsService rightsService;
@Autowired
ExpOperationService expOperationService;
private ExpOperationService expOperationService;
@Autowired
PointsOperationService pointsOperationService;
private PointsOperationService pointsOperationService;
@Autowired
CouponService couponService;
// @Autowired
// ThreadPoolTaskExecutor threadPoolTaskExecutor;
private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10);
private CouponService couponService;
/**
* 系统手动发放
......@@ -117,7 +112,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
*/
private void grantExp(List<TempExp> tempExpList) {
if (!CollectionUtils.isEmpty(tempExpList))
this.expOperationService.grantPointsThroughTempExp(tempExpList);
this.expOperationService.grantExpThroughTempExp(tempExpList);
}
/**
......@@ -127,7 +122,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
*/
private void grantPoint(List<TempPoints> tempPointsList) {
if (!CollectionUtils.isEmpty(tempPointsList))
this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList);
this.pointsOperationService.grantPointsThroughTempPoint(tempPointsList);
}
/**
......
......@@ -64,27 +64,25 @@ import static java.util.stream.Collectors.toList;
public class TaskOperationServiceImpl implements TaskOperationService {
@Autowired
TaskService taskService;
private TaskService taskService;
@Autowired
MemberService memberService;
private MemberService memberService;
@Autowired
RightsService rightsService;
private RightsService rightsService;
@Autowired
TaskTemplateService taskTemplateService;
private TaskTemplateService taskTemplateService;
@Autowired
RightsOperationService rightsOperationService;
private RightsOperationService rightsOperationService;
@Autowired
TrTaskProgressService trTaskProgressService;
private TrTaskProgressService trTaskProgressService;
@Autowired
PermanentRightsService permanentRightsService;
private CouponService couponService;
@Autowired
CouponService couponService;
private MemberGroupService memberGroupService;
@Autowired
MemberGroupService memberGroupService;
private TaskAttrService taskAttrService;
@Autowired
TaskAttrService taskAttrService;
@Autowired
UserTvService userTvService;
private UserTvService userTvService;
private static final Integer TASK_FINISH_STATUS = 1;
......
......@@ -45,7 +45,7 @@ public class MemberOperationServiceImpl implements MemberOperationService {
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@CachePut(key = "#resources.memberId")
// @CachePut(key = "#resources.memberId")
@Override
public MemberDTO buyVip(BuyVipBean resources) {
// 小程序账户id
......@@ -134,7 +134,7 @@ public class MemberOperationServiceImpl implements MemberOperationService {
return this.update(resources);
}
@CachePut(key = "#resources.id")
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doInsertMember(Member resources) {
return this.memberService.create(resources);
......@@ -148,8 +148,8 @@ public class MemberOperationServiceImpl implements MemberOperationService {
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doUpdateMemberExp(Member resources) {
return this.update(resources);
public MemberDTO doUpdateMemberExpAndLevel(Member resources) {
return this.memberService.doUpdateMemberExpAndLevel(resources);
}
// @CachePut(key = "#resources.id")
......@@ -161,7 +161,7 @@ public class MemberOperationServiceImpl implements MemberOperationService {
// @CachePut(key = "#resources.id")
@Override
public MemberDTO doUpdateMemberCoupon(Member member) {
return this.update(member);
return this.memberService.doUpdateMemberCoupon(member);
}
@Override
......
......@@ -65,7 +65,7 @@ public interface MemberOperationService {
*
* @param resources
*/
MemberDTO doUpdateMemberExp(Member resources);
MemberDTO doUpdateMemberExpAndLevel(Member resources);
/**
*
......