西海岸特殊处理

This commit is contained in:
wangliwen 2022-06-23 09:25:29 +08:00
parent ecdd006c4e
commit a4500ca2bb
1 changed files with 139 additions and 109 deletions

View File

@ -145,8 +145,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
wrapper.in(true, "del_flag", 0, 5); wrapper.in(true, "del_flag", 0, 5);
} }
} }
wrapper.orderByAsc("del_flag") wrapper.orderByAsc("del_flag").orderByDesc("create_date");
.orderByDesc("create_date");
return wrapper; return wrapper;
} }
@ -211,8 +210,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
return null; return null;
} }
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>(); QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
wrapper.eq("data_resource_id", id) wrapper.eq("data_resource_id", id).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag());
.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag());
List<AttrEntity> attrEntities = attrDao.selectList(wrapper); List<AttrEntity> attrEntities = attrDao.selectList(wrapper);
resourceDTO.setInfoList(attrEntities == null ? new ArrayList<>() : attrEntities); // npe? resourceDTO.setInfoList(attrEntities == null ? new ArrayList<>() : attrEntities); // npe?
return resourceDTO; return resourceDTO;
@ -257,88 +255,84 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
if ("基础设施".equals(resourceDTO.getType())) { // 基础设施 if ("基础设施".equals(resourceDTO.getType())) { // 基础设施
logger.info("西海岸基础设施"); logger.info("西海岸基础设施");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
CompletableFuture cloud = CompletableFuture cloud = CompletableFuture.runAsync(() -> { // 云脑专网
CompletableFuture.runAsync(() -> { // 云脑专网 OkHttpClient client = new OkHttpClient();
OkHttpClient client = new OkHttpClient(); String url = String.format(tsingtao_xhaProperties.getCloudcam(), resourceDTO.getName(), pageNum, pageSize);
String url = String.format(tsingtao_xhaProperties.getCloudcam(), resourceDTO.getName(), pageNum, pageSize); logger.info(url);
logger.info(url); Request request = new Request.Builder().url(url).build();
Request request = new Request.Builder().url(url).build(); try (Response response = client.newCall(request).execute()) {
try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) {
if (response.isSuccessful()) { JSONObject jsonObject_ = JSON.parseObject(response.body().string());
JSONObject jsonObject_ = JSON.parseObject(response.body().string()); 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")); resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)).map(index -> {
resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)) ResourceDTO resourceDTO1 = new ResourceDTO();
.map(index -> { resourceDTO1.setId(Long.valueOf(index.getString("id")));
ResourceDTO resourceDTO1 = new ResourceDTO(); resourceDTO1.setDelFlag(index.getIntValue("delFlag"));
resourceDTO1.setId(Long.valueOf(index.getString("id"))); resourceDTO1.setLink(index.getString("cameraIndexCode"));
resourceDTO1.setDelFlag(index.getIntValue("delFlag")); resourceDTO1.setName(index.getString("name"));
resourceDTO1.setLink(index.getString("cameraIndexCode")); resourceDTO1.setType("基础设施");
resourceDTO1.setName(index.getString("name")); try {
resourceDTO1.setType("基础设施"); resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime")));
try { } catch (ParseException e) {
resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); logger.error("时间异常");
} catch (ParseException e) { resourceDTO1.setCreateDate(new Date());
logger.error("时间异常");
resourceDTO1.setCreateDate(new Date());
}
return resourceDTO1;
}).collect(Collectors.toList()));
} else {
resultPage.setRecords(null);
resultPage.setTotal(0);
} }
return resourceDTO1;
} }).collect(Collectors.toList()));
} else { } else {
logger.error("获取失败"); resultPage.setRecords(null);
resultPage.setTotal(0);
} }
} catch (Exception exception) {
logger.error("失败", exception);
} }
}); } else {
CompletableFuture local = logger.error("获取失败");
CompletableFuture.runAsync(() -> { // 金宏网 }
OkHttpClient client = new OkHttpClient(); } catch (Exception exception) {
String url = String.format(tsingtao_xhaProperties.getLocalcam(), resourceDTO.getName(), pageNum, pageSize); logger.error("失败", exception);
logger.info(url); }
Request request = new Request.Builder().url(url).build(); });
try (Response response = client.newCall(request).execute()) { CompletableFuture local = CompletableFuture.runAsync(() -> { // 金宏网
if (response.isSuccessful()) { OkHttpClient client = new OkHttpClient();
JSONObject jsonObject_ = JSON.parseObject(response.body().string()); String url = String.format(tsingtao_xhaProperties.getLocalcam(), resourceDTO.getName(), pageNum, pageSize);
if (jsonObject_.containsKey("data")) { logger.info(url);
if (jsonObject_.getJSONObject("data").containsKey("list")) { Request request = new Request.Builder().url(url).build();
resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total")); try (Response response = client.newCall(request).execute()) {
resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)) if (response.isSuccessful()) {
.map(index -> { JSONObject jsonObject_ = JSON.parseObject(response.body().string());
ResourceDTO resourceDTO1 = new ResourceDTO(); if (jsonObject_.containsKey("data")) {
resourceDTO1.setId(Long.valueOf(index.getString("id"))); if (jsonObject_.getJSONObject("data").containsKey("list")) {
resourceDTO1.setDelFlag(index.getIntValue("delFlag")); resultPage.setTotal(jsonObject_.getJSONObject("data").getLongValue("total"));
resourceDTO1.setLink(index.getString("cameraIndexCode")); resultPage.setRecords(jsonObject_.getJSONObject("data").getJSONArray("list").stream().map(index -> (JSONObject) JSON.toJSON(index)).map(index -> {
resourceDTO1.setName(index.getString("name")); ResourceDTO resourceDTO1 = new ResourceDTO();
resourceDTO1.setType("基础设施"); resourceDTO1.setId(Long.valueOf(index.getString("id")));
try { resourceDTO1.setDelFlag(index.getIntValue("delFlag"));
resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime"))); resourceDTO1.setLink(index.getString("cameraIndexCode"));
} catch (ParseException e) { resourceDTO1.setName(index.getString("name"));
logger.error("时间异常"); resourceDTO1.setType("基础设施");
resourceDTO1.setCreateDate(new Date()); try {
} resourceDTO1.setCreateDate(sdf.parse(index.getString("createdTime")));
return resourceDTO1; } catch (ParseException e) {
}).collect(Collectors.toList())); logger.error("时间异常");
} else { resourceDTO1.setCreateDate(new Date());
resultPage.setRecords(null);
resultPage.setTotal(0);
} }
return resourceDTO1;
} }).collect(Collectors.toList()));
} else { } 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); CompletableFuture.allOf(cloud, local);
} else { } else {
logger.info("西海岸基普通"); logger.info("西海岸基普通");
@ -371,16 +365,70 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override @Override
public List<AttrEntity> selectAttrsByResourceId(Long resourceId) { public List<AttrEntity> selectAttrsByResourceId(Long resourceId) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>(); QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
wrapper.eq("data_resource_id", resourceId) wrapper.eq("data_resource_id", resourceId).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).orderByDesc("attr_type");
.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag())
.orderByDesc("attr_type");
return attrDao.selectList(wrapper); return attrDao.selectList(wrapper);
} }
@Override @Override
public Object selectTotal() { public Object selectTotal() {
HashMap<String, Object> resultMap = new HashMap<>(); HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("total", resourceDao.selectTypeCount(null)); List<Map> re = resourceDao.selectTypeCount(null);
switch (Constant.ProjectPlace.getByFlag(projectPlace)) {
case TSINGTAO_XHA: { // 青岛西海岸
CompletableFuture allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目
List<Long> 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<String, Object>() {
{
put("amount", sum);
put("type", "视频资源数量");
}
});
});
allAmount.join();
}
}
resultMap.put("total", re);
return resultMap; return resultMap;
} }
@ -389,9 +437,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
public Object selectNewest(JSONObject jsonObject) { public Object selectNewest(JSONObject jsonObject) {
IPage<ResourceEntity> page = new Page<>(jsonObject.getIntValue("pageNum"), jsonObject.getIntValue("pageSize")); IPage<ResourceEntity> page = new Page<>(jsonObject.getIntValue("pageNum"), jsonObject.getIntValue("pageSize"));
QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")) queryWrapper.eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type")).eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).orderByDesc("create_date");
.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag())
.orderByDesc("create_date");
return resourceDao.selectPage(page, queryWrapper); return resourceDao.selectPage(page, queryWrapper);
} }
@ -403,8 +449,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
List<ResourceDTO> resourceDTOS = resourceDao.selectMostPopular(selectMap); List<ResourceDTO> resourceDTOS = resourceDao.selectMostPopular(selectMap);
page.setRecords(resourceDTOS); page.setRecords(resourceDTOS);
QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()) queryWrapper.eq("del_flag", ResourceEntityDelFlag.NORMAL.getFlag()).eq("type", jsonObject.getString("type"));
.eq("type", jsonObject.getString("type"));
Integer count = resourceDao.selectCount(queryWrapper); Integer count = resourceDao.selectCount(queryWrapper);
page.setTotal(count); page.setTotal(count);
return page; return page;
@ -417,9 +462,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
ResourceEntity entity = new ResourceEntity(); ResourceEntity entity = new ResourceEntity();
entity.setVisits((resourceEntity.getVisits() == null ? 0 : resourceEntity.getVisits()) + 1); entity.setVisits((resourceEntity.getVisits() == null ? 0 : resourceEntity.getVisits()) + 1);
UpdateWrapper<ResourceEntity> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<ResourceEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda() updateWrapper.lambda().eq(ResourceEntity::getId, resourceEntity.getId()).eq(ResourceEntity::getDelFlag, ResourceEntityDelFlag.NORMAL.getFlag());
.eq(ResourceEntity::getId, resourceEntity.getId())
.eq(ResourceEntity::getDelFlag, ResourceEntityDelFlag.NORMAL.getFlag());
resourceDao.update(entity, updateWrapper); resourceDao.update(entity, updateWrapper);
ResourceBrowseEntity browseEntity = new ResourceBrowseEntity(); ResourceBrowseEntity browseEntity = new ResourceBrowseEntity();
browseEntity.setResourceId(id); browseEntity.setResourceId(id);
@ -487,16 +530,14 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
HashMap<String, Object> resourceMap = new HashMap<>(); HashMap<String, Object> resourceMap = new HashMap<>();
resourceMap.put("type", "全部能力目录"); resourceMap.put("type", "全部能力目录");
QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("del_flag", 0) queryWrapper.eq("del_flag", 0).eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type"));
.eq(StringUtils.isNotBlank(jsonObject.getString("type")), "type", jsonObject.getString("type"));
resourceMap.put("total", resourceDao.selectCount(queryWrapper)); resourceMap.put("total", resourceDao.selectCount(queryWrapper));
resultList.add(resourceMap); resultList.add(resourceMap);
List<Map<String, Object>> typeMapList = resourceDao.selectGroupByDeptId(jsonObject.getString("type")); List<Map<String, Object>> typeMapList = resourceDao.selectGroupByDeptId(jsonObject.getString("type"));
if (typeMapList.isEmpty()) { if (typeMapList.isEmpty()) {
return resultList; return resultList;
} }
Map<String, List<Map<String, Object>>> listMap = typeMapList.stream() Map<String, List<Map<String, Object>>> listMap = typeMapList.stream().collect(Collectors.groupingBy(m -> m.get("type").toString()));
.collect(Collectors.groupingBy(m -> m.get("type").toString()));
//区级要根据行政区划多加一层结构 //区级要根据行政区划多加一层结构
listMap.entrySet().stream().filter(index -> !"区级".equals(index.getKey())).forEach(item -> { listMap.entrySet().stream().filter(index -> !"区级".equals(index.getKey())).forEach(item -> {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
@ -510,8 +551,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
}); });
Optional<List<Map<String, Object>>> areaList = Optional.ofNullable(listMap.get("区级")); Optional<List<Map<String, Object>>> areaList = Optional.ofNullable(listMap.get("区级"));
Optional<Map<String, List<Map<String, Object>>>> areaTypeList = Optional.ofNullable(areaList.orElse(new ArrayList<>()).stream() Optional<Map<String, List<Map<String, Object>>>> areaTypeList = Optional.ofNullable(areaList.orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(m -> m.get("districtName").toString())));
.collect(Collectors.groupingBy(m -> m.get("districtName").toString())));
HashMap<Object, Object> areaMap = new HashMap<>(); HashMap<Object, Object> areaMap = new HashMap<>();
areaMap.put("type", "区级"); areaMap.put("type", "区级");
Integer integer = resourceDao.selectTypeCountByDept("区级", jsonObject.getString("type")); Integer integer = resourceDao.selectTypeCountByDept("区级", jsonObject.getString("type"));
@ -707,9 +747,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
*/ */
@Override @Override
public void KnowledgeBase() { public void KnowledgeBase() {
final List<String> knowledgeUUID = final List<String> 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());
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 int pageSize = 100;
final OkHttpClient client = new OkHttpClient(); final OkHttpClient client = new OkHttpClient();
Arrays.stream(catalogIds).map(index -> { Arrays.stream(catalogIds).map(index -> {
@ -733,19 +771,11 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
String bizContent_ = bizContentParam.toJSONString(); String bizContent_ = bizContentParam.toJSONString();
logger.info("biz_content参数{}", bizContent_); logger.info("biz_content参数{}", bizContent_);
// 通过FormBody对象构建Builder来添加表单参数 // 通过FormBody对象构建Builder来添加表单参数
FormBody.Builder signFormBody = new FormBody.Builder() FormBody.Builder signFormBody = new FormBody.Builder().add("app_id", appId).add("interface_id", methodId).add("version", version).add("timestamp", String.valueOf(timestamp)).add("origin", origin).add("charset", charset).add("biz_content", bizContent_);
.add("app_id", appId)
.add("interface_id", methodId)
.add("version", version)
.add("timestamp", String.valueOf(timestamp))
.add("origin", origin)
.add("charset", charset)
.add("biz_content", bizContent_);
logger.info(index + "分页{}对接知识库数据请求参数:" + signFormBody.build().contentType().toString(), page); logger.info(index + "分页{}对接知识库数据请求参数:" + signFormBody.build().contentType().toString(), page);
Request signRequest = new Request.Builder().url(sign).post(signFormBody.build()).build(); Request signRequest = new Request.Builder().url(sign).post(signFormBody.build()).build();
Response signResponse = Response signResponse = client.newCall(signRequest).execute();
client.newCall(signRequest).execute();
String signResult = signResponse.body().string(); String signResult = signResponse.body().string();
logger.info("{}分页signResult数据" + signResult, page); logger.info("{}分页signResult数据" + signResult, page);
JSONObject signJsonObject = JSON.parseObject(signResult); JSONObject signJsonObject = JSON.parseObject(signResult);