forked from github/dataease
Merge pull request #10915 from dataease/pr@dev-v2@feat_copilot
feat: 新增copilot所需接口
This commit is contained in:
commit
4c87232e5a
@ -292,13 +292,41 @@ public class CopilotManage {
|
||||
|
||||
public void rebuildChart(ReceiveDTO receiveDTO, List<TableField> fields) {
|
||||
if (StringUtils.equalsIgnoreCase(receiveDTO.getChart().getType(), "pie")) {
|
||||
if (fields.size() != 2) {
|
||||
AxisFieldDTO column = receiveDTO.getChart().getColumn();
|
||||
if (fields.size() != 2 || column == null) {
|
||||
DEException.throwException("当前字段不足以构建饼图");
|
||||
}
|
||||
AxisDTO axisDTO = new AxisDTO();
|
||||
axisDTO.setX(fields.get(0).getOriginName());
|
||||
axisDTO.setY(fields.get(1).getOriginName());
|
||||
AxisFieldDTO x = new AxisFieldDTO();
|
||||
AxisFieldDTO y = new AxisFieldDTO();
|
||||
if (StringUtils.equals(fields.get(0).getOriginName(), column.getValue())) {
|
||||
x.setName(column.getName());
|
||||
x.setValue(column.getValue());
|
||||
y.setName(fields.get(1).getOriginName());
|
||||
y.setValue(fields.get(1).getOriginName());
|
||||
} else if (StringUtils.equals(fields.get(1).getOriginName(), column.getValue())) {
|
||||
x.setName(fields.get(0).getOriginName());
|
||||
x.setValue(fields.get(0).getOriginName());
|
||||
y.setName(column.getName());
|
||||
y.setValue(column.getValue());
|
||||
} else {
|
||||
DEException.throwException("当前字段不足以构建饼图");
|
||||
}
|
||||
axisDTO.setX(x);
|
||||
axisDTO.setY(y);
|
||||
receiveDTO.getChart().setAxis(axisDTO);
|
||||
} else if (StringUtils.equalsIgnoreCase(receiveDTO.getChart().getType(), "table")) {
|
||||
// 将fields赋值给columns
|
||||
if (ObjectUtils.isEmpty(receiveDTO.getChart().getColumns())) {
|
||||
List<AxisFieldDTO> columns = new ArrayList<>();
|
||||
for (TableField field : fields) {
|
||||
AxisFieldDTO dto = new AxisFieldDTO();
|
||||
dto.setName(field.getOriginName());
|
||||
dto.setValue(field.getOriginName());
|
||||
columns.add(dto);
|
||||
}
|
||||
receiveDTO.getChart().setColumns(columns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,6 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class AxisDTO {
|
||||
private String x;
|
||||
private String y;
|
||||
private AxisFieldDTO x;
|
||||
private AxisFieldDTO y;
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package io.dataease.api.copilot.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author Junjun
|
||||
*/
|
||||
@Data
|
||||
public class AxisFieldDTO {
|
||||
private String name;
|
||||
private String value;
|
||||
}
|
@ -2,12 +2,16 @@ package io.dataease.api.copilot.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author Junjun
|
||||
*/
|
||||
@Data
|
||||
public class ChartDTO {
|
||||
private String type;
|
||||
private AxisDTO axis;
|
||||
private String title;
|
||||
private AxisDTO axis;
|
||||
private AxisFieldDTO column;
|
||||
private List<AxisFieldDTO> columns;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user