Commit 3bc2c7ff 3bc2c7ffcf7932663d92dccb6e0320bc8da12579 by xianghan@topdraw.cn

修复可用积分查询报空

1 parent 3d32c2d8
Showing 20 changed files with 107 additions and 47 deletions
......@@ -38,7 +38,6 @@ public class AsyncMqProducer {
@After("sendMqMsg(asyncMqSend)")
public void doAfter(JoinPoint joinPoint, AsyncMqSend asyncMqSend){
LOG.info("AsyncMqProducer ===>>> doAfter ====>> start");
boolean open = asyncMqSend.open();
if (open) {
try {
......@@ -47,11 +46,9 @@ public class AsyncMqProducer {
e.printStackTrace();
}
}
LOG.info("AsyncMqProducer ===>>> doAfter ====>> end ===>> " );
}
private void doTask(JoinPoint joinPoint, AsyncMqSend asyncMqSend) {
LOG.info("AsyncMqProducer ===>>> doTask ====>> start ===>> " );
String entityName = asyncMqSend.entityName();
String methodName = asyncMqSend.method();
......@@ -81,8 +78,6 @@ public class AsyncMqProducer {
// 同步
this.sendMqMessage(tableOperationMsg);
}
LOG.info("AsyncMqProducer ===>>> doTask ====>> end ===>> " );
}
private void sendMqMessage(TableOperationMsg tableOperationMsg){
......
......@@ -77,7 +77,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable
*/
@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);
Long findAvailablePointsByMemberId(long memberId);
List<PointsAvailable> findByMemberIdOrderByExpireTime(Long memberId);
......
......@@ -154,7 +154,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
@Override
public long findAvailablePointsByMemberId(long memberId) {
return this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId);
Long availablePoints = this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId);
return availablePoints == null ? 0L : availablePoints;
}
@Override
......
......@@ -13,4 +13,6 @@ import java.util.Optional;
public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> {
Optional<PermanentRights> findFirstByCode(String code);
PermanentRights findByLevel(Integer level);
}
......
......@@ -47,4 +47,11 @@ public interface PermanentRightsService {
* @return PermanentRightsDTO
*/
PermanentRightsDTO getByCode(String code);
/**
* 通过会员等级获取对应的永久权益
* @param level
* @return
*/
PermanentRightsDTO findByLevel(Integer level);
}
......
......@@ -87,4 +87,10 @@ public class PermanentRightsServiceImpl implements PermanentRightsService {
return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new))
: new PermanentRightsDTO();
}
@Override
public PermanentRightsDTO findByLevel(Integer level) {
PermanentRights PermanentRights = PermanentRightsRepository.findByLevel(level);
return PermanentRightsMapper.toDto(PermanentRights);
}
}
......
package com.topdraw.business.basicdata.task.progress.repository;
import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Optional;
/**
......@@ -12,4 +15,8 @@ import java.util.Optional;
*/
public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> {
@Query(value = "select id, member_id, task_id , current_action_amount , \n" +
" target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" +
" and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true)
List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
}
......
......@@ -43,4 +43,5 @@ public interface TrTaskProgressService {
void delete(Long id);
List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
}
......
......@@ -83,5 +83,10 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
TrTaskProgressRepository.delete(TrTaskProgress);
}
@Override
public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
return TrTaskProgressMapper.toDto(this.TrTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1));
}
}
......
......@@ -60,7 +60,6 @@ public class PointsOperationController {
@ApiOperation("新增PointsDetail")
public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) {
Long memberId = tempPoints.getMemberId();
LOG.info("PointsOperationController -->> grantPointsByManual -->> " + tempPoints);
this.pointsOperationService.grantPointsByManual(memberId,tempPoints);
return ResultInfo.success();
}
......
......@@ -8,7 +8,10 @@ import com.topdraw.business.process.service.CouponOperationService;
import com.topdraw.business.process.service.MemberOperationService;
import com.topdraw.business.process.domian.TempCoupon;
import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.util.RedissonUtil;
import com.topdraw.util.TimestampUtil;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
......@@ -35,6 +38,8 @@ public class CouponOperationServiceImpl implements CouponOperationService {
MemberOperationService memberOperationService;
@Autowired
RightsOperationService rightsOperationService;
@Autowired
RedissonClient redissonClient;
// 过期阀值(默认一个月)
private static final Integer EXPIRE_FACTOR_MONTH = 1;
......@@ -83,8 +88,9 @@ public class CouponOperationServiceImpl implements CouponOperationService {
private void refreshMemberCoupon(TempCoupon tempCoupon) {
Long userId = tempCoupon.getUserId();
Long memberId = tempCoupon.getMemberId();
try{
// reentrantLock.lock();
RLock rLock = this.redissonClient.getLock("refreshMemberCoupon" + memberId.toString());
try {
RedissonUtil.lock(rLock);
// 1.获取用户领取的总优惠券
Long totalCouponCount = this.getTotalCoupon(userId);
// 2.获取已过期的优惠券数量
......@@ -99,9 +105,8 @@ public class CouponOperationServiceImpl implements CouponOperationService {
e.printStackTrace();
throw e;
} finally {
// reentrantLock.unlock();
RedissonUtil.unlock(rLock);
}
}
......
......@@ -10,8 +10,11 @@ import com.topdraw.business.process.service.ExpOperationService;
import com.topdraw.business.process.service.MemberOperationService;
import com.topdraw.business.process.domian.TempExp;
import com.topdraw.util.IdWorker;
import com.topdraw.util.RedissonUtil;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
......@@ -21,9 +24,6 @@ import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
*
......@@ -39,6 +39,8 @@ public class ExpOperationServiceImpl implements ExpOperationService {
MemberOperationService memberOperationService;
@Autowired
MemberLevelService memberLevelService;
@Autowired
RedissonClient redissonClient;
@Override
public void grantPointsThroughTempExp(List<TempExp> tempExpList) {
......@@ -83,17 +85,28 @@ public class ExpOperationServiceImpl implements ExpOperationService {
* @param tempExp 成长值列表
*/
private void refreshMemberExpAndLevel(TempExp tempExp) {
Long memberId = tempExp.getMemberId();
// 1.获取当前成长值
MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId);
// 2.获取下一级需要的成长值
MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel()+1,1);
// 3.成长值累加
Long newExp = memberDTO.getExp() + tempExp.getRewardExp();
// 4.成长值比较,判断是否升级
long i = this.compareExp(newExp,memberLevelDTO);
// 5.更新用户信息
this.updateMemberInfo(i,newExp,memberLevelDTO,memberId);
RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString());
try {
RedissonUtil.lock(rLock);
// 1.获取当前成长值
MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId);
// 2.获取下一级需要的成长值
MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1);
// 3.成长值累加
Long newExp = memberDTO.getExp() + tempExp.getRewardExp();
// 4.成长值比较,判断是否升级
long i = this.compareExp(newExp, memberLevelDTO);
// 5.更新用户信息
this.updateMemberInfo(i, newExp, memberLevelDTO, memberId);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
RedissonUtil.unlock(rLock);
}
}
/**
......
......@@ -14,8 +14,11 @@ import com.topdraw.business.process.service.MemberOperationService;
import com.topdraw.business.process.service.PointsOperationService;
import com.topdraw.business.process.domian.TempPoints;
import com.topdraw.util.IdWorker;
import com.topdraw.util.RedissonUtil;
import com.topdraw.util.TimestampUtil;
import com.topdraw.utils.StringUtils;
import io.swagger.models.auth.In;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -30,6 +33,9 @@ import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask;
import java.util.stream.Collectors;
/**
......@@ -319,16 +325,25 @@ public class PointsOperationServiceImpl implements PointsOperationService {
*/
private void refresh(TempPoints tempPoints) {
Long memberId = tempPoints.getMemberId();
// 1.可用总积分
long currentPoints = this.findAvailablePointsByMemberId(memberId);
// 2.添加积分明细,并计算总积分
long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints,currentPoints);
// 3.获取即将过期的积分
long soonExpireTime = this.getSoonExpirePoints(memberId,tempPoints);
// 4.更新会员的总积分
this.freshMemberCurrentPoints(memberId,totalPoints,soonExpireTime);
// 5.添加可用积分
this.doInsertTrPointsAvailable(tempPoints);
RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString());
try {
RedissonUtil.lock(rLock);
// 1.可用总积分
long currentPoints = this.findAvailablePointsByMemberId(memberId);
// 2.添加积分明细,并计算总积分
long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints);
// 3.获取即将过期的积分
long soonExpireTime = this.getSoonExpirePoints(memberId, tempPoints);
// 4.更新会员的总积分
this.freshMemberCurrentPoints(memberId, totalPoints, soonExpireTime);
// 5.添加可用积分
this.doInsertTrPointsAvailable(tempPoints);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
RedissonUtil.unlock(rLock);
}
}
/**
......@@ -382,7 +397,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
* @return
*/
private long findAvailablePointsByMemberId(long memberId){
return this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
long availablePointsByMemberId = this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
return availablePointsByMemberId;
}
/**
......
......@@ -137,20 +137,25 @@ public class RightsOperationServiceImpl implements RightsOperationService {
* @param tempRightsMap
*/
private void refresh(Map<RightType, Object> tempRightsMap) {
/*threadPoolTaskExecutor.execute(()->{
// 积分
this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS));
});
threadPoolTaskExecutor.execute(()->{
// 成长值
this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP));
});
threadPoolTaskExecutor.execute(()->{
// 优惠券
this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));
});*/
this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS));
this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP));
this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));
}
/**
......
......@@ -15,7 +15,6 @@ public class RabbitMqConfig {
public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv";
public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin";
@Bean
FanoutExchange ucFanoutExchange(){
return ExchangeBuilder.fanoutExchange(UC_EXCHANGE_FANOUT).build();
......@@ -41,6 +40,4 @@ public class RabbitMqConfig {
return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange);
}
}
......
......@@ -62,15 +62,16 @@ spring:
#连接超时时间
timeout: 5000
rabbitmq:
host: 122.112.214.149 # rabbitmq的连接地址
host: 47.100.212.170 # rabbitmq的连接地址
# host: 122.112.214.149 # rabbitmq的连接地址
#host: 139.196.192.242 # rabbitmq的连接地址
port: 5672 # rabbitmq的连接端口号
#virtual-host: /member_center # rabbitmq的虚拟host
#username: member_center # rabbitmq的用户名
#password: Tjlh@2021 # rabbitmq的密码
virtual-host: / # rabbitmq的虚拟host
username: guest # rabbitmq的用户名
password: guest # rabbitmq的密码
virtual-host: test # rabbitmq的虚拟host
username: omo_test # rabbitmq的用户名
password: omo_test # rabbitmq的密码
publisher-confirms: true #如果对异步消息需要回调必须设置为true
#jwt。依赖的common中有需要jwt的部分属性。
......
......@@ -55,7 +55,7 @@ public class PointsOperationControllerTest extends BaseTest {
TempPoints tempPoints = new TempPoints();
tempPoints.setPoints(10L);
tempPoints.setPointsType(0);
tempPoints.setMemberId(2L);
tempPoints.setMemberId(3L);
tempPoints.setRightsSendStrategy(0);
tempPoints.setAccountId(2L);
tempPoints.setExpireTime(Timestamp.valueOf("2021-10-27 09:00:00"));
......
......@@ -24,7 +24,7 @@ public class TaskOperationControllerTest extends BaseTest {
DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
msgData.setEvent(1);
msgData.setRemarks("remark");
msgData.setMemberId(1L);
msgData.setMemberId(3L);
msgData.setDeviceType(2);
msgData.setAppCode("WEI_XIN_GOLD_PANDA");
dataSyncMsg.setMsg(msgData);
......
......@@ -16,7 +16,7 @@ public class TaskOperationServiceTest extends BaseTest {
@Test
public void dealTaskTest() {
Long memberId = 2L;
Long memberId = 3L;
DataSyncMsg dataSyncMsg = new DataSyncMsg();
// dataSyncMsg.setEntityType(EntityType.MEMBER);
dataSyncMsg.setEventType(EventType.LOGIN.name());
......