Commit e7f3d8bd by 章家宝

feat:九月份日报大版本代码提交

1 parent a898dbfc
package com.glsx.usedcar.web.rest.report;
import com.glsx.usedcar.module.report.service.ReportDataService;
import com.glsx.usedcar.module.report.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.List;
/**
* 报表数据接口(供收车端调用)
* <p>
* 提供收车端所需的原始数据查询接口,按车辆明细返回,不做聚合计算。
* 所有接口均有日志记录,便于排查问题。
* </p>
*
* @author Claude
* @since 2026-09-01
*/
@Slf4j
@RestController
// 供收车端跨系统调用,不能放在 /rest/** 下(受 admin 登录鉴权保护),与 /pushCarData 同模式
@RequestMapping("/report")
@Tag(name = "报表数据接口", description = "供收车端拉取原始数据(不做聚合计算)")
public class ReportDataController {
@Resource
private ReportDataService reportDataService;
@GetMapping("/disposal/monthly")
@Operation(summary = "按月处置成交明细", description = "按车辆明细返回当月处置成交数据,不做聚合")
public List<MonthlyDisposalDetailVO> getMonthlyDisposalDetail(
@Parameter(description = "年份", required = true) @RequestParam int year,
@Parameter(description = "月份", required = true) @RequestParam int month) {
log.info("【报表接口】按月处置成交明细 - year={}, month={}", year, month);
return reportDataService.getMonthlyDisposalDetail(year, month);
}
@GetMapping("/pricing/monthly")
@Operation(summary = "按月定价明细", description = "按车辆明细返回当月定价完成数据,不做聚合")
public List<MonthlyPricingDetailVO> getMonthlyPricingDetail(
@Parameter(description = "年份", required = true) @RequestParam int year,
@Parameter(description = "月份", required = true) @RequestParam int month) {
log.info("【报表接口】按月定价明细 - year={}, month={}", year, month);
return reportDataService.getMonthlyPricingDetail(year, month);
}
@GetMapping("/vehicle-archive/monthly")
@Operation(summary = "按月车辆档案", description = "按车辆明细返回当月车辆档案数据")
public List<MonthlyVehicleArchiveVO> getMonthlyVehicleArchive(
@Parameter(description = "年份", required = true) @RequestParam int year,
@Parameter(description = "月份", required = true) @RequestParam int month) {
log.info("【报表接口】按月车辆档案 - year={}, month={}", year, month);
return reportDataService.getMonthlyVehicleArchive(year, month);
}
@GetMapping("/auction-name/stat")
@Operation(summary = "按拍场名统计", description = "按拍场名称模糊查询统计成交量")
public List<AuctionNameStatVO> getAuctionNameStat(
@Parameter(description = "年份", required = true) @RequestParam int year,
@Parameter(description = "月份", required = true) @RequestParam int month,
@Parameter(description = "拍场名称模糊关键字(如“即时拍”)", required = true) @RequestParam String auctionName) {
log.info("【报表接口】按拍场名统计 - year={}, month={}, auctionName={}", year, month, auctionName);
return reportDataService.getAuctionNameStat(year, month, auctionName);
}
@GetMapping("/auction-attempt/deal")
@Operation(summary = "按拍卖次数区分成交", description = "区分首次拍卖即成交(AN)和多次拍卖才成交(AO)")
public List<AuctionAttemptDealVO> getAuctionAttemptDeal(
@Parameter(description = "年份", required = true) @RequestParam int year,
@Parameter(description = "月份", required = true) @RequestParam int month) {
log.info("【报表接口】按拍卖次数区分成交 - year={}, month={}", year, month);
return reportDataService.getAuctionAttemptDeal(year, month);
}
@GetMapping("/disposal/snapshot/daily")
@Operation(summary = "按日处置快照", description = "按日查询处置快照数据")
public List<DailyDisposalSnapshotVO> getDailyDisposalSnapshot(
@Parameter(description = "日期(yyyy-MM-dd)", required = true)
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
log.info("【报表接口】按日处置快照 - date={}", date);
return reportDataService.getDailyDisposalSnapshot(date);
}
@GetMapping("/vehicle-start-bid/price")
@Operation(summary = "车辆档案起拍价", description = "按评估单号批量查询车辆档案起拍价(最后一轮审核通过评估的起拍价),供收车端顶价收车判定")
public List<VehicleStartBidPriceVO> getVehicleStartBidPrice(
@Parameter(description = "评估单编号列表(逗号分隔)", required = true)
@RequestParam List<String> evalOrderNos) {
log.info("【报表接口】车辆档案起拍价 - 共 {} 个评估单号", evalOrderNos == null ? 0 : evalOrderNos.size());
return reportDataService.getVehicleStartBidPrice(evalOrderNos);
}
@GetMapping("/inventory/summary")
@Operation(summary = "在库车辆汇总", description = "统计指定日期仍处于在库状态(已入库且未处置完成)的车辆台数、金额、平均在库天数、超期台数")
public InventorySummaryVO getInventorySummary(
@Parameter(description = "快照日期(yyyy-MM-dd)", required = true)
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date,
@Parameter(description = "超期天数阈值", required = true) @RequestParam int overdueDays) {
log.info("【报表接口】在库车辆汇总 - date={}, overdueDays={}", date, overdueDays);
return reportDataService.getInventorySummary(date, overdueDays);
}
}
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,7 @@ import com.glsx.usedcar.module.meta.AuditState; ...@@ -5,6 +5,7 @@ import com.glsx.usedcar.module.meta.AuditState;
import com.glsx.usedcar.module.vehicle.entity.Vehicle; import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.summerframework.orm.BaseRepository; import org.summerframework.orm.BaseRepository;
import java.util.List; import java.util.List;
...@@ -18,4 +19,27 @@ public interface AppraisePriceDao extends BaseRepository<AppraisePrice, Integer> ...@@ -18,4 +19,27 @@ public interface AppraisePriceDao extends BaseRepository<AppraisePrice, Integer>
@EntityGraph(attributePaths = {"user"}) @EntityGraph(attributePaths = {"user"})
List<AppraisePrice> findByVehicle_VehicleIdAndAuditStateNotOrderByCreateTimeDesc(int vehicleId, AuditState auditState); List<AppraisePrice> findByVehicle_VehicleIdAndAuditStateNotOrderByCreateTimeDesc(int vehicleId, AuditState auditState);
/**
* 按月查询定价完成的记录(含车辆信息)
* 用于收车端日报拉取
*
* @param year 年份
* @param month 月份
* @return 定价记录列表
*/
@EntityGraph(attributePaths = {"vehicle"})
@Query("select a from AppraisePrice a where year(a.createTime) = ?1 and month(a.createTime) = ?2 and a.auditState = ?3")
List<AppraisePrice> findByCreateTimeYearAndMonthAndAuditState(int year, int month, AuditState auditState);
/**
* 批量查询车辆的审核通过定价记录(按定价时间倒序)
* 用于收车端日报处置明细带出最新保留价
*
* @param vehicleIds 车辆ID列表
* @param auditState 审核状态
* @return 定价记录列表
*/
@EntityGraph(attributePaths = {"vehicle"})
List<AppraisePrice> findByVehicle_VehicleIdInAndAuditStateOrderByCreateTimeDesc(List<Integer> vehicleIds, AuditState auditState);
} }
...@@ -214,6 +214,29 @@ public interface AuctionOrderDao extends BaseRepository<AuctionOrder, Integer>, ...@@ -214,6 +214,29 @@ public interface AuctionOrderDao extends BaseRepository<AuctionOrder, Integer>,
from AuctionOrder o left join o.vehicle vehicle where o.orderState = ?1 from AuctionOrder o left join o.vehicle vehicle where o.orderState = ?1
""") """)
Optional<ProfitRadioProjection> calOrderProfitRadio(AuctionOrder.OrderState orderState); Optional<ProfitRadioProjection> calOrderProfitRadio(AuctionOrder.OrderState orderState);
/**
* 按月查询处置成交明细(含车辆和拍场信息)
* 用于收车端日报拉取
*
* @param year 年份
* @param month 月份
* @return 拍卖订单列表
*/
@EntityGraph(attributePaths = {"vehicle", "auction"})
@Query("select o from AuctionOrder o where year(o.transferredTime) = ?1 and month(o.transferredTime) = ?2 and o.orderState = ?3")
List<AuctionOrder> findByTransferredTimeYearAndMonth(int year, int month, AuctionOrder.OrderState orderState);
/**
* 按日查询处置快照(含车辆信息)
* 用于收车端每日快照拉取
*
* @param date 日期
* @return 拍卖订单列表
*/
@EntityGraph(attributePaths = {"vehicle"})
@Query("select o from AuctionOrder o where date(o.createTime) = ?1")
List<AuctionOrder> findByCreateTimeDate(java.time.LocalDate date);
} }
interface AuctionOrderDaoPlus { interface AuctionOrderDaoPlus {
......
...@@ -116,4 +116,29 @@ public interface AuctionVehicleDao extends BaseRepository<AuctionVehicle, Intege ...@@ -116,4 +116,29 @@ public interface AuctionVehicleDao extends BaseRepository<AuctionVehicle, Intege
group by av.vehicle.vehicleId group by av.vehicle.vehicleId
""") """)
List<VehicleIdCountProjection> countByVehicleIdIn(List<Integer> vehicleIds); List<VehicleIdCountProjection> countByVehicleIdIn(List<Integer> vehicleIds);
/**
* 按拍场名称模糊查询拍卖车辆(用于按拍场名统计)
*
* @param auctionName 拍场名称模糊关键字
* @param year 年份
* @param month 月份
* @return 拍卖车辆列表
*/
@EntityGraph(attributePaths = {"vehicle", "auction"})
@Query("select av from AuctionVehicle av where av.auction.auctionName like concat('%', ?1, '%') and year(av.auctionStartTime) = ?2 and month(av.auctionStartTime) = ?3")
List<AuctionVehicle> findByAuctionNameLikeAndYearMonth(String auctionName, int year, int month);
/**
* 按月查询某车辆的所有拍卖记录(按拍卖开始时间升序)
* 用于判断首次成交/多次成交
*
* @param vehicleId 车辆ID
* @param year 年份
* @param month 月份
* @return 拍卖车辆列表
*/
@EntityGraph(attributePaths = {"auction"})
@Query("select av from AuctionVehicle av where av.vehicle.vehicleId = ?1 and year(av.auctionStartTime) = ?2 and month(av.auctionStartTime) = ?3 order by av.auctionStartTime asc")
List<AuctionVehicle> findByVehicleIdAndYearMonthOrderByStartTimeAsc(int vehicleId, int year, int month);
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.service;
import com.glsx.usedcar.module.auction.dao.AppraisePriceDao;
import com.glsx.usedcar.module.auction.dao.AuctionOrderDao;
import com.glsx.usedcar.module.auction.dao.AuctionVehicleDao;
import com.glsx.usedcar.module.auction.entity.AppraisePrice;
import com.glsx.usedcar.module.auction.entity.AuctionOrder;
import com.glsx.usedcar.module.auction.entity.AuctionVehicle;
import com.glsx.usedcar.module.meta.AuditState;
import com.glsx.usedcar.module.report.vo.*;
import com.glsx.usedcar.module.vehicle.dao.VehicleDao;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 报表数据查询服务(拍卖端原始数据接口)
* <p>
* 提供收车端所需的原始数据查询接口,按车辆明细返回,不做聚合计算。
* 所有接口均有日志记录,便于排查问题。
* </p>
*
* @author Claude
* @since 2026-09-01
*/
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ReportDataService {
@Resource
private AuctionOrderDao auctionOrderDao;
@Resource
private AppraisePriceDao appraisePriceDao;
@Resource
private VehicleDao vehicleDao;
@Resource
private AuctionVehicleDao auctionVehicleDao;
/**
* 按月查询处置成交明细
*
* @param year 年份
* @param month 月份
* @return 处置成交明细列表
*/
public List<MonthlyDisposalDetailVO> getMonthlyDisposalDetail(int year, int month) {
log.info("【报表数据查询】按月处置成交明细 - year={}, month={}", year, month);
List<AuctionOrder> orders = auctionOrderDao.findByTransferredTimeYearAndMonth(year, month, AuctionOrder.OrderState.COMPLETED);
if (CollectionUtils.isEmpty(orders)) {
log.info("【报表数据查询】按月处置成交明细 - 无数据, year={}, month={}", year, month);
return new ArrayList<>();
}
// 批量取成交车辆的最新审核保留价(不受定价月份限制,用于溢价金额计算)
List<Integer> vehicleIds = orders.stream()
.map(order -> order.getVehicle().getVehicleId())
.distinct()
.toList();
List<AppraisePrice> auditedPrices = appraisePriceDao.findByVehicle_VehicleIdInAndAuditStateOrderByCreateTimeDesc(vehicleIds, AuditState.AUDITED);
Map<Integer, BigDecimal> reservePriceMap = new HashMap<>();
for (AppraisePrice price : auditedPrices) {
reservePriceMap.putIfAbsent(price.getVehicle().getVehicleId(), BigDecimal.valueOf(price.getReservePrice()));
}
List<MonthlyDisposalDetailVO> result = orders.stream().map(order -> {
Vehicle vehicle = order.getVehicle();
return MonthlyDisposalDetailVO.builder()
.vehicleId(vehicle.getVehicleId())
.orderPrice(BigDecimal.valueOf(order.getOrderPrice()))
.orderState(order.getOrderState().name())
.transferredTime(order.getTransferredTime())
.warehousingTime(vehicle.getWarehousingTime())
.commissionPrice(BigDecimal.valueOf(order.getCommissionPrice()))
.auctionName(order.getAuction().getAuctionName())
.purchasePrice(vehicle.getEvaluationTransaction() != null
? BigDecimal.valueOf(vehicle.getEvaluationTransaction().getPurchasePrice()) : null)
.reservePrice(reservePriceMap.get(vehicle.getVehicleId()))
.sellerMerchantName(vehicle.getEvaluationTransaction() != null
? vehicle.getEvaluationTransaction().getSellerMerchantName() : null)
.build();
}).toList();
log.info("【报表数据查询】按月处置成交明细 - 返回 {} 条记录, year={}, month={}", result.size(), year, month);
return result;
}
/**
* 按月查询定价明细
*
* @param year 年份
* @param month 月份
* @return 定价明细列表
*/
public List<MonthlyPricingDetailVO> getMonthlyPricingDetail(int year, int month) {
log.info("【报表数据查询】按月定价明细 - year={}, month={}", year, month);
List<AppraisePrice> prices = appraisePriceDao.findByCreateTimeYearAndMonthAndAuditState(year, month, AuditState.AUDITED);
if (CollectionUtils.isEmpty(prices)) {
log.info("【报表数据查询】按月定价明细 - 无数据, year={}, month={}", year, month);
return new ArrayList<>();
}
List<MonthlyPricingDetailVO> result = prices.stream().map(price -> {
Vehicle vehicle = price.getVehicle();
String sellerMerchantName = vehicle.getEvaluationTransaction() != null
? vehicle.getEvaluationTransaction().getSellerMerchantName() : null;
return MonthlyPricingDetailVO.builder()
.vehicleId(vehicle.getVehicleId())
.reservePrice(BigDecimal.valueOf(price.getReservePrice()))
.auditState(price.getAuditState().name())
.sellerMerchantName(sellerMerchantName)
.build();
}).toList();
log.info("【报表数据查询】按月定价明细 - 返回 {} 条记录, year={}, month={}", result.size(), year, month);
return result;
}
/**
* 按月查询车辆档案
*
* @param year 年份
* @param month 月份
* @return 车辆档案列表
*/
public List<MonthlyVehicleArchiveVO> getMonthlyVehicleArchive(int year, int month) {
log.info("【报表数据查询】按月车辆档案 - year={}, month={}", year, month);
List<Vehicle> vehicles = vehicleDao.findByTransferredTimeYearAndMonth(year, month);
if (CollectionUtils.isEmpty(vehicles)) {
log.info("【报表数据查询】按月车辆档案 - 无数据, year={}, month={}", year, month);
return new ArrayList<>();
}
List<MonthlyVehicleArchiveVO> result = vehicles.stream().map(vehicle -> {
String venueName = vehicle.getVenue() != null ? vehicle.getVenue().getVenueName() : null;
String sellerMerchantName = vehicle.getEvaluationTransaction() != null
? vehicle.getEvaluationTransaction().getSellerMerchantName() : null;
return MonthlyVehicleArchiveVO.builder()
.vehicleId(vehicle.getVehicleId())
.vehicleSource(vehicle.getVehicleSource() != null ? vehicle.getVehicleSource().name() : null)
.warehouseInfo(venueName)
.sourceNo(vehicle.getBaseInfo() != null ? vehicle.getBaseInfo().getSourceNo() : null)
.sellerMerchantName(sellerMerchantName)
.build();
}).toList();
log.info("【报表数据查询】按月车辆档案 - 返回 {} 条记录, year={}, month={}", result.size(), year, month);
return result;
}
/**
* 按评估单号批量查询车辆档案起拍价
*
* <p>起拍价 = 最后一轮审核通过评估的起拍价(评估审核通过时冗余到车辆档案,
* 见 AppraiseService#auditAppraisePrice)。供收车端日报顶价收车判定:
* 收车端核价 - 拍卖端起拍价 ≥ 500。无车辆档案或无审核通过评估(起拍价≤0)的
* 评估单不返回,由收车端跳过并记日志。</p>
*
* @param evalOrderNos 评估单编号列表
* @return 车辆档案起拍价列表
*/
public List<VehicleStartBidPriceVO> getVehicleStartBidPrice(List<String> evalOrderNos) {
log.info("【报表数据查询】车辆档案起拍价 - 共 {} 个评估单号", CollectionUtils.isEmpty(evalOrderNos) ? 0 : evalOrderNos.size());
if (CollectionUtils.isEmpty(evalOrderNos)) {
return new ArrayList<>();
}
List<Vehicle> vehicles = vehicleDao.findByEvaluationTransaction_EvalOrderNoIn(evalOrderNos);
List<VehicleStartBidPriceVO> result = vehicles.stream()
.filter(v -> v.getStartingBidPrice() > 0)
.map(v -> VehicleStartBidPriceVO.builder()
.evalOrderNo(v.getEvaluationTransaction().getEvalOrderNo())
.startingBidPrice(BigDecimal.valueOf(v.getStartingBidPrice()))
.build())
.toList();
log.info("【报表数据查询】车辆档案起拍价 - 请求 {} 个评估单号, 返回 {} 条", evalOrderNos.size(), result.size());
return result;
}
/**
* 按拍场名模糊查询统计
*
* @param year 年份
* @param month 月份
* @param auctionName 拍场名称模糊关键字
* @return 拍场统计列表
*/
public List<AuctionNameStatVO> getAuctionNameStat(int year, int month, String auctionName) {
log.info("【报表数据查询】按拍场名统计 - year={}, month={}, auctionName={}", year, month, auctionName);
List<AuctionVehicle> list = auctionVehicleDao.findByAuctionNameLikeAndYearMonth(auctionName, year, month);
if (CollectionUtils.isEmpty(list)) {
log.info("【报表数据查询】按拍场名统计 - 无数据, year={}, month={}, auctionName={}", year, month, auctionName);
return new ArrayList<>();
}
List<AuctionNameStatVO> result = list.stream().map(av -> AuctionNameStatVO.builder()
.vehicleId(av.getVehicle().getVehicleId())
.auctionName(av.getAuction().getAuctionName())
.isDealt(AuctionVehicle.AuctionState.SOLD == av.getAuctionState())
.build()
).toList();
log.info("【报表数据查询】按拍场名统计 - 返回 {} 条记录, year={}, month={}", result.size(), year, month);
return result;
}
/**
* 按拍卖次数区分成交
* <p>
* 首次拍卖即成交(AN):该车辆只有一条拍卖记录且状态为SOLD
* 多次拍卖才成交(AO):该车辆有多条拍卖记录且最后一条状态为SOLD
* </p>
*
* @param year 年份
* @param month 月份
* @return 拍卖次数区分成交列表
*/
public List<AuctionAttemptDealVO> getAuctionAttemptDeal(int year, int month) {
log.info("【报表数据查询】按拍卖次数区分成交 - year={}, month={}", year, month);
// 先获取当月所有处置完成的车辆ID
List<AuctionOrder> orders = auctionOrderDao.findByTransferredTimeYearAndMonth(year, month, AuctionOrder.OrderState.COMPLETED);
if (CollectionUtils.isEmpty(orders)) {
log.info("【报表数据查询】按拍卖次数区分成交 - 当月无处置完成数据, year={}, month={}", year, month);
return new ArrayList<>();
}
List<Integer> vehicleIds = orders.stream()
.map(order -> order.getVehicle().getVehicleId())
.distinct()
.toList();
// 批量查询所有车辆的拍卖记录(含拍场信息)
List<AuctionVehicle> allAuctionVehicles = auctionVehicleDao.findByVehicle_VehicleIdInOrderByAuctionStartTimeDesc(vehicleIds);
// 按车辆ID分组
Map<Integer, List<AuctionVehicle>> vehicleAuctionMap = allAuctionVehicles.stream()
.collect(Collectors.groupingBy(av -> av.getVehicle().getVehicleId()));
List<AuctionAttemptDealVO> result = new ArrayList<>();
for (Integer vehicleId : vehicleIds) {
List<AuctionVehicle> avList = vehicleAuctionMap.get(vehicleId);
if (CollectionUtils.isEmpty(avList)) {
continue;
}
// 按拍卖开始时间升序排列
avList.sort((a, b) -> {
if (a.getAuctionStartTime() == null || b.getAuctionStartTime() == null) return 0;
return a.getAuctionStartTime().compareTo(b.getAuctionStartTime());
});
boolean firstAttemptDealt = false;
boolean multipleAttemptDealt = false;
if (avList.size() == 1) {
// 仅一次拍卖记录 → 首次拍卖即成交
firstAttemptDealt = AuctionVehicle.AuctionState.SOLD == avList.get(0).getAuctionState();
} else if (avList.size() > 1) {
// 多条拍卖记录 → 末条SOLD则为多次拍卖才成交
AuctionVehicle last = avList.get(avList.size() - 1);
multipleAttemptDealt = AuctionVehicle.AuctionState.SOLD == last.getAuctionState();
}
result.add(AuctionAttemptDealVO.builder()
.vehicleId(vehicleId)
.firstAttemptDealt(firstAttemptDealt)
.multipleAttemptDealt(multipleAttemptDealt)
.build());
}
log.info("【报表数据查询】按拍卖次数区分成交 - 返回 {} 条记录, year={}, month={}", result.size(), year, month);
return result;
}
/**
* 按日查询处置快照
*
* @param date 日期
* @return 处置快照列表
*/
public List<DailyDisposalSnapshotVO> getDailyDisposalSnapshot(LocalDate date) {
log.info("【报表数据查询】按日处置快照 - date={}", date);
List<AuctionOrder> orders = auctionOrderDao.findByCreateTimeDate(date);
if (CollectionUtils.isEmpty(orders)) {
log.info("【报表数据查询】按日处置快照 - 无数据, date={}", date);
return new ArrayList<>();
}
List<DailyDisposalSnapshotVO> result = orders.stream().map(order -> {
Vehicle vehicle = order.getVehicle();
String sellerMerchantName = vehicle.getEvaluationTransaction() != null
? vehicle.getEvaluationTransaction().getSellerMerchantName() : null;
return DailyDisposalSnapshotVO.builder()
.vehicleId(vehicle.getVehicleId())
.orderPrice(BigDecimal.valueOf(order.getOrderPrice()))
.transferredTime(order.getTransferredTime())
.orderState(order.getOrderState().name())
.sellerMerchantName(sellerMerchantName)
.build();
}).toList();
log.info("【报表数据查询】按日处置快照 - 返回 {} 条记录, date={}", result.size(), date);
return result;
}
/**
* 统计指定日期的在库车辆汇总(已入库且未处置完成)
* <p>在库口径:入库时间早于快照日期次日零点,且无早于快照日期次日零点的处置完成时间(transferredTime),
* 排除待入库/已取消状态。在库天数=快照日期-入库日期,均值四舍五入取整;
* 超期=在库天数超过 overdueDays 阈值;金额为收购价合计。</p>
*
* @param date 快照日期(yyyy-MM-dd)
* @param overdueDays 超期天数阈值(由调用方传入)
* @return 在库车辆汇总
*/
public InventorySummaryVO getInventorySummary(LocalDate date, int overdueDays) {
log.info("【报表数据查询】在库车辆汇总 - date={}, overdueDays={}", date, overdueDays);
LocalDateTime snapshotEnd = date.plusDays(1).atStartOfDay();
List<Vehicle> vehicles = vehicleDao.findInStockBefore(snapshotEnd,
List.of(Vehicle.VehicleState.INVENTORY, Vehicle.VehicleState.CANCELED));
int totalQuantity = vehicles.size();
BigDecimal totalAmount = BigDecimal.ZERO;
long daySum = 0;
int overdueQuantity = 0;
for (Vehicle vehicle : vehicles) {
if (vehicle.getEvaluationTransaction() != null) {
totalAmount = totalAmount.add(BigDecimal.valueOf(
vehicle.getEvaluationTransaction().getPurchasePrice()));
}
if (vehicle.getWarehousingTime() != null) {
long days = Math.max(0, ChronoUnit.DAYS.between(
vehicle.getWarehousingTime().toLocalDate(), date));
daySum += days;
if (days > overdueDays) {
overdueQuantity++;
}
}
}
InventorySummaryVO result = InventorySummaryVO.builder()
.totalQuantity(totalQuantity)
.totalAmount(totalAmount)
.avgInStockDays(vehicles.isEmpty() ? 0
: (int) Math.round((double) daySum / vehicles.size()))
.overdueQuantity(overdueQuantity)
.build();
log.info("【报表数据查询】在库车辆汇总 - date={}, 在库{}台, 金额{}, 均值{}天, 超期{}台",
date, result.getTotalQuantity(), result.getTotalAmount(),
result.getAvgInStockDays(), result.getOverdueQuantity());
return result;
}
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 按拍卖次数区分成交 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按拍卖次数区分成交")
public class AuctionAttemptDealVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "首次拍卖即成交(AN)")
private Boolean firstAttemptDealt;
@Schema(description = "多次拍卖才成交(AO)")
private Boolean multipleAttemptDealt;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 按拍场名统计 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按拍场名统计")
public class AuctionNameStatVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "拍场名称")
private String auctionName;
@Schema(description = "是否成交(true=成交,false=未成交)")
private Boolean isDealt;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 按日处置快照 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按日处置快照")
public class DailyDisposalSnapshotVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "成交价")
private BigDecimal orderPrice;
@Schema(description = "完成时间(过户时间)")
private LocalDateTime transferredTime;
@Schema(description = "订单状态")
private String orderState;
@Schema(description = "来源门店名称")
private String sellerMerchantName;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 在库车辆汇总 VO
*
* <p>统计指定日期仍处于"在库"状态(已入库且未处置完成)的车辆:
* 台数、收购金额合计、平均在库天数(周转天数)、超期台数。</p>
*
* @author Claude
* @since 2026-09-03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "在库车辆汇总")
public class InventorySummaryVO {
@Schema(description = "在库合计车辆数(台)")
private Integer totalQuantity;
@Schema(description = "在库合计金额(元,收购价合计)")
private BigDecimal totalAmount;
@Schema(description = "平均在库天数(快照日期-入库日期的均值,四舍五入取整)")
private Integer avgInStockDays;
@Schema(description = "超期台数(在库天数超过调用方传入的overdueDays阈值)")
private Integer overdueQuantity;
}
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 按月处置成交明细 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按月处置成交明细")
public class MonthlyDisposalDetailVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "成交价")
private BigDecimal orderPrice;
@Schema(description = "订单状态")
private String orderState;
@Schema(description = "完成时间(过户时间)")
private LocalDateTime transferredTime;
@Schema(description = "入库时间")
private LocalDateTime warehousingTime;
@Schema(description = "佣金")
private BigDecimal commissionPrice;
@Schema(description = "拍场名称")
private String auctionName;
@Schema(description = "收购价")
private BigDecimal purchasePrice;
@Schema(description = "保留价(该车辆最新审核通过的定价)")
private BigDecimal reservePrice;
@Schema(description = "来源门店名称")
private String sellerMerchantName;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 按月定价明细 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按月定价明细")
public class MonthlyPricingDetailVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "保留价")
private BigDecimal reservePrice;
@Schema(description = "审定状态")
private String auditState;
@Schema(description = "来源门店名称")
private String sellerMerchantName;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 按月车辆档案 VO
*
* @author Claude
* @since 2026-09-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "按月车辆档案")
public class MonthlyVehicleArchiveVO {
@Schema(description = "车辆ID")
private Integer vehicleId;
@Schema(description = "车辆来源")
private String vehicleSource;
@Schema(description = "仓库信息")
private String warehouseInfo;
@Schema(description = "车源号(用于跨端关联)")
private String sourceNo;
@Schema(description = "来源门店名称")
private String sellerMerchantName;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.report.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 车辆档案起拍价 VO(按评估单号)
*
* <p>起拍价 = 最后一轮审核通过评估的起拍价(评估审核通过时冗余到车辆档案),
* 供收车端日报顶价收车判定:核价 - 起拍价 ≥ 500。</p>
*
* @author Claude
* @since 2026-09-04
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "车辆档案起拍价")
public class VehicleStartBidPriceVO {
@Schema(description = "评估单编号")
private String evalOrderNo;
@Schema(description = "起拍价(最后一轮审核通过评估的起拍价)")
private BigDecimal startingBidPrice;
}
...@@ -10,6 +10,7 @@ import org.summerframework.orm.BaseRepository; ...@@ -10,6 +10,7 @@ import org.summerframework.orm.BaseRepository;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -61,4 +62,37 @@ public interface VehicleDao extends BaseRepository<Vehicle, Integer>, JpaSpecifi ...@@ -61,4 +62,37 @@ public interface VehicleDao extends BaseRepository<Vehicle, Integer>, JpaSpecifi
@Query("select v.baseInfo.sourceNo from Vehicle v where v.vehicleId in ?1 and v.vehicleState <>?2") @Query("select v.baseInfo.sourceNo from Vehicle v where v.vehicleId in ?1 and v.vehicleState <>?2")
List<String> findBySourceNoVehicleStateNot(List<Integer> vehicleIds, Vehicle.VehicleState vehicleState); List<String> findBySourceNoVehicleStateNot(List<Integer> vehicleIds, Vehicle.VehicleState vehicleState);
/**
* 按月查询车辆档案(含已完成的车辆)
* 用于收车端日报拉取
*
* @param year 年份
* @param month 月份
* @return 车辆列表
*/
@Query("select v from Vehicle v where year(v.transferredTime) = ?1 and month(v.transferredTime) = ?2")
List<Vehicle> findByTransferredTimeYearAndMonth(int year, int month);
/**
* 查询指定时刻的在库车辆(已入库、未处置完成)
* 用于收车端日报在库车辆分析:入库时间早于快照时刻,且无早于快照时刻的处置完成时间
*
* @param snapshotEnd 快照时刻(开区间上界,通常取快照日期次日零点)
* @param excludedStates 排除的车辆状态(待入库/已取消)
* @return 在库车辆列表
*/
@Query("select v from Vehicle v where v.warehousingTime is not null and v.warehousingTime < ?1"
+ " and (v.transferredTime is null or v.transferredTime >= ?1)"
+ " and v.vehicleState not in ?2")
List<Vehicle> findInStockBefore(LocalDateTime snapshotEnd, Collection<Vehicle.VehicleState> excludedStates);
/**
* 按评估单号批量查询车辆
* 用于收车端日报顶价收车判定(评估单编号与收车端 vcp_eval_order.eval_order_no 同源)
*
* @param evalOrderNos 评估单编号列表
* @return 车辆列表
*/
List<Vehicle> findByEvaluationTransaction_EvalOrderNoIn(Collection<String> evalOrderNos);
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!