4 Commits

  1. 1
      src/main/java/com/example/demo/controller/cash/BankController.java
  2. 4
      src/main/java/com/example/demo/mapper/cash/CashCollectionMapper.java
  3. 2
      src/main/java/com/example/demo/service/cash/BankService.java
  4. 106
      src/main/java/com/example/demo/serviceImpl/cash/BankServiceImpl.java
  5. 10
      src/main/resources/cashMapper/CashCollectionMapper.xml

1
src/main/java/com/example/demo/controller/cash/BankController.java

@ -114,4 +114,5 @@ public class BankController {
return Result.error(e.getMessage());
}
}
}

4
src/main/java/com/example/demo/mapper/cash/CashCollectionMapper.java

@ -79,5 +79,7 @@ public interface CashCollectionMapper {
void updateByGoldCoinOrderCodeByFirstdata(FirstdataDTO firstdataDTO);
void updateByGoldCoinOrderCodeByIpay88(Ipay88DTO ipay88DTO);
List<String> selectFirstdataList();
List<CashCollection> selectIpayList();
List<CashCollection> selectIpayList();
List<String> selectStripeList();
List<String> selectPaymentList();
}

2
src/main/java/com/example/demo/service/cash/BankService.java

@ -36,4 +36,6 @@ public interface BankService {
//firstdata银行接口(批量)
Result ipayAuto(BankDTO bankDTO);
//bank银行接口(批量)
Result bankAuto();
}

106
src/main/java/com/example/demo/serviceImpl/cash/BankServiceImpl.java

@ -18,6 +18,7 @@ import com.stripe.param.ChargeListParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -159,8 +160,6 @@ public class BankServiceImpl implements BankService {
}
}
//payment银行接口(批量)
@Override
public Result paymentAuto(BankDTO bankDTO) {
try {
// 1. 准备参数
@ -202,6 +201,12 @@ public class BankServiceImpl implements BankService {
JSONObject jsonObject = JSON.parseObject(responseBody);
JSONArray transactions = jsonObject.getJSONObject("payload").getJSONArray("transactions");
// 添加非空校验
if (transactions == null || transactions.isEmpty()) {
log.warn("transactions为空或无数据");
return Result.error("payment当天无数据请切换日期");
}
// 创建BankVO并设置paymentDTOList
BankVO bankVO = new BankVO();
List<PaymentDTO> paymentDTOList;
@ -232,15 +237,15 @@ public class BankServiceImpl implements BankService {
// 获取订单号
String orderNo = paymentDTO.getMerchant_reference();
// 查询金币系统中的订单
CashCollection cashCollection = cashCollectionMapper.selectByGoldCoinOrderCode(orderNo);
if (cashCollection != null) {
// 更新金币系统中的订单信息
List<String> orderNoList = cashCollectionMapper.selectPaymentList();
// 检查当前订单号是否在列表中
if (orderNoList.contains(orderNo)) {
cashCollectionMapper.updateByGoldCoinOrderCodeByPayment(paymentDTO);
processedPayments.add(paymentDTO);
log.info("成功处理订单: {}", orderNo);
messages.add("成功处理订单: " + orderNo);
} else {
}
else {
log.warn("金币系统中未找到订单: {}", orderNo);
messages.add("金币系统中未找到订单: " + orderNo);
}
@ -265,6 +270,7 @@ public class BankServiceImpl implements BankService {
}
}
//stripe银行接口(批量)
@Override
public Result stripeAuto(BankDTO bankDTO) {
@ -365,10 +371,12 @@ public class BankServiceImpl implements BankService {
// 添加到列表中
stripeDTOList.add(stripeDTO);
// 如果订单号存在则更新数据库中的记录
// 如果订单号存在且在selectStripeList返回的列表中则更新数据库中的记录
if (stripeDTO.getOrderNo() != null && !stripeDTO.getOrderNo().isEmpty()) {
CashCollection cashCollection = cashCollectionMapper.selectByGoldCoinOrderCode(stripeDTO.getOrderNo());
if (cashCollection != null) {
// 获取需要处理的订单号列表
List<String> orderNoList = cashCollectionMapper.selectStripeList();
// 检查当前订单号是否在列表中
if (orderNoList.contains(stripeDTO.getOrderNo())) {
cashCollectionMapper.updateByGoldCoinOrderCodeByStripe(stripeDTO);
}
}
@ -714,6 +722,81 @@ public class BankServiceImpl implements BankService {
return Result.success(bankVO);
}
// 银行自动处理接口(每天早上6点执行)
@Scheduled(cron = "0 0 6 * * ?")
@Override
public Result bankAuto() {
try {
// 生成昨天的日期格式为yyyyMMdd
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate sevenDayAgo = LocalDate.now().minusDays(7);
String sevenDayAgoStr = sevenDayAgo.format(formatter);
LocalDate sixDayAgo = LocalDate.now().minusDays(6);
String sixDayAgoStr = sixDayAgo.format(formatter);
LocalDate fiveDayAgo = LocalDate.now().minusDays(5);
String fiveDayAgoStr = fiveDayAgo.format(formatter);
LocalDate fourDayAgo = LocalDate.now().minusDays(4);
String fourDayAgoStr = fourDayAgo.format(formatter);
LocalDate threeDayAgo = LocalDate.now().minusDays(3);
String threeDayAgoStr = threeDayAgo.format(formatter);
LocalDate twoDayAgo = LocalDate.now().minusDays(2);
String twoDayAgoStr = twoDayAgo.format(formatter);
LocalDate oneDayAgo = LocalDate.now().minusDays(1);
String oneDayAgoStr = oneDayAgo.format(formatter);
LocalDate today = LocalDate.now();
String todayStr = today.format(formatter);
// 创建BankDTO实例并设置时间
BankDTO dto = new BankDTO();
dto.setStartTime(fiveDayAgoStr);
dto.setEndTime(todayStr);
dto.setSum(1000);
// 依次调用各个自动处理方法
dto.setTime(oneDayAgoStr);
Result paymentOneDayResult = paymentAuto(dto);
dto.setTime(twoDayAgoStr);
Result paymentTwoDayResult = paymentAuto(dto);
dto.setTime(threeDayAgoStr);
Result paymentThreeDayResult = paymentAuto(dto);
dto.setTime(fourDayAgoStr);
Result paymentFourDayResult = paymentAuto(dto);
dto.setTime(fiveDayAgoStr);
Result paymentFiveDayResult = paymentAuto(dto);
dto.setTime(sixDayAgoStr);
Result paymentSixDayResult = paymentAuto(dto);
dto.setTime(sevenDayAgoStr);
Result paymentSevenDayResult = paymentAuto(dto);
Result stripeResult = stripeAuto(dto);
Result firstdataResult = firstdataAuto(dto);
Result ipayResult = ipayAuto(dto);
// 创建响应VO对象并收集处理结果
BankVO bankVO = new BankVO();
List<String> messages = new ArrayList<>();
// 收集各方法的处理结果信息
messages.add("Payment One Day Auto Result: " + (paymentOneDayResult != null ? paymentOneDayResult.toString() : "null"));
messages.add("Payment Two Day Auto Result: " + (paymentTwoDayResult != null ? paymentTwoDayResult.toString() : "null"));
messages.add("Payment Three Day Auto Result: " + (paymentThreeDayResult != null ? paymentThreeDayResult.toString() : "null"));
messages.add("Payment Four Day Auto Result: " + (paymentFourDayResult != null ? paymentFourDayResult.toString() : "null"));
messages.add("Payment Five Day Auto Result: " + (paymentFiveDayResult != null ? paymentFiveDayResult.toString() : "null"));
messages.add("Payment Six Day Auto Result: " + (paymentSixDayResult != null ? paymentSixDayResult.toString() : "null"));
messages.add("Payment Seven Day Auto Result: " + (paymentSevenDayResult != null ? paymentSevenDayResult.toString() : "null"));
messages.add("Stripe Auto Result: " + (stripeResult != null ? stripeResult.toString() : "null"));
messages.add("Firstdata Auto Result: " + (firstdataResult != null ? firstdataResult.toString() : "null"));
messages.add("Ipay Auto Result: " + (ipayResult != null ? ipayResult.toString() : "null"));
bankVO.setMessage(messages);
return Result.success(bankVO);
} catch (Exception e) {
log.error("bankAuto执行失败", e);
return Result.error("bankAuto执行失败: " + e.getMessage());
}
}
/**
* 生成PaymentAsia API所需的签名
*
@ -786,4 +869,7 @@ public class BankServiceImpl implements BankService {
}
return hexStr.toString();
}
}

10
src/main/resources/cashMapper/CashCollectionMapper.xml

@ -311,6 +311,12 @@
<select id="selectFirstdataList" resultType="java.lang.String">
select bank_code from cash_record_collection where bank_code is not null and payload='FirstData' and order_no_status=1
</select>
<select id="selectStripeList" resultType="java.lang.String">
select order_code from cash_record_collection where payload='Stripe' and order_no_status=1
</select>
<select id="selectPaymentList" resultType="java.lang.String">
select order_code from cash_record_collection where payload='PaymentAsia' and order_no_status=1
</select>
<select id="selectIpayList" resultType="com.example.demo.domain.vo.cash.CashCollection">
select order_code,permanent_gold from cash_record_collection where payload='Ipay88' and order_no_status=1
</select>
@ -324,6 +330,7 @@
payment_amount=#{order_amount},
received_amount=#{net_amount},
handling_charge=#{charge},
status=4,
order_no_status=0
where order_code=#{merchant_reference}
</update>
@ -337,6 +344,7 @@
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderNo}
</update>
@ -348,6 +356,7 @@
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderId}
</update>
@ -359,6 +368,7 @@
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderNo}
</update>
Loading…
Cancel
Save