This commit is contained in:
wangliwen 2022-08-12 10:41:11 +08:00
parent f6509b5e19
commit 8980f61b1c
1 changed files with 41 additions and 16 deletions

View File

@ -46,6 +46,7 @@ import io.renren.modules.sys.dao.SysDeptDao;
import io.renren.modules.sys.dto.SysUserDTO;
import io.renren.modules.sys.service.SysDeptService;
import io.renren.modules.sys.service.SysUserService;
import lombok.SneakyThrows;
import okhttp3.*;
import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricProcessInstance;
@ -408,7 +409,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
if (response.isSuccessful()) {
String body = response.body().string();
JSONObject jsonObject_ = JSON.parseObject(body);
logger.info("西海岸接口{}返回:{}" , url, body);
logger.info("西海岸接口{}返回:{}", url, body);
if (jsonObject_.containsKey("data")) {
if (jsonObject_.getJSONObject("data").containsKey("list")) {
resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total"));
@ -453,30 +454,53 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
/**
* 从本库内查询
*/
@SneakyThrows
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 CopyOnWriteArrayList<>();
ForkJoinPool customThreadPool = new ForkJoinPool(CPU_NUM * 3);
switch (orderType.toUpperCase()) {
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())
).limit(pageSize).collect(Collectors.toList());
ids = customThreadPool.submit(() -> {
List<Long> temp = 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())
).limit(pageSize).collect(Collectors.toList());
return temp;
}).get();
// 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())
// ).limit(pageSize).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())
).limit(pageSize).collect(Collectors.toList());
ids = customThreadPool.submit(() -> {
List<Long> temp = 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())
).limit(pageSize).collect(Collectors.toList());
return temp;
}).get();
// 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())
// ).limit(pageSize).collect(Collectors.toList());
break;
}
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids);
@ -491,6 +515,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
return index.getTotal() == null ? 0L : index.getTotal();
})).collect(Collectors.toList()));
}
customThreadPool.shutdown();
} else { // 非总体评价排序时
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null);
}