Commit 402b59d5 by 章家宝

feat:管理端检测报告导出,检测工单导出

1 parent 78962897
package com.glsx.usedcar.export;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.glsx.usedcar.module.inspect.vo.InspectionReportRespVO;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import lombok.*;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 检测报告导出Bean
* @author yangwei
* @version 1.0
* @since 2026/03/17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InspectionReportExportBean implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
// 日期格式化器
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 工单单号
*/
@ExcelProperty("工单单号")
@ColumnWidth(20)
private String woId;
/**
* 生成时间(创建时间)
*/
@ExcelProperty("生成时间")
@ColumnWidth(20)
private String createTime;
/**
* 车源号
*/
@ExcelProperty("车源号")
@ColumnWidth(20)
private String sourceNo;
/**
* 车型名称
*/
@ExcelProperty("车型名称")
@ColumnWidth(30)
private String carTypeName;
/**
* VIN码
*/
@ExcelProperty("VIN码")
@ColumnWidth(20)
private String vin;
/**
* 车牌号
*/
@ExcelProperty("车牌号")
@ColumnWidth(15)
private String licensePlate;
/**
* 车辆状态
*/
@ExcelProperty("车辆状态")
@ColumnWidth(20)
private String vehicleState;
/**
* 评分
*/
@ExcelProperty("评分")
@ColumnWidth(10)
private String score;
/**
* 绑定状态
*/
@ExcelProperty("绑定状态")
@ColumnWidth(15)
private String bindStatus;
/**
* 更新时间
*/
@ExcelProperty("更新时间")
@ColumnWidth(20)
private String updateTime;
/**
* 从VO转换为导出Bean
* @param vo 检测报告响应VO
* @param createTime 报告创建时间(需从Report实体中获取,VO中若未包含需调整)
* @param updateTime 报告更新时间(需从Report实体中获取,VO中若未包含需调整)
*/
public InspectionReportExportBean(InspectionReportRespVO vo, LocalDateTime createTime, LocalDateTime updateTime) {
if (vo == null) {
return;
}
// 工单信息
this.woId = vo.getWoId();
// 时间信息
this.createTime = createTime != null ? createTime.format(DATE_TIME_FORMATTER) : "";
this.updateTime = updateTime != null ? updateTime.format(DATE_TIME_FORMATTER) : "";
// 评分
this.score = vo.getScore() != null ? vo.getScore().toString() : "";
// 绑定状态转换
this.bindStatus = switch (vo.getBindStatus()) {
case 1 -> "已绑定";
case 2 -> "未绑定";
default -> "未知状态";
};
// 车辆信息
Vehicle vehicle = vo.getVehicle();
if (vehicle != null) {
// 基础信息
if (vehicle.getBaseInfo() != null) {
this.sourceNo = vehicle.getBaseInfo().getSourceNo();
this.carTypeName = vehicle.getBaseInfo().getCarTypeName();
this.vin = vehicle.getBaseInfo().getVin();
this.licensePlate = vehicle.getBaseInfo().getLicensePlate();
} else {
this.sourceNo = "";
this.carTypeName = "";
this.vin = "";
this.licensePlate = "";
}
// 车辆状态转换
this.vehicleState = vehicle.getVehicleState() != null ? switch (vehicle.getVehicleState()) {
case INVENTORY -> "待入库";
case VENUE -> "场地待维护";
case TO_BE_PRICED -> "待定价";
case PRICED -> "待关联拍场";
case PENDING_AUCTION -> "待上拍";
case WAIT_AUCTION -> "待拍卖";
case PREVIEW -> "预展中";
case AUCTIONING -> "拍卖中";
case CONTRACT_UNSIGNED -> "待签署合同";
case UNPAID -> "待付车款";
case WAIT_PICKUP -> "待提车";
case TRANSFERRING -> "待过户";
case COMPLETED -> "已完成";
case CANCELED -> "已取消";
default -> "未知状态";
} : "";
} else {
// 车辆信息为空时初始化
this.sourceNo = "";
this.carTypeName = "";
this.vin = "";
this.licensePlate = "";
this.vehicleState = "";
}
}
/**
* 简化构造器(若VO中已包含创建/更新时间)
*/
public InspectionReportExportBean(InspectionReportRespVO vo) {
this(vo, null, null);
}
}
\ No newline at end of file
package com.glsx.usedcar.export;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.glsx.usedcar.module.inspect.vo.InspectionWORespVO;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InspectionWorkOrderExportBean implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
// 日期格式化器
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 工单单号
*/
@ExcelProperty("工单单号")
@ColumnWidth(20)
private String woId;
/**
* 车源号
*/
@ExcelProperty("车源号")
@ColumnWidth(20)
private String sourceNo;
/**
* 车型名称
*/
@ExcelProperty("车型名称")
@ColumnWidth(30)
private String carTypeName;
/**
* vin码
*/
@ExcelProperty("VIN码")
@ColumnWidth(20)
private String vin;
/**
* 车牌号
*/
@ExcelProperty("车牌号")
@ColumnWidth(15)
private String licensePlate;
/**
* 所属门店
*/
@ExcelProperty("所属门店")
@ColumnWidth(20)
private String venueName;
/**
* 车辆保管人
*/
@ExcelProperty("车辆保管人")
@ColumnWidth(15)
private String custodianName;
/**
* 车辆保管人电话
*/
@ExcelProperty("车辆保管人电话")
@ColumnWidth(20)
private String custodianPhone;
/**
* 车辆状态
*/
@ExcelProperty("车辆状态")
@ColumnWidth(20)
private String vehicleState;
/**
* 检测师
*/
@ExcelProperty("检测师")
@ColumnWidth(15)
private String inspectorName;
/**
* 检测师电话
*/
@ExcelProperty("检测师电话")
@ColumnWidth(20)
private String inspectorPhone;
/**
* 检测地址
*/
@ExcelProperty("检测地址")
@ColumnWidth(30)
private String inspectionAddress;
/**
* 检测状态
*/
@ExcelProperty("检测状态")
@ColumnWidth(15)
private String status;
/**
* 审核状态
*/
@ExcelProperty("审核状态")
@ColumnWidth(15)
private String auditStatus;
/**
* 创建时间(派单时间)
*/
@ExcelProperty("创建时间")
@ColumnWidth(20)
private String createTime;
/**
* 完成检测时间
*/
@ExcelProperty("完成检测时间")
@ColumnWidth(20)
private String inspectionCompletedTime;
/**
* 从VO转换为导出Bean
*/
public InspectionWorkOrderExportBean(InspectionWORespVO vo) {
if (vo == null) {
return;
}
// 工单基础信息
this.woId = vo.getWoId();
this.inspectionAddress = vo.getInspectionAddress();
this.createTime = vo.getWoTime() != null ? vo.getWoTime().format(DATE_TIME_FORMATTER) : "";
this.inspectionCompletedTime = vo.getInspectionCompletedTime() != null ? vo.getInspectionCompletedTime().format(DATE_TIME_FORMATTER) : "";
// 检测状态转换
this.status = switch (vo.getStatus()) {
case 1 -> "待检测";
case 2 -> "检测中";
case 3 -> "已完成";
case 4 -> "已取消";
default -> "未知状态";
};
// 审核状态转换
this.auditStatus = switch (vo.getAuditStatus()) {
case 1 -> "待审批";
case 2 -> "审批中";
case 3 -> "审批通过";
case 4 -> "审批驳回";
default -> "未知状态";
};
// 检测师信息
if (vo.getInspector() != null) {
this.inspectorName = vo.getInspector().getName();
this.inspectorPhone = vo.getInspector().getPhone();
} else {
this.inspectorName = "";
this.inspectorPhone = "";
}
// 车辆信息
Vehicle vehicle = vo.getVehicle();
if (vehicle != null) {
// 基础信息
if (vehicle.getBaseInfo() != null) {
this.sourceNo = vehicle.getBaseInfo().getSourceNo();
this.carTypeName = vehicle.getBaseInfo().getCarTypeName();
this.vin = vehicle.getBaseInfo().getVin();
this.licensePlate = vehicle.getBaseInfo().getLicensePlate();
} else {
this.sourceNo = "";
this.carTypeName = "";
this.vin = "";
this.licensePlate = "";
}
// 所属门店
this.venueName = vehicle.getVenue() != null ? vehicle.getVenue().getVenueName() : "";
// 保管人信息
if (vehicle.getCustodianInfo() != null) {
this.custodianName = vehicle.getCustodianInfo().getCustodianName();
this.custodianPhone = vehicle.getCustodianInfo().getCustodianPhone();
} else {
this.custodianName = "";
this.custodianPhone = "";
}
// 车辆状态转换
this.vehicleState = vehicle.getVehicleState() != null ? switch (vehicle.getVehicleState()) {
case INVENTORY -> "待入库";
case VENUE -> "场地待维护";
case TO_BE_PRICED -> "待定价";
case PRICED -> "待关联拍场";
case PENDING_AUCTION -> "待上拍";
case WAIT_AUCTION -> "待拍卖";
case PREVIEW -> "预展中";
case AUCTIONING -> "拍卖中";
case CONTRACT_UNSIGNED -> "待签署合同";
case UNPAID -> "待付车款";
case WAIT_PICKUP -> "待提车";
case TRANSFERRING -> "待过户";
case COMPLETED -> "已完成";
case CANCELED -> "已取消";
default -> "未知状态";
} : "";
} else {
// 车辆信息为空时初始化
this.sourceNo = "";
this.carTypeName = "";
this.vin = "";
this.licensePlate = "";
this.venueName = "";
this.custodianName = "";
this.custodianPhone = "";
this.vehicleState = "";
}
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@ package com.glsx.usedcar.web.rest.inspect;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum;
import com.glsx.usedcar.export.ExcelExporter;
import com.glsx.usedcar.export.InspectionReportExportBean;
import com.glsx.usedcar.module.inspect.entity.InspectionReport;
import com.glsx.usedcar.module.inspect.service.InspectionReportService;
import com.glsx.usedcar.module.inspect.vo.*;
......@@ -11,6 +13,7 @@ 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 jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -20,6 +23,12 @@ import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.BusinessCodeException;
import org.summerframework.orm.paging.Pagination;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Tag(name = "检测报告接口", description = "检测报告的增删改查、绑定解绑操作")
@RestController
......@@ -133,6 +142,27 @@ public class InspectionReportController {
}
}
@Operation(summary = "检测报告导出", description = "导出检测报告数据列表为Excel文件")
@PostMapping("/export")
public void export(@RequestBody Pagination<InspectionReport> pagination,
HttpServletResponse response,
Authentication authentication) throws IOException {
log.info("【接口请求】导出检测报告,操作人={}", getUserName(authentication));
pagination.setLimit(99999);
Page<InspectionReportRespVO> pageResult = inspectionReportService.pageList(pagination);
List<InspectionReportRespVO> reportList = pageResult.getContent();
List<InspectionReportExportBean> exportBeans = reportList.stream()
.map(vo -> {
return new InspectionReportExportBean(vo, vo.getCreateTime(), vo.getUpdateTime());
})
.collect(Collectors.toList());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String fileName = String.format("检测报告列表_%s", sdf.format(new Date()));
ExcelExporter.exportExcel(response, fileName, "检测报告列表", InspectionReportExportBean.class, exportBeans);
log.info("【接口响应】导出检测报告完成,操作人={},导出数量={}", getUserName(authentication), exportBeans.size());
}
/**
* 安全获取操作人姓名(避免空指针)
*/
......
......@@ -3,6 +3,8 @@ package com.glsx.usedcar.web.rest.inspect;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum;
import com.glsx.usedcar.export.ExcelExporter;
import com.glsx.usedcar.export.InspectionWorkOrderExportBean;
import com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder;
import com.glsx.usedcar.module.inspect.service.InspectionWorkOrderService;
import com.glsx.usedcar.module.inspect.vo.*;
......@@ -10,6 +12,7 @@ import com.glsx.usedcar.module.security.entity.User;
import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -21,6 +24,12 @@ import org.summerframework.core.enums.ErrorCodeEnum;
import org.summerframework.core.exception.BusinessCodeException;
import org.summerframework.orm.paging.Pagination;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Tag(name = "检测工单接口", description = "检测工单的增删改查操作")
......@@ -147,4 +156,32 @@ public class InspectionWorkOrderController {
}
return BaseResp.success();
}
@Operation(summary = "检测工单导出", description = "导出检测工单数据列表为Excel文件")
@PostMapping("/export")
public void export(@RequestBody Pagination<InspectionWorkOrder> pagination,
HttpServletResponse response,
Authentication authentication) throws IOException {
User user = (User)authentication.getPrincipal();
log.info("【接口请求】导出检测工单,操作人={}", user.getUserName());
// 设置分页查询所有数据
pagination.setLimit(99999);
Page<InspectionWORespVO> pageResult = inspectionWorkOrderService.pageList(pagination);
List<InspectionWORespVO> woList = pageResult.getContent();
// 转换为导出Bean
List<InspectionWorkOrderExportBean> exportBeans = woList.stream()
.map(InspectionWorkOrderExportBean::new)
.collect(Collectors.toList());
// 生成导出文件名
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String fileName = String.format("检测工单列表_%s", sdf.format(new Date()));
// 导出Excel
ExcelExporter.exportExcel(response, fileName, "检测工单列表", InspectionWorkOrderExportBean.class, exportBeans);
log.info("【接口响应】导出检测工单完成,操作人={},导出数量={}", user.getUserName(), exportBeans.size());
}
}
package com.glsx.usedcar.module.inspect.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@Schema(description = "检测报告分页返回")
......@@ -38,4 +40,14 @@ public class InspectionReportRespVO {
@Schema(description = "检测结论", example = "车辆无重大事故,发动机工况良好")
private String conclusion;
// 创建时间
@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;
}
\ 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!