@ApiOperation("导入盒须图数据4")
@PostMapping("/importData4")
@Transactional(rollbackFor = Exception.class)
public AjaxResult importData4(@RequestBody ChartDateTto chartDateTto) throws Exception {
List<List<String>> getdata = extractDataFromListNullString(chartDateTto.getDataList());
// 获取第一行数据
List<String> firstRow = getdata.get(0);
// 获取第一行第二列的文字,前提是该文字不为 "0"
String secondColumnText = firstRow.get(1);
int columnsBetween = 0;
if (!"0".equals(secondColumnText)) {
// 查找下一个非空且非 "0" 的单元格文字并计算列数
int secondColumnIndex = 1; // 第二列的索引为 1
int nextNonEmptyIndex = -1;
for (int i = secondColumnIndex + 1; i < firstRow.size(); i++) {
String currentCell = firstRow.get(i);
if (currentCell != null && !currentCell.isEmpty() && !"0".equals(currentCell)) {
nextNonEmptyIndex = i;
break;
}
}
if (nextNonEmptyIndex != -1) {
columnsBetween = nextNonEmptyIndex - secondColumnIndex; // 计算间隔列数
System.out.println("第一行第二列的文字: " + secondColumnText);
System.out.println("下一个非空且非 '0' 的文字在列索引: " + nextNonEmptyIndex);
System.out.println("它们之间的列数是: " + columnsBetween);
} else {
System.out.println("在第一行没有找到下一个非空且非 '0' 的单元格文字。");
}
} else {
System.out.println("第二列的值为 0,跳过该列。");
}
// 移除前两行数据
getdata.remove(0); // Remove first row
getdata.remove(0); // Remove second row
// 删除每一行的第一列数据
for (List<String> row : getdata) {
if (!row.isEmpty()) {
row.remove(0); // 删除每一行的第一列数据
}
}
// 创建一个列表用于存储每列的数据
List<List<String>> transposedData = new ArrayList<>();
for (int col = 0; col < getdata.get(0).size(); col++) {
List<String> columnData = new ArrayList<>();
for (List<String> row : getdata) {
if (col < row.size()) {
columnData.add(row.get(col));
}
}
transposedData.add(columnData);
}
int size = transposedData.size();
System.out.println("我是数据的组数: " + size);
// 计算 size 除以 columnsBetween 的值
if (columnsBetween > 0) {
int divisionResult = size / columnsBetween;
System.out.println("size 除以 columnsBetween 的结果: " + divisionResult);
} else {
System.out.println("columnsBetween 的值为 0,无法进行除法操作。");
}
// 打印转置后的数据
for (int groupIndex = 0; groupIndex < transposedData.size(); groupIndex++) {
System.out.print("列 " + (groupIndex + 1) + " 数据: " + transposedData.get(groupIndex) + " ");
System.out.println(); // 每列数据换行
}
// 根据列间隔将数据分组为每3列
List<List<List<String>>> groupedData = new ArrayList<>();
int columnsPerGroup = 3;
for (int i = 0; i < transposedData.size(); i += columnsPerGroup) {
List<List<String>> group = new ArrayList<>();
for (int j = 0; j < columnsPerGroup; j++) {
if (i + j < transposedData.size()) {
group.add(transposedData.get(i + j));
}
}
groupedData.add(group);
}
System.out.println("----------------------------以上是入参的数据-----------------------------------------");
String chartValue = chartDateTto.getChartValue();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(chartValue);
JsonNode dataset = jsonNode.path("dataset");
return null
12-31
167
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-19
101
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
440
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-15
392
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-18
1142
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)