Compare commits
2 Commits
2048ce356d
...
48f03f1bbe
Author | SHA1 | Date |
---|---|---|
|
48f03f1bbe | 3 months ago |
|
4ccf5c5762 | 3 months ago |
@ -0,0 +1,58 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
||||||
|
|
||||||
|
import com.mashibing.common.constant.CacheConstant;
|
||||||
|
import com.mashibing.common.enums.ExceptionEnums;
|
||||||
|
import com.mashibing.common.exception.StrategyException;
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
import com.mashibing.strategy.feignclient.CacheClient;
|
||||||
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
||||||
|
import com.mashibing.strategy.utils.OutstandingFeeLimitUtil;
|
||||||
|
import com.mashibing.strategy.utils.StrategyCheckFailedUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: FeeStrategyFilter
|
||||||
|
* @Description: 策略模块扣费校验
|
||||||
|
* @date 2025/6/11 15:07
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service(value = "fee")
|
||||||
|
public class FeeStrategyFilter implements StrategyFilter {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CacheClient cacheClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
StrategyCheckFailedUtil strategyCheckFailedUtil;
|
||||||
|
|
||||||
|
private static final String STRATEGY_NAME = "扣费";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strategy(StandardSubmit submit) {
|
||||||
|
log.info("【策略模块-扣费校验】开始====================================");
|
||||||
|
Long fee = submit.getFee();
|
||||||
|
//欠费额度
|
||||||
|
Long outstandingFeeLimit = OutstandingFeeLimitUtil.getClientOutstandingFeeLimit();
|
||||||
|
|
||||||
|
String key = CacheConstant.CLIENT_BALANCE + submit.getClientId();
|
||||||
|
String filed = CacheConstant.FIELD_BALANCE;
|
||||||
|
//扣费
|
||||||
|
Long balance = cacheClient.hincrby(key, filed, -1 * fee);
|
||||||
|
log.info("【策略模块-扣费校验】本条短信扣费{},预扣费后客户余额:{},欠费额度{}", fee, balance, outstandingFeeLimit);
|
||||||
|
//超额欠费
|
||||||
|
if (balance < outstandingFeeLimit) {
|
||||||
|
log.info("【策略模块-扣费校验】超出欠费额度!!!");
|
||||||
|
//加回去
|
||||||
|
cacheClient.hincrby(key, filed, fee);
|
||||||
|
strategyCheckFailedUtil.smsSendLog(submit, STRATEGY_NAME);
|
||||||
|
strategyCheckFailedUtil.smsPushReport(submit, STRATEGY_NAME);
|
||||||
|
throw new StrategyException(ExceptionEnums.BALANCE_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("【策略模块-扣费校验】扣费成功!!!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue