forked from github/dataease
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
5f95db6a53
@ -13,6 +13,8 @@ public class ChartViewWithBLOBs extends ChartView implements Serializable {
|
||||
|
||||
private String yAxis;
|
||||
|
||||
private String extStack;
|
||||
|
||||
private String customAttr;
|
||||
|
||||
private String customStyle;
|
||||
|
@ -16,6 +16,7 @@
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.dataease.base.domain.ChartViewWithBLOBs">
|
||||
<result column="x_axis" jdbcType="LONGVARCHAR" property="xAxis" />
|
||||
<result column="y_axis" jdbcType="LONGVARCHAR" property="yAxis" />
|
||||
<result column="ext_stack" jdbcType="LONGVARCHAR" property="extStack" />
|
||||
<result column="custom_attr" jdbcType="LONGVARCHAR" property="customAttr" />
|
||||
<result column="custom_style" jdbcType="LONGVARCHAR" property="customStyle" />
|
||||
<result column="custom_filter" jdbcType="LONGVARCHAR" property="customFilter" />
|
||||
@ -84,7 +85,7 @@
|
||||
style_priority
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
x_axis, y_axis, custom_attr, custom_style, custom_filter, snapshot
|
||||
x_axis, y_axis, ext_stack, custom_attr, custom_style, custom_filter, snapshot
|
||||
</sql>
|
||||
<select id="selectByExampleWithBLOBs" parameterType="io.dataease.base.domain.ChartViewExample" resultMap="ResultMapWithBLOBs">
|
||||
select
|
||||
@ -139,14 +140,14 @@
|
||||
table_id, `type`, title,
|
||||
create_by, create_time, update_time,
|
||||
style_priority, x_axis, y_axis,
|
||||
custom_attr, custom_style, custom_filter,
|
||||
snapshot)
|
||||
ext_stack, custom_attr, custom_style,
|
||||
custom_filter, snapshot)
|
||||
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{sceneId,jdbcType=VARCHAR},
|
||||
#{tableId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
|
||||
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
|
||||
#{stylePriority,jdbcType=VARCHAR}, #{xAxis,jdbcType=LONGVARCHAR}, #{yAxis,jdbcType=LONGVARCHAR},
|
||||
#{customAttr,jdbcType=LONGVARCHAR}, #{customStyle,jdbcType=LONGVARCHAR}, #{customFilter,jdbcType=LONGVARCHAR},
|
||||
#{snapshot,jdbcType=LONGVARCHAR})
|
||||
#{extStack,jdbcType=LONGVARCHAR}, #{customAttr,jdbcType=LONGVARCHAR}, #{customStyle,jdbcType=LONGVARCHAR},
|
||||
#{customFilter,jdbcType=LONGVARCHAR}, #{snapshot,jdbcType=LONGVARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.dataease.base.domain.ChartViewWithBLOBs">
|
||||
insert into chart_view
|
||||
@ -187,6 +188,9 @@
|
||||
<if test="yAxis != null">
|
||||
y_axis,
|
||||
</if>
|
||||
<if test="extStack != null">
|
||||
ext_stack,
|
||||
</if>
|
||||
<if test="customAttr != null">
|
||||
custom_attr,
|
||||
</if>
|
||||
@ -237,6 +241,9 @@
|
||||
<if test="yAxis != null">
|
||||
#{yAxis,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="extStack != null">
|
||||
#{extStack,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="customAttr != null">
|
||||
#{customAttr,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
@ -296,6 +303,9 @@
|
||||
<if test="record.yAxis != null">
|
||||
y_axis = #{record.yAxis,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.extStack != null">
|
||||
ext_stack = #{record.extStack,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.customAttr != null">
|
||||
custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
@ -327,6 +337,7 @@
|
||||
style_priority = #{record.stylePriority,jdbcType=VARCHAR},
|
||||
x_axis = #{record.xAxis,jdbcType=LONGVARCHAR},
|
||||
y_axis = #{record.yAxis,jdbcType=LONGVARCHAR},
|
||||
ext_stack = #{record.extStack,jdbcType=LONGVARCHAR},
|
||||
custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR},
|
||||
custom_style = #{record.customStyle,jdbcType=LONGVARCHAR},
|
||||
custom_filter = #{record.customFilter,jdbcType=LONGVARCHAR},
|
||||
@ -387,6 +398,9 @@
|
||||
<if test="yAxis != null">
|
||||
y_axis = #{yAxis,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="extStack != null">
|
||||
ext_stack = #{extStack,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="customAttr != null">
|
||||
custom_attr = #{customAttr,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
@ -415,6 +429,7 @@
|
||||
style_priority = #{stylePriority,jdbcType=VARCHAR},
|
||||
x_axis = #{xAxis,jdbcType=LONGVARCHAR},
|
||||
y_axis = #{yAxis,jdbcType=LONGVARCHAR},
|
||||
ext_stack = #{extStack,jdbcType=LONGVARCHAR},
|
||||
custom_attr = #{customAttr,jdbcType=LONGVARCHAR},
|
||||
custom_style = #{customStyle,jdbcType=LONGVARCHAR},
|
||||
custom_filter = #{customFilter,jdbcType=LONGVARCHAR},
|
||||
|
@ -0,0 +1,75 @@
|
||||
package io.dataease.commons.utils;
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExcelReaderUtil {
|
||||
//excel2003扩展名
|
||||
public static final String EXCEL03_EXTENSION = ".xls";
|
||||
//excel2007扩展名
|
||||
public static final String EXCEL07_EXTENSION = ".xlsx";
|
||||
|
||||
public static void sendRows(String filePath, String sheetName, int sheetIndex, int curRow, List<String> cellList) {
|
||||
StringBuffer oneLineSb = new StringBuffer();
|
||||
oneLineSb.append(filePath);
|
||||
oneLineSb.append("--");
|
||||
oneLineSb.append("sheet" + sheetIndex);
|
||||
oneLineSb.append("::" + sheetName);//加上sheet名
|
||||
oneLineSb.append("--");
|
||||
oneLineSb.append("row" + curRow);
|
||||
oneLineSb.append("::");
|
||||
|
||||
// map.put(cellList.get(9),cellList.get(0)) ;
|
||||
|
||||
for (String cell : cellList) {
|
||||
oneLineSb.append(cell.trim());
|
||||
oneLineSb.append("|");
|
||||
}
|
||||
String oneLine = oneLineSb.toString();
|
||||
if (oneLine.endsWith("|")) {
|
||||
oneLine = oneLine.substring(0, oneLine.lastIndexOf("|"));
|
||||
}// 去除最后一个分隔符
|
||||
|
||||
System.out.println(oneLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取excel文件路径
|
||||
* @param fileName 文件路径
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void readExcel(String fileName, InputStream inputStream) throws Exception {
|
||||
if (fileName.endsWith(EXCEL03_EXTENSION)) { //处理excel2003文件
|
||||
ExcelXlsReader excelXls=new ExcelXlsReader();
|
||||
excelXls.process(inputStream);
|
||||
System.out.println(excelXls.totalSheets.size());
|
||||
System.out.println(excelXls.totalSheets.get(0).getSheetName());
|
||||
for (TableFiled field : excelXls.totalSheets.get(0).getFields()) {
|
||||
System.out.println(new Gson().toJson(field));
|
||||
}
|
||||
System.out.println(excelXls.totalSheets.get(0).getData().get(0));
|
||||
|
||||
} else if (fileName.endsWith(EXCEL07_EXTENSION)) {//处理excel2007文件
|
||||
ExcelXlsxReader excelXlsxReader = new ExcelXlsxReader();
|
||||
excelXlsxReader.process(inputStream);
|
||||
System.out.println(excelXlsxReader.totalSheets.size());
|
||||
System.out.println(excelXlsxReader.totalSheets.get(0).getSheetName());
|
||||
for (TableFiled field : excelXlsxReader.totalSheets.get(0).getFields()) {
|
||||
System.out.println(new Gson().toJson(field));
|
||||
}
|
||||
System.out.println(excelXlsxReader.totalSheets.get(0).getData().get(0));
|
||||
|
||||
} else {
|
||||
throw new Exception("文件格式错误,fileName的扩展名只能是xls或xlsx。");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ExcelReaderUtil.readExcel("111.xls", new FileInputStream("/Users/taojinlong/Desktop/111.xls"));
|
||||
}
|
||||
}
|
@ -0,0 +1,401 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
import io.dataease.dto.dataset.ExcelSheetData;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.poi.hssf.eventusermodel.*;
|
||||
import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
|
||||
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
|
||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||
import org.apache.poi.hssf.record.*;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author y
|
||||
* @create 2018-01-19 14:18
|
||||
* @desc 用于解决.xls2003版本大数据量问题
|
||||
**/
|
||||
public class ExcelXlsReader implements HSSFListener {
|
||||
|
||||
public ExcelReaderUtil excelReaderUtil = new ExcelReaderUtil();
|
||||
|
||||
private int minColums = -1;
|
||||
|
||||
private POIFSFileSystem fs;
|
||||
|
||||
/**
|
||||
* 总行数
|
||||
*/
|
||||
private int totalRows = 0;
|
||||
|
||||
/**
|
||||
* 上一行row的序号
|
||||
*/
|
||||
private int lastRowNumber;
|
||||
|
||||
/**
|
||||
* 上一单元格的序号
|
||||
*/
|
||||
private int lastColumnNumber;
|
||||
|
||||
/**
|
||||
* 是否输出formula,还是它对应的值
|
||||
*/
|
||||
private boolean outputFormulaValues = true;
|
||||
|
||||
/**
|
||||
* 用于转换formulas
|
||||
*/
|
||||
private EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener;
|
||||
|
||||
//excel2003工作簿
|
||||
private HSSFWorkbook stubWorkbook;
|
||||
|
||||
private SSTRecord sstRecord;
|
||||
|
||||
private FormatTrackingHSSFListener formatListener;
|
||||
|
||||
private final HSSFDataFormatter formatter = new HSSFDataFormatter();
|
||||
|
||||
/**
|
||||
* 文件的绝对路径
|
||||
*/
|
||||
private String filePath = "";
|
||||
|
||||
//表索引
|
||||
private int sheetIndex = 0;
|
||||
|
||||
private BoundSheetRecord[] orderedBSRs;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ArrayList boundSheetRecords = new ArrayList();
|
||||
|
||||
private int nextRow;
|
||||
|
||||
private int nextColumn;
|
||||
|
||||
private boolean outputNextStringRecord;
|
||||
|
||||
//当前行
|
||||
private int curRow = 0;
|
||||
|
||||
//存储一行记录所有单元格的容器
|
||||
private List<String> cellList = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* 判断整行是否为空行的标记
|
||||
*/
|
||||
private boolean flag = false;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String sheetName;
|
||||
|
||||
public List<TableFiled> fields = new ArrayList<>();
|
||||
public List<List<String>> data = new ArrayList<>();
|
||||
public List<ExcelSheetData> totalSheets = new ArrayList<>();
|
||||
/**
|
||||
* 是否为日期
|
||||
*/
|
||||
private boolean isDateFormat = false;
|
||||
|
||||
|
||||
public List<TableFiled> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<TableFiled> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<List<String>> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<List<String>> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 遍历excel下所有的sheet
|
||||
*
|
||||
* @param inputStream
|
||||
* @throws Exception
|
||||
*/
|
||||
public int process(InputStream inputStream) throws Exception {
|
||||
this.fs = new POIFSFileSystem(inputStream);
|
||||
MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
|
||||
formatListener = new FormatTrackingHSSFListener(listener);
|
||||
HSSFEventFactory factory = new HSSFEventFactory();
|
||||
HSSFRequest request = new HSSFRequest();
|
||||
if (outputFormulaValues) {
|
||||
request.addListenerForAllRecords(formatListener);
|
||||
} else {
|
||||
workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener(formatListener);
|
||||
request.addListenerForAllRecords(workbookBuildingListener);
|
||||
}
|
||||
factory.processWorkbookEvents(request, fs);
|
||||
|
||||
return totalRows; //返回该excel文件的总行数,不包括首列和空行
|
||||
}
|
||||
|
||||
/**
|
||||
* HSSFListener 监听方法,处理Record
|
||||
* 处理每个单元格
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void processRecord(Record record) {
|
||||
int thisRow = -1;
|
||||
int thisColumn = -1;
|
||||
String thisStr = null;
|
||||
String value = null;
|
||||
switch (record.getSid()) {
|
||||
case BoundSheetRecord.sid:
|
||||
boundSheetRecords.add(record);
|
||||
break;
|
||||
case BOFRecord.sid: //开始处理每个sheet
|
||||
BOFRecord br = (BOFRecord) record;
|
||||
if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
|
||||
//如果有需要,则建立子工作簿
|
||||
if (workbookBuildingListener != null && stubWorkbook == null) {
|
||||
stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
|
||||
}
|
||||
|
||||
if (orderedBSRs == null) {
|
||||
orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
|
||||
}
|
||||
sheetName = orderedBSRs[sheetIndex].getSheetname();
|
||||
sheetIndex++;
|
||||
}
|
||||
break;
|
||||
case MergeCellsRecord.sid:
|
||||
throw new RuntimeException(Translator.get("i18n_excel_have_merge_region"));
|
||||
case SSTRecord.sid:
|
||||
sstRecord = (SSTRecord) record;
|
||||
break;
|
||||
case BlankRecord.sid: //单元格为空白
|
||||
BlankRecord brec = (BlankRecord) record;
|
||||
thisRow = brec.getRow();
|
||||
thisColumn = brec.getColumn();
|
||||
thisStr = "";
|
||||
cellList.add(thisColumn, thisStr);
|
||||
break;
|
||||
case BoolErrRecord.sid: //单元格为布尔类型
|
||||
BoolErrRecord berec = (BoolErrRecord) record;
|
||||
thisRow = berec.getRow();
|
||||
thisColumn = berec.getColumn();
|
||||
thisStr = berec.getBooleanValue() + "";
|
||||
cellList.add(thisColumn, thisStr);
|
||||
|
||||
checkRowIsNull(thisStr); //如果里面某个单元格含有值,则标识该行不为空行
|
||||
break;
|
||||
case FormulaRecord.sid://单元格为公式类型
|
||||
FormulaRecord frec = (FormulaRecord) record;
|
||||
thisRow = frec.getRow();
|
||||
thisColumn = frec.getColumn();
|
||||
thisStr = String.valueOf(frec.getValue());
|
||||
// if (outputFormulaValues) {
|
||||
// if (Double.isNaN(frec.getValue())) {
|
||||
// outputNextStringRecord = true;
|
||||
// nextRow = frec.getRow();
|
||||
// nextColumn = frec.getColumn();
|
||||
// } else {
|
||||
// thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
|
||||
// }
|
||||
// } else {
|
||||
// thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
|
||||
// }
|
||||
String feildType = checkType(thisStr, thisColumn);
|
||||
if(feildType.equalsIgnoreCase("LONG") && thisStr.endsWith(".0")){
|
||||
thisStr = thisStr.substring(0, thisStr.length() -2);
|
||||
}
|
||||
cellList.add(thisColumn, thisStr);
|
||||
checkRowIsNull(thisStr); //如果里面某个单元格含有值,则标识该行不为空行
|
||||
break;
|
||||
case StringRecord.sid: //单元格中公式的字符串
|
||||
if (outputNextStringRecord) {
|
||||
StringRecord srec = (StringRecord) record;
|
||||
thisStr = srec.getString();
|
||||
thisRow = nextRow;
|
||||
thisColumn = nextColumn;
|
||||
outputNextStringRecord = false;
|
||||
}
|
||||
break;
|
||||
case LabelRecord.sid:
|
||||
LabelRecord lrec = (LabelRecord) record;
|
||||
curRow = thisRow = lrec.getRow();
|
||||
thisColumn = lrec.getColumn();
|
||||
value = lrec.getValue().trim();
|
||||
value = value.equals("") ? "" : value;
|
||||
cellList.add(thisColumn, value);
|
||||
checkRowIsNull(value); //如果里面某个单元格含有值,则标识该行不为空行
|
||||
break;
|
||||
case LabelSSTRecord.sid: //单元格为字符串类型
|
||||
LabelSSTRecord lsrec = (LabelSSTRecord) record;
|
||||
curRow = thisRow = lsrec.getRow();
|
||||
thisColumn = lsrec.getColumn();
|
||||
if (sstRecord == null) {
|
||||
cellList.add(thisColumn, "");
|
||||
} else {
|
||||
value = sstRecord.getString(lsrec.getSSTIndex()).toString().trim();
|
||||
value = value.equals("") ? "" : value;
|
||||
cellList.add(thisColumn, value);
|
||||
checkRowIsNull(value); //如果里面某个单元格含有值,则标识该行不为空行
|
||||
}
|
||||
break;
|
||||
case NumberRecord.sid: //单元格为数字类型
|
||||
NumberRecord numrec = (NumberRecord) record;
|
||||
curRow = thisRow = numrec.getRow();
|
||||
thisColumn = numrec.getColumn();
|
||||
//第一种方式
|
||||
//value = formatListener.formatNumberDateCell(numrec).trim();//这个被写死,采用的m/d/yy h:mm格式,不符合要求
|
||||
//第二种方式,参照formatNumberDateCell里面的实现方法编写
|
||||
Double valueDouble = ((NumberRecord) numrec).getValue();
|
||||
String formatString = formatListener.getFormatString(numrec);
|
||||
if (formatString.contains("m/d/yy")) {
|
||||
formatString = "yyyy-MM-dd hh:mm:ss";
|
||||
}
|
||||
int formatIndex = formatListener.getFormatIndex(numrec);
|
||||
|
||||
value = formatter.formatRawCellContents(valueDouble, formatIndex, formatString).trim();
|
||||
value = value.equals("") ? "" : value;
|
||||
//向容器加入列值
|
||||
cellList.add(thisColumn, value);
|
||||
if(formatIndex == 59){
|
||||
totalSheets.get(totalSheets.size() -1).getFields().get(thisColumn).setFieldType("DATETIME");
|
||||
}else {
|
||||
checkType(value, thisColumn);
|
||||
}
|
||||
checkRowIsNull(value); //如果里面某个单元格含有值,则标识该行不为空行
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//遇到新行的操作
|
||||
if (thisRow != -1 && thisRow != lastRowNumber) {
|
||||
lastColumnNumber = -1;
|
||||
}
|
||||
|
||||
//空值的操作
|
||||
if (record instanceof MissingCellDummyRecord) {
|
||||
MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
|
||||
curRow = thisRow = mc.getRow();
|
||||
thisColumn = mc.getColumn();
|
||||
cellList.add(thisColumn, "");
|
||||
}
|
||||
|
||||
//更新行和列的值
|
||||
if (thisRow > -1)
|
||||
lastRowNumber = thisRow;
|
||||
if (thisColumn > -1)
|
||||
lastColumnNumber = thisColumn;
|
||||
|
||||
//行结束时的操作
|
||||
if (record instanceof LastCellOfRowDummyRecord) {
|
||||
if (minColums > 0) {
|
||||
//列值重新置空
|
||||
if (lastColumnNumber == -1) {
|
||||
lastColumnNumber = 0;
|
||||
}
|
||||
}
|
||||
lastColumnNumber = -1;
|
||||
|
||||
if(!totalSheets.stream().map(ExcelSheetData::getSheetName).collect(Collectors.toList()).contains(sheetName)){
|
||||
ExcelSheetData excelSheetData = new ExcelSheetData();
|
||||
excelSheetData.setSheetName(sheetName);
|
||||
excelSheetData.setData(new ArrayList<>());
|
||||
excelSheetData.setFields(new ArrayList<>());
|
||||
totalSheets.add(excelSheetData);
|
||||
}
|
||||
|
||||
if(curRow == 0){
|
||||
for (String s : cellList) {
|
||||
TableFiled tableFiled = new TableFiled();
|
||||
tableFiled.setFieldType("TEXT");
|
||||
tableFiled.setFieldSize(65533);
|
||||
tableFiled.setFieldName(s);
|
||||
tableFiled.setRemarks(s);
|
||||
this.fields.add(tableFiled);
|
||||
totalSheets.get(totalSheets.size() -1).getFields().add(tableFiled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (flag && curRow != 0) { //该行不为空行且该行不是第一行,发送(第一行为列名,不需要)
|
||||
if(!totalSheets.stream().map(ExcelSheetData::getSheetName).collect(Collectors.toList()).contains(sheetName)){
|
||||
ExcelSheetData excelSheetData = new ExcelSheetData();
|
||||
excelSheetData.setData(new ArrayList<>(data));
|
||||
excelSheetData.setSheetName(sheetName);
|
||||
excelSheetData.setFields(new ArrayList<>(fields));
|
||||
List<String> tmp = new ArrayList<>(cellList);
|
||||
excelSheetData.getData().add(tmp);
|
||||
totalRows++;
|
||||
totalSheets.add(excelSheetData);
|
||||
}else {
|
||||
List<String> tmp = new ArrayList<>(cellList);
|
||||
totalSheets.stream().filter(s->s.getSheetName().equalsIgnoreCase(sheetName)).collect(Collectors.toList()).get(0).getData().add(tmp);
|
||||
totalRows++;
|
||||
}
|
||||
}
|
||||
|
||||
//清空容器
|
||||
cellList.clear();
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果里面某个单元格含有值,则标识该行不为空行
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public void checkRowIsNull(String value) {
|
||||
if (value != null && !"".equals(value)) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String checkType(String str, int thisColumn){
|
||||
String type = null;
|
||||
try {
|
||||
double d = Double.valueOf(str);
|
||||
try {
|
||||
Double value = new Double(d);
|
||||
double eps = 1e-10;
|
||||
if (value - Math.floor(value) < eps) {
|
||||
type = "LONG";
|
||||
} else {
|
||||
type = "DOUBLE";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
type = "TEXT";
|
||||
}
|
||||
}catch (Exception e){
|
||||
type = "TEXT";
|
||||
}
|
||||
|
||||
String oldType = totalSheets.get(totalSheets.size() -1).getFields().get(thisColumn).getFieldType();
|
||||
if(type.equalsIgnoreCase("LONG") && oldType.equalsIgnoreCase("TEXT")){
|
||||
totalSheets.get(totalSheets.size() -1).getFields().get(thisColumn).setFieldType(type);
|
||||
}
|
||||
if(type.equalsIgnoreCase("DOUBLE")){
|
||||
totalSheets.get(totalSheets.size() -1).getFields().get(thisColumn).setFieldType(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,470 @@
|
||||
package io.dataease.commons.utils;
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
import io.dataease.dto.dataset.ExcelSheetData;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.message.MsgAop;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||
import org.apache.poi.xssf.model.SharedStringsTable;
|
||||
import org.apache.poi.xssf.model.StylesTable;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author y
|
||||
* @create 2018-01-18 14:28
|
||||
* @desc POI读取excel有两种模式,一种是用户模式,一种是事件驱动模式
|
||||
* 采用SAX事件驱动模式解决XLSX文件,可以有效解决用户模式内存溢出的问题,
|
||||
* 该模式是POI官方推荐的读取大数据的模式,
|
||||
* 在用户模式下,数据量较大,Sheet较多,或者是有很多无用的空行的情况下,容易出现内存溢出
|
||||
* <p>
|
||||
* 用于解决.xlsx2007版本大数据量问题
|
||||
**/
|
||||
public class ExcelXlsxReader extends DefaultHandler {
|
||||
|
||||
/**
|
||||
* 自定义获取表格某些信息
|
||||
*/
|
||||
public Map map = new TreeMap<String,String>();
|
||||
/**
|
||||
* 单元格中的数据可能的数据类型
|
||||
*/
|
||||
enum CellDataType {
|
||||
BOOL, ERROR, FORMULA, INLINESTR, SSTINDEX, NUMBER, DATE, NULL
|
||||
}
|
||||
|
||||
/**
|
||||
* 共享字符串表
|
||||
*/
|
||||
private SharedStringsTable sst;
|
||||
|
||||
/**
|
||||
* 上一次的索引值
|
||||
*/
|
||||
private String lastIndex;
|
||||
|
||||
/**
|
||||
* 总行数
|
||||
*/
|
||||
private int totalRows=0;
|
||||
|
||||
/**
|
||||
* 一行内cell集合
|
||||
*/
|
||||
private List<String> cellList = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* 判断整行是否为空行的标记
|
||||
*/
|
||||
private boolean flag = false;
|
||||
|
||||
/**
|
||||
* 当前行
|
||||
*/
|
||||
private int curRow = 1;
|
||||
|
||||
/**
|
||||
* 当前列
|
||||
*/
|
||||
private int curCol = 0;
|
||||
|
||||
/**
|
||||
* T元素标识
|
||||
*/
|
||||
private boolean isTElement;
|
||||
|
||||
/**
|
||||
* 单元格数据类型,默认为字符串类型
|
||||
*/
|
||||
private CellDataType nextDataType = CellDataType.SSTINDEX;
|
||||
|
||||
private final DataFormatter formatter = new DataFormatter();
|
||||
|
||||
/**
|
||||
* 单元格日期格式的索引
|
||||
*/
|
||||
private short formatIndex;
|
||||
|
||||
/**
|
||||
* 日期格式字符串
|
||||
*/
|
||||
private String formatString;
|
||||
|
||||
//定义前一个元素和当前元素的位置,用来计算其中空的单元格数量,如A6和A8等
|
||||
private String preRef = null, ref = null;
|
||||
|
||||
//定义该文档一行最大的单元格数,用来补全一行最后可能缺失的单元格
|
||||
private String maxRef = null;
|
||||
|
||||
/**
|
||||
* 单元格
|
||||
*/
|
||||
private StylesTable stylesTable;
|
||||
|
||||
public List<TableFiled> fields = new ArrayList<>();
|
||||
public List<List<String>> data = new ArrayList<>();
|
||||
public List<ExcelSheetData> totalSheets = new ArrayList<>();
|
||||
/**
|
||||
* 是否为日期
|
||||
*/
|
||||
private boolean isDateFormat = false;
|
||||
|
||||
|
||||
public List<TableFiled> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<TableFiled> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<List<String>> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<List<String>> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int process(InputStream inputStream) throws Exception {
|
||||
OPCPackage pkg = OPCPackage.open(inputStream);
|
||||
XSSFReader xssfReader = new XSSFReader(pkg);
|
||||
stylesTable = xssfReader.getStylesTable();
|
||||
SharedStringsTable sst = xssfReader.getSharedStringsTable();
|
||||
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
|
||||
this.sst = sst;
|
||||
parser.setContentHandler(this);
|
||||
XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
|
||||
while (sheets.hasNext()) { //遍历sheet
|
||||
curRow = 1; //标记初始行为第一行
|
||||
fields.clear();
|
||||
data.clear();
|
||||
InputStream sheet = sheets.next(); //sheets.next()和sheets.getSheetName()不能换位置,否则sheetName报错
|
||||
InputSource sheetSource = new InputSource(sheet);
|
||||
parser.parse(sheetSource); //解析excel的每条记录,在这个过程中startElement()、characters()、endElement()这三个函数会依次执行
|
||||
|
||||
ExcelSheetData excelSheetData = new ExcelSheetData();
|
||||
excelSheetData.setData(new ArrayList<>(data));
|
||||
excelSheetData.setSheetName(sheets.getSheetName());
|
||||
excelSheetData.setFields(new ArrayList<>(fields));
|
||||
totalSheets.add(excelSheetData);
|
||||
|
||||
sheet.close();
|
||||
}
|
||||
return totalRows; //返回该excel文件的总行数,不包括首列和空行
|
||||
}
|
||||
|
||||
/**
|
||||
* 第一个执行
|
||||
*
|
||||
* @param uri
|
||||
* @param localName
|
||||
* @param name
|
||||
* @param attributes
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
|
||||
if(curRow>101){
|
||||
return;
|
||||
}
|
||||
|
||||
if(name.equalsIgnoreCase("mergeCell")){
|
||||
throw new RuntimeException(Translator.get("i18n_excel_have_merge_region"));
|
||||
}
|
||||
//c => 单元格
|
||||
if ("c".equals(name)) {
|
||||
//当前单元格的位置
|
||||
ref = attributes.getValue("r");
|
||||
//设定单元格类型
|
||||
this.setNextDataType(attributes);
|
||||
}
|
||||
|
||||
//当元素为t时
|
||||
if ("t".equals(name)) {
|
||||
isTElement = true;
|
||||
} else {
|
||||
isTElement = false;
|
||||
}
|
||||
|
||||
//置空
|
||||
lastIndex = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 第二个执行
|
||||
* 得到单元格对应的索引值或是内容值
|
||||
* 如果单元格类型是字符串、INLINESTR、数字、日期,lastIndex则是索引值
|
||||
* 如果单元格类型是布尔值、错误、公式,lastIndex则是内容值
|
||||
* @param ch
|
||||
* @param start
|
||||
* @param length
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if(curRow>101){
|
||||
return;
|
||||
}
|
||||
lastIndex += new String(ch, start, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三个执行
|
||||
*
|
||||
* @param uri
|
||||
* @param localName
|
||||
* @param name
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||
if(curRow>101){
|
||||
return;
|
||||
}
|
||||
//t元素也包含字符串
|
||||
if (isTElement) {//这个程序没经过
|
||||
//将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符
|
||||
String value = lastIndex.trim();
|
||||
cellList.add(curCol, value);
|
||||
curCol++;
|
||||
isTElement = false;
|
||||
//如果里面某个单元格含有值,则标识该行不为空行
|
||||
if (value != null && !"".equals(value)) {
|
||||
flag = true;
|
||||
}
|
||||
} else if ("v".equals(name)) {
|
||||
//v => 单元格的值,如果单元格是字符串,则v标签的值为该字符串在SST中的索引
|
||||
String value = this.getDataValue(lastIndex.trim(), "");//根据索引值获取对应的单元格值
|
||||
if (preRef == null) {
|
||||
preRef = ref;
|
||||
}
|
||||
//补全单元格之间的空单元格
|
||||
if (!ref.equals(preRef)) {
|
||||
int len = countNullCell(ref, preRef);
|
||||
for (int i = 0; i < len; i++) {
|
||||
cellList.add(curCol, "");
|
||||
curCol++;
|
||||
}
|
||||
}
|
||||
cellList.add(curCol, value);
|
||||
curCol++;
|
||||
//如果里面某个单元格含有值,则标识该行不为空行
|
||||
if (value != null && !"".equals(value)) {
|
||||
flag = true;
|
||||
}
|
||||
preRef = ref;
|
||||
} else {
|
||||
//如果标签名称为row,这说明已到行尾
|
||||
if ("row".equals(name)) {
|
||||
//默认第一行为表头,以该行单元格数目为最大数目
|
||||
if (curRow == 1) {
|
||||
maxRef = ref;
|
||||
}
|
||||
//补全一行尾部可能缺失的单元格
|
||||
if (maxRef != null) {
|
||||
int len = countNullCell(maxRef, ref);
|
||||
for (int i = 0; i <= len; i++) {
|
||||
cellList.add(curCol, "");
|
||||
curCol++;
|
||||
}
|
||||
}
|
||||
if(curRow>1){
|
||||
List<String> tmp = new ArrayList<>(cellList);
|
||||
this.getData().add(tmp);
|
||||
}
|
||||
totalRows++;
|
||||
cellList.clear();
|
||||
curRow++;
|
||||
curCol = 0;
|
||||
preRef = null;
|
||||
ref = null;
|
||||
flag=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据类型
|
||||
*
|
||||
* @param attributes
|
||||
*/
|
||||
public void setNextDataType(Attributes attributes) {
|
||||
nextDataType = CellDataType.NUMBER; //cellType为空,则表示该单元格类型为数字
|
||||
formatIndex = -1;
|
||||
formatString = null;
|
||||
String cellType = attributes.getValue("t"); //单元格类型
|
||||
if ("b".equals(cellType)) { //处理布尔值
|
||||
nextDataType = CellDataType.BOOL;
|
||||
} else if ("e".equals(cellType)) { //处理错误
|
||||
nextDataType = CellDataType.ERROR;
|
||||
} else if ("inlineStr".equals(cellType)) {
|
||||
nextDataType = CellDataType.INLINESTR;
|
||||
} else if ("s".equals(cellType)) { //处理字符串
|
||||
nextDataType = CellDataType.SSTINDEX;
|
||||
} else if ("str".equals(cellType)) {
|
||||
nextDataType = CellDataType.FORMULA;
|
||||
}
|
||||
|
||||
String cellStyleStr = attributes.getValue("s"); //
|
||||
if (cellStyleStr != null) {
|
||||
int styleIndex = Integer.parseInt(cellStyleStr);
|
||||
XSSFCellStyle style = this.stylesTable.getStyleAt(styleIndex);
|
||||
formatIndex = style.getDataFormat();
|
||||
formatString = style.getDataFormatString();
|
||||
short format = this.formatIndex;
|
||||
if (format == 14 || format == 31 || format == 57 ||format == 59||
|
||||
format == 58 || (176 <= format && format <= 178)
|
||||
|| (182 <= format && format <= 196) ||
|
||||
(210 <= format && format <= 213) || (208 == format))
|
||||
{ // 日期
|
||||
isDateFormat = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 对解析出来的数据进行类型处理
|
||||
* @param value 单元格的值,
|
||||
* value代表解析:BOOL的为0或1, ERROR的为内容值,FORMULA的为内容值,INLINESTR的为索引值需转换为内容值,
|
||||
* SSTINDEX的为索引值需转换为内容值, NUMBER为内容值,DATE为内容值
|
||||
* @param thisStr 一个空字符串
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getDataValue(String value, String thisStr) {
|
||||
String type = "TEXT";
|
||||
switch (nextDataType) {
|
||||
// 这几个的顺序不能随便交换,交换了很可能会导致数据错误
|
||||
case BOOL: //布尔值
|
||||
char first = value.charAt(0);
|
||||
thisStr = first == '0' ? "FALSE" : "TRUE";
|
||||
type = "LONG";
|
||||
break;
|
||||
case ERROR: //错误
|
||||
thisStr = "\"ERROR:" + value.toString() + '"';
|
||||
break;
|
||||
case FORMULA: //公式
|
||||
thisStr = '"' + value.toString() + '"';
|
||||
type = getType(thisStr);
|
||||
break;
|
||||
case INLINESTR:
|
||||
XSSFRichTextString rtsi = new XSSFRichTextString(value.toString());
|
||||
thisStr = rtsi.toString();
|
||||
rtsi = null;
|
||||
break;
|
||||
case SSTINDEX: //字符串
|
||||
String sstIndex = value.toString();
|
||||
try {
|
||||
int idx = Integer.parseInt(sstIndex);
|
||||
XSSFRichTextString rtss = new XSSFRichTextString(sst.getEntryAt(idx));//根据idx索引值获取内容值
|
||||
thisStr = rtss.toString();
|
||||
rtss = null;
|
||||
} catch (NumberFormatException ex) {
|
||||
thisStr = value.toString();
|
||||
}
|
||||
|
||||
break;
|
||||
case NUMBER: //数字
|
||||
if (formatString != null) {
|
||||
thisStr = formatter.formatRawCellContents(Double.parseDouble(value), formatIndex, formatString).trim();
|
||||
} else {
|
||||
thisStr = value;
|
||||
}
|
||||
thisStr = thisStr.replace("_", "").trim();
|
||||
if(isDateFormat){
|
||||
type = "DATETIME";isDateFormat = false;
|
||||
}else {
|
||||
type = getType(thisStr);
|
||||
}
|
||||
break;
|
||||
case DATE: //日期
|
||||
thisStr = formatter.formatRawCellContents(Double.parseDouble(value), formatIndex, formatString);
|
||||
// 对日期字符串作特殊处理,去掉T
|
||||
thisStr = thisStr.replace("T", " ");
|
||||
type = "DATETIME";
|
||||
break;
|
||||
default:
|
||||
thisStr = " ";
|
||||
break;
|
||||
}
|
||||
if(curRow==1){
|
||||
TableFiled tableFiled = new TableFiled();
|
||||
tableFiled.setFieldType(type);
|
||||
tableFiled.setFieldSize(65533);
|
||||
tableFiled.setFieldName(thisStr);
|
||||
tableFiled.setRemarks(thisStr);
|
||||
this.fields.add(tableFiled);
|
||||
}else {
|
||||
this.getFields().get(curCol).setFieldType(type);
|
||||
}
|
||||
return thisStr;
|
||||
}
|
||||
|
||||
private String getType(String thisStr){
|
||||
if(totalRows==0){
|
||||
return "TEXT";
|
||||
}
|
||||
try{
|
||||
if(thisStr.endsWith("%")){
|
||||
thisStr = thisStr.substring(0, thisStr.length()-1);
|
||||
thisStr = String.valueOf(Double.valueOf(thisStr)/100);
|
||||
}
|
||||
Long.valueOf(thisStr);
|
||||
if(this.getFields().get(curCol).getFieldType().equalsIgnoreCase("TEXT")){
|
||||
return "LONG";
|
||||
}
|
||||
}catch (Exception e){
|
||||
try {
|
||||
Double.valueOf(thisStr);
|
||||
return "DOUBLE";
|
||||
}catch (Exception ignore){ }
|
||||
}
|
||||
return "TEXT";
|
||||
}
|
||||
|
||||
public int countNullCell(String ref, String preRef) {
|
||||
//excel2007最大行数是1048576,最大列数是16384,最后一列列名是XFD
|
||||
String xfd = ref.replaceAll("\\d+", "");
|
||||
String xfd_1 = preRef.replaceAll("\\d+", "");
|
||||
|
||||
xfd = fillChar(xfd, 3, '@', true);
|
||||
xfd_1 = fillChar(xfd_1, 3, '@', true);
|
||||
|
||||
char[] letter = xfd.toCharArray();
|
||||
char[] letter_1 = xfd_1.toCharArray();
|
||||
int res = (letter[0] - letter_1[0]) * 26 * 26 + (letter[1] - letter_1[1]) * 26 + (letter[2] - letter_1[2]);
|
||||
return res - 1;
|
||||
}
|
||||
|
||||
public String fillChar(String str, int len, char let, boolean isPre) {
|
||||
int len_1 = str.length();
|
||||
if (len_1 < len) {
|
||||
if (isPre) {
|
||||
for (int i = 0; i < (len - len_1); i++) {
|
||||
str = let + str;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < (len - len_1); i++) {
|
||||
str = str + let;
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
@ -185,6 +185,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
field.setFieldType(t);
|
||||
field.setFieldSize(metaData.getColumnDisplaySize(j + 1));
|
||||
if(t.equalsIgnoreCase("LONG")){field.setFieldSize(65533);} //oracle LONG
|
||||
if(StringUtils.isNotEmpty(t) && t.toLowerCase().contains("date") && field.getFieldSize() < 50 ){
|
||||
field.setFieldSize(50);
|
||||
}
|
||||
fieldList.add(field);
|
||||
}
|
||||
return fieldList;
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.dataease.dto.dataset;
|
||||
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ExcelSheetData {
|
||||
private String sheetName;
|
||||
private List<List<String>> data;
|
||||
private List<TableFiled> fields;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package io.dataease.map.dto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@ -10,6 +11,7 @@ import java.util.Optional;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AreaEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1326667005437020282L;
|
||||
|
@ -5,6 +5,7 @@ import io.dataease.map.api.MapApi;
|
||||
import io.dataease.map.dto.entity.AreaEntity;
|
||||
import io.dataease.map.service.MapService;
|
||||
import io.dataease.map.utils.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Resource;
|
||||
@ -40,7 +41,9 @@ public class MapServer implements MapApi {
|
||||
@Override
|
||||
public List<AreaEntity> areaEntitys(@PathVariable String pcode) {
|
||||
List<AreaEntity> areaEntities = mapService.areaEntities();
|
||||
|
||||
if (StringUtils.equals(pcode, "0")) {
|
||||
return areaEntities;
|
||||
}
|
||||
return mapService.entitysByPid(areaEntities, pcode);
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,23 @@ public abstract class QueryProvider {
|
||||
|
||||
public abstract String getSQLAsTmp(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList);
|
||||
|
||||
public abstract String getSQLStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack);
|
||||
|
||||
public abstract String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack);
|
||||
|
||||
public abstract String searchTable(String table);
|
||||
|
||||
public abstract String getSQLSummary(String table, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList);
|
||||
|
||||
/**
|
||||
* 单指标汇总
|
||||
*
|
||||
* @param sql
|
||||
* @param yAxis
|
||||
* @param customFilter
|
||||
* @param extFilterRequestList
|
||||
* @return
|
||||
*/
|
||||
public abstract String getSQLSummaryAsTmp(String sql, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList);
|
||||
|
||||
public abstract String wrapSql(String sql);
|
||||
|
@ -263,6 +263,104 @@ public class DorisQueryProvider extends QueryProvider {
|
||||
return getSQL("(" + sql + ")", xAxis, yAxis, customFilter, extFilterRequestList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(DorisConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
|
||||
.build();
|
||||
List<SQLObj> xFields = new ArrayList<>();
|
||||
List<SQLObj> xWheres = new ArrayList<>();
|
||||
List<SQLObj> xOrders = new ArrayList<>();
|
||||
List<ChartViewFieldDTO> xList = new ArrayList<>();
|
||||
xList.addAll(xAxis);
|
||||
xList.addAll(extStack);
|
||||
if (CollectionUtils.isNotEmpty(xList)) {
|
||||
for (int i = 0; i < xList.size(); i++) {
|
||||
ChartViewFieldDTO x = xList.get(i);
|
||||
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getDataeaseName());
|
||||
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
|
||||
// 处理横轴字段
|
||||
xFields.add(getXFields(x, originField, fieldAlias));
|
||||
// 处理横轴过滤
|
||||
xWheres.addAll(getXWheres(x, originField, fieldAlias));
|
||||
// 处理横轴排序
|
||||
if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
|
||||
xOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(x.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<SQLObj> yFields = new ArrayList<>();
|
||||
List<SQLObj> yWheres = new ArrayList<>();
|
||||
List<SQLObj> yOrders = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(yAxis)) {
|
||||
for (int i = 0; i < yAxis.size(); i++) {
|
||||
ChartViewFieldDTO y = yAxis.get(i);
|
||||
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getDataeaseName());
|
||||
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
|
||||
// 处理纵轴字段
|
||||
yFields.add(getYFields(y, originField, fieldAlias));
|
||||
// 处理纵轴过滤
|
||||
yWheres.addAll(getYWheres(y, originField, fieldAlias));
|
||||
// 处理纵轴排序
|
||||
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
|
||||
yOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(y.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理视图中字段过滤
|
||||
List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
|
||||
// 处理仪表板字段过滤
|
||||
List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
|
||||
// 构建sql所有参数
|
||||
List<SQLObj> fields = new ArrayList<>();
|
||||
fields.addAll(xFields);
|
||||
fields.addAll(yFields);
|
||||
List<SQLObj> wheres = new ArrayList<>();
|
||||
wheres.addAll(xWheres);
|
||||
if (customWheres != null) wheres.addAll(customWheres);
|
||||
if (extWheres != null) wheres.addAll(extWheres);
|
||||
List<SQLObj> groups = new ArrayList<>();
|
||||
groups.addAll(xFields);
|
||||
// 外层再次套sql
|
||||
List<SQLObj> orders = new ArrayList<>();
|
||||
orders.addAll(xOrders);
|
||||
orders.addAll(yOrders);
|
||||
List<SQLObj> aggWheres = new ArrayList<>();
|
||||
aggWheres.addAll(yWheres);
|
||||
|
||||
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
|
||||
ST st_sql = stg.getInstanceOf("querySql");
|
||||
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
|
||||
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
String sql = st_sql.render();
|
||||
|
||||
ST st = stg.getInstanceOf("querySql");
|
||||
SQLObj tableSQL = SQLObj.builder()
|
||||
.tableName(String.format(DorisConstants.BRACKETS, sql))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
|
||||
.build();
|
||||
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
|
||||
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
|
||||
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
|
||||
return st.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
return getSQLStack("(" + table + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchTable(String table) {
|
||||
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
|
||||
|
@ -254,6 +254,123 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
return getSQL("(" + sqlFix(sql) + ")", xAxis, yAxis, customFilter, extFilterRequestList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(MySQLConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
|
||||
.build();
|
||||
List<SQLObj> xFields = new ArrayList<>();
|
||||
List<SQLObj> xWheres = new ArrayList<>();
|
||||
List<SQLObj> xOrders = new ArrayList<>();
|
||||
List<ChartViewFieldDTO> xList = new ArrayList<>();
|
||||
xList.addAll(xAxis);
|
||||
xList.addAll(extStack);
|
||||
if (CollectionUtils.isNotEmpty(xList)) {
|
||||
for (int i = 0; i < xList.size(); i++) {
|
||||
ChartViewFieldDTO x = xList.get(i);
|
||||
String originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
|
||||
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
|
||||
// 处理横轴字段
|
||||
xFields.add(getXFields(x, originField, fieldAlias));
|
||||
// 处理横轴过滤
|
||||
xWheres.addAll(getXWheres(x, originField, fieldAlias));
|
||||
// 处理横轴排序
|
||||
if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
|
||||
xOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(x.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<SQLObj> yFields = new ArrayList<>();
|
||||
List<SQLObj> yWheres = new ArrayList<>();
|
||||
List<SQLObj> yOrders = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(yAxis)) {
|
||||
for (int i = 0; i < yAxis.size(); i++) {
|
||||
ChartViewFieldDTO y = yAxis.get(i);
|
||||
String originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
|
||||
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
|
||||
// 处理纵轴字段
|
||||
yFields.add(getYFields(y, originField, fieldAlias));
|
||||
// 处理纵轴过滤
|
||||
yWheres.addAll(getYWheres(y, originField, fieldAlias));
|
||||
// 处理纵轴排序
|
||||
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
|
||||
yOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(y.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<SQLObj> stackFields = new ArrayList<>();
|
||||
List<SQLObj> stackOrders = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(extStack)) {
|
||||
for (int i = 0; i < extStack.size(); i++) {
|
||||
ChartViewFieldDTO stack = extStack.get(i);
|
||||
String originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), stack.getOriginName());
|
||||
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
|
||||
// 处理横轴字段
|
||||
stackFields.add(getXFields(stack, originField, fieldAlias));
|
||||
// 处理横轴排序
|
||||
if (StringUtils.isNotEmpty(stack.getSort()) && !StringUtils.equalsIgnoreCase(stack.getSort(), "none")) {
|
||||
stackOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(stack.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理视图中字段过滤
|
||||
List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
|
||||
// 处理仪表板字段过滤
|
||||
List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
|
||||
// 构建sql所有参数
|
||||
List<SQLObj> fields = new ArrayList<>();
|
||||
fields.addAll(xFields);
|
||||
fields.addAll(yFields);
|
||||
List<SQLObj> wheres = new ArrayList<>();
|
||||
wheres.addAll(xWheres);
|
||||
if (customWheres != null) wheres.addAll(customWheres);
|
||||
if (extWheres != null) wheres.addAll(extWheres);
|
||||
List<SQLObj> groups = new ArrayList<>();
|
||||
groups.addAll(xFields);
|
||||
// 外层再次套sql
|
||||
List<SQLObj> orders = new ArrayList<>();
|
||||
orders.addAll(xOrders);
|
||||
orders.addAll(yOrders);
|
||||
List<SQLObj> aggWheres = new ArrayList<>();
|
||||
aggWheres.addAll(yWheres);
|
||||
|
||||
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
|
||||
ST st_sql = stg.getInstanceOf("querySql");
|
||||
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
|
||||
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
String sql = st_sql.render();
|
||||
|
||||
ST st = stg.getInstanceOf("querySql");
|
||||
SQLObj tableSQL = SQLObj.builder()
|
||||
.tableName(String.format(MySQLConstants.BRACKETS, sql))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
|
||||
.build();
|
||||
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
|
||||
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
|
||||
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
|
||||
return st.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchTable(String table) {
|
||||
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
|
||||
|
@ -107,8 +107,7 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<SQLObj> xFields(String table, List<DatasetTableField> fields){
|
||||
private List<SQLObj> xFields(String table, List<DatasetTableField> fields) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
|
||||
@ -155,6 +154,7 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
}
|
||||
return xFields;
|
||||
}
|
||||
|
||||
private String sqlColumn(List<SQLObj> xFields) {
|
||||
String[] array = xFields.stream().map(f -> {
|
||||
return f.getFieldAlias();
|
||||
@ -287,6 +287,104 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
return getSQL("(" + sqlFix(sql) + ")", xAxis, yAxis, customFilter, extFilterRequestList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
|
||||
.build();
|
||||
List<SQLObj> xFields = new ArrayList<>();
|
||||
List<SQLObj> xWheres = new ArrayList<>();
|
||||
List<SQLObj> xOrders = new ArrayList<>();
|
||||
List<ChartViewFieldDTO> xList = new ArrayList<>();
|
||||
xList.addAll(xAxis);
|
||||
xList.addAll(extStack);
|
||||
if (CollectionUtils.isNotEmpty(xList)) {
|
||||
for (int i = 0; i < xList.size(); i++) {
|
||||
ChartViewFieldDTO x = xList.get(i);
|
||||
String originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
|
||||
String fieldAlias = String.format(OracleConstants.ALIAS_FIX, String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i));
|
||||
// 处理横轴字段
|
||||
xFields.add(getXFields(x, originField, fieldAlias));
|
||||
// 处理横轴过滤
|
||||
xWheres.addAll(getXWheres(x, originField, fieldAlias));
|
||||
// 处理横轴排序
|
||||
if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
|
||||
xOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(x.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<SQLObj> yFields = new ArrayList<>();
|
||||
List<SQLObj> yWheres = new ArrayList<>();
|
||||
List<SQLObj> yOrders = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(yAxis)) {
|
||||
for (int i = 0; i < yAxis.size(); i++) {
|
||||
ChartViewFieldDTO y = yAxis.get(i);
|
||||
String originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
|
||||
String fieldAlias = String.format(OracleConstants.ALIAS_FIX, String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i));
|
||||
// 处理纵轴字段
|
||||
yFields.add(getYFields(y, originField, fieldAlias));
|
||||
// 处理纵轴过滤
|
||||
yWheres.addAll(getYWheres(y, originField, fieldAlias));
|
||||
// 处理纵轴排序
|
||||
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
|
||||
yOrders.add(SQLObj.builder()
|
||||
.orderField(originField)
|
||||
.orderAlias(fieldAlias)
|
||||
.orderDirection(y.getSort())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理视图中字段过滤
|
||||
List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
|
||||
// 处理仪表板字段过滤
|
||||
List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
|
||||
// 构建sql所有参数
|
||||
List<SQLObj> fields = new ArrayList<>();
|
||||
fields.addAll(xFields);
|
||||
fields.addAll(yFields);
|
||||
List<SQLObj> wheres = new ArrayList<>();
|
||||
wheres.addAll(xWheres);
|
||||
if (customWheres != null) wheres.addAll(customWheres);
|
||||
if (extWheres != null) wheres.addAll(extWheres);
|
||||
List<SQLObj> groups = new ArrayList<>();
|
||||
groups.addAll(xFields);
|
||||
// 外层再次套sql
|
||||
List<SQLObj> orders = new ArrayList<>();
|
||||
orders.addAll(xOrders);
|
||||
orders.addAll(yOrders);
|
||||
List<SQLObj> aggWheres = new ArrayList<>();
|
||||
aggWheres.addAll(yWheres);
|
||||
|
||||
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
|
||||
ST st_sql = stg.getInstanceOf("querySql");
|
||||
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
|
||||
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
String sql = st_sql.render();
|
||||
|
||||
ST st = stg.getInstanceOf("querySql");
|
||||
SQLObj tableSQL = SQLObj.builder()
|
||||
.tableName(String.format(OracleConstants.BRACKETS, sql))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
|
||||
.build();
|
||||
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
|
||||
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
|
||||
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
|
||||
return st.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchTable(String table) {
|
||||
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
|
||||
|
@ -271,6 +271,16 @@ public class SqlserverQueryProvider extends QueryProvider {
|
||||
return getSQL(" (" + sqlFix(sql) + ") AS tmp ", xAxis, yAxis, customFilter, extFilterRequestList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchTable(String table) {
|
||||
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
|
||||
|
@ -134,6 +134,8 @@ public class ChartViewService {
|
||||
}.getType());
|
||||
List<ChartViewFieldDTO> yAxis = new Gson().fromJson(view.getYAxis(), new TypeToken<List<ChartViewFieldDTO>>() {
|
||||
}.getType());
|
||||
List<ChartViewFieldDTO> extStack = new Gson().fromJson(view.getExtStack(), new TypeToken<List<ChartViewFieldDTO>>() {
|
||||
}.getType());
|
||||
List<ChartFieldCustomFilterDTO> fieldCustomFilter = new Gson().fromJson(view.getCustomFilter(), new TypeToken<List<ChartFieldCustomFilterDTO>>() {
|
||||
}.getType());
|
||||
List<ChartCustomFilterDTO> customFilter = fieldCustomFilter.stream().map(ele -> {
|
||||
@ -145,24 +147,19 @@ public class ChartViewService {
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
// xAxis = new ArrayList<>();
|
||||
// if (CollectionUtils.isEmpty(yAxis)) {
|
||||
// ChartViewDTO dto = new ChartViewDTO();
|
||||
// BeanUtils.copyBean(dto, view);
|
||||
// return dto;
|
||||
// }
|
||||
// } else {
|
||||
// if (CollectionUtils.isEmpty(xAxis) || CollectionUtils.isEmpty(yAxis)) {
|
||||
// ChartViewDTO dto = new ChartViewDTO();
|
||||
// BeanUtils.copyBean(dto, view);
|
||||
// return dto;
|
||||
// }
|
||||
// }
|
||||
if (CollectionUtils.isEmpty(xAxis) && CollectionUtils.isEmpty(yAxis)) {
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
return dto;
|
||||
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
xAxis = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(yAxis)) {
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
return dto;
|
||||
}
|
||||
} else {
|
||||
if (CollectionUtils.isEmpty(xAxis) && CollectionUtils.isEmpty(yAxis)) {
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤来自仪表板的条件
|
||||
@ -204,12 +201,16 @@ public class ChartViewService {
|
||||
datasourceRequest.setTable(dataTableInfoDTO.getTable());
|
||||
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
datasourceRequest.setQuery(qp.getSQLSummary(dataTableInfoDTO.getTable(), yAxis, customFilter, extFilterList));
|
||||
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
datasourceRequest.setQuery(qp.getSQLStack(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList, extStack));
|
||||
} else {
|
||||
datasourceRequest.setQuery(qp.getSQL(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList));
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(table.getType(), "sql")) {
|
||||
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(dataTableInfoDTO.getSql(), yAxis, customFilter, extFilterList));
|
||||
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
datasourceRequest.setQuery(qp.getSQLAsTmpStack(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList, extStack));
|
||||
} else {
|
||||
datasourceRequest.setQuery(qp.getSQLAsTmp(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList));
|
||||
}
|
||||
@ -219,6 +220,8 @@ public class ChartViewService {
|
||||
String sql = dataSetTableService.getCustomSQLDatasource(dt, list, ds);
|
||||
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, customFilter, extFilterList));
|
||||
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
datasourceRequest.setQuery(qp.getSQLAsTmpStack(sql, xAxis, yAxis, customFilter, extFilterList, extStack));
|
||||
} else {
|
||||
datasourceRequest.setQuery(qp.getSQLAsTmp(sql, xAxis, yAxis, customFilter, extFilterList));
|
||||
}
|
||||
@ -245,6 +248,8 @@ public class ChartViewService {
|
||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
datasourceRequest.setQuery(qp.getSQLSummary(tableName, yAxis, customFilter, extFilterList));
|
||||
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
datasourceRequest.setQuery(qp.getSQLStack(tableName, xAxis, yAxis, customFilter, extFilterList, extStack));
|
||||
} else {
|
||||
datasourceRequest.setQuery(qp.getSQL(tableName, xAxis, yAxis, customFilter, extFilterList));
|
||||
}
|
||||
@ -279,67 +284,24 @@ public class ChartViewService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "pie") && data.size() > 1000) {
|
||||
data = data.subList(0, 1000);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new TreeMap<>();
|
||||
// 图表组件可再扩展
|
||||
List<String> x = new ArrayList<>();
|
||||
List<Series> series = new ArrayList<>();
|
||||
for (ChartViewFieldDTO y : yAxis) {
|
||||
Series series1 = new Series();
|
||||
series1.setName(y.getName());
|
||||
series1.setType(view.getType());
|
||||
series1.setData(new ArrayList<>());
|
||||
series.add(series1);
|
||||
Map<String, Object> mapChart;
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
mapChart = transStackChartData(xAxis, yAxis, view, data, extStack);
|
||||
} else {
|
||||
mapChart = transChartData(xAxis, yAxis, view, data);
|
||||
}
|
||||
for (String[] d : data) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (int i = 0; i < xAxis.size(); i++) {
|
||||
if (i == xAxis.size() - 1) {
|
||||
a.append(d[i]);
|
||||
} else {
|
||||
a.append(d[i]).append("\n");
|
||||
}
|
||||
}
|
||||
x.add(a.toString());
|
||||
for (int i = xAxis.size(); i < xAxis.size() + yAxis.size(); i++) {
|
||||
int j = i - xAxis.size();
|
||||
try {
|
||||
series.get(j).getData().add(new BigDecimal(StringUtils.isEmpty(d[i]) ? "0" : d[i]));
|
||||
} catch (Exception e) {
|
||||
series.get(j).getData().add(new BigDecimal(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
// table组件
|
||||
List<ChartViewFieldDTO> fields = new ArrayList<>();
|
||||
List<Map<String, Object>> tableRow = new ArrayList<>();
|
||||
if (ObjectUtils.isNotEmpty(xAxis) && !StringUtils.equalsIgnoreCase("text", view.getType()) && !StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||
fields.addAll(xAxis);
|
||||
}
|
||||
fields.addAll(yAxis);
|
||||
data.forEach(ele -> {
|
||||
Map<String, Object> d = new HashMap<>();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
ChartViewFieldDTO chartViewFieldDTO = fields.get(i);
|
||||
if (chartViewFieldDTO.getDeType() == 0 || chartViewFieldDTO.getDeType() == 1) {
|
||||
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? "" : ele[i]);
|
||||
} else if (chartViewFieldDTO.getDeType() == 2 || chartViewFieldDTO.getDeType() == 3) {
|
||||
d.put(fields.get(i).getDataeaseName(), new BigDecimal(StringUtils.isEmpty(ele[i]) ? "0" : ele[i]).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
}
|
||||
tableRow.add(d);
|
||||
});
|
||||
// table组件,明细表,也用于导出数据
|
||||
Map<String, Object> mapTableNormal = transTableNormal(xAxis, yAxis, view, data, extStack);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("x", x);
|
||||
map.put("series", series);
|
||||
map.put("fields", fields);
|
||||
map.put("tableRow", tableRow);
|
||||
map.putAll(mapChart);
|
||||
map.putAll(mapTableNormal);
|
||||
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
@ -384,6 +346,166 @@ public class ChartViewService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> transChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
List<String> x = new ArrayList<>();
|
||||
List<Series> series = new ArrayList<>();
|
||||
for (ChartViewFieldDTO y : yAxis) {
|
||||
Series series1 = new Series();
|
||||
series1.setName(y.getName());
|
||||
series1.setType(view.getType());
|
||||
series1.setData(new ArrayList<>());
|
||||
series.add(series1);
|
||||
}
|
||||
for (String[] d : data) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (int i = 0; i < xAxis.size(); i++) {
|
||||
if (i == xAxis.size() - 1) {
|
||||
a.append(d[i]);
|
||||
} else {
|
||||
a.append(d[i]).append("\n");
|
||||
}
|
||||
}
|
||||
x.add(a.toString());
|
||||
for (int i = xAxis.size(); i < xAxis.size() + yAxis.size(); i++) {
|
||||
int j = i - xAxis.size();
|
||||
try {
|
||||
series.get(j).getData().add(new BigDecimal(StringUtils.isEmpty(d[i]) ? "0" : d[i]));
|
||||
} catch (Exception e) {
|
||||
series.get(j).getData().add(new BigDecimal(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.put("x", x);
|
||||
map.put("series", series);
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> transStackChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
List<String> x = new ArrayList<>();
|
||||
List<String> stack = new ArrayList<>();
|
||||
List<Series> series = new ArrayList<>();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(extStack)) {
|
||||
BigDecimal defaultValue = StringUtils.containsIgnoreCase(view.getType(), "line") ? new BigDecimal(0) : null;
|
||||
// 构建横轴
|
||||
for (String[] d : data) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (int i = 0; i < xAxis.size(); i++) {
|
||||
if (i == xAxis.size() - 1) {
|
||||
a.append(d[i]);
|
||||
} else {
|
||||
a.append(d[i]).append("\n");
|
||||
}
|
||||
}
|
||||
x.add(a.toString());
|
||||
}
|
||||
x = x.stream().distinct().collect(Collectors.toList());
|
||||
// 构建堆叠
|
||||
for (String[] d : data) {
|
||||
stack.add(d[xAxis.size()]);
|
||||
}
|
||||
stack = stack.stream().distinct().collect(Collectors.toList());
|
||||
for (String s : stack) {
|
||||
Series series1 = new Series();
|
||||
series1.setName(s);
|
||||
series1.setType(view.getType());
|
||||
List<BigDecimal> list = new ArrayList<>();
|
||||
for (int i = 0; i < x.size(); i++) {
|
||||
list.add(defaultValue);
|
||||
}
|
||||
series1.setData(list);
|
||||
series.add(series1);
|
||||
}
|
||||
for (Series ss : series) {
|
||||
for (int i = 0; i < x.size(); i++) {
|
||||
for (String[] row : data) {
|
||||
String stackColumn = row[xAxis.size()];
|
||||
if (StringUtils.equals(ss.getName(), stackColumn)) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (int j = 0; j < xAxis.size(); j++) {
|
||||
if (j == xAxis.size() - 1) {
|
||||
a.append(row[j]);
|
||||
} else {
|
||||
a.append(row[j]).append("\n");
|
||||
}
|
||||
}
|
||||
if (StringUtils.equals(a.toString(), x.get(i))) {
|
||||
ss.getData().set(i, new BigDecimal(row[xAxis.size() + extStack.size()]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (ChartViewFieldDTO y : yAxis) {
|
||||
Series series1 = new Series();
|
||||
series1.setName(y.getName());
|
||||
series1.setType(view.getType());
|
||||
series1.setData(new ArrayList<>());
|
||||
series.add(series1);
|
||||
}
|
||||
for (String[] d : data) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
for (int i = 0; i < xAxis.size(); i++) {
|
||||
if (i == xAxis.size() - 1) {
|
||||
a.append(d[i]);
|
||||
} else {
|
||||
a.append(d[i]).append("\n");
|
||||
}
|
||||
}
|
||||
x.add(a.toString());
|
||||
for (int i = xAxis.size(); i < xAxis.size() + yAxis.size(); i++) {
|
||||
int j = i - xAxis.size();
|
||||
try {
|
||||
series.get(j).getData().add(new BigDecimal(StringUtils.isEmpty(d[i]) ? "0" : d[i]));
|
||||
} catch (Exception e) {
|
||||
series.get(j).getData().add(new BigDecimal(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.put("x", x);
|
||||
map.put("series", series);
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> transTableNormal(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) {
|
||||
Map<String, Object> map = new TreeMap<>();
|
||||
List<ChartViewFieldDTO> fields = new ArrayList<>();
|
||||
List<Map<String, Object>> tableRow = new ArrayList<>();
|
||||
if (ObjectUtils.isNotEmpty(xAxis)) {
|
||||
fields.addAll(xAxis);
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
if (ObjectUtils.isNotEmpty(extStack)) {
|
||||
fields.addAll(extStack);
|
||||
}
|
||||
}
|
||||
fields.addAll(yAxis);
|
||||
data.forEach(ele -> {
|
||||
Map<String, Object> d = new HashMap<>();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
ChartViewFieldDTO chartViewFieldDTO = fields.get(i);
|
||||
if (chartViewFieldDTO.getDeType() == 0 || chartViewFieldDTO.getDeType() == 1) {
|
||||
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? "" : ele[i]);
|
||||
} else if (chartViewFieldDTO.getDeType() == 2 || chartViewFieldDTO.getDeType() == 3) {
|
||||
d.put(fields.get(i).getDataeaseName(), new BigDecimal(StringUtils.isEmpty(ele[i]) ? "0" : ele[i]).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
}
|
||||
tableRow.add(d);
|
||||
});
|
||||
map.put("fields", fields);
|
||||
map.put("tableRow", tableRow);
|
||||
return map;
|
||||
}
|
||||
|
||||
private void checkName(ChartViewWithBLOBs chartView) {
|
||||
// if (StringUtils.isEmpty(chartView.getId())) {
|
||||
// return;
|
||||
|
@ -1012,7 +1012,7 @@ public class DataSetTableService {
|
||||
public Map<String, Object> excelSaveAndParse(MultipartFile file, String tableId) throws Exception {
|
||||
String filename = file.getOriginalFilename();
|
||||
// parse file
|
||||
Map<String, Object> fileMap = parseExcel(filename, file.getInputStream(), true);
|
||||
Map<String, Object> fileMap = parseExcel2(filename, file.getInputStream(), true);
|
||||
if (StringUtils.isNotEmpty(tableId)) {
|
||||
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId);
|
||||
datasetTableFields.sort((o1, o2) -> {
|
||||
@ -1038,6 +1038,52 @@ public class DataSetTableService {
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> parseExcel2(String filename, InputStream inputStream, boolean isPreview) throws Exception {
|
||||
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
|
||||
List<TableFiled> fields = new ArrayList<>();
|
||||
List<List<String>> data = new ArrayList<>();
|
||||
List<Map<String, Object>> jsonArray = new ArrayList<>();
|
||||
List<String> sheets = new ArrayList<>();
|
||||
if (StringUtils.equalsIgnoreCase(suffix, "xls")) {
|
||||
ExcelXlsReader excelXlsReader = new ExcelXlsReader();
|
||||
excelXlsReader.process(inputStream);
|
||||
fields = excelXlsReader.totalSheets.get(0).getFields();
|
||||
data = excelXlsReader.totalSheets.get(0).getData();
|
||||
sheets = excelXlsReader.totalSheets.stream().map(ExcelSheetData::getSheetName).collect(Collectors.toList());
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase(suffix, "xlsx")) {
|
||||
ExcelXlsxReader excelXlsxReader = new ExcelXlsxReader();
|
||||
excelXlsxReader.process(inputStream);
|
||||
fields = excelXlsxReader.totalSheets.get(0).getFields();
|
||||
data = excelXlsxReader.totalSheets.get(0).getData();
|
||||
sheets = excelXlsxReader.totalSheets.stream().map(ExcelSheetData::getSheetName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
String[] fieldArray = fields.stream().map(TableFiled::getFieldName).toArray(String[]::new);
|
||||
|
||||
// 校验excel字段是否重名
|
||||
if (checkIsRepeat(fieldArray)) {
|
||||
DataEaseException.throwException(Translator.get("i18n_excel_field_repeat"));
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(data)) {
|
||||
jsonArray = data.stream().map(ele -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (int i = 0; i < ele.size(); i++) {
|
||||
map.put(fieldArray[i], ele.get(i));
|
||||
}
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
inputStream.close();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("fields", fields);
|
||||
map.put("data", jsonArray);
|
||||
map.put("sheets", sheets);
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> parseExcel(String filename, InputStream inputStream, boolean isPreview) throws Exception {
|
||||
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
|
||||
List<TableFiled> fields = new ArrayList<>();
|
||||
@ -1191,6 +1237,7 @@ public class DataSetTableService {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
private String readCell(Cell cell, boolean cellType, TableFiled tableFiled) {
|
||||
if (cell == null) {
|
||||
return "";
|
||||
|
@ -0,0 +1,4 @@
|
||||
ALTER TABLE `chart_view` ADD COLUMN `ext_stack` LONGTEXT COMMENT '堆叠项' AFTER `y_axis`;
|
||||
|
||||
UPDATE `chart_view` SET `ext_stack` = '[]';
|
||||
UPDATE `chart_view` SET `custom_filter` = '[]';
|
2938
backend/src/main/resources/db/migration/V17__area_mapping.sql
Normal file
2938
backend/src/main/resources/db/migration/V17__area_mapping.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -64,7 +64,7 @@
|
||||
|
||||
<!--要生成的数据库表 -->
|
||||
|
||||
<!-- <table tableName="datasource"/>-->
|
||||
<table tableName="chart_view"/>
|
||||
<!-- <table tableName="sys_dict"/>-->
|
||||
<!-- <table tableName="sys_dict_item"/>-->
|
||||
<!-- <table tableName="dataset_table_field"/>-->
|
||||
@ -74,9 +74,9 @@
|
||||
<!-- </table>-->
|
||||
<!-- <table tableName="v_dataset"/>-->
|
||||
<!-- <table tableName="sys_auth_detail"/>-->
|
||||
<table tableName="dataset_table_task">
|
||||
<columnOverride column="extra_data" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
</table>
|
||||
<!-- <table tableName="dataset_table_task">-->
|
||||
<!-- <columnOverride column="extra_data" javaType="java.lang.String" jdbcType="VARCHAR" />-->
|
||||
<!-- </table>-->
|
||||
|
||||
|
||||
</context>
|
||||
|
17
frontend/src/api/map/map.js
Normal file
17
frontend/src/api/map/map.js
Normal file
@ -0,0 +1,17 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export const areaMapping = () => {
|
||||
return request({
|
||||
url: '/api/map/areaEntitys/0',
|
||||
method: 'get',
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
|
||||
export function geoJson(areaCode) {
|
||||
return request({
|
||||
url: '/api/map/resourceFull/' + areaCode,
|
||||
method: 'get',
|
||||
loading: true
|
||||
})
|
||||
}
|
1
frontend/src/icons/svg/map.svg
Normal file
1
frontend/src/icons/svg/map.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1626859344070" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="819" width="200" height="200"><path d="M948.3 170.5c-7.2-6.1-17.4-8.7-26.6-7.2l-237.1 42-60.4-20c-17.4-5.6-35.8 3.6-41.5 20.5-5.6 16.9 3.6 35.8 20.5 41.5l68.6 22.5c1.5 0.5 3.1 1 4.6 1v265.7L541.2 495c-11.8-3.6-23.6 3.1-27.1 14.3s3.1 23.6 14.3 27.1l148 45.6v273.9L392.8 776V652.8c0-12.3-9.7-22-22-22s-22 9.7-22 22v123.9L130.7 811V195.1c0-17.9-14.8-32.8-32.8-32.8s-32.8 14.8-32.8 32.8v654.3c0 9.7 4.1 18.4 11.3 25.1 7.2 6.1 16.9 9.2 26.1 7.7l270.8-42.5 304.1 85.5c3.1 1 5.6 1 8.7 1 2 0 4.1 0 5.6-0.5l240.1-43.5c15.4-3.1 26.6-16.4 26.6-32.3V195.6c1.7-9.7-2.9-19-10.1-25.1z" p-id="820"></path><path d="M376.4 97.8c-102.4 0-185.3 82.9-185.3 185.3 0 28.2 6.7 55.8 20.5 82.9 10.8 21 109.1 159.7 138.8 201.7 6.1 8.7 15.9 13.8 26.6 13.8 10.8 0 20.5-5.1 26.6-13.8 29.7-42.5 127.5-181.8 137.7-201.2 13.3-25.6 20.5-54.8 20.5-83.5 0-102.3-83-185.2-185.4-185.2z m0.5 240.1c-30.2 0-54.8-24.6-54.8-54.8s24.1-54.8 54.8-54.8c30.2 0 54.8 24.6 54.8 54.8s-24.6 54.8-54.8 54.8z" p-id="821"></path></svg>
|
After Width: | Height: | Size: 1.1 KiB |
1
frontend/src/icons/svg/sort-asc.svg
Normal file
1
frontend/src/icons/svg/sort-asc.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1626861945234" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5279" width="200" height="200"><path d="M0 0h307.2v122.88H0V0z m0 460.8h614.4v122.88H0V460.8z m0 440.32h1024V1024H0v-122.88z" p-id="5280"></path></svg>
|
After Width: | Height: | Size: 267 B |
1
frontend/src/icons/svg/sort-desc.svg
Normal file
1
frontend/src/icons/svg/sort-desc.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1626861978178" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4648" width="200" height="200"><path d="M0 0h1024v122.88H0V0z m0 460.8h614.4v122.88H0V460.8z m0 440.32h307.2V1024H0v-122.88z" p-id="4649"></path></svg>
|
After Width: | Height: | Size: 267 B |
@ -750,6 +750,7 @@ export default {
|
||||
chart_funnel: 'Funnel',
|
||||
chart_radar: 'Radar',
|
||||
chart_gauge: 'Gauge',
|
||||
chart_map: 'Map',
|
||||
dateStyle: 'Date Style',
|
||||
datePattern: 'Date Format',
|
||||
y: 'Year',
|
||||
@ -817,7 +818,11 @@ export default {
|
||||
drag_block_funnel_width: 'Funnel Width',
|
||||
drag_block_funnel_split: 'Funnel Split',
|
||||
drag_block_radar_length: 'Branch Length',
|
||||
drag_block_radar_label: 'Branch Label'
|
||||
drag_block_radar_label: 'Branch Label',
|
||||
stack_item: 'Stack Item',
|
||||
map_range: 'Map range',
|
||||
select_map_range: 'Please select map range',
|
||||
area: 'Area'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default',
|
||||
|
@ -750,6 +750,7 @@ export default {
|
||||
chart_funnel: '漏鬥圖',
|
||||
chart_radar: '雷達圖',
|
||||
chart_gauge: '儀表盤',
|
||||
chart_map: '地圖',
|
||||
dateStyle: '日期顯示',
|
||||
datePattern: '日期格式',
|
||||
y: '年',
|
||||
@ -817,7 +818,11 @@ export default {
|
||||
drag_block_funnel_width: '漏鬥層寬',
|
||||
drag_block_funnel_split: '漏鬥分層',
|
||||
drag_block_radar_length: '分支長度',
|
||||
drag_block_radar_label: '分支標簽'
|
||||
drag_block_radar_label: '分支標簽',
|
||||
map_range: '地圖範圍',
|
||||
select_map_range: '請選擇地圖範圍',
|
||||
area: '地區',
|
||||
stack_item: '堆疊項'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多個sheet頁面,默認抽取第一個',
|
||||
|
@ -750,6 +750,7 @@ export default {
|
||||
chart_funnel: '漏斗图',
|
||||
chart_radar: '雷达图',
|
||||
chart_gauge: '仪表盘',
|
||||
chart_map: '地图',
|
||||
dateStyle: '日期显示',
|
||||
datePattern: '日期格式',
|
||||
y: '年',
|
||||
@ -817,7 +818,11 @@ export default {
|
||||
drag_block_funnel_width: '漏斗层宽',
|
||||
drag_block_funnel_split: '漏斗分层',
|
||||
drag_block_radar_length: '分支长度',
|
||||
drag_block_radar_label: '分支标签'
|
||||
drag_block_radar_label: '分支标签',
|
||||
map_range: '地图范围',
|
||||
select_map_range: '请选择地图范围',
|
||||
area: '地区',
|
||||
stack_item: '堆叠项'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多个 Sheet 页,默认抽取第一个',
|
||||
|
@ -121,6 +121,8 @@ export default {
|
||||
width: 100% !important;
|
||||
position: initial !important;
|
||||
height: calc(100vh - 80px) !important;
|
||||
overflow-x: hidden !important;
|
||||
overflow-y: auto !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -221,7 +221,7 @@ div:focus {
|
||||
|
||||
%field-icon{
|
||||
font-size: 13px;
|
||||
margin: 0 3px 0 0;
|
||||
margin: 0 2px 0 0;
|
||||
}
|
||||
.field-icon-text{
|
||||
@extend %field-icon;
|
||||
@ -239,6 +239,11 @@ div:focus {
|
||||
@extend %field-icon;
|
||||
color: #F56C6C;
|
||||
}
|
||||
.field-icon-sort{
|
||||
font-size: 10px;
|
||||
@extend %field-icon;
|
||||
color: #999999;
|
||||
}
|
||||
.ds-icon-scene{
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
|
@ -528,3 +528,37 @@ export const BASE_CHART = {
|
||||
},
|
||||
customFilter: []
|
||||
}
|
||||
|
||||
export const BASE_MAP = {
|
||||
title: {
|
||||
text: '',
|
||||
textStyle: {
|
||||
fontWeight: 'normal'
|
||||
}
|
||||
},
|
||||
|
||||
tooltip: {},
|
||||
visualMap: {
|
||||
min: 50,
|
||||
max: 52,
|
||||
text: ['High', 'Low'],
|
||||
realtime: false,
|
||||
calculable: true,
|
||||
inRange: {
|
||||
color: ['lightskyblue', 'yellow', 'orangered']
|
||||
}
|
||||
},
|
||||
// legend: {},
|
||||
series: [
|
||||
{
|
||||
name: '',
|
||||
type: 'map',
|
||||
map: 'HK',
|
||||
roam: true,
|
||||
// label: {
|
||||
// show: true
|
||||
// },
|
||||
data: []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ export function componentStyle(chart_option, chart) {
|
||||
customStyle.text.isBolder ? style.fontWeight = 'bold' : style.fontWeight = 'normal'
|
||||
chart_option.title.textStyle = style
|
||||
}
|
||||
if (customStyle.legend) {
|
||||
if (customStyle.legend && chart_option.legend) {
|
||||
chart_option.legend.show = customStyle.legend.show
|
||||
// 水平方向
|
||||
if (customStyle.legend.hPosition === 'left') {
|
||||
|
59
frontend/src/views/chart/chart/map/map.js
Normal file
59
frontend/src/views/chart/chart/map/map.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { hexColorToRGBA } from '@/views/chart/chart/util'
|
||||
import { componentStyle } from '../common/common'
|
||||
|
||||
export function baseMapOption(chart_option, chart) {
|
||||
// 处理shape attr
|
||||
let customAttr = {}
|
||||
if (chart.customAttr) {
|
||||
customAttr = JSON.parse(chart.customAttr)
|
||||
if (customAttr.color) {
|
||||
chart_option.color = customAttr.color.colors
|
||||
}
|
||||
// tooltip
|
||||
if (customAttr.tooltip) {
|
||||
const tooltip = JSON.parse(JSON.stringify(customAttr.tooltip))
|
||||
const reg = new RegExp('\n', 'g')
|
||||
tooltip.formatter = tooltip.formatter.replace(reg, '<br/>')
|
||||
chart_option.tooltip = tooltip
|
||||
}
|
||||
}
|
||||
// 处理data
|
||||
if (chart.data) {
|
||||
chart_option.title.text = chart.title
|
||||
if (chart.data.series.length > 0) {
|
||||
chart_option.series[0].name = chart.data.series[0].name
|
||||
// size
|
||||
if (customAttr.size) {
|
||||
chart_option.series[0].radius = [customAttr.size.pieInnerRadius + '%', customAttr.size.pieOuterRadius + '%']
|
||||
}
|
||||
// label
|
||||
if (customAttr.label) {
|
||||
chart_option.series[0].label = customAttr.label
|
||||
chart_option.series[0].labelLine = customAttr.label.labelLine
|
||||
}
|
||||
// visualMap
|
||||
const valueArr = chart.data.series[0].data
|
||||
chart_option.visualMap.min = Math.min(...valueArr)
|
||||
chart_option.visualMap.max = Math.max(...valueArr)
|
||||
if (customAttr.color && customAttr.color.colors) {
|
||||
chart_option.visualMap.inRange.color = customAttr.color.colors
|
||||
}
|
||||
for (let i = 0; i < valueArr.length; i++) {
|
||||
const y = {
|
||||
name: chart.data.x[i],
|
||||
value: valueArr[i]
|
||||
}
|
||||
// color
|
||||
y.itemStyle = {
|
||||
color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha),
|
||||
borderRadius: 0
|
||||
}
|
||||
chart_option.series[0].data.push(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(chart_option);
|
||||
componentStyle(chart_option, chart)
|
||||
return chart_option
|
||||
}
|
||||
|
@ -5,15 +5,17 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { BASE_BAR, BASE_LINE, HORIZONTAL_BAR, BASE_PIE, BASE_FUNNEL, BASE_RADAR, BASE_GAUGE } from '../chart/chart'
|
||||
import { BASE_BAR, BASE_LINE, HORIZONTAL_BAR, BASE_PIE, BASE_FUNNEL, BASE_RADAR, BASE_GAUGE, BASE_MAP } from '../chart/chart'
|
||||
import { baseBarOption, stackBarOption, horizontalBarOption, horizontalStackBarOption } from '../chart/bar/bar'
|
||||
import { baseLineOption, stackLineOption } from '../chart/line/line'
|
||||
import { basePieOption, rosePieOption } from '../chart/pie/pie'
|
||||
import { baseMapOption } from '../chart/map/map'
|
||||
import { baseFunnelOption } from '../chart/funnel/funnel'
|
||||
import { baseRadarOption } from '../chart/radar/radar'
|
||||
import { baseGaugeOption } from '../chart/gauge/gauge'
|
||||
import eventBus from '@/components/canvas/utils/eventBus'
|
||||
// import eventBus from '@/components/canvas/utils/eventBus'
|
||||
import { uuid } from 'vue-uuid'
|
||||
import { geoJson } from '@/api/map/map'
|
||||
|
||||
export default {
|
||||
name: 'ChartComponent',
|
||||
@ -93,6 +95,29 @@ export default {
|
||||
} else if (chart.type === 'gauge') {
|
||||
chart_option = baseGaugeOption(JSON.parse(JSON.stringify(BASE_GAUGE)), chart)
|
||||
}
|
||||
|
||||
if (chart.type === 'map') {
|
||||
const customAttr = JSON.parse(chart.customAttr)
|
||||
if (!customAttr.areaCode) return
|
||||
|
||||
let areaJson
|
||||
if ((areaJson = localStorage.getItem('areaJson' + customAttr.areaCode)) !== null) {
|
||||
this.initMapChart(areaJson, chart)
|
||||
return
|
||||
}
|
||||
geoJson(customAttr.areaCode).then(res => {
|
||||
this.initMapChart(res.data, chart)
|
||||
// localStorage最大容量只有5M,先取消缓存
|
||||
// localStorage.setItem('areaJson' + customAttr.areaCode, res.data)
|
||||
})
|
||||
return
|
||||
}
|
||||
this.myEcharts(chart_option)
|
||||
},
|
||||
initMapChart(geoJson, chart) {
|
||||
this.$echarts.registerMap('HK', geoJson)
|
||||
const base_json = JSON.parse(JSON.stringify(BASE_MAP))
|
||||
const chart_option = baseMapOption(base_json, chart)
|
||||
this.myEcharts(chart_option)
|
||||
},
|
||||
myEcharts(option) {
|
||||
|
156
frontend/src/views/chart/components/drag-item/ChartDragItem.vue
Normal file
156
frontend/src/views/chart/components/drag-item/ChartDragItem.vue
Normal file
@ -0,0 +1,156 @@
|
||||
<template>
|
||||
<span>
|
||||
<el-tag v-if="!hasDataPermission('manage',param.privileges)" size="small" class="item-axis">
|
||||
<span style="float: left">
|
||||
<svg-icon v-if="item.deType === 0" icon-class="field_text" class="field-icon-text" />
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
</el-tag>
|
||||
<el-dropdown v-else trigger="click" size="mini" @command="clickItem">
|
||||
<span class="el-dropdown-link">
|
||||
<el-tag size="small" class="item-axis">
|
||||
<span style="float: left">
|
||||
<svg-icon v-if="item.deType === 0" icon-class="field_text" class="field-icon-text" />
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
<i class="el-icon-arrow-down el-icon--right" style="position: absolute;top: 6px;right: 10px;" />
|
||||
</el-tag>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item>
|
||||
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="sort">
|
||||
<span class="el-dropdown-link inner-dropdown-menu">
|
||||
<span>
|
||||
<i class="el-icon-sort" />
|
||||
<span>{{ $t('chart.sort') }}</span>
|
||||
<span class="summary-span">({{ $t('chart.'+item.sort) }})</span>
|
||||
</span>
|
||||
<i class="el-icon-arrow-right el-icon--right" />
|
||||
</span>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="beforeSort('none')">{{ $t('chart.none') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeSort('asc')">{{ $t('chart.asc') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeSort('desc')">{{ $t('chart.desc') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item icon="el-icon-delete" divided :command="beforeClickItem('remove')">
|
||||
<span>{{ $t('chart.delete') }}</span>
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</span>
|
||||
</el-dropdown>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'ChartDragItem',
|
||||
props: {
|
||||
param: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
item: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
index: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
methods: {
|
||||
clickItem(param) {
|
||||
if (!param) {
|
||||
return
|
||||
}
|
||||
switch (param.type) {
|
||||
case 'remove':
|
||||
this.removeItem()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
},
|
||||
beforeClickItem(type) {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
sort(param) {
|
||||
// console.log(param)
|
||||
this.item.sort = param.type
|
||||
this.$emit('onItemChange', this.item)
|
||||
},
|
||||
beforeSort(type) {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
removeItem() {
|
||||
this.item.index = this.index
|
||||
this.$emit('onItemRemove', this.item)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.item-axis {
|
||||
padding: 1px 6px;
|
||||
margin: 0 3px 2px 3px;
|
||||
text-align: left;
|
||||
height: 24px;
|
||||
line-height: 22px;
|
||||
display: flex;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
white-space: nowrap;
|
||||
width: 159px;
|
||||
}
|
||||
|
||||
.item-axis:hover {
|
||||
background-color: #fdfdfd;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.summary-span{
|
||||
margin-left: 4px;
|
||||
color: #878d9f;;
|
||||
}
|
||||
|
||||
.inner-dropdown-menu{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%
|
||||
}
|
||||
|
||||
.item-span-style{
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
@ -6,6 +6,8 @@
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
</el-tag>
|
||||
@ -17,6 +19,8 @@
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
<i class="el-icon-arrow-down el-icon--right" style="position: absolute;top: 6px;right: 10px;" />
|
||||
|
@ -6,6 +6,8 @@
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
<span v-if="item.summary" class="summary-span">{{ $t('chart.'+item.summary) }}</span>
|
||||
@ -18,6 +20,8 @@
|
||||
<svg-icon v-if="item.deType === 1" icon-class="field_time" class="field-icon-time" />
|
||||
<svg-icon v-if="item.deType === 2 || item.deType === 3" icon-class="field_value" class="field-icon-value" />
|
||||
<svg-icon v-if="item.deType === 5" icon-class="field_location" class="field-icon-location" />
|
||||
<svg-icon v-if="item.sort === 'asc'" icon-class="sort-asc" class-name="field-icon-sort" />
|
||||
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
|
||||
</span>
|
||||
<span class="item-span-style" :title="item.name">{{ item.name }}</span>
|
||||
<span v-if="item.summary" class="summary-span">{{ $t('chart.'+item.summary) }}</span>
|
||||
@ -226,7 +230,7 @@ export default {
|
||||
|
||||
.item-span-style{
|
||||
display: inline-block;
|
||||
width: 80px;
|
||||
width: 70px;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
|
@ -741,6 +741,9 @@ export default {
|
||||
background: DEFAULT_BACKGROUND_COLOR,
|
||||
split: DEFAULT_SPLIT
|
||||
})
|
||||
view.xaxis = JSON.stringify([])
|
||||
view.yaxis = JSON.stringify([])
|
||||
view.extStack = JSON.stringify([])
|
||||
view.customFilter = JSON.stringify([])
|
||||
post('/chart/view/save', view).then(response => {
|
||||
this.closeCreateChart()
|
||||
|
@ -190,6 +190,11 @@
|
||||
<svg-icon icon-class="gauge" class="chart-icon" />
|
||||
</span>
|
||||
</el-radio>
|
||||
<el-radio value="map" label="map">
|
||||
<span :title="$t('chart.chart_map')">
|
||||
<svg-icon icon-class="map" class="chart-icon" />
|
||||
</span>
|
||||
</el-radio>
|
||||
<el-radio value="" label="" disabled class="disabled-none-cursor"><svg-icon icon-class="" class="chart-icon" /></el-radio>
|
||||
<el-radio value="" label="" disabled class="disabled-none-cursor"><svg-icon icon-class="" class="chart-icon" /></el-radio>
|
||||
</div>
|
||||
@ -212,13 +217,31 @@
|
||||
</div>
|
||||
<div style="overflow:auto;border-top: 1px solid #e6e6e6" class="attr-style">
|
||||
<el-row style="height: 100%;">
|
||||
<el-row v-if="chart.type ==='map'" class="padding-lr">
|
||||
<span style="width: 80px;text-align: right;">
|
||||
|
||||
<span>{{ $t('chart.map_range') }}</span>
|
||||
</span>
|
||||
<span class="tree-select-span">
|
||||
<treeselect
|
||||
ref="mapSelector"
|
||||
v-model="view.customAttr.areaCode"
|
||||
:options="places"
|
||||
:placeholder="$t('chart.select_map_range')"
|
||||
:normalizer="normalizer"
|
||||
@input="save"
|
||||
@deselect="save"
|
||||
/>
|
||||
</span>
|
||||
</el-row>
|
||||
<el-row v-if="chart.type !=='text' && chart.type !== 'gauge'" class="padding-lr">
|
||||
<span style="width: 80px;text-align: right;">
|
||||
<span v-if="chart.type.includes('table')">{{ $t('chart.drag_block_table_data_column') }}</span>
|
||||
<span v-else-if="chart.type.includes('bar') || chart.type.includes('line')">{{ $t('chart.drag_block_type_axis') }}</span>
|
||||
<span v-else-if="chart.type.includes('pie')">{{ $t('chart.drag_block_pie_label') }}</span>
|
||||
<span v-else-if="chart.type.includes('funnel')">{{ $t('chart.drag_block_funnel_split') }}</span>
|
||||
<span v-else-if="chart.type.includes('radar')">{{ $t('chart.drag_block_radar_label') }}</span>
|
||||
<span v-if="chart.type && chart.type.includes('table')">{{ $t('chart.drag_block_table_data_column') }}</span>
|
||||
<span v-else-if="chart.type && (chart.type.includes('bar') || chart.type.includes('line'))">{{ $t('chart.drag_block_type_axis') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('pie')">{{ $t('chart.drag_block_pie_label') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('funnel')">{{ $t('chart.drag_block_funnel_split') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('radar')">{{ $t('chart.drag_block_radar_label') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('map')">{{ $t('chart.area') }}</span>
|
||||
/
|
||||
<span>{{ $t('chart.dimension') }}</span>
|
||||
</span>
|
||||
@ -238,13 +261,14 @@
|
||||
</el-row>
|
||||
<el-row class="padding-lr" style="margin-top: 6px;">
|
||||
<span style="width: 80px;text-align: right;">
|
||||
<span v-if="chart.type.includes('table')">{{ $t('chart.drag_block_table_data_column') }}</span>
|
||||
<span v-else-if="chart.type.includes('bar') || chart.type.includes('line')">{{ $t('chart.drag_block_value_axis') }}</span>
|
||||
<span v-else-if="chart.type.includes('pie')">{{ $t('chart.drag_block_pie_angel') }}</span>
|
||||
<span v-else-if="chart.type.includes('funnel')">{{ $t('chart.drag_block_funnel_width') }}</span>
|
||||
<span v-else-if="chart.type.includes('radar')">{{ $t('chart.drag_block_radar_length') }}</span>
|
||||
<span v-else-if="chart.type.includes('gauge')">{{ $t('chart.drag_block_gauge_angel') }}</span>
|
||||
<span v-else-if="chart.type.includes('text')">{{ $t('chart.drag_block_label_value') }}</span>
|
||||
<span v-if="chart.type && chart.type.includes('table')">{{ $t('chart.drag_block_table_data_column') }}</span>
|
||||
<span v-else-if="chart.type && (chart.type.includes('bar') || chart.type.includes('line'))">{{ $t('chart.drag_block_value_axis') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('pie')">{{ $t('chart.drag_block_pie_angel') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('funnel')">{{ $t('chart.drag_block_funnel_width') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('radar')">{{ $t('chart.drag_block_radar_length') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('gauge')">{{ $t('chart.drag_block_gauge_angel') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('text')">{{ $t('chart.drag_block_label_value') }}</span>
|
||||
<span v-else-if="chart.type && chart.type.includes('map')">{{ $t('chart.chart_data') }}</span>
|
||||
/
|
||||
<span>{{ $t('chart.quota') }}</span>
|
||||
</span>
|
||||
@ -262,6 +286,26 @@
|
||||
</transition-group>
|
||||
</draggable>
|
||||
</el-row>
|
||||
<el-row v-if="chart.type && chart.type.includes('stack')" class="padding-lr" style="margin-top: 6px;">
|
||||
<span style="width: 80px;text-align: right;">
|
||||
<span>{{ $t('chart.stack_item') }}</span>
|
||||
/
|
||||
<span>{{ $t('chart.dimension') }}</span>
|
||||
</span>
|
||||
<draggable
|
||||
v-model="view.extStack"
|
||||
:disabled="!hasDataPermission('manage',param.privileges)"
|
||||
group="drag"
|
||||
animation="300"
|
||||
:move="onMove"
|
||||
style="padding:2px 0 0 0;width:100%;min-height: 32px;border-radius: 4px;border: 1px solid #DCDFE6;overflow-x: auto;display: flex;align-items: center;background-color: white;"
|
||||
@add="addStack"
|
||||
>
|
||||
<transition-group class="draggable-group">
|
||||
<chart-drag-item v-for="(item,index) in view.extStack" :key="item.id" :param="param" :index="index" :item="item" @onItemChange="stackItemChange" @onItemRemove="stackItemRemove" />
|
||||
</transition-group>
|
||||
</draggable>
|
||||
</el-row>
|
||||
<div class="padding-lr filter-class" style="margin-top: 6px;">
|
||||
<span>{{ $t('chart.result_filter') }}</span>
|
||||
<!-- <el-button :disabled="!hasDataPermission('manage',param.privileges)" size="mini" class="filter-btn-class" @click="showResultFilter">-->
|
||||
@ -301,7 +345,7 @@
|
||||
<span>{{ $t('chart.shape_attr') }}</span>
|
||||
<el-row>
|
||||
<color-selector :param="param" class="attr-selector" :chart="chart" @onColorChange="onColorChange" />
|
||||
<size-selector :param="param" class="attr-selector" :chart="chart" @onSizeChange="onSizeChange" />
|
||||
<size-selector v-show="chart.type !== 'map'" :param="param" class="attr-selector" :chart="chart" @onSizeChange="onSizeChange" />
|
||||
<label-selector v-show="!view.type.includes('table') && !view.type.includes('text')" :param="param" class="attr-selector" :chart="chart" @onLabelChange="onLabelChange" />
|
||||
<tooltip-selector v-show="!view.type.includes('table') && !view.type.includes('text')" :param="param" class="attr-selector" :chart="chart" @onTooltipChange="onTooltipChange" />
|
||||
</el-row>
|
||||
@ -309,11 +353,11 @@
|
||||
<el-row class="padding-lr">
|
||||
<span>{{ $t('chart.module_style') }}</span>
|
||||
<el-row>
|
||||
<x-axis-selector v-show="view.type.includes('bar') || view.type.includes('line')" :param="param" class="attr-selector" :chart="chart" @onChangeXAxisForm="onChangeXAxisForm" />
|
||||
<y-axis-selector v-show="view.type.includes('bar') || view.type.includes('line')" :param="param" class="attr-selector" :chart="chart" @onChangeYAxisForm="onChangeYAxisForm" />
|
||||
<split-selector v-show="view.type.includes('radar')" :param="param" class="attr-selector" :chart="chart" @onChangeSplitForm="onChangeSplitForm" />
|
||||
<x-axis-selector v-show="view.type && (view.type.includes('bar') || view.type.includes('line'))" :param="param" class="attr-selector" :chart="chart" @onChangeXAxisForm="onChangeXAxisForm" />
|
||||
<y-axis-selector v-show="view.type && (view.type.includes('bar') || view.type.includes('line'))" :param="param" class="attr-selector" :chart="chart" @onChangeYAxisForm="onChangeYAxisForm" />
|
||||
<split-selector v-show="view.type && view.type.includes('radar')" :param="param" class="attr-selector" :chart="chart" @onChangeSplitForm="onChangeSplitForm" />
|
||||
<title-selector :param="param" class="attr-selector" :chart="chart" @onTextChange="onTextChange" />
|
||||
<legend-selector v-show="!view.type.includes('table') && !view.type.includes('text')" :param="param" class="attr-selector" :chart="chart" @onLegendChange="onLegendChange" />
|
||||
<legend-selector v-show="view.type && !view.type.includes('map') && !view.type.includes('table') && !view.type.includes('text')" :param="param" class="attr-selector" :chart="chart" @onLegendChange="onLegendChange" />
|
||||
<background-color-selector :param="param" class="attr-selector" :chart="chart" @onChangeBackgroundForm="onChangeBackgroundForm" />
|
||||
</el-row>
|
||||
</el-row>
|
||||
@ -434,6 +478,7 @@ import draggable from 'vuedraggable'
|
||||
import DimensionItem from '../components/drag-item/DimensionItem'
|
||||
import QuotaItem from '../components/drag-item/QuotaItem'
|
||||
import FilterItem from '../components/drag-item/FilterItem'
|
||||
import ChartDragItem from '../components/drag-item/ChartDragItem'
|
||||
import ResultFilterEditor from '../components/filter/ResultFilterEditor'
|
||||
import ChartComponent from '../components/ChartComponent'
|
||||
import bus from '@/utils/bus'
|
||||
@ -465,10 +510,10 @@ import QuotaFilterEditor from '../components/filter/QuotaFilterEditor'
|
||||
import DimensionFilterEditor from '../components/filter/DimensionFilterEditor'
|
||||
import TableNormal from '../components/table/TableNormal'
|
||||
import LabelNormal from '../components/normal/LabelNormal'
|
||||
import html2canvas from 'html2canvasde'
|
||||
// import html2canvas from 'html2canvasde'
|
||||
import TableSelector from './TableSelector'
|
||||
import FieldEdit from '../../dataset/data/FieldEdit'
|
||||
|
||||
import { areaMapping } from '@/api/map/map'
|
||||
export default {
|
||||
name: 'ChartEdit',
|
||||
components: {
|
||||
@ -494,7 +539,8 @@ export default {
|
||||
ChartComponent,
|
||||
QuotaItem,
|
||||
DimensionItem,
|
||||
draggable
|
||||
draggable,
|
||||
ChartDragItem
|
||||
},
|
||||
props: {
|
||||
param: {
|
||||
@ -513,6 +559,7 @@ export default {
|
||||
view: {
|
||||
xaxis: [],
|
||||
yaxis: [],
|
||||
extStack: [],
|
||||
show: true,
|
||||
type: 'bar',
|
||||
title: '',
|
||||
@ -563,7 +610,8 @@ export default {
|
||||
searchField: '',
|
||||
editDsField: false,
|
||||
changeDsTitle: '',
|
||||
filterItem: {}
|
||||
filterItem: {},
|
||||
places: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -587,6 +635,7 @@ export default {
|
||||
},
|
||||
created() {
|
||||
// this.get(this.$store.state.chart.viewId);
|
||||
this.initAreas()
|
||||
},
|
||||
mounted() {
|
||||
// this.get(this.$store.state.chart.viewId);
|
||||
@ -667,6 +716,11 @@ export default {
|
||||
ele.filter = []
|
||||
}
|
||||
})
|
||||
view.extStack.forEach(function(ele) {
|
||||
if (!ele.sort || ele.sort === '') {
|
||||
ele.sort = 'none'
|
||||
}
|
||||
})
|
||||
if (view.type.startsWith('pie') || view.type.startsWith('funnel') || view.type.startsWith('text') || view.type.startsWith('gauge')) {
|
||||
if (view.yaxis.length > 1) {
|
||||
view.yaxis.splice(1, view.yaxis.length)
|
||||
@ -688,6 +742,7 @@ export default {
|
||||
view.customAttr = JSON.stringify(view.customAttr)
|
||||
view.customStyle = JSON.stringify(view.customStyle)
|
||||
view.customFilter = JSON.stringify(view.customFilter)
|
||||
view.extStack = JSON.stringify(view.extStack)
|
||||
post('/chart/view/save', view).then(response => {
|
||||
// this.get(response.data.id);
|
||||
// this.getData(response.data.id)
|
||||
@ -707,67 +762,67 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
saveSnapshot() {
|
||||
if (this.view.title && this.view.title.length > 50) {
|
||||
this.$warning(this.$t('chart.title_limit'))
|
||||
return
|
||||
}
|
||||
if (this.loading) {
|
||||
return
|
||||
}
|
||||
this.loading = true
|
||||
html2canvas(this.$refs.imageWrapper).then(canvas => {
|
||||
const snapshot = canvas.toDataURL('image/jpeg', 0.1) // 0.1是图片质量
|
||||
if (snapshot !== '') {
|
||||
const view = JSON.parse(JSON.stringify(this.view))
|
||||
view.id = this.view.id
|
||||
view.sceneId = this.view.sceneId
|
||||
view.name = this.view.name ? this.view.name : this.table.name
|
||||
view.tableId = this.view.tableId
|
||||
view.xaxis.forEach(function(ele) {
|
||||
// if (!ele.summary || ele.summary === '') {
|
||||
// ele.summary = 'sum'
|
||||
// }
|
||||
if (!ele.sort || ele.sort === '') {
|
||||
ele.sort = 'none'
|
||||
}
|
||||
if (!ele.filter) {
|
||||
ele.filter = []
|
||||
}
|
||||
})
|
||||
view.yaxis.forEach(function(ele) {
|
||||
if (!ele.summary || ele.summary === '') {
|
||||
if (ele.id === 'count') {
|
||||
ele.summary = 'count'
|
||||
} else {
|
||||
ele.summary = 'sum'
|
||||
}
|
||||
}
|
||||
if (!ele.sort || ele.sort === '') {
|
||||
ele.sort = 'none'
|
||||
}
|
||||
if (!ele.filter) {
|
||||
ele.filter = []
|
||||
}
|
||||
})
|
||||
if (view.type.startsWith('pie') || view.type.startsWith('funnel') || view.type.startsWith('gauge')) {
|
||||
if (view.yaxis.length > 1) {
|
||||
view.yaxis.splice(1, view.yaxis.length)
|
||||
}
|
||||
}
|
||||
view.xaxis = JSON.stringify(view.xaxis)
|
||||
view.yaxis = JSON.stringify(view.yaxis)
|
||||
view.customAttr = JSON.stringify(view.customAttr)
|
||||
view.customStyle = JSON.stringify(view.customStyle)
|
||||
view.customFilter = JSON.stringify(view.customFilter)
|
||||
view.snapshot = snapshot
|
||||
post('/chart/view/save', view).then(response => {
|
||||
this.loading = false
|
||||
this.$success(this.$t('commons.save_success'))
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// saveSnapshot() {
|
||||
// if (this.view.title && this.view.title.length > 50) {
|
||||
// this.$warning(this.$t('chart.title_limit'))
|
||||
// return
|
||||
// }
|
||||
// if (this.loading) {
|
||||
// return
|
||||
// }
|
||||
// this.loading = true
|
||||
// html2canvas(this.$refs.imageWrapper).then(canvas => {
|
||||
// const snapshot = canvas.toDataURL('image/jpeg', 0.1) // 0.1是图片质量
|
||||
// if (snapshot !== '') {
|
||||
// const view = JSON.parse(JSON.stringify(this.view))
|
||||
// view.id = this.view.id
|
||||
// view.sceneId = this.view.sceneId
|
||||
// view.name = this.view.name ? this.view.name : this.table.name
|
||||
// view.tableId = this.view.tableId
|
||||
// view.xaxis.forEach(function(ele) {
|
||||
// // if (!ele.summary || ele.summary === '') {
|
||||
// // ele.summary = 'sum'
|
||||
// // }
|
||||
// if (!ele.sort || ele.sort === '') {
|
||||
// ele.sort = 'none'
|
||||
// }
|
||||
// if (!ele.filter) {
|
||||
// ele.filter = []
|
||||
// }
|
||||
// })
|
||||
// view.yaxis.forEach(function(ele) {
|
||||
// if (!ele.summary || ele.summary === '') {
|
||||
// if (ele.id === 'count') {
|
||||
// ele.summary = 'count'
|
||||
// } else {
|
||||
// ele.summary = 'sum'
|
||||
// }
|
||||
// }
|
||||
// if (!ele.sort || ele.sort === '') {
|
||||
// ele.sort = 'none'
|
||||
// }
|
||||
// if (!ele.filter) {
|
||||
// ele.filter = []
|
||||
// }
|
||||
// })
|
||||
// if (view.type.startsWith('pie') || view.type.startsWith('funnel') || view.type.startsWith('gauge')) {
|
||||
// if (view.yaxis.length > 1) {
|
||||
// view.yaxis.splice(1, view.yaxis.length)
|
||||
// }
|
||||
// }
|
||||
// view.xaxis = JSON.stringify(view.xaxis)
|
||||
// view.yaxis = JSON.stringify(view.yaxis)
|
||||
// view.customAttr = JSON.stringify(view.customAttr)
|
||||
// view.customStyle = JSON.stringify(view.customStyle)
|
||||
// view.customFilter = JSON.stringify(view.customFilter)
|
||||
// view.snapshot = snapshot
|
||||
// post('/chart/view/save', view).then(response => {
|
||||
// this.loading = false
|
||||
// this.$success(this.$t('commons.save_success'))
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
closeEdit() {
|
||||
if (this.view.title && this.view.title.length > 50) {
|
||||
this.$warning(this.$t('chart.title_limit'))
|
||||
@ -787,6 +842,7 @@ export default {
|
||||
this.view = JSON.parse(JSON.stringify(response.data))
|
||||
this.view.xaxis = this.view.xaxis ? JSON.parse(this.view.xaxis) : []
|
||||
this.view.yaxis = this.view.yaxis ? JSON.parse(this.view.yaxis) : []
|
||||
this.view.extStack = this.view.extStack ? JSON.parse(this.view.extStack) : []
|
||||
this.view.customAttr = this.view.customAttr ? JSON.parse(this.view.customAttr) : {}
|
||||
this.view.customStyle = this.view.customStyle ? JSON.parse(this.view.customStyle) : {}
|
||||
this.view.customFilter = this.view.customFilter ? JSON.parse(this.view.customFilter) : {}
|
||||
@ -815,6 +871,7 @@ export default {
|
||||
this.view = JSON.parse(JSON.stringify(response.data))
|
||||
this.view.xaxis = this.view.xaxis ? JSON.parse(this.view.xaxis) : []
|
||||
this.view.yaxis = this.view.yaxis ? JSON.parse(this.view.yaxis) : []
|
||||
this.view.extStack = this.view.extStack ? JSON.parse(this.view.extStack) : []
|
||||
this.view.customAttr = this.view.customAttr ? JSON.parse(this.view.customAttr) : {}
|
||||
this.view.customStyle = this.view.customStyle ? JSON.parse(this.view.customStyle) : {}
|
||||
this.view.customFilter = this.view.customFilter ? JSON.parse(this.view.customFilter) : {}
|
||||
@ -1201,12 +1258,53 @@ export default {
|
||||
}
|
||||
this.dragMoveDuplicate(this.view.customFilter, e)
|
||||
this.save(true)
|
||||
},
|
||||
|
||||
initAreas() {
|
||||
let mapping
|
||||
if ((mapping = localStorage.getItem('areaMapping')) !== null) {
|
||||
this.places = JSON.parse(mapping)
|
||||
return
|
||||
}
|
||||
Object.keys(this.places).length === 0 && areaMapping().then(res => {
|
||||
this.places = res.data
|
||||
localStorage.setItem('areaMapping', JSON.stringify(res.data))
|
||||
})
|
||||
},
|
||||
|
||||
normalizer(node) {
|
||||
const resultNode = {
|
||||
id: node.code,
|
||||
label: node.name
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
resultNode.children = node.children
|
||||
}
|
||||
|
||||
if (resultNode.children && (!node.children || node.children.length === 0)) {
|
||||
delete resultNode.children
|
||||
}
|
||||
return resultNode
|
||||
},
|
||||
addStack(e) {
|
||||
this.dragCheckType(this.dimensionData, 'd')
|
||||
if (this.view.extStack && this.view.extStack.length > 1) {
|
||||
this.view.extStack = [this.view.extStack[0]]
|
||||
}
|
||||
this.save(true)
|
||||
},
|
||||
stackItemChange(item) {
|
||||
this.save(true)
|
||||
},
|
||||
stackItemRemove(item) {
|
||||
this.view.extStack.splice(item.index, 1)
|
||||
this.save(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
<style lang='scss' scoped>
|
||||
.padding-lr {
|
||||
padding: 0 6px;
|
||||
}
|
||||
@ -1413,4 +1511,10 @@ export default {
|
||||
line-height: 40px;
|
||||
padding: 0 0 0 10px;
|
||||
}
|
||||
.tree-select-span {
|
||||
>>>div.vue-treeselect__control {
|
||||
height: 32px !important;
|
||||
font-weight: normal !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user