调整pageWithAttrs 接口代码结构
This commit is contained in:
parent
0f980cf238
commit
e1329442cb
|
@ -374,67 +374,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
case TSINGTAO:
|
||||
case BAOTOU: { // 包头、青岛
|
||||
logger.info("包头、青岛");
|
||||
if (resourceDTO.getInfoList().isEmpty()) {
|
||||
List<ResourceDTO> resourceDTOS = null;
|
||||
if (orderField.equals("total")) { // 对总体评价特殊处理
|
||||
List<Long> ids = new ArrayList<>();
|
||||
switch (orderType) {
|
||||
case "DESC": // total 倒序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
Map index = (Map) x;
|
||||
String string = (index.get("total") == null) ? "0" : index.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
case "ASC": // total 升序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
String string = (x.get("total") == null) ? "0" : x.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
)).skip((pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
}
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids);
|
||||
if ("DESC".equals(orderType)) {
|
||||
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
|
||||
ResourceDTO index = (ResourceDTO) x;
|
||||
return index.getTotal() == null ? 0L : index.getTotal();
|
||||
}).reversed()).collect(Collectors.toList()));
|
||||
} else {
|
||||
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
|
||||
ResourceDTO index = x;
|
||||
return index.getTotal() == null ? 0L : index.getTotal();
|
||||
})).collect(Collectors.toList()));
|
||||
}
|
||||
} else {
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null);
|
||||
}
|
||||
resultPage.setRecords(resourceDTOS);
|
||||
resultPage.setTotal(resourceDao.selectDTOPageCount(resourceDTO));
|
||||
} else {
|
||||
logger.info("orderField:{} orderType:{}", orderField, orderType);
|
||||
List<ResourceDTO> resourceDTOS = resourceDao.selectWithAttrs(resourceDTO, orderField, orderType);
|
||||
int j = Math.min(pageNum * pageSize, resourceDTOS.size());
|
||||
if (resourceDTOS.isEmpty()) {
|
||||
resultPage.setRecords(null);
|
||||
resultPage.setTotal(0);
|
||||
} else {
|
||||
List<ResourceDTO> recordLists = resourceDTOS.stream()
|
||||
.skip((pageNum - 1) * pageSize).limit(pageSize)
|
||||
.map(dto_ -> {
|
||||
ResourceDTO get = this.selectWithAttrs(dto_.getId());
|
||||
BeanUtils.copyProperties(get, dto_);
|
||||
return dto_;
|
||||
}).collect(Collectors.toList());
|
||||
resultPage.setRecords(recordLists);
|
||||
resultPage.setTotal(resourceDTOS.size());
|
||||
}
|
||||
}
|
||||
resultPage = common(resultPage, selectDTOPageSpecilTotal, resourceDTO, orderField, orderType, pageNum, pageSize);
|
||||
}
|
||||
break;
|
||||
case TSINGTAO_XHA: {
|
||||
|
@ -442,7 +382,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
logger.info("西海岸基础设施");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
String url = String.format(tsingtao_xhaProperties.getCloudcam(), org.apache.commons.lang3.StringUtils.isNotEmpty(resourceDTO.getName()) ? resourceDTO.getName() : "", pageNum, pageSize);
|
||||
String url = String.format(tsingtao_xhaProperties.getCloudcam(), StringUtils.isNotBlank(resourceDTO.getName()) ? resourceDTO.getName() : "", pageNum, pageSize);
|
||||
logger.info(url);
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
|
@ -480,60 +420,9 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
} catch (Exception exception) {
|
||||
logger.error("失败", exception);
|
||||
}
|
||||
} else {
|
||||
} else { // 西海岸普通资源
|
||||
logger.info("西海岸基普通");
|
||||
if (resourceDTO.getInfoList().isEmpty()) {
|
||||
List<ResourceDTO> resourceDTOS = null;
|
||||
if (orderField.equals("total")) { // 对总体评价特殊处理
|
||||
List<Long> ids = new ArrayList<>();
|
||||
switch (orderType) {
|
||||
case "DESC": // total 倒序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
Map index = (Map) x;
|
||||
String string = (index.get("total") == null) ? "0" : index.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
).reversed()).skip((pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
case "ASC": // total 升序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
String string = (x.get("total") == null) ? "0" : x.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
)).skip((pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
}
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids);
|
||||
} else {
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null);
|
||||
}
|
||||
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
|
||||
ResourceDTO index = (ResourceDTO) x;
|
||||
return index.getTotal() == null ? 0L : index.getTotal();
|
||||
}).reversed()).collect(Collectors.toList()));
|
||||
resultPage.setTotal(resourceDao.selectDTOPageCount(resourceDTO));
|
||||
} else {
|
||||
List<ResourceDTO> resourceDTOS = resourceDao.selectWithAttrs(resourceDTO, orderField, orderType);
|
||||
int j = Math.min(pageNum * pageSize, resourceDTOS.size());
|
||||
if (resourceDTOS.isEmpty()) {
|
||||
resultPage.setRecords(null);
|
||||
resultPage.setTotal(0);
|
||||
} else {
|
||||
List<ResourceDTO> recordLists = resourceDTOS.stream()
|
||||
.skip((pageNum - 1) * pageSize).limit(pageSize)
|
||||
.map(dto_ -> {
|
||||
ResourceDTO get = this.selectWithAttrs(dto_.getId());
|
||||
BeanUtils.copyProperties(get, dto_);
|
||||
return dto_;
|
||||
}).collect(Collectors.toList());
|
||||
resultPage.setRecords(recordLists);
|
||||
resultPage.setTotal(resourceDTOS.size());
|
||||
}
|
||||
}
|
||||
resultPage = common(resultPage, selectDTOPageSpecilTotal, resourceDTO, orderField, orderType, pageNum, pageSize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -541,10 +430,84 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
return resultPage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从本库内查询
|
||||
*
|
||||
* @param resultPage
|
||||
* @return
|
||||
*/
|
||||
private Page<ResourceDTO> common(Page<ResourceDTO> resultPage, List<Map> selectDTOPageSpecilTotal, ResourceDTO resourceDTO, String orderField, String orderType, Integer pageNum, Integer pageSize) {
|
||||
if (resourceDTO.getInfoList().isEmpty()) {
|
||||
List<ResourceDTO> resourceDTOS;
|
||||
if (orderField.equals("total")) { // 对总体评价特殊处理
|
||||
List<Long> ids = new ArrayList<>();
|
||||
switch (orderType) {
|
||||
case "DESC": // total 倒序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
Map index = (Map) x;
|
||||
String string = (index.get("total") == null) ? "0" : index.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
case "ASC": // total 升序
|
||||
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
|
||||
String string = (x.get("total") == null) ? "0" : x.get("total").toString();
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
)).skip((pageNum - 1) * pageSize).limit(pageSize).map(x ->
|
||||
Long.valueOf(x.get("id").toString())
|
||||
).collect(Collectors.toList());
|
||||
break;
|
||||
}
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids);
|
||||
if ("DESC".equals(orderType)) {
|
||||
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
|
||||
ResourceDTO index = (ResourceDTO) x;
|
||||
return index.getTotal() == null ? 0L : index.getTotal();
|
||||
}).reversed()).collect(Collectors.toList()));
|
||||
} else {
|
||||
resultPage.setRecords(resourceDTOS.stream().sorted(Comparator.comparing(x -> {
|
||||
ResourceDTO index = x;
|
||||
return index.getTotal() == null ? 0L : index.getTotal();
|
||||
})).collect(Collectors.toList()));
|
||||
}
|
||||
} else { // 非总体评价排序时
|
||||
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null);
|
||||
}
|
||||
resultPage.setRecords(resourceDTOS);
|
||||
resultPage.setTotal(resourceDao.selectDTOPageCount(resourceDTO));
|
||||
} else {
|
||||
logger.info("orderField:{} orderType:{}", orderField, orderType);
|
||||
List<ResourceDTO> resourceDTOS = resourceDao.selectWithAttrs(resourceDTO, orderField, orderType);
|
||||
int j = Math.min(pageNum * pageSize, resourceDTOS.size());
|
||||
if (resourceDTOS.isEmpty()) {
|
||||
resultPage.setRecords(null);
|
||||
resultPage.setTotal(0);
|
||||
} else {
|
||||
List<ResourceDTO> recordLists = resourceDTOS.stream()
|
||||
.skip((pageNum - 1) * pageSize).limit(pageSize)
|
||||
.map(dto_ -> {
|
||||
ResourceDTO get = this.selectWithAttrs(dto_.getId());
|
||||
BeanUtils.copyProperties(get, dto_);
|
||||
return dto_;
|
||||
}).collect(Collectors.toList());
|
||||
resultPage.setRecords(recordLists);
|
||||
resultPage.setTotal(resourceDTOS.size());
|
||||
}
|
||||
}
|
||||
return resultPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AttrEntity> selectAttrsByResourceId(Long resourceId) {
|
||||
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("data_resource_id", resourceId).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).orderByDesc("attr_type");
|
||||
wrapper.eq("data_resource_id", resourceId)
|
||||
.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag())
|
||||
.orderByDesc("attr_type");
|
||||
return attrDao.selectList(wrapper);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue