|
@@ -1,49 +1,14 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.function.BiPredicate;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.function.Function;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.redisson.api.RBucket;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.DigestUtils;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.SysConfig;
|
|
|
-import com.ym.mec.biz.dal.entity.SysPaymentConfig;
|
|
|
import com.ym.mec.biz.dal.entity.TenantConfig;
|
|
|
import com.ym.mec.biz.dal.entity.TenantOrderRecord;
|
|
|
import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
-import com.ym.mec.biz.service.CloudTeacherOrderService;
|
|
|
-import com.ym.mec.biz.service.OrderPayOpsService;
|
|
|
-import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
-import com.ym.mec.biz.service.SysConfigService;
|
|
|
-import com.ym.mec.biz.service.SysPaymentConfigService;
|
|
|
-import com.ym.mec.biz.service.TenantConfigService;
|
|
|
-import com.ym.mec.biz.service.TenantOrderRecordService;
|
|
|
-import com.ym.mec.biz.service.TenantPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.WrapperUtil;
|
|
|
import com.ym.mec.thirdparty.adapay.ConfigInit;
|
|
@@ -51,6 +16,24 @@ import com.ym.mec.thirdparty.adapay.Payment;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import com.ym.mec.util.json.JsonUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.BiPredicate;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
|
* @author hgw
|
|
@@ -78,7 +61,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
|
|
|
@Autowired
|
|
|
private SysConfigDao sysConfigDao;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysPaymentConfigService sysPaymentConfigService;
|
|
|
|
|
@@ -327,15 +310,15 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
paymentParams.put("pay_amt", payParam.getAmount().setScale(2, RoundingMode.HALF_UP));
|
|
|
paymentParams.put("goods_title", payParam.getOrderSubject());
|
|
|
paymentParams.put("goods_desc", payParam.getOrderBody());
|
|
|
-
|
|
|
+
|
|
|
TenantConfig tenantConfig = tenantConfigService.queryByTenantId(payParam.getTenantId());
|
|
|
if (tenantConfig == null) {
|
|
|
throw new BizException("机构[{}]信息找不到", payParam.getTenantId());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (clazz instanceof StudentPaymentOrder || clazz instanceof TenantPaymentOrder) {
|
|
|
-
|
|
|
- if (payParam.getTenantId() == 1) {
|
|
|
+
|
|
|
+ if (payParam.getTenantId() == 1) {
|
|
|
// 延时分账
|
|
|
paymentParams.put("pay_mode", "delay");
|
|
|
} else {
|
|
@@ -343,13 +326,13 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
Function<BigDecimal, BigDecimal> amountTo = (a) -> a
|
|
|
.multiply(tenantConfig.getChargeRate())
|
|
|
.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
- StudentPaymentOrder st = (StudentPaymentOrder) clazz;
|
|
|
- BigDecimal amount = amountTo.apply(st.getActualAmount()).setScale(2, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
- List<Map<String, Object>> divMemberList = new ArrayList<>();
|
|
|
+
|
|
|
+ StudentPaymentOrder st = (StudentPaymentOrder) clazz;
|
|
|
+ BigDecimal amount = amountTo.apply(st.getActualAmount()).setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ List<Map<String, Object>> divMemberList = new ArrayList<>();
|
|
|
// 实时分账
|
|
|
- if (amount.doubleValue() > 0) {
|
|
|
+ if (amount.doubleValue() > 0) {
|
|
|
|
|
|
/*SysConfig config = sysConfigService.findByParamName("platform_collection_organ");
|
|
|
if (Objects.isNull(config)) {
|
|
@@ -361,65 +344,72 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
if(sysPaymentConfig == null || StringUtils.isBlank(sysPaymentConfig.getHfMerNo())){
|
|
|
throw new BizException("分部[{}]没有设置收款账号", config.getParanValue());
|
|
|
}*/
|
|
|
-
|
|
|
- String platformAccount = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
|
|
|
-
|
|
|
- if(StringUtils.isBlank(platformAccount)){
|
|
|
- throw new BizException("平台收款账户查询失败");
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> divMember = new HashMap<>();
|
|
|
- divMember.put("member_id", platformAccount);
|
|
|
- divMember.put("amount", amount);
|
|
|
- divMember.put("fee_flag", "Y");
|
|
|
- divMemberList.add(divMember);
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> divMember1 = new HashMap<>();
|
|
|
- divMember1.put("member_id", st.getMerNos());
|
|
|
- divMember1.put("amount", payParam.getAmount().subtract(amount));
|
|
|
- if (divMemberList.size() > 0) {
|
|
|
- divMember1.put("fee_flag", "N");
|
|
|
- } else {
|
|
|
- divMember1.put("fee_flag", "Y");
|
|
|
- }
|
|
|
- divMemberList.add(divMember1);
|
|
|
-
|
|
|
- paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
+
|
|
|
+ String platformAccount = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(platformAccount)) {
|
|
|
+ throw new BizException("平台收款账户查询失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> divMember = new HashMap<>();
|
|
|
+ divMember.put("member_id", platformAccount);
|
|
|
+ divMember.put("amount", amount);
|
|
|
+ divMember.put("fee_flag", "Y");
|
|
|
+ divMemberList.add(divMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> divMember1 = new HashMap<>();
|
|
|
+ divMember1.put("member_id", st.getMerNos());
|
|
|
+ divMember1.put("amount", payParam.getAmount().subtract(amount));
|
|
|
+ if (divMemberList.size() > 0) {
|
|
|
+ divMember1.put("fee_flag", "N");
|
|
|
+ } else {
|
|
|
+ divMember1.put("fee_flag", "Y");
|
|
|
+ }
|
|
|
+ divMemberList.add(divMember1);
|
|
|
+
|
|
|
+ paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} else if (clazz instanceof TenantOrderRecord) {//向平台支付,不分账
|
|
|
- TenantOrderRecord tor = (TenantOrderRecord) clazz;
|
|
|
-
|
|
|
+ TenantOrderRecord tor = (TenantOrderRecord) clazz;
|
|
|
+
|
|
|
List<Map<String, Object>> divMemberList = new ArrayList<>();
|
|
|
- Map<String, Object> divMember = new HashMap<>();
|
|
|
- divMember.put("member_id", tor.getMerNos());
|
|
|
- divMember.put("amount", tor.getActualAmount());
|
|
|
- divMember.put("fee_flag", "Y");
|
|
|
- divMemberList.add(divMember);
|
|
|
+ Map<String, Object> divMember = new HashMap<>();
|
|
|
+ divMember.put("member_id", tor.getMerNos());
|
|
|
+ divMember.put("amount", tor.getActualAmount());
|
|
|
+ divMember.put("fee_flag", "Y");
|
|
|
+ divMemberList.add(divMember);
|
|
|
|
|
|
- paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
+ paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
} else {
|
|
|
- throw new BizException("订单[{}]找不到", payParam.getOrderNo());
|
|
|
- }
|
|
|
+ throw new BizException("订单[{}]找不到", payParam.getOrderNo());
|
|
|
+ }
|
|
|
|
|
|
//手续费收取模式:O-商户手续费账户扣取手续费,I-交易金额中扣取手续费;值为空时,默认值为I;若为O时,分账对象列表中不支持传入手续费承担方
|
|
|
//paymentParams.put("fee_mode", "I");
|
|
|
return paymentParams;
|
|
|
}
|
|
|
|
|
|
+ //检查次数
|
|
|
+ private static final int times = 50;
|
|
|
+ //检查间隔 毫秒
|
|
|
+ private static final long sleepTime = 3000L;
|
|
|
+ //锁的时间
|
|
|
+ private static final int lockTime = (int) (times * sleepTime / 1000 - 1);
|
|
|
+
|
|
|
+ //主动检查订单状态
|
|
|
private void delayCheckTenant() {
|
|
|
RBucket<Object> bucket = redissonClient.getBucket("delay_check_tenant");
|
|
|
- if (!bucket.trySet(1, 15L, TimeUnit.SECONDS)) {
|
|
|
+ if (!bucket.trySet(1, lockTime, TimeUnit.SECONDS)) {
|
|
|
return;
|
|
|
}
|
|
|
//异步
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
- //检查10次
|
|
|
- for (int i = 0; i <= 10; i++) {
|
|
|
+ for (int i = 0; i <= times; i++) {
|
|
|
try {
|
|
|
- Thread.sleep(3000);//每3秒触发一次
|
|
|
tenantOrderRecordService.checkTenantOrder();
|
|
|
+ Thread.sleep(sleepTime);//每3秒触发一次
|
|
|
log.info("delayCheckTenant >>>>> start {}", i);
|
|
|
} catch (InterruptedException e) {
|
|
|
log.error("delayCheckTenant >>>>", e.getCause());
|