diff --git a/core/core-backend/src/main/java/io/dataease/copilot/manage/CopilotManage.java b/core/core-backend/src/main/java/io/dataease/copilot/manage/CopilotManage.java index dbb96c0c0c..9f5c846725 100644 --- a/core/core-backend/src/main/java/io/dataease/copilot/manage/CopilotManage.java +++ b/core/core-backend/src/main/java/io/dataease/copilot/manage/CopilotManage.java @@ -292,13 +292,41 @@ public class CopilotManage { public void rebuildChart(ReceiveDTO receiveDTO, List 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 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); + } } } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisDTO.java b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisDTO.java index 208914af9e..5c1ae4ec87 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisDTO.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisDTO.java @@ -7,6 +7,6 @@ import lombok.Data; */ @Data public class AxisDTO { - private String x; - private String y; + private AxisFieldDTO x; + private AxisFieldDTO y; } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisFieldDTO.java b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisFieldDTO.java new file mode 100644 index 0000000000..efbef9885c --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/AxisFieldDTO.java @@ -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; +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/ChartDTO.java b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/ChartDTO.java index acf5cb85f5..18e950ead0 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/ChartDTO.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/copilot/dto/ChartDTO.java @@ -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 columns; }