|
|
@ -0,0 +1,60 @@ |
|
|
|
|
|
package com.qniao.dam.application.handler.pointaccount; |
|
|
|
|
|
|
|
|
|
|
|
import com.qniao.dam.domain.aggregate.pointaccount.PointAccountAggregate; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.pointaccount.entity.PointAccount; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.pointaccount.valueobj.PointAccountRecord; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.prc.entity.PointRewardConfig; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.pointaccount.event.PointRewardCreatedMQ; |
|
|
|
|
|
import com.qniao.dam.infrastructure.constant.MqExchange; |
|
|
|
|
|
import com.qniao.dam.infrastructure.constant.MqQueue; |
|
|
|
|
|
import com.qniao.dam.query.pointaccount.PointAccountQueryService; |
|
|
|
|
|
import com.qniao.dam.query.prc.PointRewardConfigQueryService; |
|
|
|
|
|
import com.qniao.domain.BaseApplicationService; |
|
|
|
|
|
import com.qniao.framework.utils.TypeConvertUtils; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.amqp.core.ExchangeTypes; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Exchange; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.QueueBinding; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
public class PointAccountEventHandler extends BaseApplicationService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private PointAccountQueryService pointAccountQueryService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private PointRewardConfigQueryService pointRewardConfigQueryService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private PointAccountAggregate pointAccountAggregate; |
|
|
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.POINT_REWARD_CREATED), |
|
|
|
|
|
exchange = @Exchange(value = MqExchange.POINT_REWARD_CREATED, |
|
|
|
|
|
type = ExchangeTypes.FANOUT))) |
|
|
|
|
|
public void handle(PointRewardCreatedMQ mq) { |
|
|
|
|
|
try { |
|
|
|
|
|
PointAccount pointAccount = pointAccountQueryService.queryByType(mq.getOwnId(), mq.getIdentityType()); |
|
|
|
|
|
//积分计算 |
|
|
|
|
|
PointRewardConfig pointRewardConfig = pointRewardConfigQueryService.queryEnableByType(mq.getPointType()); |
|
|
|
|
|
if (Objects.nonNull(pointRewardConfig)) { |
|
|
|
|
|
Integer points = pointRewardConfig.calculateReward(mq.getAmount()); |
|
|
|
|
|
PointAccountRecord pointAccountRecord = TypeConvertUtils.convert(mq, PointAccountRecord.class); |
|
|
|
|
|
pointAccountRecord.setPoints(points); |
|
|
|
|
|
pointAccountRecord.setOriginalPoints(pointAccount.getPoints()); |
|
|
|
|
|
pointAccount.setPoints(pointAccount.getPoints() + points); |
|
|
|
|
|
pointAccountRecord.setCurrentPoints(pointAccount.getPoints()); |
|
|
|
|
|
pointAccount.setRecordList(Collections.singletonList(pointAccountRecord)); |
|
|
|
|
|
pointAccountAggregate.edit(pointAccount); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("积分奖励创建事件处理异常", e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |