Commit 21c45e8e by 章家宝

feat:管理端检测工单新增各个状态统计接口

1 parent 402b59d5
......@@ -184,4 +184,21 @@ public class InspectionWorkOrderController {
ExcelExporter.exportExcel(response, fileName, "检测工单列表", InspectionWorkOrderExportBean.class, exportBeans);
log.info("【接口响应】导出检测工单完成,操作人={},导出数量={}", user.getUserName(), exportBeans.size());
}
@Operation(summary = "统计各状态工单数量", description = "统计未删除的待检测、检测中、已完成、已取消工单数量")
@GetMapping("/countByStatus")
public BaseResp<InspectionWorkOrderStatusCountVO> countByStatus() {
log.info("开始统计各状态检测工单数量");
try {
InspectionWorkOrderStatusCountVO countVO = inspectionWorkOrderService.countByStatus();
return BaseResp.success(countVO);
} catch (BusinessCodeException be) {
log.error("统计各状态工单数量失败!业务异常!", be);
return BaseResp.fail(StrUtil.toString(be.getCode()), StrUtil.toString(be.getMessage()));
} catch (Exception e) {
log.error("统计各状态工单数量失败!系统异常!", e);
return BaseResp.fail("系统异常: " + e.getMessage());
}
}
}
......@@ -86,4 +86,6 @@ public interface InspectionWorkOrderRepository extends BaseRepository<Inspection
Page<InspectionWorkOrder> findAll(Specification<InspectionWorkOrder> spec, Pageable pageable);
boolean existsByVehicleAndDeleteFlagAndStatusIn(Vehicle vehicle, String deleteFlag, List<Integer> status);
Long countByStatusAndDeleteFlag(Integer status, String deleteFlag);
}
\ No newline at end of file
......@@ -103,7 +103,7 @@ public class InspectionWorkOrderService {
Inspector inspector = inspectorRepository.findByIdAndDeleteFlag(inspectorId, DeleteFlag.NOT_DELETED.getCode()).orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.PARAM_ERROR, "检测师不存在,检测师ID:" + inspectorId));
boolean isDetecting = inspectionWorkOrderRepository.existsByVehicleAndDeleteFlagAndStatusIn(vehicle, DeleteFlag.NOT_DELETED.getCode(), Arrays.asList(InspectionWorkOrderStatusEnum.DISPATCHED.getCode(), InspectionWorkOrderStatusEnum.IN_PROGRESS.getCode()));
if (isDetecting) {
throw new BusinessCodeException(ErrorCodeEnum.PARAM_ERROR, "车辆正在检测中,无法新增工单", vehicle.getVehicleId());
throw new BusinessCodeException(ErrorCodeEnum.VEHICLE_ALREADY_INSPECTED);
}
LocalDateTime now = LocalDateTime.now();
......@@ -557,4 +557,29 @@ public class InspectionWorkOrderService {
log.info("检测工单完成检测成功: ID={}, 唯一ID={}, 操作人={}", workOrder.getId(), workOrder.getWoId(), opName);
}
/**
* 统计各状态检测工单数量(仅统计未删除工单)
* @return 各状态数量统计结果
*/
public InspectionWorkOrderStatusCountVO countByStatus() {
InspectionWorkOrderStatusCountVO countVO = new InspectionWorkOrderStatusCountVO();
// 查询未删除标识(复用现有枚举)
String notDeleted = DeleteFlag.NOT_DELETED.getCode();
// 统计各状态数量(关联枚举编码,避免硬编码)
countVO.setDispatchedCount(inspectionWorkOrderRepository.countByStatusAndDeleteFlag(
InspectionWorkOrderStatusEnum.DISPATCHED.getCode(), notDeleted));
countVO.setInProgressCount(inspectionWorkOrderRepository.countByStatusAndDeleteFlag(
InspectionWorkOrderStatusEnum.IN_PROGRESS.getCode(), notDeleted));
countVO.setCompletedCount(inspectionWorkOrderRepository.countByStatusAndDeleteFlag(
InspectionWorkOrderStatusEnum.COMPLETED.getCode(), notDeleted));
countVO.setCanceledCount(inspectionWorkOrderRepository.countByStatusAndDeleteFlag(
InspectionWorkOrderStatusEnum.CANCELED.getCode(), notDeleted));
log.info("工单状态统计完成:待检测={}, 检测中={}, 已完成={}, 已取消={}",
countVO.getDispatchedCount(), countVO.getInProgressCount(),
countVO.getCompletedCount(), countVO.getCanceledCount());
return countVO;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.inspect.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 检测工单状态统计VO
*/
@Data
@Schema(name = "InspectionWorkOrderStatusCountVO", description = "检测工单各状态数量统计返回对象")
public class InspectionWorkOrderStatusCountVO {
/**
* 待检测数量(DISPATCHED)
*/
@Schema(description = "待检测工单数量(状态编码1)", example = "10")
private Long dispatchedCount;
/**
* 检测中数量(IN_PROGRESS)
*/
@Schema(description = "检测中工单数量(状态编码2)", example = "5")
private Long inProgressCount;
/**
* 已完成数量(COMPLETED)
*/
@Schema(description = "已完成工单数量(状态编码3)", example = "20")
private Long completedCount;
/**
* 已取消数量(CANCELED)
*/
@Schema(description = "已取消工单数量(状态编码4)", example = "3")
private Long canceledCount;
}
\ No newline at end of file
......@@ -28,9 +28,10 @@ public enum ErrorCodeEnum {
DATA_NOT_EXISTS(1001001, "id为[{0}]的[{1}]不存在!"),
INSPECTION_WO_DELETE_ERROR(1001002, "已完成/已取消/审批通过的工单不允许删除"),
PARAM_ERROR(1001003, "{0} {1}"),
DATA_ALREADY_EXISTS(1001003, "工单唯一ID已存在:{0}"),
DATA_ALREADY_EXISTS(1001004, "工单唯一ID已存在:{0}"),
PHONE_ALREADY_EXISTS(1001005, "手机号[{0}]已存在"),
VEHICLE_ALREADY_INSPECTED(1001006, "车辆已经创建检测工单"),
PHONE_ALREADY_EXISTS(1001002, "手机号[{0}]已存在"),
/* 检测模版 */
NODE_NOT_EXISTS(1001101, "节点[{0}-{1}]不存在"),
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!