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.dto.SysUserDTO;
import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysDeptService;
import io.renren.modules.sys.service.SysUserService; import io.renren.modules.sys.service.SysUserService;
import lombok.SneakyThrows;
import okhttp3.*; import okhttp3.*;
import org.activiti.engine.HistoryService; import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricProcessInstance; import org.activiti.engine.history.HistoricProcessInstance;
@ -408,7 +409,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
if (response.isSuccessful()) { if (response.isSuccessful()) {
String body = response.body().string(); String body = response.body().string();
JSONObject jsonObject_ = JSON.parseObject(body); JSONObject jsonObject_ = JSON.parseObject(body);
logger.info("西海岸接口{}返回:{}" , url, body); logger.info("西海岸接口{}返回:{}", url, body);
if (jsonObject_.containsKey("data")) { if (jsonObject_.containsKey("data")) {
if (jsonObject_.getJSONObject("data").containsKey("list")) { if (jsonObject_.getJSONObject("data").containsKey("list")) {
resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total"));
@ -453,14 +454,17 @@ 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) { private Page<ResourceDTO> common(Page<ResourceDTO> resultPage, List<Map> selectDTOPageSpecilTotal, ResourceDTO resourceDTO, String orderField, String orderType, Integer pageNum, Integer pageSize) {
if (resourceDTO.getInfoList().isEmpty()) { if (resourceDTO.getInfoList().isEmpty()) {
List<ResourceDTO> resourceDTOS; List<ResourceDTO> resourceDTOS;
if (orderField.equals("total")) { // 对总体评价特殊处理 if (orderField.equals("total")) { // 对总体评价特殊处理
List<Long> ids = new CopyOnWriteArrayList<>(); List<Long> ids = new CopyOnWriteArrayList<>();
ForkJoinPool customThreadPool = new ForkJoinPool(CPU_NUM * 3);
switch (orderType.toUpperCase()) { switch (orderType.toUpperCase()) {
case "DESC": // total 倒序 case "DESC": // total 倒序
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { ids = customThreadPool.submit(() -> {
List<Long> temp = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> {
Map index = (Map) x; Map index = (Map) x;
String string = (index.get("total") == null) ? "0" : index.get("total").toString(); String string = (index.get("total") == null) ? "0" : index.get("total").toString();
return Long.valueOf(string); return Long.valueOf(string);
@ -468,15 +472,35 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x -> ).reversed()).skip((long) (pageNum - 1) * pageSize).limit(pageSize).map(x ->
Long.valueOf(x.get("id").toString()) Long.valueOf(x.get("id").toString())
).limit(pageSize).collect(Collectors.toList()); ).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; break;
case "ASC": // total 升序 case "ASC": // total 升序
ids = selectDTOPageSpecilTotal.parallelStream().map(Map.class::cast).sorted(Comparator.comparing(x -> { 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(); String string = (x.get("total") == null) ? "0" : x.get("total").toString();
return Long.valueOf(string); return Long.valueOf(string);
} }
)).skip((pageNum - 1) * pageSize).limit(pageSize).map(x -> )).skip((pageNum - 1) * pageSize).limit(pageSize).map(x ->
Long.valueOf(x.get("id").toString()) Long.valueOf(x.get("id").toString())
).limit(pageSize).collect(Collectors.toList()); ).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; break;
} }
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, null, null, null, null, ids); 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(); return index.getTotal() == null ? 0L : index.getTotal();
})).collect(Collectors.toList())); })).collect(Collectors.toList()));
} }
customThreadPool.shutdown();
} else { // 非总体评价排序时 } else { // 非总体评价排序时
resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null); resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1) * pageSize, pageSize, orderField, orderType, null);
} }