燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-11 dc4ca57e049ec18d8303109d1aa332096b880a34
1
已修改4个文件
40 ■■■■■ 文件已修改
src/main/java/com/yssh/controller/XlsReportController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/mapper/XlsReportMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/service/XlsReportService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/XlsReportMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/controller/XlsReportController.java
@@ -15,6 +15,7 @@
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -59,4 +60,11 @@
        return Result.OK(list);
    }
    @ApiOperationSupport(order = 2)
    @GetMapping("/downloadById")
    @ApiOperation(value = "根据ID下载", notes = "根据ID下载")
    public void downloadById(@RequestParam(value = "id", required = true) int id, HttpServletResponse res) {
        xlsReportService.downloadById(id, res);
    }
}
src/main/java/com/yssh/mapper/XlsReportMapper.java
@@ -20,6 +20,11 @@
    List<XlsReport> selectReportByPage(@Param("type") String type, @Param("start") String start, @Param("end") String end, @Param("limit") Integer limit, @Param("offset") Integer offset);
    /**
     * 根据ID查询报告
     */
    XlsReport selectById(@Param("id") Integer id);
    /**
     * 报告是否存在
     */
    int reportExists(@Param("type") String type, @Param("name") String name);
src/main/java/com/yssh/service/XlsReportService.java
@@ -10,6 +10,7 @@
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.DateUtils;
import com.yssh.utils.ExcelUtils;
import com.yssh.utils.WebUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -17,6 +18,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;
@@ -343,4 +345,22 @@
            logger.error(ex.getMessage(), ex);
        }
    }
    /**
     * 根据ID下载
     */
    public void downloadById(Integer id, HttpServletResponse res) {
        XlsReport xlsReport = mapper.selectById(id);
        if (null == xlsReport) return;
        String file = reportPath + File.separator + xlsReport.getPath();
        File f = new File(file);
        if (!f.exists() || f.isDirectory()) return;
        try {
            WebUtils.download(file, xlsReport.getName(), false, res);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}
src/main/resources/mapper/XlsReportMapper.xml
@@ -21,6 +21,13 @@
        limit #{limit} offset #{offset}
    </select>
    <!-- 根据ID查询报告 -->
    <select id="selectById" resultType="com.yssh.entity.xls.XlsReport">
        select *
        from xls_report
        where id = #{id};
    </select>
    <!-- 报告是否存在 -->
    <select id="reportExists" resultType="java.lang.Integer">
        select count(*)