|
@@ -1,16 +1,782 @@
|
|
|
package com.sckw.payment.service.impl;
|
|
package com.sckw.payment.service.impl;
|
|
|
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
|
|
+import com.sckw.core.model.enums.EntTypeEnum;
|
|
|
|
|
+import com.sckw.core.utils.PageUtils;
|
|
|
|
|
+import com.sckw.core.web.context.LoginEntHolder;
|
|
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
|
|
+import com.sckw.core.web.response.BaseResult;
|
|
|
|
|
+import com.sckw.payment.config.ApplicationProperties;
|
|
|
import com.sckw.payment.entity.WalletAgent;
|
|
import com.sckw.payment.entity.WalletAgent;
|
|
|
|
|
+import com.sckw.payment.entity.WalletAgentBalance;
|
|
|
|
|
+import com.sckw.payment.entity.WalletAgentRecord;
|
|
|
|
|
+import com.sckw.payment.entity.KwpWallet;
|
|
|
|
|
+import com.sckw.payment.enums.ExecutionStatusEnum;
|
|
|
|
|
+import com.sckw.payment.enums.OrderTypeEnum;
|
|
|
|
|
+import com.sckw.payment.enums.PayStatusEnum;
|
|
|
import com.sckw.payment.mapper.WalletAgentMapper;
|
|
import com.sckw.payment.mapper.WalletAgentMapper;
|
|
|
|
|
+import com.sckw.payment.mapper.WalletAgentBalanceMapper;
|
|
|
|
|
+import com.sckw.payment.mapper.WalletAgentRecordMapper;
|
|
|
|
|
+import com.sckw.payment.mapper.KwpWalletMapper;
|
|
|
|
|
+import com.sckw.payment.pojo.dto.PayDto;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.PayRes;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.ReceivedCallbackDto;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.WalletAgentManualDto;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.WalletAgentBalanceQuery;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.WalletAgentPayDto;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.WalletAgentQuery;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.req.WalletAgentRecordQuery;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.res.WalletAgentBalanceRes;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.res.WalletAgentRecordRes;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.res.WalletAgentRes;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.res.WalletAgentSummary;
|
|
|
|
|
+import com.sckw.payment.pojo.vo.res.WalletPayAddRes;
|
|
|
|
|
+import com.sckw.payment.service.PayXwService;
|
|
|
|
|
+import com.sckw.payment.api.model.dto.common.R;
|
|
|
|
|
+import com.sckw.payment.api.model.TradeEntInfoResVo;
|
|
|
|
|
+import com.sckw.system.api.RemoteSystemService;
|
|
|
|
|
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
-* @date 2026-06-15 10:58:32
|
|
|
|
|
-* @author xucaiqin
|
|
|
|
|
-*/
|
|
|
|
|
|
|
+ * @author xucaiqin
|
|
|
|
|
+ * @date 2026-06-15 10:58:32
|
|
|
|
|
+ */
|
|
|
@Service
|
|
@Service
|
|
|
public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAgent> {
|
|
public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAgent> {
|
|
|
|
|
|
|
|
|
|
+ private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WalletAgentRecordMapper walletAgentRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WalletAgentBalanceMapper walletAgentBalanceMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PayXwService payXwService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private KwpWalletMapper kwpWalletMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ApplicationProperties applicationProperties;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
|
|
|
|
|
+ private RemoteSystemService remoteSystemService;
|
|
|
|
|
+
|
|
|
|
|
+ public WalletAgentSummary queryAgentSummary() {
|
|
|
|
|
+ WalletAgentSummary summary = new WalletAgentSummary();
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
|
|
|
|
|
+ .eq(WalletAgent::getDelFlag, 0)
|
|
|
|
|
+ .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
|
|
|
|
|
+
|
|
|
|
|
+ List<WalletAgent> list = baseMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return summary;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal preTotal = list.stream()
|
|
|
|
|
+ .map(WalletAgent::getPreBalance)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal tradingTotal = list.stream()
|
|
|
|
|
+ .map(WalletAgent::getTradingAmount)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ summary.setPreBalanceTotal(preTotal);
|
|
|
|
|
+ summary.setTradingAmountTotal(tradingTotal);
|
|
|
|
|
+ return summary;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public PageInfo<WalletAgentRes> agentList(WalletAgentQuery query) {
|
|
|
|
|
+ PageInfo<WalletAgentRes> pageInfo = new PageInfo<>(new ArrayList<>());
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
|
|
|
|
|
+ .eq(WalletAgent::getDelFlag, 0)
|
|
|
|
|
+ .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
|
|
|
|
|
+
|
|
|
|
|
+ if (query.getTradeEntId() != null) {
|
|
|
|
|
+ wrapper.eq(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, query.getTradeEntId());
|
|
|
|
|
+ } else if (StringUtils.hasText(query.getTradeEntName())) {
|
|
|
|
|
+ List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(query.getTradeEntName());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entCacheResDtos)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> ids = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
|
|
|
|
|
+ wrapper.in(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, ids);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (query.getPreBalanceMin() != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgent::getPreBalance, query.getPreBalanceMin());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getPreBalanceMax() != null) {
|
|
|
|
|
+ wrapper.le(WalletAgent::getPreBalance, query.getPreBalanceMax());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getTradingAmountMin() != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgent::getTradingAmount, query.getTradingAmountMin());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getTradingAmountMax() != null) {
|
|
|
|
|
+ wrapper.le(WalletAgent::getTradingAmount, query.getTradingAmountMax());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wrapper.orderByDesc(WalletAgent::getUpdateTime, WalletAgent::getId);
|
|
|
|
|
+
|
|
|
|
|
+ PageUtils.startPage(query);
|
|
|
|
|
+ List<WalletAgent> walletAgents = baseMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(walletAgents)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> tradeEntIds = walletAgents.stream()
|
|
|
|
|
+ .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ Map<Long, String> entNameMap = new HashMap<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(tradeEntIds)) {
|
|
|
|
|
+ List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIds);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(entInfos)) {
|
|
|
|
|
+ entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, String> finalEntNameMap = entNameMap;
|
|
|
|
|
+ pageInfo = ((Page<WalletAgent>) walletAgents).toPageInfo(e -> {
|
|
|
|
|
+ WalletAgentRes res = new WalletAgentRes();
|
|
|
|
|
+ res.setId(e.getId());
|
|
|
|
|
+ Long tradeEntId = proxy ? e.getSupEntId() : e.getAgtEntId();
|
|
|
|
|
+ res.setTradeEntId(tradeEntId);
|
|
|
|
|
+ res.setTradeEntName(finalEntNameMap.getOrDefault(tradeEntId, ""));
|
|
|
|
|
+ res.setPreBalance(e.getPreBalance());
|
|
|
|
|
+ res.setTradingAmount(e.getTradingAmount());
|
|
|
|
|
+ res.setUpdateTime(toDate(e.getUpdateTime()));
|
|
|
|
|
+ res.setCanPay(proxy ? 0 : (e.getPreBalance() != null && e.getPreBalance().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0));
|
|
|
|
|
+ res.setCanManualEntry(proxy && e.getPreBalance() != null && e.getPreBalance().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0);
|
|
|
|
|
+ return res;
|
|
|
|
|
+ });
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<TradeEntInfoResVo> queryTradeEntList() {
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
|
|
|
|
|
+ .select(WalletAgent::getAgtEntId, WalletAgent::getSupEntId)
|
|
|
|
|
+ .eq(WalletAgent::getDelFlag, 0)
|
|
|
|
|
+ .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
|
|
|
|
|
+
|
|
|
|
|
+ List<WalletAgent> list = baseMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> tradeEntIds = list.stream()
|
|
|
|
|
+ .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ if (CollectionUtils.isEmpty(tradeEntIds)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIds);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entInfos)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ return entInfos.stream().map(e -> {
|
|
|
|
|
+ TradeEntInfoResVo vo = new TradeEntInfoResVo();
|
|
|
|
|
+ vo.setEntId(e.getId());
|
|
|
|
|
+ vo.setEntName(e.getFirmName());
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }).toList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public PageInfo<WalletAgentBalanceRes> balanceList(WalletAgentBalanceQuery query) {
|
|
|
|
|
+ PageInfo<WalletAgentBalanceRes> pageInfo = new PageInfo<>(new ArrayList<>());
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+
|
|
|
|
|
+ Long agtEntId;
|
|
|
|
|
+ Long supEntId;
|
|
|
|
|
+ if (query.getAgentId() != null) {
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(query.getAgentId());
|
|
|
|
|
+ if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
|
|
|
|
|
+ throw new BusinessException("无权限查看该代理费明细");
|
|
|
|
|
+ }
|
|
|
|
|
+ agtEntId = walletAgent.getAgtEntId();
|
|
|
|
|
+ supEntId = walletAgent.getSupEntId();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ agtEntId = proxy ? curEntId : null;
|
|
|
|
|
+ supEntId = proxy ? null : curEntId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgentBalance> wrapper = Wrappers.lambdaQuery(WalletAgentBalance.class)
|
|
|
|
|
+ .eq(WalletAgentBalance::getDelFlag, 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (agtEntId != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentBalance::getAgtEntId, agtEntId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (supEntId != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentBalance::getSupEntId, supEntId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.hasText(query.getOrderNo())) {
|
|
|
|
|
+ wrapper.like(WalletAgentBalance::getOrderNo, query.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getOrderType() != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentBalance::getOrderType, query.getOrderType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (query.getTradeType() != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentBalance::getTradeType, query.getTradeType());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getTradeAmountMin() != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgentBalance::getTradeAmount, query.getTradeAmountMin());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getTradeAmountMax() != null) {
|
|
|
|
|
+ wrapper.le(WalletAgentBalance::getTradeAmount, query.getTradeAmountMax());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getStatus() != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentBalance::getStatus, query.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (query.getTradeEntId() != null || StringUtils.hasText(query.getTradeEntName())) {
|
|
|
|
|
+ List<Long> tradeEntIds;
|
|
|
|
|
+ if (query.getTradeEntId() != null) {
|
|
|
|
|
+ tradeEntIds = List.of(query.getTradeEntId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(query.getTradeEntName());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entCacheResDtos)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ tradeEntIds = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (proxy) {
|
|
|
|
|
+ wrapper.in(WalletAgentBalance::getSupEntId, tradeEntIds);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wrapper.in(WalletAgentBalance::getAgtEntId, tradeEntIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LocalDateTime startTime = parseDateTime(query.getStartTime());
|
|
|
|
|
+ LocalDateTime endTime = parseDateTime(query.getEndTime());
|
|
|
|
|
+ if (startTime != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgentBalance::getCreateTime, startTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (endTime != null) {
|
|
|
|
|
+ wrapper.le(WalletAgentBalance::getCreateTime, endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc(WalletAgentBalance::getCreateTime, WalletAgentBalance::getId);
|
|
|
|
|
+
|
|
|
|
|
+ PageUtils.startPage(query);
|
|
|
|
|
+ List<WalletAgentBalance> list = walletAgentBalanceMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> tradeEntIdList = list.stream()
|
|
|
|
|
+ .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ Map<Long, String> entNameMap = new HashMap<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(tradeEntIdList)) {
|
|
|
|
|
+ List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIdList);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(entInfos)) {
|
|
|
|
|
+ entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, String> finalEntNameMap = entNameMap;
|
|
|
|
|
+
|
|
|
|
|
+ pageInfo = ((Page<WalletAgentBalance>) list).toPageInfo(e -> {
|
|
|
|
|
+ WalletAgentBalanceRes res = new WalletAgentBalanceRes();
|
|
|
|
|
+ BeanUtils.copyProperties(e, res);
|
|
|
|
|
+ res.setStatusDesc(ExecutionStatusEnum.getByCode(e.getStatus()));
|
|
|
|
|
+ Long tradeEntId = proxy ? e.getSupEntId() : e.getAgtEntId();
|
|
|
|
|
+ res.setTradeEntId(tradeEntId);
|
|
|
|
|
+ res.setTradeEntName(finalEntNameMap.getOrDefault(tradeEntId, ""));
|
|
|
|
|
+ res.setTradeTypeDesc(getAgentTradeTypeDesc(e.getTradeType()));
|
|
|
|
|
+ res.setCreateTime(toDate(e.getCreateTime()));
|
|
|
|
|
+ return res;
|
|
|
|
|
+ });
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public PageInfo<WalletAgentRecordRes> recordList(WalletAgentRecordQuery query) {
|
|
|
|
|
+ PageInfo<WalletAgentRecordRes> pageInfo = new PageInfo<>(new ArrayList<>());
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> agentIds;
|
|
|
|
|
+ if (query.getAgentId() != null) {
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(query.getAgentId());
|
|
|
|
|
+ if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
|
|
|
|
|
+ throw new BusinessException("无权限查看该支付记录");
|
|
|
|
|
+ }
|
|
|
|
|
+ agentIds = List.of(query.getAgentId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ agentIds = resolveAgentIds(curEntId, proxy, query.getTradeEntId(), query.getTradeEntName());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(agentIds)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgentRecord> wrapper = Wrappers.lambdaQuery(WalletAgentRecord.class)
|
|
|
|
|
+ .eq(WalletAgentRecord::getDelFlag, 0)
|
|
|
|
|
+ .in(WalletAgentRecord::getAgentId, agentIds);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.hasText(query.getOrderNo())) {
|
|
|
|
|
+ wrapper.like(WalletAgentRecord::getOrderNo, query.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getPrepaidAmountMin() != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgentRecord::getPrepaidAmount, query.getPrepaidAmountMin());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getPrepaidAmountMax() != null) {
|
|
|
|
|
+ wrapper.le(WalletAgentRecord::getPrepaidAmount, query.getPrepaidAmountMax());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getStatus() != null) {
|
|
|
|
|
+ wrapper.eq(WalletAgentRecord::getStatus, query.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalDateTime startTime = parseDateTime(query.getStartTime());
|
|
|
|
|
+ LocalDateTime endTime = parseDateTime(query.getEndTime());
|
|
|
|
|
+ if (startTime != null) {
|
|
|
|
|
+ wrapper.ge(WalletAgentRecord::getCreateTime, startTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (endTime != null) {
|
|
|
|
|
+ wrapper.le(WalletAgentRecord::getCreateTime, endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc(WalletAgentRecord::getCreateTime, WalletAgentRecord::getId);
|
|
|
|
|
+
|
|
|
|
|
+ PageUtils.startPage(query);
|
|
|
|
|
+ List<WalletAgentRecord> list = walletAgentRecordMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> agentIdList = list.stream().map(WalletAgentRecord::getAgentId).filter(Objects::nonNull).distinct().toList();
|
|
|
|
|
+ Map<Long, WalletAgent> agentMap = new HashMap<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(agentIdList)) {
|
|
|
|
|
+ List<WalletAgent> agents = baseMapper.selectList(Wrappers.lambdaQuery(WalletAgent.class).in(WalletAgent::getId, agentIdList).eq(WalletAgent::getDelFlag, 0));
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(agents)) {
|
|
|
|
|
+ agentMap = agents.stream().collect(Collectors.toMap(WalletAgent::getId, e -> e, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> tradeEntIdList = agentMap.values().stream()
|
|
|
|
|
+ .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ Map<Long, String> entNameMap = new HashMap<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(tradeEntIdList)) {
|
|
|
|
|
+ List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIdList);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(entInfos)) {
|
|
|
|
|
+ entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, WalletAgent> finalAgentMap = agentMap;
|
|
|
|
|
+ Map<Long, String> finalEntNameMap = entNameMap;
|
|
|
|
|
+
|
|
|
|
|
+ pageInfo = ((Page<WalletAgentRecord>) list).toPageInfo(e -> {
|
|
|
|
|
+ WalletAgentRecordRes res = new WalletAgentRecordRes();
|
|
|
|
|
+ BeanUtils.copyProperties(e, res);
|
|
|
|
|
+ PayStatusEnum statusEnum = PayStatusEnum.getByCode(e.getStatus());
|
|
|
|
|
+ res.setStatusDesc(statusEnum == null ? "" : statusEnum.getName());
|
|
|
|
|
+ WalletAgent agent = finalAgentMap.get(e.getAgentId());
|
|
|
|
|
+ Long tradeEntId = agent == null ? null : (proxy ? agent.getSupEntId() : agent.getAgtEntId());
|
|
|
|
|
+ res.setTradeEntId(tradeEntId);
|
|
|
|
|
+ res.setTradeEntName(tradeEntId == null ? "" : finalEntNameMap.getOrDefault(tradeEntId, ""));
|
|
|
|
|
+ res.setCreateTime(toDate(e.getCreateTime()));
|
|
|
|
|
+ return res;
|
|
|
|
|
+ });
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BaseResult<Object> manualEntry(WalletAgentManualDto manualDto) {
|
|
|
|
|
+ if (!isProxyEnt()) {
|
|
|
|
|
+ return BaseResult.failed("非代理企业不可人工录入");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectOne(Wrappers.lambdaQuery(WalletAgent.class)
|
|
|
|
|
+ .eq(WalletAgent::getDelFlag, 0)
|
|
|
|
|
+ .eq(WalletAgent::getAgtEntId, curEntId)
|
|
|
|
|
+ .eq(WalletAgent::getSupEntId, manualDto.getTradeEntId())
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (walletAgent == null) {
|
|
|
|
|
+ return BaseResult.failed("代理费清单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (walletAgent.getPreBalance() == null || walletAgent.getPreBalance().compareTo(manualDto.getAmount()) < 0) {
|
|
|
|
|
+ return BaseResult.failed("金额不能大于待收代理费");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long userId = LoginUserHolder.getUserId();
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ String orderNo = "M" + System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal newPre = walletAgent.getPreBalance().subtract(manualDto.getAmount());
|
|
|
|
|
+ walletAgent.setPreBalance(newPre);
|
|
|
|
|
+ walletAgent.setUpdateBy(userId);
|
|
|
|
|
+ walletAgent.setUpdateTime(now);
|
|
|
|
|
+ baseMapper.updateById(walletAgent);
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentBalance balance = new WalletAgentBalance();
|
|
|
|
|
+ balance.setOrderNo(orderNo);
|
|
|
|
|
+ balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
|
|
|
|
|
+ balance.setAgtEntId(walletAgent.getAgtEntId());
|
|
|
|
|
+ balance.setSupEntId(walletAgent.getSupEntId());
|
|
|
|
|
+ balance.setTradeType(4);
|
|
|
|
|
+ balance.setTradeAmount(manualDto.getAmount());
|
|
|
|
|
+ balance.setPreBalance(newPre);
|
|
|
|
|
+ balance.setTradingAmount(walletAgent.getTradingAmount());
|
|
|
|
|
+ balance.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
|
|
|
|
|
+ balance.setRemark(manualDto.getRemark());
|
|
|
|
|
+ balance.setCreateBy(userId);
|
|
|
|
|
+ balance.setCreateTime(now);
|
|
|
|
|
+ balance.setUpdateBy(userId);
|
|
|
|
|
+ balance.setUpdateTime(now);
|
|
|
|
|
+ balance.setDelFlag(0);
|
|
|
|
|
+ walletAgentBalanceMapper.insert(balance);
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentRecord record = new WalletAgentRecord();
|
|
|
|
|
+ record.setAgentId(walletAgent.getId());
|
|
|
|
|
+ record.setOrderNo(orderNo);
|
|
|
|
|
+ record.setPrepaidAmount(manualDto.getAmount());
|
|
|
|
|
+ record.setReceivedAmount(manualDto.getAmount());
|
|
|
|
|
+ record.setStatus(PayStatusEnum.PAID.getCode());
|
|
|
|
|
+ record.setData("");
|
|
|
|
|
+ record.setRemark(manualDto.getRemark());
|
|
|
|
|
+ record.setCreateBy(userId);
|
|
|
|
|
+ record.setCreateTime(now);
|
|
|
|
|
+ record.setUpdateBy(userId);
|
|
|
|
|
+ record.setUpdateTime(now);
|
|
|
|
|
+ record.setDelFlag(0);
|
|
|
|
|
+ walletAgentRecordMapper.insert(record);
|
|
|
|
|
+ return BaseResult.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BaseResult<WalletPayAddRes> pay(WalletAgentPayDto payDto) {
|
|
|
|
|
+ if (isProxyEnt()) {
|
|
|
|
|
+ return BaseResult.failed("代理企业不可发起代理费付款");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(payDto.getAgentId());
|
|
|
|
|
+ if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ return BaseResult.failed("代理费清单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ if (!Objects.equals(walletAgent.getSupEntId(), curEntId)) {
|
|
|
|
|
+ return BaseResult.failed("无权限发起付款");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (walletAgent.getPreBalance() == null || walletAgent.getPreBalance().compareTo(payDto.getPayAmount()) < 0) {
|
|
|
|
|
+ return BaseResult.failed("付款金额不能大于待付代理费");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String orderNo = String.valueOf(System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ PayDto payReq = new PayDto();
|
|
|
|
|
+ payReq.setUid(getUid(curEntId));
|
|
|
|
|
+ payReq.setFilter(getUid(walletAgent.getAgtEntId()));
|
|
|
|
|
+ payReq.setOrderNo(orderNo);
|
|
|
|
|
+ payReq.setAmt(payDto.getPayAmount().toString());
|
|
|
|
|
+ payReq.setNoticeUrl(applicationProperties.getCharge());
|
|
|
|
|
+ payReq.setRemark(payDto.getRemark());
|
|
|
|
|
+
|
|
|
|
|
+ R<PayRes> pay;
|
|
|
|
|
+ try {
|
|
|
|
|
+ pay = payXwService.pay(payReq);
|
|
|
|
|
+ if (pay.getCode() != 200) {
|
|
|
|
|
+ throw new RuntimeException(pay.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long userId = LoginUserHolder.getUserId();
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentRecord record = new WalletAgentRecord();
|
|
|
|
|
+ record.setAgentId(walletAgent.getId());
|
|
|
|
|
+ record.setOrderNo(orderNo);
|
|
|
|
|
+ record.setPrepaidAmount(payDto.getPayAmount());
|
|
|
|
|
+ record.setReceivedAmount(BigDecimal.ZERO);
|
|
|
|
|
+ record.setStatus(PayStatusEnum.PAYABLE.getCode());
|
|
|
|
|
+ record.setData(JSONObject.toJSONString(pay.getData()));
|
|
|
|
|
+ record.setRemark(payDto.getRemark());
|
|
|
|
|
+ record.setCreateBy(userId);
|
|
|
|
|
+ record.setCreateTime(now);
|
|
|
|
|
+ record.setUpdateBy(userId);
|
|
|
|
|
+ record.setUpdateTime(now);
|
|
|
|
|
+ record.setDelFlag(0);
|
|
|
|
|
+ walletAgentRecordMapper.insert(record);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal newPre = walletAgent.getPreBalance().subtract(payDto.getPayAmount());
|
|
|
|
|
+ BigDecimal newTrading = (walletAgent.getTradingAmount() == null ? BigDecimal.ZERO : walletAgent.getTradingAmount()).add(payDto.getPayAmount());
|
|
|
|
|
+ walletAgent.setPreBalance(newPre);
|
|
|
|
|
+ walletAgent.setTradingAmount(newTrading);
|
|
|
|
|
+ walletAgent.setUpdateBy(userId);
|
|
|
|
|
+ walletAgent.setUpdateTime(now);
|
|
|
|
|
+ baseMapper.updateById(walletAgent);
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentBalance balance = new WalletAgentBalance();
|
|
|
|
|
+ balance.setOrderNo(orderNo);
|
|
|
|
|
+ balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
|
|
|
|
|
+ balance.setAgtEntId(walletAgent.getAgtEntId());
|
|
|
|
|
+ balance.setSupEntId(walletAgent.getSupEntId());
|
|
|
|
|
+ balance.setTradeType(2);
|
|
|
|
|
+ balance.setTradeAmount(payDto.getPayAmount());
|
|
|
|
|
+ balance.setPreBalance(newPre);
|
|
|
|
|
+ balance.setTradingAmount(newTrading);
|
|
|
|
|
+ balance.setStatus(ExecutionStatusEnum.IN_PROGRESS.getCode());
|
|
|
|
|
+ balance.setRemark(payDto.getRemark());
|
|
|
|
|
+ balance.setCreateBy(userId);
|
|
|
|
|
+ balance.setCreateTime(now);
|
|
|
|
|
+ balance.setUpdateBy(userId);
|
|
|
|
|
+ balance.setUpdateTime(now);
|
|
|
|
|
+ balance.setDelFlag(0);
|
|
|
|
|
+ walletAgentBalanceMapper.insert(balance);
|
|
|
|
|
+
|
|
|
|
|
+ WalletPayAddRes walletPayAddRes = new WalletPayAddRes();
|
|
|
|
|
+ PayRes data = pay.getData();
|
|
|
|
|
+ walletPayAddRes.setId(record.getId());
|
|
|
|
|
+ walletPayAddRes.setOrderNo(data.getOrderNo());
|
|
|
|
|
+ walletPayAddRes.setSettleAcctName(data.getFullName());
|
|
|
|
|
+ walletPayAddRes.setSettleAcctNo(data.getSettleAcct());
|
|
|
|
|
+ walletPayAddRes.setAmount(new BigDecimal(data.getAmt()));
|
|
|
|
|
+ walletPayAddRes.setBankName("新网银行");
|
|
|
|
|
+ return BaseResult.success(walletPayAddRes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BaseResult<WalletPayAddRes> getPayInfo(Long id) {
|
|
|
|
|
+ WalletAgentRecord record = walletAgentRecordMapper.selectById(id);
|
|
|
|
|
+ if (record == null || !Objects.equals(record.getDelFlag(), 0)) {
|
|
|
|
|
+ return BaseResult.failed("支付记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(record.getData())) {
|
|
|
|
|
+ return BaseResult.failed("该记录无付款信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(record.getAgentId());
|
|
|
|
|
+ if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ return BaseResult.failed("代理费清单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
|
|
|
|
|
+ return BaseResult.failed("无权限查看付款信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ WalletPayAddRes walletPayAddRes = new WalletPayAddRes();
|
|
|
|
|
+ PayRes data = JSONObject.parseObject(record.getData(), PayRes.class);
|
|
|
|
|
+ walletPayAddRes.setId(record.getId());
|
|
|
|
|
+ walletPayAddRes.setOrderNo(data.getOrderNo());
|
|
|
|
|
+ walletPayAddRes.setSettleAcctName(data.getFullName());
|
|
|
|
|
+ walletPayAddRes.setSettleAcctNo(data.getSettleAcct());
|
|
|
|
|
+ walletPayAddRes.setAmount(new BigDecimal(data.getAmt()));
|
|
|
|
|
+ walletPayAddRes.setBankName("新网银行");
|
|
|
|
|
+ return BaseResult.success(walletPayAddRes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void receivedCallback(ReceivedCallbackDto receivedCallbackDto) {
|
|
|
|
|
+ WalletAgentRecord record = walletAgentRecordMapper.selectOne(Wrappers.lambdaQuery(WalletAgentRecord.class)
|
|
|
|
|
+ .eq(WalletAgentRecord::getOrderNo, receivedCallbackDto.getPayOrderNo())
|
|
|
|
|
+ .eq(WalletAgentRecord::getDelFlag, 0)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (record == null) {
|
|
|
|
|
+ throw new BusinessException("支付记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long userId = LoginUserHolder.getUserId();
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+
|
|
|
|
|
+ record.setReceivedAmount(receivedCallbackDto.getTranAmt());
|
|
|
|
|
+ record.setStatus(PayStatusEnum.PAID.getCode());
|
|
|
|
|
+ record.setUpdateBy(userId);
|
|
|
|
|
+ record.setUpdateTime(now);
|
|
|
|
|
+ walletAgentRecordMapper.updateById(record);
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(record.getAgentId());
|
|
|
|
|
+ if (walletAgent != null && Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ BigDecimal newTrading = (walletAgent.getTradingAmount() == null ? BigDecimal.ZERO : walletAgent.getTradingAmount()).subtract(receivedCallbackDto.getTranAmt());
|
|
|
|
|
+ walletAgent.setTradingAmount(newTrading.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : newTrading);
|
|
|
|
|
+ walletAgent.setUpdateBy(userId);
|
|
|
|
|
+ walletAgent.setUpdateTime(now);
|
|
|
|
|
+ baseMapper.updateById(walletAgent);
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentBalance update = new WalletAgentBalance();
|
|
|
|
|
+ update.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
|
|
|
|
|
+ update.setUpdateBy(userId);
|
|
|
|
|
+ update.setUpdateTime(now);
|
|
|
|
|
+ walletAgentBalanceMapper.update(update, Wrappers.lambdaQuery(WalletAgentBalance.class)
|
|
|
|
|
+ .eq(WalletAgentBalance::getOrderNo, record.getOrderNo())
|
|
|
|
|
+ .eq(WalletAgentBalance::getDelFlag, 0)
|
|
|
|
|
+ .eq(WalletAgentBalance::getTradeType, 2));
|
|
|
|
|
+
|
|
|
|
|
+ WalletAgentBalance balance = new WalletAgentBalance();
|
|
|
|
|
+ balance.setOrderNo(record.getOrderNo());
|
|
|
|
|
+ balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
|
|
|
|
|
+ balance.setAgtEntId(walletAgent.getAgtEntId());
|
|
|
|
|
+ balance.setSupEntId(walletAgent.getSupEntId());
|
|
|
|
|
+ balance.setTradeType(3);
|
|
|
|
|
+ balance.setTradeAmount(receivedCallbackDto.getTranAmt());
|
|
|
|
|
+ balance.setPreBalance(walletAgent.getPreBalance());
|
|
|
|
|
+ balance.setTradingAmount(walletAgent.getTradingAmount());
|
|
|
|
|
+ balance.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
|
|
|
|
|
+ balance.setRemark(record.getRemark());
|
|
|
|
|
+ balance.setCreateBy(userId);
|
|
|
|
|
+ balance.setCreateTime(now);
|
|
|
|
|
+ balance.setUpdateBy(userId);
|
|
|
|
|
+ balance.setUpdateTime(now);
|
|
|
|
|
+ balance.setDelFlag(0);
|
|
|
|
|
+ walletAgentBalanceMapper.insert(balance);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isProxyEnt() {
|
|
|
|
|
+ String entTypes = LoginEntHolder.get().getEntTypes();
|
|
|
|
|
+ return entTypes != null && entTypes.contains(String.valueOf(EntTypeEnum.PROXY.getCode()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String getAgentTradeTypeDesc(Integer tradeType) {
|
|
|
|
|
+ if (tradeType == null) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ return switch (tradeType) {
|
|
|
|
|
+ case 1 -> "消费";
|
|
|
|
|
+ case 2 -> "申请付款";
|
|
|
|
|
+ case 3 -> "付款成功";
|
|
|
|
|
+ case 4 -> "人工录入";
|
|
|
|
|
+ default -> "";
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Long> resolveAgentIds(Long curEntId, boolean proxy, Long tradeEntId, String tradeEntName) {
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgent> agentWrapper = Wrappers.lambdaQuery(WalletAgent.class)
|
|
|
|
|
+ .select(WalletAgent::getId)
|
|
|
|
|
+ .eq(WalletAgent::getDelFlag, 0)
|
|
|
|
|
+ .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
|
|
|
|
|
+
|
|
|
|
|
+ if (tradeEntId != null) {
|
|
|
|
|
+ agentWrapper.eq(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, tradeEntId);
|
|
|
|
|
+ } else if (StringUtils.hasText(tradeEntName)) {
|
|
|
|
|
+ List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(tradeEntName);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entCacheResDtos)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> ids = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
|
|
|
|
|
+ agentWrapper.in(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, ids);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<WalletAgent> agents = baseMapper.selectList(agentWrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(agents)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ return agents.stream().map(WalletAgent::getId).filter(Objects::nonNull).toList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getUid(Long entId) {
|
|
|
|
|
+ if (Objects.isNull(entId)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ KwpWallet kwpWallet = kwpWalletMapper.selectOne(Wrappers.lambdaQuery(KwpWallet.class)
|
|
|
|
|
+ .eq(KwpWallet::getEntId, entId)
|
|
|
|
|
+ .eq(KwpWallet::getStatus, 2)
|
|
|
|
|
+ .eq(KwpWallet::getDelFlag, 0)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (Objects.isNull(kwpWallet)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return kwpWallet.getUid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static LocalDateTime parseDateTime(String time) {
|
|
|
|
|
+ if (!StringUtils.hasText(time)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return LocalDateTime.parse(time, DATE_TIME_FORMATTER);
|
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Date toDate(LocalDateTime localDateTime) {
|
|
|
|
|
+ if (localDateTime == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BaseResult<List<WalletAgentRecordRes>> getPayList(Long agentId) {
|
|
|
|
|
+ if (agentId == null) {
|
|
|
|
|
+ return BaseResult.success(new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
|
|
+ WalletAgent walletAgent = baseMapper.selectById(agentId);
|
|
|
|
|
+ if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
|
|
|
|
|
+ return BaseResult.success(new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long curEntId = LoginEntHolder.getEntId();
|
|
|
|
|
+ if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
|
|
|
|
|
+ return BaseResult.failed("无权限查看该支付记录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<WalletAgentRecord> wrapper = Wrappers.lambdaQuery(WalletAgentRecord.class)
|
|
|
|
|
+ .eq(WalletAgentRecord::getDelFlag, 0)
|
|
|
|
|
+ .eq(WalletAgentRecord::getAgentId, agentId)
|
|
|
|
|
+ .orderByAsc(WalletAgentRecord::getStatus)
|
|
|
|
|
+ .orderByDesc(WalletAgentRecord::getCreateTime, WalletAgentRecord::getId);
|
|
|
|
|
+ List<WalletAgentRecord> list = walletAgentRecordMapper.selectList(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return BaseResult.success(new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean proxy = isProxyEnt();
|
|
|
|
|
+ Long tradeEntId = proxy ? walletAgent.getSupEntId() : walletAgent.getAgtEntId();
|
|
|
|
|
+ String tradeEntName = "";
|
|
|
|
|
+ if (tradeEntId != null) {
|
|
|
|
|
+ EntCacheResDto entCacheResDto = remoteSystemService.queryEntCacheById(tradeEntId);
|
|
|
|
|
+ tradeEntName = entCacheResDto == null ? "" : entCacheResDto.getFirmName();
|
|
|
|
|
+ }
|
|
|
|
|
+ String finalTradeEntName = tradeEntName;
|
|
|
|
|
+
|
|
|
|
|
+ List<WalletAgentRecordRes> resList = list.stream().map(e -> {
|
|
|
|
|
+ WalletAgentRecordRes res = new WalletAgentRecordRes();
|
|
|
|
|
+ BeanUtils.copyProperties(e, res);
|
|
|
|
|
+ PayStatusEnum statusEnum = PayStatusEnum.getByCode(e.getStatus());
|
|
|
|
|
+ res.setStatusDesc(statusEnum == null ? "" : statusEnum.getName());
|
|
|
|
|
+ res.setCreateTime(toDate(e.getCreateTime()));
|
|
|
|
|
+ res.setTradeEntId(tradeEntId);
|
|
|
|
|
+ res.setTradeEntName(finalTradeEntName);
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }).toList();
|
|
|
|
|
+
|
|
|
|
|
+ return BaseResult.success(resList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|