fix(优惠券中心):新增携程优惠券独立微服务模块
This commit is contained in:
-1895
File diff suppressed because it is too large
Load Diff
+41
-17
@@ -741,14 +741,27 @@ public class OrderController {
|
||||
.filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
List<Map<String,String>> videoList = new ArrayList<>();
|
||||
for (OrderFile orderFile : videoFiles){
|
||||
for (int i = 0; i < videoFiles.size(); i++){
|
||||
OrderFile orderFile = videoFiles.get(i);
|
||||
Map<String,String> videoMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
videoMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
|
||||
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
String thumbnailUrl = null;
|
||||
if (!imgList.isEmpty()) {
|
||||
if (i < imgList.size()) {
|
||||
// 使用对应索引的图片作为缩略图
|
||||
thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
} else {
|
||||
// 如果视频数量超过图片数量,使用最后一张图片作为缩略图
|
||||
thumbnailUrl = imgList.get(imgList.size() - 1).get("viewUrl");
|
||||
}
|
||||
}
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
orderFileMap.put("videoList", videoList);
|
||||
@@ -877,14 +890,18 @@ public class OrderController {
|
||||
for (String filePath : allFilePaths) {
|
||||
String url = fileCenterService.getViewUrlByPath(filePath);
|
||||
fileUrlMap.put(filePath, url.replace(cdnOssUrl, cdnUrl));
|
||||
|
||||
// 预计算样式URL(仅对图片文件)
|
||||
if (filePath.contains("image/jpeg") || filePath.contains("image/")) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("path", filePath);
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
fileStyleUrlMap.put(filePath, styleUrl);
|
||||
}
|
||||
|
||||
// 预计算样式URL(仅对图片文件)
|
||||
for (List<OrderFile> files : orderFilesMap.values()) {
|
||||
for (OrderFile file : files) {
|
||||
if ("image/jpeg".equals(file.getFileType()) || "image/jpg".equals(file.getFileType()) || "image/png".equals(file.getFileType())) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("path", file.getFilePath());
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
fileStyleUrlMap.put(file.getFilePath(), styleUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,12 +932,16 @@ public class OrderController {
|
||||
.filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
.toList();
|
||||
List<Map<String,String>> imgList = new ArrayList<>();
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
for (OrderFile orderFile : imgFiles){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
imgMap.put("url", fileUrlMap.get(orderFile.getFilePath()));
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
imgMap.put("path", orderFile.getFilePath());
|
||||
imgMap.put("viewUrl", fileStyleUrlMap.get(orderFile.getFilePath()));
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
String viewUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
|
||||
imgMap.put("viewUrl", viewUrl);
|
||||
imgList.add(imgMap);
|
||||
}
|
||||
orderFileMap.put("imgList", imgList);
|
||||
@@ -937,13 +958,16 @@ public class OrderController {
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
|
||||
// 视频缩略图使用对应索引的图片缩略图
|
||||
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
String thumbnailUrl = null;
|
||||
if (!imgList.isEmpty() && i < imgList.size()) {
|
||||
String thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
} else {
|
||||
videoMap.put("viewUrl", null);
|
||||
// 使用对应索引的图片作为缩略图
|
||||
thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
} else if (!imgList.isEmpty()) {
|
||||
// 如果视频数量超过图片数量,使用第一张图片作为缩略图
|
||||
thumbnailUrl = imgList.get(0).get("viewUrl");
|
||||
}
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
package com.central.order.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 优惠券实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_coupon")
|
||||
public class Coupon implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券编号
|
||||
*/
|
||||
private String couponNo;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-满减券,2-折扣券,3-免费券
|
||||
*/
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 优惠券面额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 使用门槛金额
|
||||
*/
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/**
|
||||
* 折扣率(0-100,折扣券时使用)
|
||||
*/
|
||||
private Integer discountRate;
|
||||
|
||||
/**
|
||||
* 优惠券状态:0-未使用,1-已使用,2-已过期,3-已作废
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 用户手机号
|
||||
*/
|
||||
private String userPhone;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 来源:1-携程,2-高飞自建
|
||||
*/
|
||||
private Integer source;
|
||||
|
||||
/**
|
||||
* 携程优惠券ID(来源为携程时使用)
|
||||
*/
|
||||
private String ctripCouponId;
|
||||
|
||||
/**
|
||||
* 有效期开始时间
|
||||
*/
|
||||
private Date validStartTime;
|
||||
|
||||
/**
|
||||
* 有效期结束时间
|
||||
*/
|
||||
private Date validEndTime;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private Date usedTime;
|
||||
|
||||
/**
|
||||
* 使用订单号
|
||||
*/
|
||||
private String usedOrderNo;
|
||||
|
||||
/**
|
||||
* 退券时间
|
||||
*/
|
||||
private Date cancelTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.central.order.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.order.entity.Coupon;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponMapper extends BaseMapper<Coupon> {
|
||||
|
||||
/**
|
||||
* 分页查询优惠券列表
|
||||
*/
|
||||
IPage<Coupon> selectCouponPage(Page<Coupon> page, @Param("coupon") Coupon coupon);
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户优惠券
|
||||
*/
|
||||
List<Coupon> selectByUserPhone(@Param("userPhone") String userPhone);
|
||||
|
||||
/**
|
||||
* 根据手机号查询可用优惠券
|
||||
*/
|
||||
List<Coupon> selectAvailableByUserPhone(@Param("userPhone") String userPhone);
|
||||
|
||||
/**
|
||||
* 根据携程优惠券ID查询
|
||||
*/
|
||||
Coupon selectByCtripCouponId(@Param("ctripCouponId") String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 根据订单号查询使用的优惠券
|
||||
*/
|
||||
Coupon selectByUsedOrderNo(@Param("usedOrderNo") String usedOrderNo);
|
||||
|
||||
/**
|
||||
* 更新优惠券状态为已使用
|
||||
*/
|
||||
int updateCouponUsed(@Param("id") Long id, @Param("usedOrderNo") String usedOrderNo);
|
||||
|
||||
/**
|
||||
* 批量更新过期优惠券状态
|
||||
*/
|
||||
int updateExpiredCoupons();
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程核销通知请求
|
||||
*/
|
||||
@Data
|
||||
public class CtripConsumedNoticeRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
private CtripConsumedNoticeHeader header;
|
||||
|
||||
/**
|
||||
* 请求体
|
||||
*/
|
||||
private CtripConsumedNoticeBody body;
|
||||
|
||||
/**
|
||||
* 携程核销通知请求头
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeHeader {
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private String requestTime;
|
||||
|
||||
/**
|
||||
* 账户ID
|
||||
*/
|
||||
private String accountId;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程核销通知请求体
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeBody {
|
||||
/**
|
||||
* OTA订单ID
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单ID
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 核销时间
|
||||
*/
|
||||
private String consumedTime;
|
||||
|
||||
/**
|
||||
* 核销地点
|
||||
*/
|
||||
private String consumedLocation;
|
||||
|
||||
/**
|
||||
* 核销人
|
||||
*/
|
||||
private String consumedBy;
|
||||
|
||||
/**
|
||||
* 核销备注
|
||||
*/
|
||||
private String consumedRemark;
|
||||
}
|
||||
}
|
||||
-87
@@ -1,87 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程核销通知响应
|
||||
*/
|
||||
@Data
|
||||
public class CtripConsumedNoticeResponse {
|
||||
|
||||
/**
|
||||
* 响应头
|
||||
*/
|
||||
private CtripConsumedNoticeResponseHeader header;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 响应消息
|
||||
*/
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 响应体
|
||||
*/
|
||||
private CtripConsumedNoticeResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程核销通知响应头
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeResponseHeader {
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private String requestTime;
|
||||
|
||||
/**
|
||||
* 账户ID
|
||||
*/
|
||||
private String accountId;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程核销通知响应体
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeResponseBody {
|
||||
/**
|
||||
* OTA订单ID
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单ID
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 处理结果
|
||||
*/
|
||||
private String processResult;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
private String processTime;
|
||||
}
|
||||
}
|
||||
-190
@@ -1,190 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订请求
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body; // 改为Object类型,支持字符串和对象两种格式
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId;
|
||||
@JsonProperty("items")
|
||||
private List<CtripOrderItem> items;
|
||||
@JsonProperty("contacts")
|
||||
private List<CtripContact> contacts;
|
||||
@JsonProperty("confirmType")
|
||||
private Integer confirmType;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderItem {
|
||||
@JsonProperty("passengers")
|
||||
private List<CtripPassenger> passengers;
|
||||
@JsonProperty("cost")
|
||||
private java.math.BigDecimal cost;
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity;
|
||||
@JsonProperty("salePrice")
|
||||
private java.math.BigDecimal salePrice;
|
||||
@JsonProperty("remark")
|
||||
private String remark;
|
||||
@JsonProperty("useEndDate")
|
||||
private String useEndDate;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
@JsonProperty("useStartDate")
|
||||
private String useStartDate;
|
||||
@JsonProperty("priceCurrency")
|
||||
private String priceCurrency;
|
||||
@JsonProperty("adjunctions")
|
||||
private List<String> adjunctions;
|
||||
@JsonProperty("price")
|
||||
private java.math.BigDecimal price;
|
||||
@JsonProperty("PLU")
|
||||
private String PLU;
|
||||
@JsonProperty("deposit")
|
||||
private Object deposit; // 改回Object类型,因为可能是对象
|
||||
@JsonProperty("distributionChannel")
|
||||
private String distributionChannel;
|
||||
@JsonProperty("costCurrency")
|
||||
private String costCurrency;
|
||||
@JsonProperty("salePriceCurrency")
|
||||
private String salePriceCurrency;
|
||||
@JsonProperty("expressDelivery")
|
||||
private CtripExpressDelivery expressDelivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程乘客信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripPassenger {
|
||||
@JsonProperty("cardIssuePlace")
|
||||
private String cardIssuePlace;
|
||||
@JsonProperty("lastName")
|
||||
private String lastName;
|
||||
@JsonProperty("cardIssueCountry")
|
||||
private String cardIssueCountry;
|
||||
@JsonProperty("shoeSize")
|
||||
private Integer shoeSize;
|
||||
@JsonProperty("gender")
|
||||
private String gender;
|
||||
@JsonProperty("cardIssueDate")
|
||||
private String cardIssueDate;
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("nationalityName")
|
||||
private String nationalityName;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("cardType")
|
||||
private String cardType;
|
||||
@JsonProperty("weight")
|
||||
private Integer weight;
|
||||
@JsonProperty("myopiaDegreeL")
|
||||
private Integer myopiaDegreeL;
|
||||
@JsonProperty("birthDate")
|
||||
private String birthDate;
|
||||
@JsonProperty("cardNo")
|
||||
private String cardNo;
|
||||
@JsonProperty("ageType")
|
||||
private String ageType;
|
||||
@JsonProperty("myopiaDegreeR")
|
||||
private Integer myopiaDegreeR;
|
||||
@JsonProperty("firstName")
|
||||
private String firstName;
|
||||
@JsonProperty("birthPlace")
|
||||
private String birthPlace;
|
||||
@JsonProperty("nationalityCode")
|
||||
private String nationalityCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId;
|
||||
@JsonProperty("cardValidDate")
|
||||
private String cardValidDate;
|
||||
@JsonProperty("height")
|
||||
private Integer height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程联系人信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripContact {
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("optionalMobile")
|
||||
private String optionalMobile;
|
||||
@JsonProperty("optionalIntlCode")
|
||||
private String optionalIntlCode;
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程快递信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripExpressDelivery {
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订响应
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId;
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType;
|
||||
@JsonProperty("voucherSender")
|
||||
private Integer voucherSender;
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers;
|
||||
@JsonProperty("orderExtendMessage")
|
||||
private String orderExtendMessage;
|
||||
@JsonProperty("items")
|
||||
private List<CtripResponseOrderItem> items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("voucherType")
|
||||
private Integer voucherType;
|
||||
@JsonProperty("voucherContent")
|
||||
private String voucherContent;
|
||||
@JsonProperty("voucherUrl")
|
||||
private String voucherUrl;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId;
|
||||
@JsonProperty("supplierItemId")
|
||||
private String supplierItemId;
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
@Schema(description = "首页统计数据VO")
|
||||
public class DashboardStatisticsVO {
|
||||
@Schema(description = "订单统计")
|
||||
private OrderStatistics orderStats;
|
||||
private OrderStatisticsVO orderStats;
|
||||
|
||||
@Schema(description = "图表统计")
|
||||
private ChartStatistics chartStats;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Schema(description = "订单统计")
|
||||
public class OrderStatistics {
|
||||
public class OrderStatisticsVO {
|
||||
@Schema(description = "总订单数")
|
||||
private Long totalOrders;
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.central.order.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.common.model.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券服务接口
|
||||
*/
|
||||
public interface ICouponService extends IService<Coupon> {
|
||||
|
||||
/**
|
||||
* 分页查询优惠券列表
|
||||
*/
|
||||
IPage<Coupon> getCouponPage(Page<Coupon> page, Coupon coupon);
|
||||
|
||||
/**
|
||||
* 查询优惠券列表(统一风格)
|
||||
*/
|
||||
PageResult<Coupon> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
boolean createCoupon(Coupon coupon);
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
*/
|
||||
boolean updateCoupon(Coupon coupon);
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
*/
|
||||
boolean deleteCoupon(Long id);
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户优惠券
|
||||
*/
|
||||
List<Coupon> getCouponsByUserPhone(String userPhone);
|
||||
|
||||
/**
|
||||
* 根据手机号查询可用优惠券
|
||||
*/
|
||||
List<Coupon> getAvailableCouponsByUserPhone(String userPhone);
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
*/
|
||||
boolean useCoupon(Long couponId, String orderNo);
|
||||
|
||||
/**
|
||||
* 根据携程优惠券ID创建优惠券(携程接口调用)
|
||||
*/
|
||||
boolean createCouponFromCtrip(String ctripCouponId, String userPhone, String couponName,
|
||||
Integer couponType, java.math.BigDecimal amount,
|
||||
java.math.BigDecimal minAmount, Integer discountRate,
|
||||
java.util.Date validStartTime,
|
||||
java.util.Date validEndTime);
|
||||
|
||||
/**
|
||||
* 批量更新过期优惠券状态
|
||||
*/
|
||||
void updateExpiredCoupons();
|
||||
|
||||
/**
|
||||
* 核销携程优惠券
|
||||
*/
|
||||
boolean verifyCtripCoupon(String ctripCouponId, String orderNo);
|
||||
|
||||
/**
|
||||
* 校验手机号+携程券ID是否已存在
|
||||
*/
|
||||
boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 根据携程优惠券ID查询优惠券
|
||||
*/
|
||||
Coupon getByCtripCouponId(String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 更新优惠券为已核销状态
|
||||
*/
|
||||
boolean updateCouponConsumed(Long couponId, String orderNo, String consumedTime);
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.central.order.service;
|
||||
|
||||
/**
|
||||
* 携程API服务接口
|
||||
*/
|
||||
public interface ICtripApiService {
|
||||
|
||||
/**
|
||||
* 核销携程优惠券
|
||||
* @param ctripCouponId 携程优惠券ID
|
||||
* @param orderNo 订单号
|
||||
* @return 是否核销成功
|
||||
*/
|
||||
boolean verifyCoupon(String ctripCouponId, String orderNo);
|
||||
|
||||
/**
|
||||
* 查询携程优惠券状态
|
||||
* @param ctripCouponId 携程优惠券ID
|
||||
* @return 优惠券状态
|
||||
*/
|
||||
String getCouponStatus(String ctripCouponId);
|
||||
}
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.central.order.service;
|
||||
|
||||
import com.central.order.model.vo.DashboardStatisticsVO;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.model.Order;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -15,5 +16,5 @@ public interface IDashboardService {
|
||||
/**
|
||||
* 获取首页订单列表
|
||||
*/
|
||||
PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params);
|
||||
PageResult<Order> getDashboardOrders(Map<String, Object> params);
|
||||
}
|
||||
|
||||
-301
@@ -1,301 +0,0 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.order.mapper.CouponMapper;
|
||||
import com.central.order.service.ICouponService;
|
||||
import com.central.order.service.ICtripApiService;
|
||||
import com.central.common.model.PageResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 优惠券服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {
|
||||
|
||||
@Autowired
|
||||
private ICtripApiService ctripApiService;
|
||||
|
||||
@Override
|
||||
public IPage<Coupon> getCouponPage(Page<Coupon> page, Coupon coupon) {
|
||||
return baseMapper.selectCouponPage(page, coupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Coupon> findList(Map<String, Object> params) {
|
||||
// 获取分页参数
|
||||
Integer page = Integer.parseInt(params.getOrDefault("page", "1").toString());
|
||||
Integer limit = Integer.parseInt(params.getOrDefault("limit", "10").toString());
|
||||
|
||||
// 构建查询条件
|
||||
Coupon queryCoupon = new Coupon();
|
||||
if (params.get("couponName") != null) {
|
||||
queryCoupon.setCouponName(params.get("couponName").toString());
|
||||
}
|
||||
if (params.get("couponType") != null) {
|
||||
queryCoupon.setCouponType(Integer.parseInt(params.get("couponType").toString()));
|
||||
}
|
||||
if (params.get("status") != null) {
|
||||
queryCoupon.setStatus(Integer.parseInt(params.get("status").toString()));
|
||||
}
|
||||
if (params.get("userPhone") != null) {
|
||||
queryCoupon.setUserPhone(params.get("userPhone").toString());
|
||||
}
|
||||
if (params.get("source") != null) {
|
||||
queryCoupon.setSource(Integer.parseInt(params.get("source").toString()));
|
||||
}
|
||||
if (params.get("ctripCouponId") != null) {
|
||||
queryCoupon.setCtripCouponId(params.get("ctripCouponId").toString());
|
||||
}
|
||||
|
||||
// 执行分页查询
|
||||
Page<Coupon> pageParam = new Page<>(page, limit);
|
||||
IPage<Coupon> pageResult = baseMapper.selectCouponPage(pageParam, queryCoupon);
|
||||
|
||||
// 构建返回结果
|
||||
return PageResult.<Coupon>builder()
|
||||
.count(pageResult.getTotal())
|
||||
.resp_code(0)
|
||||
.data(pageResult.getRecords())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createCoupon(Coupon coupon) {
|
||||
// 生成优惠券编号
|
||||
if (!StringUtils.hasText(coupon.getCouponNo())) {
|
||||
coupon.setCouponNo(generateCouponNo());
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if (coupon.getStatus() == null) {
|
||||
coupon.setStatus(0); // 未使用
|
||||
}
|
||||
if (coupon.getCreateTime() == null) {
|
||||
coupon.setCreateTime(new Date());
|
||||
}
|
||||
if (coupon.getUpdateTime() == null) {
|
||||
coupon.setUpdateTime(new Date());
|
||||
}
|
||||
|
||||
return save(coupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateCoupon(Coupon coupon) {
|
||||
coupon.setUpdateTime(new Date());
|
||||
return updateById(coupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteCoupon(Long id) {
|
||||
return removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Coupon> getCouponsByUserPhone(String userPhone) {
|
||||
return baseMapper.selectByUserPhone(userPhone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Coupon> getAvailableCouponsByUserPhone(String userPhone) {
|
||||
return baseMapper.selectAvailableByUserPhone(userPhone);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean useCoupon(Long couponId, String orderNo) {
|
||||
Coupon coupon = getById(couponId);
|
||||
if (coupon == null) {
|
||||
log.error("优惠券不存在,couponId: {}", couponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (coupon.getStatus() != 0) {
|
||||
log.error("优惠券状态不正确,couponId: {}, status: {}", couponId, coupon.getStatus());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (coupon.getValidEndTime().before(new Date())) {
|
||||
log.error("优惠券已过期,couponId: {}", couponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return baseMapper.updateCouponUsed(couponId, orderNo) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createCouponFromCtrip(String ctripCouponId, String userPhone, String couponName,
|
||||
Integer couponType, java.math.BigDecimal amount,
|
||||
java.math.BigDecimal minAmount, Integer discountRate,
|
||||
java.util.Date validStartTime,
|
||||
java.util.Date validEndTime) {
|
||||
|
||||
log.info("开始创建携程优惠券 - ctripCouponId: {}, userPhone: {}, couponName: {}, amount: {}, minAmount: {}",
|
||||
ctripCouponId, userPhone, couponName, amount, minAmount);
|
||||
|
||||
// 检查是否已存在该携程优惠券
|
||||
Coupon existingCoupon = baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||
if (existingCoupon != null) {
|
||||
log.warn("携程优惠券已存在,ctripCouponId: {}, 优惠券ID: {}", ctripCouponId, existingCoupon.getId());
|
||||
return true; // 已存在也算成功
|
||||
}
|
||||
|
||||
log.info("携程优惠券不存在,开始创建新优惠券");
|
||||
|
||||
Coupon coupon = new Coupon();
|
||||
coupon.setCouponNo(generateCouponNo());
|
||||
coupon.setCouponName(couponName);
|
||||
coupon.setCouponType(couponType);
|
||||
coupon.setAmount(amount);
|
||||
coupon.setMinAmount(minAmount);
|
||||
coupon.setDiscountRate(discountRate);
|
||||
coupon.setStatus(0); // 未使用
|
||||
coupon.setUserPhone(userPhone);
|
||||
coupon.setSource(1); // 来源:携程
|
||||
coupon.setCtripCouponId(ctripCouponId);
|
||||
coupon.setValidStartTime(validStartTime);
|
||||
coupon.setValidEndTime(validEndTime);
|
||||
coupon.setCreateTime(new Date());
|
||||
coupon.setUpdateTime(new Date());
|
||||
coupon.setCreateBy("ctrip");
|
||||
coupon.setUpdateBy("ctrip");
|
||||
|
||||
log.info("优惠券对象创建完成,准备保存到数据库 - couponNo: {}", coupon.getCouponNo());
|
||||
|
||||
boolean saveResult = save(coupon);
|
||||
|
||||
if (saveResult) {
|
||||
log.info("携程优惠券保存成功 - 优惠券ID: {}, couponNo: {}, ctripCouponId: {}",
|
||||
coupon.getId(), coupon.getCouponNo(), ctripCouponId);
|
||||
} else {
|
||||
log.error("携程优惠券保存失败 - ctripCouponId: {}, userPhone: {}", ctripCouponId, userPhone);
|
||||
}
|
||||
|
||||
return saveResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateExpiredCoupons() {
|
||||
int count = baseMapper.updateExpiredCoupons();
|
||||
log.info("批量更新过期优惠券完成,更新数量: {}", count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean verifyCtripCoupon(String ctripCouponId, String orderNo) {
|
||||
Coupon coupon = baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||
if (coupon == null) {
|
||||
log.error("携程优惠券不存在,ctripCouponId: {}", ctripCouponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (coupon.getStatus() != 0) {
|
||||
log.error("携程优惠券状态不正确,ctripCouponId: {}, status: {}", ctripCouponId, coupon.getStatus());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (coupon.getValidEndTime().before(new Date())) {
|
||||
log.error("携程优惠券已过期,ctripCouponId: {}", ctripCouponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 调用携程核销接口
|
||||
boolean ctripVerifyResult = ctripApiService.verifyCoupon(ctripCouponId, orderNo);
|
||||
if (!ctripVerifyResult) {
|
||||
log.error("携程核销失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新本地优惠券状态
|
||||
return baseMapper.updateCouponUsed(coupon.getId(), orderNo) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId) {
|
||||
return lambdaQuery()
|
||||
.eq(Coupon::getUserPhone, userPhone)
|
||||
.eq(Coupon::getCtripCouponId, ctripCouponId)
|
||||
.count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成优惠券编号
|
||||
*/
|
||||
private String generateCouponNo() {
|
||||
return "CP" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coupon getByCtripCouponId(String ctripCouponId) {
|
||||
return baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateCouponConsumed(Long couponId, String orderNo, String consumedTime) {
|
||||
try {
|
||||
Coupon coupon = getById(couponId);
|
||||
if (coupon == null) {
|
||||
log.error("优惠券不存在,couponId: {}", couponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新优惠券状态
|
||||
coupon.setStatus(1); // 已使用
|
||||
coupon.setUsedOrderNo(orderNo);
|
||||
coupon.setUsedTime(parseDate(consumedTime));
|
||||
coupon.setUpdateTime(new Date());
|
||||
coupon.setUpdateBy("ctrip-consumed");
|
||||
|
||||
boolean result = updateById(coupon);
|
||||
if (result) {
|
||||
log.info("优惠券核销成功,couponId: {}, orderNo: {}, consumedTime: {}",
|
||||
couponId, orderNo, consumedTime);
|
||||
} else {
|
||||
log.error("优惠券核销失败,couponId: {}", couponId);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("更新优惠券核销状态失败,couponId: {}", couponId, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析日期字符串
|
||||
*/
|
||||
private Date parseDate(String dateStr) {
|
||||
try {
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
|
||||
} catch (Exception ex) {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.order.service.ICtripApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程API服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripApiServiceImpl implements ICtripApiService {
|
||||
|
||||
@Override
|
||||
public boolean verifyCoupon(String ctripCouponId, String orderNo) {
|
||||
log.info("调用携程核销接口,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
|
||||
try {
|
||||
// 根据携程API文档实现核销接口调用
|
||||
// 这里需要根据实际的携程API接口进行实现
|
||||
|
||||
// 1. 构建请求参数
|
||||
Map<String, Object> requestParams = new HashMap<>();
|
||||
requestParams.put("ctripCouponId", ctripCouponId);
|
||||
requestParams.put("orderNo", orderNo);
|
||||
requestParams.put("verifyTime", new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));
|
||||
|
||||
// 2. 添加签名验证(如果需要)
|
||||
// String sign = generateSign(requestParams);
|
||||
// requestParams.put("sign", sign);
|
||||
|
||||
// 3. 调用携程核销API
|
||||
// 这里应该使用HttpClient或其他HTTP客户端调用携程的核销接口
|
||||
// 例如:
|
||||
// String url = "https://api.ctrip.com/coupon/verify";
|
||||
// String response = httpClient.post(url, requestParams);
|
||||
|
||||
// 4. 解析响应结果
|
||||
// JSONObject responseJson = JSON.parseObject(response);
|
||||
// boolean success = responseJson.getBoolean("success");
|
||||
// String message = responseJson.getString("message");
|
||||
|
||||
// 暂时模拟成功响应
|
||||
log.info("携程核销接口调用成功,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("携程核销接口调用失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCouponStatus(String ctripCouponId) {
|
||||
// TODO: 实现具体的携程API调用逻辑
|
||||
// 这里需要根据携程的API文档实现具体的调用
|
||||
log.info("调用携程查询优惠券状态接口,ctripCouponId: {}", ctripCouponId);
|
||||
|
||||
// 模拟API调用
|
||||
try {
|
||||
// 这里应该调用携程的查询API
|
||||
// 例如:HttpClient调用携程的查询接口
|
||||
|
||||
// 暂时返回"VALID",实际需要根据API调用结果返回
|
||||
return "VALID";
|
||||
} catch (Exception e) {
|
||||
log.error("携程查询优惠券状态接口调用失败", e);
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-83
@@ -1,22 +1,20 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mapper.DashboardMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.vo.*;
|
||||
import com.central.order.service.IDashboardService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -48,84 +46,26 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params) {
|
||||
public PageResult<Order> getDashboardOrders(Map<String, Object> params) {
|
||||
try {
|
||||
// 获取分页参数
|
||||
Integer page = (Integer) params.getOrDefault("page", 1);
|
||||
Integer limit = (Integer) params.getOrDefault("limit", 10);
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<Order>()
|
||||
.orderByDesc(Order::getCreateTime);
|
||||
|
||||
// 如果有时间筛选条件,添加时间范围
|
||||
if (params.get("startTime") != null && !params.get("startTime").toString().isEmpty()) {
|
||||
wrapper.ge(Order::getCreateTime, params.get("startTime"));
|
||||
}
|
||||
if (params.get("endTime") != null && !params.get("endTime").toString().isEmpty()) {
|
||||
wrapper.le(Order::getCreateTime, params.get("endTime"));
|
||||
}
|
||||
|
||||
// 添加其他筛选条件
|
||||
if (params.get("tourismId") != null) {
|
||||
wrapper.eq(Order::getTourismId, params.get("tourismId"));
|
||||
}
|
||||
if (params.get("qrcodeId") != null && !params.get("qrcodeId").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getCodeId, params.get("qrcodeId"));
|
||||
}
|
||||
if (params.get("deviceSn") != null && !params.get("deviceSn").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getDeviceSn, params.get("deviceSn"));
|
||||
}
|
||||
|
||||
// 执行分页查询
|
||||
Page<Order> pageParam = new Page<>(page, limit);
|
||||
Page<Order> resultPage = orderService.page(pageParam, wrapper);
|
||||
// 获取订单列表
|
||||
PageResult<Order> result = orderService.findList(params);
|
||||
|
||||
// 添加调试日志
|
||||
log.info("获取订单列表 - 参数: {}, 结果数量: {}", params, resultPage.getRecords().size());
|
||||
if (!resultPage.getRecords().isEmpty()) {
|
||||
Order firstOrder = resultPage.getRecords().get(0);
|
||||
log.info("第一个订单数据 - orderNo: {}, userId: {}, orderAmount: {}",
|
||||
firstOrder.getOrderNo(), firstOrder.getUserId(), firstOrder.getOrderAmount());
|
||||
}
|
||||
log.info("获取仪表盘订单列表 - 参数: {}, 结果数量: {}", params, result.getCount());
|
||||
|
||||
// 转换为PageResult
|
||||
return PageResult.<Order>builder()
|
||||
.data(resultPage.getRecords())
|
||||
.resp_code(0)
|
||||
.count(resultPage.getTotal())
|
||||
.build();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("获取首页订单列表失败", e);
|
||||
return PageResult.<Order>builder()
|
||||
.data(new ArrayList<>())
|
||||
.resp_code(0)
|
||||
.count(0L)
|
||||
.build();
|
||||
log.error("获取仪表盘订单列表失败", e);
|
||||
return new PageResult<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单统计(包含对账数据)
|
||||
*
|
||||
* 订单状态说明:
|
||||
* - 有效订单:order_status IN (1, 3, 4, 5, 7, 8, 9)
|
||||
* - 1: 已支付排队中
|
||||
* - 3: 设备执行完成
|
||||
* - 4: 正在服务中
|
||||
* - 5: 素材上传中
|
||||
* - 7: 退款中
|
||||
* - 8: 已退款
|
||||
* - 9: 退款失败(算作有效订单)
|
||||
*
|
||||
* - 收款订单:order_status IN (1, 3, 4, 5, 7)
|
||||
* - 已支付但未退款的订单
|
||||
*
|
||||
* - 退款订单:order_status = 8
|
||||
* - 已成功退款的订单
|
||||
* 获取订单统计
|
||||
*/
|
||||
private OrderStatistics getOrderStatistics(Map<String, Object> params) {
|
||||
OrderStatistics stats = new OrderStatistics();
|
||||
private OrderStatisticsVO getOrderStatistics(Map<String, Object> params) {
|
||||
OrderStatisticsVO stats = new OrderStatisticsVO();
|
||||
|
||||
// 获取订单总数
|
||||
stats.setTotalOrders(dashboardMapper.getTotalOrders(params));
|
||||
@@ -167,8 +107,6 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
|
||||
// 添加调试日志
|
||||
log.info("今日收款订单数统计 - 参数: {}, 结果: {}", params, todayPaidOrders);
|
||||
log.info("时间范围参数 - startTime: {}, endTime: {}", params.get("startTime"), params.get("endTime"));
|
||||
log.info("hasTimeRange判断: {}", (params.get("startTime") != null && params.get("endTime") != null));
|
||||
|
||||
// 获取退款订单数量
|
||||
Long refundedOrders = dashboardMapper.getRefundedOrders(params);
|
||||
@@ -178,16 +116,16 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
Long todayRefundedOrders = dashboardMapper.getTodayRefundedOrders(params);
|
||||
stats.setTodayRefundedOrders(todayRefundedOrders);
|
||||
|
||||
// 获取对账相关数据 - 使用 orders 表的数据
|
||||
// 获取订单总金额
|
||||
Long totalAmount = dashboardMapper.getTotalAmount(params);
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
|
||||
// 设置基础数据
|
||||
stats.setTotalAmount(totalAmount);
|
||||
|
||||
// 获取退款金额
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
stats.setRefundAmount(refundAmount);
|
||||
|
||||
// 计算净收入 = 总金额 - 退款金额
|
||||
Long netIncome = (totalAmount != null ? totalAmount : 0) - (refundAmount != null ? refundAmount : 0);
|
||||
|
||||
// 计算净收入
|
||||
Long netIncome = (totalAmount != null ? totalAmount : 0L) - (refundAmount != null ? refundAmount : 0L);
|
||||
stats.setNetIncome(netIncome);
|
||||
|
||||
return stats;
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.central.order.task;
|
||||
|
||||
import com.central.order.service.ICouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 优惠券过期定时任务
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CouponExpirationTask {
|
||||
|
||||
@Autowired
|
||||
private ICouponService couponService;
|
||||
|
||||
/**
|
||||
* 每天凌晨2点执行,批量更新过期优惠券状态
|
||||
*/
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void updateExpiredCoupons() {
|
||||
log.info("开始执行优惠券过期状态更新任务");
|
||||
try {
|
||||
couponService.updateExpiredCoupons();
|
||||
log.info("优惠券过期状态更新任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("优惠券过期状态更新任务执行失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
package com.central.order.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 携程API解密工具类
|
||||
* 实现AES-128-CBC解密和MD5签名验证
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CtripDecryptUtil {
|
||||
|
||||
@Value("${ctrip.aes.key:}")
|
||||
private String aesKey;
|
||||
|
||||
@Value("${ctrip.sign.key:}")
|
||||
private String signKey;
|
||||
|
||||
@Value("${ctrip.aes.iv:}")
|
||||
private String aesIv;
|
||||
|
||||
/**
|
||||
* AES-128-CBC解密(携程标准)
|
||||
*
|
||||
* @param encryptedData 携程自定义编码的加密数据
|
||||
* @return 解密后的原始数据
|
||||
*/
|
||||
public String decryptAES(String encryptedData) {
|
||||
try {
|
||||
if (encryptedData == null || encryptedData.isEmpty()) {
|
||||
log.warn("加密数据为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.debug("开始解密携程数据,数据长度: {}", encryptedData.length());
|
||||
|
||||
// 使用携程自定义解码方法
|
||||
byte[] encryptedBytes = decodeBytes(encryptedData);
|
||||
log.debug("自定义解码成功,数据长度: {}", encryptedBytes.length);
|
||||
|
||||
// 检查数据长度
|
||||
if (encryptedBytes.length < 16) {
|
||||
log.error("加密数据长度不足,无法提取IV");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 提取IV(前16字节)
|
||||
byte[] iv = Arrays.copyOfRange(encryptedBytes, 0, 16);
|
||||
byte[] cipherData = Arrays.copyOfRange(encryptedBytes, 16, encryptedBytes.length);
|
||||
|
||||
log.debug("提取IV成功,IV长度: {}, 密文长度: {}", iv.length, cipherData.length);
|
||||
|
||||
// 使用UTF-8字节作为密钥和IV(携程标准)
|
||||
byte[] keyBytes = aesKey.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ivBytes = aesIv.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
log.debug("密钥长度: {}, IV长度: {}", keyBytes.length, ivBytes.length);
|
||||
|
||||
// 创建AES密钥
|
||||
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
||||
|
||||
// 创建解密器
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec);
|
||||
|
||||
// 解密
|
||||
byte[] decryptedBytes = cipher.doFinal(cipherData);
|
||||
String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
|
||||
|
||||
log.info("AES解密成功,解密后数据长度: {}", decryptedData.length());
|
||||
|
||||
// 清理解密后的数据,移除可能的头部乱码
|
||||
String cleanedData = cleanDecryptedData(decryptedData);
|
||||
log.debug("清理后数据长度: {}", cleanedData.length());
|
||||
|
||||
return cleanedData;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("AES解密失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理解密后的数据,移除头部乱码
|
||||
*/
|
||||
private String cleanDecryptedData(String decryptedData) {
|
||||
if (decryptedData == null || decryptedData.isEmpty()) {
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
log.info("原始解密数据前100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(0, 100) : decryptedData);
|
||||
log.info("原始解密数据后100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(decryptedData.length() - 100) : decryptedData);
|
||||
|
||||
// 查找第一个 '{' 字符(JSON对象开始)
|
||||
int startIndex = decryptedData.indexOf('{');
|
||||
if (startIndex == -1) {
|
||||
// 如果没有找到 '{',查找第一个 '"' 字符
|
||||
startIndex = decryptedData.indexOf('"');
|
||||
}
|
||||
|
||||
if (startIndex == -1) {
|
||||
// 如果都没有找到,查找第一个字母或数字
|
||||
for (int i = 0; i < decryptedData.length(); i++) {
|
||||
char c = decryptedData.charAt(i);
|
||||
if (Character.isLetterOrDigit(c)) {
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (startIndex > 0) {
|
||||
String cleanedData = decryptedData.substring(startIndex);
|
||||
log.info("移除头部乱码,从位置 {} 开始,清理后数据前100个字符: {}",
|
||||
startIndex, cleanedData.length() > 100 ? cleanedData.substring(0, 100) : cleanedData);
|
||||
return cleanedData;
|
||||
}
|
||||
|
||||
log.info("无需清理,数据前100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(0, 100) : decryptedData);
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程自定义解码方法(转字节数组)
|
||||
*
|
||||
* @param str 编码字符串
|
||||
* @return 字节数组
|
||||
*/
|
||||
private byte[] decodeBytes(String str) {
|
||||
byte[] bytes = new byte[str.length() / 2];
|
||||
for (int i = 0; i < str.length(); i += 2) {
|
||||
char c = str.charAt(i);
|
||||
bytes[i / 2] = (byte) ((c - 'a') << 4);
|
||||
c = str.charAt(i + 1);
|
||||
bytes[i / 2] += (c - 'a');
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程自定义编码方法(转16进制)
|
||||
*
|
||||
* @param bytes 字节数组
|
||||
* @return 编码字符串
|
||||
*/
|
||||
private String encodeBytes(byte[] bytes) {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
|
||||
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
|
||||
}
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证MD5签名(携程标准)
|
||||
*
|
||||
* @param accountId 账号ID
|
||||
* @param serviceName 服务名称
|
||||
* @param requestTime 请求时间
|
||||
* @param body 请求体
|
||||
* @param version 版本
|
||||
* @param sign 签名
|
||||
* @return 验证结果
|
||||
*/
|
||||
public boolean verifySign(String accountId, String serviceName, String requestTime, String body, String version, String sign) {
|
||||
try {
|
||||
// 按携程标准拼接参数:accountId+serviceName+requestTime+body+version+signkey
|
||||
String signContent = accountId + serviceName + requestTime + body + version + signKey;
|
||||
log.debug("签名内容: {}", signContent);
|
||||
|
||||
// 计算MD5并转小写
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 转换为小写十六进制
|
||||
StringBuilder calculatedSign = new StringBuilder();
|
||||
for (byte b : md5Bytes) {
|
||||
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
|
||||
String calculatedSignStr = calculatedSign.toString();
|
||||
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||
|
||||
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证MD5签名(兼容旧版本)
|
||||
*
|
||||
* @param params 请求参数
|
||||
* @param sign 签名
|
||||
* @return 验证结果
|
||||
*/
|
||||
public boolean verifySign(Map<String, String> params, String sign) {
|
||||
try {
|
||||
// 按字典序排序参数
|
||||
TreeMap<String, String> sortedParams = new TreeMap<>(params);
|
||||
|
||||
// 构建签名字符串
|
||||
StringBuilder signStr = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
|
||||
if (entry.getValue() != null && !entry.getValue().isEmpty()) {
|
||||
signStr.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
}
|
||||
|
||||
// 添加签名密钥
|
||||
signStr.append("key=").append(signKey);
|
||||
|
||||
String signContent = signStr.toString();
|
||||
log.debug("签名内容: {}", signContent);
|
||||
|
||||
// 计算MD5
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 转换为小写十六进制
|
||||
StringBuilder calculatedSign = new StringBuilder();
|
||||
for (byte b : md5Bytes) {
|
||||
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
|
||||
String calculatedSignStr = calculatedSign.toString();
|
||||
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||
|
||||
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密携程请求体
|
||||
*
|
||||
* @param encryptedBody 加密的请求体
|
||||
* @return 解密后的JSON字符串
|
||||
*/
|
||||
public String decryptCtripBody(String encryptedBody) {
|
||||
if (encryptedBody == null || encryptedBody.isEmpty()) {
|
||||
log.warn("请求体为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("开始解密携程请求体,数据长度: {}", encryptedBody.length());
|
||||
|
||||
// 尝试AES解密
|
||||
String decryptedData = decryptAES(encryptedBody);
|
||||
if (decryptedData != null) {
|
||||
log.info("携程请求体解密成功");
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
log.error("携程请求体解密失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查配置是否完整
|
||||
*/
|
||||
public boolean isConfigValid() {
|
||||
boolean valid = true;
|
||||
|
||||
if (aesKey == null || aesKey.isEmpty()) {
|
||||
log.error("携程AES密钥未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (signKey == null || signKey.isEmpty()) {
|
||||
log.error("携程签名密钥未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (aesIv == null || aesIv.isEmpty()) {
|
||||
log.error("携程AES IV未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息(脱敏)
|
||||
*/
|
||||
public String getConfigInfo() {
|
||||
return String.format("AES密钥长度: %d, 签名密钥长度: %d, IV长度: %d",
|
||||
aesKey != null ? aesKey.length() : 0,
|
||||
signKey != null ? signKey.length() : 0,
|
||||
aesIv != null ? aesIv.length() : 0);
|
||||
}
|
||||
}
|
||||
-363
@@ -1,363 +0,0 @@
|
||||
package com.central.order.util;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderResponse;
|
||||
import com.central.order.model.CtripConsumedNoticeResponse;
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程标准响应码工具类
|
||||
* 根据携程API平台标准定义响应码
|
||||
*
|
||||
* @author system
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Slf4j
|
||||
public class CtripResponseCodeUtil {
|
||||
|
||||
/**
|
||||
* 携程标准响应码定义
|
||||
*/
|
||||
public static class CtripResponseCodes {
|
||||
// 成功响应码
|
||||
public static final String SUCCESS = "0000";
|
||||
public static final String SUCCESS_MESSAGE = "操作成功";
|
||||
|
||||
// 系统错误码 (1000-1999)
|
||||
public static final String SYSTEM_ERROR = "1000";
|
||||
public static final String SYSTEM_ERROR_MESSAGE = "系统错误";
|
||||
|
||||
public static final String PARAM_ERROR = "1001";
|
||||
public static final String PARAM_ERROR_MESSAGE = "参数错误";
|
||||
|
||||
public static final String SIGN_ERROR = "1002";
|
||||
public static final String SIGN_ERROR_MESSAGE = "签名验证失败";
|
||||
|
||||
public static final String TIMESTAMP_ERROR = "1003";
|
||||
public static final String TIMESTAMP_ERROR_MESSAGE = "时间戳错误";
|
||||
|
||||
public static final String VERSION_ERROR = "1004";
|
||||
public static final String VERSION_ERROR_MESSAGE = "版本号错误";
|
||||
|
||||
// 业务错误码 (2000-2999)
|
||||
public static final String ORDER_NOT_FOUND = "2000";
|
||||
public static final String ORDER_NOT_FOUND_MESSAGE = "订单不存在";
|
||||
|
||||
public static final String ORDER_ALREADY_EXISTS = "2001";
|
||||
public static final String ORDER_ALREADY_EXISTS_MESSAGE = "订单已存在";
|
||||
|
||||
public static final String ORDER_STATUS_ERROR = "2002";
|
||||
public static final String ORDER_STATUS_ERROR_MESSAGE = "订单状态错误";
|
||||
|
||||
public static final String COUPON_NOT_FOUND = "2003";
|
||||
public static final String COUPON_NOT_FOUND_MESSAGE = "优惠券不存在";
|
||||
|
||||
public static final String COUPON_ALREADY_USED = "2004";
|
||||
public static final String COUPON_ALREADY_USED_MESSAGE = "优惠券已使用";
|
||||
|
||||
public static final String COUPON_EXPIRED = "2005";
|
||||
public static final String COUPON_EXPIRED_MESSAGE = "优惠券已过期";
|
||||
|
||||
public static final String COUPON_INSUFFICIENT = "2006";
|
||||
public static final String COUPON_INSUFFICIENT_MESSAGE = "优惠券余额不足";
|
||||
|
||||
public static final String USER_NOT_FOUND = "2007";
|
||||
public static final String USER_NOT_FOUND_MESSAGE = "用户不存在";
|
||||
|
||||
public static final String PRODUCT_NOT_FOUND = "2008";
|
||||
public static final String PRODUCT_NOT_FOUND_MESSAGE = "产品不存在";
|
||||
|
||||
public static final String PRODUCT_UNAVAILABLE = "2009";
|
||||
public static final String PRODUCT_UNAVAILABLE_MESSAGE = "产品不可用";
|
||||
|
||||
// 网络错误码 (3000-3999)
|
||||
public static final String NETWORK_ERROR = "3000";
|
||||
public static final String NETWORK_ERROR_MESSAGE = "网络连接错误";
|
||||
|
||||
public static final String TIMEOUT_ERROR = "3001";
|
||||
public static final String TIMEOUT_ERROR_MESSAGE = "请求超时";
|
||||
|
||||
public static final String SERVICE_UNAVAILABLE = "3002";
|
||||
public static final String SERVICE_UNAVAILABLE_MESSAGE = "服务不可用";
|
||||
|
||||
// 权限错误码 (4000-4999)
|
||||
public static final String UNAUTHORIZED = "4000";
|
||||
public static final String UNAUTHORIZED_MESSAGE = "未授权访问";
|
||||
|
||||
public static final String FORBIDDEN = "4001";
|
||||
public static final String FORBIDDEN_MESSAGE = "访问被拒绝";
|
||||
|
||||
public static final String ACCOUNT_DISABLED = "4002";
|
||||
public static final String ACCOUNT_DISABLED_MESSAGE = "账户已禁用";
|
||||
|
||||
// 数据错误码 (5000-5999)
|
||||
public static final String DATA_NOT_FOUND = "5000";
|
||||
public static final String DATA_NOT_FOUND_MESSAGE = "数据不存在";
|
||||
|
||||
public static final String DATA_INVALID = "5001";
|
||||
public static final String DATA_INVALID_MESSAGE = "数据格式错误";
|
||||
|
||||
public static final String DATA_CONFLICT = "5002";
|
||||
public static final String DATA_CONFLICT_MESSAGE = "数据冲突";
|
||||
|
||||
// 第三方服务错误码 (6000-6999)
|
||||
public static final String THIRD_PARTY_ERROR = "6000";
|
||||
public static final String THIRD_PARTY_ERROR_MESSAGE = "第三方服务错误";
|
||||
|
||||
public static final String PAYMENT_ERROR = "6001";
|
||||
public static final String PAYMENT_ERROR_MESSAGE = "支付服务错误";
|
||||
|
||||
public static final String SMS_ERROR = "6002";
|
||||
public static final String SMS_ERROR_MESSAGE = "短信服务错误";
|
||||
|
||||
public static final String EMAIL_ERROR = "6003";
|
||||
public static final String EMAIL_ERROR_MESSAGE = "邮件服务错误";
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程订单创建成功响应
|
||||
*/
|
||||
public static CtripCreateOrderResponse buildCreateOrderSuccessResponse(
|
||||
CtripCreateOrderRequest request,
|
||||
String otaOrderId,
|
||||
String supplierOrderId,
|
||||
String message) {
|
||||
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode(CtripResponseCodes.SUCCESS);
|
||||
response.setResultMessage(CtripResponseCodes.SUCCESS_MESSAGE);
|
||||
|
||||
// 设置返回体
|
||||
CtripCreateOrderResponse.CtripResponseBody responseBody = new CtripCreateOrderResponse.CtripResponseBody();
|
||||
responseBody.setOtaOrderId(otaOrderId);
|
||||
responseBody.setSupplierOrderId(supplierOrderId);
|
||||
responseBody.setSupplierConfirmType(1); // 已确认
|
||||
responseBody.setVoucherSender(1); // 携程对客发送凭证
|
||||
responseBody.setOrderExtendMessage(message);
|
||||
|
||||
// 设置订单项
|
||||
List<CtripCreateOrderResponse.CtripResponseOrderItem> responseItems = new ArrayList<>();
|
||||
CtripCreateOrderResponse.CtripResponseOrderItem responseItem = new CtripCreateOrderResponse.CtripResponseOrderItem();
|
||||
responseItem.setItemId("1");
|
||||
responseItem.setSupplierItemId(supplierOrderId + "_ITEM");
|
||||
responseItem.setStatus(1); // 成功
|
||||
responseItem.setMessage(message);
|
||||
responseItems.add(responseItem);
|
||||
responseBody.setItems(responseItems);
|
||||
|
||||
response.setBody(responseBody);
|
||||
|
||||
log.info("构建携程订单创建成功响应: otaOrderId={}, supplierOrderId={}", otaOrderId, supplierOrderId);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程订单创建错误响应
|
||||
*/
|
||||
public static CtripCreateOrderResponse buildCreateOrderErrorResponse(
|
||||
CtripCreateOrderRequest request,
|
||||
String resultCode,
|
||||
String resultMessage) {
|
||||
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode(resultCode);
|
||||
response.setResultMessage(resultMessage);
|
||||
|
||||
log.warn("构建携程订单创建错误响应: resultCode={}, resultMessage={}", resultCode, resultMessage);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知成功响应
|
||||
*/
|
||||
public static CtripConsumedNoticeResponse buildConsumedNoticeSuccessResponse(
|
||||
String otaOrderId,
|
||||
String supplierOrderId) {
|
||||
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置响应头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader header = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.setAccountId("SYSTEM");
|
||||
header.setSign("SUCCESS");
|
||||
header.setServiceName("ConsumedNotice");
|
||||
header.setVersion("1.0");
|
||||
response.setHeader(header);
|
||||
|
||||
// 设置响应码
|
||||
response.setResultCode(CtripResponseCodes.SUCCESS);
|
||||
response.setResultMessage(CtripResponseCodes.SUCCESS_MESSAGE);
|
||||
|
||||
// 设置响应体
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody body = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody();
|
||||
body.setOtaOrderId(otaOrderId);
|
||||
body.setSupplierOrderId(supplierOrderId);
|
||||
body.setProcessResult("SUCCESS");
|
||||
body.setProcessTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
response.setBody(body);
|
||||
|
||||
log.info("构建携程核销通知成功响应: otaOrderId={}, supplierOrderId={}", otaOrderId, supplierOrderId);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知错误响应
|
||||
*/
|
||||
public static CtripConsumedNoticeResponse buildConsumedNoticeErrorResponse(
|
||||
String otaOrderId,
|
||||
String supplierOrderId,
|
||||
String resultCode,
|
||||
String resultMessage) {
|
||||
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置响应头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader header = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.setAccountId("SYSTEM");
|
||||
header.setSign("ERROR");
|
||||
header.setServiceName("ConsumedNotice");
|
||||
header.setVersion("1.0");
|
||||
response.setHeader(header);
|
||||
|
||||
// 设置响应码
|
||||
response.setResultCode(resultCode);
|
||||
response.setResultMessage(resultMessage);
|
||||
|
||||
// 设置响应体
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody body = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody();
|
||||
body.setOtaOrderId(otaOrderId);
|
||||
body.setSupplierOrderId(supplierOrderId);
|
||||
body.setProcessResult("FAILED");
|
||||
body.setProcessTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
response.setBody(body);
|
||||
|
||||
log.warn("构建携程核销通知错误响应: otaOrderId={}, resultCode={}, resultMessage={}", otaOrderId, resultCode, resultMessage);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据异常类型获取标准响应码
|
||||
*/
|
||||
public static String getResultCodeByException(Exception e) {
|
||||
String exceptionName = e.getClass().getSimpleName();
|
||||
|
||||
switch (exceptionName) {
|
||||
case "IllegalArgumentException":
|
||||
case "MissingServletRequestParameterException":
|
||||
return CtripResponseCodes.PARAM_ERROR;
|
||||
case "UnauthorizedException":
|
||||
return CtripResponseCodes.UNAUTHORIZED;
|
||||
case "ForbiddenException":
|
||||
return CtripResponseCodes.FORBIDDEN;
|
||||
case "NotFoundException":
|
||||
return CtripResponseCodes.DATA_NOT_FOUND;
|
||||
case "ConflictException":
|
||||
return CtripResponseCodes.DATA_CONFLICT;
|
||||
case "TimeoutException":
|
||||
return CtripResponseCodes.TIMEOUT_ERROR;
|
||||
default:
|
||||
return CtripResponseCodes.SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据异常类型获取标准响应消息
|
||||
*/
|
||||
public static String getResultMessageByException(Exception e) {
|
||||
String exceptionName = e.getClass().getSimpleName();
|
||||
|
||||
switch (exceptionName) {
|
||||
case "IllegalArgumentException":
|
||||
case "MissingServletRequestParameterException":
|
||||
return CtripResponseCodes.PARAM_ERROR_MESSAGE;
|
||||
case "UnauthorizedException":
|
||||
return CtripResponseCodes.UNAUTHORIZED_MESSAGE;
|
||||
case "ForbiddenException":
|
||||
return CtripResponseCodes.FORBIDDEN_MESSAGE;
|
||||
case "NotFoundException":
|
||||
return CtripResponseCodes.DATA_NOT_FOUND_MESSAGE;
|
||||
case "ConflictException":
|
||||
return CtripResponseCodes.DATA_CONFLICT_MESSAGE;
|
||||
case "TimeoutException":
|
||||
return CtripResponseCodes.TIMEOUT_ERROR_MESSAGE;
|
||||
default:
|
||||
return CtripResponseCodes.SYSTEM_ERROR_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证响应码是否有效
|
||||
*/
|
||||
public static boolean isValidResponseCode(String resultCode) {
|
||||
if (resultCode == null || resultCode.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否为4位数字
|
||||
if (!resultCode.matches("\\d{4}")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否在有效范围内
|
||||
int code = Integer.parseInt(resultCode);
|
||||
return (code >= 0 && code <= 9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取响应码分类
|
||||
*/
|
||||
public static String getResponseCodeCategory(String resultCode) {
|
||||
if (resultCode == null || resultCode.isEmpty()) {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int code = Integer.parseInt(resultCode);
|
||||
|
||||
if (code == 0) {
|
||||
return "SUCCESS";
|
||||
} else if (code >= 1000 && code < 2000) {
|
||||
return "SYSTEM_ERROR";
|
||||
} else if (code >= 2000 && code < 3000) {
|
||||
return "BUSINESS_ERROR";
|
||||
} else if (code >= 3000 && code < 4000) {
|
||||
return "NETWORK_ERROR";
|
||||
} else if (code >= 4000 && code < 5000) {
|
||||
return "AUTHORIZATION_ERROR";
|
||||
} else if (code >= 5000 && code < 6000) {
|
||||
return "DATA_ERROR";
|
||||
} else if (code >= 6000 && code < 7000) {
|
||||
return "THIRD_PARTY_ERROR";
|
||||
} else {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ spring:
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.device.model
|
||||
typeAliasesPackage: com.central.order.model
|
||||
# configuration:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
@@ -87,7 +87,7 @@ tencent:
|
||||
file:
|
||||
oss-url: goflyapp.oss-cn-beijing.aliyuncs.com
|
||||
cdn-url: cdn.goflytec.com
|
||||
style: image/resize,m_mfit,w_218,h_160
|
||||
style: image/resize,m_mfit,w_218,h_288
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.order.mapper.CouponMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.Coupon">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="coupon_no" property="couponNo" jdbcType="VARCHAR"/>
|
||||
<result column="coupon_name" property="couponName" jdbcType="VARCHAR"/>
|
||||
<result column="coupon_type" property="couponType" jdbcType="INTEGER"/>
|
||||
<result column="amount" property="amount" jdbcType="DECIMAL"/>
|
||||
<result column="min_amount" property="minAmount" jdbcType="DECIMAL"/>
|
||||
<result column="discount_rate" property="discountRate" jdbcType="INTEGER"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="user_phone" property="userPhone" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userId" jdbcType="BIGINT"/>
|
||||
<result column="source" property="source" jdbcType="INTEGER"/>
|
||||
<result column="ctrip_coupon_id" property="ctripCouponId" jdbcType="VARCHAR"/>
|
||||
<result column="valid_start_time" property="validStartTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="valid_end_time" property="validEndTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="used_time" property="usedTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="used_order_no" property="usedOrderNo" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, coupon_no, coupon_name, coupon_type, amount, min_amount, discount_rate, status,
|
||||
user_phone, user_id, source, ctrip_coupon_id, valid_start_time, valid_end_time,
|
||||
used_time, used_order_no, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询优惠券列表 -->
|
||||
<select id="selectCouponPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_coupon
|
||||
<where>
|
||||
<if test="coupon.couponName != null and coupon.couponName != ''">
|
||||
AND coupon_name LIKE CONCAT('%', #{coupon.couponName}, '%')
|
||||
</if>
|
||||
<if test="coupon.couponType != null">
|
||||
AND coupon_type = #{coupon.couponType}
|
||||
</if>
|
||||
<if test="coupon.status != null">
|
||||
AND status = #{coupon.status}
|
||||
</if>
|
||||
<if test="coupon.userPhone != null and coupon.userPhone != ''">
|
||||
AND user_phone = #{coupon.userPhone}
|
||||
</if>
|
||||
<if test="coupon.source != null">
|
||||
AND source = #{coupon.source}
|
||||
</if>
|
||||
<if test="coupon.ctripCouponId != null and coupon.ctripCouponId != ''">
|
||||
AND ctrip_coupon_id = #{coupon.ctripCouponId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号查询用户优惠券 -->
|
||||
<select id="selectByUserPhone" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_coupon
|
||||
WHERE user_phone = #{userPhone}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号查询可用优惠券 -->
|
||||
<select id="selectAvailableByUserPhone" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_coupon
|
||||
WHERE user_phone = #{userPhone}
|
||||
AND status = 0
|
||||
AND valid_start_time <= NOW()
|
||||
AND valid_end_time >= NOW()
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据携程优惠券ID查询 -->
|
||||
<select id="selectByCtripCouponId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_coupon
|
||||
WHERE ctrip_coupon_id = #{ctripCouponId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据订单号查询使用的优惠券 -->
|
||||
<select id="selectByUsedOrderNo" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_coupon
|
||||
WHERE used_order_no = #{usedOrderNo}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 更新优惠券状态为已使用 -->
|
||||
<update id="updateCouponUsed">
|
||||
UPDATE t_coupon
|
||||
SET status = 1,
|
||||
used_time = NOW(),
|
||||
used_order_no = #{usedOrderNo},
|
||||
update_time = NOW()
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 批量更新过期优惠券状态 -->
|
||||
<update id="updateExpiredCoupons">
|
||||
UPDATE t_coupon
|
||||
SET status = 2,
|
||||
update_time = NOW()
|
||||
WHERE status = 0
|
||||
AND valid_end_time < NOW()
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
-427
@@ -1,427 +0,0 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 优惠券控制器测试
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class CouponControllerTest {
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestDeserialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2024-12-19 10:00:00\",\n" +
|
||||
" \"accountId\": \"testAccount\",\n" +
|
||||
" \"sign\": \"testSign\",\n" +
|
||||
" \"serviceName\": \"createOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"CTRIP123456\",\n" +
|
||||
" \"sequenceId\": \"SEQ123456\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardType\": \"ID\",\n" +
|
||||
" \"cardNo\": \"110101199001011234\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 100.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 80.00,\n" +
|
||||
" \"price\": 100.00,\n" +
|
||||
" \"useStartDate\": \"2024-12-20\",\n" +
|
||||
" \"useEndDate\": \"2024-12-25\",\n" +
|
||||
" \"adjunctions\": [\"adj1\", \"adj2\"],\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"online\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"email\": \"zhangsan@example.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("testAccount", request.getHeader().getAccountId());
|
||||
assertEquals("createOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("CTRIP123456", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("张三", item.getPassengers().get(0).getName());
|
||||
assertEquals("13800138000", item.getPassengers().get(0).getMobile());
|
||||
|
||||
System.out.println("JSON反序列化测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试对象
|
||||
CtripCreateOrderRequest request = new CtripCreateOrderRequest();
|
||||
|
||||
// 设置header
|
||||
CtripCreateOrderRequest.CtripHeader header = new CtripCreateOrderRequest.CtripHeader();
|
||||
header.setRequestTime("2024-12-19 10:00:00");
|
||||
header.setAccountId("testAccount");
|
||||
header.setSign("testSign");
|
||||
header.setServiceName("createOrder");
|
||||
header.setVersion("1.0");
|
||||
request.setHeader(header);
|
||||
|
||||
// 设置body为对象
|
||||
CtripCreateOrderRequest.CtripOrderBody body = new CtripCreateOrderRequest.CtripOrderBody();
|
||||
body.setOtaOrderId("CTRIP123456");
|
||||
body.setSequenceId("SEQ123456");
|
||||
|
||||
// 设置item
|
||||
CtripCreateOrderRequest.CtripOrderItem item = new CtripCreateOrderRequest.CtripOrderItem();
|
||||
item.setCost(new BigDecimal("100.00"));
|
||||
item.setQuantity(1);
|
||||
item.setSalePrice(new BigDecimal("80.00"));
|
||||
item.setPrice(new BigDecimal("100.00"));
|
||||
item.setUseStartDate("2024-12-20");
|
||||
item.setUseEndDate("2024-12-25");
|
||||
item.setAdjunctions(Arrays.asList("adj1", "adj2"));
|
||||
item.setDeposit(new Object());
|
||||
item.setDistributionChannel("online");
|
||||
item.setPriceCurrency("CNY");
|
||||
item.setCostCurrency("CNY");
|
||||
item.setSalePriceCurrency("CNY");
|
||||
|
||||
// 设置passenger
|
||||
CtripCreateOrderRequest.CtripPassenger passenger = new CtripCreateOrderRequest.CtripPassenger();
|
||||
passenger.setName("张三");
|
||||
passenger.setMobile("13800138000");
|
||||
passenger.setGender("M");
|
||||
passenger.setCardType("ID");
|
||||
passenger.setCardNo("110101199001011234");
|
||||
item.setPassengers(Arrays.asList(passenger));
|
||||
|
||||
body.setItems(Arrays.asList(item));
|
||||
|
||||
// 设置contact
|
||||
CtripCreateOrderRequest.CtripContact contact = new CtripCreateOrderRequest.CtripContact();
|
||||
contact.setName("张三");
|
||||
contact.setMobile("13800138000");
|
||||
contact.setEmail("zhangsan@example.com");
|
||||
body.setContacts(Arrays.asList(contact));
|
||||
|
||||
request.setBody(body);
|
||||
|
||||
// 测试序列化
|
||||
String json = objectMapper.writeValueAsString(request);
|
||||
assertNotNull(json);
|
||||
assertTrue(json.contains("CTRIP123456"));
|
||||
assertTrue(json.contains("testAccount"));
|
||||
|
||||
System.out.println("JSON序列化测试通过!");
|
||||
System.out.println("生成的JSON: " + json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorHandling() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 测试错误的JSON格式
|
||||
String invalidJson = "{\"invalid\": \"data\"}";
|
||||
|
||||
try {
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(invalidJson, CtripCreateOrderRequest.class);
|
||||
// 如果没有抛出异常,说明@JsonIgnoreProperties生效了
|
||||
assertNotNull(request);
|
||||
System.out.println("错误处理测试通过 - 忽略未知属性");
|
||||
} catch (Exception e) {
|
||||
// 如果抛出异常,也是正常的
|
||||
System.out.println("错误处理测试通过 - 捕获到异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptedDataHandling() {
|
||||
// 测试加密数据处理
|
||||
String encryptedData = "anipkokpjcnikijobbdgmeddhnmngkidmfoeamjgmmjenpikgpeafnoonnjppdlhhhoidlopkfbpepchhbikpeiaogpmglhjbcaoomkponmciaphjjajhogmmagkiflikbffgmgkinckainhidjjmmoifodpakdlacfepfphenlflpcpdmjpnpaocckibgoagfcncpjnkhaniibphkmgknjabnfoeiblkfbmpekpkpaolangbbpflclbnbmffcaaemnaceckfmaegfnoclpgkblgpjggkjdmkbnkbffacmlpbnefipiaenjclfppilnedllghnejhdchhkdacadanioehbpbdmghioohnjbaamahjdoebckhhljnohfaddbndlepilbnngdhlmfbajnjchllinafbpeldcaacnddmieipmnikgbbbmjpbnpofceacdecjdifkmipeknimidgpbjpdoclimemkjmjhnneghcknneambllglnahlkenngnakncoijpggpdafipbladoaadbdfdebkcjfkaopaieknmjfopbojgljmlgkehmgoghnhggppbeoflhgfijjoabbmkipehekdpchlagnlbdidbmdmghdhoicoapnneljedkkaiikieneiopokkbidoigjlbmkkpeilapilhcmdkaiokiciaacenikijicllgdkbhlenhhcdapipkjhompefkfeginnmgmkjjooleihjfnjofkdgelojfboejjdopiajgldoppcaepkoceffkfjacfcpcbfcblgkaigddakfagnijfjdombelmfgjgopighebpdgbfcbmbecblhdgfbgkoacoiemfelalemmnkeejnighfgmlbenocgdlmoelbcakjppjlpoecimikkbcjblemhbhcgnapcmjbbflgmlfkllmpgdmhiagpolnlccanjdbajnbieapghplipmemakjkkfgphligccnlpjhgeiglbpdcejaajfhjfkplhocifopajenpmdmpncbpkhbbnpnbckmkahemfddhkgijgagkbmpigmbdedmkonkcchimohghkojhmgfeafpefoefccbjjkfkdcedbcmlgomoicfihhaalamkafkmfefdlihpopbdomkiodfdaiogemkebjmbgnfodmnbfedbaacdlmmangllfjihbhmngeoibobbjjmfmfdmpncdpbnfhcggonmfnpifhbjbjlnmcffdpnjpajkgdhllhdpffbdnioacknijcabmncijgmepdkipfpncchmaiamlmfpbcjamggjdjeokhdepklpflafjolemjednbbfmgoikkmfdhgnfiomkaahccnflpdlholfdkncdimgdgfmjdahadbohhfiamlfggljdeahjaaoopclacaakmpobapkhnbmcfmlbobdhblillhdbmmnoaaaeedaleehgpeofipljnmloicglmdmefpkdiplhlmhgiafhjjijigeapikdcdaoallpjlcmebbcohnmlacnkcbcnjkapdaeemkgcgbodjbneaapdgomhbmoljahdlmffnebohgngnfhkjlhejfebgjcccfpmclbeooaghapbkdcjicgjpjnjcgfnhefcmkknglodcoajnobpakaempkbllghgfcobefnebjnaniocjmdedcbgpbbacelfecgemifkedogbloplckenjopknbpfgabpfnaphcklifibbhgohhkjldaekcedkeimlmegdhbjnffililaamfbfdkakleknjdjahogknimijcdahggheehclghkbkkclebcgopeabkkcceiahldnmnffhkgcdbahaldpgddehbpjieaojnknbedoinappdpjjkinjcgiodfahffppcpkeaelgcabkelblhlbbddbemckhkjldpndoohboioplpdohngjpbdegfcnhloenmncalldemhoigglahmnpcdepjfmfhdekbnombijpcfiggmllpglbghlelijohdegkkmicbcgioccekjbhfhoimhdpcejcjcjlmohpfiijjpmknihlhgjeniknkjlhjdgemjgjbnahdhjgobmgonnlljhpendhke";
|
||||
|
||||
// 验证这是一个长字符串而不是JSON
|
||||
assertFalse(encryptedData.startsWith("{"));
|
||||
assertFalse(encryptedData.endsWith("}"));
|
||||
assertTrue(encryptedData.length() > 1000);
|
||||
|
||||
System.out.println("加密数据处理测试通过 - 识别为非JSON格式的长字符串");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testOrderCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程订单数据
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2025-08-01 22:58:01\",\n" +
|
||||
" \"accountId\": \"c50a8f2a4a59c9e7\",\n" +
|
||||
" \"sign\": \"5e8ebe775c7aaa466cd469947d6dee22\",\n" +
|
||||
" \"serviceName\": \"CreatePreOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("c50a8f2a4a59c9e7", request.getHeader().getAccountId());
|
||||
assertEquals("CreatePreOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("订单创建测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCouponCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程优惠券数据
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2025-08-01 22:58:01\",\n" +
|
||||
" \"accountId\": \"c50a8f2a4a59c9e7\",\n" +
|
||||
" \"sign\": \"5e8ebe775c7aaa466cd469947d6dee22\",\n" +
|
||||
" \"serviceName\": \"CreatePreOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("c50a8f2a4a59c9e7", request.getHeader().getAccountId());
|
||||
assertEquals("CreatePreOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("携程优惠券创建测试通过!");
|
||||
System.out.println("接口路径: /coupon/ctrip/create");
|
||||
System.out.println("请求方法: POST");
|
||||
System.out.println("Content-Type: application/json");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user