//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.jeecg.modules.jmreport.desreport.a;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.jeecg.modules.jmreport.api.data.IDataSetFactory;
import org.jeecg.modules.jmreport.common.ColumnCovertService;
//import org.jeecg.modules.jmreport.common.ExportExcelService;
import org.jeecg.modules.jmreport.common.annotation.JimuLoginRequired;
import org.jeecg.modules.jmreport.common.expetion.JimuReportException;
import org.jeecg.modules.jmreport.common.util.CommonUtils;
import org.jeecg.modules.jmreport.common.util.MinioUtil;
import org.jeecg.modules.jmreport.common.util.OssBootUtil;
import org.jeecg.modules.jmreport.common.util.ViewFreemarker;
import org.jeecg.modules.jmreport.common.util.oConvertUtils;
import org.jeecg.modules.jmreport.common.vo.JmDictModel;
import org.jeecg.modules.jmreport.common.vo.Result;
import org.jeecg.modules.jmreport.config.JmReportBaseConfig;
import org.jeecg.modules.jmreport.config.client.JmReportTokenClient;
import org.jeecg.modules.jmreport.config.oss.JmReportUploadConfig;
import org.jeecg.modules.jmreport.desreport.a.service.a.IJmReportDbService;
import org.jeecg.modules.jmreport.desreport.entity.JimuReport;
import org.jeecg.modules.jmreport.desreport.entity.JmReportDataSource;
import org.jeecg.modules.jmreport.desreport.entity.JmReportDb;
import org.jeecg.modules.jmreport.desreport.entity.JmReportDbField;
import org.jeecg.modules.jmreport.desreport.entity.JmReportDbParam;
import org.jeecg.modules.jmreport.desreport.model.QueryVO;
import org.jeecg.modules.jmreport.desreport.render.utils.FreeMarkerUtils;
import org.jeecg.modules.jmreport.desreport.service.IJimuReportService;
import org.jeecg.modules.jmreport.desreport.service.IJmReportDbFieldService;
import org.jeecg.modules.jmreport.desreport.service.IJmReportDbParamService;
import org.jeecg.modules.jmreport.desreport.service.IJmReportDbSourceService;
import org.jeecg.modules.jmreport.desreport.service.IJmReportExportExcel;
import org.jeecg.modules.jmreport.desreport.service.IJmReportExportPdf;
import org.jeecg.modules.jmreport.desreport.service.IJmReportMapService;
import org.jeecg.modules.jmreport.desreport.util.d;
import org.jeecg.modules.jmreport.desreport.util.e;
import org.jeecg.modules.jmreport.dyndb.vo.JmreportDynamicDataSourceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.HandlerMapping;

@RestController("designReportController")
@RequestMapping({"/jmreport"})
public class a {
    private static final Logger a = LoggerFactory.getLogger(a.class);
    @Value("classpath:static/jmreport/json/excel.virtual.json")
    private Resource virtualJson;
    @Autowired
    private IJimuReportService jmReportDesignService;
    @Autowired
    private IJmReportDbService reportDbService;
    @Autowired
    private IJmReportDbParamService jmReportDbParamService;
    @Autowired
    private IJmReportDbFieldService jmReportDbFieldService;
    @Autowired
    private IJmReportDbSourceService jmReportDbSourceService;
    @Autowired
    private IJmReportMapService jmReportMapService;
    @Autowired
    private IJmReportExportExcel exportExcel;
//    @Autowired
//    private ExportExcelService exportExcelService;
    @Autowired
    private JmReportTokenClient jimuTokenClient;
    @Autowired
    private JmReportUploadConfig jimuReportUploadConfig;
    @Autowired
    private JmReportBaseConfig jmBaseConfig;
    @Autowired
    private IJmReportExportPdf jmReportExportPdf;

    public a() {
    }

