1821349743@qq.com
2023-02-20 059154a3b7d812b3bb4b89ecfa4d94f9b905f7e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.product.server.report.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.product.common.enums.IEnum;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.module.sys.version.ApiVersion;
import com.product.server.report.config.ReportCode;
import com.product.server.report.service.idel.EChartsReportConfigService;
 
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
/**
 * @author : shicf
 * @Description: 公司国际化语言Controller
 * @date :
 */
@RequestMapping("/api/report/config")
@RestController
public class EChartsReportConfigController extends AbstractBaseController {
    @Autowired
    public EChartsReportConfigService eChartsReportConfigService;
 
    @ResponseBody
    @RequestMapping(value = "/getTableInfo/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getTableInfo(HttpServletResponse response, HttpServletRequest request, HttpSession session) {
        Object bean = request.getAttribute("requestPara");
        RequestParameterEntity reqp = (RequestParameterEntity) bean;
        try {
            String customSql = reqp.getFormData().getValue("customSql").toString();
            //目前取得uuid
            String tableUuid = reqp.getFormData().getValue("tableName").toString();
            JSONObject fieldName = null;
 
            if (tableUuid == null || tableUuid.equals("")) {
                if (customSql == null || customSql.equals("")) {
                    return error(ReportCode.REPORT_TABLE_NOT_NULL.getValue(), ReportCode.REPORT_TABLE_NOT_NULL.getText());
                } else {
                    fieldName = eChartsReportConfigService.getSqlTableInfo(customSql);
                }
            } else {
                fieldName = eChartsReportConfigService.getNameTableInfo(tableUuid);
 
            }
            return BaseUtil.success(fieldName);
        } catch (BaseException e) {
            return error(ReportCode.REPORT_GET_FIELD_BE_DEFEATED.getText(), e.getMessage());
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/getReportInfo/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getReportInfo(HttpServletResponse response, HttpServletRequest request, HttpSession session) {
        Object bean = request.getAttribute("requestPara");
        RequestParameterEntity reqp = (RequestParameterEntity) bean;
        try {
            //获取报表uuid
            String report_uuid = reqp.getFormData().getValue("report_uuid").toString();
 
            return BaseUtil.success(eChartsReportConfigService.getReportInfo(report_uuid));//BaseUtil.success(fieldName);
        } catch (BaseException e) {
            return error(ReportCode.REPORT_GET_CONFIG_BE_DEFEATED.getText(), e.getMessage());
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/saveTheReportConfiguration/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String saveTheReportConfiguration(HttpServletResponse response, HttpServletRequest request, HttpSession session) {
        Object bean = request.getAttribute("requestPara");
        RequestParameterEntity reqp = (RequestParameterEntity) bean;
        JSONObject reportInfo = JSONObject.parseObject(reqp.getFormJson().toString(), Feature.OrderedField);
        System.out.println(reportInfo);
        try {
            EChartsReportConfigService service = (EChartsReportConfigService) getProxyInstance(eChartsReportConfigService);
            service.addTableInfo(reportInfo);
            //eChartsReportConfigService.addTableInfo(reportInfo);
            return OK();
        } catch (BaseException e) {
            return error(ReportCode.REPORT_SAVE_BE_DEFEATED.getText(), e.getMessage());
        }
    }
 
    private String error(IEnum code, String msg) {
        if (!"".equals(msg)) {
            return error(code.getValue(), code.getText() + "(" + msg + ")");
        } else {
            return error(code.getValue(), code.getText());
        }
    }
}