2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-13 aff79ef4ee875cd72b124982f4123e53013f03e4
单灯数据导出
已修改3个文件
21 ■■■■ 文件已修改
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportDataMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/LightController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportDataService.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportDataMapper.java
@@ -1,12 +1,13 @@
package com.sandu.ximon.dao.mapper;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sandu.ximon.dao.bo.LightReportDataBo;
import com.sandu.ximon.dao.domain.LightReportData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.util.List;
/**
@@ -31,6 +32,7 @@
     * @param deviceCode 设备码
     * @return 上报数据
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    List<LightReportDataBo> listReportData(String keyword, String deviceCode);
    /**
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/LightController.java
@@ -108,8 +108,8 @@
        if (length != 24) {
            return ResponseUtil.fail("设备编号长度不正确");
        }
        String url = lightReportDataService.exportList(request,response, deviceCode);
        return ResponseUtil.success(url);
        lightReportDataService.exportList(request,response, deviceCode);
        return ResponseUtil.success("导出成功");
    }
    @GetMapping("/error/list")
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportDataService.java
@@ -47,6 +47,7 @@
    private final FileProperties properties;
    private final AliOssFileServiceImpl fileService;
    private final LightReportDataMapper lightReportDataMapper;
    /**
     * 保存上报的灯心跳数据
@@ -132,7 +133,7 @@
    }
    @SneakyThrows
    public String exportList(HttpServletRequest request, HttpServletResponse response, String deviceCode) {
    public void exportList(HttpServletRequest request, HttpServletResponse response, String deviceCode) {
        if (SecurityUtils.getClientId() != null) {
            PoleBinding one = SpringContextHolder.getBean(PoleBindingService.class).getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode)
@@ -149,7 +150,7 @@
            }
        }
        List<LightReportDataBo> list = baseMapper.listReportData(null, deviceCode);
        List<LightReportDataBo> list = lightReportDataMapper.listReportData(null, deviceCode);
        File file = new File("./" + RandomUtil.randomString(12) + ".xlsx");
@@ -158,8 +159,7 @@
        //文件流化返回给前端
        findfile(request, response, file);
        //删除文件
        file.delete();
        return null;
       // file.delete();
    }
    /**
@@ -174,8 +174,6 @@
        ServletOutputStream out = null;
        FileInputStream ips = null;
        try {
            //获取文件存放的路径
            String fileName = file.getName();
            //获取到文字 数据库里对应的附件名字加上老的文件名字:filename 截取到后面的文件类型 例:txt  组成一个新的文件名字:newFileName
            //生成3个随机数,用来生成新的文件名字
            String newFileName = "单灯数据" + RandomUtil.randomString(3) + ".xlsx";
@@ -201,6 +199,7 @@
            try {
                out.close();
                ips.close();
                file.delete();
            } catch (IOException e) {
                System.out.println("关闭流出现异常");
                e.printStackTrace();