    @RequestMapping({"/demo"})
    public void a(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器demo --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest) var1, (HttpServletResponse) var2, (Map) var3, (String) "jmreport/desreport/demo.ftl");
    }

    @RequestMapping({"/list"})
    public void b(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器列表展示 --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest) var1, (HttpServletResponse) var2, (Map) var3, (String) "jmreport/desreport/list.ftl");
    }

    @PostMapping({"/excelCreate"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JimuReport var2) {
        a.debug("============EXCEL模板创建/编辑==========");

        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            var2.setCreateBy(var3);
            var2 = this.jmReportDesignService.excelCreate(var2);
        } catch (Exception var4) {
            a.error(var4.getMessage(), var4);
            return Result.error(var4.getMessage());
        }

        return Result.OK(var2);
    }

    @PostMapping({"/excelQueryName"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JimuReport var2) {
        boolean var3 = this.jmReportDesignService.excelQueryName(var2);
        return var3 ? Result.OK() : Result.FAIL("您输入的报表名字已经存在，换一个吧！", var3);
    }

    @GetMapping({"/excelQuery"})
    @JimuLoginRequired
    public Result<?> a(@RequestParam(name = "reportType", required = false) String var1, @RequestParam(name = "name") String var2, @RequestParam(name = "pageNo", defaultValue = "1") Integer var3, @RequestParam(name = "pageSize", defaultValue = "10") Integer var4, HttpServletRequest var5) {
        a.debug("============EXCEL模板查询==========");
        return this.jmReportDesignService.excelQuery(var1, var2, var5, var3, var4);
    }

    @GetMapping({"/excelQueryByTemplate"})
    public Result<?> b(@RequestParam(name = "reportType", required = false) String var1, @RequestParam(name = "name") String var2, @RequestParam(name = "pageNo", defaultValue = "1") Integer var3, @RequestParam(name = "pageSize", defaultValue = "10") Integer var4, HttpServletRequest var5) {
        return this.jmReportDesignService.excelQueryByTemplate(var1, var2, var5, var3, var4);
    }

    @GetMapping({"/userinfo"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1) {
        Result var2 = Result.OK();
        String var3 = this.jimuTokenClient.getUsername(var1);
        var2.setMessage(var3);
        return Result.OK(var2);
    }

    public void c(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器 --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest) var1, (HttpServletResponse) var2, (Map) var3, (String) "jmreport/desreport/index.ftl");
    }

    @RequestMapping({"/index/{id}"})
    public void a(@PathVariable("id") String var1, HttpServletRequest var2, HttpServletResponse var3) throws Exception {
        a.debug(" --- 进入报表设计器 --- ");
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("mode", this.jmBaseConfig.getMode());
        String var5 = "jmreport/desreport/index.ftl";
        a.info("进入设计器页面，saas: " + this.jmBaseConfig.getSaas() + " ,登录Token: " + this.jimuTokenClient.getToken());
        if (this.jmBaseConfig.getSaas() && oConvertUtils.isNotEmpty(this.jimuTokenClient.getToken())) {
            String var6 = this.jimuTokenClient.getUsername(var2);
            JimuReport var7 = this.jmReportDesignService.getById(var1);
            if (var7 != null && !var6.equals(var7.getCreateBy())) {
                var5 = "jmreport/desreport/authority.ftl";
            }
        }

        this.a((HttpServletRequest) var2, (HttpServletResponse) var3, (Map) var4, (String) var5);
    }

    @RequestMapping({"/view/{id}"})
    public void b(@PathVariable("id") String var1, HttpServletRequest var2, HttpServletResponse var3) throws Exception {
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("shareView", "0");
        this.a((HttpServletRequest) var2, (HttpServletResponse) var3, (Map) var4, (String) "jmreport/desreport/view.ftl");
    }

    @RequestMapping({"/shareView/{id}"})
    public void a(@PathVariable("id") String var1, HttpServletResponse var2, HttpServletRequest var3) throws Exception {
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("shareView", "1");
        this.a((HttpServletRequest) var3, (HttpServletResponse) var2, (Map) var4, (String) "jmreport/desreport/view.ftl");
    }

    @PostMapping({"/addViewCount/{id}"})
    public Result<?> a(@PathVariable("id") String var1) {
        Integer var2 = this.jmReportDesignService.updateViewCount(var1);
        boolean var3 = false;
        if (var2 > 0) {
            var3 = true;
        }

        return Result.OK("", var3);
    }

    @GetMapping({"/checkParam/{id}"})
    public Result<List<JmReportDbParam>> b(@PathVariable(name = "id") String var1) {
        Result var2 = new Result();
        List var3 = this.jmReportDesignService.queryReportParam(var1);
        if (var3 != null && var3.size() != 0) {
            var2.setSuccess(true);
            var2.setResult(var3);
        } else {
            var2.setSuccess(false);
        }

        return var2;
    }

    @RequestMapping({"/show"})
    public Result<?> a(@RequestParam(name = "id") String var1, HttpServletRequest var2) {
        String var3 = var2.getParameter("params");

        try {
            return this.jmReportDesignService.show(var1, var3);
        } catch (Exception var5) {
            a.error(var5.getMessage(), var5);
            return Result.error(var5.getMessage());
        }
    }

    @PostMapping({"/save"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JSONObject var2) {
        try {
            JimuReport var3 = this.jmReportDesignService.saveReport(var2, var1);
            return Result.OK(var3);
        } catch (Exception var4) {
            a.error(var4.getMessage(), var4);
            return Result.error("保存失败！");
        }
    }

    @GetMapping({"/get/{id}"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @PathVariable("id") String var2) {
        a.debug("============EXCEL JSON数据查询==========");
        JimuReport var3 = this.jmReportDesignService.getById(var2);
        return Result.OK(var3);
    }

    @GetMapping({"/mockPieData"})
    public Result<?> a() {
        a.debug("============模拟图表数据==========");
        ArrayList var1 = new ArrayList();
        String[] var2 = new String[]{"IE", "Safari", "Firefox", "Opera", "Chrome"};
        Random var3 = new Random();
        String[] var4 = var2;
        int var5 = var2.length;

        for (int var6 = 0; var6 < var5; ++var6) {
            String var7 = var4[var6];
            HashMap var8 = new HashMap();
            var8.put("name", var7);
            var8.put("value", var3.nextInt(1901) + 100);
            var1.add(var8);
        }

        return Result.OK(var1);
    }

    @GetMapping({"/mockChartData"})
    public Result<?> b() {
        a.debug("============模拟图表数据2==========");
        ArrayList var1 = new ArrayList();
        String[] var2 = new String[]{"邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"};
        Random var3 = new Random();
        String[] var4 = var2;
        int var5 = var2.length;

        for (int var6 = 0; var6 < var5; ++var6) {
            String var7 = var4[var6];
            HashMap var8 = new HashMap();
            var8.put("name", var7);
            ArrayList var9 = new ArrayList();

            for (int var10 = 0; var10 < 7; ++var10) {
                var9.add(var3.nextInt(1901) + 100);
            }

            var8.put("data", var9);
            var1.add(var8);
        }

        return Result.OK(var1);
    }

    @PostMapping({"/upload"})
    public Result<?> d(HttpServletRequest var1, HttpServletResponse var2) {
        Result var3 = new Result();

        try {
            MultipartHttpServletRequest var4 = (MultipartHttpServletRequest) var1;
            MultipartFile var5 = var4.getFile("file");
            String var6 = var1.getParameter("bizType");
            if (oConvertUtils.isEmpty(var6)) {
                var6 = this.jimuReportUploadConfig.getUploadType();
            }

            String var7 = "";
            a.debug("文件上传开始------------------------------uploadType  " + var6);
            if ("alioss".equals(var6)) {
                a.debug("进入OSS方法----->CommonConstant.UPLOAD_TYPE_OSS  alioss");
                var7 = OssBootUtil.upload(var5, "designreport/images");
            } else if ("minio".equals(var6)) {
                a.debug("进入MINIO方法----->CommonConstant.UPLOAD_TYPE_MINIO  minio");
                var7 = MinioUtil.upload(var5, "designreport/images");
            } else if ("local".equals(var6)) {
                a.debug("进入LOCAL方法----->CommonConstant.UPLOAD_TYPE_LOCAL local");
                var7 = this.a(var5, "excel_online");
            }

            a.debug("文件上传结束------------------------------返回url", var7);
            var3.setMessage(var7);
            var3.setSuccess(true);
        } catch (Exception var8) {
            var3.setSuccess(false);
            var3.setMessage("");
            a.error(var8.getMessage(), var8);
        }

        return var3;
    }

    @CrossOrigin
    @GetMapping({"/img/**"})
    public void e(HttpServletRequest var1, HttpServletResponse var2) {
        String var3 = e(var1);
        BufferedInputStream var4 = null;
        ServletOutputStream var5 = null;

        try {
            var3 = var3.replace("..", "");
            if (var3.endsWith(",")) {
                var3 = var3.substring(0, var3.length() - 1);
            }

            var2.setContentType("image/jpeg;charset=utf-8");
            String var6 = this.jimuReportUploadConfig.getPath().getUpload();
            String var7 = var6 + File.separator + var3;
            var4 = new BufferedInputStream(new FileInputStream(var7));
            var5 = var2.getOutputStream();
            byte[] var8 = new byte[1024];

            int var9;
            while ((var9 = var4.read(var8)) > 0) {
                var5.write(var8, 0, var9);
            }

            var2.flushBuffer();
        } catch (IOException var22) {
            a.error("预览图片失败" + var22.getMessage(), var22);
        } finally {
            if (var4 != null) {
                try {
                    var4.close();
                } catch (IOException var21) {
                    a.error(var21.getMessage(), var21);
                }
            }

            if (var5 != null) {
                try {
                    var5.close();
                } catch (IOException var20) {
                    a.error(var20.getMessage(), var20);
                }
            }

        }

    }

    private String a(File var1) {
        Scanner var2 = null;
        StringBuilder var3 = new StringBuilder();

        try {
            var2 = new Scanner(var1, "utf-8");

            while (var2.hasNextLine()) {
                var3.append(var2.nextLine());
            }
        } catch (Exception var8) {
            var8.printStackTrace();
        } finally {
            if (var2 != null) {
                var2.close();
            }

        }

        return var3.toString();
    }

    private void a(HttpServletRequest var1, HttpServletResponse var2, Map var3, String var4) throws Exception {
        try {
            var3.put("base", var1.getContextPath());
            var3.put("baseURL", d.a(var1));
            a.info("freemarker customPrePath: {}", oConvertUtils.getString(var1.getAttribute("customPrePath"), ""));
            var3.put("customPrePath", oConvertUtils.getString(var1.getAttribute("customPrePath"), ""));
            var3.put("reportConfig", JSON.toJSONString(this.jmBaseConfig));
        } catch (Exception var6) {
            var6.printStackTrace();
            var3.put("message", var6.getMessage());
        }

        ViewFreemarker.view(var1, var2, var4, var3);
    }

    private static String e(HttpServletRequest var0) {
        String var1 = (String) var0.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String var2 = (String) var0.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        return (new AntPathMatcher()).extractPathWithinPattern(var2, var1);
    }

    @PostMapping({"/loadTable"})
    public Result<?> a(HttpServletRequest var1, @RequestParam("dbSource") String var2, @RequestParam(name = "pageNo", defaultValue = "1") Integer var3, @RequestParam(name = "pageSize", defaultValue = "50") Integer var4) {
        a.debug("============加载表信息loadTable()==========");
        if (oConvertUtils.isNotEmpty(var2)) {
            JmreportDynamicDataSourceVo var5 = this.jmReportDbSourceService.getByDbKey(var2);
            if (var5 == null) {
                return Result.error("数据源不存在");
            }
        }

        List var7 = this.reportDbService.loadDataSourceTable(var2);
        Map var6 = e.a(var7, var3, var4);
        return Result.OK(var6);
    }

    @PostMapping({"/loadTableData"})
    public Result<?> a(HttpServletRequest var1, @RequestParam(value = "dbSource", required = false) String var2, @RequestParam(value = "tableName", required = false) String var3, @RequestParam(value = "pageNo", required = false) Integer var4, @RequestParam(value = "pageSize", required = false) Integer var5, @RequestParam(value = "sql", required = false) String var6, @RequestParam("paramArray") String var7) {
        a.debug("============加载表数据信息loadTableData()==========");
        if (oConvertUtils.isEmpty(var2) && this.jmBaseConfig.getSaas()) {
            return Result.error(1001, "数据源不允许为空，请选择数据源！");
        } else {
            JmreportDynamicDataSourceVo var8;
            if (oConvertUtils.isNotEmpty(var2)) {
                var8 = this.jmReportDbSourceService.getByDbKey(var2);
                if (var8 == null) {
                    return Result.error("数据源不存在");
                }
            }

            var8 = null;

            Map var11;
            try {
                var11 = this.reportDbService.loadTableData(var2, var3, var4, var5, var6, var7);
            } catch (Exception var10) {
                var10.printStackTrace();
                return Result.error("SQL执行失败，{}" + var10.getMessage());
            }

            return Result.OK(var11);
        }
    }

    @PostMapping({"/queryFieldBySql"})
    public Result<?> a(@RequestBody JSONObject var1) {
        a.debug("============解析sql==========");
        String var2 = var1.getString("sql");
        String var3 = var1.getString("dbSource");
        Object var4 = var1.get("paramArray");
        String var5 = var1.getString("type");
        String tableName = var1.getString("tableName");
        Integer var6 = 0;
        JmreportDynamicDataSourceVo var7 = null;
        if (oConvertUtils.isEmpty(var3) && this.jmBaseConfig.getSaas()) {
            return Result.error(1001, "数据源不允许为空，请选择数据源！");
        } else {
            if (oConvertUtils.isNotEmpty(var3)) {
                var7 = this.jmReportDbSourceService.getByDbKey(var3);
                var6 = var7.getConnectTimes();
                if (var6 != null && var6 > 5) {
                    return Result.error("数据源配置不正确,请修改!");
                }

                if (var7 == null) {
                    return Result.error("数据源不存在");
                }
            }

            try {
                Map var8 = this.reportDbService.parseReportSql(var2, var3, var4, var5, tableName);
                return var8.get("message") != null ? Result.OK(var8) : Result.OK("解析成功", var8);
            } catch (Exception var10) {
                if (var10 instanceof JimuReportException) {
                    JimuReportException var9 = (JimuReportException) var10;
                    return Result.error(var9.getExceptionCode(), var9.getMessage());
                } else {
                    return Result.error(var10.getMessage());
                }
            }
        }
    }

    @PostMapping({"/queryFieldByBean"})
    public Result<?> b(@RequestBody JSONObject var1) {
        a.debug("============解析javabean==========");
        String var2 = var1.getString("javaType");
        String var3 = var1.getString("javaValue");
        Boolean var4 = var1.getBoolean("isPage");
        JSONObject var5 = var1.getJSONObject("param");
        Map var6 = d.a(var5);

        try {
            Object var7 = d.c(var2, var3);
            if (var7 != null && var7 instanceof IDataSetFactory) {
                IDataSetFactory var8 = (IDataSetFactory) var7;
                List var9 = d.a(var8, var6, var4);
                return var9 != null && var9.size() != 0 ? Result.OK("解析成功", var9) : Result.error("解析成功但是无数据!");
            } else {
                return Result.error("javabean数据集需要实现接口IDataSetFactory");
            }
        } catch (Exception var10) {
            return Result.error(var10.getMessage());
        }
    }

    @PostMapping({"/executeSelectApi"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestParam("api") String var2, @RequestParam("method") String var3) {
        String var4 = var1.getParameter("token");
        String var5 = var1.getParameter("apiConvert");
        String var6 = var1.getParameter("paramArray");
        if (oConvertUtils.isEmpty(var4)) {
            var4 = this.jimuTokenClient.getToken();
        }

        a.info("报表executeSelectApi:: api= " + var2 + ", method= " + var3 + ", token= " + var4);
        Map var7 = this.reportDbService.executeSelectApi(var2, var3, var4, var5, var6);
        List var8 = this.reportDbService.parseData(var7);
        return Result.OK(var8);
    }

    @PostMapping({"/saveDb"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JmReportDb var2) {
        a.debug("============saveDb==========");

        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            var2.setCreateBy(var3);
            Date var4 = new Date();
            var2.setCreateTime(var4);
            var2.setUpdateTime(var4);
            var2 = this.reportDbService.saveDb(var2);
        } catch (Exception var5) {
            a.error(var5.getMessage(), var5);
            return Result.error(var5.getMessage());
        }

        return Result.OK(var2);
    }

    @GetMapping({"/field/tree/{reportId}"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @PathVariable("reportId") String var2) {
        a.debug("============fieldTree==========");
        Object var3 = new ArrayList();

        try {
            var3 = this.reportDbService.fieldTree(var2);
        } catch (Exception var5) {
            var5.printStackTrace();
        }

        return Result.OK(var3);
    }

    @GetMapping({"/queryIsPage/{reportId}"})
    @JimuLoginRequired
    public Result<?> c(HttpServletRequest var1, @PathVariable("reportId") String var2) {
        boolean var3 = this.reportDbService.queryIsPage(var2);
        return Result.OK(var3);
    }

    @GetMapping({"loadDbData/{dbId}"})
    @JimuLoginRequired
    public Result<?> d(HttpServletRequest var1, @PathVariable("dbId") String var2) {
        a.debug("============loadDbData==========");
        Map var3 = this.reportDbService.loadDbData(var2);
        return Result.OK(var3);
    }

    @GetMapping({"initDataSource"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1) {
        a.debug("============initDataSource==========");
        String var2 = "";
        if (this.jmBaseConfig.getSaas()) {
            var2 = this.jimuTokenClient.getUsername(var1);
        }

        List var3 = this.reportDbService.initDataSource(var2);
        return Result.OK(var3);
    }

    @GetMapping({"/delDbData/{dbId}"})
    @JimuLoginRequired
    public Result<?> e(HttpServletRequest var1, @PathVariable("dbId") String var2) {
        a.debug("============delDbData==========");
        this.reportDbService.delDbData(var2);
        return Result.OK();
    }

    @PostMapping({"/deleteParamByIds"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JSONObject var2) {
        a.debug("============deleteParamByIds==========");
        JSONArray var3 = var2.getJSONArray("selectIds");
        String var4 = var2.getString("id");
        String var5 = var2.getString("dbDynSql");
        this.jmReportDbParamService.deleteParamByIdsAndUpdateDbSql(var3, var4, var5);
        return Result.OK();
    }

    @DeleteMapping({"/deleteFieldByIds"})
    @JimuLoginRequired
    public Result<?> f(HttpServletRequest var1, @RequestBody String var2) {
        a.debug("============deleParams==========");
        this.jmReportDbFieldService.deleteByIds(var2);
        return Result.OK();
    }

    @DeleteMapping({"/delete"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> g(HttpServletRequest var1, @RequestParam(name = "id", required = true) String var2) {
        JimuReport var3 = new JimuReport();
        var3.setId(var2);
        var3.setDelFlag(1);
        this.jmReportDesignService.updateById(var3);
        return Result.OK("删除成功!", true);
    }

    @GetMapping({"/reportCopy"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> h(HttpServletRequest var1, @RequestParam(name = "id", required = true) String var2) {
        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            JimuReport var4 = new JimuReport();
            var4.setCreateBy(var3);
            Date var5 = new Date();
            var4.setCreateTime(var5);
            var4.setUpdateTime(var5);
            var4.setId(var2);
            this.jmReportDesignService.reportCopy(var4);
        } catch (Exception var6) {
            var6.printStackTrace();
            return Result.error(403, "您没有权限");
        }

        return Result.OK("复制成功!", true);
    }

    @GetMapping({"/setTemplate"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestParam(name = "id", required = true) String var2, @RequestParam(name = "template", required = true) Integer var3) {
        JimuReport var4 = new JimuReport();
        var4.setId(var2);
        var4.setTemplate(var3);
        Integer var5 = this.jmReportDesignService.updateById(var4);
        boolean var6 = false;
        if (var5 > 0) {
            var6 = true;
        }

        return Result.OK("设置成功!", var6);
    }

    @PostMapping({"/importExcel"})
    @ResponseBody
    @JimuLoginRequired
    public Result<Object> a(HttpServletRequest var1, @RequestParam("file") MultipartFile var2) throws IOException {
        Result var3 = new Result();
        Map var4 = this.jmReportDesignService.importExcel(var2);
        if (var4.size() > 0 && !var4.isEmpty()) {
            var3.setResult(var4);
            var3.setSuccess(true);
        } else {
            var3.setSuccess(false);
        }

        return var3;
    }

    @PostMapping({"/exportAllExcel"})
    @ResponseBody
    public Result<Object> a(HttpServletRequest var1, HttpServletResponse var2, @RequestBody JSONObject var3) throws IOException {
        HashMap var4 = new HashMap(var1.getParameterMap());
        boolean var5 = var4.containsKey("token");
        if (var5) {
            var4.remove("token");
        }

        String var6 = var3.getString("excelConfigId");
        JSONObject var7 = var3.getJSONObject("queryParam");
        long var8 = System.currentTimeMillis();
        JSONArray var10 = var3.getJSONArray("base64Arry");
        Map var11 = this.exportExcel.exportExcel(var6, var7, var10);
        File var12 = new File(var11.get("name").toString());
        ServletOutputStream var13 = var2.getOutputStream();
        SXSSFWorkbook var14 = (SXSSFWorkbook) var11.get("workbook");
        ByteArrayOutputStream var15 = new ByteArrayOutputStream();
        HashMap var16 = new HashMap();

        try {
            var14.write(var15);
            String var17 = Base64Utils.encodeToString(var15.toByteArray());
            var16.put("file", var17);
            var16.put("success", true);
            var16.put("name", var12.getName());
        } catch (IOException var26) {
            var26.printStackTrace();
            var16.put("error", var26.getMessage());
        } finally {
            try {
                var15.close();
            } catch (IOException var25) {
                var25.printStackTrace();
            }

        }

        long var28 = System.currentTimeMillis();
        a.info("导出excel数据运行时间：" + (var28 - var8) + "ms");
        return Result.OK(var16);
    }

    @PostMapping({"/exportEmptyExcel"})
    @ResponseBody
    public Result<Object> exportEmptyExcel(HttpServletRequest var1, HttpServletResponse var2, @RequestBody JSONObject var3) throws IOException {
        HashMap var4 = new HashMap(var1.getParameterMap());
        boolean var5 = var4.containsKey("token");
        if (var5) {
            var4.remove("token");
        }

        String var6 = var3.getString("excelConfigId");
        JSONObject var7 = var3.getJSONObject("queryParam");
        long var8 = System.currentTimeMillis();
        JSONArray var10 = var3.getJSONArray("base64Arry");
//        Map var11 = this.exportExcelService.exportEmptyExcel(var6, var7, var10);
        Map var11 = null;
        File var12 = new File(var11.get("name").toString());
        ServletOutputStream var13 = var2.getOutputStream();
        SXSSFWorkbook var14 = (SXSSFWorkbook) var11.get("workbook");
        ByteArrayOutputStream var15 = new ByteArrayOutputStream();
        HashMap var16 = new HashMap();

        try {
            var14.write(var15);
            String var17 = Base64Utils.encodeToString(var15.toByteArray());
            var16.put("file", var17);
            var16.put("success", true);
            var16.put("name", var12.getName());
        } catch (IOException var26) {
            var26.printStackTrace();
            var16.put("error", var26.getMessage());
        } finally {
            try {
                var15.close();
            } catch (IOException var25) {
                var25.printStackTrace();
            }

        }

        long var28 = System.currentTimeMillis();
        a.info("导出excel数据运行时间：" + (var28 - var8) + "ms");
        return Result.OK(var16);
    }

    @RequestMapping({"/print"})
    public void a(HttpServletResponse var1, HttpServletRequest var2) throws Exception {
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest) var2, (HttpServletResponse) var1, (Map) var3, (String) "jmreport/desreport/print.ftl");
    }

    @PostMapping({"/putFile"})
    @ResponseBody
    @JimuLoginRequired
    public Result<JimuReport> i(HttpServletRequest var1, @RequestParam String var2) {
        Result var3 = new Result();

        try {
            MultipartHttpServletRequest var4 = (MultipartHttpServletRequest) var1;
            MultipartFile var5 = var4.getFile("file");
            String var6 = "";
            String var7 = this.jimuReportUploadConfig.getUploadType();
            if ("alioss".equals(var7)) {
                var6 = OssBootUtil.upload(var5, "designreport/images");
            } else if ("minio".equals(var7)) {
                var6 = MinioUtil.upload(var5, "designreport/images");
            } else {
                var6 = this.a(var5, "excel_online");
            }

            JimuReport var8 = new JimuReport();
            if (oConvertUtils.isNotEmpty(var6) && oConvertUtils.isNotEmpty(var2)) {
                var8.setId(var2);
                var8.setThumb(var6);
                this.jmReportDesignService.updateById(var8);
                var3.setMessage("封面图上传成功!");
                var3.setResult(var8);
            }
        } catch (Exception var9) {
            var3.setSuccess(false);
            var3.setMessage("");
            a.error(var9.getMessage(), var9);
        }

        return var3;
    }

    @GetMapping({"/download/image"})
    @ResponseBody
    public Result<Object> f(HttpServletRequest var1, HttpServletResponse var2) throws IOException {
        String var3 = var1.getParameter("imageUrl");
        Result var4 = new Result();
        if (oConvertUtils.isEmpty(var3)) {
            var4.setSuccess(false);
            return var4;
        } else {
            if (!var3.contains("http")) {
                var4.setSuccess(true);
                var4.setResult(var3);
            }

            String var5 = File.separator + "designreport" + File.separator + "images" + File.separator;
            String var6 = var3.substring(var3.lastIndexOf("/") + 1);
            String var7 = this.jimuReportUploadConfig.getPath().getUpload();
            File var8 = new File(var7 + var5);
            if (!var8.exists()) {
                var8.mkdirs();
            }

            a.debug("----imageUrl------" + var3);
            a.debug("----fileName------" + var6);
            a.debug("----downFilePath------" + var7 + var5 + var6);
            File var9 = new File(var7 + var5 + var6);
            if (!var9.exists()) {
                d.a(var3, var9);
            }

            var4.setSuccess(true);
            var4.setResult(var5 + var6);
            return var4;
        }
    }

    private String a(MultipartFile var1, String var2) {
        try {
            String var3 = this.jimuReportUploadConfig.getPath().getUpload();
            a.info(" --- local upload path : " + var3 + " --- ");
            String var4 = null;
            File var5 = new File(var3 + File.separator + var2 + File.separator);
            if (!var5.exists()) {
                var5.mkdirs();
            }

            String var6 = var1.getOriginalFilename();
            var6 = CommonUtils.getFileName(var6);
            if (var6.indexOf(".") != -1) {
                var4 = var6.substring(0, var6.lastIndexOf(".")) + "_" + System.currentTimeMillis() + var6.substring(var6.indexOf("."));
            } else {
                var4 = var6 + "_" + System.currentTimeMillis();
            }

            String var7 = var5.getPath() + File.separator + var4;
            File var8 = new File(var7);
            FileCopyUtils.copy(var1.getBytes(), var8);
            String var9 = null;
            if (oConvertUtils.isNotEmpty(var2)) {
                var9 = var2 + File.separator + var4;
            } else {
                var9 = var4;
            }

            if (var9.contains("\\")) {
                var9 = var9.replace("\\", "/");
            }

            return var9;
        } catch (IOException var10) {
            a.error(var10.getMessage(), var10);
            return "";
        }
    }

    @PostMapping({"/addDataSource"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        return this.reportDbService.addDataSource(var2, var1);
    }

    @PostMapping({"/querySourceCode"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        boolean var3 = this.reportDbService.querySourceCode(var2);
        return Result.OK(var3);
    }

    @PostMapping({"/delDataSource"})
    @JimuLoginRequired
    public Result<?> c(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        this.reportDbService.delDataSource(var2);
        return Result.OK("删除成功", true);
    }

    @PostMapping({"/testConnection"})
    public Result a(@RequestBody JmreportDynamicDataSourceVo var1) {
        Connection var2 = null;

        Result var3;
        try {
            Result var4;
            try {
                Class.forName(var1.getDbDriver());
                DriverManager.setLoginTimeout(10);
                var2 = DriverManager.getConnection(var1.getDbUrl(), var1.getDbUsername(), var1.getDbPassword());
                if (var2 != null) {
                    var3 = Result.OK("数据库连接成功", true);
                    return var3;
                }

                var3 = Result.OK("数据库连接失败：错误未知", true);
            } catch (ClassNotFoundException var17) {
                a.error(var17.toString());
                var4 = Result.error("数据库连接失败：驱动类不存在");
                return var4;
            } catch (Exception var18) {
                a.error(var18.toString());
                var4 = Result.error("数据库连接失败：" + var18.getMessage());
                return var4;
            }
        } finally {
            try {
                if (var2 != null && !var2.isClosed()) {
                    var2.close();
                }
            } catch (SQLException var16) {
                a.error(var16.toString());
            }

        }

        return var3;
    }

    @RequestMapping({"/qurestApi"})
    public Result<?> b(@RequestParam(name = "apiSelectId") String var1, HttpServletRequest var2) {
        String var3 = "";
        JmReportDb var4 = this.reportDbService.getById(var1);
        if (var4 == null) {
            return Result.ok("");
        } else {
            String var5 = var2.getParameter("token");
            if (oConvertUtils.isEmpty(var5)) {
                var5 = var2.getHeader("token");
            }

            String var6 = var4.getApiUrl();
            Map var7 = this.jimuTokenClient.getUserInfo(var5);
            var6 = d.a(var6, var7, this.jmBaseConfig.getApiBasePath());
            List var8 = this.jmReportDbParamService.list(var4.getId());
            HashMap var9;
            Iterator var10;
            JmReportDbParam var11;
            if ("1".equals(var4.getDbType())) {
                var9 = new HashMap();
                var10 = var8.iterator();

                while (var10.hasNext()) {
                    var11 = (JmReportDbParam) var10.next();
                    if (var6.indexOf(var11.getParamName()) > 0) {
                        var9.put(var11.getParamName(), var11.getParamValue());
                    }
                }

                String var15 = FreeMarkerUtils.a(var6, var9);
                var15 = var15.replace("'", "");
                if ("0".equals(var4.getApiMethod())) {
                    var3 = d.b(var15, var5);
                } else {
                    var3 = d.a(var15, var5, (JSONObject) null);
                }

                JSONObject var17 = JSONObject.parseObject(var3);
                return Result.OK(var17);
            } else if ("3".equals(var4.getDbType())) {
                JSONObject var13 = JSONObject.parseObject(var4.getJsonData());
                return Result.OK(var13);
            } else if (!"2".equals(var4.getDbType())) {
                return null;
            } else {
                var9 = new HashMap();
                var10 = var8.iterator();

                while (var10.hasNext()) {
                    var11 = (JmReportDbParam) var10.next();
                    var9.put(var11.getParamName(), var11.getParamValue());
                }

                JSONObject var14 = JSONObject.parseObject(var4.getJsonData());
                IDataSetFactory var16 = d.d(var4.getJavaType(), var4.getJavaValue());
                if ("1".equals(var4.getIsPage())) {
                    var16.createPageData(var9);
                    return Result.OK(var14);
                } else {
                    List var12 = var16.createData(var9);
                    return Result.OK(var12);
                }
            }
        }
    }

    @RequestMapping({"/qurestSql"})
    public Result<?> c(@RequestParam(name = "apiSelectId") String var1, HttpServletRequest var2) {
        JmReportDb var3 = this.reportDbService.getById(var1);
        List var4 = this.reportDbService.qurestechSql(var3);
        this.jmReportDesignService.replaceDbCode(var1, var4);
        return Result.OK(d.b(var4));
    }

    @GetMapping({"/dataCodeExist"})
    public Result<Boolean> a(@RequestParam(name = "reportId") String var1, @RequestParam(name = "code") String var2) {
        int var3 = this.reportDbService.getCount(var1, var2);
        return Result.OK(var3 > 0);
    }

    @GetMapping({"/getQueryInfo"})
    public Result<List<QueryVO>> a(@RequestParam(name = "reportId") String var1, HttpServletRequest var2, @RequestParam("param") String var3) {
        String var4 = this.jimuTokenClient.getUsername(var2);
        if (!this.jmBaseConfig.getSaas()) {
            var4 = "";
        }

        List var5 = this.jmReportDesignService.getReportQueryInfo(var1, var4, var3);
        return Result.OK(var5);
    }

    @RequestMapping({"/addChart"})
    @JimuLoginRequired
    public Result<?> d(@RequestParam(name = "chartType") String var1, HttpServletRequest var2) {
        JSONObject var3 = this.jmReportDesignService.addChart(var1);
        return Result.OK(var3);
    }

    @PostMapping({"/queryTableName"})
    public Result<?> a(HttpServletRequest var1, @RequestParam("dbSource") String var2, @RequestParam("tableName") String var3, @RequestParam(name = "pageNo", defaultValue = "1") Integer var4, @RequestParam(name = "pageSize", defaultValue = "50") Integer var5) {
        List var6 = this.reportDbService.queryTableName(var2, var3);
        Map var7 = e.a(var6, var4, var5);
        return Result.OK(var7);
    }

    @GetMapping({"/getReportByUser"})
    public Result<List<JimuReport>> j(HttpServletRequest var1, @RequestParam(name = "reportId") String var2) {
        Result var3 = new Result();
        String var4 = this.jimuTokenClient.getUsername(var1);
        List var5 = this.jmReportDesignService.getReportByUser(var4, var2);
        var3.setSuccess(true);
        var3.setResult(var5);
        return var3;
    }

    @GetMapping({"/getReportChars"})
    public Result<List<JSONObject>> b(@RequestParam(name = "reportId") String var1, @RequestParam(name = "charId", required = false) String var2) {
        ArrayList var3 = new ArrayList();
        JimuReport var4 = this.jmReportDesignService.getById(var1);
        if (var4 != null) {
            String var5 = var4.getJsonStr();
            JSONObject var6 = JSONObject.parseObject(var5);
            Object var7 = var6.get("chartList");
            if (null != var7) {
                JSONArray var8 = JSONArray.parseArray(var7.toString());

                for (int var9 = 0; var9 < var8.size(); ++var9) {
                    JSONObject var10 = new JSONObject();
                    Object var11 = var8.getJSONObject(var9).get("layer_id");
                    Object var12 = var8.getJSONObject(var9).get("config");
                    JSONObject var13 = JSONObject.parseObject(var12.toString());
                    JSONObject var14 = var13.getJSONObject("title");
                    Object var15 = var14.get("text");
                    if (null != var15 && null != var11) {
                        if (oConvertUtils.isNotEmpty(var2) && !var2.equals(var11)) {
                            var10.put("id", var11);
                            var10.put("name", var15);
                            var3.add(var10);
                        }

                        if (oConvertUtils.isEmpty(var2)) {
                            var10.put("id", var11);
                            var10.put("name", var15);
                            var3.add(var10);
                        }
                    }
                }
            }
        }

        return Result.OK(var3);
    }

    @GetMapping({"/getCharData"})
    public Result<JSONObject> a(@RequestParam(name = "reportId") String var1, @RequestParam(name = "charId") String var2, @RequestParam(name = "params") String var3, HttpServletRequest var4) {
        String var5 = var4.getParameter("X-Access-Token");
        JSONObject var6 = this.jmReportDesignService.getCharData(var1, var2, var3, var5);
        return Result.OK(var6);
    }

    @GetMapping({"/verificationToken"})
    public void c(HttpServletRequest var1) {
        this.jimuTokenClient.verifyToken(var1);
    }

    @PostMapping({"/exportPdf"})
    public Result<Object> b(HttpServletRequest var1, HttpServletResponse var2, @RequestBody JSONObject var3) {
        HashMap var4 = new HashMap(var1.getParameterMap());
        boolean var5 = var4.containsKey("token");
        if (var5) {
            var4.remove("token");
        }

        String var6 = var3.getString("excelConfigId");
        JSONObject var7 = var3.getJSONObject("queryParam");
        var7.put("printAll", true);
        Result var8 = this.jmReportDesignService.show(var6, var7.toJSONString());
        JimuReport var9 = (JimuReport) var8.getResult();
        String var10 = var1.getParameter("dpi");
        float var11 = 96.0F;
        if (oConvertUtils.isNotEmpty(var10)) {
            var11 = Float.parseFloat(var10);
        }

        JSONArray var12 = var3.getJSONArray("base64Arry");
        Map var13 = this.jmReportExportPdf.exportPdf(var9, var12, var11);
        return Result.OK(var13);
    }

    @GetMapping({"/getLinkageChartInfo"})
    public Result<Object> d(HttpServletRequest var1) {
        String var2 = var1.getParameter("reportId");
        String var3 = var1.getParameter("dbCode");
        String var4 = var1.getParameter("linkageDbCode");
        List var5 = this.jmReportDbParamService.queryParamByDbcode(var2, var4);
        List var6 = this.jmReportDbFieldService.queryFieldsByDbcode(var2, var3);
        HashMap var7 = new HashMap();
        var7.put("paramList", var5);
        var7.put("fieldList", var6);
        return Result.OK(var7);
    }

    @GetMapping({"/getListReportDb"})
    public Result<Map<String, Object>> c(@RequestParam(name = "reportId") String var1) {
        HashMap var2 = new HashMap();
        List var3 = this.reportDbService.getListReportDb(var1);
        new HashMap();
        HashMap var5 = new HashMap();
        Iterator var6 = var3.iterator();

        while (var6.hasNext()) {
            JmReportDb var7 = (JmReportDb) var6.next();
            List var8 = this.jmReportDbParamService.list(var7.getId());
            var5.put(var7.getDbCode(), var8);
        }

        var2.put("reportDbParam", var5);
        return Result.OK(var2);
    }

    @GetMapping({"/dictCodeSearch"})
    public Result<List<JmDictModel>> a(@RequestParam(name = "key") String var1, @RequestParam(name = "text") String var2, @RequestParam(name = "reportId") String var3) {
        Result var4 = new Result();
        List var5 = this.reportDbService.getListReportDb(var3);
        String var6 = this.jimuTokenClient.getUsername();
        if (oConvertUtils.isEmpty(var1)) {
            return null;
        } else {
            String[] var7 = var1.split("__");
            Iterator var8 = var5.iterator();

            while (true) {
                JmReportDb var9;
                do {
                    do {
                        if (!var8.hasNext()) {
                            return null;
                        }

                        var9 = (JmReportDb) var8.next();
                    } while (var7.length != 2);
                } while (!var7[0].equals(var9.getDbCode()));

                List var10 = this.jmReportDbFieldService.getByDbId(var9.getId());
                Iterator var11 = var10.iterator();

                while (var11.hasNext()) {
                    JmReportDbField var12 = (JmReportDbField) var11.next();
                    if (var12.getFieldName().equals(var7[1])) {
                        new JSONObject();
                        List var14 = this.jmReportDesignService.queryQueryDictList(var9, var12, var6, var2, (String) null);
                        var4.setResult(var14);
                        var4.setSuccess(true);
                        return var4;
                    }
                }
            }
        }
    }
}
