From a4500ca2bb49a4f35217d7ac1e121cc9029063ec Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 23 Jun 2022 09:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A5=BF=E6=B5=B7=E5=B2=B8=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ResourceServiceImpl.java | 248 ++++++++++-------- 1 file changed, 139 insertions(+), 109 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 16689f53..369c51b9 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -145,8 +145,7 @@ public class ResourceServiceImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); - wrapper.eq("data_resource_id", id) - .eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()); + wrapper.eq("data_resource_id", id).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()); List attrEntities = attrDao.selectList(wrapper); resourceDTO.setInfoList(attrEntities == null ? new ArrayList<>() : attrEntities); // npe? return resourceDTO; @@ -257,88 +255,84 @@ public class ResourceServiceImpl extends CrudServiceImpl { // 云脑专网 - OkHttpClient client = new OkHttpClient(); - String url = String.format(tsingtao_xhaProperties.getCloudcam(), resourceDTO.getName(), pageNum, pageSize); - logger.info(url); - Request request = new Request.Builder().url(url).build(); - try (Response response = client.newCall(request).execute()) { - if (response.isSuccessful()) { - JSONObject jsonObject_ = JSON.parseObject(response.body().string()); - if (jsonObject_.containsKey("data")) { - if (jsonObject_.getJSONObject("data").containsKey("list")) { - resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); - resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)) - .map(index -> { - ResourceDTO resourceDTO1 = new ResourceDTO(); - resourceDTO1.setId(Long.valueOf(index.getString("id"))); - resourceDTO1.setDelFlag(index.getIntValue("delFlag")); - resourceDTO1.setLink(index.getString("cameraIndexCode")); - resourceDTO1.setName(index.getString("name")); - resourceDTO1.setType("基础设施"); - try { - resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); - } catch (ParseException e) { - logger.error("时间异常"); - resourceDTO1.setCreateDate(new Date()); - } - return resourceDTO1; - }).collect(Collectors.toList())); - } else { - resultPage.setRecords(null); - resultPage.setTotal(0); + CompletableFuture cloud = CompletableFuture.runAsync(() -> { // 云脑专网 + OkHttpClient client = new OkHttpClient(); + String url = String.format(tsingtao_xhaProperties.getCloudcam(), resourceDTO.getName(), pageNum, pageSize); + logger.info(url); + Request request = new Request.Builder().url(url).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject_ = JSON.parseObject(response.body().string()); + if (jsonObject_.containsKey("data")) { + if (jsonObject_.getJSONObject("data").containsKey("list")) { + resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); + resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)).map(index -> { + ResourceDTO resourceDTO1 = new ResourceDTO(); + resourceDTO1.setId(Long.valueOf(index.getString("id"))); + resourceDTO1.setDelFlag(index.getIntValue("delFlag")); + resourceDTO1.setLink(index.getString("cameraIndexCode")); + resourceDTO1.setName(index.getString("name")); + resourceDTO1.setType("基础设施"); + try { + resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); + } catch (ParseException e) { + logger.error("时间异常"); + resourceDTO1.setCreateDate(new Date()); } - - } + return resourceDTO1; + }).collect(Collectors.toList())); } else { - logger.error("获取失败"); + resultPage.setRecords(null); + resultPage.setTotal(0); } - } catch (Exception exception) { - logger.error("失败", exception); + } - }); - CompletableFuture local = - CompletableFuture.runAsync(() -> { // 金宏网 - OkHttpClient client = new OkHttpClient(); - String url = String.format(tsingtao_xhaProperties.getLocalcam(), resourceDTO.getName(), pageNum, pageSize); - logger.info(url); - Request request = new Request.Builder().url(url).build(); - try (Response response = client.newCall(request).execute()) { - if (response.isSuccessful()) { - JSONObject jsonObject_ = JSON.parseObject(response.body().string()); - if (jsonObject_.containsKey("data")) { - if (jsonObject_.getJSONObject("data").containsKey("list")) { - resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); - resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)) - .map(index -> { - ResourceDTO resourceDTO1 = new ResourceDTO(); - resourceDTO1.setId(Long.valueOf(index.getString("id"))); - resourceDTO1.setDelFlag(index.getIntValue("delFlag")); - resourceDTO1.setLink(index.getString("cameraIndexCode")); - resourceDTO1.setName(index.getString("name")); - resourceDTO1.setType("基础设施"); - try { - resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); - } catch (ParseException e) { - logger.error("时间异常"); - resourceDTO1.setCreateDate(new Date()); - } - return resourceDTO1; - }).collect(Collectors.toList())); - } else { - resultPage.setRecords(null); - resultPage.setTotal(0); + } else { + logger.error("获取失败"); + } + } catch (Exception exception) { + logger.error("失败", exception); + } + }); + CompletableFuture local = CompletableFuture.runAsync(() -> { // 金宏网 + OkHttpClient client = new OkHttpClient(); + String url = String.format(tsingtao_xhaProperties.getLocalcam(), resourceDTO.getName(), pageNum, pageSize); + logger.info(url); + Request request = new Request.Builder().url(url).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject_ = JSON.parseObject(response.body().string()); + if (jsonObject_.containsKey("data")) { + if (jsonObject_.getJSONObject("data").containsKey("list")) { + resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); + resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)).map(index -> { + ResourceDTO resourceDTO1 = new ResourceDTO(); + resourceDTO1.setId(Long.valueOf(index.getString("id"))); + resourceDTO1.setDelFlag(index.getIntValue("delFlag")); + resourceDTO1.setLink(index.getString("cameraIndexCode")); + resourceDTO1.setName(index.getString("name")); + resourceDTO1.setType("基础设施"); + try { + resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); + } catch (ParseException e) { + logger.error("时间异常"); + resourceDTO1.setCreateDate(new Date()); } - - } + return resourceDTO1; + }).collect(Collectors.toList())); } else { - logger.error("获取失败"); + resultPage.setRecords(null); + resultPage.setTotal(0); } - } catch (Exception exception) { - logger.error("失败", exception); + } - }); + } else { + logger.error("获取失败"); + } + } catch (Exception exception) { + logger.error("失败", exception); + } + }); CompletableFuture.allOf(cloud, local); } else { logger.info("西海岸基普通"); @@ -371,16 +365,70 @@ public class ResourceServiceImpl extends CrudServiceImpl selectAttrsByResourceId(Long resourceId) { QueryWrapper 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); } @Override public Object selectTotal() { HashMap resultMap = new HashMap<>(); - resultMap.put("total", resourceDao.selectTypeCount(null)); + List re = resourceDao.selectTypeCount(null); + switch (Constant.ProjectPlace.getByFlag(projectPlace)) { + case TSINGTAO_XHA: { // 青岛西海岸 + CompletableFuture allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目 + List result_ = new CopyOnWriteArrayList<>(); + CompletableFuture cloud = + CompletableFuture.runAsync(() -> { // 云脑专网 + OkHttpClient client = new OkHttpClient(); + String url = String.format(tsingtao_xhaProperties.getCloudcam(), "", 1, 10); + logger.info(url); + Request request = new Request.Builder().url(url).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject = JSON.parseObject(response.body().string()); + if (jsonObject.containsKey("data")) { + result_.add(jsonObject.getJSONObject("data").getLongValue("total")); + } + } else { + logger.error("青岛西海岸获取失败"); + } + } catch (Exception exception) { + logger.error("青岛西海岸失败", exception); + } + }); + CompletableFuture local = + CompletableFuture.runAsync(() -> { // 金宏网 + OkHttpClient client = new OkHttpClient(); + String url = String.format(tsingtao_xhaProperties.getLocalcam(), "", 1, 10); + logger.info(url); + Request request = new Request.Builder().url(url).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject = JSON.parseObject(response.body().string()); + if (jsonObject.containsKey("data")) { + result_.add(jsonObject.getJSONObject("data").getLongValue("total")); + } + } else { + logger.error("青岛西海岸获取失败"); + } + } catch (Exception exception) { + logger.error("青岛西海岸失败", exception); + } + }); + CompletableFuture.allOf(cloud, local); + return result_.stream().filter(index -> index != null).findAny().orElse(0l); + }).thenAccept(sum -> { + re.add(new HashMap() { + { + put("amount", sum); + put("type", "视频资源数量"); + } + }); + }); + allAmount.join(); + } + } + resultMap.put("total", re); return resultMap; } @@ -389,9 +437,7 @@ public class ResourceServiceImpl extends CrudServiceImpl page = new Page<>(jsonObject.getIntValue("pageNum"), jsonObject.getIntValue("pageSize")); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")) - .eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()) - .orderByDesc("create_date"); + queryWrapper.eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).orderByDesc("create_date"); return resourceDao.selectPage(page, queryWrapper); } @@ -403,8 +449,7 @@ public class ResourceServiceImpl extends CrudServiceImpl resourceDTOS = resourceDao.selectMostPopular(selectMap); page.setRecords(resourceDTOS); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()) - .eq("type", jsonObject.getString("type")); + queryWrapper.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).eq("type", jsonObject.getString("type")); Integer count = resourceDao.selectCount(queryWrapper); page.setTotal(count); return page; @@ -417,9 +462,7 @@ public class ResourceServiceImpl extends CrudServiceImpl updateWrapper = new UpdateWrapper<>(); - updateWrapper.lambda() - .eq(ResourceEntity::getId, resourceEntity.getId()) - .eq(ResourceEntity::getDelFlag, ResourceEntityDelFlag.NORMAL.getFlag()); + updateWrapper.lambda().eq(ResourceEntity::getId, resourceEntity.getId()).eq(ResourceEntity::getDelFlag, ResourceEntityDelFlag.NORMAL.getFlag()); resourceDao.update(entity, updateWrapper); ResourceBrowseEntity browseEntity = new ResourceBrowseEntity(); browseEntity.setResourceId(id); @@ -487,16 +530,14 @@ public class ResourceServiceImpl extends CrudServiceImpl resourceMap = new HashMap<>(); resourceMap.put("type", "全部能力目录"); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("del_flag", 0) - .eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")); + queryWrapper.eq("del_flag", 0).eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")); resourceMap.put("total", resourceDao.selectCount(queryWrapper)); resultList.add(resourceMap); List> typeMapList = resourceDao.selectGroupByDeptId(jsonObject.getString("type")); if (typeMapList.isEmpty()) { return resultList; } - Map>> listMap = typeMapList.stream() - .collect(Collectors.groupingBy(m -> m.get("type").toString())); + Map>> listMap = typeMapList.stream().collect(Collectors.groupingBy(m -> m.get("type").toString())); //区级要根据行政区划多加一层结构 listMap.entrySet().stream().filter(index -> !"区级".equals(index.getKey())).forEach(item -> { HashMap map = new HashMap<>(); @@ -510,8 +551,7 @@ public class ResourceServiceImpl extends CrudServiceImpl>> areaList = Optional.ofNullable(listMap.get("区级")); - Optional>>> areaTypeList = Optional.ofNullable(areaList.orElse(new ArrayList<>()).stream() - .collect(Collectors.groupingBy(m -> m.get("districtName").toString()))); + Optional>>> areaTypeList = Optional.ofNullable(areaList.orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(m -> m.get("districtName").toString()))); HashMap areaMap = new HashMap<>(); areaMap.put("type", "区级"); Integer integer = resourceDao.selectTypeCountByDept("区级", jsonObject.getString("type")); @@ -707,9 +747,7 @@ public class ResourceServiceImpl extends CrudServiceImpl knowledgeUUID = - jdbcTemplate.queryForList("SELECT note1 FROM tb_data_resource WHERE type ='知识库' AND note1 IS NOT NULL FOR UPDATE;", String.class) - .stream().distinct().collect(Collectors.toList()); + final List knowledgeUUID = jdbcTemplate.queryForList("SELECT note1 FROM tb_data_resource WHERE type ='知识库' AND note1 IS NOT NULL FOR UPDATE;", String.class).stream().distinct().collect(Collectors.toList()); final int pageSize = 100; final OkHttpClient client = new OkHttpClient(); Arrays.stream(catalogIds).map(index -> { @@ -733,19 +771,11 @@ public class ResourceServiceImpl extends CrudServiceImpl