Commit 92530f15 by yancanhua

Merge branch 'v1.3.0' of https://gitee.com/foutouren/aus into v1.3.0

2 parents 2a693e33 e3fdb51b
Showing 23 changed files with 209 additions and 77 deletions
......@@ -18,3 +18,6 @@ spring:
await-termination: true
await-termination-period: 30s
thread-name-prefix: task-
inspector:
inspection-audit-url: http://localhost:6904/inspection-audit
......@@ -43,9 +43,9 @@ spring:
format_sql: true
datasource:
#url: jdbc:mysql://192.168.0.20:3306/aus?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&nullCatalogMeansCurrent=true
url: jdbc:mysql://120.237.107.125:17689/aus?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&nullCatalogMeansCurrent=true
username: root
password: Ml1234..
url: jdbc:mysql://192.168.3.227:3306/aus?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&nullCatalogMeansCurrent=true
username: os_user
password: os#123
driver-class-name: com.mysql.cj.jdbc.Driver
max-idle: 10 #指定连接池最大的空闲连接数量.
max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
......@@ -67,10 +67,10 @@ spring:
max-lifetime: 1800000
data:
redis:
database: 6
host: 192.168.0.20
database: 0
host: 192.168.3.207
port: 6379
password: Ml1234..
password:
# 连接超时时间 单位 ms(毫秒)
timeout: 3000ms
jedis:
......@@ -179,7 +179,7 @@ wx:
notifyUrl: http://120.237.107.125:6911/api/wxpay/notify # 微信支付通知url
transferNotifyUrl: http://120.237.107.125:6911/api/wxpay/transfer_notify # 微信转账通知url
application:
host: 192.168.0.20
host: 127.0.0.1
jwt:
header: Authorization
secret: mySecretApp
......
package com.glsx.usedcar.consts.inspect;
import com.glsx.usedcar.module.inspect.entity.InspectionNode;
/**
* 检测相关常量
* @author yangwei
......@@ -58,7 +60,27 @@ public interface InspectConstants {
/** 默认值类型:表达式 */
int DEFAULT_TYPE_EXPR = 3;
// 选项数据源类型:1-固定值,2-接口获取
// // ==================== 选项数据源类型:1-固定值,2-接口获取 ====================
int OPTION_DATA_TYPE_FIXED = 1;
int OPTION_DATA_TYPE_API = 2;
/**
* ==================== 是否必填:0-选填,1-必填 ====================
* @see InspectionNode#getRequired()
* @since 2026/3/20 10:40
*/
int IS_REQUIRED_NO = 0;
int IS_REQUIRED_YES = 1;
/**
* 是否支持"无此结构":0-否,1-是
* @see InspectionNode#getAllowNoStructure()
*/
int IS_SUPPORT_NO_STRUCTURE_NO = 0;
int IS_SUPPORT_NO_STRUCTURE_YES = 1;
// // ==================== simple-lock key ====================
/** 检测锁,使用工单id加锁 */
String INSPECTION_LOCK_KEY = "simpleLock:inspection:{0}";
}
......@@ -3,6 +3,7 @@ package com.glsx.usedcar.enums.inspect;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
......@@ -77,4 +78,15 @@ public enum InspectionWorkOrderStatusEnum {
public static boolean isValidCode(Integer code) {
return Objects.nonNull(getByCode(code));
}
/**
* 待检测和检测中才能检测
* @author yangwei
* @since 2026/3/20 10:13
* @param status 检测工单状态
* @return java.lang.Boolean
*/
public static Boolean beableInspection(Integer status) {
return Arrays.asList(DISPATCHED.getCode(), IN_PROGRESS.getCode()).contains(status);
}
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ public enum InteractionTypeEnum {
DROPDOWN("dropdown", "下拉"),
CASCADE("cascade", "级联选项"),
BUTTON_SELECT("button_select", "按钮选择"),
RADIO_BUTTON_SELECT("radio_button_select", "单选按钮选择"),
IMAGE_UPLOAD("image_upload", "图片上传"),
VIDEO_UPLOAD("video_upload", "视频上传"),
IMAGE_UPLOAD_AND_BUTTON_SELECT("image_upload_and_button_select", "图片和按钮选择"),
......
......@@ -64,12 +64,13 @@ public interface InspectionResultRepository extends BaseRepository<InspectionRes
* @param deletedFlag 删除标识
* @return 结果列表(已包含 inspectionValues)
*/
@Query("SELECT DISTINCT r FROM InspectionResult r " +
"LEFT JOIN FETCH r.inspectionValues v " +
"WHERE r.recordId = :recordId " +
"AND r.deletedFlag = :deletedFlag " +
"AND (v.deletedFlag = :deletedFlag OR v.id IS NOT NULL) " +
"ORDER BY v.valueSeq ASC")
@Query("""
SELECT DISTINCT r FROM InspectionResult r
LEFT JOIN FETCH r.inspectionValues v
WHERE r.recordId = :recordId
AND r.deletedFlag = :deletedFlag
ORDER BY v.valueSeq ASC
""")
List<InspectionResult> findByRecordIdWithValues(@Param("recordId") Long recordId,
@Param("deletedFlag") String deletedFlag);
......
......@@ -7,6 +7,7 @@ import jakarta.validation.constraints.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingEntity;
import org.summerframework.orm.validator.CreateValidGroup;
......@@ -85,7 +86,7 @@ public class InspectionReport extends AuditingEntity implements Serializable {
* 关联InspectionWorkOrder实体(懒加载,非级联)
*/
@JsonView(value = Summary.class)
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@OneToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(
name = "work_order_inner_id",
referencedColumnName = "id",
......@@ -97,12 +98,13 @@ public class InspectionReport extends AuditingEntity implements Serializable {
* 车辆ID(关联Vehicle实体)
*/
@JsonView(value = Summary.class)
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@OneToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(
name = "vehicle_id",
referencedColumnName = "vehicleId",
nullable = false
)
@ReadOnlyProperty
private Vehicle vehicle;
/**
......
......@@ -7,6 +7,7 @@ import jakarta.validation.constraints.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingEntity;
import org.summerframework.orm.validator.CreateValidGroup;
......@@ -64,6 +65,7 @@ public class InspectionWorkOrder extends AuditingEntity implements Serializable
referencedColumnName = "vehicleId",
nullable = false
)
@ReadOnlyProperty
private Vehicle vehicle;
@OneToOne(cascade = {}, fetch = FetchType.LAZY)
......@@ -72,6 +74,7 @@ public class InspectionWorkOrder extends AuditingEntity implements Serializable
referencedColumnName = "id",
nullable = false
)
@ReadOnlyProperty
private Inspector inspector;
/**
......
......@@ -30,6 +30,9 @@ public class InspectionLeafNodeDataVO implements Serializable {
@Schema(description = "值内容(统一存储:文本/数字")
private String valueText;
@Schema(description = "值对应的key")
private String valueKey;
@Schema(description = "交互类型,复合类型取子集")
private String interactionType;
......
......@@ -45,8 +45,7 @@ public class InspectionNodeVO implements Serializable {
* 父节点 ID,0 表示根节点
*/
@Schema(description = "父节点 ID,0 表示根节点")
@Builder.Default
private Long parentId = 0L;
private Long parentId;
@Schema(description = "节点代码")
private String nodeCode;
......@@ -67,15 +66,13 @@ public class InspectionNodeVO implements Serializable {
* 展示节点名称:1-展示 0-不展示
*/
@Schema(description = "展示节点名称:1-展示 0-不展示")
@Builder.Default
private String showNodeName = "1";
private String showNodeName;
/**
* 编辑权限,0 不可编辑,1 可编辑
*/
@Schema(description = "编辑权限,0 不可编辑,1 可编辑")
@Builder.Default
private String editPermission = "1";
private String editPermission;
/**
* 展现模式:1-列表表单,2-网格检测,3-区域分组,4-图片上传,5-基础信息,6-视频录制
......@@ -129,8 +126,7 @@ public class InspectionNodeVO implements Serializable {
* 是否必填:0-选填,1-必填
*/
@Schema(description = "是否必填:0-选填,1-必填")
@Builder.Default
private Integer required = 1;
private Integer required;
/**
* 选项配置(JSON 格式文本):固定选项或动态接口配置
......@@ -142,8 +138,7 @@ public class InspectionNodeVO implements Serializable {
* 选项数据源类型:1-固定值,2-接口获取
*/
@Schema(description = "选项数据源类型:1-固定值,2-接口获取")
@Builder.Default
private Integer optionsSourceType = 1;
private Integer optionsSourceType;
/**
* 校验规则(JSON 格式文本):{"min": 2, "max": 9, "regex": "..."}
......@@ -161,15 +156,13 @@ public class InspectionNodeVO implements Serializable {
* 是否支持"无此结构":0-否,1-是
*/
@Schema(description = "是否支持\"无此结构\":0-否,1-是")
@Builder.Default
private Integer allowNoStructure = 0;
private Integer allowNoStructure;
/**
* 是否存在默认值:1-存在 0-不存在
*/
@Schema(description = "是否存在默认值:1-存在 0-不存在")
@Builder.Default
private String existsDefaultValue = "0";
private String existsDefaultValue;
/**
* 默认值(固定值)
......@@ -193,8 +186,7 @@ public class InspectionNodeVO implements Serializable {
* 默认值类型:1-固定值,2-接口获取,3-表达式
*/
@Schema(description = "默认值类型:1-固定值,2-接口获取,3-表达式")
@Builder.Default
private Integer defaultType = 1;
private Integer defaultType;
/**
* 默认值配置(JSON 格式文本)
......@@ -206,8 +198,7 @@ public class InspectionNodeVO implements Serializable {
* 最大上传数量
*/
@Schema(description = "最大上传数量")
@Builder.Default
private Integer maxCount = 1;
private Integer maxCount;
/**
* 拍摄要求说明
......@@ -231,22 +222,19 @@ public class InspectionNodeVO implements Serializable {
* 节点层级,根节点为 0
*/
@Schema(description = "节点层级,根节点为 0")
@Builder.Default
private Integer nodeLevel = 0;
private Integer nodeLevel;
/**
* 同级排序号
*/
@Schema(description = "同级排序号")
@Builder.Default
private Integer sortOrder = 0;
private Integer sortOrder;
/**
* 状态:0-禁用,1-启用
*/
@Schema(description = "状态:0-禁用,1-启用")
@Builder.Default
private Integer status = 1;
private Integer status;
/**
* 备注
......
package com.glsx.usedcar.module.inspect.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
......@@ -32,17 +33,18 @@ public class InspectionSaveVO implements Serializable {
/**
* 当前所在的一级模块 ID
*/
@NotNull(message = "当前所在的一级模块 ID 不能为空")
@Schema(description = "当前所在的一级模块 ID", requiredMode = Schema.RequiredMode.REQUIRED)
private Long locationModule;
/**
* 当前所在的二级模块 ID
*/
@Schema(description = "当前所在的二级模块 ID,如果没有则为null")
@Schema(description = "当前所在的二级模块 ID,如果没有则为null,如果有必传")
private Long locationSubModule;
@Schema(description = "是否是下一个步,true-是,false-否,下一步会保存并校验,保存不会做必填校验")
private Boolean nextFlag;
@Schema(description = "是否是下一个步,true-是,false-否,下一步会保存并校验,保存不会做必填校验, 默认为true")
private Boolean nextFlag = true;
/**
* 叶子节点数据列表,可以为空,为空表示都是正常的
......
......@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.glsx.usedcar.consts.common.CommonConsts;
import com.glsx.usedcar.consts.common.SymbolConsts;
import com.glsx.usedcar.consts.inspect.InspectConstants;
import com.glsx.usedcar.consts.inspect.ValidatorConstants;
......@@ -47,15 +48,15 @@ public abstract class AbstractNodeValidator implements NodeValidator {
String nodeName = node.getNodeName();
// 1. 处理"无此结构"
if (result.getResultStatus() != null && result.getResultStatus() == 3) {
if (node.getAllowNoStructure() == null || node.getAllowNoStructure() != 1) {
if (result.getResultStatus() != null && result.getResultStatus() == InspectConstants.RESULT_STATUS_NO_STRUCTURE) {
if (node.getAllowNoStructure() == null || node.getAllowNoStructure() != InspectConstants.IS_SUPPORT_NO_STRUCTURE_YES) {
return ValidationResult.error(String.format("【%s】不支持[无此结构]", nodeName), nodeName);
}
return ValidationResult.success();
}
// 2. 必填校验(检查所有类型的值,不限于当前 interactionType)
if (node.getRequired() != null && node.getRequired() == 1) {
if (node.getRequired() != null && node.getRequired() == InspectConstants.IS_REQUIRED_YES) {
boolean hasAnyValue = CollUtil.isNotEmpty(result.getValues())
&& result.getValues().stream().anyMatch(v -> StrUtil.isNotBlank(v.getValueText()));
if (!hasAnyValue) {
......@@ -70,7 +71,7 @@ public abstract class AbstractNodeValidator implements NodeValidator {
}
// 4. 从节点配置中解析校验规则
ValidationRuleConfig ruleConfig = ValidationRuleConfig.parse(node.getValidationRules());
ValidationRuleConfig ruleConfig = ValidationRuleConfig.parse(node.getValidationRules(), node.getNodeName());
ruleConfig = ruleConfigHandler(ruleConfig, node);
// 5. 委托子类执行具体校验
......@@ -91,7 +92,7 @@ public abstract class AbstractNodeValidator implements NodeValidator {
// 文件数量
Integer maxCount = Optional.ofNullable(ruleConfig.getMaxCount())
.or(() -> node.getMaxCount().describeConstable())
.or(() -> Optional.ofNullable(node.getMaxCount()))
.orElse(null);
ruleConfig.setMaxCount(maxCount);
......
......@@ -8,7 +8,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import java.math.BigDecimal;
import java.text.ParsePosition;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.util.Optional;
/**
......@@ -168,7 +170,7 @@ public enum DataFormatValidator {
DateTimeFormatter formatter;
try {
formatter = DateTimeFormatter.ofPattern(pattern);
formatter = DateTimeFormatter.ofPattern(pattern).withResolverStyle(ResolverStyle.STRICT);
} catch (IllegalArgumentException e) {
return ValidationResult.error(
String.format("【%s】配置的日期格式不合法:%s", nodeName, pattern), nodeName);
......@@ -197,8 +199,30 @@ public enum DataFormatValidator {
String.format("【%s】配置的最大日期格式不合法:%s", nodeName, dateMax), nodeName);
}
}
// 1. 先检查字符串长度是否匹配格式(防止 "2020-01-105" 这类情况)
int expectedLength = calculateExpectedDateLength(pattern);
if (expectedLength > 0 && value.length() != expectedLength) {
return ValidationResult.error(
String.format("【%s】数据格式要求为日期(%s)", nodeName, pattern),
node.getNodeName(), value);
}
try {
formatter.parse(value);
// 使用 ParsePosition 检查是否完全解析整个字符串
ParsePosition pos = new ParsePosition(0);
formatter.parse(value, pos);
// 检查是否有解析错误
if (pos.getErrorIndex() >= 0) {
return ValidationResult.error(
String.format("【%s】数据格式要求为日期(%s)", nodeName, pattern),
node.getNodeName(), value);
}
// 如果解析位置不等于字符串长度,说明有未解析的字符(如 "2020-01-105" 只解析了前10位)
if (pos.getIndex() != value.length()) {
return ValidationResult.error(
String.format("【%s】数据格式要求为日期(%s)", nodeName, pattern),
node.getNodeName(), value);
}
} catch (Exception e) {
return ValidationResult.error(
String.format("【%s】数据格式要求为日期(%s)", nodeName, pattern),
......@@ -332,4 +356,46 @@ public enum DataFormatValidator {
}
return ValidationResult.success();
}
/**
* 计算日期格式对应的预期字符串长度
* <p>
* 用于在解析前快速校验字符串长度是否匹配,防止 "2020-01-105" 这类情况被部分解析成功
* </p>
*
* @param pattern 日期格式模式
* @return 预期长度,如果无法计算则返回 -1
*/
private static int calculateExpectedDateLength(String pattern) {
if (StrUtil.isBlank(pattern)) {
return -1;
}
// 常见格式的预期长度
// yyyy-MM-dd -> 10
// yyyy-MM -> 7
// yyyy-MM-dd HH:mm:ss -> 19
// yyyy-MM-dd HH:mm -> 16
// yyyy/MM/dd -> 10
// 简单计算:每个字母占1位,其他字符原样保留
int length = 0;
for (int i = 0; i < pattern.length(); i++) {
char c = pattern.charAt(i);
if (c == 'y' || c == 'M' || c == 'd' || c == 'H' || c == 'm' || c == 's') {
// 日期时间字母,每个占1位(实际值可能是1-2位,但标准格式都是固定宽度)
// 对于 yyyy, MM, dd 等固定宽度的格式,我们假设都是标准格式
// 这里需要统计连续相同字母的数量
int count = 1;
while (i + 1 < pattern.length() && pattern.charAt(i + 1) == c) {
count++;
i++;
}
// yyyy=4位年份, MM=2位月份, dd=2位日期, HH=2位小时, mm=2位分钟, ss=2位秒
length += count;
} else {
// 分隔符等其他字符,原样保留
length++;
}
}
return length;
}
}
......@@ -72,7 +72,7 @@ public class NodeValidationManager {
for (InspectionLeafNodeVO leafNode : leafNodes) {
InspectionNodeVO nodeConfig = nodeConfigMap.get(leafNode.getNodeId());
if (nodeConfig == null) {
throw new BusinessCodeException(1001003, "节点不存在:{0}", leafNode.getNodeId());
throw new BusinessCodeException(ErrorCodeEnum.NODE_NOT_EXISTS, leafNode.getNodeId(), leafNode.getNodeName());
}
validateNode(leafNode, nodeConfig);
}
......@@ -96,15 +96,6 @@ public class NodeValidationManager {
}
/**
* InspectionNodeVO → InspectionNodeDTO
*/
private InspectionNodeDTO toNodeDTO(InspectionNodeVO vo) {
InspectionNodeDTO dto = new InspectionNodeDTO();
BeanUtil.copyProperties(vo, dto);
return dto;
}
/**
* InspectionLeafNodeVO → InspectionResultDTO
* @author yangwei
* @since 2026/3/17 10:29
......@@ -116,6 +107,7 @@ public class NodeValidationManager {
if (CollUtil.isNotEmpty(leafNode.getData())) {
valueItems = leafNode.getData().stream()
.map(d -> InspectionResultDTO.ValueItem.builder()
.valueKey(d.getValueKey())
.valueText(d.getValueText())
.interactionType(d.getInteractionType())
.valueSeq(d.getValueSeq())
......
......@@ -9,7 +9,7 @@ import java.util.List;
import java.util.Set;
/**
* 选项类校验(dropdown / cascade / button_select)
* 选项类校验(dropdown / cascade / button_select / radio_button_select)
*
* @author yangwei
* @since 2026/3/16
......@@ -20,7 +20,8 @@ public class OptionsValidator extends AbstractNodeValidator {
private static final Set<String> SUPPORTED = Set.of(
InteractionTypeEnum.DROPDOWN.getCode(),
InteractionTypeEnum.CASCADE.getCode(),
InteractionTypeEnum.BUTTON_SELECT.getCode()
InteractionTypeEnum.BUTTON_SELECT.getCode(),
InteractionTypeEnum.RADIO_BUTTON_SELECT.getCode()
);
@Override
......
......@@ -39,7 +39,11 @@ public class UploadValidator extends AbstractNodeValidator {
List<String> values = extractValues(result, node.getInteractionType());
String typeName = node.getInteractionType().contains(InteractionTypeEnum.IMAGE_UPLOAD.getCode())
? ValidatorConstants.IMAGE : ValidatorConstants.VIDEO;
validateUploadCount(values, maxCount, typeName, nodeName);
ValidationResult validationResult = validateUploadCount(values, maxCount, typeName, nodeName);
if (!validationResult.isValid()) {
return validationResult;
}
return ValidationResult.success();
}
}
......@@ -3,6 +3,8 @@ package com.glsx.usedcar.validators.inspector;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import lombok.Data;
import org.summerframework.core.enums.ErrorCodeEnum;
import org.summerframework.core.exception.BusinessCodeException;
import java.util.List;
import java.util.Map;
......@@ -55,6 +57,10 @@ public class ValidationRuleConfig {
private Integer maxCount;
/** 文件校验最大大小 */
private Long maxSize;
/** 文件校验最小时长 */
private Integer minDuration;
/** 文件校验最大时长 */
private Integer maxDuration;
/** 文件校验允许的格式 */
private List<String> allowedFormats;
......@@ -76,14 +82,14 @@ public class ValidationRuleConfig {
* @param json validation_rules JSON
* @return 配置对象,解析失败返回 null
*/
public static ValidationRuleConfig parse(String json) {
public static ValidationRuleConfig parse(String json, String nodeName) {
if (StrUtil.isBlank(json)) {
return null;
}
try {
return JSON.parseObject(json, ValidationRuleConfig.class);
} catch (Exception e) {
return null;
throw new BusinessCodeException(ErrorCodeEnum.NODE_CHECK_RULE_ERROR, nodeName);
}
}
}
......@@ -20,6 +20,7 @@ public enum ErrorCodeEnum {
DATA_NOT_EXIST(1004, "数据不存在"),
VALIDATION_ERROR(1005, "参数校验失败"),
LOGIN_ERROR(1006, "未登录或登录已过期,请重新登录"),
BUSINESS_BUSY(1010, "业务繁忙,请稍后重试"),
COMMON_ERROR(1000000, "{0}"),
DATA_INCOMPLETE(1000001, "数据不完整:[{0}]"),
......@@ -39,7 +40,10 @@ public enum ErrorCodeEnum {
/* 检测模版 */
NODE_NOT_EXISTS(1001101, "节点[{0}-{1}]不存在"),
NODE_NOT_LEAF(1001102, "[{0}-{1}]不是叶子节点,无法保存检测值"),
NODE_CHECK_ERROR(1001103, "数据校验失败:[]"),
NODE_CHECK_ERROR(1001103, "数据校验失败:{0}"),
NOT_ABLE_INSPECT(1001104, "当前工单不允许检测"),
NODE_CHECK_RULE_ERROR(1001105, "[{0}]校验规则解析异常"),
;
private final Integer code;
......
package com.glsx.usedcar.advice;
import cn.hutool.core.util.StrUtil;
import com.glsx.usedcar.resp.BaseResp;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.HibernateException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import org.summerframework.core.enums.ErrorCodeEnum;
import org.summerframework.core.exception.BusinessCodeException;
import org.summerframework.core.exception.BusinessException;
import java.util.stream.Collectors;
......@@ -16,19 +20,21 @@ import java.util.stream.Collectors;
@RestControllerAdvice
public class GlobalExceptionHandler {
// 捕获所有未指定的异常(兜底)
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 明确返回500状态码
public BaseResp<Void> handleAllUncaughtException(Exception e) {
// 打印完整异常堆栈
log.error("全局捕获未处理异常:", e);
// 返回标准化错误响应
return BaseResp.fail("服务器内部错误:" + e.getMessage());
/**
* 捕获业务异常
* @author yangwei
* @since 2026/3/20 11:03
* @param e 业务异常
* @return com.glsx.usedcar.resp.BaseResp<java.lang.Void>
*/
@ExceptionHandler(BusinessCodeException.class)
public BaseResp<Void> handleBusinessException(BusinessCodeException e) {
log.error("业务异常", e);
return BaseResp.fail(StrUtil.toString(e.getCode()), e.getMessage());
}
// 捕获参数校验异常(比如@Valid校验失败)
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResp<Void> handleValidationException(MethodArgumentNotValidException e) {
log.error("参数校验失败:", e);
String errorMsg = e.getBindingResult().getFieldErrors().stream()
......@@ -37,6 +43,16 @@ public class GlobalExceptionHandler {
return BaseResp.fail("参数错误:" + errorMsg);
}
// 捕获所有未指定的异常(兜底)
@ExceptionHandler(Exception.class)
public BaseResp<Void> handleAllUncaughtException(Exception e) {
// 打印完整异常堆栈
log.error("全局捕获未处理异常:", e);
// 返回标准化错误响应
return BaseResp.fail("服务器内部错误:" + e.getMessage());
}
// 捕获JPA/Hibernate相关异常
@ExceptionHandler(HibernateException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
......
package com.glsx.usedcar.controller;
import com.glsx.usedcar.annotation.RequireLogin;
import com.glsx.usedcar.module.inspect.service.InspectionRecordService;
import com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO;
import com.glsx.usedcar.module.inspect.vo.CompleteInspectionVO;
......@@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
* @since 2026/03/12 10:42
*/
@Slf4j
@RequireLogin
@RestController
@RequiredArgsConstructor
@RequestMapping("/rest/inspectionRecord")
......@@ -53,9 +55,10 @@ public class InspectionRecordController {
* 编写查询检测详情接口,根据检测记录id查询,检测节点还要统计根节点以及模块节点的正常数,故障数以及无此结构数量
* @author yangwei
* @since 2026/3/18 15:00
* @param recordId
* @param recordId 检测记录id
* @return com.glsx.usedcar.resp.BaseResp<com.glsx.usedcar.module.inspect.vo.InspectionDetailRespVO>
*/
@RequireLogin(required = false)
@GetMapping("/{recordId}/detail")
@Operation(summary = "详情", description = "检测详情")
public BaseResp<InspectionDetailRespVO> detail(
......
package com.glsx.usedcar.controller;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.map.MapUtil;
import com.glsx.usedcar.module.inspect.service.InspectionNodeService;
import com.glsx.usedcar.resp.BaseResp;
......@@ -43,6 +44,7 @@ public class InspectionTemplateController {
return BaseResp.success(rootNodes);
}
@PostMapping("/default")
@Operation(summary = "获取模版默认值", description = "获取模版默认值")
public BaseResp<Map<String, String>> getTemplateDefaultValue(
......
......@@ -26,7 +26,7 @@ import java.io.PrintWriter;
*/
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequiredArgsConstructor
public class LoginInterceptor implements HandlerInterceptor {
private final JwtProvider jwtProvider;
private final InspectorService inspectorService;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!