修正issue:IANBO8问题

This commit is contained in:
inrgihc
2024-10-25 22:11:07 +08:00
parent 35bd4c70ce
commit d2c6ffd7ea
4 changed files with 26 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ public enum ResultCode {
ERROR_INVALID_JDBC_URL(9, "JDBC连接的URL格式不正确"),
ERROR_CANNOT_CONNECT_REMOTE(10, "远程地址不可达"),
ERROR_INVALID_ASSIGNMENT_CONFIG(11, "无效的任务参数配置"),
ERROR_RELATED_ASSIGNMENT(12, "存在关联的任务"),
ERROR_ACCESS_FORBIDDEN(403, "无效的登陆凭证"),
ERROR_TOKEN_EXPIRED(404, "登录凭证已失效"),

View File

@@ -12,6 +12,7 @@ package com.gitee.dbswitch.admin.dao;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gitee.dbswitch.admin.entity.AssignmentConfigEntity;
import com.gitee.dbswitch.admin.mapper.AssignmentConfigMapper;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository;
@@ -35,6 +36,13 @@ public class AssignmentConfigDAO {
return assignmentConfigMapper.selectOne(queryWrapper);
}
public List<AssignmentConfigEntity> getByConnectionId(Long connId) {
QueryWrapper<AssignmentConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AssignmentConfigEntity::getSourceConnectionId, connId)
.or().eq(AssignmentConfigEntity::getTargetConnectionId, connId);
return assignmentConfigMapper.selectList(queryWrapper);
}
public void updateSelective(AssignmentConfigEntity assignmentConfigEntity) {
assignmentConfigMapper.updateById(assignmentConfigEntity);
}

View File

@@ -15,7 +15,11 @@ import com.gitee.dbswitch.admin.common.response.PageResult;
import com.gitee.dbswitch.admin.common.response.Result;
import com.gitee.dbswitch.admin.common.response.ResultCode;
import com.gitee.dbswitch.admin.controller.converter.DbConnectionDetailConverter;
import com.gitee.dbswitch.admin.dao.AssignmentConfigDAO;
import com.gitee.dbswitch.admin.dao.AssignmentTaskDAO;
import com.gitee.dbswitch.admin.dao.DatabaseConnectionDAO;
import com.gitee.dbswitch.admin.entity.AssignmentConfigEntity;
import com.gitee.dbswitch.admin.entity.AssignmentTaskEntity;
import com.gitee.dbswitch.admin.entity.DatabaseConnectionEntity;
import com.gitee.dbswitch.admin.model.request.DbConnectionCreateRequest;
import com.gitee.dbswitch.admin.model.request.DbConnectionSearchRequest;
@@ -51,6 +55,10 @@ public class ConnectionService {
private DriverLoadService driverLoadService;
@Resource
private DatabaseConnectionDAO databaseConnectionDAO;
@Resource
private AssignmentTaskDAO assignmentTaskDAO;
@Resource
private AssignmentConfigDAO assignmentConfigDAO;
public CloseableDataSource getDataSource(Long id) {
return getDataSource(getDatabaseConnectionById(id));
@@ -239,6 +247,14 @@ public class ConnectionService {
}
public void deleteDatabaseConnection(Long id) {
List<Long> assignmentIds = assignmentConfigDAO.getByConnectionId(id)
.stream()
.map(AssignmentConfigEntity::getAssignmentId)
.collect(Collectors.toList());
if (assignmentIds.size() > 0) {
AssignmentTaskEntity taskEntity = assignmentTaskDAO.getById(assignmentIds.get(0));
throw new DbswitchException(ResultCode.ERROR_RELATED_ASSIGNMENT, "[" + taskEntity.getName() + "]");
}
databaseConnectionDAO.deleteById(id);
}

View File

@@ -26,15 +26,10 @@ public final class ExcelUtils {
public static <T> void write(HttpServletResponse response, Class<T> clazz, List<T> list, String fileName,
String sheetName) {
try {
// 这里注意 有同学反应使用swagger 会导致各种问题请直接用浏览器或者用postman
// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
// response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");