Commit 420ce71a by 章家宝

feat:联调后台上传过户资料、支付凭证

1 parent e21f635f
......@@ -12,6 +12,9 @@ import com.glsx.usedcar.module.auction.entity.vo.UpdateVehicleDocumentsVO;
import com.glsx.usedcar.module.auction.entity.Auction_;
import com.glsx.usedcar.module.auction.service.AuctionOrderService;
import com.glsx.usedcar.module.auction.service.AuctionService;
import com.glsx.usedcar.module.finance.entity.OrderTransaction;
import com.glsx.usedcar.module.finance.service.TransactionService;
import com.glsx.usedcar.module.meta.AuditState;
import com.glsx.usedcar.module.security.entity.User;
import com.glsx.usedcar.module.track.entity.ApproveHistory;
import com.glsx.usedcar.module.vehicle.entity.Vehicle_;
......@@ -29,9 +32,11 @@ import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.FieldException;
import org.summerframework.orm.paging.Filter;
import org.summerframework.orm.paging.Pagination;
import org.summerframework.storage.domain.FileInfo;
import org.summerframework.storage.web.annotation.OssProcess;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
......@@ -54,6 +59,8 @@ public class AuctionOrderController {
private AuctionOrderService auctionOrderService;
@Resource
private AuctionService auctionService;
@Resource
private TransactionService transactionService;
/**
* 分页查询拍卖订单
......@@ -183,14 +190,15 @@ public class AuctionOrderController {
/**
* 后台代上传付款凭证
* <p>
* 仅当订单状态为待付款且付款凭证数为0时可操作
* 仅当订单状态为待付款时可操作,创建OrderTransaction记录并进入待审核状态
* 后台审核通过后订单状态更新为待提车
* </p>
*
* @param vo 请求参数
* @return 更新后的订单
*/
@PostMapping("proxyUploadPayVoucher")
@Operation(summary = "后台代上传付款凭证", description = "仅当订单状态为待付款且付款凭证数为0时可操作")
@Operation(summary = "后台代上传付款凭证", description = "仅当订单状态为待付款时可操作,需后台审核通过")
public BaseResp<AuctionOrder> proxyUploadPayVoucher(@Valid @RequestBody ProxyUploadPayVoucherVO vo) {
log.info("后台代上传付款凭证, 请求参数: {}", vo);
try {
......@@ -202,17 +210,39 @@ public class AuctionOrderController {
return BaseResp.fail("订单状态不正确,仅待付款订单可上传付款凭证");
}
// 校验是否已有付款凭证
if (order.getPayVouchers() != null && !order.getPayVouchers().isEmpty()) {
log.warn("后台代上传付款凭证失败, 订单已有付款凭证, orderId: {}", vo.getOrderId());
// 校验是否已有审核通过的付款凭证
OrderTransaction existTransaction = transactionService.getOrderTransactionByOrderId(vo.getOrderId());
if (existTransaction != null && existTransaction.getAuditState() == AuditState.AUDITED) {
log.warn("后台代上传付款凭证失败, 订单已有审核通过的付款凭证, orderId: {}", vo.getOrderId());
return BaseResp.fail("订单已有付款凭证,不可重复上传");
}
// 更新付款凭证
order.setPayVouchers(vo.getPayVouchers());
auctionOrderService.updateAuctionOrder(order);
// 转换URL为FileInfo
List<FileInfo> payVouchers = null;
if (vo.getPayVouchers() != null && !vo.getPayVouchers().isEmpty()) {
payVouchers = convertUrlsToFileInfos(vo.getPayVouchers());
}
// 创建或更新OrderTransaction记录(与小程序端逻辑一致)
OrderTransaction orderTransaction;
if (existTransaction != null && existTransaction.getAuditState() == AuditState.UNAUDITED) {
// 已有待审核记录,更新
orderTransaction = existTransaction;
orderTransaction.setPayVouchers(payVouchers);
orderTransaction.setRemark(vo.getRemark());
transactionService.updateOrderTransaction(orderTransaction, vo.getRemark());
} else {
// 无记录或已拒绝(EXCEPTION),创建新记录
orderTransaction = new OrderTransaction();
orderTransaction.setAuctionOrder(order);
orderTransaction.setPaymentType(OrderTransaction.PaymentType.OFFLINE);
orderTransaction.setAmount(order.getOrderPrice() + order.getCommissionPrice());
orderTransaction.setRemark(vo.getRemark());
orderTransaction.setPayVouchers(payVouchers);
transactionService.proxySaveOrderTransaction(orderTransaction, vo.getRemark());
}
log.info("后台代上传付款凭证成功, orderId: {}", vo.getOrderId());
log.info("后台代上传付款凭证成功, orderId: {}, transactionId: {}", vo.getOrderId(), orderTransaction.getTransactionId());
return BaseResp.success(order);
} catch (Exception e) {
log.error("后台代上传付款凭证失败, 请求参数: {}", vo, e);
......@@ -246,17 +276,17 @@ public class AuctionOrderController {
if (vo.getNewPlateNumber() != null) {
order.setNewPlateNumber(vo.getNewPlateNumber());
}
if (vo.getRegistrationCertificate() != null) {
order.setRegistrationCertificate(vo.getRegistrationCertificate());
if (vo.getRegistrationCertificate() != null && !vo.getRegistrationCertificate().isEmpty()) {
order.setRegistrationCertificate(convertUrlsToFileInfos(vo.getRegistrationCertificate()));
}
if (vo.getVehicleLicense() != null) {
order.setVehicleLicense(vo.getVehicleLicense());
if (vo.getVehicleLicense() != null && !vo.getVehicleLicense().isEmpty()) {
order.setVehicleLicense(convertUrlsToFileInfos(vo.getVehicleLicense()));
}
if (vo.getTransferInvoice() != null) {
order.setTransferInvoice(vo.getTransferInvoice());
if (vo.getTransferInvoice() != null && !vo.getTransferInvoice().isEmpty()) {
order.setTransferInvoice(completeFileInfos(vo.getTransferInvoice()));
}
if (vo.getNewOwnerIdCard() != null) {
order.setNewOwnerIdCard(vo.getNewOwnerIdCard());
if (vo.getNewOwnerIdCard() != null && !vo.getNewOwnerIdCard().isEmpty()) {
order.setNewOwnerIdCard(convertUrlsToFileInfos(vo.getNewOwnerIdCard()));
}
auctionOrderService.updateAuctionOrder(order);
......@@ -290,8 +320,12 @@ public class AuctionOrderController {
}
// 更新车务资料
order.setRegistrationCertificate(vo.getRegistrationCertificate());
order.setVehicleLicense(vo.getVehicleLicense());
if (vo.getRegistrationCertificate() != null && !vo.getRegistrationCertificate().isEmpty()) {
order.setRegistrationCertificate(convertUrlsToFileInfos(vo.getRegistrationCertificate()));
}
if (vo.getVehicleLicense() != null && !vo.getVehicleLicense().isEmpty()) {
order.setVehicleLicense(convertUrlsToFileInfos(vo.getVehicleLicense()));
}
auctionOrderService.updateAuctionOrder(order);
log.info("更新车务资料成功, orderId: {}", vo.getOrderId());
......@@ -302,4 +336,52 @@ public class AuctionOrderController {
}
}
/**
* 将URL字符串列表转换为FileInfo对象列表
*
* @param urls URL字符串列表
* @return FileInfo对象列表
*/
private List<FileInfo> convertUrlsToFileInfos(List<String> urls) {
return urls.stream()
.map(url -> {
String fileName = url.substring(url.lastIndexOf('/') + 1);
return new FileInfo(String.valueOf(url.hashCode()), fileName, url, url, LocalDateTime.now());
})
.toList();
}
/**
* 补充FileInfo缺失字段
* <p>
* 前端传 filePath 和 size(FileInfo 的 url 字段有 @JsonProperty(access = READ_ONLY),无法接收输入)
* 需要补充 uid、name、lastModifiedDate
* </p>
*
* @param fileInfos 前端传来的FileInfo列表(filePath 和 size)
* @return 补充完整字段后的FileInfo列表
*/
private List<FileInfo> completeFileInfos(List<FileInfo> fileInfos) {
return fileInfos.stream()
.filter(info -> {
// filePath 字段可以接收前端传的 URL
String path = info.getFilePath();
return path != null && !path.isEmpty();
})
.map(info -> {
String url = info.getFilePath();
String fileName = url.substring(url.lastIndexOf('/') + 1);
FileInfo complete = new FileInfo(
String.valueOf(url.hashCode()),
fileName,
url,
url,
info.getSize(),
LocalDateTime.now()
);
return complete;
})
.toList();
}
}
\ No newline at end of file
......@@ -219,6 +219,12 @@ public class AuctionOrder extends AuditingEntity implements Serializable {
private String cancelReason;
/**
* 备注
*/
@Column(length = 500)
private String remark;
/**
* 优惠券名称(非持久化字段,用于展示)
*/
@Transient
......
......@@ -3,7 +3,6 @@ package com.glsx.usedcar.module.auction.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.summerframework.storage.domain.FileInfo;
import java.io.Serial;
import java.io.Serializable;
......@@ -26,6 +25,9 @@ public class ProxyUploadPayVoucherVO implements Serializable {
@Schema(description = "订单ID", required = true, example = "1")
private Integer orderId;
@Schema(description = "付款凭证文件列表")
private List<FileInfo> payVouchers;
@Schema(description = "付款凭证URL列表")
private List<String> payVouchers;
@Schema(description = "备注")
private String remark;
}
......@@ -29,15 +29,15 @@ public class ProxyUploadTransferMaterialsVO implements Serializable {
@Schema(description = "新车牌号")
private String newPlateNumber;
@Schema(description = "机动车登记证书")
private List<FileInfo> registrationCertificate;
@Schema(description = "机动车登记证书URL列表")
private List<String> registrationCertificate;
@Schema(description = "机动车行驶证")
private List<FileInfo> vehicleLicense;
@Schema(description = "机动车行驶证URL列表")
private List<String> vehicleLicense;
@Schema(description = "过户发票")
@Schema(description = "过户发票文件列表(前端传 filePath 和 size)")
private List<FileInfo> transferInvoice;
@Schema(description = "新车主身份证")
private List<FileInfo> newOwnerIdCard;
@Schema(description = "新车主身份证URL列表")
private List<String> newOwnerIdCard;
}
......@@ -3,7 +3,6 @@ package com.glsx.usedcar.module.auction.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.summerframework.storage.domain.FileInfo;
import java.io.Serial;
import java.io.Serializable;
......@@ -26,9 +25,9 @@ public class UpdateVehicleDocumentsVO implements Serializable {
@Schema(description = "订单ID", required = true, example = "1")
private Integer orderId;
@Schema(description = "机动车登记证书")
private List<FileInfo> registrationCertificate;
@Schema(description = "机动车登记证书URL列表")
private List<String> registrationCertificate;
@Schema(description = "机动车行驶证")
private List<FileInfo> vehicleLicense;
@Schema(description = "机动车行驶证URL列表")
private List<String> vehicleLicense;
}
......@@ -162,6 +162,62 @@ public class TransactionService extends AbstractAuctionService {
}
}
/**
* 后台代上传付款凭证保存
* <p>
* 创建OrderTransaction记录,状态为待审核,与小程序端上传逻辑一致
* </p>
*
* @param orderTransaction 订单交易实例对象
* @param remark 订单备注(同步保存到AuctionOrder)
* @return 订单交易实例对象
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public OrderTransaction proxySaveOrderTransaction(OrderTransaction orderTransaction, String remark) {
// 重新查询订单并加载关联对象,避免懒加载异常
AuctionOrder auctionOrder = auctionOrderDao.findById(orderTransaction.getAuctionOrder().getOrderId()).orElseThrow();
// 触发懒加载
auctionOrder.getVehicle().getVehicleId();
auctionOrder.getAccount().getAccountId();
orderTransaction.setAuctionOrder(auctionOrder);
orderTransaction.setTransactionCode(CoderGenerator.generateCode(6));
orderTransaction.setAuditState(AuditState.UNAUDITED);
// 设置订单审核状态为待审核
auctionOrder.setAuditState(AuditState.UNAUDITED);
// 同步备注到订单
if (remark != null) {
auctionOrder.setRemark(remark);
}
// 发送通知消息
sendNoticeMessage(NoticeTemplate.TemplateType.ORDER_TRANSACTION, Map.of(
NoticeField.ORDER_CODE, auctionOrder.getOrderCode(),
NoticeField.VEHICLE_NAME, auctionOrder.getVehicle().toVehicleName(),
NoticeField.AMOUNT, auctionOrder.getOrderPrice() + auctionOrder.getCommissionPrice(),
NoticeField.ORDER_ACCOUNT_NAME, auctionOrder.getAccount().getAccountName(),
NoticeField.ORDER_TRANSACTION_TIME, auctionOrder.getCreateTime()));
return orderTransactionDao.save(orderTransaction);
}
/**
* 更新订单交易记录
*
* @param orderTransaction 订单交易实例对象
* @param remark 订单备注(同步保存到AuctionOrder)
* @return 订单交易实例对象
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public OrderTransaction updateOrderTransaction(OrderTransaction orderTransaction, String remark) {
AuctionOrder auctionOrder = auctionOrderDao.findById(orderTransaction.getAuctionOrder().getOrderId()).orElseThrow();
if (remark != null) {
auctionOrder.setRemark(remark);
}
return orderTransactionDao.save(orderTransaction);
}
/**
* 修改订单交易
......
......@@ -458,6 +458,7 @@ public class VehicleService {
vehicleDb.setEvaluationTransaction(vehicle.getEvaluationTransaction());
vehicleDb.setCustodianInfo(vehicle.getCustodianInfo());
vehicleDb.setOwnerInfo(vehicle.getOwnerInfo());
vehicleDb.setTransferMaterials(vehicle.getTransferMaterials());
if (vehicleDb.getVehicleState() == Vehicle.VehicleState.INVENTORY) {
// 车辆状态设置为待维护场地
vehicleDb.setVehicleState(Vehicle.VehicleState.VENUE);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!