优化BizException
This commit is contained in:
parent
70a05e23c3
commit
d989e8847f
|
|
@ -30,11 +30,11 @@ public class GlobalExceptionHandler {
|
|||
@ResponseBody
|
||||
public ElectromagneticResult<?> bizError(BizException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return ElectromagneticResultUtil.fail("-1", e.getMsg());
|
||||
return ElectromagneticResultUtil.fail("-1", e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(PermissionDeniedException.class)
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public ElectromagneticResult<?> accessDeniedError(PermissionDeniedException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class EdFileRelationController {
|
|||
Boolean res = edFileRelationService.createRelation(relation);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("500", e.getMsg());
|
||||
return ElectromagneticResultUtil.fail("500", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class RoleController {
|
|||
Boolean res = roleService.createRole(roleDTO);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("400", e.getMsg());
|
||||
return ElectromagneticResultUtil.fail("400", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ public class RoleController {
|
|||
Boolean res = roleService.updateRole(roleDTO);
|
||||
return ElectromagneticResultUtil.success(res);
|
||||
} catch (BizException e) {
|
||||
return ElectromagneticResultUtil.fail("400", e.getMsg());
|
||||
return ElectromagneticResultUtil.fail("400", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ public class CommonService {
|
|||
}
|
||||
|
||||
private String getDbPath(List<String> ids) {
|
||||
// TODO cache
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo::getId, EdFileInfo::getFileName, EdFileInfo::getDataType, EdFileInfo::getFileType, EdFileInfo::getFileCode)
|
||||
.in(EdFileInfo::getId, ids);
|
||||
|
|
@ -211,7 +210,7 @@ public class CommonService {
|
|||
} catch (Exception e) {
|
||||
String info = "添加失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +273,7 @@ public class CommonService {
|
|||
} catch (Exception e) {
|
||||
String info = "查询项目失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +342,7 @@ public class CommonService {
|
|||
} catch (Exception e) {
|
||||
String info = "删除子集异常";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.exception.PermissionDeniedException;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.*;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
|
|
@ -90,6 +91,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
@Override
|
||||
public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO pars) {
|
||||
|
||||
String parentId = pars.getParentId();
|
||||
List<String> accessibleTree = permissionService.getAccessibleTree();
|
||||
if (!accessibleTree.contains(parentId)) {
|
||||
throw new PermissionDeniedException();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select()
|
||||
.eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code)
|
||||
|
|
@ -236,7 +243,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} catch (Exception e) {
|
||||
String info = "下载文件异常";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -275,11 +282,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
Map<String, EdFileInfo> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
if (map.size() == 1) {
|
||||
if (!map.values().iterator().next().getId().equals(updateFileInfoDTO.getId())) {
|
||||
throw new BizException(-1, "文件名已经存在");
|
||||
throw new BizException("文件名已经存在");
|
||||
}
|
||||
} else if (map.size() > 1) {
|
||||
log.warn("数据库中存在了两份同名同后缀的文件");
|
||||
throw new BizException(-1, "文件名已经存在");
|
||||
throw new BizException("文件名已经存在");
|
||||
}
|
||||
|
||||
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath());
|
||||
|
|
@ -297,7 +304,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} catch (Exception e) {
|
||||
String info = "更新文件信息失败。";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, e.getMessage());
|
||||
throw new BizException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +330,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} catch (Exception e) {
|
||||
String info = "版本回退失败。";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -377,7 +384,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
FileUtil.writeFromStream(fileChunkDTO.getFile().getInputStream(), destPath);
|
||||
} catch (IOException ioException) {
|
||||
log.error("上传文件失败...", ioException);
|
||||
throw new BizException(-1, "上传文件失败");
|
||||
throw new BizException("上传文件失败");
|
||||
}
|
||||
return ElectromagneticResultUtil.success(fileChunkDTO.getIdentifier());
|
||||
}
|
||||
|
|
@ -410,7 +417,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} catch (Exception e) {
|
||||
String info = "文件上传错误";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
String tmpDir = uploadDataDir + currentUserId + File.separator + uuid + File.separator;
|
||||
|
|
@ -673,7 +680,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} catch (Exception e) {
|
||||
String info = "导出失败。";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
fileSystemService.deleteFile(exportZipFile, prjDirPath);
|
||||
}
|
||||
|
|
@ -770,7 +777,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
this.saveOrUpdate(newEdFileInfo);
|
||||
String info = "上传文件失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -1128,7 +1135,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (!FileUtil.exist(new File(tmpPath))) {
|
||||
String info = StrFormatter.format("第{}个分片没有上传完成,请上传完成后再合并。", i);
|
||||
log.error(info);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
// 合并分片
|
||||
|
|
@ -1143,7 +1150,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
FileUtil.del(destColibPath);
|
||||
String info = "文件合并失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
Arrays.stream(partFiles).forEach(e -> FileUtil.del(e.getAbsolutePath()));
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
.eq(EdFileRelation::getId1, queryId2).eq(EdFileRelation::getId2, queryId1);
|
||||
List<EdFileRelation> list = this.list(queryWrapper);
|
||||
if (!list.isEmpty()) {
|
||||
throw new BizException(-1, "请勿重复建立关系");
|
||||
throw new BizException("请勿重复建立关系");
|
||||
}
|
||||
|
||||
edFileRelation.setId(IdWorker.getSnowFlakeIdString());
|
||||
|
|
@ -256,7 +256,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
||||
String info = "上传文件失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("文件创建失败,具体为--->{}", e.getMessage());
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("修改工程名异常--->{},{}", newPrjName, e.getMessage());
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = "删除项目失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = "子集重排序异常";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = "项目发布异常";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} else {
|
||||
String info = "存在相同子集";
|
||||
log.error(info);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("层级沿用失败");
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -425,7 +425,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("修改子集名称为{}失败", newFolderName);
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
if (!checkRoleNameUnique(roleDTO)) {
|
||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||
log.error(info);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
|
||||
// 创建角色
|
||||
|
|
@ -104,7 +104,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
if (!checkRoleNameUnique(roleDTO)) {
|
||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||
log.error(info);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
|
||||
// 更新角色信息
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ public class UserServiceImpl implements UserService {
|
|||
@Override
|
||||
public Boolean bindRoles(List<UserBindRoleDTO> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new BizException(-1, "请勿发布空数据");
|
||||
throw new BizException("请勿发布空数据");
|
||||
}
|
||||
for (UserBindRoleDTO dto : list) {
|
||||
activeRole(dto);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
package com.electromagnetic.industry.software.common.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
public BizException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BizException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BizException() {
|
||||
super("请求错误,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public final class EleCommonUtil {
|
|||
} catch (Exception e) {
|
||||
String info = "文件加密失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
FileUtil.del(filePath);
|
||||
FileUtil.move(new File(tmpPath), new File(filePath), true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue