【更新】新增MyBatisSystemException异常拦截处理

pull/45/head
徐玉祥 2022-10-04 19:14:51 +08:00
parent 1d9934bd48
commit 6671d2bbcc
4 changed files with 27 additions and 9 deletions

View File

@ -75,7 +75,7 @@ public class BizUser extends CommonEntity implements TransPojo {
/** 性别 */
@ApiModelProperty(value = "性别", position = 8)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type= TransType.DICTIONARY, key = "GENDER")
@Trans(type = TransType.DICTIONARY, key = "GENDER")
private String gender;
/** 年龄 */
@ -196,13 +196,13 @@ public class BizUser extends CommonEntity implements TransPojo {
/** 机构id */
@ApiModelProperty(value = "机构id", position = 32)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = BizOrg.class, fields = "name", alias = "org", ref = "orgName")
@Trans(type =TransType.SIMPLE, target = BizOrg.class, fields = "name", alias = "org", ref = "orgName")
private String orgId;
/** 岗位id */
@ApiModelProperty(value = "岗位id", position = 33)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = BizPosition.class, fields = "name", alias = "position", ref = "positionName")
@Trans(type =TransType.SIMPLE, target = BizPosition.class, fields = "name", alias = "position", ref = "positionName")
private String positionId;
/** 职级 */
@ -213,7 +213,7 @@ public class BizUser extends CommonEntity implements TransPojo {
/** 主管id */
@ApiModelProperty(value = "主管id", position = 35)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = BizUser.class, fields = "name", alias = "director", ref = "directorName")
@Trans(type =TransType.SIMPLE, target = BizUser.class, fields = "name", alias = "director", ref = "directorName")
private String directorId;
/** 兼任信息 */

View File

@ -68,6 +68,7 @@ public class ClientUser extends CommonEntity {
/** 性别 */
@ApiModelProperty(value = "性别", position = 8)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type = TransType.DICTIONARY, key = "GENDER")
private String gender;
/** 年龄 */

View File

@ -75,7 +75,7 @@ public class SysUser extends CommonEntity implements TransPojo {
/** 性别 */
@ApiModelProperty(value = "性别", position = 8)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type= TransType.DICTIONARY,key = "GENDER")
@Trans(type = TransType.DICTIONARY,key = "GENDER")
private String gender;
/** 年龄 */
@ -196,13 +196,13 @@ public class SysUser extends CommonEntity implements TransPojo {
/** 组织id */
@ApiModelProperty(value = "组织id", position = 32)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = SysOrg.class, fields = "name", alias = "org", ref = "orgName")
@Trans(type = TransType.SIMPLE, target = SysOrg.class, fields = "name", alias = "org", ref = "orgName")
private String orgId;
/** 职位id */
@ApiModelProperty(value = "职位id", position = 33)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = SysPosition.class, fields = "name", alias = "position", ref = "positionName")
@Trans(type = TransType.SIMPLE, target = SysPosition.class, fields = "name", alias = "position", ref = "positionName")
private String positionId;
/** 职级 */
@ -213,7 +213,7 @@ public class SysUser extends CommonEntity implements TransPojo {
/** 主管id */
@ApiModelProperty(value = "主管id", position = 35)
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
@Trans(type=TransType.SIMPLE, target = SysUser.class, fields = "name", alias = "director", ref = "directorName")
@Trans(type = TransType.SIMPLE, target = SysUser.class, fields = "name", alias = "director", ref = "directorName")
private String directorId;
/** 兼任信息 */

View File

@ -17,6 +17,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.http.HttpMethod;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
@ -113,7 +115,22 @@ public class GlobalExceptionUtil {
// 如果是SaToken相关异常则由AuthExceptionUtil处理
return AuthExceptionUtil.getCommonResult(e);
} else if (e instanceof CommonException) {
} else if(e instanceof MyBatisSystemException) {
// 如果是MyBatisSystemException
Throwable cause = e.getCause();
if (cause instanceof PersistenceException) {
Throwable secondCause = cause.getCause();
if (secondCause instanceof CommonException) {
CommonException commonException = (CommonException) secondCause;
commonResult = CommonResult.get(commonException.getCode(), commonException.getMsg(), null);
} else {
commonResult = CommonResult.error("数据操作异常");
}
}else {
commonResult = CommonResult.error("数据操作异常");
}
} else if (e instanceof CommonException) {
// 通用业务异常,直接返回给前端
CommonException commonException = (CommonException) e;