fix:无人船
This commit is contained in:
+64
@@ -1,10 +1,13 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.enums.RefundState;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.service.ICtripDistOrderService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.IRefundService;
|
||||
@@ -17,13 +20,16 @@ import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import com.wechat.pay.java.service.refund.model.Status;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -47,6 +53,12 @@ public class WxPayController {
|
||||
@Value("${zlt.tenant.id}")
|
||||
private String defaultTenantId;
|
||||
|
||||
@Autowired
|
||||
private ICtripDistOrderService ctripDistOrderService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/pay/notify")
|
||||
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
||||
@RequestHeader("Wechatpay-Timestamp") String timestamp,
|
||||
@@ -149,6 +161,32 @@ public class WxPayController {
|
||||
order.setPayTime(new Date());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
// === 携程分销订单创建 ===
|
||||
if (Integer.valueOf(1).equals(qrCode.getEnableCtripOrder())) {
|
||||
log.info("二维码已开启携程分销,异步创建携程订单,orderNo: {}, ctripProductId: {}",
|
||||
order.getOrderNo(), qrCode.getCtripProductId());
|
||||
try {
|
||||
//获取用户手机号
|
||||
String mobile = null;
|
||||
if(Objects.nonNull(order.getUserId())){
|
||||
SysUser sysUser = userService.findUserById(order.getUserId());
|
||||
if(Objects.nonNull(sysUser)&& StringUtil.isNotEmpty(sysUser.getMobile())){
|
||||
mobile=sysUser.getMobile();
|
||||
}
|
||||
}
|
||||
|
||||
ctripDistOrderService.createCtripDistOrder(
|
||||
order.getOrderNo(),
|
||||
order.getOrderAmount(),
|
||||
qrCode.getCtripProductId(),
|
||||
order.getTenantId(),
|
||||
mobile
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("异步创建携程分销订单失败,orderNo: {},不影响本地订单", order.getOrderNo(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -185,6 +223,32 @@ public class WxPayController {
|
||||
order.setPayTime(new Date());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
// === 携程分销订单创建 ===
|
||||
if (Integer.valueOf(1).equals(qrCode.getEnableCtripOrder())) {
|
||||
log.info("二维码已开启携程分销,异步创建携程订单,orderNo: {}, ctripProductId: {}",
|
||||
order.getOrderNo(), qrCode.getCtripProductId());
|
||||
try {
|
||||
//获取用户手机号
|
||||
String mobile = null;
|
||||
if(Objects.nonNull(order.getUserId())){
|
||||
SysUser sysUser = userService.findUserById(order.getUserId());
|
||||
if(Objects.nonNull(sysUser)&& StringUtil.isNotEmpty(sysUser.getMobile())){
|
||||
mobile=sysUser.getMobile();
|
||||
}
|
||||
}
|
||||
|
||||
ctripDistOrderService.createCtripDistOrder(
|
||||
order.getOrderNo(),
|
||||
order.getOrderAmount(),
|
||||
qrCode.getCtripProductId(),
|
||||
order.getTenantId(),
|
||||
mobile
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("异步创建携程分销订单失败,orderNo: {},不影响本地订单", order.getOrderNo(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.central.order.feign;
|
||||
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.fallback.CouponCenterServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.COUPON_SERVICE, fallbackFactory = CouponCenterServiceFallbackFactory.class, dismiss404 = true)
|
||||
public interface CouponCenterService {
|
||||
|
||||
/**
|
||||
* 创建携程分销订单
|
||||
*/
|
||||
@PostMapping("/ctrip/dist/order/create")
|
||||
Result<String> createCtripDistOrder(@RequestBody Map<String, Object> params);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.order.feign.fallback;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.CouponCenterService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CouponCenterServiceFallbackFactory implements FallbackFactory<CouponCenterService> {
|
||||
|
||||
@Override
|
||||
public CouponCenterService create(Throwable cause) {
|
||||
return new CouponCenterService() {
|
||||
@Override
|
||||
public Result<String> createCtripDistOrder(Map<String, Object> params) {
|
||||
log.error("调用coupon-center创建携程分销订单失败,params: {}", params, cause);
|
||||
return Result.failed("调用coupon-center失败: " + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -94,16 +94,17 @@ public class MissionController {
|
||||
return createResult;
|
||||
}
|
||||
|
||||
// 一键起飞任务:创建后自动执行
|
||||
if (MissionType.isTakeoffTask(missionType)) {
|
||||
// 一键起飞任务 / 无人船航线任务:创建后自动执行
|
||||
if (MissionType.isTakeoffTask(missionType) || MissionType.isBoatRouteTask(missionType)) {
|
||||
boolean dispatched = missionService.dispatchMissionToDevice(mission);
|
||||
if (!dispatched) {
|
||||
log.warn("一键起飞任务创建成功但下发失败: {}", mission.getMissionCode());
|
||||
log.warn("任务创建成功但下发失败: {}", mission.getMissionCode());
|
||||
return Result.failed("任务创建成功但执行失败,请重试");
|
||||
}
|
||||
return Result.succeed(mission, "一键起飞任务已执行");
|
||||
String msg = MissionType.isTakeoffTask(missionType) ? "一键起飞任务已执行" : "无人船航线任务已执行";
|
||||
return Result.succeed(mission, msg);
|
||||
}
|
||||
// 航线任务:只创建,不自动执行
|
||||
// 无人机航线任务:只创建,不自动执行
|
||||
return Result.succeed(mission, "任务创建成功,请确认执行");
|
||||
} catch (Exception e) {
|
||||
log.error("创建任务异常", e);
|
||||
|
||||
@@ -120,4 +120,16 @@ public class QrCode extends SuperEntity {
|
||||
@Schema(description = "描述")
|
||||
private String qrDescribe;
|
||||
|
||||
/**
|
||||
* 是否创建携程订单(0:否,1:是)
|
||||
*/
|
||||
@Schema(description = "是否创建携程订单(0:否,1:是)")
|
||||
private Integer enableCtripOrder;
|
||||
|
||||
/**
|
||||
* 携程产品ID
|
||||
*/
|
||||
@Schema(description = "携程产品ID")
|
||||
private Long ctripProductId;
|
||||
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.central.order.service;
|
||||
|
||||
/**
|
||||
* 携程分销订单异步调用服务
|
||||
*/
|
||||
public interface ICtripDistOrderService {
|
||||
/**
|
||||
* 异步创建携程分销订单
|
||||
*
|
||||
* @param orderNo 本地订单号
|
||||
* @param orderAmount 订单金额(分)
|
||||
* @param ctripProductId 携程产品ID
|
||||
* @param tenantId 租户ID
|
||||
* @param mobile 用户手机号(可为null,为null时使用默认值)
|
||||
*/
|
||||
void createCtripDistOrder(String orderNo, String orderAmount, Long ctripProductId, String tenantId, String mobile);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.CouponCenterService;
|
||||
import com.central.order.service.ICtripDistOrderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripDistOrderServiceImpl implements ICtripDistOrderService {
|
||||
|
||||
@Autowired
|
||||
private CouponCenterService couponCenterService;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void createCtripDistOrder(String orderNo, String orderAmount,
|
||||
Long ctripProductId, String tenantId, String mobile) {
|
||||
log.info("开始异步创建携程分销订单,orderNo: {}, mobile: {}", orderNo, mobile);
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("orderNo", orderNo);
|
||||
params.put("orderAmount", orderAmount);
|
||||
params.put("ctripProductId", ctripProductId);
|
||||
params.put("tenantId", tenantId);
|
||||
params.put("mobile", mobile);
|
||||
|
||||
Result<String> result = couponCenterService.createCtripDistOrder(params);
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("携程分销订单创建成功,orderNo: {}", orderNo);
|
||||
} else {
|
||||
log.error("携程分销订单创建失败,orderNo: {}, result: {}", orderNo, result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("携程分销订单创建异常,orderNo: {}", orderNo, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
-- 二维码表添加携程分销相关字段
|
||||
-- 用途:标识该二维码是否需要在支付成功后自动创建携程分销订单
|
||||
ALTER TABLE qrcodes
|
||||
ADD COLUMN enable_ctrip_order TINYINT(1) DEFAULT 0 COMMENT '是否创建携程订单(0:否,1:是)',
|
||||
ADD COLUMN ctrip_product_id BIGINT DEFAULT NULL COMMENT '携程产品ID';
|
||||
|
||||
CREATE INDEX idx_qrcodes_enable_ctrip ON qrcodes(enable_ctrip_order);
|
||||
Reference in New Issue
Block a user