Commit 00840374 authored by zhangsen's avatar zhangsen

风电、光伏 健康指数页面 排序问题处理,兼容平台组件问题

parent a7f257a3
package com.yeejoin.amos.boot.module.jxiop.biz.controller; package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.FanHealthIndexDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.FanHealthIndexDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.FullViewRecallDataDTO; import com.yeejoin.amos.boot.module.jxiop.biz.dto.FullViewRecallDataDTO;
...@@ -82,15 +84,31 @@ public class TdInfoQueryController { ...@@ -82,15 +84,31 @@ public class TdInfoQueryController {
} }
Page<FanHealthIndex> resultPage = new Page<>(dto.getCurrent(), dto.getSize()); Page<FanHealthIndex> resultPage = new Page<>(dto.getCurrent(), dto.getSize());
dto.setCurrent((dto.getCurrent() - 1) * dto.getSize()); dto.setCurrent((dto.getCurrent() - 1) * dto.getSize());
if (CharSequenceUtil.isNotEmpty(dto.getSortsString())) {
ObjectMapper objectMapper = new ObjectMapper();
try {
List<Map<String, String>> list = objectMapper.readValue(dto.getSortsString(), new TypeReference<List<Map<String, String>>>(){});
dto.setSorts(list);
} catch (Exception e) {
e.printStackTrace();
}
}
List<Map<String, String>> orderWeight = dto.getSorts().stream().sorted(Comparator.comparing(t -> Integer.parseInt(t.get("orderWeight")))).collect(Collectors.toList()); List<Map<String, String>> orderWeight = dto.getSorts().stream().sorted(Comparator.comparing(t -> Integer.parseInt(t.get("orderWeight")))).collect(Collectors.toList());
List<String> orderByList = new ArrayList<>(); List<String> orderByList = new ArrayList<>();
for (Map<String, String> map : orderWeight) { for (Map<String, String> map : orderWeight) {
String replace = map.get("order").replace("end", ""); String replace = map.get("order").replace("end", "");
String columnOrder = map.get("columnKey") + " " + replace; String columnOrder = convert(map.get("columnKey")) + " " + replace;
orderByList.add(columnOrder); orderByList.add(columnOrder);
} }
String join = String.join(",", orderByList); String join = String.join(",", orderByList);
dto.setOrderColumns(join); dto.setOrderColumns(join);
if (CharSequenceUtil.isNotEmpty(dto.getSortOne())) {
String[] split = dto.getSortOne().split(",");
String replace = split[1].replace("end", "");
String orderColumn = convert(split[0]) + " " + replace;
dto.setSortOne(orderColumn);
}
List<FanHealthIndex> fanHealthIndexIPage = fanHealthIndexMapper.getInfoByPage(dto); List<FanHealthIndex> fanHealthIndexIPage = fanHealthIndexMapper.getInfoByPage(dto);
Integer infoByPageTotal = fanHealthIndexMapper.getInfoByPageTotal(dto); Integer infoByPageTotal = fanHealthIndexMapper.getInfoByPageTotal(dto);
resultPage.setRecords(fanHealthIndexIPage); resultPage.setRecords(fanHealthIndexIPage);
...@@ -98,6 +116,19 @@ public class TdInfoQueryController { ...@@ -98,6 +116,19 @@ public class TdInfoQueryController {
return ResponseHelper.buildResponse(resultPage); return ResponseHelper.buildResponse(resultPage);
} }
public static String convert(String camelCase) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < camelCase.length(); i++) {
char currentChar = camelCase.charAt(i);
if (Character.isUpperCase(currentChar)) {
result.append("_").append(Character.toLowerCase(currentChar));
} else {
result.append(currentChar);
}
}
return result.toString();
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/getPvHealthIndexInfo") @PostMapping(value = "/getPvHealthIndexInfo")
@ApiOperation(httpMethod = "POST", value = "分页查询健康指数信息 - 光伏", notes = "分页查询健康指数信息 - 光伏") @ApiOperation(httpMethod = "POST", value = "分页查询健康指数信息 - 光伏", notes = "分页查询健康指数信息 - 光伏")
...@@ -114,16 +145,30 @@ public class TdInfoQueryController { ...@@ -114,16 +145,30 @@ public class TdInfoQueryController {
String endDateString = DateUtils.dateFormat(DateUtils.dateAddHours(endDateDate, -8), DATE_TIME_PATTERN); String endDateString = DateUtils.dateFormat(DateUtils.dateAddHours(endDateDate, -8), DATE_TIME_PATTERN);
dto.setEndDate(endDateString); dto.setEndDate(endDateString);
} }
if (CharSequenceUtil.isNotEmpty(dto.getSortsString())) {
ObjectMapper objectMapper = new ObjectMapper();
try {
List<Map<String, String>> list = objectMapper.readValue(dto.getSortsString(), new TypeReference<List<Map<String, String>>>(){});
dto.setSorts(list);
} catch (Exception e) {
e.printStackTrace();
}
}
Page<PvHealthIndex> resultPage = new Page<>(dto.getCurrent(), dto.getSize()); Page<PvHealthIndex> resultPage = new Page<>(dto.getCurrent(), dto.getSize());
dto.setCurrent((dto.getCurrent() - 1) * dto.getSize()); dto.setCurrent((dto.getCurrent() - 1) * dto.getSize());
List<Map<String, String>> orderWeight = dto.getSorts().stream().sorted(Comparator.comparing(t -> Integer.parseInt(t.get("orderWeight")))).collect(Collectors.toList()); List<Map<String, String>> orderWeight = dto.getSorts().stream().sorted(Comparator.comparing(t -> Integer.parseInt(t.get("orderWeight")))).collect(Collectors.toList());
List<String> orderByList = new ArrayList<>(); List<String> orderByList = new ArrayList<>();
for (Map<String, String> map : orderWeight) { for (Map<String, String> map : orderWeight) {
String replace = map.get("order").replace("end", ""); String replace = map.get("order").replace("end", "");
String columnOrder = map.get("columnKey") + " " + replace; String columnOrder = convert(map.get("columnKey")) + " " + replace;
orderByList.add(columnOrder); orderByList.add(columnOrder);
} }
if (CharSequenceUtil.isNotEmpty(dto.getSortOne())) {
String[] split = dto.getSortOne().split(",");
String replace = split[1].replace("end", "");
String orderColumn = convert(split[0]) + " " + replace;
dto.setSortOne(orderColumn);
}
String join = String.join(",", orderByList); String join = String.join(",", orderByList);
dto.setOrderColumns(join); dto.setOrderColumns(join);
List<PvHealthIndex> pvHealthIndexIPage = pvHealthIndexMapper.getInfoByPage(dto); List<PvHealthIndex> pvHealthIndexIPage = pvHealthIndexMapper.getInfoByPage(dto);
......
...@@ -41,4 +41,6 @@ public class FanHealthIndexDto implements Serializable { ...@@ -41,4 +41,6 @@ public class FanHealthIndexDto implements Serializable {
private String warningStatus; private String warningStatus;
private String disposotionState; private String disposotionState;
private String subarray; private String subarray;
private String sortOne;
private String sortsString;
} }
...@@ -43,5 +43,7 @@ public class PvHealthIndexDto { ...@@ -43,5 +43,7 @@ public class PvHealthIndexDto {
private Integer current; private Integer current;
private Integer size; private Integer size;
private String orderColumns; private String orderColumns;
private String sortOne;
private String sortsString;
} }
...@@ -174,6 +174,9 @@ ...@@ -174,6 +174,9 @@
<if test="dto.orderColumns != null and dto.orderColumns != ''"> <if test="dto.orderColumns != null and dto.orderColumns != ''">
order by ${dto.orderColumns} order by ${dto.orderColumns}
</if> </if>
<if test="(dto.orderColumns == null or dto.orderColumns == '') and dto.sortOne != null and dto.sortOne != ''">
order by ${dto.sortOne}
</if>
limit #{dto.current}, #{dto.size} limit #{dto.current}, #{dto.size}
</select> </select>
......
...@@ -205,6 +205,9 @@ ...@@ -205,6 +205,9 @@
<if test="dto.orderColumns != null and dto.orderColumns != ''"> <if test="dto.orderColumns != null and dto.orderColumns != ''">
order by ${dto.orderColumns} order by ${dto.orderColumns}
</if> </if>
<if test="(dto.orderColumns == null or dto.orderColumns == '') and dto.sortOne != null and dto.sortOne != ''">
order by ${dto.sortOne}
</if>
limit #{dto.current}, #{dto.size} limit #{dto.current}, #{dto.size}
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment