package com.vincent.rsf.server.system.controller;
|
|
import com.vincent.rsf.framework.common.R;
|
import com.vincent.rsf.server.common.domain.BaseParam;
|
import com.vincent.rsf.server.common.domain.PageParam;
|
import com.vincent.rsf.server.common.service.AsyncListExportTaskService;
|
import com.vincent.rsf.server.common.utils.FileServerUtil;
|
import com.vincent.rsf.server.manager.utils.buildPageRowsUtils;
|
import com.vincent.rsf.server.system.entity.ExportTask;
|
import com.vincent.rsf.server.system.service.ExportTaskService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletResponse;
|
import java.io.File;
|
import java.util.Map;
|
|
@RestController
|
public class ExportTaskController extends BaseController {
|
|
@Autowired
|
private ExportTaskService exportTaskService;
|
|
@Autowired
|
private AsyncListExportTaskService asyncListExportTaskService;
|
|
@PreAuthorize("hasAuthority('system:exportTask:list')")
|
@PostMapping("/exportTask/page")
|
public R page(@RequestBody Map<String, Object> map) {
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
if (baseParam.getOrderBy() == null || baseParam.getOrderBy().trim().isEmpty()) {
|
baseParam.setOrderBy("create_time desc");
|
}
|
|
PageParam<ExportTask, BaseParam> pageParam = new PageParam<>(baseParam, ExportTask.class);
|
|
return R.ok().add(
|
buildPageRowsUtils.rowsMap(
|
exportTaskService.page(
|
pageParam,
|
pageParam.buildWrapper(true)
|
.eq("deleted", 0)
|
.eq("tenant_id", getTenantId())
|
.eq("create_by", getLoginUserId())
|
)
|
)
|
);
|
}
|
|
@PreAuthorize("hasAuthority('system:exportTask:list')")
|
@GetMapping("/exportTask/{taskId}")
|
public R get(@PathVariable("taskId") Long taskId) {
|
ExportTask task = asyncListExportTaskService.getTask(taskId, getTenantId(), getLoginUserId());
|
if (task == null) {
|
return R.error("导出任务不存在");
|
}
|
return R.ok().add(buildPageRowsUtils.rowsMap(task));
|
}
|
|
@PreAuthorize("hasAuthority('system:exportTask:list')")
|
@GetMapping("/exportTask/{taskId}/download")
|
public void download(
|
@PathVariable("taskId") Long taskId,
|
HttpServletResponse response,
|
HttpServletRequest request
|
) {
|
File file = asyncListExportTaskService.getDownloadFile(taskId, getTenantId(), getLoginUserId());
|
FileServerUtil.preview(file, true, file.getName(), null, null, response, request);
|
}
|
}
|