修复可用积分查询报空
Showing
20 changed files
with
277 additions
and
94 deletions
| ... | @@ -38,7 +38,6 @@ public class AsyncMqProducer { | ... | @@ -38,7 +38,6 @@ public class AsyncMqProducer { |
| 38 | 38 | ||
| 39 | @After("sendMqMsg(asyncMqSend)") | 39 | @After("sendMqMsg(asyncMqSend)") |
| 40 | public void doAfter(JoinPoint joinPoint, AsyncMqSend asyncMqSend){ | 40 | public void doAfter(JoinPoint joinPoint, AsyncMqSend asyncMqSend){ |
| 41 | LOG.info("AsyncMqProducer ===>>> doAfter ====>> start"); | ||
| 42 | boolean open = asyncMqSend.open(); | 41 | boolean open = asyncMqSend.open(); |
| 43 | if (open) { | 42 | if (open) { |
| 44 | try { | 43 | try { |
| ... | @@ -47,11 +46,9 @@ public class AsyncMqProducer { | ... | @@ -47,11 +46,9 @@ public class AsyncMqProducer { |
| 47 | e.printStackTrace(); | 46 | e.printStackTrace(); |
| 48 | } | 47 | } |
| 49 | } | 48 | } |
| 50 | LOG.info("AsyncMqProducer ===>>> doAfter ====>> end ===>> " ); | ||
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | private void doTask(JoinPoint joinPoint, AsyncMqSend asyncMqSend) { | 51 | private void doTask(JoinPoint joinPoint, AsyncMqSend asyncMqSend) { |
| 54 | LOG.info("AsyncMqProducer ===>>> doTask ====>> start ===>> " ); | ||
| 55 | 52 | ||
| 56 | String entityName = asyncMqSend.entityName(); | 53 | String entityName = asyncMqSend.entityName(); |
| 57 | String methodName = asyncMqSend.method(); | 54 | String methodName = asyncMqSend.method(); |
| ... | @@ -81,8 +78,6 @@ public class AsyncMqProducer { | ... | @@ -81,8 +78,6 @@ public class AsyncMqProducer { |
| 81 | // 同步 | 78 | // 同步 |
| 82 | this.sendMqMessage(tableOperationMsg); | 79 | this.sendMqMessage(tableOperationMsg); |
| 83 | } | 80 | } |
| 84 | |||
| 85 | LOG.info("AsyncMqProducer ===>>> doTask ====>> end ===>> " ); | ||
| 86 | } | 81 | } |
| 87 | 82 | ||
| 88 | private void sendMqMessage(TableOperationMsg tableOperationMsg){ | 83 | private void sendMqMessage(TableOperationMsg tableOperationMsg){ | ... | ... |
| ... | @@ -77,7 +77,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -77,7 +77,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
| 77 | */ | 77 | */ |
| 78 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time >= now()" | 78 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time >= now()" |
| 79 | ,nativeQuery = true) | 79 | ,nativeQuery = true) |
| 80 | long findAvailablePointsByMemberId(long memberId); | 80 | Long findAvailablePointsByMemberId(long memberId); |
| 81 | 81 | ||
| 82 | List<PointsAvailable> findByMemberIdOrderByExpireTime(Long memberId); | 82 | List<PointsAvailable> findByMemberIdOrderByExpireTime(Long memberId); |
| 83 | 83 | ... | ... |
| ... | @@ -154,7 +154,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -154,7 +154,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 154 | 154 | ||
| 155 | @Override | 155 | @Override |
| 156 | public long findAvailablePointsByMemberId(long memberId) { | 156 | public long findAvailablePointsByMemberId(long memberId) { |
| 157 | return this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId); | 157 | Long availablePoints = this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId); |
| 158 | return availablePoints == null ? 0L : availablePoints; | ||
| 158 | } | 159 | } |
| 159 | 160 | ||
| 160 | @Override | 161 | @Override | ... | ... |
| ... | @@ -13,4 +13,6 @@ import java.util.Optional; | ... | @@ -13,4 +13,6 @@ import java.util.Optional; |
| 13 | public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> { | 13 | public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> { |
| 14 | 14 | ||
| 15 | Optional<PermanentRights> findFirstByCode(String code); | 15 | Optional<PermanentRights> findFirstByCode(String code); |
| 16 | |||
| 17 | PermanentRights findByLevel(Integer level); | ||
| 16 | } | 18 | } | ... | ... |
| ... | @@ -47,4 +47,11 @@ public interface PermanentRightsService { | ... | @@ -47,4 +47,11 @@ public interface PermanentRightsService { |
| 47 | * @return PermanentRightsDTO | 47 | * @return PermanentRightsDTO |
| 48 | */ | 48 | */ |
| 49 | PermanentRightsDTO getByCode(String code); | 49 | PermanentRightsDTO getByCode(String code); |
| 50 | |||
| 51 | /** | ||
| 52 | * 通过会员等级获取对应的永久权益 | ||
| 53 | * @param level | ||
| 54 | * @return | ||
| 55 | */ | ||
| 56 | PermanentRightsDTO findByLevel(Integer level); | ||
| 50 | } | 57 | } | ... | ... |
| ... | @@ -87,4 +87,10 @@ public class PermanentRightsServiceImpl implements PermanentRightsService { | ... | @@ -87,4 +87,10 @@ public class PermanentRightsServiceImpl implements PermanentRightsService { |
| 87 | return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new)) | 87 | return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new)) |
| 88 | : new PermanentRightsDTO(); | 88 | : new PermanentRightsDTO(); |
| 89 | } | 89 | } |
| 90 | |||
| 91 | @Override | ||
| 92 | public PermanentRightsDTO findByLevel(Integer level) { | ||
| 93 | PermanentRights PermanentRights = PermanentRightsRepository.findByLevel(level); | ||
| 94 | return PermanentRightsMapper.toDto(PermanentRights); | ||
| 95 | } | ||
| 90 | } | 96 | } | ... | ... |
| 1 | package com.topdraw.business.basicdata.task.progress.repository; | 1 | package com.topdraw.business.basicdata.task.progress.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress; | 3 | import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress; |
| 4 | import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 5 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 6 | 8 | ||
| 9 | import java.util.List; | ||
| 7 | import java.util.Optional; | 10 | import java.util.Optional; |
| 8 | 11 | ||
| 9 | /** | 12 | /** |
| ... | @@ -12,4 +15,8 @@ import java.util.Optional; | ... | @@ -12,4 +15,8 @@ import java.util.Optional; |
| 12 | */ | 15 | */ |
| 13 | public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { | 16 | public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { |
| 14 | 17 | ||
| 18 | @Query(value = "select id, member_id, task_id , current_action_amount , \n" + | ||
| 19 | " target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" + | ||
| 20 | " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true) | ||
| 21 | List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | ||
| 15 | } | 22 | } | ... | ... |
| ... | @@ -43,4 +43,5 @@ public interface TrTaskProgressService { | ... | @@ -43,4 +43,5 @@ public interface TrTaskProgressService { |
| 43 | 43 | ||
| 44 | void delete(Long id); | 44 | void delete(Long id); |
| 45 | 45 | ||
| 46 | List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | ||
| 46 | } | 47 | } | ... | ... |
| ... | @@ -83,5 +83,10 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -83,5 +83,10 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
| 83 | TrTaskProgressRepository.delete(TrTaskProgress); | 83 | TrTaskProgressRepository.delete(TrTaskProgress); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | @Override | ||
| 87 | public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) { | ||
| 88 | return TrTaskProgressMapper.toDto(this.TrTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1)); | ||
| 89 | } | ||
| 90 | |||
| 86 | 91 | ||
| 87 | } | 92 | } | ... | ... |
| ... | @@ -60,7 +60,6 @@ public class PointsOperationController { | ... | @@ -60,7 +60,6 @@ public class PointsOperationController { |
| 60 | @ApiOperation("新增PointsDetail") | 60 | @ApiOperation("新增PointsDetail") |
| 61 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { | 61 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { |
| 62 | Long memberId = tempPoints.getMemberId(); | 62 | Long memberId = tempPoints.getMemberId(); |
| 63 | LOG.info("PointsOperationController -->> grantPointsByManual -->> " + tempPoints); | ||
| 64 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); | 63 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); |
| 65 | return ResultInfo.success(); | 64 | return ResultInfo.success(); |
| 66 | } | 65 | } | ... | ... |
| ... | @@ -8,7 +8,10 @@ import com.topdraw.business.process.service.CouponOperationService; | ... | @@ -8,7 +8,10 @@ import com.topdraw.business.process.service.CouponOperationService; |
| 8 | import com.topdraw.business.process.service.MemberOperationService; | 8 | import com.topdraw.business.process.service.MemberOperationService; |
| 9 | import com.topdraw.business.process.domian.TempCoupon; | 9 | import com.topdraw.business.process.domian.TempCoupon; |
| 10 | import com.topdraw.business.process.service.RightsOperationService; | 10 | import com.topdraw.business.process.service.RightsOperationService; |
| 11 | import com.topdraw.util.RedissonUtil; | ||
| 11 | import com.topdraw.util.TimestampUtil; | 12 | import com.topdraw.util.TimestampUtil; |
| 13 | import org.redisson.api.RLock; | ||
| 14 | import org.redisson.api.RedissonClient; | ||
| 12 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
| 14 | import org.springframework.beans.BeanUtils; | 17 | import org.springframework.beans.BeanUtils; |
| ... | @@ -35,6 +38,8 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -35,6 +38,8 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 35 | MemberOperationService memberOperationService; | 38 | MemberOperationService memberOperationService; |
| 36 | @Autowired | 39 | @Autowired |
| 37 | RightsOperationService rightsOperationService; | 40 | RightsOperationService rightsOperationService; |
| 41 | @Autowired | ||
| 42 | RedissonClient redissonClient; | ||
| 38 | 43 | ||
| 39 | // 过期阀值(默认一个月) | 44 | // 过期阀值(默认一个月) |
| 40 | private static final Integer EXPIRE_FACTOR_MONTH = 1; | 45 | private static final Integer EXPIRE_FACTOR_MONTH = 1; |
| ... | @@ -83,8 +88,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -83,8 +88,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 83 | private void refreshMemberCoupon(TempCoupon tempCoupon) { | 88 | private void refreshMemberCoupon(TempCoupon tempCoupon) { |
| 84 | Long userId = tempCoupon.getUserId(); | 89 | Long userId = tempCoupon.getUserId(); |
| 85 | Long memberId = tempCoupon.getMemberId(); | 90 | Long memberId = tempCoupon.getMemberId(); |
| 86 | try{ | 91 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon" + memberId.toString()); |
| 87 | // reentrantLock.lock(); | 92 | try { |
| 93 | RedissonUtil.lock(rLock); | ||
| 88 | // 1.获取用户领取的总优惠券 | 94 | // 1.获取用户领取的总优惠券 |
| 89 | Long totalCouponCount = this.getTotalCoupon(userId); | 95 | Long totalCouponCount = this.getTotalCoupon(userId); |
| 90 | // 2.获取已过期的优惠券数量 | 96 | // 2.获取已过期的优惠券数量 |
| ... | @@ -99,9 +105,8 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -99,9 +105,8 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 99 | e.printStackTrace(); | 105 | e.printStackTrace(); |
| 100 | throw e; | 106 | throw e; |
| 101 | } finally { | 107 | } finally { |
| 102 | // reentrantLock.unlock(); | 108 | RedissonUtil.unlock(rLock); |
| 103 | } | 109 | } |
| 104 | |||
| 105 | } | 110 | } |
| 106 | 111 | ||
| 107 | 112 | ... | ... |
| ... | @@ -10,8 +10,11 @@ import com.topdraw.business.process.service.ExpOperationService; | ... | @@ -10,8 +10,11 @@ import com.topdraw.business.process.service.ExpOperationService; |
| 10 | import com.topdraw.business.process.service.MemberOperationService; | 10 | import com.topdraw.business.process.service.MemberOperationService; |
| 11 | import com.topdraw.business.process.domian.TempExp; | 11 | import com.topdraw.business.process.domian.TempExp; |
| 12 | import com.topdraw.util.IdWorker; | 12 | import com.topdraw.util.IdWorker; |
| 13 | import com.topdraw.util.RedissonUtil; | ||
| 13 | import com.topdraw.util.TimestampUtil; | 14 | import com.topdraw.util.TimestampUtil; |
| 14 | import com.topdraw.utils.StringUtils; | 15 | import com.topdraw.utils.StringUtils; |
| 16 | import org.redisson.api.RLock; | ||
| 17 | import org.redisson.api.RedissonClient; | ||
| 15 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 19 | import org.slf4j.LoggerFactory; |
| 17 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
| ... | @@ -21,9 +24,6 @@ import org.springframework.util.CollectionUtils; | ... | @@ -21,9 +24,6 @@ import org.springframework.util.CollectionUtils; |
| 21 | 24 | ||
| 22 | import java.util.List; | 25 | import java.util.List; |
| 23 | import java.util.Objects; | 26 | import java.util.Objects; |
| 24 | import java.util.concurrent.locks.Lock; | ||
| 25 | import java.util.concurrent.locks.ReentrantLock; | ||
| 26 | import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * | 29 | * |
| ... | @@ -39,6 +39,8 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -39,6 +39,8 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 39 | MemberOperationService memberOperationService; | 39 | MemberOperationService memberOperationService; |
| 40 | @Autowired | 40 | @Autowired |
| 41 | MemberLevelService memberLevelService; | 41 | MemberLevelService memberLevelService; |
| 42 | @Autowired | ||
| 43 | RedissonClient redissonClient; | ||
| 42 | 44 | ||
| 43 | @Override | 45 | @Override |
| 44 | public void grantPointsThroughTempExp(List<TempExp> tempExpList) { | 46 | public void grantPointsThroughTempExp(List<TempExp> tempExpList) { |
| ... | @@ -83,17 +85,28 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -83,17 +85,28 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 83 | * @param tempExp 成长值列表 | 85 | * @param tempExp 成长值列表 |
| 84 | */ | 86 | */ |
| 85 | private void refreshMemberExpAndLevel(TempExp tempExp) { | 87 | private void refreshMemberExpAndLevel(TempExp tempExp) { |
| 88 | |||
| 86 | Long memberId = tempExp.getMemberId(); | 89 | Long memberId = tempExp.getMemberId(); |
| 90 | |||
| 91 | RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); | ||
| 92 | try { | ||
| 93 | RedissonUtil.lock(rLock); | ||
| 87 | // 1.获取当前成长值 | 94 | // 1.获取当前成长值 |
| 88 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | 95 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); |
| 89 | // 2.获取下一级需要的成长值 | 96 | // 2.获取下一级需要的成长值 |
| 90 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel()+1,1); | 97 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); |
| 91 | // 3.成长值累加 | 98 | // 3.成长值累加 |
| 92 | Long newExp = memberDTO.getExp() + tempExp.getRewardExp(); | 99 | Long newExp = memberDTO.getExp() + tempExp.getRewardExp(); |
| 93 | // 4.成长值比较,判断是否升级 | 100 | // 4.成长值比较,判断是否升级 |
| 94 | long i = this.compareExp(newExp,memberLevelDTO); | 101 | long i = this.compareExp(newExp, memberLevelDTO); |
| 95 | // 5.更新用户信息 | 102 | // 5.更新用户信息 |
| 96 | this.updateMemberInfo(i,newExp,memberLevelDTO,memberId); | 103 | this.updateMemberInfo(i, newExp, memberLevelDTO, memberId); |
| 104 | } catch (Exception e) { | ||
| 105 | e.printStackTrace(); | ||
| 106 | throw e; | ||
| 107 | } finally { | ||
| 108 | RedissonUtil.unlock(rLock); | ||
| 109 | } | ||
| 97 | } | 110 | } |
| 98 | 111 | ||
| 99 | /** | 112 | /** | ... | ... |
| ... | @@ -14,8 +14,11 @@ import com.topdraw.business.process.service.MemberOperationService; | ... | @@ -14,8 +14,11 @@ import com.topdraw.business.process.service.MemberOperationService; |
| 14 | import com.topdraw.business.process.service.PointsOperationService; | 14 | import com.topdraw.business.process.service.PointsOperationService; |
| 15 | import com.topdraw.business.process.domian.TempPoints; | 15 | import com.topdraw.business.process.domian.TempPoints; |
| 16 | import com.topdraw.util.IdWorker; | 16 | import com.topdraw.util.IdWorker; |
| 17 | import com.topdraw.util.RedissonUtil; | ||
| 17 | import com.topdraw.util.TimestampUtil; | 18 | import com.topdraw.util.TimestampUtil; |
| 18 | import com.topdraw.utils.StringUtils; | 19 | import com.topdraw.utils.StringUtils; |
| 20 | import io.swagger.models.auth.In; | ||
| 21 | import org.redisson.api.RLock; | ||
| 19 | import org.redisson.api.RedissonClient; | 22 | import org.redisson.api.RedissonClient; |
| 20 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
| ... | @@ -30,6 +33,9 @@ import java.sql.Time; | ... | @@ -30,6 +33,9 @@ import java.sql.Time; |
| 30 | import java.sql.Timestamp; | 33 | import java.sql.Timestamp; |
| 31 | import java.time.LocalDateTime; | 34 | import java.time.LocalDateTime; |
| 32 | import java.util.*; | 35 | import java.util.*; |
| 36 | import java.util.concurrent.ForkJoinPool; | ||
| 37 | import java.util.concurrent.ForkJoinTask; | ||
| 38 | import java.util.concurrent.RecursiveTask; | ||
| 33 | import java.util.stream.Collectors; | 39 | import java.util.stream.Collectors; |
| 34 | 40 | ||
| 35 | /** | 41 | /** |
| ... | @@ -319,16 +325,25 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -319,16 +325,25 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 319 | */ | 325 | */ |
| 320 | private void refresh(TempPoints tempPoints) { | 326 | private void refresh(TempPoints tempPoints) { |
| 321 | Long memberId = tempPoints.getMemberId(); | 327 | Long memberId = tempPoints.getMemberId(); |
| 328 | RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); | ||
| 329 | try { | ||
| 330 | RedissonUtil.lock(rLock); | ||
| 322 | // 1.可用总积分 | 331 | // 1.可用总积分 |
| 323 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | 332 | long currentPoints = this.findAvailablePointsByMemberId(memberId); |
| 324 | // 2.添加积分明细,并计算总积分 | 333 | // 2.添加积分明细,并计算总积分 |
| 325 | long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints,currentPoints); | 334 | long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints); |
| 326 | // 3.获取即将过期的积分 | 335 | // 3.获取即将过期的积分 |
| 327 | long soonExpireTime = this.getSoonExpirePoints(memberId,tempPoints); | 336 | long soonExpireTime = this.getSoonExpirePoints(memberId, tempPoints); |
| 328 | // 4.更新会员的总积分 | 337 | // 4.更新会员的总积分 |
| 329 | this.freshMemberCurrentPoints(memberId,totalPoints,soonExpireTime); | 338 | this.freshMemberCurrentPoints(memberId, totalPoints, soonExpireTime); |
| 330 | // 5.添加可用积分 | 339 | // 5.添加可用积分 |
| 331 | this.doInsertTrPointsAvailable(tempPoints); | 340 | this.doInsertTrPointsAvailable(tempPoints); |
| 341 | } catch (Exception e) { | ||
| 342 | e.printStackTrace(); | ||
| 343 | throw e; | ||
| 344 | } finally { | ||
| 345 | RedissonUtil.unlock(rLock); | ||
| 346 | } | ||
| 332 | } | 347 | } |
| 333 | 348 | ||
| 334 | /** | 349 | /** |
| ... | @@ -382,7 +397,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -382,7 +397,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 382 | * @return | 397 | * @return |
| 383 | */ | 398 | */ |
| 384 | private long findAvailablePointsByMemberId(long memberId){ | 399 | private long findAvailablePointsByMemberId(long memberId){ |
| 385 | return this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | 400 | long availablePointsByMemberId = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); |
| 401 | return availablePointsByMemberId; | ||
| 386 | } | 402 | } |
| 387 | 403 | ||
| 388 | /** | 404 | /** | ... | ... |
| ... | @@ -137,20 +137,25 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -137,20 +137,25 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 137 | * @param tempRightsMap | 137 | * @param tempRightsMap |
| 138 | */ | 138 | */ |
| 139 | private void refresh(Map<RightType, Object> tempRightsMap) { | 139 | private void refresh(Map<RightType, Object> tempRightsMap) { |
| 140 | |||
| 140 | /*threadPoolTaskExecutor.execute(()->{ | 141 | /*threadPoolTaskExecutor.execute(()->{ |
| 142 | // 积分 | ||
| 141 | this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); | 143 | this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); |
| 142 | }); | 144 | }); |
| 145 | |||
| 143 | threadPoolTaskExecutor.execute(()->{ | 146 | threadPoolTaskExecutor.execute(()->{ |
| 147 | // 成长值 | ||
| 144 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | 148 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); |
| 145 | }); | 149 | }); |
| 150 | |||
| 146 | threadPoolTaskExecutor.execute(()->{ | 151 | threadPoolTaskExecutor.execute(()->{ |
| 152 | // 优惠券 | ||
| 147 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); | 153 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); |
| 148 | });*/ | 154 | });*/ |
| 149 | 155 | ||
| 150 | this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); | 156 | this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); |
| 151 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | 157 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); |
| 152 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); | 158 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); |
| 153 | |||
| 154 | } | 159 | } |
| 155 | 160 | ||
| 156 | /** | 161 | /** | ... | ... |
| 1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.topdraw.business.basicdata.rights.constant.RightsType; | 4 | import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService; |
| 5 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; | ||
| 5 | import com.topdraw.business.basicdata.rights.service.RightsService; | 6 | import com.topdraw.business.basicdata.rights.service.RightsService; |
| 6 | import com.topdraw.business.basicdata.rights.service.dto.RightsDTO; | 7 | import com.topdraw.business.basicdata.rights.service.dto.RightsDTO; |
| 7 | import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress; | 8 | import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress; |
| ... | @@ -9,7 +10,6 @@ import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressServic | ... | @@ -9,7 +10,6 @@ import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressServic |
| 9 | import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO; | 10 | import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO; |
| 10 | import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria; | 11 | import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria; |
| 11 | import com.topdraw.business.process.service.RightsOperationService; | 12 | import com.topdraw.business.process.service.RightsOperationService; |
| 12 | import com.topdraw.business.process.service.TaskDealService; | ||
| 13 | import com.topdraw.business.process.service.TaskOperationService; | 13 | import com.topdraw.business.process.service.TaskOperationService; |
| 14 | import com.topdraw.business.basicdata.member.service.MemberService; | 14 | import com.topdraw.business.basicdata.member.service.MemberService; |
| 15 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | 15 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; |
| ... | @@ -19,21 +19,23 @@ import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | ... | @@ -19,21 +19,23 @@ import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; |
| 19 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; | 19 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; |
| 20 | import com.topdraw.business.process.domian.*; | 20 | import com.topdraw.business.process.domian.*; |
| 21 | import com.topdraw.module.mq.DataSyncMsg; | 21 | import com.topdraw.module.mq.DataSyncMsg; |
| 22 | import com.topdraw.module.mq.EventType; | ||
| 23 | import com.topdraw.util.*; | 22 | import com.topdraw.util.*; |
| 24 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
| 26 | import org.springframework.beans.BeanUtils; | ||
| 27 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
| 28 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 26 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 29 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| 30 | import org.springframework.util.Assert; | ||
| 31 | import org.springframework.util.CollectionUtils; | 28 | import org.springframework.util.CollectionUtils; |
| 32 | import org.springframework.util.StringUtils; | 29 | import org.springframework.util.StringUtils; |
| 33 | 30 | ||
| 34 | import javax.annotation.Resource; | 31 | import javax.annotation.Resource; |
| 32 | import java.math.BigDecimal; | ||
| 33 | import java.math.RoundingMode; | ||
| 35 | import java.sql.Timestamp; | 34 | import java.sql.Timestamp; |
| 35 | import java.time.LocalDate; | ||
| 36 | import java.util.*; | 36 | import java.util.*; |
| 37 | import java.util.concurrent.locks.ReentrantLock; | ||
| 38 | import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
| 37 | import java.util.stream.Collectors; | 39 | import java.util.stream.Collectors; |
| 38 | 40 | ||
| 39 | /** | 41 | /** |
| ... | @@ -59,14 +61,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -59,14 +61,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 59 | private RightsOperationService rightsOperationService; | 61 | private RightsOperationService rightsOperationService; |
| 60 | @Autowired | 62 | @Autowired |
| 61 | private TrTaskProgressService trTaskProgressService; | 63 | private TrTaskProgressService trTaskProgressService; |
| 64 | @Autowired | ||
| 65 | private PermanentRightsService permanentRightsService; | ||
| 62 | 66 | ||
| 63 | private static final Integer POINTS_TYPE_RANDOM = 1; | 67 | private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(); |
| 64 | private static final Integer POINTS_MIN = 1; | ||
| 65 | 68 | ||
| 66 | private static final Integer TASK_FINISH_STATUS = 1; | 69 | private static final Integer TASK_FINISH_STATUS = 1; |
| 67 | 70 | private static final Integer TASK_UNFINISH_STATUS = 2; | |
| 68 | @Resource(name = "executorTask") | 71 | private static final Integer POINTS_TYPE_RANDOM = 1; |
| 69 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 72 | private static final Integer POINTS_MIN = 1; |
| 70 | 73 | ||
| 71 | @Override | 74 | @Override |
| 72 | public void dealTask(String content) { | 75 | public void dealTask(String content) { |
| ... | @@ -74,10 +77,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -74,10 +77,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 74 | long l = System.currentTimeMillis(); | 77 | long l = System.currentTimeMillis(); |
| 75 | 78 | ||
| 76 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class); | 79 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class); |
| 77 | |||
| 78 | String eventType = dataSyncMsg.getEventType(); | 80 | String eventType = dataSyncMsg.getEventType(); |
| 79 | DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); | 81 | DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); |
| 80 | |||
| 81 | Long memberId = msgData.getMemberId(); | 82 | Long memberId = msgData.getMemberId(); |
| 82 | 83 | ||
| 83 | // 1.通过任务标识获取任务模板 | 84 | // 1.通过任务标识获取任务模板 |
| ... | @@ -89,10 +90,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -89,10 +90,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 89 | // 4.判断当前用户是否满足任务完成条件 | 90 | // 4.判断当前用户是否满足任务完成条件 |
| 90 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); | 91 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); |
| 91 | if (checkResult) { | 92 | if (checkResult) { |
| 92 | // 4.权益区分(积分、权益、成长值) | 93 | // 5.权益区分(积分、权益、成长值) |
| 93 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 94 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); |
| 94 | // 5.权益发放 | 95 | // 6.永久权益 |
| 95 | this.grantRight(tempRightsMap); | 96 | PermanentRightsDTO permanentRights = this.getPermanentRights(memberId); |
| 97 | // 7.永久权益计算之后的权益 | ||
| 98 | Map<RightType, Object> rightTypeObjectMap = this.calculateRight(permanentRights, tempRightsMap, memberId); | ||
| 99 | // 8..权益发放 | ||
| 100 | this.grantRight(rightTypeObjectMap); | ||
| 96 | } | 101 | } |
| 97 | 102 | ||
| 98 | long r = System.currentTimeMillis(); | 103 | long r = System.currentTimeMillis(); |
| ... | @@ -100,9 +105,25 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -100,9 +105,25 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 100 | } | 105 | } |
| 101 | 106 | ||
| 102 | /** | 107 | /** |
| 108 | * 永久权益 | ||
| 109 | * @param memberId 会员id | ||
| 110 | * @return PermanentRightsDTO 永久权益 | ||
| 111 | */ | ||
| 112 | private PermanentRightsDTO getPermanentRights(Long memberId) { | ||
| 113 | PermanentRightsDTO permanentRights = null; | ||
| 114 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 115 | if (Objects.nonNull(memberDTO)) { | ||
| 116 | Integer level = memberDTO.getLevel(); | ||
| 117 | // 永久权益 | ||
| 118 | permanentRights = this.permanentRightsService.findByLevel(level); | ||
| 119 | } | ||
| 120 | return permanentRights; | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 103 | * 解析模板参数 | 124 | * 解析模板参数 |
| 104 | * @param taskTemplate | 125 | * @param taskTemplate 任务模板 |
| 105 | * @return | 126 | * @return Map<String, Object> 模板参数解析结果 |
| 106 | */ | 127 | */ |
| 107 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { | 128 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { |
| 108 | if (Objects.nonNull(taskTemplate)) { | 129 | if (Objects.nonNull(taskTemplate)) { |
| ... | @@ -116,21 +137,30 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -116,21 +137,30 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 116 | } | 137 | } |
| 117 | 138 | ||
| 118 | /** | 139 | /** |
| 119 | * 保存任务的完成情况 | 140 | * 任务完成情况 |
| 141 | * @param resources 任务完成情况 | ||
| 120 | */ | 142 | */ |
| 121 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { | 143 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { |
| 122 | Long id = resources.getId(); | 144 | Long id = resources.getId(); |
| 145 | ReentrantReadWriteLock.WriteLock writeLock = this.reentrantReadWriteLock.writeLock(); | ||
| 146 | try { | ||
| 147 | writeLock.lock(); | ||
| 123 | if (Objects.nonNull(id)) { | 148 | if (Objects.nonNull(id)) { |
| 124 | resources.setUpdateTime(TimestampUtil.now()); | 149 | resources.setUpdateTime(TimestampUtil.now()); |
| 125 | this.trTaskProgressService.update(resources); | 150 | this.trTaskProgressService.update(resources); |
| 126 | } else { | 151 | } else { |
| 127 | this.trTaskProgressService.create(resources); | 152 | this.trTaskProgressService.create(resources); |
| 128 | } | 153 | } |
| 154 | } catch (Exception e) { | ||
| 155 | e.printStackTrace(); | ||
| 156 | } finally { | ||
| 157 | writeLock.unlock(); | ||
| 158 | } | ||
| 129 | } | 159 | } |
| 130 | 160 | ||
| 131 | /** | 161 | /** |
| 132 | * 权益发放 | 162 | * 权益发放 |
| 133 | * @param tempRightsMap 会员id | 163 | * @param tempRightsMap 权益 |
| 134 | */ | 164 | */ |
| 135 | private void grantRight(Map<RightType,Object> tempRightsMap) { | 165 | private void grantRight(Map<RightType,Object> tempRightsMap) { |
| 136 | this.rightsOperationService.grantRights(tempRightsMap); | 166 | this.rightsOperationService.grantRights(tempRightsMap); |
| ... | @@ -140,6 +170,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -140,6 +170,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 140 | * 权益区分 | 170 | * 权益区分 |
| 141 | * | 171 | * |
| 142 | * @param taskList 任务列表 | 172 | * @param taskList 任务列表 |
| 173 | * @return Map<RightType,Object> 权益分类 | ||
| 143 | */ | 174 | */ |
| 144 | private Map<RightType,Object> distinguishRight(Long memberId,List<Task> taskList,DataSyncMsg.MsgData msgData) { | 175 | private Map<RightType,Object> distinguishRight(Long memberId,List<Task> taskList,DataSyncMsg.MsgData msgData) { |
| 145 | 176 | ||
| ... | @@ -165,6 +196,106 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -165,6 +196,106 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 165 | 196 | ||
| 166 | } | 197 | } |
| 167 | 198 | ||
| 199 | /** | ||
| 200 | * 计算总权益 = 已获得的积分 + 已获得的积分 * 额外积分比率 | ||
| 201 | * @param permanentRights | ||
| 202 | * @param map | ||
| 203 | */ | ||
| 204 | private Map<RightType, Object> calculateRight(PermanentRightsDTO permanentRights, Map<RightType, Object> map,Long memberId) { | ||
| 205 | |||
| 206 | // 验证永久权益 | ||
| 207 | boolean b = this.validatedPermanentRights(permanentRights, memberId); | ||
| 208 | |||
| 209 | if (b) { | ||
| 210 | // 获得的积分 | ||
| 211 | List<TempPoints> tempPointsList = (List<TempPoints>)map.get(RightType.POINTS); | ||
| 212 | |||
| 213 | if (!CollectionUtils.isEmpty(tempPointsList)) { | ||
| 214 | // 经过永久权益计算后的总积分 | ||
| 215 | this.calculateTotalPoints(permanentRights,tempPointsList); | ||
| 216 | map.put(RightType.POINTS,tempPointsList); | ||
| 217 | } | ||
| 218 | |||
| 219 | // TODO 其他权益 | ||
| 220 | |||
| 221 | } | ||
| 222 | |||
| 223 | return map; | ||
| 224 | } | ||
| 225 | |||
| 226 | /** | ||
| 227 | * 经过永久权益计算后的总积分 | ||
| 228 | * @param permanentRights 永久权益 | ||
| 229 | * @param tempPointsList 积分 | ||
| 230 | * @return BigDecimal 总积分 | ||
| 231 | */ | ||
| 232 | private BigDecimal calculateTotalPoints(PermanentRightsDTO permanentRights, List<TempPoints> tempPointsList) { | ||
| 233 | |||
| 234 | // 总积分 | ||
| 235 | BigDecimal rewardsPoints = null; | ||
| 236 | // 额外积分费率 | ||
| 237 | BigDecimal extraPoints = permanentRights.getExtraPoints(); | ||
| 238 | |||
| 239 | for (TempPoints tempPoints : tempPointsList) { | ||
| 240 | |||
| 241 | rewardsPoints = new BigDecimal(tempPoints.getPoints()); | ||
| 242 | if (Objects.nonNull(extraPoints) && extraPoints.compareTo(BigDecimal.ZERO) > 0) { | ||
| 243 | // 已获得的积分 * 额外积分比率 | ||
| 244 | BigDecimal multiply = (extraPoints.divide(new BigDecimal(100),4,RoundingMode.HALF_UP)).multiply(rewardsPoints); | ||
| 245 | // 四舍五入 | ||
| 246 | BigDecimal bigDecimal = multiply.setScale(0, RoundingMode.HALF_UP); | ||
| 247 | // 已获得的积分 + 已获得的积分 * 额外积分比率 | ||
| 248 | rewardsPoints = rewardsPoints.add(bigDecimal); | ||
| 249 | tempPoints.setPoints(rewardsPoints.longValue()); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | return rewardsPoints; | ||
| 254 | } | ||
| 255 | |||
| 256 | /** | ||
| 257 | * 验证是否满足永久权益 | ||
| 258 | * @param permanentRights | ||
| 259 | * @param memberId | ||
| 260 | * @return | ||
| 261 | */ | ||
| 262 | private boolean validatedPermanentRights(PermanentRightsDTO permanentRights, Long memberId){ | ||
| 263 | // 永久权益类型 0:vip;1:会员等级 | ||
| 264 | Integer type = 0; | ||
| 265 | // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) | ||
| 266 | Integer level = 0; | ||
| 267 | if (Objects.nonNull(permanentRights)) { | ||
| 268 | level = permanentRights.getLevel(); | ||
| 269 | type = permanentRights.getType(); | ||
| 270 | } | ||
| 271 | |||
| 272 | boolean result = false; | ||
| 273 | |||
| 274 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 275 | if (Objects.nonNull(memberDTO)) { | ||
| 276 | // 会员vip等级 | ||
| 277 | Integer memberVip = memberDTO.getVip(); | ||
| 278 | // 会员等级 | ||
| 279 | Integer memberLevel = memberDTO.getLevel(); | ||
| 280 | switch (type) { | ||
| 281 | // vip等级 | ||
| 282 | case 0: | ||
| 283 | if ((Objects.isNull(memberVip) ? 0 : memberVip) >= level) | ||
| 284 | result = true; | ||
| 285 | break; | ||
| 286 | // 会员等级 | ||
| 287 | case 1: | ||
| 288 | if ((Objects.isNull(memberLevel) ? 0 : memberLevel) >= level) | ||
| 289 | result = true; | ||
| 290 | break; | ||
| 291 | |||
| 292 | default: | ||
| 293 | break; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | return result; | ||
| 298 | } | ||
| 168 | 299 | ||
| 169 | /** | 300 | /** |
| 170 | * 创建权益 | 301 | * 创建权益 |
| ... | @@ -184,7 +315,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -184,7 +315,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 184 | return tempRights; | 315 | return tempRights; |
| 185 | } | 316 | } |
| 186 | 317 | ||
| 187 | |||
| 188 | /** | 318 | /** |
| 189 | * 优惠券 | 319 | * 优惠券 |
| 190 | * @param memberId | 320 | * @param memberId |
| ... | @@ -202,8 +332,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -202,8 +332,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 202 | return tempCoupon; | 332 | return tempCoupon; |
| 203 | } | 333 | } |
| 204 | 334 | ||
| 205 | |||
| 206 | |||
| 207 | /** | 335 | /** |
| 208 | * 权益1 | 336 | * 权益1 |
| 209 | * @param task | 337 | * @param task |
| ... | @@ -214,6 +342,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -214,6 +342,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 214 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 342 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
| 215 | // 权益列表,用以保存权益记录 | 343 | // 权益列表,用以保存权益记录 |
| 216 | List<TempRights> rightsList = new ArrayList<>(); | 344 | List<TempRights> rightsList = new ArrayList<>(); |
| 345 | |||
| 217 | // 权益1 | 346 | // 权益1 |
| 218 | Long rights1Id = task.getRightsId(); | 347 | Long rights1Id = task.getRightsId(); |
| 219 | if (Objects.nonNull(rights1Id)) { | 348 | if (Objects.nonNull(rights1Id)) { |
| ... | @@ -317,16 +446,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -317,16 +446,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 317 | * @param rightsId | 446 | * @param rightsId |
| 318 | * @return | 447 | * @return |
| 319 | */ | 448 | */ |
| 320 | private Integer getRightType(Long rightsId) { | ||
| 321 | RightsDTO rightsDTO = this.getRight(rightsId); | ||
| 322 | return Objects.nonNull(rightsDTO) ? rightsDTO.getType() : -999; | ||
| 323 | } | ||
| 324 | |||
| 325 | /** | ||
| 326 | * | ||
| 327 | * @param rightsId | ||
| 328 | * @return | ||
| 329 | */ | ||
| 330 | private RightsDTO getRight(Long rightsId) { | 449 | private RightsDTO getRight(Long rightsId) { |
| 331 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); | 450 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); |
| 332 | return rightsDTO; | 451 | return rightsDTO; |
| ... | @@ -362,6 +481,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -362,6 +481,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 362 | * @return | 481 | * @return |
| 363 | */ | 482 | */ |
| 364 | private List<TempPoints> getTempPoints(Long memberId,DataSyncMsg.MsgData msgData,Task task) { | 483 | private List<TempPoints> getTempPoints(Long memberId,DataSyncMsg.MsgData msgData,Task task) { |
| 484 | |||
| 365 | // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值 | 485 | // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值 |
| 366 | Long rewardPoints = task.getRewardPoints(); | 486 | Long rewardPoints = task.getRewardPoints(); |
| 367 | // 过期时间 | 487 | // 过期时间 |
| ... | @@ -431,7 +551,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -431,7 +551,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 431 | 551 | ||
| 432 | if (CollectionUtils.isEmpty(taskStream)) { | 552 | if (CollectionUtils.isEmpty(taskStream)) { |
| 433 | // 获取当前任务的完成情况 | 553 | // 获取当前任务的完成情况 |
| 434 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskStream); | 554 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); |
| 435 | return result; | 555 | return result; |
| 436 | } | 556 | } |
| 437 | return true; | 557 | return true; |
| ... | @@ -446,29 +566,29 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -446,29 +566,29 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 446 | * 检查并更新当前任务的完成情况 | 566 | * 检查并更新当前任务的完成情况 |
| 447 | * @param memberId | 567 | * @param memberId |
| 448 | * @param taskStream | 568 | * @param taskStream |
| 449 | * @return | 569 | * @return boolean false:失败 true:成功 |
| 450 | */ | 570 | */ |
| 451 | private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream) { | 571 | private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream) { |
| 452 | TrTaskProgressQueryCriteria trTaskProgressQueryCriteria = new TrTaskProgressQueryCriteria(); | 572 | TrTaskProgressQueryCriteria trTaskProgressQueryCriteria = new TrTaskProgressQueryCriteria(); |
| 453 | trTaskProgressQueryCriteria.setMemberId(memberId); | 573 | trTaskProgressQueryCriteria.setMemberId(memberId); |
| 454 | String time1 = LocalDateTimeUtil.todayStart(); | 574 | String time1 = LocalDateTimeUtil.todayStart(); |
| 455 | String time2 = LocalDateTimeUtil.todayEnd();; | 575 | |
| 456 | trTaskProgressQueryCriteria.setCompletionTime(time1+","+time2); | ||
| 457 | ArrayList array = new ArrayList<>(); | ||
| 458 | for (Task task : taskStream) { | 576 | for (Task task : taskStream) { |
| 459 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | ||
| 460 | 577 | ||
| 461 | Long taskId = task.getId(); | 578 | Long taskId = task.getId(); |
| 462 | // 行为量(完成此任务需要多少次相同行为的触发) | ||
| 463 | Integer actionAmount = task.getActionAmount(); | ||
| 464 | trTaskProgressQueryCriteria.setTaskId(taskId); | 579 | trTaskProgressQueryCriteria.setTaskId(taskId); |
| 465 | List<TrTaskProgressDTO> trTaskProgressDTOS = this.trTaskProgressService.queryAll(trTaskProgressQueryCriteria); | 580 | // 任务完成记录 |
| 581 | List<TrTaskProgressDTO> trTaskProgressDTOS = | ||
| 582 | this.trTaskProgressService.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1); | ||
| 466 | 583 | ||
| 467 | Long id = null; | 584 | Long id = null; |
| 468 | Integer currentActionAmount = null; | 585 | Integer currentActionAmount = null; |
| 469 | Timestamp completionTime = null; | 586 | Timestamp completionTime = null; |
| 470 | Integer status = 0; | 587 | Integer status = 0; |
| 471 | 588 | ||
| 589 | // 行为量(完成此任务需要多少次相同行为的触发) | ||
| 590 | Integer actionAmount = task.getActionAmount(); | ||
| 591 | |||
| 472 | // 行为量 1 | 592 | // 行为量 1 |
| 473 | if (actionAmount == 1) { | 593 | if (actionAmount == 1) { |
| 474 | 594 | ||
| ... | @@ -484,24 +604,28 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -484,24 +604,28 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 484 | Long id_ = trTaskProgressDTO.getId(); | 604 | Long id_ = trTaskProgressDTO.getId(); |
| 485 | Integer status_ = trTaskProgressDTO.getStatus(); | 605 | Integer status_ = trTaskProgressDTO.getStatus(); |
| 486 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | 606 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); |
| 487 | if (status_ != 1 && Objects.isNull(trTaskProgressDTO.getCompletionTime())) { | 607 | Timestamp completionTime1 = trTaskProgressDTO.getCompletionTime(); |
| 488 | 608 | ||
| 609 | // 任务已做,不成功 | ||
| 610 | if (Objects.nonNull(status_) && status_ == 1 && | ||
| 611 | Objects.nonNull(currentActionAmount_) && currentActionAmount_ == 1 && | ||
| 612 | Objects.nonNull(completionTime1) && | ||
| 613 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | ||
| 614 | |||
| 615 | return false; | ||
| 616 | |||
| 617 | // 未做,成功 | ||
| 618 | } else { | ||
| 489 | id = id_; | 619 | id = id_; |
| 490 | currentActionAmount = 1; | 620 | currentActionAmount = 1; |
| 491 | completionTime = TimestampUtil.now(); | 621 | completionTime = TimestampUtil.now(); |
| 492 | status = TASK_FINISH_STATUS; | 622 | status = TASK_FINISH_STATUS; |
| 493 | |||
| 494 | } else { | ||
| 495 | |||
| 496 | id = id_; | ||
| 497 | currentActionAmount = currentActionAmount_+1; | ||
| 498 | |||
| 499 | } | 623 | } |
| 500 | 624 | ||
| 501 | } | 625 | } |
| 502 | } | 626 | } |
| 503 | 627 | ||
| 504 | // 行为量不是1 | 628 | // 行为量非1 |
| 505 | if (actionAmount != 1) { | 629 | if (actionAmount != 1) { |
| 506 | 630 | ||
| 507 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | 631 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { |
| ... | @@ -513,22 +637,29 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -513,22 +637,29 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 513 | Integer status_ = trTaskProgressDTO.getStatus(); | 637 | Integer status_ = trTaskProgressDTO.getStatus(); |
| 514 | Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime(); | 638 | Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime(); |
| 515 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | 639 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); |
| 640 | // 行为量达到,完成 | ||
| 516 | if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) { | 641 | if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) { |
| 517 | id = id_; | 642 | id = id_; |
| 518 | currentActionAmount = actionAmount; | 643 | currentActionAmount = actionAmount; |
| 519 | completionTime = TimestampUtil.now(); | 644 | completionTime = TimestampUtil.now(); |
| 520 | status = TASK_FINISH_STATUS; | 645 | status = TASK_FINISH_STATUS; |
| 521 | } else { | 646 | } else { |
| 647 | // 行为量未达到,未完成 | ||
| 522 | id = id_; | 648 | id = id_; |
| 523 | currentActionAmount = currentActionAmount_+1; | 649 | currentActionAmount = currentActionAmount_+1; |
| 524 | } | 650 | } |
| 525 | 651 | ||
| 526 | } else { | 652 | } |
| 653 | |||
| 654 | // 未达到行为量,未完成 | ||
| 655 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
| 527 | currentActionAmount = 1; | 656 | currentActionAmount = 1; |
| 657 | status = TASK_UNFINISH_STATUS; | ||
| 528 | } | 658 | } |
| 529 | 659 | ||
| 530 | } | 660 | } |
| 531 | 661 | ||
| 662 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | ||
| 532 | trTaskProgress.setId(id); | 663 | trTaskProgress.setId(id); |
| 533 | trTaskProgress.setCurrentActionAmount(currentActionAmount); | 664 | trTaskProgress.setCurrentActionAmount(currentActionAmount); |
| 534 | trTaskProgress.setCompletionTime(completionTime); | 665 | trTaskProgress.setCompletionTime(completionTime); |
| ... | @@ -539,23 +670,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -539,23 +670,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 539 | 670 | ||
| 540 | // 更新任务完成情况 | 671 | // 更新任务完成情况 |
| 541 | this.doRefreshTrTaskProcess(trTaskProgress); | 672 | this.doRefreshTrTaskProcess(trTaskProgress); |
| 542 | 673 | // 行为量达标 | |
| 543 | if (status == 1) { | 674 | if (currentActionAmount.compareTo(actionAmount) == 0) { |
| 544 | array.add(task); | ||
| 545 | } | ||
| 546 | |||
| 547 | } | ||
| 548 | |||
| 549 | if (CollectionUtils.isEmpty(array)) { | ||
| 550 | return true; | 675 | return true; |
| 551 | } | 676 | } |
| 552 | 677 | } | |
| 553 | 678 | ||
| 554 | return false; | 679 | return false; |
| 555 | } | 680 | } |
| 556 | 681 | ||
| 557 | |||
| 558 | |||
| 559 | /** | 682 | /** |
| 560 | * 获取任务模板对应的任务列表 | 683 | * 获取任务模板对应的任务列表 |
| 561 | * | 684 | * | ... | ... |
| ... | @@ -15,7 +15,6 @@ public class RabbitMqConfig { | ... | @@ -15,7 +15,6 @@ public class RabbitMqConfig { |
| 15 | public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv"; | 15 | public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv"; |
| 16 | public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin"; | 16 | public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin"; |
| 17 | 17 | ||
| 18 | |||
| 19 | @Bean | 18 | @Bean |
| 20 | FanoutExchange ucFanoutExchange(){ | 19 | FanoutExchange ucFanoutExchange(){ |
| 21 | return ExchangeBuilder.fanoutExchange(UC_EXCHANGE_FANOUT).build(); | 20 | return ExchangeBuilder.fanoutExchange(UC_EXCHANGE_FANOUT).build(); |
| ... | @@ -41,6 +40,4 @@ public class RabbitMqConfig { | ... | @@ -41,6 +40,4 @@ public class RabbitMqConfig { |
| 41 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); | 40 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); |
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | |||
| 45 | |||
| 46 | } | 43 | } | ... | ... |
| ... | @@ -62,15 +62,16 @@ spring: | ... | @@ -62,15 +62,16 @@ spring: |
| 62 | #连接超时时间 | 62 | #连接超时时间 |
| 63 | timeout: 5000 | 63 | timeout: 5000 |
| 64 | rabbitmq: | 64 | rabbitmq: |
| 65 | host: 122.112.214.149 # rabbitmq的连接地址 | 65 | host: 47.100.212.170 # rabbitmq的连接地址 |
| 66 | # host: 122.112.214.149 # rabbitmq的连接地址 | ||
| 66 | #host: 139.196.192.242 # rabbitmq的连接地址 | 67 | #host: 139.196.192.242 # rabbitmq的连接地址 |
| 67 | port: 5672 # rabbitmq的连接端口号 | 68 | port: 5672 # rabbitmq的连接端口号 |
| 68 | #virtual-host: /member_center # rabbitmq的虚拟host | 69 | #virtual-host: /member_center # rabbitmq的虚拟host |
| 69 | #username: member_center # rabbitmq的用户名 | 70 | #username: member_center # rabbitmq的用户名 |
| 70 | #password: Tjlh@2021 # rabbitmq的密码 | 71 | #password: Tjlh@2021 # rabbitmq的密码 |
| 71 | virtual-host: / # rabbitmq的虚拟host | 72 | virtual-host: test # rabbitmq的虚拟host |
| 72 | username: guest # rabbitmq的用户名 | 73 | username: omo_test # rabbitmq的用户名 |
| 73 | password: guest # rabbitmq的密码 | 74 | password: omo_test # rabbitmq的密码 |
| 74 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | 75 | publisher-confirms: true #如果对异步消息需要回调必须设置为true |
| 75 | 76 | ||
| 76 | #jwt。依赖的common中有需要jwt的部分属性。 | 77 | #jwt。依赖的common中有需要jwt的部分属性。 | ... | ... |
| ... | @@ -55,7 +55,7 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -55,7 +55,7 @@ public class PointsOperationControllerTest extends BaseTest { |
| 55 | TempPoints tempPoints = new TempPoints(); | 55 | TempPoints tempPoints = new TempPoints(); |
| 56 | tempPoints.setPoints(10L); | 56 | tempPoints.setPoints(10L); |
| 57 | tempPoints.setPointsType(0); | 57 | tempPoints.setPointsType(0); |
| 58 | tempPoints.setMemberId(2L); | 58 | tempPoints.setMemberId(3L); |
| 59 | tempPoints.setRightsSendStrategy(0); | 59 | tempPoints.setRightsSendStrategy(0); |
| 60 | tempPoints.setAccountId(2L); | 60 | tempPoints.setAccountId(2L); |
| 61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-10-27 09:00:00")); | 61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-10-27 09:00:00")); | ... | ... |
| ... | @@ -24,7 +24,7 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -24,7 +24,7 @@ public class TaskOperationControllerTest extends BaseTest { |
| 24 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); | 24 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); |
| 25 | msgData.setEvent(1); | 25 | msgData.setEvent(1); |
| 26 | msgData.setRemarks("remark"); | 26 | msgData.setRemarks("remark"); |
| 27 | msgData.setMemberId(1L); | 27 | msgData.setMemberId(3L); |
| 28 | msgData.setDeviceType(2); | 28 | msgData.setDeviceType(2); |
| 29 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); | 29 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); |
| 30 | dataSyncMsg.setMsg(msgData); | 30 | dataSyncMsg.setMsg(msgData); | ... | ... |
| ... | @@ -16,7 +16,7 @@ public class TaskOperationServiceTest extends BaseTest { | ... | @@ -16,7 +16,7 @@ public class TaskOperationServiceTest extends BaseTest { |
| 16 | 16 | ||
| 17 | @Test | 17 | @Test |
| 18 | public void dealTaskTest() { | 18 | public void dealTaskTest() { |
| 19 | Long memberId = 2L; | 19 | Long memberId = 3L; |
| 20 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | 20 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); |
| 21 | // dataSyncMsg.setEntityType(EntityType.MEMBER); | 21 | // dataSyncMsg.setEntityType(EntityType.MEMBER); |
| 22 | dataSyncMsg.setEventType(EventType.LOGIN.name()); | 22 | dataSyncMsg.setEventType(EventType.LOGIN.name()); | ... | ... |
-
Please register or sign in to post a comment