@PostMapping("/v2/importData/demo")
@Transactional(rollbackFor = Exception.class)
public AjaxResult cornerLoopPhoto(@RequestBody ChartDateTto chartDateTto) throws Exception {
String chartValue = chartDateTto.getChartValue();
List<List<String>> lists = extractDataFromList(chartDateTto.getDataList());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode chartValueJson = objectMapper.readTree(chartValue);
ArrayNode dataset = (ArrayNode) chartValueJson.path("dataset");
for (JsonNode node : dataset) {
if (node.has("source")) {
((com.fasterxml.jackson.databind.node.ObjectNode) node).set("source", objectMapper.valueToTree(lists));
break;
}
}
if (!lists.isEmpty() && !lists.get(0).isEmpty()) {
lists.get(0).remove(0);
}
ArrayNode seriesArray = (ArrayNode) chartValueJson.path("series");
if (seriesArray.size() > 1) {
while (seriesArray.size() > 1) {
seriesArray.remove(1);
}
}
int firstObjectRemainingElements = lists.isEmpty() ? 0 : lists.get(0).size();
JsonNode firstSeriesObject = seriesArray.get(0);
for (int i = 1; i < firstObjectRemainingElements; i++) {
seriesArray.add(firstSeriesObject.deepCopy());
}
for (int i = 0; i < firstObjectRemainingElements; i++) {
((ObjectNode) seriesArray.get(i)).put("name", lists.get(0).get(i));
}
JsonNode legend = chartValueJson.path("legend");
ChartDataUtils.updateLegendData(legend, lists);
String updatedChartValue = chartValueJson.toString();
ArrayList<ChartSmartVo> newList = new ArrayList<>();
ChartConfigs configs = chartConfigsService.getById(chartDateTto.getConfigId());
ChartSmartVo chartSmartVo = new ChartSmartVo();
chartSmartVo.setConfigId(configs.getId());
chartSmartVo.setConfigName(configs.getConfigName());
chartSmartVo.setConfigValue(updatedChartValue);
chartSmartVo.setChartTypeId(configs.getChartTypeId());
newList.add(chartSmartVo);
System.out.println(updatedChartValue);
return AjaxResult.success(newList);
}
String chartValue = chartDateTto.getChartValue();
List<List<String>> lists = extractDataFromList(chartDateTto.getDataList());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode chartValueJson = objectMapper.readTree(chartValue);
ArrayNode dataset = (ArrayNode) chartValueJson.path("dataset");
for (JsonNode node : dataset) {
if (node.has("source")) {
((com.fasterxml.jackson.databind.node.ObjectNode) node).set("source", objectMapper.valueToTree(lists));
break;
}
}
if (!lists.isEmpty() && !lists.get(0).isEmpty()) {
lists.get(0).remove(0);
}
ArrayNode seriesArray = (ArrayNode) chartValueJson.path("series");
if (seriesArray.size() > 1) {
while (seriesArray.size() > 1) {
seriesArray.remove(1);
}
}
int firstObjectRemainingElements = lists.isEmpty() ? 0 : lists.get(0).size();
JsonNode firstSeriesObject = seriesArray.get(0);
for (int i = 1; i < firstObjectRemainingElements; i++) {
seriesArray.add(firstSeriesObject.deepCopy());
}
for (int i = 0; i < firstObjectRemainingElements; i++) {
((ObjectNode) seriesArray.get(i)).put("name", lists.get(0).get(i));
}
JsonNode legend = chartValueJson.path("legend");
ChartDataUtils.updateLegendData(legend, lists);
String updatedChartValue = chartValueJson.toString();
ArrayList<ChartSmartVo> newList = new ArrayList<>();
ChartConfigs configs = chartConfigsService.getById(chartDateTto.getConfigId());
ChartSmartVo chartSmartVo = new ChartSmartVo();
chartSmartVo.setConfigId(configs.getId());
chartSmartVo.setConfigName(configs.getConfigName());
chartSmartVo.setConfigValue(updatedChartValue);
chartSmartVo.setChartTypeId(configs.getChartTypeId());
newList.add(chartSmartVo);
System.out.println(updatedChartValue);
return AjaxResult.success(newList);