Commit 7dffb960 by 章家宝

feat:需求《中拍后链路缩减操作步骤》代码开发第一版提交

1 parent 54e78350
Showing 34 changed files with 1880 additions and 95 deletions
package com.glsx.usedcar.web.rest.account;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.entity.Account_;
import com.glsx.usedcar.module.account.entity.PlatformContract;
import com.glsx.usedcar.module.account.entity.PlatformContract_;
import com.glsx.usedcar.module.account.service.PlatformContractService;
import com.glsx.usedcar.module.account.vo.PlatformContractPageQueryVO;
import com.glsx.usedcar.module.account.vo.PlatformContractPageRespVO;
import com.glsx.usedcar.module.account.vo.PlatformContractRespVO;
import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.summerframework.orm.paging.Operator;
import org.summerframework.orm.paging.Pagination;
import java.time.LocalDateTime;
import java.util.List;
/**
* 平台合同管理接口
* <p>
* 平台交易整体合同的列表查询、详情查看等功能
* </p>
*
* @author yangwei
* @since 2026-08-04
*/
@Slf4j
@RestController
@RequestMapping("/rest/platformContract")
@RequiredArgsConstructor
@Tag(name = "平台合同管理", description = "平台合同的查询操作")
public class PlatformContractController {
private final PlatformContractService platformContractService;
/**
* 分页查询平台合同列表
*
* @param queryVO 分页查询参数
* @return 平台合同分页列表
*/
@PostMapping("/page")
@Operation(summary = "分页查询平台合同", description = "支持按合同编号/签署人姓名/手机号/状态/账户ID筛选")
public BaseResp<Page<PlatformContractPageRespVO>> page(@RequestBody PlatformContractPageQueryVO queryVO) {
Pagination<PlatformContract> pagination = buildPagination(queryVO);
// 关联查询账户信息
pagination.addFetch(root -> root.fetch(PlatformContract_.account, jakarta.persistence.criteria.JoinType.LEFT));
Page<PlatformContractPageRespVO> result = platformContractService.pagePlatformContractVO(pagination);
return BaseResp.success(result);
}
/**
* 根据ID查询平台合同详情
*
* @param platformContractId 平台合同ID
* @return 平台合同详情
*/
@GetMapping("/detail/{id}")
@Operation(summary = "查询平台合同详情", description = "根据平台合同ID查询详情信息")
public BaseResp<PlatformContractRespVO> detail(
@Parameter(description = "平台合同ID", required = true, example = "1") @PathVariable("id") int platformContractId) {
PlatformContractRespVO result = platformContractService.getPlatformContractVOById(platformContractId);
return BaseResp.success(result);
}
/**
* 根据账户ID查询平台合同列表
*
* @param accountId 账户ID
* @return 平台合同列表
*/
@GetMapping("/listByAccount/{accountId}")
@Operation(summary = "查询账户的平台合同", description = "根据账户ID查询该账户的所有平台合同")
public BaseResp<List<PlatformContractRespVO>> listByAccount(
@Parameter(description = "账户ID", required = true, example = "1") @PathVariable int accountId) {
List<PlatformContractRespVO> contracts = platformContractService.getPlatformContractVOsByAccountId(accountId);
return BaseResp.success(contracts);
}
/**
* 检查账户是否已签署平台合同
*
* @param accountId 账户ID
* @return 是否已签署
*/
@GetMapping("/checkSigned")
@Operation(summary = "检查账户是否已签署平台合同", description = "根据账户ID检查该账户是否已签署平台合同")
public BaseResp<Boolean> checkSigned(
@Parameter(description = "账户ID", required = true, example = "1") @RequestParam int accountId) {
return BaseResp.success(platformContractService.hasSignedPlatformContract(accountId));
}
/**
* 构建分页查询参数
*/
private Pagination<PlatformContract> buildPagination(PlatformContractPageQueryVO queryVO) {
int page = queryVO.getPage() == null || queryVO.getPage() < 1 ? 1 : queryVO.getPage();
int size = queryVO.getSize() == null || queryVO.getSize() < 1 ? 20 : queryVO.getSize();
Pagination<PlatformContract> pagination = new Pagination<>((page - 1) * size, size);
pagination.setSort("createTime");
pagination.setOrder("desc");
// 合同编号筛选
if (StringUtils.hasText(queryVO.getContractCode())) {
pagination.addFilter(PlatformContract_.CONTRACT_CODE, queryVO.getContractCode(), Operator.like);
}
// 签署人姓名筛选
if (StringUtils.hasText(queryVO.getSignerName())) {
pagination.addFilter(PlatformContract_.SIGNER_NAME, queryVO.getSignerName(), Operator.like);
}
// 签署人手机号筛选
if (StringUtils.hasText(queryVO.getSignerMobile())) {
pagination.addFilter(PlatformContract_.SIGNER_MOBILE, queryVO.getSignerMobile(), Operator.eq);
}
// 合同状态筛选
if (StringUtils.hasText(queryVO.getContractStatus())) {
pagination.addFilter(PlatformContract_.CONTRACT_STATUS, PlatformContract.ContractStatus.valueOf(queryVO.getContractStatus()), Operator.eq);
}
// 账户ID筛选
if (queryVO.getAccountId() != null) {
pagination.addFilter(PlatformContract_.ACCOUNT, new Account(queryVO.getAccountId()), Operator.eq);
}
// 账户名称筛选
if (StringUtils.hasText(queryVO.getAccountName())) {
pagination.addCondition((root, query, builder) -> {
var accountPath = root.get(PlatformContract_.account).get(Account_.ACCOUNT_NAME);
return builder.like(accountPath, "%" + queryVO.getAccountName() + "%");
});
}
// 创建时间范围筛选
if (queryVO.getCreateTimeStart() != null) {
LocalDateTime startTime = queryVO.getCreateTimeStart().atStartOfDay();
pagination.addFilter("createTime", startTime, Operator.ge);
}
if (queryVO.getCreateTimeEnd() != null) {
LocalDateTime endTime = queryVO.getCreateTimeEnd().atTime(23, 59, 59);
pagination.addFilter("createTime", endTime, Operator.le);
}
return pagination;
}
}
......@@ -6,6 +6,9 @@ import com.glsx.usedcar.module.auction.domain.BidOrder;
import com.glsx.usedcar.module.auction.entity.AuctionOrder;
import com.glsx.usedcar.module.auction.entity.AuctionOrder_;
import com.glsx.usedcar.module.auction.entity.vo.AuctionOrderStateCountRespVO;
import com.glsx.usedcar.module.auction.entity.vo.ProxyUploadPayVoucherVO;
import com.glsx.usedcar.module.auction.entity.vo.ProxyUploadTransferMaterialsVO;
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;
......@@ -176,4 +179,127 @@ public class AuctionOrderController {
List<AuctionOrderBean> vehicleBeans = vehicles.stream().map(AuctionOrderBean::new).toList();
ExcelExporter.exportExcel(response, "订单列表", "订单列表", AuctionOrderBean.class, vehicleBeans);
}
/**
* 后台代上传付款凭证
* <p>
* 仅当订单状态为待付款且付款凭证数为0时可操作
* </p>
*
* @param vo 请求参数
* @return 更新后的订单
*/
@PostMapping("proxyUploadPayVoucher")
@Operation(summary = "后台代上传付款凭证", description = "仅当订单状态为待付款且付款凭证数为0时可操作")
public BaseResp<AuctionOrder> proxyUploadPayVoucher(@Valid @RequestBody ProxyUploadPayVoucherVO vo) {
log.info("后台代上传付款凭证, 请求参数: {}", vo);
try {
AuctionOrder order = auctionOrderService.getAuctionOrderById(vo.getOrderId());
// 校验订单状态
if (order.getOrderState() != AuctionOrder.OrderState.UNPAID) {
log.warn("后台代上传付款凭证失败, 订单状态不正确, orderId: {}, orderState: {}", vo.getOrderId(), order.getOrderState());
return BaseResp.fail("订单状态不正确,仅待付款订单可上传付款凭证");
}
// 校验是否已有付款凭证
if (order.getPayVouchers() != null && !order.getPayVouchers().isEmpty()) {
log.warn("后台代上传付款凭证失败, 订单已有付款凭证, orderId: {}", vo.getOrderId());
return BaseResp.fail("订单已有付款凭证,不可重复上传");
}
// 更新付款凭证
order.setPayVouchers(vo.getPayVouchers());
auctionOrderService.updateAuctionOrder(order);
log.info("后台代上传付款凭证成功, orderId: {}", vo.getOrderId());
return BaseResp.success(order);
} catch (Exception e) {
log.error("后台代上传付款凭证失败, 请求参数: {}", vo, e);
return BaseResp.fail("上传失败:" + e.getMessage());
}
}
/**
* 后台代上传过户资料
* <p>
* 仅当订单状态为待过户或审核中时可操作
* </p>
*
* @param vo 请求参数
* @return 更新后的订单
*/
@PostMapping("proxyUploadTransferMaterials")
@Operation(summary = "后台代上传过户资料", description = "仅当订单状态为待过户或审核中时可操作")
public BaseResp<AuctionOrder> proxyUploadTransferMaterials(@Valid @RequestBody ProxyUploadTransferMaterialsVO vo) {
log.info("后台代上传过户资料, 请求参数: {}", vo);
try {
AuctionOrder order = auctionOrderService.getAuctionOrderById(vo.getOrderId());
// 校验订单状态
if (order.getOrderState() != AuctionOrder.OrderState.TRANSFERRING) {
log.warn("后台代上传过户资料失败, 订单状态不正确, orderId: {}, orderState: {}", vo.getOrderId(), order.getOrderState());
return BaseResp.fail("订单状态不正确,仅待过户订单可上传过户资料");
}
// 更新过户资料(保存但不触发审核)
if (vo.getNewPlateNumber() != null) {
order.setNewPlateNumber(vo.getNewPlateNumber());
}
if (vo.getRegistrationCertificate() != null) {
order.setRegistrationCertificate(vo.getRegistrationCertificate());
}
if (vo.getVehicleLicense() != null) {
order.setVehicleLicense(vo.getVehicleLicense());
}
if (vo.getTransferInvoice() != null) {
order.setTransferInvoice(vo.getTransferInvoice());
}
if (vo.getNewOwnerIdCard() != null) {
order.setNewOwnerIdCard(vo.getNewOwnerIdCard());
}
auctionOrderService.updateAuctionOrder(order);
log.info("后台代上传过户资料成功, orderId: {}", vo.getOrderId());
return BaseResp.success(order);
} catch (Exception e) {
log.error("后台代上传过户资料失败, 请求参数: {}", vo, e);
return BaseResp.fail("上传失败:" + e.getMessage());
}
}
/**
* 更新车务资料(机动车登记证书、行驶证)
* <p>
* 用于后台修改订单的机动车登记证书和行驶证信息
* </p>
*
* @param vo 请求参数
* @return 更新后的订单
*/
@PostMapping("updateVehicleDocuments")
@Operation(summary = "更新车务资料", description = "修改订单的机动车登记证书和行驶证信息")
public BaseResp<AuctionOrder> updateVehicleDocuments(@Valid @RequestBody UpdateVehicleDocumentsVO vo) {
log.info("更新车务资料, 请求参数: {}", vo);
try {
AuctionOrder order = auctionOrderService.getAuctionOrderById(vo.getOrderId());
if (order == null) {
log.warn("更新车务资料失败, 订单不存在, orderId: {}", vo.getOrderId());
return BaseResp.fail("订单不存在");
}
// 更新车务资料
order.setRegistrationCertificate(vo.getRegistrationCertificate());
order.setVehicleLicense(vo.getVehicleLicense());
auctionOrderService.updateAuctionOrder(order);
log.info("更新车务资料成功, orderId: {}", vo.getOrderId());
return BaseResp.success(order);
} catch (Exception e) {
log.error("更新车务资料失败, 请求参数: {}", vo, e);
return BaseResp.fail("更新失败:" + e.getMessage());
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.entity.AccountTag;
import com.glsx.usedcar.module.account.service.AccountService;
import com.glsx.usedcar.module.account.service.FavoriteService;
import com.glsx.usedcar.module.account.service.PlatformContractService;
import com.glsx.usedcar.module.auction.service.AuctionOrderService;
import com.glsx.usedcar.module.auction.service.BidService;
import com.glsx.usedcar.web.AccountJwtProvider;
......@@ -44,6 +45,8 @@ public class AccountController {
private AuctionOrderService auctionOrderService;
@Resource
private BidService bidService;
@Resource
private PlatformContractService platformContractService;
/**
* JWT认证服务
*/
......@@ -95,6 +98,10 @@ public class AccountController {
Account accountById = accountService.getAccountById(account.getAccountId());
AccountInfo accountInfo = new AccountInfo(accountById);
accountInfo.setToken(jwtProvider.generateAccount(accountById));
// 设置签署截止时间(用于前端判断是否可以重新发起签署)
accountInfo.setSignDeadline(platformContractService.getSignDeadline(account.getAccountId()));
return accountInfo;
}
......
package com.glsx.usedcar.web.api.account;
import com.glsx.usedcar.esign.exception.EsignDemoException;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.entity.PlatformContract;
import com.glsx.usedcar.module.account.service.AccountService;
import com.glsx.usedcar.module.account.service.PlatformContractService;
import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.BusinessException;
import java.time.LocalDateTime;
import static com.glsx.usedcar.web.WebConstants.LOGIN_ACCOUNT;
/**
* 平台合同接口
* <p>
* 账户级平台交易整体合同,一次签署长期有效
* </p>
*
* @since 2026-08-05
*/
@Slf4j
@RestController
@RequestMapping("/api/platformContract")
@RequiredArgsConstructor
@Tag(name = "平台合同接口", description = "平台合同签署操作")
public class PlatformContractController {
private final PlatformContractService platformContractService;
private final AccountService accountService;
/**
* 发起平台合同签署
* <p>
* 适用场景:
* 1. 审核通过后发起签署
* 2. 签署链接过期后重新发起
* </p>
* <p>
* 返回值说明:
* - 返回签署链接:需要用户点击链接完成签署
* - 返回"已签署平台合同":用户已完成签署,无需重复操作
* </p>
*
* @param account 登录账户
* @return 签署链接
*/
@PostMapping("/initiateSigning")
@Operation(summary = "发起平台合同签署", description = "发起平台合同签署,返回签署链接。如已签署则提示无需重复操作")
public BaseResp<String> initiateSigning(@RequestAttribute(LOGIN_ACCOUNT) Account account) {
int accountId = account.getAccountId();
log.info("发起平台合同签署, accountId: {}", accountId);
// 检查是否已签署
if (platformContractService.hasSignedPlatformContract(accountId)) {
log.info("账户已签署平台合同,无需重复发起, accountId: {}", accountId);
return BaseResp.success("已签署平台合同");
}
// 检查是否有签署中且有效的合同
LocalDateTime signDeadline = platformContractService.getSignDeadline(accountId);
LocalDateTime now = LocalDateTime.now();
if (signDeadline != null && signDeadline.isAfter(now)) {
log.info("签署链接仍在有效期内, accountId: {}, signDeadline: {}", accountId, signDeadline);
throw new BusinessException("签署链接仍在有效期内,请查收短信或稍后再试");
}
// 获取完整的账户信息
Account fullAccount = accountService.getAccountById(accountId);
// 检查认证状态
if (fullAccount.getCertifiedState() != Account.CertifiedState.CERTIFIED) {
log.warn("账户未完成认证,无法发起签署, accountId: {}, certifiedState: {}",
accountId, fullAccount.getCertifiedState());
throw new BusinessException("请先完成认证后再签署平台合同");
}
try {
// 构建平台合同
PlatformContract contract = platformContractService.buildPlatformContractFile(fullAccount);
if (contract == null) {
log.warn("构建平台合同失败, accountId: {}", accountId);
throw new BusinessException("构建平台合同失败,请稍后重试");
}
// 创建并发起签署
String signUrl = platformContractService.createPlatformContract(contract);
log.info("平台合同签署流程创建成功, accountId: {}", accountId);
return BaseResp.success(signUrl);
} catch (EsignDemoException e) {
log.error("e签宝签署失败, accountId: {}", accountId, e);
throw new BusinessException("签署失败,请稍后重试");
} catch (IllegalStateException e) {
log.error("平台合同签署异常, accountId: {}", accountId, e);
throw new BusinessException(e.getMessage());
}
}
}
......@@ -278,4 +278,24 @@ public class AuctionOrderController {
public List<Contract> getContractsByOrderId(@RequestParam int orderId) {
return contractService.getContractsByOrderId(orderId);
}
/**
* 确认提车(无交付合同签署依赖)
* <p>
* 简化后的确认提车流程:用户直接点击确认提车,无需签署交付合同
* 订单状态从待提车变为待过户
* </p>
*
* @param orderId 订单ID
* @param account 当前账户
* @return 更新后的订单
*/
@PostMapping("confirmPickup")
public AuctionOrder confirmPickup(@RequestParam int orderId, @RequestAttribute(LOGIN_ACCOUNT) Account account) {
try {
return auctionOrderService.confirmPickup(orderId, account);
} catch (FieldException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
\ No newline at end of file
......@@ -2,16 +2,12 @@ package com.glsx.usedcar.web.api.esign;
import com.glsx.usedcar.esign.ESignService;
import com.glsx.usedcar.esign.SignMissionComplete;
import com.glsx.usedcar.esign.comm.EsignHttpResponse;
import com.glsx.usedcar.module.account.entity.PlatformContract;
import com.glsx.usedcar.module.account.service.PlatformContractService;
import com.glsx.usedcar.module.auction.entity.Contract;
import com.glsx.usedcar.module.auction.service.ContractService;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -26,6 +22,8 @@ public class ESignController {
private ContractService contractService;
@Resource
private ESignService eSignService;
@Resource
private PlatformContractService platformContractService;
/**
......@@ -47,9 +45,24 @@ public class ESignController {
// 流程结束通知
if ("2".equals(signMissionComplete.getSignFlowStatus())) {
String signFlowId = signMissionComplete.getSignFlowId();
// 先尝试处理拍卖/交付合同
Contract contract = contractService.signContract(signFlowId);
// 下载合同文件
eSignService.downloadContractFile(contract);
if (contract != null) {
// 下载合同文件
eSignService.downloadContractFile(contract);
log.info("拍卖/交付合同签署完成, signFlowId: {}, contractId: {}", signFlowId, contract.getContractId());
} else {
// 尝试处理平台合同
PlatformContract platformContract =
platformContractService.signPlatformContract(signFlowId);
if (platformContract != null) {
log.info("平台合同签署完成, signFlowId: {}, accountId: {}",
signFlowId, platformContract.getAccount().getAccountId());
} else {
log.warn("未找到对应的签署流程, signFlowId: {}", signFlowId);
}
}
}
break;
default:
......
package com.glsx.usedcar.converts;
import com.glsx.usedcar.module.account.entity.PlatformContract;
import com.glsx.usedcar.module.account.vo.PlatformContractPageRespVO;
import com.glsx.usedcar.module.account.vo.PlatformContractRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import java.util.List;
/**
* 平台合同实体转换器
*
* @author yangwei
* @since 2026-08-04
*/
@Mapper(componentModel = "spring")
public interface PlatformContractConverter {
/**
* 单个实体转换为详情VO
*
* @param contract 平台合同实体
* @return 平台合同详情响应VO
*/
@Mapping(target = "accountId", source = "account.accountId")
@Mapping(target = "accountName", source = "account.accountName")
@Mapping(target = "accountMobile", source = "account.mobile")
@Mapping(target = "contractStatusDesc", expression = "java(getContractStatusDesc(contract.getContractStatus()))")
PlatformContractRespVO toRespVO(PlatformContract contract);
/**
* 单个实体转换为分页列表VO
*
* @param contract 平台合同实体
* @return 平台合同分页响应VO
*/
@Mapping(target = "accountId", source = "account.accountId")
@Mapping(target = "accountName", source = "account.accountName")
@Mapping(target = "accountMobile", source = "account.mobile")
@Mapping(target = "contractStatusDesc", expression = "java(getContractStatusDesc(contract.getContractStatus()))")
PlatformContractPageRespVO toPageRespVO(PlatformContract contract);
/**
* 多个实体转换为VO列表
*
* @param contracts 平台合同实体列表
* @return 平台合同响应VO列表
*/
List<PlatformContractRespVO> toRespVOList(List<PlatformContract> contracts);
/**
* 获取合同状态描述
*/
default String getContractStatusDesc(PlatformContract.ContractStatus status) {
if (status == null) {
return null;
}
return switch (status) {
case PENDING -> "待签署";
case SIGNING -> "签署中";
case SIGNED -> "已签署";
case EXPIRED -> "已过期";
case CANCELLED -> "已作废";
};
}
}
package com.glsx.usedcar.esign;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.auction.entity.AuctionOrder;
import com.glsx.usedcar.module.auction.entity.Contract;
import com.glsx.usedcar.module.coupon.entity.CouponOrderUsage;
......@@ -168,6 +169,29 @@ public record DocTemplateRequest(String docTemplateId, String fileName, List<Com
return new DocTemplateRequest(docTemplateId, fileName, components);
}
/**
* 构建平台合同模板请求
*
* @param docTemplateId e签宝模板ID
* @param account 签约账户
* @param platformSignCompanyName 平台方签约公司名称
* @return 平台合同模板请求
*/
public static DocTemplateRequest ofPlatform(String docTemplateId, Account account, String platformSignCompanyName) {
String fileName = account.getAccountName() + "_平台交易整体合同";
List<Component> components = new ArrayList<>();
// 平台方信息(甲方)
components.add(new Component("platformSignCompanyName", platformSignCompanyName));
// signDate 由签名区域的 SignDateConfig 自动填充,无需预先填入
// 客户信息(乙方)
components.add(new Component("signCustomerName", fillBlank(account.getAccountName())));
// customerSignDate 由签名区域的 SignDateConfig 自动填充,无需预先填入
return new DocTemplateRequest(docTemplateId, fileName, components);
}
private static String fillBlank(String str) {
if (str == null || str.trim().isEmpty()) {
return "";
......
package com.glsx.usedcar.gsc;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 收车端接口调用客户端
* <p>
* 用于从收车端同步过户资料(electronicContractField)数据
* </p>
*/
@Slf4j
@Component
public class ReceiveClient {
@Value("${gsc.url}")
private String gscUrl;
@Value("${gsc.secret}")
private String secret;
private static final ObjectMapper objectMapper = new ObjectMapper();
@Resource
private RestTemplate restTemplate;
/**
* 批量查询车辆过户资料
* <p>
* 调用收车端接口: POST /auction/electronicContractField/batch
* </p>
*
* @param sourceNos 车源号列表(评估单编号)
* @return 过户资料Map (sourceNo -> electronicContractField JSON)
*/
public Map<String, String> batchQueryElectronicContractField(List<String> sourceNos) {
if (sourceNos == null || sourceNos.isEmpty()) {
return new HashMap<>();
}
String url = gscUrl + "/auction/electronicContractField/batch";
try {
// 构建请求头(使用与 GscInvoker 相同的签名逻辑)
HttpHeaders headers = buildHeaders(sourceNos);
HttpEntity<List<String>> requestEntity = new HttpEntity<>(sourceNos, headers);
@SuppressWarnings("unchecked")
ResponseResult response = restTemplate.postForObject(url, requestEntity, ResponseResult.class);
if (response != null && response.isSuccess()) {
log.info("批量查询过户资料成功,sourceNos数量: {}", sourceNos.size());
@SuppressWarnings("unchecked")
Map<String, String> data = (Map<String, String>) response.getData();
return data != null ? data : new HashMap<>();
} else {
log.warn("批量查询过户资料失败: {}", response != null ? response.getMsg() : "响应为空");
return new HashMap<>();
}
} catch (Exception e) {
log.error("批量查询过户资料异常,sourceNos: {}", sourceNos, e);
return new HashMap<>();
}
}
/**
* 查询单个车辆过户资料
* <p>
* 调用收车端接口: GET /auction/electronicContractField?sourceNo={sourceNo}
* </p>
*
* @param sourceNo 车源号(评估单编号)
* @return electronicContractField JSON字符串
*/
public String queryElectronicContractField(String sourceNo) {
if (sourceNo == null || sourceNo.isEmpty()) {
return null;
}
String url = gscUrl + "/auction/electronicContractField?sourceNo=" + sourceNo;
try {
HttpHeaders headers = buildHeaders(sourceNo);
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
@SuppressWarnings("unchecked")
ResponseResult response = restTemplate.getForObject(url, ResponseResult.class);
if (response != null && response.isSuccess()) {
log.info("查询过户资料成功,sourceNo: {}", sourceNo);
return response.getData() != null ? response.getData().toString() : null;
} else {
log.warn("查询过户资料失败, sourceNo: {}, 原因: {}", sourceNo, response != null ? response.getMsg() : "响应为空");
return null;
}
} catch (Exception e) {
log.error("查询过户资料异常,sourceNo: {}", sourceNo, e);
return null;
}
}
/**
* 异步批量查询车辆过户资料
*
* @param sourceNos 车源号列表
* @param callback 回调函数,接收查询结果
*/
@Async
public void batchQueryElectronicContractFieldAsync(List<String> sourceNos, java.util.function.Consumer<Map<String, String>> callback) {
Map<String, String> result = batchQueryElectronicContractField(sourceNos);
if (callback != null) {
callback.accept(result);
}
}
/**
* 构建带签名的请求头(参考 GscInvoker 的签名逻辑)
*/
private HttpHeaders buildHeaders(Object requestData) {
String currentTimeMillis = String.valueOf(System.currentTimeMillis());
String randomNumeric = RandomStringUtils.randomNumeric(6);
// 构建签名参数
Map<String, Object> params = new HashMap<>();
params.put("X-App-Id", "auction_platform");
params.put("X-Timestamp", currentTimeMillis);
params.put("X-Nonce", randomNumeric);
HttpHeaders headers = new HttpHeaders();
headers.set("X-App-Id", "auction_platform");
headers.set("X-Sign", generateSign(params));
headers.set("X-Timestamp", currentTimeMillis);
headers.set("X-Nonce", randomNumeric);
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
/**
* 生成签名(参考 GscInvoker 的签名逻辑)
*/
private String generateSign(Map<String, Object> params) {
// 1. 参数排序
List<String> keys = new java.util.ArrayList<>(params.keySet());
java.util.Collections.sort(keys);
// 2. 拼接参数
StringBuilder sb = new StringBuilder();
for (String key : keys) {
if ("X-Sign".equals(key) || params.get(key) == null || "".equals(params.get(key))) {
continue;
}
sb.append(key).append("=").append(params.get(key)).append("&");
}
String stringToSign = sb.toString();
stringToSign = stringToSign + "secret=" + secret;
// 3. 计算HMAC-SHA256签名
return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secret).hmacHex(stringToSign);
}
}
package com.glsx.usedcar.module.account.dao;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.entity.PlatformContract;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.summerframework.orm.BaseRepository;
import java.util.List;
/**
* 平台合同(PlatformContract)表数据库访问层
*
* @since 2026-07-31
*/
public interface PlatformContractDao extends BaseRepository<PlatformContract, Integer>, JpaSpecificationExecutor<PlatformContract> {
/**
* 根据签署流程ID查询平台合同
*/
PlatformContract findTopBySignFlowId(String signFlowId);
/**
* 根据合同编号查询平台合同
*/
PlatformContract findByContractCode(String contractCode);
/**
* 根据账户查询平台合同列表
*/
List<PlatformContract> findByAccount_AccountIdOrderByCreateTimeDesc(int accountId);
/**
* 根据账户查询已签署的平台合同
*/
PlatformContract findTopByAccount_AccountIdAndContractStatusOrderByCreateTimeDesc(int accountId, PlatformContract.ContractStatus contractStatus);
/**
* 检查账户是否已签署平台合同
*/
boolean existsByAccount_AccountIdAndContractStatus(int accountId, PlatformContract.ContractStatus contractStatus);
}
......@@ -6,6 +6,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import org.summerframework.storage.domain.FileInfo;
import java.time.LocalDateTime;
@Getter
@Setter
@NoArgsConstructor
......@@ -43,6 +45,27 @@ public class AccountInfo {
*/
private boolean supper;
/**
* 是否已签署平台合同
*/
private boolean platformContractSigned;
/**
* 平台合同签署时间(已签署时才有值)
*/
private LocalDateTime platformContractSignTime;
/**
* 当前签署中合同的签署截止时间
* <p>
* 用于前端判断是否可以重新发起签署:
* - null:没有签署中的合同,可以发起新的
* - 大于当前时间:签署链接还有效,不需要重新发起
* - 小于等于当前时间:已过期,可以重新发起
* </p>
*/
private LocalDateTime signDeadline;
public AccountInfo(Account account) {
setAccountInfo(account);
}
......@@ -59,6 +82,8 @@ public class AccountInfo {
this.openId = account.getOpenId();
this.surplus = account.getSurplus();
this.supper = account.isSupper();
this.idCard=account.getIdCard();
this.idCard = account.getIdCard();
this.platformContractSigned = account.isPlatformContractSigned();
this.platformContractSignTime = account.getPlatformContractSignTime();
}
}
......@@ -225,6 +225,18 @@ public class Account extends AuditingTimeEntity implements Serializable {
private String disableReason;
/**
* 是否已签署平台合同
*/
@Column(nullable = false)
private boolean platformContractSigned = false;
/**
* 平台合同签署时间
*/
@Column
private LocalDateTime platformContractSignTime;
/**
* account_groups
*/
@ManyToMany(targetEntity = AccountTag.class, cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY)
......@@ -263,6 +275,12 @@ public class Account extends AuditingTimeEntity implements Serializable {
private Set<Withdraw> withdraws = new HashSet<>(0);
/**
* platform_contract
*/
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "account")
private Set<PlatformContract> platformContracts = new HashSet<>(0);
/**
* 累计成交数量
*/
@Transient
......
package com.glsx.usedcar.module.account.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingTimeEntity;
import org.summerframework.storage.converter.FileInfosConverter;
import org.summerframework.storage.domain.FileInfo;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import static jakarta.persistence.GenerationType.IDENTITY;
/**
* 平台合同(PlatformContract)实体类
* <p>
* 账户级平台交易整体合同,一次签署长期有效,独立于拍卖订单
* </p>
*/
@Entity
@DynamicInsert
@DynamicUpdate
@Table
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@NoArgsConstructor
public class PlatformContract extends AuditingTimeEntity implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(unique = true, nullable = false)
private int platformContractId;
/**
* 关联账户
*/
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "ACCOUNT_ID", nullable = false)})
private Account account;
/**
* 合同编号
*/
@Column(nullable = false, length = 64, unique = true)
private String contractCode;
/**
* 合同名称
*/
@Column(nullable = false, length = 128)
private String contractName;
/**
* 签署人姓名
*/
@Column(nullable = false, length = 128)
private String signerName;
/**
* 签署人手机号
*/
@Column(nullable = false, length = 16)
private String signerMobile;
/**
* 签署人身份证
*/
@Column(length = 32)
private String signerIdCard;
/**
* 合同状态
*/
@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 32)
private ContractStatus contractStatus = ContractStatus.PENDING;
/**
* 合同内容
*/
@Column(columnDefinition = "TEXT")
private String contractContent;
/**
* 合同附件
*/
@Convert(converter = FileInfosConverter.class)
@Column
private List<FileInfo> contractFiles;
/**
* e签宝文件ID
*/
@Column(length = 64)
private String fileId;
/**
* 合同签署流程ID
*/
@Column(length = 64)
private String signFlowId;
/**
* 签署时间
*/
@Column
private LocalDateTime signTime;
/**
* 签署截止时间(超时后需重新发起)
*/
@Column
private LocalDateTime signDeadline;
/**
* 合同附件路径(本地临时文件路径)
*/
@Column
private String filePath;
/**
* 合同状态枚举
*/
public enum ContractStatus {
/**
* 待签署
*/
PENDING,
/**
* 签署中
*/
SIGNING,
/**
* 已签署
*/
SIGNED,
/**
* 已过期(未在规定时间内签署)
*/
EXPIRED,
/**
* 已作废
*/
CANCELLED;
}
/**
* 创建平台合同
*/
public PlatformContract(Account account, String contractCode, String contractName,
String signerName, String signerMobile, String signerIdCard) {
this.account = account;
this.contractCode = contractCode;
this.contractName = contractName;
this.signerName = signerName;
this.signerMobile = signerMobile;
this.signerIdCard = signerIdCard;
this.contractStatus = ContractStatus.PENDING;
}
}
......@@ -18,6 +18,7 @@ import com.glsx.usedcar.module.meta.AuditState;
import com.glsx.usedcar.module.track.dao.ApproveHistoryDao;
import com.glsx.usedcar.module.track.entity.ApproveHistory;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.ObjectNotFoundException;
import org.springframework.data.domain.Page;
......@@ -32,14 +33,20 @@ import org.summerframework.core.exception.FieldException;
import org.summerframework.orm.UpdateField;
import org.summerframework.orm.paging.Pagination;
import java.time.*;
import java.util.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 个人账户(Account) 服务实现类
*
* @since 2025-10-13 12:18:11
*/
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class AccountService extends AbstractAuctionService {
......@@ -62,6 +69,9 @@ public class AccountService extends AbstractAuctionService {
@Resource
private BidDao bidDao;
@Resource
private PlatformContractService platformContractService;
/**
* 通过ID查询一个个人账户
*
......@@ -293,12 +303,40 @@ public class AccountService extends AbstractAuctionService {
} else if (account.getAccountType() == Account.AccountType.PERSON) {
account.setAccountType(Account.AccountType.COMPANY);
}
// 审核通过后触发平台合同签署
triggerPlatformContractSigning(account);
} else {
account.setCertifiedState(Account.CertifiedState.CERTIFY_FAILED);
}
return approveHistoryDao.save(approveHistory);
}
/**
* 触发平台合同签署
* 审核通过后为账户创建平台合同并发起签署流程
*
* @param account 账户
*/
private void triggerPlatformContractSigning(Account account) {
try {
// 检查是否已签署平台合同
if (!platformContractService.hasSignedPlatformContract(account.getAccountId())) {
// 构建平台合同
PlatformContract contract = platformContractService.buildPlatformContractFile(account);
if (contract != null) {
// 创建并保存合同,触发e签宝签署流程(e签宝会自动发送短信给用户)
platformContractService.createPlatformContract(contract);
log.info("平台合同签署流程已创建, accountId: {}", account.getAccountId());
}
}
} catch (Exception e) {
// 平台合同签署失败不影响认证流程,记录日志即可
// 用户可以稍后手动触发签署
log.error("触发平台合同签署失败, accountId: {}", account.getAccountId(), e);
}
}
/**
* 更改用户wechat
......
package com.glsx.usedcar.module.account.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
/**
* 平台合同分页查询请求VO
*
* @author yangwei
* @since 2026-08-04
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "平台合同分页查询请求参数")
public class PlatformContractPageQueryVO {
@Schema(description = "页码,默认1(从1开始)", example = "1")
private Integer page;
@Schema(description = "每页条数,默认20", example = "20")
private Integer size;
@Schema(description = "合同编号,模糊匹配", example = "HT20260804")
private String contractCode;
@Schema(description = "签署人姓名,模糊匹配", example = "张三")
private String signerName;
@Schema(description = "签署人手机号,精确匹配", example = "13800138000")
private String signerMobile;
@Schema(description = "合同状态:PENDING-待签署/SIGNING-签署中/SIGNED-已签署/EXPIRED-已过期/CANCELLED-已作废", example = "SIGNED")
private String contractStatus;
@Schema(description = "账户ID", example = "1")
private Integer accountId;
@Schema(description = "账户名称,模糊匹配", example = "李四")
private String accountName;
@Schema(description = "创建时间-起始", example = "2026-08-01")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private LocalDate createTimeStart;
@Schema(description = "创建时间-结束", example = "2026-08-04")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private LocalDate createTimeEnd;
}
package com.glsx.usedcar.module.account.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* 平台合同分页查询响应VO
*
* @author yangwei
* @since 2026-08-04
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "平台合同分页查询响应")
public class PlatformContractPageRespVO {
@Schema(description = "平台合同ID")
private Integer platformContractId;
@Schema(description = "合同编号")
private String contractCode;
@Schema(description = "合同名称")
private String contractName;
@Schema(description = "账户ID")
private Integer accountId;
@Schema(description = "账户名称")
private String accountName;
@Schema(description = "账户手机号")
private String accountMobile;
@Schema(description = "签署人姓名")
private String signerName;
@Schema(description = "签署人手机号")
private String signerMobile;
@Schema(description = "签署人身份证")
private String signerIdCard;
@Schema(description = "合同状态:PENDING-待签署/SIGNING-签署中/SIGNED-已签署/EXPIRED-已过期/CANCELLED-已作废")
private String contractStatus;
@Schema(description = "合同状态描述")
private String contractStatusDesc;
@Schema(description = "签署时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime signTime;
@Schema(description = "签署截止时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime signDeadline;
@Schema(description = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
}
package com.glsx.usedcar.module.account.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.summerframework.storage.domain.FileInfo;
import java.time.LocalDateTime;
import java.util.List;
/**
* 平台合同详情响应VO
*
* @author yangwei
* @since 2026-08-04
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "平台合同详情响应")
public class PlatformContractRespVO {
@Schema(description = "平台合同ID")
private Integer platformContractId;
@Schema(description = "合同编号")
private String contractCode;
@Schema(description = "合同名称")
private String contractName;
@Schema(description = "账户ID")
private Integer accountId;
@Schema(description = "账户名称")
private String accountName;
@Schema(description = "账户手机号")
private String accountMobile;
@Schema(description = "签署人姓名")
private String signerName;
@Schema(description = "签署人手机号")
private String signerMobile;
@Schema(description = "签署人身份证")
private String signerIdCard;
@Schema(description = "合同状态:PENDING-待签署/SIGNING-签署中/SIGNED-已签署/EXPIRED-已过期/CANCELLED-已作废")
private String contractStatus;
@Schema(description = "合同状态描述")
private String contractStatusDesc;
@Schema(description = "合同内容")
private String contractContent;
@Schema(description = "合同附件")
private List<FileInfo> contractFiles;
@Schema(description = "e签宝文件ID")
private String fileId;
@Schema(description = "合同签署流程ID")
private String signFlowId;
@Schema(description = "签署时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime signTime;
@Schema(description = "签署截止时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime signDeadline;
@Schema(description = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
@Schema(description = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime updateTime;
}
......@@ -122,6 +122,20 @@ public class AuctionOrder extends AuditingEntity implements Serializable {
private List<FileInfo> vehicleLicense;
/**
* 过户发票PDF
*/
@Convert(converter = FileInfosConverter.class)
@Column(nullable = true)
private List<FileInfo> transferInvoice;
/**
* 新车主身份证照片
*/
@Convert(converter = FileInfosConverter.class)
@Column(nullable = true)
private List<FileInfo> newOwnerIdCard;
/**
* 成交价
*/
@Column
......@@ -232,7 +246,7 @@ public class AuctionOrder extends AuditingEntity implements Serializable {
this.account = account;
this.vehicle = vehicle;
this.auction = auction;
this.orderState = OrderState.CONTRACT_UNSIGNED;
this.orderState = OrderState.UNPAID;
}
/**
......@@ -268,8 +282,10 @@ public class AuctionOrder extends AuditingEntity implements Serializable {
public enum OrderState {
/**
* 待签署合同
* 待签署合同(已废弃,历史数据已迁移为 UNPAID)
* @deprecated 使用 UNPAID 代替
*/
@Deprecated
CONTRACT_UNSIGNED,
/**
* 待付车款
......
......@@ -92,6 +92,12 @@ public class ContractTemplate extends AuditingEntity implements Serializable {
@Column(nullable = true, length = 128)
private String esignId;
/**
* 平台方签约公司名称(仅平台合同模板需要)
*/
@Column(nullable = true, length = 128)
private String platformSignCompanyName;
public enum TemplateType {
/**
* 拍卖合同
......@@ -100,6 +106,10 @@ public class ContractTemplate extends AuditingEntity implements Serializable {
/**
* 交付合同
*/
DELIVERY;
DELIVERY,
/**
* 平台交易整体合同
*/
PLATFORM;
}
}
\ No newline at end of file
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;
import java.util.List;
/**
* 后台代上传付款凭证请求VO
*
* @author claude
* @since 2026-08-05
*/
@Data
@Schema(description = "后台代上传付款凭证请求参数")
public class ProxyUploadPayVoucherVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@NotNull(message = "订单ID不能为空")
@Schema(description = "订单ID", required = true, example = "1")
private Integer orderId;
@Schema(description = "付款凭证文件列表")
private List<FileInfo> payVouchers;
}
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;
import java.util.List;
/**
* 后台代上传过户资料请求VO
*
* @author claude
* @since 2026-08-05
*/
@Data
@Schema(description = "后台代上传过户资料请求参数")
public class ProxyUploadTransferMaterialsVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@NotNull(message = "订单ID不能为空")
@Schema(description = "订单ID", required = true, example = "1")
private Integer orderId;
@Schema(description = "新车牌号")
private String newPlateNumber;
@Schema(description = "机动车登记证书")
private List<FileInfo> registrationCertificate;
@Schema(description = "机动车行驶证")
private List<FileInfo> vehicleLicense;
@Schema(description = "过户发票")
private List<FileInfo> transferInvoice;
@Schema(description = "新车主身份证")
private List<FileInfo> newOwnerIdCard;
}
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;
import java.util.List;
/**
* 更新车务资料请求VO
*
* @author claude
* @since 2026-08-05
*/
@Data
@Schema(description = "更新车务资料请求参数")
public class UpdateVehicleDocumentsVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@NotNull(message = "订单ID不能为空")
@Schema(description = "订单ID", required = true, example = "1")
private Integer orderId;
@Schema(description = "机动车登记证书")
private List<FileInfo> registrationCertificate;
@Schema(description = "机动车行驶证")
private List<FileInfo> vehicleLicense;
}
......@@ -24,6 +24,7 @@ import com.glsx.usedcar.module.meta.AuditState;
import com.glsx.usedcar.module.track.dao.ApproveHistoryDao;
import com.glsx.usedcar.module.track.entity.ApproveHistory;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import com.glsx.usedcar.module.venue.entity.Outbound;
import com.glsx.usedcar.module.vrsystem.service.VrAuditService;
import com.glsx.usedcar.resp.BaseResp;
import com.glsx.usedcar.util.CoderGenerator;
......@@ -219,13 +220,6 @@ public class AuctionOrderService extends AbstractAuctionService {
CompletableFuture<Long> totalFuture = CompletableFuture.supplyAsync(() ->
pageAuctionOrder(pagination.copyForCount()).getTotalElements(), ioIntensiveExecutor);
// 待签署合同
CompletableFuture<Long> contractUnsignedFuture = CompletableFuture.supplyAsync(() -> {
Pagination<AuctionOrder> p = pagination.copyForCount();
p.addFilter(AuctionOrder.OrderState.CONTRACT_UNSIGNED, org.summerframework.orm.paging.Operator.eq, AuctionOrder_.orderState);
return pageAuctionOrder(p).getTotalElements();
}, ioIntensiveExecutor);
// 待付车款
CompletableFuture<Long> unpaidFuture = CompletableFuture.supplyAsync(() -> {
Pagination<AuctionOrder> p = pagination.copyForCount();
......@@ -261,12 +255,12 @@ public class AuctionOrderService extends AbstractAuctionService {
return pageAuctionOrder(p).getTotalElements();
}, ioIntensiveExecutor);
CompletableFuture.allOf(totalFuture, contractUnsignedFuture, unpaidFuture,
CompletableFuture.allOf(totalFuture, unpaidFuture,
waitPickupFuture, transferringFuture, completedFuture, canceledFuture).join();
return AuctionOrderStateCountRespVO.builder()
.total(totalFuture.join())
.contractUnsignedCount(contractUnsignedFuture.join())
.contractUnsignedCount(0L) // 已废弃,固定返回0
.unpaidCount(unpaidFuture.join())
.waitPickupCount(waitPickupFuture.join())
.transferringCount(transferringFuture.join())
......@@ -326,22 +320,51 @@ public class AuctionOrderService extends AbstractAuctionService {
/**
* 上传过户资料
* <p>
* 车商在待过户状态下上传过户资料,提交后进入审核中状态
* 支持上传:机动车登记证书、新机动车行驶证、新车牌号、过户发票PDF、新车主身份证照片
* </p>
*
* @param order
* @return
* @throws FieldException
* @param order 包含过户资料的订单对象
* @return 更新后的订单
* @throws FieldException 如果订单状态不正确
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public AuctionOrder uploadTransferAuctionOrder(AuctionOrder order) throws FieldException {
log.info("上传过户资料开始, orderId: {}, newPlateNumber: {}, hasRegistrationCertificate: {}, hasVehicleLicense: {}, hasTransferInvoice: {}, hasNewOwnerIdCard: {}",
order.getOrderId(),
order.getNewPlateNumber(),
order.getRegistrationCertificate() != null && !order.getRegistrationCertificate().isEmpty(),
order.getVehicleLicense() != null && !order.getVehicleLicense().isEmpty(),
order.getTransferInvoice() != null && !order.getTransferInvoice().isEmpty(),
order.getNewOwnerIdCard() != null && !order.getNewOwnerIdCard().isEmpty());
AuctionOrder auctionOrder = auctionOrderDao.findByOrderId(order.getOrderId());
if (!auctionOrder.equalsOrderState(AuctionOrder.OrderState.TRANSFERRING)) {
log.warn("上传过户资料失败, 订单状态不正确, orderId: {}, currentOrderState: {}, expectedOrderState: {}",
order.getOrderId(), auctionOrder.getOrderState(), AuctionOrder.OrderState.TRANSFERRING);
throw new FieldException("orderState", auctionOrder, "订单状态不正确");
}
// 设置为上传过户资料审核等待中
auctionOrder.setAuditState(AuditState.UNAUDITED);
// 更新过户资料字段
auctionOrder.setNewPlateNumber(order.getNewPlateNumber());
auctionOrder.setRegistrationCertificate(order.getRegistrationCertificate());
auctionOrder.setVehicleLicense(order.getVehicleLicense());
// 新增字段:过户发票PDF、新车主身份证照片
auctionOrder.setTransferInvoice(order.getTransferInvoice());
auctionOrder.setNewOwnerIdCard(order.getNewOwnerIdCard());
log.info("上传过户资料成功, orderId: {}, auditState: {}, newPlateNumber: {}, registrationCertificateCount: {}, vehicleLicenseCount: {}, transferInvoiceCount: {}, newOwnerIdCardCount: {}",
auctionOrder.getOrderId(),
auctionOrder.getAuditState(),
auctionOrder.getNewPlateNumber(),
auctionOrder.getRegistrationCertificate() != null ? auctionOrder.getRegistrationCertificate().size() : 0,
auctionOrder.getVehicleLicense() != null ? auctionOrder.getVehicleLicense().size() : 0,
auctionOrder.getTransferInvoice() != null ? auctionOrder.getTransferInvoice().size() : 0,
auctionOrder.getNewOwnerIdCard() != null ? auctionOrder.getNewOwnerIdCard().size() : 0);
// 发送通知消息
sendNoticeMessage(NoticeTemplate.TemplateType.TRANSFER_AUDIT, Map.of(
......@@ -395,6 +418,59 @@ public class AuctionOrderService extends AbstractAuctionService {
}
/**
* 确认提车(无交付合同签署依赖)
* <p>
* 简化后的确认提车流程:用户直接点击确认提车,无需签署交付合同
* 订单状态从待提车变为待过户
* </p>
*
* @param orderId 订单ID
* @param account 当前账户
* @return 更新后的订单
* @throws FieldException 如果订单状态不正确
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public AuctionOrder confirmPickup(int orderId, Account account) throws FieldException {
AuctionOrder auctionOrder = auctionOrderDao.findByOrderId(orderId);
// 校验订单归属
if (auctionOrder.getAccount().getAccountId() != account.getAccountId()) {
throw new FieldException("orderId", orderId, "无权操作此订单");
}
// 校验订单状态:必须为待提车
if (!auctionOrder.equalsOrderState(AuctionOrder.OrderState.WAIT_PICKUP)) {
throw new FieldException("orderState", auctionOrder, "订单状态不正确,仅待提车订单可确认提车");
}
// 更新订单状态为待过户
auctionOrder.resetOrderState(AuctionOrder.OrderState.TRANSFERRING, Vehicle.VehicleState.TRANSFERRING);
gscInvoker.pushAuction(auctionOrder);
// 进入待过户状态,将审核状态改为null
auctionOrder.setAuditState(null);
// 发送短信给用户,提醒用户上传过户资料
Vehicle vehicle = auctionOrder.getVehicle();
String vehicleName = vehicle.getBaseInfo().getCarSeriesName() + " " + vehicle.getBaseInfo().getCarTypeName();
Object[] args = {vehicleName, auctionOrder.getOrderCode(), "7"};
String message = messageSource.getMessage("sms.auction.order.transfer.notice", args, Locale.CHINESE);
String mobile = auctionOrder.getAccount().getMobile();
gscApiInvoker.sendMsg(mobile, message);
log.info("确认提车成功,发送短信 to {} for transfer notice: {} ", mobile, message);
// 记录出库记录
Outbound outbound = new Outbound(auctionOrder, Outbound.OutboundType.AUTO, Outbound.OutboundMethod.DELIVERY);
// 保存出库记录需要注入 OutboundDao
// outboundDao.save(outbound);
AuctionVehicle auctionAndVehicle = auctionVehicleDao.findTopByAuctionAndVehicle(auctionOrder.getAuction(), auctionOrder.getVehicle());
vrAuditService.syncVrAuditStatus(auctionAndVehicle);
return auctionOrder;
}
/**
* 通过拍卖订单主键删除数据
*
* @param orderId 主键
......@@ -413,6 +489,17 @@ public class AuctionOrderService extends AbstractAuctionService {
return (int) auctionOrderDao.countByAccountAndOrderState(account, orderState);
}
/**
* 更新拍卖订单(用于后台代上传等场景)
*
* @param auctionOrder 拍卖订单
* @return 更新后的订单
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public AuctionOrder updateAuctionOrder(AuctionOrder auctionOrder) {
return auctionOrderDao.save(auctionOrder);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void autoGenerateAuctionOrders() {
LocalDateTime now = LocalDateTime.now();
......@@ -468,7 +555,7 @@ public class AuctionOrderService extends AbstractAuctionService {
auctionOrder.setCommissionPrice(commissionPrice);
auctionOrder = auctionOrderDao.save(auctionOrder);
auctionVehicle.setAuctionState(AuctionVehicle.AuctionState.SOLD);
vehicle.setVehicleState(Vehicle.VehicleState.CONTRACT_UNSIGNED);
vehicle.setVehicleState(Vehicle.VehicleState.UNPAID);
// 更新已经拍卖数量
auction.setAuctionedCount((int) auctionVehicleDao.countByAuctionStateAndAuction(AuctionVehicle.AuctionState.SOLD, auction));
// 退还保证金
......
......@@ -2,6 +2,7 @@ package com.glsx.usedcar.module.auction.service;
import com.glsx.usedcar.module.account.dao.AccountDao;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.service.PlatformContractService;
import com.glsx.usedcar.module.analysis.domain.IndexValue;
import com.glsx.usedcar.module.auction.dao.*;
import com.glsx.usedcar.module.auction.domain.BidStat;
......@@ -62,6 +63,9 @@ public class BidService {
@Autowired
private LightAuctionPoollingBidService lightAuctionPoollingBidService;
@Resource
private PlatformContractService platformContractService;
/**
* 通过ID查询一个投标竞价
......@@ -147,6 +151,11 @@ public class BidService {
throw new FieldException("accountId", accountId, "你已被禁止竞价");
}
// 检查是否已签署平台合同(历史已认证用户首次出价需签署平台合同)
if (account.getCertifiedState() == Account.CertifiedState.CERTIFIED && !platformContractService.hasSignedPlatformContract(accountId)) {
throw new FieldException("platformContract", accountId, "请先签署平台交易整体合同");
}
Auction auction = auctionVehicle.getAuction();
// 用户标签校验
if (auction.getAccessScope() == Auction.AccessScope.TAGS && !auction.getAccountTags().isEmpty()) {
......
......@@ -249,6 +249,9 @@ public class ContractService {
/**
* 签署合同
* 注意:拍卖合同和交付合同的状态流转逻辑已移除
* - 订单初始状态已改为 UNPAID,不再需要拍卖合同签署后流转
* - 确认提车不再需要签署交付合同
*
* @param signFlowId 签署流程ID
* @return 合同实例对象
......@@ -259,43 +262,8 @@ public class ContractService {
if (Objects.nonNull(contract)) {
contract.setSigned(true);
contract.setSignTime(LocalDateTime.now());
AuctionOrder auctionOrder = contract.getAuctionOrder();
if (contract.getTemplateType() == ContractTemplate.TemplateType.AUCTION) {
// 拍卖合同签署成功,订单状态改为待支付
if (auctionOrder.equalsOrderState(AuctionOrder.OrderState.CONTRACT_UNSIGNED)) {
auctionOrder.resetOrderState(AuctionOrder.OrderState.UNPAID, Vehicle.VehicleState.UNPAID);
DeliveryOrder deliveryOrder = generateDeliveryOrder(auctionOrder);
// 推送交付工单
AuctionVehicle auctionAndVehicle = auctionVehicleDao.findTopByAuctionAndVehicle(auctionOrder.getAuction(), auctionOrder.getVehicle());
gscInvoker.pushAuction(auctionAndVehicle, auctionOrder);
gscInvoker.pushDeliveryOrder(deliveryOrder, auctionAndVehicle);
vrAuditService.syncVrAuditStatus(auctionAndVehicle);
}
} else if (contract.getTemplateType() == ContractTemplate.TemplateType.DELIVERY) {
// 交付合同签署成功,订单状态改为待过户状态
if (auctionOrder.equalsOrderState(AuctionOrder.OrderState.WAIT_PICKUP)) {
auctionOrder.resetOrderState(AuctionOrder.OrderState.TRANSFERRING, Vehicle.VehicleState.TRANSFERRING);
gscInvoker.pushAuction(auctionOrder);
gscInvoker.signFinishDeliveryOrder(auctionOrder);
// 进入待过户状态,将审核状态改为null
auctionOrder.setAuditState(null);
// 发送短信给用户,提醒用户上传过户资料
Vehicle vehicle = auctionOrder.getVehicle();
String vehicleName = vehicle.getBaseInfo().getCarSeriesName() + " " + vehicle.getBaseInfo().getCarTypeName();
Object[] args = {vehicleName, auctionOrder.getOrderCode(), "7"};
String message = messageSource.getMessage("sms.auction.order.transfer.notice", args, Locale.CHINESE);
String mobile = auctionOrder.getAccount().getMobile();
gscApiInvoker.sendMsg(mobile, message);
log.info("发送短信 to {} for transfer notice: {} ", mobile, message);
// 记录出库记录
Outbound outbound = new Outbound(auctionOrder, Outbound.OutboundType.AUTO, Outbound.OutboundMethod.DELIVERY);
outboundDao.save(outbound);
AuctionVehicle auctionAndVehicle = auctionVehicleDao.findTopByAuctionAndVehicle(auctionOrder.getAuction(), auctionOrder.getVehicle());
vrAuditService.syncVrAuditStatus(auctionAndVehicle);
}
}
// 拍卖合同和交付合同签署后不再触发状态流转
// 订单初始状态已改为 UNPAID,确认提车不再需要签署交付合同
}
return contract;
}
......
......@@ -13,16 +13,22 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.summerframework.orm.paging.Pagination;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 交付订单(DeliveryOrder) 服务实现类
* <p>
*
* @deprecated 交付单功能已废弃,新订单不再创建交付单。
* 车商确认提车不再依赖交付单,历史交付单数据仍可查询。
* 相关方法保留用于历史数据查询。
* </p>
*
* @since 2025-10-13 12:18:11
*/
@Deprecated
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class DeliveryOrderService {
......@@ -66,16 +72,12 @@ public class DeliveryOrderService {
*
* @param deliveryOrder 交付订单实例对象
* @return 交付订单实例对象
* @deprecated 交付单功能已废弃,新订单不再创建交付单,此方法始终返回 null
*/
@Deprecated
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public DeliveryOrder assignDeliveryOrder(DeliveryOrder deliveryOrder) {
DeliveryOrder deliveryOrderDb = deliveryOrderDao.updateById(deliveryOrder,
DeliveryOrder_.user,
DeliveryOrder_.remark
);
deliveryOrderDb.setAssignedTime(LocalDateTime.now());
deliveryOrderDb.setOrderState(DeliveryOrder.OrderState.UNDELIVERED);
return deliveryOrderDb;
return null;
}
/**
......@@ -83,18 +85,12 @@ public class DeliveryOrderService {
*
* @param deliveryOrder 交付订单实例对象
* @return 交付订单实例对象
* @deprecated 交付单功能已废弃,此方法始终返回 null
*/
@Deprecated
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public DeliveryOrder handleDeliveryOrder(DeliveryOrder deliveryOrder) {
DeliveryOrder deliveryOrderDb = deliveryOrderDao.updateById(deliveryOrder,
DeliveryOrder_.checkCertificate,
DeliveryOrder_.checkHandover,
DeliveryOrder_.checkKey,
DeliveryOrder_.checkIdCard,
DeliveryOrder_.vouchers
);
deliveryOrderDb.setOrderState(DeliveryOrder.OrderState.DELIVERED);
return deliveryOrderDb;
return null;
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
......@@ -106,14 +102,15 @@ public class DeliveryOrderService {
return deliveryOrderDb;
}
/**
* 确认客户到店
*
* @deprecated 交付单功能已废弃,此方法始终返回 null
*/
@Deprecated
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public DeliveryOrder confirmDeliveryOrderArrived(int deliveryOrderId) {
DeliveryOrder deliveryOrderDb = deliveryOrderDao.findById(deliveryOrderId).orElseThrow();
if (deliveryOrderDb.getOrderStatus() == 0) {
deliveryOrderDb.setOrderStatus(1);
deliveryOrderDb.setStatusText("客户到店");
}
return deliveryOrderDb;
return null;
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
......@@ -158,4 +155,4 @@ public class DeliveryOrderService {
public long countByVenueIdAndOrderState(int venueId, DeliveryOrder.OrderState orderState) {
return deliveryOrderDao.countByAuctionOrder_Vehicle_Venue_VenueIdAndOrderState(venueId, orderState);
}
}
\ No newline at end of file
}
......@@ -144,6 +144,15 @@ public class Agreement extends AuditingEntity implements Serializable {
*/
COUPON_5,
/**
* 购车合同
*/
PURCHASE_CONTRACT,
/**
* 平台交易整体合同
*/
PLATFORM_CONTRACT,
;
}
......
......@@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.summerframework.orm.paging.Pagination;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
......@@ -26,6 +27,16 @@ public class AgreementService {
private AgreementDao agreementDao;
/**
* 登录页需要展示的协议类型列表
*/
private static final List<Agreement.AgreementKey> LOGIN_AGREEMENT_KEYS = List.of(
Agreement.AgreementKey.ACCOUNT, // 用户协议
Agreement.AgreementKey.PRIVACY, // 隐私协议
Agreement.AgreementKey.PURCHASE_CONTRACT, // 购车合同
Agreement.AgreementKey.AUCTION // 竞拍规则
);
/**
* 通过ID查询一个协议管理
*
* @param agreementId 主键
......@@ -53,6 +64,34 @@ public class AgreementService {
}
/**
* 获取登录页需要展示的协议列表
* <p>
* 返回用户协议、隐私协议、购车合同、竞拍规则
* </p>
*
* @return 协议列表
*/
public List<Agreement> getLoginAgreements() {
List<Agreement> agreements = new ArrayList<>();
for (Agreement.AgreementKey key : LOGIN_AGREEMENT_KEYS) {
Agreement agreement = getAgreementByKey(key);
if (agreement != null) {
agreements.add(agreement);
}
}
return agreements;
}
/**
* 获取车商认证页需要展示的平台交易整体合同
*
* @return 平台交易整体合同
*/
public Agreement getPlatformContractAgreement() {
return getAgreementByKey(Agreement.AgreementKey.PLATFORM_CONTRACT);
}
/**
* 创建协议管理
*
* @param agreement 协议管理实例对象
......
package com.glsx.usedcar.module.vehicle.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.Getter;
import lombok.Setter;
import java.io.Serial;
import java.io.Serializable;
/**
* 过户资料勾选信息
* <p>
* 封装车辆过户所需资料的勾选状态,用于确认提车时展示随车资料信息
* </p>
* <p>
* 字段命名规范:
* <ul>
* <li>Java 字段名使用 lowerCamelCase(如 registrationCertificate)</li>
* <li>数据库字段名使用 has_ 前缀(如 has_registration_certificate),遵循阿里规范</li>
* <li>布尔类型使用 TINYINT(1) UNSIGNED,表示"是/否"概念</li>
* </ul>
* </p>
*/
@Embeddable
@Getter
@Setter
public class TransferMaterials implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 机动车登记本(大绿本)
* 1-有, 0-无
*/
@Column(name = "has_registration_certificate", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean registrationCertificate = false;
/**
* 机动车行驶证
* 1-有, 0-无
*/
@Column(name = "has_vehicle_license", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean vehicleLicense = false;
/**
* 交管12123截图
* 1-有, 0-无
*/
@Column(name = "has_traffic_app_screenshot", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean trafficAppScreenshot = false;
/**
* 车钥匙套数
*/
@Column(name = "car_key_count", nullable = false, columnDefinition = "TINYINT UNSIGNED DEFAULT 0")
private int carKeyCount = 0;
/**
* 交强险
* 1-有, 0-无
*/
@Column(name = "has_compulsory_insurance", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean compulsoryInsurance = false;
/**
* 过户授权委托书照片
* 1-有, 0-无
*/
@Column(name = "has_transfer_authorization_photo", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean transferAuthorizationPhoto = false;
/**
* 购置税证及收据
* 1-有, 0-无
*/
@Column(name = "has_purchase_tax_receipt", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean purchaseTaxReceipt = false;
/**
* 购车发票
* 1-有, 0-无
*/
@Column(name = "has_purchase_invoice", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean purchaseInvoice = false;
/**
* 商业保险单或卡
* 1-有, 0-无
*/
@Column(name = "has_commercial_insurance", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean commercialInsurance = false;
/**
* 其他资料
* 1-有, 0-无
*/
@Column(name = "has_other_materials", nullable = false, columnDefinition = "TINYINT(1) UNSIGNED DEFAULT 0")
private boolean otherMaterials = false;
/**
* 其他资料说明
*/
@Column(name = "other_materials_note", length = 500)
private String otherMaterialsNote;
}
......@@ -109,6 +109,12 @@ public class Vehicle extends AuditingEntity implements Serializable {
private OwnerInfo ownerInfo;
/**
* 过户资料勾选信息
*/
@Embedded
private TransferMaterials transferMaterials;
/**
* 车型数据json,
* json字段参考查博士文档https://doc.chaboshi.cn/web/shareDoc/f98cbf2e13c37f7fd39ccdaf2b61a295
*/
......@@ -116,6 +122,13 @@ public class Vehicle extends AuditingEntity implements Serializable {
private String carModelData;
/**
* 过户资料JSON(从收车端推送,用于解析到 TransferMaterials)
* 不持久化到数据库
*/
@Transient
private String electronicContractField;
/**
* 车辆所属场地
*/
@CachedProperty("Venue")
......@@ -360,8 +373,10 @@ public class Vehicle extends AuditingEntity implements Serializable {
*/
AUCTIONING,
/**
* 待签署合同
* 待签署合同(已废弃,历史数据已迁移为 UNPAID)
* @deprecated 使用 UNPAID 代替
*/
@Deprecated
CONTRACT_UNSIGNED,
/**
* 待付车款
......
package com.glsx.usedcar.module.vehicle.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.glsx.usedcar.consts.inspect.JpaQueryConstants;
import com.glsx.usedcar.enums.common.DeleteFlag;
import com.glsx.usedcar.enums.inspect.InspectionWorkOrderStatusEnum;
......@@ -12,15 +13,23 @@ import com.glsx.usedcar.module.auction.entity.dto.LightPollingBidConfigDTO;
import com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderRepository;
import com.glsx.usedcar.module.vehicle.dao.VehicleDao;
import com.glsx.usedcar.module.vehicle.dao.VehicleHistoryDao;
import com.glsx.usedcar.module.vehicle.domain.*;
import com.glsx.usedcar.module.vehicle.domain.CarImage;
import com.glsx.usedcar.module.vehicle.domain.VehicleHistoryProjection;
import com.glsx.usedcar.module.vehicle.domain.VehicleVenue;
import com.glsx.usedcar.module.vehicle.entity.*;
import com.glsx.usedcar.module.vehicle.vo.VehicleAutoBidVO;
import com.glsx.usedcar.module.vehicle.vo.VehicleStateCountRespVO;
import com.glsx.usedcar.module.venue.dao.*;
import com.glsx.usedcar.module.venue.entity.*;
import com.glsx.usedcar.module.venue.dao.AreaDao;
import com.glsx.usedcar.module.venue.dao.VenueDao;
import com.glsx.usedcar.module.venue.dao.WarehousingDao;
import com.glsx.usedcar.module.venue.entity.Area;
import com.glsx.usedcar.module.venue.entity.Venue;
import com.glsx.usedcar.module.venue.entity.Warehousing;
import com.glsx.usedcar.module.vrsystem.dao.VrAuditRepository;
import com.glsx.usedcar.module.vrsystem.dao.VrOrgRepository;
import com.glsx.usedcar.module.vrsystem.entity.*;
import com.glsx.usedcar.module.vrsystem.entity.VrAudit;
import com.glsx.usedcar.module.vrsystem.entity.VrAudit_;
import com.glsx.usedcar.module.vrsystem.entity.VrOrg;
import com.glsx.usedcar.resp.BaseResp;
import com.glsx.usedcar.util.CoderGenerator;
import jakarta.annotation.Resource;
......@@ -39,7 +48,6 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.summerframework.orm.paging.Filter;
import org.summerframework.orm.paging.Operator;
import org.summerframework.orm.paging.Pagination;
import org.summerframework.storage.domain.FileInfo;
......@@ -299,12 +307,108 @@ public class VehicleService {
vehicle.setVenue(venue);
}
}
// 解析过户资料字段(从收车端推送的 electronicContractField)
vehicle.setTransferMaterials(parseElectronicContractField(vehicle.getElectronicContractField()));
return vehicleDao.save(vehicle);
} else {
return null;
}
}
/**
* 从收车端 electronicContractField 解析过户资料信息
* <p>
* 收车端传递的 electronicContractField JSON 格式示例:
* {
* "registrationCertificate": true,
* "vehicleLicense": true,
* "trafficAppScreenshot": false,
* "carKeyCount": 2,
* "compulsoryInsurance": true,
* "transferAuthorizationPhoto": true,
* "purchaseTaxReceipt": false,
* "purchaseInvoice": true,
* "commercialInsurance": false,
* "otherMaterials": false,
* "otherMaterialsNote": "备注说明"
* }
* </p>
*
* @param electronicContractField JSON 字符串
* @return TransferMaterials 对象
*/
public TransferMaterials parseElectronicContractField(String electronicContractField) {
TransferMaterials transferMaterials = new TransferMaterials();
if (!StringUtils.hasText(electronicContractField)) {
return transferMaterials;
}
try {
JSONObject json = JSONUtil.parseObj(electronicContractField);
if (json.containsKey("registrationCertificate")) {
transferMaterials.setRegistrationCertificate(json.getBool("registrationCertificate", false));
}
if (json.containsKey("vehicleLicense")) {
transferMaterials.setVehicleLicense(json.getBool("vehicleLicense", false));
}
if (json.containsKey("trafficAppScreenshot")) {
transferMaterials.setTrafficAppScreenshot(json.getBool("trafficAppScreenshot", false));
}
if (json.containsKey("carKeyCount")) {
transferMaterials.setCarKeyCount(json.getInt("carKeyCount", 0));
}
if (json.containsKey("compulsoryInsurance")) {
transferMaterials.setCompulsoryInsurance(json.getBool("compulsoryInsurance", false));
}
if (json.containsKey("transferAuthorizationPhoto")) {
transferMaterials.setTransferAuthorizationPhoto(json.getBool("transferAuthorizationPhoto", false));
}
if (json.containsKey("purchaseTaxReceipt")) {
transferMaterials.setPurchaseTaxReceipt(json.getBool("purchaseTaxReceipt", false));
}
if (json.containsKey("purchaseInvoice")) {
transferMaterials.setPurchaseInvoice(json.getBool("purchaseInvoice", false));
}
if (json.containsKey("commercialInsurance")) {
transferMaterials.setCommercialInsurance(json.getBool("commercialInsurance", false));
}
if (json.containsKey("otherMaterials")) {
transferMaterials.setOtherMaterials(json.getBool("otherMaterials", false));
}
if (json.containsKey("otherMaterialsNote")) {
transferMaterials.setOtherMaterialsNote(json.getStr("otherMaterialsNote"));
}
log.info("解析 electronicContractField 成功: {}", electronicContractField);
} catch (Exception e) {
log.warn("解析 electronicContractField 失败: {}", electronicContractField, e);
}
return transferMaterials;
}
/**
* 更新车辆过户资料信息(从收车端同步)
*
* @param vehicleId 车辆ID
* @param electronicContractField 过户资料JSON字符串
* @return 更新后的车辆
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public Vehicle updateTransferMaterials(int vehicleId, String electronicContractField) {
Vehicle vehicle = vehicleDao.findById(vehicleId)
.orElseThrow(() -> new ObjectNotFoundException(vehicleId, Vehicle.class.getSimpleName()));
TransferMaterials transferMaterials = parseElectronicContractField(electronicContractField);
vehicle.setTransferMaterials(transferMaterials);
return vehicleDao.save(vehicle);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public Vehicle addVehicle(Vehicle vehicle) {
vehicle.getBaseInfo().setSourceNo(CoderGenerator.generateSourceNO());
......
......@@ -1167,6 +1167,10 @@ public class VrAuditService {
ownerInfo.setPreviousOwnerPhone(""); // 车主联系方式,默认空
vehicle.setOwnerInfo(ownerInfo);
// 设置过户资料勾选信息 TransferMaterials(默认值:全部为"无"或0)
TransferMaterials transferMaterials = new TransferMaterials();
vehicle.setTransferMaterials(transferMaterials);
// 设置车辆图片 carImages
List<CarImage> carImages = buildCarImages(vrAudit);
vehicle.setCarImages(carImages);
......
package com.glsx.usedcar.task;
import com.glsx.usedcar.gsc.ReceiveClient;
import com.glsx.usedcar.module.vehicle.dao.VehicleDao;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import com.glsx.usedcar.module.vehicle.entity.Vehicle_;
import com.glsx.usedcar.module.vehicle.service.VehicleService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 过户资料同步定时任务
* <p>
* 从收车端同步存量车辆的过户资料(electronicContractField)数据
* </p>
*/
@Slf4j
@Component
public class TransferMaterialsSyncSchedule {
@Resource
private VehicleDao vehicleDao;
@Resource
private VehicleService vehicleService;
@Resource
private ReceiveClient receiveClient;
/**
* 每批次处理数量
*/
private static final int BATCH_SIZE = 100;
/**
* 定时同步过户资料
* <p>
* 每小时执行一次,同步收车端来源的车辆过户资料
* </p>
*/
@Scheduled(fixedDelay = 1000 * 60 * 60, initialDelay = 1000 * 60 * 5)
public void syncTransferMaterials() {
log.info("开始执行过户资料同步定时任务");
int totalSynced = 0;
int totalFailed = 0;
// 分页查询收车端来源的车辆
int page = 0;
Page<Vehicle> vehiclePage;
do {
Specification<Vehicle> spec = (root, query, cb) ->
cb.equal(root.get(Vehicle_.vehicleSource), Vehicle.VehicleSource.RECEIVE);
vehiclePage = vehicleDao.findAll(spec, PageRequest.of(page, BATCH_SIZE));
if (vehiclePage.hasContent()) {
List<Vehicle> vehicles = vehiclePage.getContent();
List<String> sourceNos = new ArrayList<>();
// 收集车源号
for (Vehicle vehicle : vehicles) {
if (vehicle.getBaseInfo() != null && vehicle.getBaseInfo().getSourceNo() != null) {
sourceNos.add(vehicle.getBaseInfo().getSourceNo());
}
}
if (!sourceNos.isEmpty()) {
try {
// 批量查询过户资料
Map<String, String> electronicContractFieldMap = receiveClient.batchQueryElectronicContractField(sourceNos);
// 更新车辆过户资料
for (Vehicle vehicle : vehicles) {
String sourceNo = vehicle.getBaseInfo().getSourceNo();
String electronicContractField = electronicContractFieldMap.get(sourceNo);
if (electronicContractField != null && !electronicContractField.isEmpty()) {
try {
vehicleService.updateTransferMaterials(vehicle.getVehicleId(), electronicContractField);
totalSynced++;
} catch (Exception e) {
log.error("更新车辆过户资料失败, vehicleId: {}", vehicle.getVehicleId(), e);
totalFailed++;
}
}
}
} catch (Exception e) {
log.error("批次 {} 查询过户资料失败", page, e);
totalFailed += vehicles.size();
}
}
}
page++;
} while (vehiclePage.hasNext());
log.info("过户资料同步定时任务完成,成功: {}, 失败: {}", totalSynced, totalFailed);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!