Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
向汉
/
uc-engine
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
3bc2c7ff
...
3bc2c7ffcf7932663d92dccb6e0320bc8da12579
authored
2021-11-11 14:47:30 +0800
by
xianghan@topdraw.cn
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复可用积分查询报空
1 parent
3d32c2d8
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
277 additions
and
94 deletions
member-service-impl/src/main/java/com/topdraw/aspect/AsyncMqProducer.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/points/available/repository/PointsAvailableRepository.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/points/available/service/impl/PointsAvailableServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/repository/PermanentRightsRepository.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/service/PermanentRightsService.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/service/impl/PermanentRightsServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/repository/TrTaskProgressRepository.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/service/TrTaskProgressService.java
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/service/impl/TrTaskProgressServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/process/rest/PointsOperationController.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/CouponOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/ExpOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
member-service-impl/src/main/java/com/topdraw/mq/config/RabbitMqConfig.java
member-service-impl/src/main/resources/config/application-dev.yml
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/PointsOperationControllerTest.java
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/TaskOperationControllerTest.java
member-service-impl/src/test/java/com/topdraw/test/business/process/service/TaskOperationServiceTest.java
member-service-impl/src/main/java/com/topdraw/aspect/AsyncMqProducer.java
View file @
3bc2c7f
...
...
@@ -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
){
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/points/available/repository/PointsAvailableRepository.java
View file @
3bc2c7f
...
...
@@ -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
)
l
ong
findAvailablePointsByMemberId
(
long
memberId
);
L
ong
findAvailablePointsByMemberId
(
long
memberId
);
List
<
PointsAvailable
>
findByMemberIdOrderByExpireTime
(
Long
memberId
);
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/points/available/service/impl/PointsAvailableServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/repository/PermanentRightsRepository.java
View file @
3bc2c7f
...
...
@@ -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
);
}
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/service/PermanentRightsService.java
View file @
3bc2c7f
...
...
@@ -47,4 +47,11 @@ public interface PermanentRightsService {
* @return PermanentRightsDTO
*/
PermanentRightsDTO
getByCode
(
String
code
);
/**
* 通过会员等级获取对应的永久权益
* @param level
* @return
*/
PermanentRightsDTO
findByLevel
(
Integer
level
);
}
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/rights/permanentrights/service/impl/PermanentRightsServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
);
}
}
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/repository/TrTaskProgressRepository.java
View file @
3bc2c7f
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
);
}
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/service/TrTaskProgressService.java
View file @
3bc2c7f
...
...
@@ -43,4 +43,5 @@ public interface TrTaskProgressService {
void
delete
(
Long
id
);
List
<
TrTaskProgressDTO
>
findByMemberIdAndTaskIdAndCompletionTime
(
Long
memberId
,
Long
taskId
,
String
time1
);
}
...
...
member-service-impl/src/main/java/com/topdraw/business/basicdata/task/progress/service/impl/TrTaskProgressServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
));
}
}
...
...
member-service-impl/src/main/java/com/topdraw/business/process/rest/PointsOperationController.java
View file @
3bc2c7f
...
...
@@ -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
();
}
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/CouponOperationServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
);
}
}
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/ExpOperationServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
();
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
);
MemberLevelDTO
memberLevelDTO
=
this
.
getNextLevelExp
(
memberDTO
.
getLevel
()
+
1
,
1
);
// 3.成长值累加
Long
newExp
=
memberDTO
.
getExp
()
+
tempExp
.
getRewardExp
();
// 4.成长值比较,判断是否升级
long
i
=
this
.
compareExp
(
newExp
,
memberLevelDTO
);
long
i
=
this
.
compareExp
(
newExp
,
memberLevelDTO
);
// 5.更新用户信息
this
.
updateMemberInfo
(
i
,
newExp
,
memberLevelDTO
,
memberId
);
this
.
updateMemberInfo
(
i
,
newExp
,
memberLevelDTO
,
memberId
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
finally
{
RedissonUtil
.
unlock
(
rLock
);
}
}
/**
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
();
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
);
long
totalPoints
=
this
.
doInsertTrPointsDetail
(
memberId
,
tempPoints
,
currentPoints
);
// 3.获取即将过期的积分
long
soonExpireTime
=
this
.
getSoonExpirePoints
(
memberId
,
tempPoints
);
long
soonExpireTime
=
this
.
getSoonExpirePoints
(
memberId
,
tempPoints
);
// 4.更新会员的总积分
this
.
freshMemberCurrentPoints
(
memberId
,
totalPoints
,
soonExpireTime
);
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
;
}
/**
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
View file @
3bc2c7f
...
...
@@ -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
));
}
/**
...
...
member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
View file @
3bc2c7f
package
com
.
topdraw
.
business
.
process
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.topdraw.business.basicdata.rights.constant.RightsType
;
import
com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService
;
import
com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO
;
import
com.topdraw.business.basicdata.rights.service.RightsService
;
import
com.topdraw.business.basicdata.rights.service.dto.RightsDTO
;
import
com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress
;
...
...
@@ -9,7 +10,6 @@ import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressServic
import
com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO
;
import
com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria
;
import
com.topdraw.business.process.service.RightsOperationService
;
import
com.topdraw.business.process.service.TaskDealService
;
import
com.topdraw.business.process.service.TaskOperationService
;
import
com.topdraw.business.basicdata.member.service.MemberService
;
import
com.topdraw.business.basicdata.member.service.dto.MemberDTO
;
...
...
@@ -19,21 +19,23 @@ import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
import
com.topdraw.business.basicdata.task.template.service.TaskTemplateService
;
import
com.topdraw.business.process.domian.*
;
import
com.topdraw.module.mq.DataSyncMsg
;
import
com.topdraw.module.mq.EventType
;
import
com.topdraw.util.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.sql.Timestamp
;
import
java.time.LocalDate
;
import
java.util.*
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -59,14 +61,15 @@ public class TaskOperationServiceImpl implements TaskOperationService {
private
RightsOperationService
rightsOperationService
;
@Autowired
private
TrTaskProgressService
trTaskProgressService
;
@Autowired
private
PermanentRightsService
permanentRightsService
;
private
static
final
Integer
POINTS_TYPE_RANDOM
=
1
;
private
static
final
Integer
POINTS_MIN
=
1
;
private
ReentrantReadWriteLock
reentrantReadWriteLock
=
new
ReentrantReadWriteLock
();
private
static
final
Integer
TASK_FINISH_STATUS
=
1
;
@Resource
(
name
=
"executorTask"
)
ThreadPoolTaskExecutor
threadPoolTaskExecutor
;
private
static
final
Integer
TASK_UNFINISH_STATUS
=
2
;
private
static
final
Integer
POINTS_TYPE_RANDOM
=
1
;
private
static
final
Integer
POINTS_MIN
=
1
;
@Override
public
void
dealTask
(
String
content
)
{
...
...
@@ -74,10 +77,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
long
l
=
System
.
currentTimeMillis
();
DataSyncMsg
dataSyncMsg
=
JSONUtil
.
parseMsg2Object
(
content
,
DataSyncMsg
.
class
);
String
eventType
=
dataSyncMsg
.
getEventType
();
DataSyncMsg
.
MsgData
msgData
=
dataSyncMsg
.
getMsg
();
Long
memberId
=
msgData
.
getMemberId
();
// 1.通过任务标识获取任务模板
...
...
@@ -89,10 +90,14 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// 4.判断当前用户是否满足任务完成条件
boolean
checkResult
=
this
.
checkTaskCompletion
(
memberId
,
taskList
);
if
(
checkResult
)
{
//
4
.权益区分(积分、权益、成长值)
//
5
.权益区分(积分、权益、成长值)
Map
<
RightType
,
Object
>
tempRightsMap
=
this
.
distinguishRight
(
memberId
,
taskList
,
msgData
);
// 5.权益发放
this
.
grantRight
(
tempRightsMap
);
// 6.永久权益
PermanentRightsDTO
permanentRights
=
this
.
getPermanentRights
(
memberId
);
// 7.永久权益计算之后的权益
Map
<
RightType
,
Object
>
rightTypeObjectMap
=
this
.
calculateRight
(
permanentRights
,
tempRightsMap
,
memberId
);
// 8..权益发放
this
.
grantRight
(
rightTypeObjectMap
);
}
long
r
=
System
.
currentTimeMillis
();
...
...
@@ -100,9 +105,25 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
/**
* 永久权益
* @param memberId 会员id
* @return PermanentRightsDTO 永久权益
*/
private
PermanentRightsDTO
getPermanentRights
(
Long
memberId
)
{
PermanentRightsDTO
permanentRights
=
null
;
MemberDTO
memberDTO
=
this
.
memberService
.
findById
(
memberId
);
if
(
Objects
.
nonNull
(
memberDTO
))
{
Integer
level
=
memberDTO
.
getLevel
();
// 永久权益
permanentRights
=
this
.
permanentRightsService
.
findByLevel
(
level
);
}
return
permanentRights
;
}
/**
* 解析模板参数
* @param taskTemplate
* @return
* @param taskTemplate
任务模板
* @return
Map<String, Object> 模板参数解析结果
*/
private
Map
<
String
,
Object
>
parseTaskTemplateParam
(
TaskTemplate
taskTemplate
)
{
if
(
Objects
.
nonNull
(
taskTemplate
))
{
...
...
@@ -116,21 +137,30 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
/**
* 保存任务的完成情况
* 任务完成情况
* @param resources 任务完成情况
*/
private
void
doRefreshTrTaskProcess
(
TrTaskProgress
resources
)
{
Long
id
=
resources
.
getId
();
ReentrantReadWriteLock
.
WriteLock
writeLock
=
this
.
reentrantReadWriteLock
.
writeLock
();
try
{
writeLock
.
lock
();
if
(
Objects
.
nonNull
(
id
))
{
resources
.
setUpdateTime
(
TimestampUtil
.
now
());
this
.
trTaskProgressService
.
update
(
resources
);
}
else
{
this
.
trTaskProgressService
.
create
(
resources
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
writeLock
.
unlock
();
}
}
/**
* 权益发放
* @param tempRightsMap
会员id
* @param tempRightsMap
权益
*/
private
void
grantRight
(
Map
<
RightType
,
Object
>
tempRightsMap
)
{
this
.
rightsOperationService
.
grantRights
(
tempRightsMap
);
...
...
@@ -140,6 +170,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* 权益区分
*
* @param taskList 任务列表
* @return Map<RightType,Object> 权益分类
*/
private
Map
<
RightType
,
Object
>
distinguishRight
(
Long
memberId
,
List
<
Task
>
taskList
,
DataSyncMsg
.
MsgData
msgData
)
{
...
...
@@ -165,6 +196,106 @@ public class TaskOperationServiceImpl implements TaskOperationService {
}
/**
* 计算总权益 = 已获得的积分 + 已获得的积分 * 额外积分比率
* @param permanentRights
* @param map
*/
private
Map
<
RightType
,
Object
>
calculateRight
(
PermanentRightsDTO
permanentRights
,
Map
<
RightType
,
Object
>
map
,
Long
memberId
)
{
// 验证永久权益
boolean
b
=
this
.
validatedPermanentRights
(
permanentRights
,
memberId
);
if
(
b
)
{
// 获得的积分
List
<
TempPoints
>
tempPointsList
=
(
List
<
TempPoints
>)
map
.
get
(
RightType
.
POINTS
);
if
(!
CollectionUtils
.
isEmpty
(
tempPointsList
))
{
// 经过永久权益计算后的总积分
this
.
calculateTotalPoints
(
permanentRights
,
tempPointsList
);
map
.
put
(
RightType
.
POINTS
,
tempPointsList
);
}
// TODO 其他权益
}
return
map
;
}
/**
* 经过永久权益计算后的总积分
* @param permanentRights 永久权益
* @param tempPointsList 积分
* @return BigDecimal 总积分
*/
private
BigDecimal
calculateTotalPoints
(
PermanentRightsDTO
permanentRights
,
List
<
TempPoints
>
tempPointsList
)
{
// 总积分
BigDecimal
rewardsPoints
=
null
;
// 额外积分费率
BigDecimal
extraPoints
=
permanentRights
.
getExtraPoints
();
for
(
TempPoints
tempPoints
:
tempPointsList
)
{
rewardsPoints
=
new
BigDecimal
(
tempPoints
.
getPoints
());
if
(
Objects
.
nonNull
(
extraPoints
)
&&
extraPoints
.
compareTo
(
BigDecimal
.
ZERO
)
>
0
)
{
// 已获得的积分 * 额外积分比率
BigDecimal
multiply
=
(
extraPoints
.
divide
(
new
BigDecimal
(
100
),
4
,
RoundingMode
.
HALF_UP
)).
multiply
(
rewardsPoints
);
// 四舍五入
BigDecimal
bigDecimal
=
multiply
.
setScale
(
0
,
RoundingMode
.
HALF_UP
);
// 已获得的积分 + 已获得的积分 * 额外积分比率
rewardsPoints
=
rewardsPoints
.
add
(
bigDecimal
);
tempPoints
.
setPoints
(
rewardsPoints
.
longValue
());
}
}
return
rewardsPoints
;
}
/**
* 验证是否满足永久权益
* @param permanentRights
* @param memberId
* @return
*/
private
boolean
validatedPermanentRights
(
PermanentRightsDTO
permanentRights
,
Long
memberId
){
// 永久权益类型 0:vip;1:会员等级
Integer
type
=
0
;
// 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)
Integer
level
=
0
;
if
(
Objects
.
nonNull
(
permanentRights
))
{
level
=
permanentRights
.
getLevel
();
type
=
permanentRights
.
getType
();
}
boolean
result
=
false
;
MemberDTO
memberDTO
=
this
.
memberService
.
findById
(
memberId
);
if
(
Objects
.
nonNull
(
memberDTO
))
{
// 会员vip等级
Integer
memberVip
=
memberDTO
.
getVip
();
// 会员等级
Integer
memberLevel
=
memberDTO
.
getLevel
();
switch
(
type
)
{
// vip等级
case
0
:
if
((
Objects
.
isNull
(
memberVip
)
?
0
:
memberVip
)
>=
level
)
result
=
true
;
break
;
// 会员等级
case
1
:
if
((
Objects
.
isNull
(
memberLevel
)
?
0
:
memberLevel
)
>=
level
)
result
=
true
;
break
;
default
:
break
;
}
}
return
result
;
}
/**
* 创建权益
...
...
@@ -184,7 +315,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
return
tempRights
;
}
/**
* 优惠券
* @param memberId
...
...
@@ -202,8 +332,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
return
tempCoupon
;
}
/**
* 权益1
* @param task
...
...
@@ -214,6 +342,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
List
<
TempCoupon
>
tempCouponList
=
new
ArrayList
<>();
// 权益列表,用以保存权益记录
List
<
TempRights
>
rightsList
=
new
ArrayList
<>();
// 权益1
Long
rights1Id
=
task
.
getRightsId
();
if
(
Objects
.
nonNull
(
rights1Id
))
{
...
...
@@ -317,16 +446,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* @param rightsId
* @return
*/
private
Integer
getRightType
(
Long
rightsId
)
{
RightsDTO
rightsDTO
=
this
.
getRight
(
rightsId
);
return
Objects
.
nonNull
(
rightsDTO
)
?
rightsDTO
.
getType
()
:
-
999
;
}
/**
*
* @param rightsId
* @return
*/
private
RightsDTO
getRight
(
Long
rightsId
)
{
RightsDTO
rightsDTO
=
this
.
rightsService
.
findById
(
rightsId
);
return
rightsDTO
;
...
...
@@ -362,6 +481,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* @return
*/
private
List
<
TempPoints
>
getTempPoints
(
Long
memberId
,
DataSyncMsg
.
MsgData
msgData
,
Task
task
)
{
// 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值
Long
rewardPoints
=
task
.
getRewardPoints
();
// 过期时间
...
...
@@ -431,7 +551,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
if
(
CollectionUtils
.
isEmpty
(
taskStream
))
{
// 获取当前任务的完成情况
boolean
result
=
this
.
checkAndRefreshTaskCompletion
(
memberId
,
task
Stream
);
boolean
result
=
this
.
checkAndRefreshTaskCompletion
(
memberId
,
task
List
);
return
result
;
}
return
true
;
...
...
@@ -446,29 +566,29 @@ public class TaskOperationServiceImpl implements TaskOperationService {
* 检查并更新当前任务的完成情况
* @param memberId
* @param taskStream
* @return
* @return
boolean false:失败 true:成功
*/
private
boolean
checkAndRefreshTaskCompletion
(
Long
memberId
,
List
<
Task
>
taskStream
)
{
TrTaskProgressQueryCriteria
trTaskProgressQueryCriteria
=
new
TrTaskProgressQueryCriteria
();
trTaskProgressQueryCriteria
.
setMemberId
(
memberId
);
String
time1
=
LocalDateTimeUtil
.
todayStart
();
String
time2
=
LocalDateTimeUtil
.
todayEnd
();;
trTaskProgressQueryCriteria
.
setCompletionTime
(
time1
+
","
+
time2
);
ArrayList
array
=
new
ArrayList
<>();
for
(
Task
task
:
taskStream
)
{
TrTaskProgress
trTaskProgress
=
new
TrTaskProgress
();
Long
taskId
=
task
.
getId
();
// 行为量(完成此任务需要多少次相同行为的触发)
Integer
actionAmount
=
task
.
getActionAmount
();
trTaskProgressQueryCriteria
.
setTaskId
(
taskId
);
List
<
TrTaskProgressDTO
>
trTaskProgressDTOS
=
this
.
trTaskProgressService
.
queryAll
(
trTaskProgressQueryCriteria
);
// 任务完成记录
List
<
TrTaskProgressDTO
>
trTaskProgressDTOS
=
this
.
trTaskProgressService
.
findByMemberIdAndTaskIdAndCompletionTime
(
memberId
,
taskId
,
time1
);
Long
id
=
null
;
Integer
currentActionAmount
=
null
;
Timestamp
completionTime
=
null
;
Integer
status
=
0
;
// 行为量(完成此任务需要多少次相同行为的触发)
Integer
actionAmount
=
task
.
getActionAmount
();
// 行为量 1
if
(
actionAmount
==
1
)
{
...
...
@@ -484,24 +604,28 @@ public class TaskOperationServiceImpl implements TaskOperationService {
Long
id_
=
trTaskProgressDTO
.
getId
();
Integer
status_
=
trTaskProgressDTO
.
getStatus
();
Integer
currentActionAmount_
=
trTaskProgressDTO
.
getCurrentActionAmount
();
if
(
status_
!=
1
&&
Objects
.
isNull
(
trTaskProgressDTO
.
getCompletionTime
()))
{
Timestamp
completionTime1
=
trTaskProgressDTO
.
getCompletionTime
();
// 任务已做,不成功
if
(
Objects
.
nonNull
(
status_
)
&&
status_
==
1
&&
Objects
.
nonNull
(
currentActionAmount_
)
&&
currentActionAmount_
==
1
&&
Objects
.
nonNull
(
completionTime1
)
&&
completionTime1
.
toLocalDateTime
().
toLocalDate
().
compareTo
(
LocalDate
.
now
())
==
0
)
{
return
false
;
// 未做,成功
}
else
{
id
=
id_
;
currentActionAmount
=
1
;
completionTime
=
TimestampUtil
.
now
();
status
=
TASK_FINISH_STATUS
;
}
else
{
id
=
id_
;
currentActionAmount
=
currentActionAmount_
+
1
;
}
}
}
// 行为量
不是
1
// 行为量
非
1
if
(
actionAmount
!=
1
)
{
if
(!
CollectionUtils
.
isEmpty
(
trTaskProgressDTOS
))
{
...
...
@@ -513,22 +637,29 @@ public class TaskOperationServiceImpl implements TaskOperationService {
Integer
status_
=
trTaskProgressDTO
.
getStatus
();
Timestamp
completionTime_
=
trTaskProgressDTO
.
getCompletionTime
();
Integer
currentActionAmount_
=
trTaskProgressDTO
.
getCurrentActionAmount
();
// 行为量达到,完成
if
(
status_
!=
1
&&
Objects
.
isNull
(
completionTime_
)
&&
actionAmount
==
currentActionAmount_
+
1
)
{
id
=
id_
;
currentActionAmount
=
actionAmount
;
completionTime
=
TimestampUtil
.
now
();
status
=
TASK_FINISH_STATUS
;
}
else
{
// 行为量未达到,未完成
id
=
id_
;
currentActionAmount
=
currentActionAmount_
+
1
;
}
}
else
{
}
// 未达到行为量,未完成
if
(
CollectionUtils
.
isEmpty
(
trTaskProgressDTOS
))
{
currentActionAmount
=
1
;
status
=
TASK_UNFINISH_STATUS
;
}
}
TrTaskProgress
trTaskProgress
=
new
TrTaskProgress
();
trTaskProgress
.
setId
(
id
);
trTaskProgress
.
setCurrentActionAmount
(
currentActionAmount
);
trTaskProgress
.
setCompletionTime
(
completionTime
);
...
...
@@ -539,23 +670,15 @@ public class TaskOperationServiceImpl implements TaskOperationService {
// 更新任务完成情况
this
.
doRefreshTrTaskProcess
(
trTaskProgress
);
if
(
status
==
1
)
{
array
.
add
(
task
);
}
}
if
(
CollectionUtils
.
isEmpty
(
array
))
{
// 行为量达标
if
(
currentActionAmount
.
compareTo
(
actionAmount
)
==
0
)
{
return
true
;
}
}
return
false
;
}
/**
* 获取任务模板对应的任务列表
*
...
...
member-service-impl/src/main/java/com/topdraw/mq/config/RabbitMqConfig.java
View file @
3bc2c7f
...
...
@@ -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
);
}
}
...
...
member-service-impl/src/main/resources/config/application-dev.yml
View file @
3bc2c7f
...
...
@@ -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
:
gu
est
# rabbitmq的用户名
password
:
gu
est
# rabbitmq的密码
virtual-host
:
test
# rabbitmq的虚拟host
username
:
omo_t
est
# rabbitmq的用户名
password
:
omo_t
est
# rabbitmq的密码
publisher-confirms
:
true
#如果对异步消息需要回调必须设置为true
#jwt。依赖的common中有需要jwt的部分属性。
...
...
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/PointsOperationControllerTest.java
View file @
3bc2c7f
...
...
@@ -55,7 +55,7 @@ public class PointsOperationControllerTest extends BaseTest {
TempPoints
tempPoints
=
new
TempPoints
();
tempPoints
.
setPoints
(
10L
);
tempPoints
.
setPointsType
(
0
);
tempPoints
.
setMemberId
(
2
L
);
tempPoints
.
setMemberId
(
3
L
);
tempPoints
.
setRightsSendStrategy
(
0
);
tempPoints
.
setAccountId
(
2L
);
tempPoints
.
setExpireTime
(
Timestamp
.
valueOf
(
"2021-10-27 09:00:00"
));
...
...
member-service-impl/src/test/java/com/topdraw/test/business/process/rest/TaskOperationControllerTest.java
View file @
3bc2c7f
...
...
@@ -24,7 +24,7 @@ public class TaskOperationControllerTest extends BaseTest {
DataSyncMsg
.
MsgData
msgData
=
new
DataSyncMsg
.
MsgData
();
msgData
.
setEvent
(
1
);
msgData
.
setRemarks
(
"remark"
);
msgData
.
setMemberId
(
1
L
);
msgData
.
setMemberId
(
3
L
);
msgData
.
setDeviceType
(
2
);
msgData
.
setAppCode
(
"WEI_XIN_GOLD_PANDA"
);
dataSyncMsg
.
setMsg
(
msgData
);
...
...
member-service-impl/src/test/java/com/topdraw/test/business/process/service/TaskOperationServiceTest.java
View file @
3bc2c7f
...
...
@@ -16,7 +16,7 @@ public class TaskOperationServiceTest extends BaseTest {
@Test
public
void
dealTaskTest
()
{
Long
memberId
=
2
L
;
Long
memberId
=
3
L
;
DataSyncMsg
dataSyncMsg
=
new
DataSyncMsg
();
// dataSyncMsg.setEntityType(EntityType.MEMBER);
dataSyncMsg
.
setEventType
(
EventType
.
LOGIN
.
name
());
...
...
Please
register
or
sign in
to post a comment