Merge branch 'dev' into feature-business-minigram

This commit is contained in:
Lemon
2026-05-07 16:08:03 +08:00
18 changed files with 414 additions and 26 deletions

View File

@@ -41,11 +41,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -1104,6 +1101,7 @@ public class TempController extends BaseController {
@PostMapping("/batchUpdateOrderReviewByDatePoor")
public RestApiResponse<?> batchUpdateOrderReviewByDatePoor(@RequestBody UpdateOrderReviewDTO dto) {
logger.info("批量更新订单评价, param:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
// 根据传来的开始日期、结束日期按天划分为批次,对每个批次进行批量更新
@@ -1114,7 +1112,8 @@ public class TempController extends BaseController {
// 将startTime、endTime转换成localDateTime
LocalDateTime localStartTime = LocalDateTime.parse(date + "T00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));;
LocalDateTime localEndTime = LocalDateTime.parse(date + "T23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));;
int i = orderBasicInfoService.updateOrderReviewFlagTemp(localStartTime, localEndTime, null);
int i = orderBasicInfoService.updateOrderReviewFlagTemp(localStartTime, localEndTime, dto.getStationId(), dto.getRatio());
logger.info("批量更新订单评价, 批次:{}, 影响行数:{}", date, i);
}
response = new RestApiResponse<>();
} catch (Exception e) {

View File

@@ -9,7 +9,7 @@ spring:
# redis 配置
redis:
# 地址
host: 106.14.94.149
host: 192.168.0.8
# 端口默认为6379
port: 6379
# 数据库索引
@@ -38,9 +38,9 @@ spring:
master:
# url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: jsowell_pre
url: jdbc:mysql://192.168.0.32:3306/jsowell_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: jsowell_dev
password: 123456
url: jdbc:mysql://192.168.0.8:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: jsowell_prd
password: dev@js160829
# 从库数据源
slave:
# 从数据源开关/默认关闭
@@ -273,9 +273,9 @@ dubbo:
registry:
address: nacos://106.14.94.149:8848
parameters:
namespace: 200784c9-7e8f-4b2b-a44f-1eb52e675491
namespace: e328faaf-8516-42d0-817a-7406232b3581
username: nacos
password: 3rtJPEb0KaUs5NAm
password: 79HMu!6nlOiLm^Q[
protocol:
name: dubbo
port: -1

View File

@@ -48,7 +48,7 @@ spring:
# 数据库索引
database: 0
# 密码
password: 123456
password: js160829
# 连接超时时间
timeout: 10s
lettuce:

View File

@@ -8,12 +8,18 @@ import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.huifu.adapay.model.PaymentReverse;
import com.huifu.adapay.model.Refund;
import com.jsowell.adapay.common.AdaPayment;
import com.jsowell.JsowellApplication;
import com.jsowell.adapay.common.DivMember;
import com.jsowell.adapay.common.PaymentConfirmInfo;
import com.jsowell.adapay.common.RefundInfo;
import com.jsowell.adapay.config.AbstractAdapayConfig;
import com.jsowell.adapay.dto.PaymentConfirmParam;
import com.jsowell.adapay.dto.QueryConfirmReverseDTO;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.factory.AdapayConfigFactory;
import com.jsowell.adapay.operation.PaymentReverseOperation;
import com.jsowell.adapay.response.ConfirmReverseResponse;
import com.jsowell.adapay.response.PaymentConfirmResponse;
import com.jsowell.adapay.response.PaymentReverseResponse;
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
@@ -24,10 +30,12 @@ import com.jsowell.api.uniapp.customer.TempController;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.AdapayUnsplitRecord;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.OrderDetail;
@@ -60,7 +68,7 @@ import java.util.concurrent.TimeUnit;
/**
* 专用处理汇付支付相关
*/
@ActiveProfiles("dev")
@ActiveProfiles("sit")
@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class PaymentTestController {
@@ -940,4 +948,197 @@ public class PaymentTestController {
logger.info("{}", JSON.toJSONString(paymentConfirmInfo));
}
@Test
public void queryPaymentAllInfoTest() throws BaseAdaPayException {
String paymentId = System.getProperty("paymentId");
if (StringUtils.isBlank(paymentId)) {
throw new IllegalArgumentException("请通过 -DpaymentId=支付ID 传入 paymentId");
}
JSONObject result = queryPaymentAllInfo(paymentId);
logger.info("paymentId:{}, result:{}", paymentId, JSON.toJSONString(result));
}
public JSONObject queryPaymentAllInfo(String paymentId) throws BaseAdaPayException {
if (StringUtils.isBlank(paymentId)) {
throw new IllegalArgumentException("paymentId不能为空");
}
PaymentQueryContext context = queryPaymentContext(paymentId);
if (context == null) {
throw new IllegalArgumentException("未匹配到支付单paymentId:" + paymentId);
}
QueryPaymentConfirmDTO queryPaymentConfirmDTO = new QueryPaymentConfirmDTO();
queryPaymentConfirmDTO.setWechatAppId(context.getWechatAppId());
queryPaymentConfirmDTO.setPaymentId(paymentId);
QueryPaymentConfirmDetailResponse confirmResponse = adapayService.queryPaymentConfirmList(queryPaymentConfirmDTO);
List<PaymentConfirmInfo> paymentConfirms = confirmResponse == null || CollectionUtils.isEmpty(confirmResponse.getPaymentConfirms())
? Lists.newArrayList()
: paymentResponseToList(confirmResponse.getPaymentConfirms());
List<PaymentReverseResponse> paymentReverses = adapayService.queryPaymentReverse(paymentId, context.getWechatAppId());
if (paymentReverses == null) {
paymentReverses = Lists.newArrayList();
}
List<RefundInfo> refunds = adapayService.queryPaymentRefund(paymentId, context.getWechatAppId());
if (refunds == null) {
refunds = Lists.newArrayList();
}
AdaPayment payment = context.getPayment();
BigDecimal payAmount = safeAmount(payment.getPay_amt());
BigDecimal apiConfirmedAmount = safeAmount(payment.getConfirmed_amt());
BigDecimal apiRefundedAmount = safeAmount(payment.getRefunded_amt());
BigDecimal apiReservedAmount = safeAmount(payment.getReserved_amt());
BigDecimal successConfirmedAmount = sumConfirmedAmount(paymentConfirms, context.getWechatAppId());
BigDecimal successRefundAmount = sumRefundAmount(refunds);
BigDecimal successReverseAmount = sumReverseAmount(paymentReverses);
BigDecimal alreadySplitAmount = apiConfirmedAmount.compareTo(BigDecimal.ZERO) > 0
? apiConfirmedAmount
: successConfirmedAmount;
BigDecimal alreadyRefundAmount;
if (StringUtils.equals("delay", payment.getPay_mode())) {
alreadyRefundAmount = successReverseAmount.compareTo(BigDecimal.ZERO) > 0
? successReverseAmount
: apiReservedAmount;
} else {
alreadyRefundAmount = successRefundAmount.compareTo(BigDecimal.ZERO) > 0
? successRefundAmount
: apiRefundedAmount;
}
BigDecimal unsplitAmount = payAmount.subtract(alreadySplitAmount).subtract(alreadyRefundAmount);
if (unsplitAmount.compareTo(BigDecimal.ZERO) < 0) {
unsplitAmount = BigDecimal.ZERO;
}
JSONObject summary = new JSONObject();
summary.put("payMode", payment.getPay_mode());
summary.put("payAmount", AdapayUtil.formatAmount(payAmount));
summary.put("apiConfirmedAmount", AdapayUtil.formatAmount(apiConfirmedAmount));
summary.put("apiRefundedAmount", AdapayUtil.formatAmount(apiRefundedAmount));
summary.put("apiReservedAmount", AdapayUtil.formatAmount(apiReservedAmount));
summary.put("successConfirmedAmount", AdapayUtil.formatAmount(successConfirmedAmount));
summary.put("successRefundAmount", AdapayUtil.formatAmount(successRefundAmount));
summary.put("successReverseAmount", AdapayUtil.formatAmount(successReverseAmount));
summary.put("alreadySplitAmount", AdapayUtil.formatAmount(alreadySplitAmount));
summary.put("alreadyRefundAmount", AdapayUtil.formatAmount(alreadyRefundAmount));
summary.put("unsplitAmount", AdapayUtil.formatAmount(unsplitAmount));
JSONObject result = new JSONObject();
result.put("paymentId", paymentId);
result.put("wechatAppId", context.getWechatAppId());
result.put("adapayAppId", context.getAdapayAppId());
result.put("payment", payment);
result.put("paymentRaw", JSON.parseObject(JSON.toJSONString(payment)));
result.put("paymentConfirms", paymentConfirms);
result.put("paymentReverses", paymentReverses);
result.put("refunds", refunds);
result.put("summary", summary);
return result;
}
private PaymentQueryContext queryPaymentContext(String paymentId) throws BaseAdaPayException {
List<AbstractAdapayConfig> configList = AdapayConfigFactory.getAllConfig();
if (CollectionUtils.isEmpty(configList)) {
throw new IllegalStateException("未加载到汇付商户配置");
}
for (AbstractAdapayConfig config : configList) {
AdaPayment payment = adapayService.queryPaymentDetailWithFallback(paymentId, config.getWechatAppId());
if (payment != null) {
return new PaymentQueryContext(config.getWechatAppId(), config.getAdapayAppId(), payment);
}
}
return null;
}
private BigDecimal sumConfirmedAmount(List<PaymentConfirmInfo> paymentConfirms, String wechatAppId) throws BaseAdaPayException {
BigDecimal totalAmount = BigDecimal.ZERO;
if (CollectionUtils.isEmpty(paymentConfirms)) {
return totalAmount;
}
for (PaymentConfirmInfo paymentConfirm : paymentConfirms) {
if (isConfirmReversed(paymentConfirm, wechatAppId)) {
continue;
}
totalAmount = totalAmount.add(safeAmount(paymentConfirm.getConfirmedAmt()));
}
return totalAmount;
}
private boolean isConfirmReversed(PaymentConfirmInfo paymentConfirm, String wechatAppId) throws BaseAdaPayException {
QueryConfirmReverseDTO queryConfirmReverseDTO = QueryConfirmReverseDTO.builder()
.wechatAppId(wechatAppId)
.paymentConfirmId(paymentConfirm.getId())
.build();
ConfirmReverseResponse confirmReverseResponse = adapayService.queryConfirmReverse(queryConfirmReverseDTO);
return confirmReverseResponse != null && confirmReverseResponse.isSuccess();
}
private BigDecimal sumRefundAmount(List<RefundInfo> refunds) {
BigDecimal totalAmount = BigDecimal.ZERO;
if (CollectionUtils.isEmpty(refunds)) {
return totalAmount;
}
for (RefundInfo refund : refunds) {
if (!StringUtils.equals("S", refund.getTrans_status())) {
continue;
}
totalAmount = totalAmount.add(safeAmount(refund.getRefund_amt()));
}
return totalAmount;
}
private BigDecimal sumReverseAmount(List<PaymentReverseResponse> paymentReverses) {
BigDecimal totalAmount = BigDecimal.ZERO;
if (CollectionUtils.isEmpty(paymentReverses)) {
return totalAmount;
}
for (PaymentReverseResponse paymentReverseResponse : paymentReverses) {
if (!StringUtils.equals(AdapayStatusEnum.SUCCEEDED.getValue(), paymentReverseResponse.getStatus())) {
continue;
}
totalAmount = totalAmount.add(safeAmount(paymentReverseResponse.getReverse_amt()));
}
return totalAmount;
}
private BigDecimal safeAmount(String amount) {
if (StringUtils.isBlank(amount)) {
return BigDecimal.ZERO;
}
return new BigDecimal(amount);
}
private List<PaymentConfirmInfo> paymentResponseToList(List<PaymentConfirmInfo> paymentConfirms) {
return Lists.newArrayList(paymentConfirms);
}
private static class PaymentQueryContext {
private final String wechatAppId;
private final String adapayAppId;
private final AdaPayment payment;
private PaymentQueryContext(String wechatAppId, String adapayAppId, AdaPayment payment) {
this.wechatAppId = wechatAppId;
this.adapayAppId = adapayAppId;
this.payment = payment;
}
private String getWechatAppId() {
return wechatAppId;
}
private String getAdapayAppId() {
return adapayAppId;
}
private AdaPayment getPayment() {
return payment;
}
}
}