增加导出功能
This commit is contained in:
+85
@@ -37,6 +37,16 @@ import com.bms.price.search.EsLogType;
|
||||
import com.bms.price.search.IBillSearchStore;
|
||||
import com.bms.price.search.TabOrderSyncEsLog;
|
||||
import com.bms.price.task.TabOrderCompareAsyncRunner;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import com.bms.common.config.BmsConfig;
|
||||
import com.bms.common.utils.DateUtils;
|
||||
import com.bms.common.utils.file.FileUtils;
|
||||
import com.bms.common.utils.uuid.IdUtils;
|
||||
import com.bms.price.domain.vo.TabOrderExportTask;
|
||||
import com.bms.price.task.TabOrderExportAsyncRunner;
|
||||
import com.bms.price.task.TabOrderSyncAsyncRunner;
|
||||
|
||||
/**
|
||||
@@ -58,6 +68,9 @@ public class TabOrderMonitorController extends BaseController
|
||||
@Autowired
|
||||
private TabOrderCompareAsyncRunner tabOrderCompareAsyncRunner;
|
||||
|
||||
@Autowired
|
||||
private TabOrderExportAsyncRunner tabOrderExportAsyncRunner;
|
||||
|
||||
@Autowired
|
||||
private IBillSearchStore billSearchStore;
|
||||
|
||||
@@ -320,6 +333,78 @@ public class TabOrderMonitorController extends BaseController
|
||||
/**
|
||||
* 列表查询:有任一单号即可查询;无单号时必须客户(名称或代码)+提货时间。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 异步导出订单数源:按当前筛选(须有单号,或客户+提货时间)。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:export')")
|
||||
@Log(title = "订单数源", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public AjaxResult export(@RequestBody(required = false) TabOrderMonitorQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
query = new TabOrderMonitorQuery();
|
||||
}
|
||||
if (!hasListFilters(query))
|
||||
{
|
||||
return error("请先设置列表查询条件后再导出");
|
||||
}
|
||||
customerKeywordResolver.resolve(query);
|
||||
String taskId = IdUtils.fastSimpleUUID();
|
||||
String fileName = "订单数源_" + DateUtils.dateTimeNow() + ".xlsx";
|
||||
tabOrderExportAsyncRunner.put(taskId, TabOrderExportTask.STATUS_PENDING, 0, "queued", null,
|
||||
fileName, null, 0);
|
||||
tabOrderExportAsyncRunner.run(taskId, query, fileName);
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("taskId", taskId);
|
||||
return success(data);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:export')")
|
||||
@GetMapping("/export/task/{taskId}")
|
||||
public AjaxResult exportTask(@PathVariable("taskId") String taskId)
|
||||
{
|
||||
TabOrderExportTask task = tabOrderExportAsyncRunner.get(taskId);
|
||||
if (task == null)
|
||||
{
|
||||
return error("export task not found or expired");
|
||||
}
|
||||
return success(task);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:export')")
|
||||
@GetMapping("/export/download/{taskId}")
|
||||
public void exportDownload(@PathVariable("taskId") String taskId, HttpServletResponse response)
|
||||
throws Exception
|
||||
{
|
||||
TabOrderExportTask task = tabOrderExportAsyncRunner.get(taskId);
|
||||
if (task == null)
|
||||
{
|
||||
throw new com.bms.common.exception.ServiceException("export task not found or expired");
|
||||
}
|
||||
if (!TabOrderExportTask.STATUS_SUCCESS.equals(task.getStatus())
|
||||
|| StringUtils.isEmpty(task.getStorageKey()))
|
||||
{
|
||||
throw new com.bms.common.exception.ServiceException("export file not ready");
|
||||
}
|
||||
if (!FileUtils.checkAllowDownload(task.getStorageKey()))
|
||||
{
|
||||
throw new com.bms.common.exception.ServiceException("export file missing");
|
||||
}
|
||||
Path downloadRoot = Paths.get(BmsConfig.getDownloadPath()).toAbsolutePath().normalize();
|
||||
Path filePath = downloadRoot.resolve(task.getStorageKey()).normalize();
|
||||
if (!filePath.startsWith(downloadRoot) || !Files.isRegularFile(filePath))
|
||||
{
|
||||
throw new com.bms.common.exception.ServiceException("export file missing");
|
||||
}
|
||||
String fileName = StringUtils.isNotEmpty(task.getFileName()) ? task.getFileName() : (taskId + ".xlsx");
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
FileUtils.setAttachmentResponseHeader(response, fileName);
|
||||
FileUtils.writeBytes(filePath.toString(), response.getOutputStream());
|
||||
}
|
||||
|
||||
|
||||
private static boolean hasListFilters(TabOrderMonitorQuery query)
|
||||
{
|
||||
return hasRequiredFilters(query) || hasNonBlankItem(query.getOrderIdentifiers());
|
||||
|
||||
Reference in New Issue
Block a user