管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-11 bd24c3ba340543fd522df9f05ecfb16cac0ec296
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);
    }
}