| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.sxkj.gd.common.IdParam; |
| | | import org.sxkj.gd.workorder.entity.GdPatrolTaskEntity; |
| | | import org.sxkj.gd.workorder.entity.GdWorkOrderEntity; |
| | | import org.sxkj.gd.workorder.enums.PatrolTaskStatusEnum; |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskAddParam; |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskAuditParam; |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskPageParam; |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskUpdateParam; |
| | | import org.sxkj.gd.workorder.vo.GdClueEventVO; |
| | | import org.sxkj.gd.workorder.vo.GdPatrolTaskVO; |
| | | import org.sxkj.gd.workorder.excel.GdPatrolTaskExcel; |
| | | import org.sxkj.gd.workorder.wrapper.GdPatrolTaskWrapper; |
| | |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.system.cache.SysCache; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.io.File; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.util.ArrayList; |
| | | import java.util.Map; |
| | | import java.util.List; |
| | |
| | | @PostMapping("/export-report") |
| | | @ApiOperationSupport(order = 13) |
| | | @ApiOperation(value = "导出巡查报告", notes = "传入巡查任务id") |
| | | public R<String> exportReport(@RequestParam Long id) { |
| | | public R<Boolean> exportReport(@RequestParam Long id) { |
| | | if (id == null) { |
| | | return R.fail("巡查任务id不能为空"); |
| | | } |
| | | File reportFile = gdPatrolTaskService.exportPatrolReport(id); |
| | | File savedFile = saveReportToResources(reportFile, id); |
| | | return R.data(savedFile.getAbsolutePath()); |
| | | boolean saved = gdPatrolTaskService.exportPatrolReport(id); |
| | | return R.data(saved); |
| | | } |
| | | |
| | | private File saveReportToResources(File reportFile, Long patrolTaskId) { |
| | | if (reportFile == null || !reportFile.exists()) { |
| | | throw new RuntimeException("生成的巡查报告文件不存在"); |
| | | } |
| | | Path resourcesDir = resolveResourcesDir(); |
| | | String fileName = "gd_patrol_report_" + patrolTaskId + "_" + DateUtil.time() + ".docx"; |
| | | Path targetPath = resourcesDir.resolve(fileName); |
| | | try { |
| | | Files.createDirectories(resourcesDir); |
| | | Files.copy(reportFile.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING); |
| | | return targetPath.toFile(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("保存巡查报告失败", e); |
| | | } |
| | | } |
| | | |
| | | private Path resolveResourcesDir() { |
| | | String userDir = System.getProperty("user.dir"); |
| | | if (StringUtil.isBlank(userDir)) { |
| | | throw new RuntimeException("无法获取工作目录"); |
| | | } |
| | | Path basePath = Paths.get(userDir); |
| | | if (basePath.endsWith("drone-gd")) { |
| | | return basePath.resolve("src").resolve("main").resolve("resources"); |
| | | } |
| | | if (basePath.endsWith("drone-service")) { |
| | | return basePath.resolve("drone-gd").resolve("src").resolve("main").resolve("resources"); |
| | | } |
| | | return basePath.resolve("drone-service").resolve("drone-gd").resolve("src").resolve("main").resolve("resources"); |
| | | } |
| | | |
| | | } |