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());
|
}
|
}
|
}
|