mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-10-15 14:20:25 +00:00
任务管理页面导出优化
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
</el-button>
|
||||
<el-button size="mini" icon="el-icon-video-pause" :disabled=isSelected plain @click="batchStop()">停止</el-button>
|
||||
<span style="color:#e9e9f3;"> | </span>
|
||||
<el-button size="mini" plain>导入任务</el-button>
|
||||
<el-button size="mini" plain @click="batchImport()">导入任务</el-button>
|
||||
<el-button size="mini" :disabled=isSelected plain @click="batchExport()">导出任务</el-button>
|
||||
<!-- <div class="right-add-button-group">-->
|
||||
<el-button class="right-add-button-group" type="primary"
|
||||
@@ -286,7 +286,6 @@ export default {
|
||||
url: "/dbswitch/admin/api/v1/assignment/export?ids=" + this.idsSelected,
|
||||
responseType: 'blob',
|
||||
}).then(res => {
|
||||
debugger
|
||||
if (200 === res.status) {
|
||||
this.downloadFile(res)
|
||||
this.$message({
|
||||
@@ -301,6 +300,12 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
batchImport(){
|
||||
this.$message({
|
||||
message: '功能暂未开放,敬请期待!',
|
||||
center: true
|
||||
});
|
||||
},
|
||||
downloadFile: function (resp) {
|
||||
const headers = resp.headers;
|
||||
const contentType = headers['content-type'];
|
||||
@@ -313,11 +318,10 @@ export default {
|
||||
type: contentType
|
||||
});
|
||||
|
||||
const contentDisposition = resp.headers['Content-disposition'];
|
||||
const contentDisposition = resp.headers['content-disposition'];
|
||||
let fileName = 'unknown';
|
||||
if (contentDisposition) {
|
||||
debugger
|
||||
fileName = window.decodeURI(resp.headers['Content-disposition'].split('=')[1]);
|
||||
fileName = window.decodeURI(resp.headers['content-disposition'].split('=')[1]);
|
||||
}
|
||||
console.log('文件名称:', fileName);
|
||||
this.downFile(blob, fileName);
|
||||
|
@@ -118,11 +118,6 @@
|
||||
<artifactId>easyexcel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
|
@@ -1,13 +0,0 @@
|
||||
package com.gitee.dbswitch.admin.convert;
|
||||
|
||||
import com.gitee.dbswitch.admin.entity.AssignmentTaskEntity;
|
||||
import com.gitee.dbswitch.admin.model.response.AssignmentsDataResponse;
|
||||
|
||||
/**
|
||||
* @author Li Zemin
|
||||
* @since 2024/4/22 9:44
|
||||
*/
|
||||
//@Mapper
|
||||
public interface AssignmentConvert {
|
||||
AssignmentsDataResponse toAssignmentsDataResponse(AssignmentTaskEntity assignmentTaskEntity);
|
||||
}
|
@@ -5,6 +5,9 @@ import java.util.Date;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
|
||||
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
||||
|
||||
@@ -20,6 +23,7 @@ import lombok.Setter;
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
@ColumnWidth(25)
|
||||
@EqualsAndHashCode
|
||||
public class AssignmentsDataResponse {
|
||||
|
||||
|
@@ -50,6 +50,7 @@ import com.gitee.dbswitch.admin.model.response.AssignmentInfoResponse;
|
||||
import com.gitee.dbswitch.admin.model.response.AssignmentsDataResponse;
|
||||
import com.gitee.dbswitch.admin.type.JobStatusEnum;
|
||||
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
||||
import com.gitee.dbswitch.admin.util.EasyexcelUtils;
|
||||
import com.gitee.dbswitch.admin.util.PageUtils;
|
||||
import com.gitee.dbswitch.common.converter.ConverterFactory;
|
||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||
@@ -80,9 +81,6 @@ public class AssignmentService {
|
||||
@Resource
|
||||
private AssignmentJobMapper assignmentJobMapper;
|
||||
|
||||
// @Resource
|
||||
// private AssignmentConvert assignmentConvert;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AssignmentInfoResponse createAssignment(AssigmentCreateRequest request) {
|
||||
AssignmentTaskEntity assignment = request.toAssignmentTask();
|
||||
@@ -359,11 +357,8 @@ public class AssignmentService {
|
||||
public void exportAssignments(List<Long> ids, HttpServletResponse response) {
|
||||
checkAssignmentAllExist(ids);
|
||||
List<AssignmentsDataResponse> assignmentsDataResponses = new ArrayList<>();
|
||||
// TODO 任务导出
|
||||
for (Long id : ids) {
|
||||
AssignmentTaskEntity assignmentTaskEntity = assignmentTaskDAO.getById(id);
|
||||
// AssignmentsDataResponse assignmentsDataResponse =
|
||||
// this.assignmentConvert.toAssignmentsDataResponse(assignmentTaskEntity);
|
||||
AssignmentsDataResponse assignmentsDataResponse = ConverterFactory.getConverter(AssignmentsConverter.class)
|
||||
.convert(assignmentTaskEntity);
|
||||
|
||||
@@ -392,22 +387,7 @@ public class AssignmentService {
|
||||
assignmentJobEntity.getStatus();
|
||||
assignmentsDataResponse.setRunStatus(JobStatusEnum.of(status).getName());
|
||||
assignmentsDataResponses.add(assignmentsDataResponse);
|
||||
|
||||
}
|
||||
try {
|
||||
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
|
||||
// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
||||
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
|
||||
// response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
EasyExcel.write(response.getOutputStream(), AssignmentsDataResponse.class)
|
||||
.sheet("模板")
|
||||
.doWrite(assignmentsDataResponses);
|
||||
} catch (IOException ex) {
|
||||
throw new DbswitchException(ResultCode.ERROR_INTERNAL_ERROR, ex.getMessage());
|
||||
}
|
||||
EasyexcelUtils.write(response,AssignmentsDataResponse.class,assignmentsDataResponses,"任务管理","任务管理列表");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
// Copyright tang. All rights reserved.
|
||||
// https://gitee.com/benbenyezi/dbswitch
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
//
|
||||
// Author: Li Zemin
|
||||
// Date : 2024/4/23 16:12
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.admin.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.gitee.dbswitch.admin.common.exception.DbswitchException;
|
||||
import com.gitee.dbswitch.admin.common.response.ResultCode;
|
||||
|
||||
/**
|
||||
* excel工具类
|
||||
*
|
||||
* @author Li Zemin
|
||||
* @since 2024/4/23 16:12
|
||||
*/
|
||||
public final class EasyexcelUtils {
|
||||
|
||||
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");
|
||||
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");
|
||||
EasyExcel.write(response.getOutputStream(), clazz)
|
||||
.sheet(sheetName)
|
||||
.doWrite(list);
|
||||
} catch (IOException ex) {
|
||||
throw new DbswitchException(ResultCode.ERROR_INTERNAL_ERROR, ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user