Commit f80260a0 f80260a0b3d049f4aa6961cc1cedd8be381df41b by xianghan@topdraw.cn

修复测试缺陷

1 parent 3974b7e4
Showing 28 changed files with 368 additions and 135 deletions
......@@ -10,7 +10,7 @@
<entry key="lastExternalPluginCheckTime" value="1636770952724" />
</map>
</option>
<option name="version" value="5" />
<option name="version" value="6" />
</configuration>
</facet>
</component>
......
package com.topdraw.module.mq;
import javax.annotation.Resource;
// 关注的事件
public enum EventType {
......@@ -22,7 +24,7 @@ public enum EventType {
// 登录
LOGIN,
// 订购产品包
SUBSCRIBE_PRODUCT_PACKAGE
SUBSCRIBE_PRODUCT_PACKAGE,
// 签到
SIGN
}
......
......@@ -10,7 +10,7 @@
<entry key="lastExternalPluginCheckTime" value="1636770952726" />
</map>
</option>
<option name="version" value="5" />
<option name="version" value="6" />
</configuration>
</facet>
</component>
......
......@@ -125,6 +125,17 @@
<build>
<finalName>member-service</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......@@ -143,6 +154,7 @@
</plugin>
<!-- 复制指定配置文件到指定目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
......
......@@ -28,7 +28,7 @@ public class AsyncMqProducer {
@Autowired
MessageProducer messageProducer;
@Resource(name = "executorTask")
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Pointcut(value = "@annotation(asyncMqSend)")
......
......@@ -90,7 +90,6 @@ public class MemberLevelServiceImpl implements MemberLevelService {
: new MemberLevelDTO();
}
@Cacheable(cacheNames = "uc-member_level",key = "#level")
@Override
public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) {
return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status));
......
......@@ -75,7 +75,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable
* @param memberId
* @return
*/
@Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time >= now()"
@Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time > now()"
,nativeQuery = true)
Long findAvailablePointsByMemberId(long memberId);
......@@ -87,4 +87,8 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable
void deleteBatchByIds(List<Long> id);
List<PointsAvailable> findByExpireTimeBefore(Timestamp now);
@Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1"
,nativeQuery = true)
long findTotalCountByMemberId(Long memberId);
}
......
......@@ -136,4 +136,6 @@ public interface PointsAvailableService {
List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now);
long findTotalPointsByMemberId(Long memberId);
}
......
......@@ -163,4 +163,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now));
}
@Override
public long findTotalPointsByMemberId(Long memberId) {
return this.PointsAvailableRepository.findTotalCountByMemberId(memberId);
}
}
......
......@@ -20,7 +20,7 @@ import io.swagger.annotations.*;
//@RequestMapping("/api/Points")
public class PointsController {
/* @Autowired
/*@Autowired
private PointsService PointsService;
@GetMapping
......@@ -33,9 +33,9 @@ public class PointsController {
@ApiOperation("查询所有Points")
public ResultInfo getPointss(PointsQueryCriteria criteria) {
return ResultInfo.success(PointsService.queryAll(criteria));
}
}*/
@Log
/*@Log
@PostMapping
@ApiOperation("新增Points")
public ResultInfo create(@Validated @RequestBody Points resources) {
......
......@@ -80,7 +80,7 @@ public class TaskServiceImpl implements TaskService {
TaskRepository.delete(Task);
}
@Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId")
// @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId")
@Override
public List<Task> findByTemplateId(Long taskTemplateId) {
return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null;
......
......@@ -93,10 +93,9 @@ public class TaskTemplateServiceImpl implements TaskTemplateService {
return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null;
}
@Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event")
// @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event")
@Override
public TaskTemplate findByType(Integer event) {
System.out.println("查询数据库了!!");
return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null;
}
}
......
......@@ -17,9 +17,13 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* @author XiangHan
* @date 2021-10-22
......@@ -32,11 +36,11 @@ public class PointsOperationController {
private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class);
@Autowired
private PointsOperationService pointsOperationService;
PointsOperationService pointsOperationService;
@Autowired
private PointsDetailService pointsDetailService;
PointsDetailService pointsDetailService;
@Autowired
private PointsAvailableService pointsAvailableService;
PointsAvailableService pointsAvailableService;
@GetMapping(value = "/pagePointsDetails")
@ApiOperation("查询PointsDetail")
......@@ -56,10 +60,29 @@ public class PointsOperationController {
}
@Log
@GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
@ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) {
Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id);
return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong);
}
/*@Log
@PostMapping(value = "/cleanInvalidPointsAndCalculateCurrentPointsByMemberIds")
@ApiOperation("清除过期积分并计算总积分,管理端使用")
public ResultInfo cleanInvalidPointsAndCalculateCurrentPointsByMemberIds(List<Long> memberIds) {
if (!CollectionUtils.isEmpty(memberIds)) {
for (Long memberId : memberIds) {
this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId);
}
}
return ResultInfo.success();
}*/
@Log
@PostMapping(value = "/grantPointsByManual")
@ApiOperation("新增PointsDetail")
public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) {
LOG.info("======>>>>> grantPointsByManual start");
Long memberId = tempPoints.getMemberId();
this.pointsOperationService.grantPointsByManual(memberId,tempPoints);
return ResultInfo.success();
......
......@@ -35,13 +35,11 @@ public interface PointsOperationService {
*/
void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList);
/**
* 清理过期的积分
*/
void cleanInvalidAvailablePoints();
/**
* 清理过期的积分
* 清理过期并计算可用总积分
* @param memberId
* @return
*/
void cleanInvalidAvailablePointsByMemberId(Long memberId);
Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId);
}
......
......@@ -45,7 +45,7 @@ public class CouponOperationServiceImpl implements CouponOperationService {
RightsOperationService rightsOperationService;
@Autowired
RedissonClient redissonClient;
@Resource(name = "executorTask")
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
// 过期阀值(默认一个月)
......@@ -99,9 +99,9 @@ public class CouponOperationServiceImpl implements CouponOperationService {
// Long userId = tempCoupon.getUserId();
Long memberId = tempCoupon.getMemberId();
Integer rightsAmount = tempCoupon.getRightsAmount();
// RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString());
RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString());
try {
// RedissonUtil.lock(rLock);
RedissonUtil.lock(rLock);
// 1.历史总优惠券数量
Long historyCouponCount = this.getTotalHistoryCoupon(memberId);
// 1.当前总优惠券数量
......@@ -118,7 +118,7 @@ public class CouponOperationServiceImpl implements CouponOperationService {
e.printStackTrace();
throw e;
} finally {
// RedissonUtil.unlock(rLock);
RedissonUtil.unlock(rLock);
}
}
......@@ -160,7 +160,7 @@ public class CouponOperationServiceImpl implements CouponOperationService {
* @return
*/
private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) {
Timestamp expireTime = TimestampUtil.localDateTime2Timestamp1(LocalDateTime.now().plusDays(expireFactor));
Timestamp expireTime = TimestampUtil.localDateTime2Timestamp(LocalDateTime.now().plusDays(expireFactor));
return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime);
}
......
......@@ -43,7 +43,7 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberLevelService memberLevelService;
@Autowired
RedissonClient redissonClient;
@Resource(name = "executorTask")
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override
......@@ -83,10 +83,12 @@ public class ExpOperationServiceImpl implements ExpOperationService {
// 总积分
long totalExp = this.calculateTotalExp(originExp, tempExp);
// 1.添加成长值记录
this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp));
// this.doInsertExpDetail(tempExp, originExp, totalExp);
// this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp));
// 2.更新成长值与等级
this.refreshMemberExpAndLevel(tempExp,totalExp);
this.doInsertExpDetail(tempExp, originExp, totalExp);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -116,10 +118,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) {
Long memberId = tempExp.getMemberId();
// RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString());
try {
// RedissonUtil.lock(rLock);
// 1.获取当前成长值
MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId);
// 2.获取下一级需要的成长值
......@@ -128,12 +126,6 @@ public class ExpOperationServiceImpl implements ExpOperationService {
Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO);
// 5.更新用户信息
this.updateMemberInfo(level, totalExp, memberId);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
// RedissonUtil.unlock(rLock);
}
}
/**
......
......@@ -16,6 +16,7 @@ import com.topdraw.util.IdWorker;
import com.topdraw.util.RedissonUtil;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
......@@ -39,6 +40,7 @@ import java.util.stream.Collectors;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@Slf4j
public class PointsOperationServiceImpl implements PointsOperationService {
private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class);
......@@ -62,12 +64,13 @@ public class PointsOperationServiceImpl implements PointsOperationService {
@Autowired
RedissonClient redissonClient;
@Resource(name = "executorTask")
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsByManual(Long memberId,TempPoints tempPoints){
if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints()))
this.refresh(tempPoints);
}
......@@ -167,7 +170,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1);
BeanUtils.copyProperties(tempPoints,tempPoints1);
tempPoints1.setPoints(-(Math.abs(points)));
long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints);
Long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints);
this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints);
}
}
......@@ -265,58 +268,92 @@ public class PointsOperationServiceImpl implements PointsOperationService {
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start1");
for (TempPoints tempPoints : tempPointsList){
log.info("------->>grantPointsThroughTempRightsList start");
this.refresh(tempPoints);
}
}
/**
* 定时清理过期的可用积分
* 清理过期积分
* @param memberId
*/
@Override
public void cleanInvalidAvailablePoints() {
// 获取已过期的积分
List<PointsAvailableDTO> pointsAvailableDTOS = pointsAvailableService.findByExpireTimeBefore(TimestampUtil.now());
private void cleanInvalidAvailablePointsByMemberId(Long memberId) {
List<PointsAvailableDTO> pointsAvailableDTOS =
pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,TimestampUtil.now());
if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
//1.获取原始积分
for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
// 添加积分明细 uc_points_detail
this.doCreatePointsDetail(pointsAvailableDTOS);
this.doCreatePointsDetail(pointsAvailableDTO);
// 删除已过期的积分
this.doDeleteInvalidAvailablePoints(pointsAvailableDTOS);
this.doDeleteInvalidAvailablePoints(pointsAvailableDTO);
}
}
}
@Override
public void cleanInvalidAvailablePointsByMemberId(Long memberId) {
List<PointsAvailableDTO> pointsAvailableDTOS = pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,TimestampUtil.now());
if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
// 添加积分明细 uc_points_detail
this.doCreatePointsDetail(pointsAvailableDTOS);
// 删除已过期的积分
this.doDeleteInvalidAvailablePoints(pointsAvailableDTOS);
public Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId) {
// 清理当前用户的过期积分
this.cleanInvalidAvailablePointsByMemberId(memberId);
// 获取当前用户的可用总积分
long currentPoints = this.findAvailablePointsByMemberId(memberId);
// 更新会员信息
this.doUpdateMemberPoints(memberId,currentPoints);
return currentPoints;
}
/**
* 获取可用总积分
* @param memberId
* @return
*/
private long findAvailablePointsByMemberId(Long memberId){
return this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
}
/**
* 修改会员信息
* @param memberId
* @param currentPoints
*/
private void doUpdateMemberPoints(Long memberId, long currentPoints) {
Member member = new Member();
member.setId(memberId);
member.setPoints(currentPoints);
this.memberOperationService.doUpdateMemberPoints(member);
}
/**
*
* @param pointsAvailableDTOS
*/
private void doDeleteInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) {
private void doDeleteBatchInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) {
List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList());
this.pointsAvailableService.deleteBatchByIds(collect);
}
/**
*
* @param pointsAvailableDTOS
* @param pointsAvailableDTO
*/
private void doCreatePointsDetail(List<PointsAvailableDTO> pointsAvailableDTOS) {
private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) {
this.pointsAvailableService.delete(pointsAvailableDTO.getId());
}
//1.获取原始积分
for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
/**
* 可用积分
* @param pointsAvailableDTO
*/
private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) {
Long memberId = pointsAvailableDTO.getMemberId();
// 原始积分
long availablePoints = this.findAvailablePointsByMemberId(memberId);
long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId);
// 过期积分
long l = pointsAvailableDTO.getPoints();
// 结果积分
......@@ -324,17 +361,15 @@ public class PointsOperationServiceImpl implements PointsOperationService {
PointsDetail pointsDetail = new PointsDetail();
BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail);
pointsDetail.setPoints(-Math.abs(l));
pointsDetail.setCode(String.valueOf(IdWorker.generator()));
pointsDetail.setOriginalPoints(availablePoints);
pointsDetail.setResultPoints(resultPoints);
pointsDetail.setDescription("过期积分");
pointsDetail.setEvtType(99);
pointsDetail.setCreateTime(TimestampUtil.now());
pointsDetail.setUpdateTime(TimestampUtil.now());
this.doInsertPointsDetail(pointsDetail);
// 更新会员积分
this.freshMemberCurrentPoints(memberId,resultPoints);
}
}
/**
......@@ -344,23 +379,34 @@ public class PointsOperationServiceImpl implements PointsOperationService {
*/
private void refresh(TempPoints tempPoints) {
Long memberId = tempPoints.getMemberId();
log.info("----------->> points refresh start");
RLock rLock = this.redissonClient.getLock("uc-refresh-points:" + memberId.toString());
log.info("----------->> rLock --->> start" );
try {
RedissonUtil.lock(rLock);
log.info("----------->> refresh findAvailablePointsByMemberId start");
// 1.可用总积分
long currentPoints = this.findAvailablePointsByMemberId(memberId);
Long currentPoints = this.findAvailablePointsByMemberId(memberId);
log.info("----------->> refresh findAvailablePointsByMemberId currentPoints " + currentPoints);
// 2.计算总积分
long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints);
Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints);
log.info("----------->> refresh findAvailablePointsByMemberId totalPoints " + totalPoints);
// 3.添加积分明细,并计算总积分
this.threadPoolTaskExecutor.execute(()->this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints));
// this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints);
log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail start ");
this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints);
log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail end ");
// 4.添加可用积分
log.info("----------->> refresh doInsertTrPointsAvailable start ");
this.doInsertTrPointsAvailable(tempPoints);
log.info("----------->> refresh doInsertTrPointsAvailable end ");
// 6.更新会员的总积分
log.info("----------->> refresh freshMemberCurrentPoints start ");
this.freshMemberCurrentPoints(memberId, totalPoints);
log.info("----------->> refresh freshMemberCurrentPoints end ");
} catch (Exception e) {
e.printStackTrace();
......@@ -376,11 +422,11 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param currentPoints
* @return
*/
private long calculateTotalPoints(TempPoints tempPoints, long currentPoints) {
private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) {
// 获取的积分
long rewardPoints = tempPoints.getPoints();
Long rewardPoints = tempPoints.getPoints();
// 总积分
long totalPoints = currentPoints + rewardPoints;
Long totalPoints = currentPoints + rewardPoints;
return totalPoints;
}
......@@ -433,9 +479,9 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param memberId 会员id
* @return
*/
private long findAvailablePointsByMemberId(long memberId){
long availablePointsByMemberId = this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
return availablePointsByMemberId;
private Long findAvailablePointsByMemberId(long memberId){
Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
return Objects.nonNull(availablePoints) ? availablePoints : 0L;
}
/**
......@@ -473,7 +519,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @param tempPoints 积分
* @return Integer 总积分
*/
private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long currentPoints,long totalPoints){
private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){
PointsDetail pointsDetail = new PointsDetail();
BeanUtils.copyProperties(tempPoints,pointsDetail);
......
......@@ -22,7 +22,7 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.*;
/**
* 权益处理
......@@ -47,8 +47,10 @@ public class RightsOperationServiceImpl implements RightsOperationService {
@Autowired
PointsOperationService pointsOperationService;
@Resource(name = "executorTask")
ThreadPoolTaskExecutor threadPoolTaskExecutor;
// @Autowired
// ThreadPoolTaskExecutor threadPoolTaskExecutor;
private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10);
/**
* 系统手动发放
......@@ -73,16 +75,15 @@ public class RightsOperationServiceImpl implements RightsOperationService {
@Override
public void grantRights(Map<RightType, Object> tempRightsMap) {
this.threadPoolTaskExecutor.execute(()-> {
// this.threadPoolTaskExecutor.execute(()-> {
// 2.创建权益历史对象
List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap);
// 3.保存权益历史
this.doInsertTrRightHistory(rightsList);
});
// });
// 1.权益下发
this.refresh(tempRightsMap);
}
/**
......@@ -123,7 +124,9 @@ public class RightsOperationServiceImpl implements RightsOperationService {
* @param tempPointsList 权益列表
*/
private void grantPoint(List<TempPoints> tempPointsList) {
log.info(Thread.currentThread().getName() + "=========>>grantPoint start");
if (!CollectionUtils.isEmpty(tempPointsList))
log.info("=======>> tempPointsList ======>> " + tempPointsList.toString());
this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList);
}
......@@ -140,20 +143,79 @@ public class RightsOperationServiceImpl implements RightsOperationService {
}
/**
* 权益发放
* @param tempRightsMap
*/
private void refresh(Map<RightType, Object> tempRightsMap) {
this.threadPoolTaskExecutor.submit(() -> {
/*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{
log.info(Thread.currentThread().getName() + "=========>> start");
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
log.info(Thread.currentThread().getName() + "=========>>grantPoint end");
// 成长值
// this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
// this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{
// 积分
// this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
// this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{
// 积分
// this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
// this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
return null;
});
this.threadPoolTaskExecutor.execute(futureTask1);
this.threadPoolTaskExecutor.execute(futureTask2);
this.threadPoolTaskExecutor.execute(futureTask3);*/
/*this.threadPoolTaskExecutor.execute(() -> {
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
// 成长值
this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
// 优惠券
this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
});*/
/*this.threadPoolTaskExecutor.execute(() -> {
log.info(Thread.currentThread().getName() + "=========>> start");
// 积分
this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
log.info(Thread.currentThread().getName() + "=========>> end");
});*/
List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS);
if (!CollectionUtils.isEmpty(tempPointsList)) {
// 积分
this.grantPoint(tempPointsList);
}
List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP);
if (!CollectionUtils.isEmpty(tempExpList)) {
// 成长值
this.grantExp(tempExpList);
}
List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON);
if (!CollectionUtils.isEmpty(tempCouponList)) {
// 优惠券
this.grantCoupon(tempCouponList);
}
}
/**
......@@ -178,9 +240,9 @@ public class RightsOperationServiceImpl implements RightsOperationService {
RightsDTO rightsDTO = this.getRights(rightId);
// 权益的实体类型 1:积分;2成长值;3优惠券
String type = rightsDTO.getEntityType();
String code = rightsDTO.getCode();
// String code = rightsDTO.getCode();
Long expireTime = rightsDTO.getExpireTime();
Timestamp validTime = rightsDTO.getValidTime();
// Timestamp validTime = rightsDTO.getValidTime();
switch (type) {
......@@ -192,6 +254,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
tempCoupon.setUserId(userId);
tempCoupon.setRightsAmount(1);
tempCoupon.setRightsSendStrategy(0);
if (Objects.nonNull(expireTime))
tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime));
tempCouponList.add(tempCoupon);
break;
......@@ -224,12 +287,12 @@ public class RightsOperationServiceImpl implements RightsOperationService {
if (!CollectionUtils.isEmpty(tempCouponList))
map.put(RightType.COUPON,tempCouponList);
// 成长值
if (!CollectionUtils.isEmpty(tempExpList))
map.put(RightType.EXP,tempExpList);
/* if (!CollectionUtils.isEmpty(tempExpList))
map.put(RightType.EXP,tempExpList);*/
// 积分
if (!CollectionUtils.isEmpty(tempPointsList))
/* if (!CollectionUtils.isEmpty(tempPointsList))
map.put(RightType.POINTS,tempPointsList);
*/
return map;
}
......
......@@ -79,11 +79,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
Long memberId = msgData.getMemberId();
long l = System.currentTimeMillis();
// 验证会员信息
/*boolean b = this.validatedMember(memberId);
if (!b) {
throw new BadRequestException("【member status exception!!】");
}*/
// 1.通过任务标识获取任务模板,通过模板参数获取具体的模板
TaskTemplate taskTemplate = this.getTaskTemplate(event);
......@@ -92,10 +87,12 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// 4.判断当前用户是否满足任务完成条件
boolean checkResult = this.checkTaskCompletion(memberId,taskList);
if (checkResult) {
// 5.权益区分(积分、权益、成长值)
Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData);
// 6.权益发放
this.grantRight(tempRightsMap);
}
long r = System.currentTimeMillis();
......@@ -544,16 +541,19 @@ public class TaskOperationServiceImpl implements TaskOperationService {
(Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) &&
(Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) &&
(Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
(Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
(Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() <= memberDTO1.getVip())
(Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
(Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip())
).collect(Collectors.toList());
// 没有满足条件的数据
if (CollectionUtils.isEmpty(taskStream)) {
return false;
} else {
// 获取当前任务的完成情况
boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList);
return result;
}
return true;
};
return compareTaskCondition.compareCondition(memberDTO,taskList);
}
......@@ -614,7 +614,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
Objects.nonNull(completionTime1) &&
completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) {
throw new BadRequestException("任务已完成,请明日再来");
return false;
// 未做,成功
} else {
......
......@@ -22,11 +22,10 @@ public class RedissonConfig {
private String password;
@Bean
public RedissonClient redisson(){
public Redisson redisson(){
Config config = new Config();
// config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword("redis123");
if (StringUtils.isNotEmpty(password)) {
config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password);;
config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password);
} else {
config.useSingleServer().setAddress("redis://"+redisHost+":"+port);
}
......@@ -34,7 +33,8 @@ public class RedissonConfig {
"redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377",
"redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380")
.setPassword("a123456").setScanInterval(5000);*/
return Redisson.create(config);
Redisson redissonClient = (Redisson)Redisson.create(config);
return redissonClient;
}
}
......
......@@ -11,13 +11,12 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
/*@Configuration
@PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8")
@Slf4j
@EnableAsync
@Slf4j*/
public class ThreadPoolTaskExecutorConfig {
@Value("${threadPoolExecutor.core_pool_size}")
/*@Value("${threadPoolExecutor.core_pool_size}")
private int corePoolSize;
@Value("${threadPoolExecutor.max_pool_size}")
private int maxPoolSize;
......@@ -28,7 +27,7 @@ public class ThreadPoolTaskExecutorConfig {
@Value("${threadPoolExecutor.keep_alive_seconds}")
private int keepAliveSeconds;
@Bean(value = "executorTask")
@Bean
public ThreadPoolTaskExecutor executorTask(){
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数
......@@ -46,6 +45,6 @@ public class ThreadPoolTaskExecutorConfig {
// 线程初始化
executor.initialize();
return executor;
}
}*/
}
......
......@@ -31,12 +31,12 @@ public class RabbitMqConfig {
}
@Bean
Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv){
Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv) {
return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange);
}
@Bean
Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin){
Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin) {
return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange);
}
......
......@@ -3,6 +3,7 @@ package com.topdraw.util;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
public class TimestampUtil {
......@@ -12,33 +13,46 @@ public class TimestampUtil {
}
public static Timestamp now(LocalDateTime localDateTime) {
long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).getEpochSecond();
long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
return new Timestamp(epochSecond);
}
public static long localDateTime2Timestamp(LocalDateTime localDateTime){
long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond();
public static long localDateTime2long(LocalDateTime localDateTime){
long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
return epochSecond;
}
public static Timestamp localDateTime2Timestamp1(LocalDateTime localDateTime){
long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond();
public static Timestamp localDateTime2Timestamp(LocalDateTime localDateTime){
long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
return long2Timestamp(epochSecond);
}
public static Timestamp long2Timestamp(long timestamp){
Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp));
Timestamp timestamp1 = Timestamp.from(Instant.ofEpochMilli(timestamp));
return timestamp1;
}
public static long Timestamp2long(Timestamp timestamp){
return timestamp.toInstant().getEpochSecond();
public static long timestamp2long(Timestamp timestamp){
long l = timestamp.toInstant().toEpochMilli();
return l;
}
public static void main(String[] args) {
LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00);
long l = localDateTime2Timestamp(of);
long a = 1636616464000L;
long b = 1637046948588L;
long c = 1637047122176L;
// long l = 16342727230L;
Timestamp timestamp = long2Timestamp(l);
System.out.println(timestamp.toString());
// Timestamp now = now(LocalDateTime.now());
long l = localDateTime2long(LocalDateTime.now());
System.out.println(l);
// System.out.println(now.toString());
Timestamp timestamp1 = long2Timestamp(a);
// long l = localDateTime2Timestamp(of);
// long l = 16342727230L;
// Timestamp timestamp = long2Timestamp(l);
System.out.println(timestamp1.toString());
long l1 = localDateTime2long(LocalDateTime.now());
System.out.println(l1);
}
}
......
......@@ -2,12 +2,15 @@
spring:
datasource:
# 测试/演示库
url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# username: root
# password: Tjlh@2017
url: jdbc:log4jdbc:mysql://47.100.212.170:3306/ucs?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: Tjlh@2017
password: Tjlh@2021
# url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# username: root
# password: root
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
......
server:
port: 8447
port: 8446
spring:
application:
......
......@@ -36,7 +36,7 @@ public class TaskServiceTest {
task.setSequence(1);
task.setRewardExp(10L);
task.setRewardPoints(1L);
task.setRewardPointsExpireTime(TimestampUtil.Timestamp2long(TimestampUtil.now()));
task.setRewardPointsExpireTime(TimestampUtil.timestamp2long(TimestampUtil.now()));
task.setPointsType(1);
task.setRewardMaxPoints(1);
task.setGroups("groups");
......
......@@ -10,6 +10,13 @@ import com.topdraw.module.mq.EventType;
import com.topdraw.BaseTest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.annotation.Resource;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class TaskOperationControllerTest extends BaseTest {
......@@ -20,9 +27,9 @@ public class TaskOperationControllerTest extends BaseTest {
public void dealTask() {
try {
DataSyncMsg dataSyncMsg = new DataSyncMsg();
dataSyncMsg.setEventType(EventType.LOGIN.name());
dataSyncMsg.setEventType(EventType.VIEWING.name());
DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
msgData.setEvent(1);
msgData.setEvent(2);
msgData.setRemarks("remark");
msgData.setMemberId(3L);
msgData.setDeviceType(2);
......@@ -41,5 +48,69 @@ public class TaskOperationControllerTest extends BaseTest {
}
@Autowired
ThreadPoolTaskExecutor threadPoolTaskExecutor;
public void t1() throws InterruptedException {
Thread.sleep(1*1000);
System.out.println(Thread.currentThread().getName()+"=======>>> t1");
}
public void t2() throws InterruptedException {
Thread.sleep(1*1000);
System.out.println(Thread.currentThread().getName()+"=======>>> t2");
}
public void t3() throws InterruptedException {
Thread.sleep(1*1000);
System.out.println(Thread.currentThread().getName()+"=======>>> t3");
}
@Test
public void main() {
long l = System.currentTimeMillis();
FutureTask futureTask1 = new FutureTask(()->{
t1();
return null;
});
FutureTask futureTask2 = new FutureTask(()->{
t2();
return null;
});
FutureTask futureTask3 = new FutureTask(()->{
t3();
return null;
});
threadPoolTaskExecutor.execute(futureTask1);
threadPoolTaskExecutor.execute(futureTask2);
threadPoolTaskExecutor.execute(futureTask3);
long l1 = System.currentTimeMillis();
System.out.println(l1-l);
/*threadPoolTaskExecutor.execute(()->{
for (int i = 0; i < 10; i++) {
try {
// Thread.sleep(2*1000);
System.out.println("===>>>> ");
} catch (Exception e) {
e.printStackTrace();
}
}
});*/
System.out.println("======>>> main end");
}
}
......
......@@ -46,7 +46,8 @@ public class PointsOperationServiceTest extends BaseTest {
@Test
public void cleanInvalidAvailablePoints() {
this.pointsOperationService.cleanInvalidAvailablePoints();
Long memberId = 2L;
this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId);
}
}
......