修复测试缺陷
Showing
28 changed files
with
284 additions
and
97 deletions
| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | <entry key="lastExternalPluginCheckTime" value="1636770952724" /> | 10 | <entry key="lastExternalPluginCheckTime" value="1636770952724" /> |
| 11 | </map> | 11 | </map> |
| 12 | </option> | 12 | </option> |
| 13 | <option name="version" value="5" /> | 13 | <option name="version" value="6" /> |
| 14 | </configuration> | 14 | </configuration> |
| 15 | </facet> | 15 | </facet> |
| 16 | </component> | 16 | </component> | ... | ... |
| 1 | package com.topdraw.module.mq; | 1 | package com.topdraw.module.mq; |
| 2 | 2 | ||
| 3 | import javax.annotation.Resource; | ||
| 4 | |||
| 3 | // 关注的事件 | 5 | // 关注的事件 |
| 4 | public enum EventType { | 6 | public enum EventType { |
| 5 | 7 | ||
| ... | @@ -22,7 +24,7 @@ public enum EventType { | ... | @@ -22,7 +24,7 @@ public enum EventType { |
| 22 | // 登录 | 24 | // 登录 |
| 23 | LOGIN, | 25 | LOGIN, |
| 24 | // 订购产品包 | 26 | // 订购产品包 |
| 25 | SUBSCRIBE_PRODUCT_PACKAGE | 27 | SUBSCRIBE_PRODUCT_PACKAGE, |
| 26 | 28 | // 签到 | |
| 27 | 29 | SIGN | |
| 28 | } | 30 | } | ... | ... |
| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | <entry key="lastExternalPluginCheckTime" value="1636770952726" /> | 10 | <entry key="lastExternalPluginCheckTime" value="1636770952726" /> |
| 11 | </map> | 11 | </map> |
| 12 | </option> | 12 | </option> |
| 13 | <option name="version" value="5" /> | 13 | <option name="version" value="6" /> |
| 14 | </configuration> | 14 | </configuration> |
| 15 | </facet> | 15 | </facet> |
| 16 | </component> | 16 | </component> | ... | ... |
| ... | @@ -125,6 +125,17 @@ | ... | @@ -125,6 +125,17 @@ |
| 125 | 125 | ||
| 126 | <build> | 126 | <build> |
| 127 | <finalName>member-service</finalName> | 127 | <finalName>member-service</finalName> |
| 128 | <resources> | ||
| 129 | <resource> | ||
| 130 | <directory>src/main/java</directory> | ||
| 131 | <includes> | ||
| 132 | <include>**/*.xml</include> | ||
| 133 | </includes> | ||
| 134 | </resource> | ||
| 135 | <resource> | ||
| 136 | <directory>src/main/resources</directory> | ||
| 137 | </resource> | ||
| 138 | </resources> | ||
| 128 | <plugins> | 139 | <plugins> |
| 129 | <plugin> | 140 | <plugin> |
| 130 | <groupId>org.springframework.boot</groupId> | 141 | <groupId>org.springframework.boot</groupId> |
| ... | @@ -143,6 +154,7 @@ | ... | @@ -143,6 +154,7 @@ |
| 143 | </plugin> | 154 | </plugin> |
| 144 | <!-- 复制指定配置文件到指定目录 --> | 155 | <!-- 复制指定配置文件到指定目录 --> |
| 145 | <plugin> | 156 | <plugin> |
| 157 | <groupId>org.apache.maven.plugins</groupId> | ||
| 146 | <artifactId>maven-resources-plugin</artifactId> | 158 | <artifactId>maven-resources-plugin</artifactId> |
| 147 | <executions> | 159 | <executions> |
| 148 | <execution> | 160 | <execution> | ... | ... |
| ... | @@ -28,7 +28,7 @@ public class AsyncMqProducer { | ... | @@ -28,7 +28,7 @@ public class AsyncMqProducer { |
| 28 | @Autowired | 28 | @Autowired |
| 29 | MessageProducer messageProducer; | 29 | MessageProducer messageProducer; |
| 30 | 30 | ||
| 31 | @Resource(name = "executorTask") | 31 | @Autowired |
| 32 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 32 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 33 | 33 | ||
| 34 | @Pointcut(value = "@annotation(asyncMqSend)") | 34 | @Pointcut(value = "@annotation(asyncMqSend)") | ... | ... |
| ... | @@ -90,7 +90,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -90,7 +90,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
| 90 | : new MemberLevelDTO(); | 90 | : new MemberLevelDTO(); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | @Cacheable(cacheNames = "uc-member_level",key = "#level") | ||
| 94 | @Override | 93 | @Override |
| 95 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 94 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
| 96 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | 95 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | ... | ... |
| ... | @@ -75,7 +75,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -75,7 +75,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
| 75 | * @param memberId | 75 | * @param memberId |
| 76 | * @return | 76 | * @return |
| 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 | ||
| ... | @@ -87,4 +87,8 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -87,4 +87,8 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
| 87 | void deleteBatchByIds(List<Long> id); | 87 | void deleteBatchByIds(List<Long> id); |
| 88 | 88 | ||
| 89 | List<PointsAvailable> findByExpireTimeBefore(Timestamp now); | 89 | List<PointsAvailable> findByExpireTimeBefore(Timestamp now); |
| 90 | |||
| 91 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1" | ||
| 92 | ,nativeQuery = true) | ||
| 93 | long findTotalCountByMemberId(Long memberId); | ||
| 90 | } | 94 | } | ... | ... |
| ... | @@ -136,4 +136,6 @@ public interface PointsAvailableService { | ... | @@ -136,4 +136,6 @@ public interface PointsAvailableService { |
| 136 | 136 | ||
| 137 | 137 | ||
| 138 | List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now); | 138 | List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now); |
| 139 | |||
| 140 | long findTotalPointsByMemberId(Long memberId); | ||
| 139 | } | 141 | } | ... | ... |
| ... | @@ -163,4 +163,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -163,4 +163,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 163 | return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now)); | 163 | return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now)); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | @Override | ||
| 167 | public long findTotalPointsByMemberId(Long memberId) { | ||
| 168 | return this.PointsAvailableRepository.findTotalCountByMemberId(memberId); | ||
| 169 | } | ||
| 170 | |||
| 166 | } | 171 | } | ... | ... |
| ... | @@ -20,7 +20,7 @@ import io.swagger.annotations.*; | ... | @@ -20,7 +20,7 @@ import io.swagger.annotations.*; |
| 20 | //@RequestMapping("/api/Points") | 20 | //@RequestMapping("/api/Points") |
| 21 | public class PointsController { | 21 | public class PointsController { |
| 22 | 22 | ||
| 23 | /* @Autowired | 23 | /*@Autowired |
| 24 | private PointsService PointsService; | 24 | private PointsService PointsService; |
| 25 | 25 | ||
| 26 | @GetMapping | 26 | @GetMapping |
| ... | @@ -33,9 +33,9 @@ public class PointsController { | ... | @@ -33,9 +33,9 @@ public class PointsController { |
| 33 | @ApiOperation("查询所有Points") | 33 | @ApiOperation("查询所有Points") |
| 34 | public ResultInfo getPointss(PointsQueryCriteria criteria) { | 34 | public ResultInfo getPointss(PointsQueryCriteria criteria) { |
| 35 | return ResultInfo.success(PointsService.queryAll(criteria)); | 35 | return ResultInfo.success(PointsService.queryAll(criteria)); |
| 36 | } | 36 | }*/ |
| 37 | 37 | ||
| 38 | @Log | 38 | /*@Log |
| 39 | @PostMapping | 39 | @PostMapping |
| 40 | @ApiOperation("新增Points") | 40 | @ApiOperation("新增Points") |
| 41 | public ResultInfo create(@Validated @RequestBody Points resources) { | 41 | public ResultInfo create(@Validated @RequestBody Points resources) { | ... | ... |
| ... | @@ -80,7 +80,7 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -80,7 +80,7 @@ public class TaskServiceImpl implements TaskService { |
| 80 | TaskRepository.delete(Task); | 80 | TaskRepository.delete(Task); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") | 83 | // @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") |
| 84 | @Override | 84 | @Override |
| 85 | public List<Task> findByTemplateId(Long taskTemplateId) { | 85 | public List<Task> findByTemplateId(Long taskTemplateId) { |
| 86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | 86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | ... | ... |
| ... | @@ -93,10 +93,9 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { | ... | @@ -93,10 +93,9 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { |
| 93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; | 93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event") | 96 | // @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event") |
| 97 | @Override | 97 | @Override |
| 98 | public TaskTemplate findByType(Integer event) { | 98 | public TaskTemplate findByType(Integer event) { |
| 99 | System.out.println("查询数据库了!!"); | ||
| 100 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; | 99 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; |
| 101 | } | 100 | } |
| 102 | } | 101 | } | ... | ... |
| ... | @@ -17,9 +17,13 @@ import org.slf4j.LoggerFactory; | ... | @@ -17,9 +17,13 @@ import org.slf4j.LoggerFactory; |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 18 | import org.springframework.data.domain.Pageable; | 18 | import org.springframework.data.domain.Pageable; |
| 19 | import org.springframework.util.Assert; | 19 | import org.springframework.util.Assert; |
| 20 | import org.springframework.util.CollectionUtils; | ||
| 20 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 21 | import org.springframework.web.bind.annotation.*; | 22 | import org.springframework.web.bind.annotation.*; |
| 22 | 23 | ||
| 24 | import java.util.List; | ||
| 25 | import java.util.Objects; | ||
| 26 | |||
| 23 | /** | 27 | /** |
| 24 | * @author XiangHan | 28 | * @author XiangHan |
| 25 | * @date 2021-10-22 | 29 | * @date 2021-10-22 |
| ... | @@ -32,11 +36,11 @@ public class PointsOperationController { | ... | @@ -32,11 +36,11 @@ public class PointsOperationController { |
| 32 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class); | 36 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class); |
| 33 | 37 | ||
| 34 | @Autowired | 38 | @Autowired |
| 35 | private PointsOperationService pointsOperationService; | 39 | PointsOperationService pointsOperationService; |
| 36 | @Autowired | 40 | @Autowired |
| 37 | private PointsDetailService pointsDetailService; | 41 | PointsDetailService pointsDetailService; |
| 38 | @Autowired | 42 | @Autowired |
| 39 | private PointsAvailableService pointsAvailableService; | 43 | PointsAvailableService pointsAvailableService; |
| 40 | 44 | ||
| 41 | @GetMapping(value = "/pagePointsDetails") | 45 | @GetMapping(value = "/pagePointsDetails") |
| 42 | @ApiOperation("查询PointsDetail") | 46 | @ApiOperation("查询PointsDetail") |
| ... | @@ -56,10 +60,29 @@ public class PointsOperationController { | ... | @@ -56,10 +60,29 @@ public class PointsOperationController { |
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | @Log | 62 | @Log |
| 63 | @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}") | ||
| 64 | @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用") | ||
| 65 | public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) { | ||
| 66 | Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id); | ||
| 67 | return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong); | ||
| 68 | } | ||
| 69 | |||
| 70 | /*@Log | ||
| 71 | @PostMapping(value = "/cleanInvalidPointsAndCalculateCurrentPointsByMemberIds") | ||
| 72 | @ApiOperation("清除过期积分并计算总积分,管理端使用") | ||
| 73 | public ResultInfo cleanInvalidPointsAndCalculateCurrentPointsByMemberIds(List<Long> memberIds) { | ||
| 74 | if (!CollectionUtils.isEmpty(memberIds)) { | ||
| 75 | for (Long memberId : memberIds) { | ||
| 76 | this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | return ResultInfo.success(); | ||
| 80 | }*/ | ||
| 81 | |||
| 82 | @Log | ||
| 59 | @PostMapping(value = "/grantPointsByManual") | 83 | @PostMapping(value = "/grantPointsByManual") |
| 60 | @ApiOperation("新增PointsDetail") | 84 | @ApiOperation("新增PointsDetail") |
| 61 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { | 85 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { |
| 62 | LOG.info("======>>>>> grantPointsByManual start"); | ||
| 63 | Long memberId = tempPoints.getMemberId(); | 86 | Long memberId = tempPoints.getMemberId(); |
| 64 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); | 87 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); |
| 65 | return ResultInfo.success(); | 88 | return ResultInfo.success(); | ... | ... |
| ... | @@ -35,13 +35,11 @@ public interface PointsOperationService { | ... | @@ -35,13 +35,11 @@ public interface PointsOperationService { |
| 35 | */ | 35 | */ |
| 36 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); | 36 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); |
| 37 | 37 | ||
| 38 | /** | ||
| 39 | * 清理过期的积分 | ||
| 40 | */ | ||
| 41 | void cleanInvalidAvailablePoints(); | ||
| 42 | 38 | ||
| 43 | /** | 39 | /** |
| 44 | * 清理过期的积分 | 40 | * 清理过期并计算可用总积分 |
| 41 | * @param memberId | ||
| 42 | * @return | ||
| 45 | */ | 43 | */ |
| 46 | void cleanInvalidAvailablePointsByMemberId(Long memberId); | 44 | Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); |
| 47 | } | 45 | } | ... | ... |
| ... | @@ -45,7 +45,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -45,7 +45,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 45 | RightsOperationService rightsOperationService; | 45 | RightsOperationService rightsOperationService; |
| 46 | @Autowired | 46 | @Autowired |
| 47 | RedissonClient redissonClient; | 47 | RedissonClient redissonClient; |
| 48 | @Resource(name = "executorTask") | 48 | @Autowired |
| 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 50 | 50 | ||
| 51 | // 过期阀值(默认一个月) | 51 | // 过期阀值(默认一个月) |
| ... | @@ -99,9 +99,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -99,9 +99,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 99 | // Long userId = tempCoupon.getUserId(); | 99 | // Long userId = tempCoupon.getUserId(); |
| 100 | Long memberId = tempCoupon.getMemberId(); | 100 | Long memberId = tempCoupon.getMemberId(); |
| 101 | Integer rightsAmount = tempCoupon.getRightsAmount(); | 101 | Integer rightsAmount = tempCoupon.getRightsAmount(); |
| 102 | // RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); | 102 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); |
| 103 | try { | 103 | try { |
| 104 | // RedissonUtil.lock(rLock); | 104 | RedissonUtil.lock(rLock); |
| 105 | // 1.历史总优惠券数量 | 105 | // 1.历史总优惠券数量 |
| 106 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); | 106 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); |
| 107 | // 1.当前总优惠券数量 | 107 | // 1.当前总优惠券数量 |
| ... | @@ -118,7 +118,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -118,7 +118,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 118 | e.printStackTrace(); | 118 | e.printStackTrace(); |
| 119 | throw e; | 119 | throw e; |
| 120 | } finally { | 120 | } finally { |
| 121 | // RedissonUtil.unlock(rLock); | 121 | RedissonUtil.unlock(rLock); |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | 124 | ||
| ... | @@ -160,7 +160,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -160,7 +160,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 160 | * @return | 160 | * @return |
| 161 | */ | 161 | */ |
| 162 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | 162 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { |
| 163 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp1(LocalDateTime.now().plusDays(expireFactor)); | 163 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp(LocalDateTime.now().plusDays(expireFactor)); |
| 164 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); | 164 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); |
| 165 | } | 165 | } |
| 166 | 166 | ... | ... |
| ... | @@ -43,7 +43,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -43,7 +43,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 43 | MemberLevelService memberLevelService; | 43 | MemberLevelService memberLevelService; |
| 44 | @Autowired | 44 | @Autowired |
| 45 | RedissonClient redissonClient; | 45 | RedissonClient redissonClient; |
| 46 | @Resource(name = "executorTask") | 46 | @Autowired |
| 47 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 47 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 48 | 48 | ||
| 49 | @Override | 49 | @Override |
| ... | @@ -83,10 +83,12 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -83,10 +83,12 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 83 | // 总积分 | 83 | // 总积分 |
| 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); |
| 85 | // 1.添加成长值记录 | 85 | // 1.添加成长值记录 |
| 86 | this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | 86 | // this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); |
| 87 | // this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
| 88 | // 2.更新成长值与等级 | 87 | // 2.更新成长值与等级 |
| 89 | this.refreshMemberExpAndLevel(tempExp,totalExp); | 88 | this.refreshMemberExpAndLevel(tempExp,totalExp); |
| 89 | |||
| 90 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
| 91 | |||
| 90 | } catch (Exception e) { | 92 | } catch (Exception e) { |
| 91 | e.printStackTrace(); | 93 | e.printStackTrace(); |
| 92 | throw e; | 94 | throw e; |
| ... | @@ -116,10 +118,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -116,10 +118,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 116 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { | 118 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { |
| 117 | 119 | ||
| 118 | Long memberId = tempExp.getMemberId(); | 120 | Long memberId = tempExp.getMemberId(); |
| 119 | |||
| 120 | // RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); | ||
| 121 | try { | ||
| 122 | // RedissonUtil.lock(rLock); | ||
| 123 | // 1.获取当前成长值 | 121 | // 1.获取当前成长值 |
| 124 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | 122 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); |
| 125 | // 2.获取下一级需要的成长值 | 123 | // 2.获取下一级需要的成长值 |
| ... | @@ -128,12 +126,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -128,12 +126,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 128 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); | 126 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); |
| 129 | // 5.更新用户信息 | 127 | // 5.更新用户信息 |
| 130 | this.updateMemberInfo(level, totalExp, memberId); | 128 | this.updateMemberInfo(level, totalExp, memberId); |
| 131 | } catch (Exception e) { | ||
| 132 | e.printStackTrace(); | ||
| 133 | throw e; | ||
| 134 | } finally { | ||
| 135 | // RedissonUtil.unlock(rLock); | ||
| 136 | } | ||
| 137 | } | 129 | } |
| 138 | 130 | ||
| 139 | /** | 131 | /** | ... | ... |
This diff is collapsed.
Click to expand it.
| ... | @@ -22,7 +22,7 @@ import org.springframework.util.StringUtils; | ... | @@ -22,7 +22,7 @@ import org.springframework.util.StringUtils; |
| 22 | import javax.annotation.Resource; | 22 | import javax.annotation.Resource; |
| 23 | import java.sql.Timestamp; | 23 | import java.sql.Timestamp; |
| 24 | import java.util.*; | 24 | import java.util.*; |
| 25 | import java.util.concurrent.Future; | 25 | import java.util.concurrent.*; |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 权益处理 | 28 | * 权益处理 |
| ... | @@ -47,8 +47,10 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -47,8 +47,10 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 47 | @Autowired | 47 | @Autowired |
| 48 | PointsOperationService pointsOperationService; | 48 | PointsOperationService pointsOperationService; |
| 49 | 49 | ||
| 50 | @Resource(name = "executorTask") | 50 | // @Autowired |
| 51 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 51 | // ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 52 | |||
| 53 | private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10); | ||
| 52 | 54 | ||
| 53 | /** | 55 | /** |
| 54 | * 系统手动发放 | 56 | * 系统手动发放 |
| ... | @@ -73,16 +75,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -73,16 +75,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 73 | @Override | 75 | @Override |
| 74 | public void grantRights(Map<RightType, Object> tempRightsMap) { | 76 | public void grantRights(Map<RightType, Object> tempRightsMap) { |
| 75 | 77 | ||
| 76 | this.threadPoolTaskExecutor.execute(()-> { | 78 | // this.threadPoolTaskExecutor.execute(()-> { |
| 77 | // 2.创建权益历史对象 | 79 | // 2.创建权益历史对象 |
| 78 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | 80 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); |
| 79 | // 3.保存权益历史 | 81 | // 3.保存权益历史 |
| 80 | this.doInsertTrRightHistory(rightsList); | 82 | this.doInsertTrRightHistory(rightsList); |
| 81 | }); | 83 | // }); |
| 82 | 84 | ||
| 83 | // 1.权益下发 | 85 | // 1.权益下发 |
| 84 | this.refresh(tempRightsMap); | 86 | this.refresh(tempRightsMap); |
| 85 | |||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | /** | 89 | /** |
| ... | @@ -123,7 +124,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -123,7 +124,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 123 | * @param tempPointsList 权益列表 | 124 | * @param tempPointsList 权益列表 |
| 124 | */ | 125 | */ |
| 125 | private void grantPoint(List<TempPoints> tempPointsList) { | 126 | private void grantPoint(List<TempPoints> tempPointsList) { |
| 127 | log.info(Thread.currentThread().getName() + "=========>>grantPoint start"); | ||
| 126 | if (!CollectionUtils.isEmpty(tempPointsList)) | 128 | if (!CollectionUtils.isEmpty(tempPointsList)) |
| 129 | log.info("=======>> tempPointsList ======>> " + tempPointsList.toString()); | ||
| 127 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); | 130 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); |
| 128 | } | 131 | } |
| 129 | 132 | ||
| ... | @@ -140,20 +143,79 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -140,20 +143,79 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 140 | } | 143 | } |
| 141 | 144 | ||
| 142 | 145 | ||
| 146 | |||
| 143 | /** | 147 | /** |
| 144 | * 权益发放 | 148 | * 权益发放 |
| 145 | * @param tempRightsMap | 149 | * @param tempRightsMap |
| 146 | */ | 150 | */ |
| 147 | private void refresh(Map<RightType, Object> tempRightsMap) { | 151 | private void refresh(Map<RightType, Object> tempRightsMap) { |
| 148 | 152 | /*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{ | |
| 149 | this.threadPoolTaskExecutor.submit(() -> { | 153 | log.info(Thread.currentThread().getName() + "=========>> start"); |
| 150 | // 积分 | 154 | // 积分 |
| 151 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | 155 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); |
| 156 | log.info(Thread.currentThread().getName() + "=========>>grantPoint end"); | ||
| 157 | // 成长值 | ||
| 158 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 159 | // 优惠券 | ||
| 160 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 161 | return null; | ||
| 162 | }); | ||
| 163 | FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{ | ||
| 164 | // 积分 | ||
| 165 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 152 | // 成长值 | 166 | // 成长值 |
| 153 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | 167 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); |
| 154 | // 优惠券 | 168 | // 优惠券 |
| 169 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 170 | return null; | ||
| 171 | }); | ||
| 172 | FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{ | ||
| 173 | // 积分 | ||
| 174 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 175 | // 成长值 | ||
| 176 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 177 | // 优惠券 | ||
| 155 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | 178 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); |
| 179 | return null; | ||
| 156 | }); | 180 | }); |
| 181 | this.threadPoolTaskExecutor.execute(futureTask1); | ||
| 182 | this.threadPoolTaskExecutor.execute(futureTask2); | ||
| 183 | this.threadPoolTaskExecutor.execute(futureTask3);*/ | ||
| 184 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
| 185 | // 积分 | ||
| 186 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 187 | // 成长值 | ||
| 188 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 189 | // 优惠券 | ||
| 190 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 191 | });*/ | ||
| 192 | |||
| 193 | |||
| 194 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
| 195 | log.info(Thread.currentThread().getName() + "=========>> start"); | ||
| 196 | // 积分 | ||
| 197 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 198 | log.info(Thread.currentThread().getName() + "=========>> end"); | ||
| 199 | });*/ | ||
| 200 | |||
| 201 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); | ||
| 202 | if (!CollectionUtils.isEmpty(tempPointsList)) { | ||
| 203 | // 积分 | ||
| 204 | this.grantPoint(tempPointsList); | ||
| 205 | } | ||
| 206 | |||
| 207 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); | ||
| 208 | if (!CollectionUtils.isEmpty(tempExpList)) { | ||
| 209 | // 成长值 | ||
| 210 | this.grantExp(tempExpList); | ||
| 211 | } | ||
| 212 | |||
| 213 | List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); | ||
| 214 | if (!CollectionUtils.isEmpty(tempCouponList)) { | ||
| 215 | // 优惠券 | ||
| 216 | this.grantCoupon(tempCouponList); | ||
| 217 | } | ||
| 218 | |||
| 157 | } | 219 | } |
| 158 | 220 | ||
| 159 | /** | 221 | /** |
| ... | @@ -178,9 +240,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -178,9 +240,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 178 | RightsDTO rightsDTO = this.getRights(rightId); | 240 | RightsDTO rightsDTO = this.getRights(rightId); |
| 179 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 241 | // 权益的实体类型 1:积分;2成长值;3优惠券 |
| 180 | String type = rightsDTO.getEntityType(); | 242 | String type = rightsDTO.getEntityType(); |
| 181 | String code = rightsDTO.getCode(); | 243 | // String code = rightsDTO.getCode(); |
| 182 | Long expireTime = rightsDTO.getExpireTime(); | 244 | Long expireTime = rightsDTO.getExpireTime(); |
| 183 | Timestamp validTime = rightsDTO.getValidTime(); | 245 | // Timestamp validTime = rightsDTO.getValidTime(); |
| 184 | 246 | ||
| 185 | 247 | ||
| 186 | switch (type) { | 248 | switch (type) { |
| ... | @@ -192,6 +254,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -192,6 +254,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 192 | tempCoupon.setUserId(userId); | 254 | tempCoupon.setUserId(userId); |
| 193 | tempCoupon.setRightsAmount(1); | 255 | tempCoupon.setRightsAmount(1); |
| 194 | tempCoupon.setRightsSendStrategy(0); | 256 | tempCoupon.setRightsSendStrategy(0); |
| 257 | if (Objects.nonNull(expireTime)) | ||
| 195 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); | 258 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); |
| 196 | tempCouponList.add(tempCoupon); | 259 | tempCouponList.add(tempCoupon); |
| 197 | break; | 260 | break; |
| ... | @@ -224,12 +287,12 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -224,12 +287,12 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 224 | if (!CollectionUtils.isEmpty(tempCouponList)) | 287 | if (!CollectionUtils.isEmpty(tempCouponList)) |
| 225 | map.put(RightType.COUPON,tempCouponList); | 288 | map.put(RightType.COUPON,tempCouponList); |
| 226 | // 成长值 | 289 | // 成长值 |
| 227 | if (!CollectionUtils.isEmpty(tempExpList)) | 290 | /* if (!CollectionUtils.isEmpty(tempExpList)) |
| 228 | map.put(RightType.EXP,tempExpList); | 291 | map.put(RightType.EXP,tempExpList);*/ |
| 229 | // 积分 | 292 | // 积分 |
| 230 | if (!CollectionUtils.isEmpty(tempPointsList)) | 293 | /* if (!CollectionUtils.isEmpty(tempPointsList)) |
| 231 | map.put(RightType.POINTS,tempPointsList); | 294 | map.put(RightType.POINTS,tempPointsList); |
| 232 | 295 | */ | |
| 233 | return map; | 296 | return map; |
| 234 | } | 297 | } |
| 235 | 298 | ... | ... |
| ... | @@ -79,11 +79,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -79,11 +79,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 79 | Long memberId = msgData.getMemberId(); | 79 | Long memberId = msgData.getMemberId(); |
| 80 | 80 | ||
| 81 | long l = System.currentTimeMillis(); | 81 | long l = System.currentTimeMillis(); |
| 82 | // 验证会员信息 | ||
| 83 | /*boolean b = this.validatedMember(memberId); | ||
| 84 | if (!b) { | ||
| 85 | throw new BadRequestException("【member status exception!!】"); | ||
| 86 | }*/ | ||
| 87 | 82 | ||
| 88 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 | 83 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 |
| 89 | TaskTemplate taskTemplate = this.getTaskTemplate(event); | 84 | TaskTemplate taskTemplate = this.getTaskTemplate(event); |
| ... | @@ -92,10 +87,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -92,10 +87,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 92 | // 4.判断当前用户是否满足任务完成条件 | 87 | // 4.判断当前用户是否满足任务完成条件 |
| 93 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); | 88 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); |
| 94 | if (checkResult) { | 89 | if (checkResult) { |
| 90 | |||
| 95 | // 5.权益区分(积分、权益、成长值) | 91 | // 5.权益区分(积分、权益、成长值) |
| 96 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 92 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); |
| 97 | // 6.权益发放 | 93 | // 6.权益发放 |
| 98 | this.grantRight(tempRightsMap); | 94 | this.grantRight(tempRightsMap); |
| 95 | |||
| 99 | } | 96 | } |
| 100 | 97 | ||
| 101 | long r = System.currentTimeMillis(); | 98 | long r = System.currentTimeMillis(); |
| ... | @@ -544,16 +541,19 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -544,16 +541,19 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 544 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && | 541 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && |
| 545 | (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && | 542 | (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && |
| 546 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && | 543 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && |
| 547 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) && | 544 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) && |
| 548 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() <= memberDTO1.getVip()) | 545 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip()) |
| 549 | ).collect(Collectors.toList()); | 546 | ).collect(Collectors.toList()); |
| 550 | 547 | ||
| 548 | // 没有满足条件的数据 | ||
| 551 | if (CollectionUtils.isEmpty(taskStream)) { | 549 | if (CollectionUtils.isEmpty(taskStream)) { |
| 550 | return false; | ||
| 551 | } else { | ||
| 552 | // 获取当前任务的完成情况 | 552 | // 获取当前任务的完成情况 |
| 553 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); | 553 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); |
| 554 | return result; | 554 | return result; |
| 555 | } | 555 | } |
| 556 | return true; | 556 | |
| 557 | }; | 557 | }; |
| 558 | return compareTaskCondition.compareCondition(memberDTO,taskList); | 558 | return compareTaskCondition.compareCondition(memberDTO,taskList); |
| 559 | } | 559 | } |
| ... | @@ -614,7 +614,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -614,7 +614,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 614 | Objects.nonNull(completionTime1) && | 614 | Objects.nonNull(completionTime1) && |
| 615 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | 615 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { |
| 616 | 616 | ||
| 617 | throw new BadRequestException("任务已完成,请明日再来"); | 617 | return false; |
| 618 | 618 | ||
| 619 | // 未做,成功 | 619 | // 未做,成功 |
| 620 | } else { | 620 | } else { | ... | ... |
| ... | @@ -22,11 +22,10 @@ public class RedissonConfig { | ... | @@ -22,11 +22,10 @@ public class RedissonConfig { |
| 22 | private String password; | 22 | private String password; |
| 23 | 23 | ||
| 24 | @Bean | 24 | @Bean |
| 25 | public RedissonClient redisson(){ | 25 | public Redisson redisson(){ |
| 26 | Config config = new Config(); | 26 | Config config = new Config(); |
| 27 | // config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword("redis123"); | ||
| 28 | if (StringUtils.isNotEmpty(password)) { | 27 | if (StringUtils.isNotEmpty(password)) { |
| 29 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password);; | 28 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password); |
| 30 | } else { | 29 | } else { |
| 31 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port); | 30 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port); |
| 32 | } | 31 | } |
| ... | @@ -34,7 +33,8 @@ public class RedissonConfig { | ... | @@ -34,7 +33,8 @@ public class RedissonConfig { |
| 34 | "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377", | 33 | "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377", |
| 35 | "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380") | 34 | "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380") |
| 36 | .setPassword("a123456").setScanInterval(5000);*/ | 35 | .setPassword("a123456").setScanInterval(5000);*/ |
| 37 | return Redisson.create(config); | 36 | Redisson redissonClient = (Redisson)Redisson.create(config); |
| 37 | return redissonClient; | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | } | 40 | } | ... | ... |
| ... | @@ -11,13 +11,12 @@ import org.springframework.stereotype.Component; | ... | @@ -11,13 +11,12 @@ import org.springframework.stereotype.Component; |
| 11 | 11 | ||
| 12 | import java.util.concurrent.ThreadPoolExecutor; | 12 | import java.util.concurrent.ThreadPoolExecutor; |
| 13 | 13 | ||
| 14 | @Configuration | 14 | /*@Configuration |
| 15 | @PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8") | 15 | @PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8") |
| 16 | @Slf4j | 16 | @Slf4j*/ |
| 17 | @EnableAsync | ||
| 18 | public class ThreadPoolTaskExecutorConfig { | 17 | public class ThreadPoolTaskExecutorConfig { |
| 19 | 18 | ||
| 20 | @Value("${threadPoolExecutor.core_pool_size}") | 19 | /*@Value("${threadPoolExecutor.core_pool_size}") |
| 21 | private int corePoolSize; | 20 | private int corePoolSize; |
| 22 | @Value("${threadPoolExecutor.max_pool_size}") | 21 | @Value("${threadPoolExecutor.max_pool_size}") |
| 23 | private int maxPoolSize; | 22 | private int maxPoolSize; |
| ... | @@ -28,7 +27,7 @@ public class ThreadPoolTaskExecutorConfig { | ... | @@ -28,7 +27,7 @@ public class ThreadPoolTaskExecutorConfig { |
| 28 | @Value("${threadPoolExecutor.keep_alive_seconds}") | 27 | @Value("${threadPoolExecutor.keep_alive_seconds}") |
| 29 | private int keepAliveSeconds; | 28 | private int keepAliveSeconds; |
| 30 | 29 | ||
| 31 | @Bean(value = "executorTask") | 30 | @Bean |
| 32 | public ThreadPoolTaskExecutor executorTask(){ | 31 | public ThreadPoolTaskExecutor executorTask(){ |
| 33 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | 32 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 34 | // 核心线程数 | 33 | // 核心线程数 |
| ... | @@ -46,6 +45,6 @@ public class ThreadPoolTaskExecutorConfig { | ... | @@ -46,6 +45,6 @@ public class ThreadPoolTaskExecutorConfig { |
| 46 | // 线程初始化 | 45 | // 线程初始化 |
| 47 | executor.initialize(); | 46 | executor.initialize(); |
| 48 | return executor; | 47 | return executor; |
| 49 | } | 48 | }*/ |
| 50 | 49 | ||
| 51 | } | 50 | } | ... | ... |
| ... | @@ -31,12 +31,12 @@ public class RabbitMqConfig { | ... | @@ -31,12 +31,12 @@ public class RabbitMqConfig { |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | @Bean | 33 | @Bean |
| 34 | Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv){ | 34 | Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv) { |
| 35 | return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange); | 35 | return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | @Bean | 38 | @Bean |
| 39 | Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin){ | 39 | Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin) { |
| 40 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); | 40 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); |
| 41 | } | 41 | } |
| 42 | 42 | ... | ... |
| ... | @@ -3,6 +3,7 @@ package com.topdraw.util; | ... | @@ -3,6 +3,7 @@ package com.topdraw.util; |
| 3 | import java.sql.Timestamp; | 3 | import java.sql.Timestamp; |
| 4 | import java.time.Instant; | 4 | import java.time.Instant; |
| 5 | import java.time.LocalDateTime; | 5 | import java.time.LocalDateTime; |
| 6 | import java.time.ZoneId; | ||
| 6 | import java.time.ZoneOffset; | 7 | import java.time.ZoneOffset; |
| 7 | 8 | ||
| 8 | public class TimestampUtil { | 9 | public class TimestampUtil { |
| ... | @@ -12,33 +13,46 @@ public class TimestampUtil { | ... | @@ -12,33 +13,46 @@ public class TimestampUtil { |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | public static Timestamp now(LocalDateTime localDateTime) { | 15 | public static Timestamp now(LocalDateTime localDateTime) { |
| 15 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).getEpochSecond(); | 16 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
| 16 | return new Timestamp(epochSecond); | 17 | return new Timestamp(epochSecond); |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | public static long localDateTime2Timestamp(LocalDateTime localDateTime){ | 20 | public static long localDateTime2long(LocalDateTime localDateTime){ |
| 20 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | 21 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
| 21 | return epochSecond; | 22 | return epochSecond; |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | public static Timestamp localDateTime2Timestamp1(LocalDateTime localDateTime){ | 25 | public static Timestamp localDateTime2Timestamp(LocalDateTime localDateTime){ |
| 25 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | 26 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
| 26 | return long2Timestamp(epochSecond); | 27 | return long2Timestamp(epochSecond); |
| 27 | } | 28 | } |
| 28 | public static Timestamp long2Timestamp(long timestamp){ | 29 | public static Timestamp long2Timestamp(long timestamp){ |
| 29 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); | 30 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochMilli(timestamp)); |
| 30 | return timestamp1; | 31 | return timestamp1; |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | public static long Timestamp2long(Timestamp timestamp){ | 34 | public static long timestamp2long(Timestamp timestamp){ |
| 34 | return timestamp.toInstant().getEpochSecond(); | 35 | long l = timestamp.toInstant().toEpochMilli(); |
| 36 | return l; | ||
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | public static void main(String[] args) { | 39 | public static void main(String[] args) { |
| 38 | LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00); | 40 | long a = 1636616464000L; |
| 39 | long l = localDateTime2Timestamp(of); | 41 | long b = 1637046948588L; |
| 42 | long c = 1637047122176L; | ||
| 40 | // long l = 16342727230L; | 43 | // long l = 16342727230L; |
| 41 | Timestamp timestamp = long2Timestamp(l); | 44 | // Timestamp now = now(LocalDateTime.now()); |
| 42 | System.out.println(timestamp.toString()); | 45 | long l = localDateTime2long(LocalDateTime.now()); |
| 46 | System.out.println(l); | ||
| 47 | // System.out.println(now.toString()); | ||
| 48 | |||
| 49 | Timestamp timestamp1 = long2Timestamp(a); | ||
| 50 | // long l = localDateTime2Timestamp(of); | ||
| 51 | // long l = 16342727230L; | ||
| 52 | // Timestamp timestamp = long2Timestamp(l); | ||
| 53 | System.out.println(timestamp1.toString()); | ||
| 54 | |||
| 55 | long l1 = localDateTime2long(LocalDateTime.now()); | ||
| 56 | System.out.println(l1); | ||
| 43 | } | 57 | } |
| 44 | } | 58 | } | ... | ... |
| ... | @@ -2,12 +2,15 @@ | ... | @@ -2,12 +2,15 @@ |
| 2 | spring: | 2 | spring: |
| 3 | datasource: | 3 | datasource: |
| 4 | # 测试/演示库 | 4 | # 测试/演示库 |
| 5 | url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 5 | # url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 6 | # username: root | ||
| 7 | # password: Tjlh@2017 | ||
| 8 | |||
| 9 | url: jdbc:log4jdbc:mysql://47.100.212.170:3306/ucs?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
| 6 | username: root | 10 | username: root |
| 7 | password: Tjlh@2017 | 11 | password: Tjlh@2021 |
| 8 | 12 | ||
| 9 | # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 13 | # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 10 | # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
| 11 | # username: root | 14 | # username: root |
| 12 | # password: root | 15 | # password: root |
| 13 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | 16 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ... | ... |
| ... | @@ -36,7 +36,7 @@ public class TaskServiceTest { | ... | @@ -36,7 +36,7 @@ public class TaskServiceTest { |
| 36 | task.setSequence(1); | 36 | task.setSequence(1); |
| 37 | task.setRewardExp(10L); | 37 | task.setRewardExp(10L); |
| 38 | task.setRewardPoints(1L); | 38 | task.setRewardPoints(1L); |
| 39 | task.setRewardPointsExpireTime(TimestampUtil.Timestamp2long(TimestampUtil.now())); | 39 | task.setRewardPointsExpireTime(TimestampUtil.timestamp2long(TimestampUtil.now())); |
| 40 | task.setPointsType(1); | 40 | task.setPointsType(1); |
| 41 | task.setRewardMaxPoints(1); | 41 | task.setRewardMaxPoints(1); |
| 42 | task.setGroups("groups"); | 42 | task.setGroups("groups"); | ... | ... |
| ... | @@ -10,6 +10,13 @@ import com.topdraw.module.mq.EventType; | ... | @@ -10,6 +10,13 @@ import com.topdraw.module.mq.EventType; |
| 10 | import com.topdraw.BaseTest; | 10 | import com.topdraw.BaseTest; |
| 11 | import org.junit.Test; | 11 | import org.junit.Test; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 14 | |||
| 15 | import javax.annotation.Resource; | ||
| 16 | import java.util.concurrent.ArrayBlockingQueue; | ||
| 17 | import java.util.concurrent.FutureTask; | ||
| 18 | import java.util.concurrent.ThreadPoolExecutor; | ||
| 19 | import java.util.concurrent.TimeUnit; | ||
| 13 | 20 | ||
| 14 | public class TaskOperationControllerTest extends BaseTest { | 21 | public class TaskOperationControllerTest extends BaseTest { |
| 15 | 22 | ||
| ... | @@ -20,9 +27,9 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -20,9 +27,9 @@ public class TaskOperationControllerTest extends BaseTest { |
| 20 | public void dealTask() { | 27 | public void dealTask() { |
| 21 | try { | 28 | try { |
| 22 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | 29 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); |
| 23 | dataSyncMsg.setEventType(EventType.LOGIN.name()); | 30 | dataSyncMsg.setEventType(EventType.VIEWING.name()); |
| 24 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); | 31 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); |
| 25 | msgData.setEvent(1); | 32 | msgData.setEvent(2); |
| 26 | msgData.setRemarks("remark"); | 33 | msgData.setRemarks("remark"); |
| 27 | msgData.setMemberId(3L); | 34 | msgData.setMemberId(3L); |
| 28 | msgData.setDeviceType(2); | 35 | msgData.setDeviceType(2); |
| ... | @@ -41,5 +48,69 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -41,5 +48,69 @@ public class TaskOperationControllerTest extends BaseTest { |
| 41 | } | 48 | } |
| 42 | 49 | ||
| 43 | 50 | ||
| 51 | @Autowired | ||
| 52 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | public void t1() throws InterruptedException { | ||
| 57 | |||
| 58 | Thread.sleep(1*1000); | ||
| 59 | System.out.println(Thread.currentThread().getName()+"=======>>> t1"); | ||
| 60 | |||
| 61 | } | ||
| 62 | public void t2() throws InterruptedException { | ||
| 63 | |||
| 64 | Thread.sleep(1*1000); | ||
| 65 | System.out.println(Thread.currentThread().getName()+"=======>>> t2"); | ||
| 66 | |||
| 67 | } | ||
| 68 | public void t3() throws InterruptedException { | ||
| 69 | |||
| 70 | Thread.sleep(1*1000); | ||
| 71 | System.out.println(Thread.currentThread().getName()+"=======>>> t3"); | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | @Test | ||
| 76 | public void main() { | ||
| 77 | long l = System.currentTimeMillis(); | ||
| 78 | FutureTask futureTask1 = new FutureTask(()->{ | ||
| 79 | t1(); | ||
| 80 | return null; | ||
| 81 | }); | ||
| 82 | FutureTask futureTask2 = new FutureTask(()->{ | ||
| 83 | t2(); | ||
| 84 | return null; | ||
| 85 | }); | ||
| 86 | |||
| 87 | FutureTask futureTask3 = new FutureTask(()->{ | ||
| 88 | t3(); | ||
| 89 | return null; | ||
| 90 | }); | ||
| 91 | |||
| 92 | threadPoolTaskExecutor.execute(futureTask1); | ||
| 93 | threadPoolTaskExecutor.execute(futureTask2); | ||
| 94 | threadPoolTaskExecutor.execute(futureTask3); | ||
| 95 | |||
| 96 | long l1 = System.currentTimeMillis(); | ||
| 97 | System.out.println(l1-l); | ||
| 98 | /*threadPoolTaskExecutor.execute(()->{ | ||
| 99 | for (int i = 0; i < 10; i++) { | ||
| 100 | try { | ||
| 101 | // Thread.sleep(2*1000); | ||
| 102 | System.out.println("===>>>> "); | ||
| 103 | } catch (Exception e) { | ||
| 104 | e.printStackTrace(); | ||
| 105 | } | ||
| 106 | |||
| 107 | } | ||
| 108 | });*/ | ||
| 109 | |||
| 110 | System.out.println("======>>> main end"); | ||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 | |||
| 44 | 115 | ||
| 45 | } | 116 | } | ... | ... |
| ... | @@ -46,7 +46,8 @@ public class PointsOperationServiceTest extends BaseTest { | ... | @@ -46,7 +46,8 @@ public class PointsOperationServiceTest extends BaseTest { |
| 46 | 46 | ||
| 47 | @Test | 47 | @Test |
| 48 | public void cleanInvalidAvailablePoints() { | 48 | public void cleanInvalidAvailablePoints() { |
| 49 | this.pointsOperationService.cleanInvalidAvailablePoints(); | 49 | Long memberId = 2L; |
| 50 | this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId); | ||
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | } | 53 | } | ... | ... |
-
Please register or sign in to post a comment