|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
@@ -11,6 +12,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.esotericsoftware.minlog.Log;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.backstage.api.RemotePtParameterService;
|
|
|
import org.dromara.backstage.basics.domain.vo.PtCardtypeVo;
|
|
|
import org.dromara.backstage.basics.service.IPtCardtypeService;
|
|
|
import org.dromara.backstage.basics.service.IPtParameterService;
|
|
|
@@ -19,14 +22,19 @@ import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
|
|
|
import org.dromara.backstage.cardCenter.mapper.PtCardMapper;
|
|
|
import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
import org.dromara.backstage.domain.vo.card.PtCardVo;
|
|
|
+import org.dromara.backstage.mq.KafkaNormalProducer;
|
|
|
import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
|
+import org.dromara.common.core.constant.CloudMqEventConstants;
|
|
|
import org.dromara.common.core.constant.Constants;
|
|
|
import org.dromara.common.core.constant.DefaultConstants;
|
|
|
import org.dromara.common.core.enums.CardOpenEnum;
|
|
|
import org.dromara.common.core.enums.CardStatusEnum;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaHeader;
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaMessage;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
@@ -47,10 +55,13 @@ import java.util.*;
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
public class PtCardServiceImpl implements IPtCardService {
|
|
|
-
|
|
|
private final PtCardMapper baseMapper;
|
|
|
private final IPtParameterService parameterService;
|
|
|
private final IPtCardtypeService cardTypeService;
|
|
|
+ private final KafkaNormalProducer kafkaNormalProducer;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private final RemotePtParameterService remotePtParameterService;
|
|
|
|
|
|
/**
|
|
|
* 查询账户卡片
|
|
|
@@ -128,6 +139,10 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean insertByBo(PtCardBo bo) {
|
|
|
+ if(ObjUtil.isEmpty(bo.getLastPay())){
|
|
|
+ bo.setLastPay(DateUtil.offsetDay(DateUtil.date(), -1));
|
|
|
+ }
|
|
|
+ bo.setLastMeal(0L);
|
|
|
PtCard add = MapstructUtils.convert(bo, PtCard.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
@@ -136,6 +151,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
bo.setCardId(add.getCardId());
|
|
|
}
|
|
|
}
|
|
|
+ sendCloudConsume(baseMapper.selectVoById(bo.getCardId()));
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
@@ -149,14 +165,16 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
public Boolean updateByBo(PtCardBo bo) {
|
|
|
PtCard update = MapstructUtils.convert(bo, PtCard.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
+ int count = baseMapper.updateById(update) ;
|
|
|
+ sendCloudConsume(baseMapper.selectVoById(bo.getCardId()));
|
|
|
+ return count>0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
private void validEntityBeforeSave(PtCard entity) {
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -171,6 +189,9 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
+ //ids.forEach(id->{
|
|
|
+ // sendCloudConsume(baseMapper.selectVoById(id));
|
|
|
+ //});
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
|
|
|
@@ -191,6 +212,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
.set(PtCard::getChangeTime, DateUtil.date())
|
|
|
.eq(PtCard::getStatus, '1')
|
|
|
.eq(PtCard::getUserId, userId));
|
|
|
+ //sendCloudConsume(baseMapper.selectVoById(userId));
|
|
|
}
|
|
|
return userIds.length;
|
|
|
}
|
|
|
@@ -206,11 +228,13 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
*/
|
|
|
@Override
|
|
|
public int resetCardType(Long[] userIds, String cardType) {
|
|
|
- Arrays.stream(userIds).forEach(userId -> baseMapper.update(null, new LambdaUpdateWrapper<PtCard>()
|
|
|
+ Arrays.stream(userIds).forEach(userId -> {baseMapper.update(null, new LambdaUpdateWrapper<PtCard>()
|
|
|
.set(PtCard::getCardType, cardType)
|
|
|
.set(PtCard::getChangeTime, DateUtil.date())
|
|
|
.eq(PtCard::getStatus, '1')
|
|
|
- .eq(PtCard::getUserId, userId)));
|
|
|
+ .eq(PtCard::getUserId, userId));
|
|
|
+ //sendCloudConsume(baseMapper.selectVoById(userId));
|
|
|
+ });
|
|
|
return userIds.length;
|
|
|
}
|
|
|
|
|
|
@@ -247,6 +271,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean lockCard(Long cardId) {
|
|
|
+ //sendCloudConsume(baseMapper.selectVoById(cardId));
|
|
|
return baseMapper.update(null, new LambdaUpdateWrapper<PtCard>()
|
|
|
.set(PtCard::getStatus, '2')
|
|
|
.set(PtCard::getChangeTime, DateUtil.date())
|
|
|
@@ -262,6 +287,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean unlockCard(Long cardId) {
|
|
|
+ //sendCloudConsume(baseMapper.selectVoById(cardId));
|
|
|
return baseMapper.update(null, new LambdaUpdateWrapper<PtCard>()
|
|
|
.set(PtCard::getStatus, '1')
|
|
|
.set(PtCard::getChangeTime, DateUtil.date())
|
|
|
@@ -511,4 +537,21 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ private void sendCloudConsume(PtCardVo vo) {
|
|
|
+ String pushData = remotePtParameterService.getPtParameterByKey("PUSH_MQ_DATA");
|
|
|
+ if (ObjectUtil.isNotEmpty(pushData) && ObjectUtil.equals(pushData, "1")) {
|
|
|
+ KafkaMessage<PtCardVo> message = new KafkaMessage<>();
|
|
|
+ KafkaHeader header = message.getHeader();
|
|
|
+ header.setTimestamp(System.currentTimeMillis());
|
|
|
+ header.setEventId(CloudMqEventConstants.CARD);
|
|
|
+ header.setEventType(CloudMqEventConstants.CARD);
|
|
|
+ header.setSender(CloudMqEventConstants.SENDER);
|
|
|
+
|
|
|
+ message.setHeader(header);
|
|
|
+ message.setBody(vo);
|
|
|
+
|
|
|
+ kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.CARD, message);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|