|
|
@@ -2,28 +2,38 @@ package org.dromara.backstage.cardCenter.service.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import org.dromara.backstage.payment.domain.PtUserAccount;
|
|
|
-import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
-import org.dromara.backstage.payment.domain.vo.PtBagVo;
|
|
|
-import org.dromara.common.core.utils.DateUtils;
|
|
|
-import org.dromara.common.core.utils.MapstructUtils;
|
|
|
-import org.dromara.common.core.utils.SpringUtils;
|
|
|
-import org.dromara.common.core.utils.StringUtils;
|
|
|
-import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
-import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.backstage.basics.domain.vo.PtCardtypeVo;
|
|
|
+import org.dromara.backstage.basics.domain.vo.PtWorkstationVo;
|
|
|
+import org.dromara.backstage.basics.service.IPtCardtypeService;
|
|
|
+import org.dromara.backstage.basics.service.IPtParameterService;
|
|
|
+import org.dromara.backstage.basics.service.IPtWorkstationService;
|
|
|
+import org.dromara.backstage.business.payments.strategy.impl.PaymentsStrategyContent;
|
|
|
+import org.dromara.backstage.cardCenter.domain.PtCard;
|
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
|
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtCardVo;
|
|
|
-import org.dromara.backstage.cardCenter.domain.PtCard;
|
|
|
import org.dromara.backstage.cardCenter.mapper.PtCardMapper;
|
|
|
import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
+import org.dromara.backstage.consumption.domain.vo.XfTermVo;
|
|
|
+import org.dromara.backstage.consumption.service.IXfTermService;
|
|
|
+import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
+import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
+import org.dromara.common.core.constant.Constants;
|
|
|
+import org.dromara.common.core.enums.CreditTypeEnum;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.SpringUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -37,6 +47,13 @@ import java.util.*;
|
|
|
public class PtCardServiceImpl implements IPtCardService {
|
|
|
|
|
|
private final PtCardMapper baseMapper;
|
|
|
+ private final IPtWorkstationService workstationService;
|
|
|
+ private final IPtUserAccountService userAccountService;
|
|
|
+ private final IXfTermService termService;
|
|
|
+ private final IPtParameterService parameterService;
|
|
|
+ private final IPtCardtypeService cardtypeService;
|
|
|
+ private final PaymentsStrategyContent paymentsStrategyContent;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询账户卡片
|
|
|
@@ -108,7 +125,9 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
- bo.setCardId(add.getCardId());
|
|
|
+ if (add != null) {
|
|
|
+ bo.setCardId(add.getCardId());
|
|
|
+ }
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
@@ -149,7 +168,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 根据Id重置账户有效期
|
|
|
+ * 根据人员Id重置账户有效期
|
|
|
*
|
|
|
* date 2024-08-06 21:53:42 21:53
|
|
|
* @author: luoyibo
|
|
|
@@ -170,7 +189,7 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 根据Id更新账户的卡类
|
|
|
+ * 根据人员Id更新账户的卡类
|
|
|
*
|
|
|
* date 2024-08-06 21:53:42 21:53
|
|
|
* @author: luoyibo
|
|
|
@@ -180,18 +199,16 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
*/
|
|
|
@Override
|
|
|
public int resetCardType(Long[] userIds, String cardType) {
|
|
|
- for (Long userId : userIds) {
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<PtCard>()
|
|
|
- .set(PtCard::getCardType, cardType)
|
|
|
- .set(PtCard::getChangeTime, DateUtil.date())
|
|
|
- .eq(PtCard::getStatus, '1')
|
|
|
- .eq(PtCard::getUserId, userId));
|
|
|
- }
|
|
|
+ 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)));
|
|
|
return userIds.length;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据Id获取账户发卡信息
|
|
|
+ * 根据人员Id获取账户发卡信息
|
|
|
*
|
|
|
* @param userIds id串,英文逗号隔开
|
|
|
* @return 发卡信息串,英文逗号隔开
|
|
|
@@ -215,6 +232,23 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
return String.join(StringUtils.SEPARATOR, list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据人员Id获取账户主卡
|
|
|
+ *
|
|
|
+ * @param userId 人员Id
|
|
|
+ * @return 主卡信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PtCardVo queryMainCardByUserId(Long userId) {
|
|
|
+ PtCardBo bo = new PtCardBo();
|
|
|
+ bo.setUserId(userId);
|
|
|
+ bo.setStatus("1");
|
|
|
+ bo.setMainCard("Y");
|
|
|
+
|
|
|
+ List<PtCardVo> list = SpringUtils.getAopProxy(this).queryList(bo);
|
|
|
+ return list == null ? null : list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据Id挂失卡片
|
|
|
*
|
|
|
@@ -244,4 +278,99 @@ public class PtCardServiceImpl implements IPtCardService {
|
|
|
.eq(PtCard::getStatus, '2')
|
|
|
.eq(PtCard::getCardId, cardId)) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户充值
|
|
|
+ *
|
|
|
+ * @param bo 充值钱包
|
|
|
+ * @return 是否充值成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean rechargeByBo(PtBagBo bo) {
|
|
|
+ BigDecimal doMoney = bo.getReceiptMoney();
|
|
|
+ if (bo.getTakeCommission().equals(Constants.TAKE_COMMISSION)) {
|
|
|
+ //需要收管理费,则要计算管理费并将管理费收支入账
|
|
|
+ BigDecimal commission = computeCommission(bo.getReceiptMoney(), bo.getUserId());
|
|
|
+ if (commission.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //管理费>0,管理费入收支账
|
|
|
+ PtBagBo commissionBo = MapstructUtils.convert(bo, PtBagBo.class);
|
|
|
+ if (commissionBo != null) {
|
|
|
+ commissionBo.setReceiptMoney(commission);
|
|
|
+ commissionBo.setCreditType(CreditTypeEnum.COMMISSION_CHARGE);
|
|
|
+ paymentsStrategyContent.createOrder(commissionBo);
|
|
|
+ }
|
|
|
+ //收了管理费,收支入账的金额=原收支金额-管理费
|
|
|
+ bo.setReceiptMoney(doMoney.subtract(commission));
|
|
|
+ paymentsStrategyContent.createOrder(bo);
|
|
|
+ } else {
|
|
|
+ //管理费=0,直接记资金收支
|
|
|
+ paymentsStrategyContent.createOrder(bo);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //不收管理费,直接记资金收支
|
|
|
+ paymentsStrategyContent.createOrder(bo);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户资金收支时获取必要的辅助信息
|
|
|
+ *
|
|
|
+ * @param bo 资金收支信息
|
|
|
+ * @param accountVo 资金收支账户信息
|
|
|
+ * @param cardVo 资金收支卡片信息
|
|
|
+ * @param termVo 资金收支消费设备信息
|
|
|
+ * @param workstationVo 资金收支工作站信息
|
|
|
+ */
|
|
|
+ private void getOtherInfo(PtBagBo bo, PtUserAccountVo accountVo, PtCardVo cardVo, XfTermVo termVo, PtWorkstationVo workstationVo) {
|
|
|
+ //1.人员辅助信息
|
|
|
+ accountVo = userAccountService.queryById(bo.getUserId());
|
|
|
+ //2.卡片辅助信息
|
|
|
+ if (bo.getCardId() > 0) {
|
|
|
+ //如果传入了cardId,根据cardId查询卡片信息
|
|
|
+ cardVo = queryById(bo.getCardId());
|
|
|
+ } else {
|
|
|
+ //查询当前人的正常主卡
|
|
|
+ cardVo = queryMainCardByUserId(bo.getUserId());
|
|
|
+ }
|
|
|
+ //3.设备辅助信息
|
|
|
+ termVo = termService.queryByNo(bo.getTermNo());
|
|
|
+ //4.工作站辅助信息
|
|
|
+ workstationVo = workstationService.queryById(bo.getStationId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算管理费
|
|
|
+ * 考虑账户可能没有卡数据就充值,此时只能从账户中获取账户的卡类,从而得到管理费的计算方式
|
|
|
+ *
|
|
|
+ * @param data 需要计算管理费的金额
|
|
|
+ * @param userId 账户Id
|
|
|
+ * @return 管理费
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BigDecimal computeCommission(BigDecimal data, Long userId) {
|
|
|
+ //当前账户信息
|
|
|
+ PtUserAccountVo accountVo = userAccountService.queryById(userId);
|
|
|
+ //当前账户的卡类
|
|
|
+ PtCardtypeVo cardTypeVo = cardtypeService.queryById(accountVo.getCardType());
|
|
|
+ //卡类对应的管理费
|
|
|
+ BigDecimal commissionRate = new BigDecimal(cardTypeVo.getCommissionCharge());
|
|
|
+ if (commissionRate.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //设置有管理费率,需要计算管理费
|
|
|
+ BigDecimal commission;
|
|
|
+ String commType = parameterService.selectParamByCode("COMMISSION_TYPE");
|
|
|
+ //从系统参数表中拿收管理费的设置
|
|
|
+ if (Constants.TAKE_COMMISSION.equals(commType)) {
|
|
|
+ //按比例收取
|
|
|
+ commission = data.multiply(commissionRate.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ } else {
|
|
|
+ //直接设置
|
|
|
+ commission = commissionRate;
|
|
|
+ }
|
|
|
+ return commission;
|
|
|
+ } else {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|