管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-11 bd24c3ba340543fd522df9f05ecfb16cac0ec296
1
已修改3个文件
111 ■■■■ 文件已修改
src/main/java/com/lf/server/config/InitConfig.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/ReportController.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/ReportService.java 83 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/config/InitConfig.java
@@ -17,6 +17,7 @@
import com.lf.server.service.show.LocateService;
import com.lf.server.service.sys.ArgsService;
import com.lf.server.service.sys.BlacklistService;
import com.lf.server.service.sys.ReportService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,6 +64,9 @@
    @Autowired
    Environment env;
    @Autowired
    ReportService reportService;
    @Override
    public void run(ApplicationArguments args) {
        // noinspection AlibabaRemoveCommentedCode
src/main/java/com/lf/server/controller/sys/ReportController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.ReportEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.service.all.UploadAttachService;
import com.lf.server.service.sys.ReportService;
import com.lf.server.service.sys.TokenService;
@@ -180,4 +181,27 @@
    public void download(String guid, HttpServletResponse res) {
        uploadAttachService.download(guid, res);
    }
    @SysLog()
    @ApiOperation(value = "下载报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guid", value = "附件Guid", dataType = "String", paramType = "body")
    })
    @GetMapping(value = "/downloadReport")
    public void downloadReport(Integer id, HttpServletResponse res) {
        try {
            if (null == id || id < 1) {
                return;
            }
            ReportEntity re = reportService.selectById(id);
            if (null == re || StringHelper.isEmpty(re.getGuid()) || StringHelper.isEmpty(re.getType()) || StringHelper.isEmpty(re.getCode())) {
                return;
            }
            reportService.createReport(re, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}
src/main/java/com/lf/server/service/sys/ReportService.java
@@ -1,15 +1,17 @@
package com.lf.server.service.sys;
import com.lf.server.entity.ctrl.CountEntity;
import com.lf.server.entity.sys.AttachEntity;
import com.lf.server.entity.sys.ReportEntity;
import com.lf.server.helper.FileHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WordHelper;
import com.lf.server.helper.*;
import com.lf.server.mapper.sys.ReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -20,6 +22,12 @@
public class ReportService implements ReportMapper {
    @Autowired
    ReportMapper reportMapper;
    @Autowired
    AttachService attachService;
    @Autowired
    PathHelper pathHelper;
    @Override
    public Integer selectCount(String name) {
@@ -91,68 +99,107 @@
    }
    /**
     * 创建报告
     */
    public void createReport(ReportEntity re, HttpServletResponse res) throws Exception {
        AttachEntity ae = attachService.selectByGuid(re.getGuid());
        if (null == ae) {
            return;
        }
        String source = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath();
        String targetName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + FileHelper.getExtension(ae.getName());
        String target = pathHelper.getShareFullPath() + File.separator + targetName;
        File sourceFile = new File(source);
        if (!sourceFile.exists() || sourceFile.isDirectory()) {
            return;
        }
        generateReport(source, target, re);
        File targetFile = new File(target);
        if (!targetFile.exists() || sourceFile.isDirectory()) {
            return;
        }
        WebHelper.download(target, targetName, res);
    }
    /**
     * 生成报告
     */
    private void generateReport(String source, String target, ReportEntity re) {
        if ("1".equals(re.getType())) {
            switch (re.getCode()) {
                case "countOperates ":
                    createCountOperatesWord(source, target);
                    break;
                case "countSizes":
                    createCountSizesWord(source, target);
                    break;
                default:
                    createCountServicesWord(source, target);
                    break;
            }
        } else {
            //
        }
    }
    /**
     * 创建 用户流量统计 Word
     */
    public void createCountOperatesWord() {
    public void createCountOperatesWord(String source, String target) {
        List<CountEntity> list = countOperates();
        if (null == list || list.isEmpty()) {
            return;
        }
        int rows = 1;
        String inputFile = "D:\\LF\\用户流量统计.docx";
        String outPutFile = "D:\\LF\\用户流量统计_new.docx";
        ArrayList<String[]> addList = new ArrayList<>();
        for (CountEntity ce : list) {
            String[] strs = new String[]{"" + rows++, ce.getM1(), ce.getM2(), ce.getCount().toString()};
            addList.add(strs);
        }
        WordHelper.generateWord(inputFile, outPutFile, null, addList);
        WordHelper.generateWord(source, target, null, addList);
    }
    /**
     * 创建 服务调用量统计 Word
     */
    public void createCountServicesWord() {
    public void createCountServicesWord(String source, String target) {
        List<CountEntity> list = countServices();
        if (null == list || list.isEmpty()) {
            return;
        }
        int rows = 1;
        String inputFile = "D:\\LF\\服务调用量统计.docx";
        String outPutFile = "D:\\LF\\服务调用量统计_new.docx";
        ArrayList<String[]> addList = new ArrayList<>();
        for (CountEntity ce : list) {
            String[] strs = new String[]{"" + rows++, ce.getM1(), ce.getCount().toString()};
            addList.add(strs);
        }
        WordHelper.generateWord(inputFile, outPutFile, null, addList);
        WordHelper.generateWord(source, target, null, addList);
    }
    /**
     * 创建 数据量统计 Word
     */
    public void createCountSizesWord() {
    public void createCountSizesWord(String source, String target) {
        List<CountEntity> list = countSizes();
        if (null == list || list.isEmpty()) {
            return;
        }
        int rows = 1;
        String inputFile = "D:\\LF\\数据量统计.docx";
        String outPutFile = "D:\\LF\\数据量统计_new.docx";
        ArrayList<String[]> addList = new ArrayList<>();
        for (CountEntity ce : list) {
            String[] strs = new String[]{"" + rows++, ce.getM1(), FileHelper.getSizes(ce.getSizes())};
            addList.add(strs);
        }
        WordHelper.generateWord(inputFile, outPutFile, null, addList);
        WordHelper.generateWord(source, target, null, addList);
    }
}