Compare commits

..

No commits in common. '3d10a2646baef7afb0aea8d1d3f8c3635a25c50c' and '9e7f33b1aac056dfb0994a27f7d24429a5b9c81e' have entirely different histories.

  1. 572
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java
  2. 241
      hzims-service/weather/src/main/java/com/hnac/hzims/weather/schedule/StationWeatherSchedule.java

572
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java

@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hnac.hzims.operational.config.HikPathConfiguration; import com.hnac.hzims.operational.config.HikPathConfiguration;
import com.hnac.hzims.operational.station.StationConstants; import com.hnac.hzims.operational.station.StationConstants;
@ -49,309 +50,308 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTypeMapper, StationVideoTypeEntity> implements IStationVideoTypeService { public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTypeMapper, StationVideoTypeEntity> implements IStationVideoTypeService {
private final HikPathConfiguration pathConfiguration; private final HikPathConfiguration pathConfiguration;
private final BladeLogger logger; private final BladeLogger logger;
@Value("${url.video.login}") @Value("${url.video.login}")
private String videoLoginUrl; private String videoLoginUrl;
@Value("${hzims.video.random-code}") @Value("${hzims.video.random-code}")
private String definitionCode; private String definitionCode;
@Value("${url.video.left}") /**
private List<String> videoLeft; * 获取海康视频接口
@Value("${url.video.right}") * @return
private List<String> videoRight; */
@Override
public String getHikVideo(){
List<StationVideoTypeEntity> stationVideoTypeEntityList = this.list();
List<Long> ids = new ArrayList<>();
stationVideoTypeEntityList.forEach(stationVideoTypeEntity -> {
if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){
try{
stationVideoTypeEntity.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewURL(stationVideoTypeEntity.getVideoHost(),
stationVideoTypeEntity.getAppKey(),stationVideoTypeEntity.getAppSecret()
,stationVideoTypeEntity.getPointCode(), DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE,
stationVideoTypeEntity.getType()),0));
ids.add(stationVideoTypeEntity.getId());
}
catch (Exception e){
stationVideoTypeEntity.setLiveSourceAddress(null);
}
}
});
String result = ids.stream().map(id -> {
return id+"";
}).collect(Collectors.joining(","));
return result;
}
/** @Override
* 获取海康视频接口 public List<StationEntity> getStationsByVideo() {
* return this.baseMapper.getStationsByVideo();
* @return }
*/
@Override
public String getHikVideo() {
List<StationVideoTypeEntity> stationVideoTypeEntityList = this.list();
List<Long> ids = new ArrayList<>();
stationVideoTypeEntityList.forEach(stationVideoTypeEntity -> {
if (ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1) {
try {
stationVideoTypeEntity.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewURL(stationVideoTypeEntity.getVideoHost(),
stationVideoTypeEntity.getAppKey(), stationVideoTypeEntity.getAppSecret()
, stationVideoTypeEntity.getPointCode(), DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE,
stationVideoTypeEntity.getType()), 0));
ids.add(stationVideoTypeEntity.getId());
} catch (Exception e) {
stationVideoTypeEntity.setLiveSourceAddress(null);
}
}
});
String result = ids.stream().map(id -> {
return id + "";
}).collect(Collectors.joining(","));
return result;
}
@Override @Override
public List<StationEntity> getStationsByVideo() { public IPage<StationVideoTypeVO> getStationVideoOrderBySort(StationVideoTypeDTO req, Query query) {
return this.baseMapper.getStationsByVideo(); StationVideoTypeEntity stationVideoTypeEntity = BeanUtil.copy(req,StationVideoTypeEntity.class);
} QueryWrapper<StationVideoTypeEntity> queryWrapper = com.hnac.hzims.common.utils.Condition.getQueryWrapper(new StationVideoTypeEntity(),stationVideoTypeEntity,false, "vt");
IPage<StationVideoTypeVO> result = this.baseMapper.getStationVideoOrderBySort(queryWrapper,Condition.getPage(query));
return result;
}
@Override @Override
public IPage<StationVideoTypeVO> getStationVideoOrderBySort(StationVideoTypeDTO req, Query query) { public IPage<StationVideoTypeEntity> getStationVideoOrderByName(StationVideoTypeVO req, Query query) {
StationVideoTypeEntity stationVideoTypeEntity = BeanUtil.copy(req, StationVideoTypeEntity.class); if (ObjectUtil.isNotEmpty(req.getVideoOwerType())&&req.getVideoOwerType().equals(1)) {
QueryWrapper<StationVideoTypeEntity> queryWrapper = com.hnac.hzims.common.utils.Condition.getQueryWrapper(new StationVideoTypeEntity(), stationVideoTypeEntity, false, "vt"); req.setVideoType("6");
IPage<StationVideoTypeVO> result = this.baseMapper.getStationVideoOrderBySort(queryWrapper, Condition.getPage(query)); }
return result; Wrapper<StationVideoTypeEntity> queryWrapper = new LambdaQueryWrapper<StationVideoTypeEntity>() {{
} if (CollectionUtil.isNotEmpty(req.getStationIds())) {
in(StationVideoTypeEntity::getStationId, req.getStationIds());
}
if (ObjectUtil.isNotEmpty(req.getStationId())) {
eq(StationVideoTypeEntity::getStationId, req.getStationId());
}
if (ObjectUtil.isNotEmpty(req.getStatus())) {
eq(StationVideoTypeEntity::getStatus, req.getStatus());
}
if (ObjectUtil.isNotEmpty(req.getVideoOwerType())) {
eq(StationVideoTypeEntity::getVideoOwerType, req.getVideoOwerType());
}
if (ObjectUtil.isNotEmpty(req.getVideoType())) {
eq(StationVideoTypeEntity::getVideoType, req.getVideoType());
}
if (ObjectUtil.isNotEmpty(req.getName())) {
eq(StationVideoTypeEntity::getName, req.getName());
}
if (ObjectUtil.isNotEmpty(req.getStationId())&&ObjectUtil.isEmpty(req.getVideoType())&&ObjectUtil.isNotEmpty(req.getVideoOwerType())&&req.getVideoOwerType().equals(2)) {
List<String> stringList = Arrays.asList("1", "2", "3", "4", "5");
in(StationVideoTypeEntity::getVideoType,stringList);
}
eq(StationVideoTypeEntity::getIsDeleted, 0);
orderBy(true,true,StationVideoTypeEntity::getStationSort);
orderBy(true,true,StationVideoTypeEntity::getSort);
}};
@Override IPage<StationVideoTypeEntity> result = this.page(Condition.getPage(query),queryWrapper);
public IPage<StationVideoTypeEntity> getStationVideoOrderByName(StationVideoTypeVO req, Query query) {
if (ObjectUtil.isNotEmpty(req.getVideoOwerType()) && req.getVideoOwerType().equals(1)) {
req.setVideoType("6");
}
Wrapper<StationVideoTypeEntity> queryWrapper = new LambdaQueryWrapper<StationVideoTypeEntity>() {{
if (CollectionUtil.isNotEmpty(req.getStationIds())) {
in(StationVideoTypeEntity::getStationId, req.getStationIds());
}
if (ObjectUtil.isNotEmpty(req.getStationId())) {
eq(StationVideoTypeEntity::getStationId, req.getStationId());
}
if (ObjectUtil.isNotEmpty(req.getStatus())) {
eq(StationVideoTypeEntity::getStatus, req.getStatus());
}
if (ObjectUtil.isNotEmpty(req.getVideoOwerType())) {
eq(StationVideoTypeEntity::getVideoOwerType, req.getVideoOwerType());
}
if (ObjectUtil.isNotEmpty(req.getVideoType())) {
eq(StationVideoTypeEntity::getVideoType, req.getVideoType());
}
if (ObjectUtil.isNotEmpty(req.getName())) {
eq(StationVideoTypeEntity::getName, req.getName());
}
if (ObjectUtil.isNotEmpty(req.getStationId()) && ObjectUtil.isEmpty(req.getVideoType()) && ObjectUtil.isNotEmpty(req.getVideoOwerType()) && req.getVideoOwerType().equals(2)) {
List<String> stringList = Arrays.asList("1", "2", "3", "4", "5");
in(StationVideoTypeEntity::getVideoType, stringList);
}
eq(StationVideoTypeEntity::getIsDeleted, 0);
orderBy(true, true, StationVideoTypeEntity::getStationSort);
orderBy(true, true, StationVideoTypeEntity::getSort);
}};
IPage<StationVideoTypeEntity> result = this.page(Condition.getPage(query), queryWrapper); if (CollectionUtil.isNotEmpty(result.getRecords())){
for (StationVideoTypeEntity video : result.getRecords()) {
try {
video.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(video.getVideoHost(), video.getAppKey(), video.getAppSecret(), video.getPointCode(), 1));
}
catch(Exception e) {
log.error("视频点位【"+video.getName()+"】获取地址失败");
}
}
}
if (CollectionUtil.isNotEmpty(result.getRecords())) { return result;
for (StationVideoTypeEntity video : result.getRecords()) { }
try { @Override
video.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(video.getVideoHost(), video.getAppKey(), video.getAppSecret(), video.getPointCode(), 1)); public List<StationVideoTypeEntity> getVideoByIdsAndType(String ids,String type) {
} catch (Exception e) { List<Long> idList = Func.toLongList(",",ids);
log.error("视频点位【" + video.getName() + "】获取地址失败"); List<StationVideoTypeEntity> result = idList.stream().parallel().map(id -> this.getById(id)).filter(ObjectUtil::isNotEmpty).filter(entity -> entity.getIsHikvideo() == 1)
} .map(entity -> {
} String address = null;
} try {
address = ArtemisPostUtils.getCameraPreviewURL(
entity.getVideoHost(), entity.getAppKey(), entity.getAppSecret(), entity.getPointCode(), type, 0
);
entity.setLiveSourceAddress(address);
} catch (Exception e) {
entity.setLiveSourceAddress(null);
}
return entity;
}).collect(Collectors.toList());
return result;
}
return result; @Override
} public List<StationVideoTypeEntity> getVideoByIds(String ids,String randomCode) {
Assert.isTrue(StringUtil.isNoneBlank(randomCode) && randomCode.equals(definitionCode),()->{
throw new ServiceException("视频随机码为空或不正确");
});
Assert.isTrue(StringUtil.isNoneBlank(ids),()->{
throw new ServiceException("视频配置ID不能为空");
});
List<StationVideoTypeEntity> result = Arrays.stream(ids.split(",")).filter(ObjectUtil::isNotEmpty).map(id -> this.getById(id)).map(entity -> {
String address;
try {
address = ArtemisPostUtils.getCameraPreviewURL(
entity.getVideoHost(),
entity.getAppKey(),
entity.getAppSecret(),
entity.getPointCode(),
DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE,entity.getType()), 0
);
entity.setLiveSourceAddress(address);
} catch (Exception e) {
entity.setLiveSourceAddress(null);
}
return entity;
}).collect(Collectors.toList());
return result;
}
@Override @Override
public List<StationVideoTypeEntity> getVideoByIdsAndType(String ids, String type) { public String getVideoReviewerToken() {
List<Long> idList = Func.toLongList(",", ids); String result = HttpUtil.post(videoLoginUrl, "");
List<StationVideoTypeEntity> result = idList.stream().parallel().map(id -> this.getById(id)).filter(ObjectUtil::isNotEmpty).filter(entity -> entity.getIsHikvideo() == 1) JSONObject resultObject = JSONObject.parseObject(result);
.map(entity -> { String data = resultObject.getString("data");
String address = null; String access_token = JSONObject.parseObject(data).getString("access_token");
try { log.info("视频查看人员登陆token为:{}",access_token);
address = ArtemisPostUtils.getCameraPreviewURL( return access_token;
entity.getVideoHost(), entity.getAppKey(), entity.getAppSecret(), entity.getPointCode(), type, 0 }
);
entity.setLiveSourceAddress(address);
} catch (Exception e) {
entity.setLiveSourceAddress(null);
}
return entity;
}).collect(Collectors.toList());
return result;
}
@Override @Override
public List<StationVideoTypeEntity> getVideoByIds(String ids, String randomCode) { public List<JSONObject> getHikVisionStations() {
Assert.isTrue(StringUtil.isNoneBlank(randomCode) && randomCode.equals(definitionCode), () -> { Assert.isTrue(StringUtil.isNotBlank(pathConfiguration.getStationsPath()),()->{
throw new ServiceException("视频随机码为空或不正确"); throw new ServiceException("nacos中未配置海康威视请求地址!");
}); });
Assert.isTrue(StringUtil.isNoneBlank(ids), () -> { HttpResponse response;
throw new ServiceException("视频配置ID不能为空"); try {
}); response = HttpUtil.createGet(pathConfiguration.getStationsPath()).execute();
List<StationVideoTypeEntity> result = Arrays.stream(ids.split(",")).filter(ObjectUtil::isNotEmpty).map(id -> this.getById(id)).map(entity -> { }
String address; catch(Exception e) {
try { logger.error("getHikVisionStations",e.getMessage());
address = ArtemisPostUtils.getCameraPreviewURL( return Lists.newArrayList();
entity.getVideoHost(), // throw new ServiceException(e.getMessage());
entity.getAppKey(), }
entity.getAppSecret(), if(HttpServletResponse.SC_OK == response.getStatus()) {
entity.getPointCode(), return JSONArray.parseArray(response.body(),JSONObject.class);
DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE, entity.getType()), 0 }
); return Lists.newArrayList();
entity.setLiveSourceAddress(address); }
} catch (Exception e) {
entity.setLiveSourceAddress(null);
}
return entity;
}).collect(Collectors.toList());
return result;
}
@Override @Override
public String getVideoReviewerToken() { public Map<HikDeviceResp, List<HikMonitorResp>> getMonitorsByStation(String stationId) {
String result = HttpUtil.post(videoLoginUrl, ""); Assert.isTrue(StringUtil.isNotBlank(pathConfiguration.getMonitorsPath()),()->{
JSONObject resultObject = JSONObject.parseObject(result); throw new ServiceException("nacos中未配置海康威视请求地址!");
String data = resultObject.getString("data"); });
String access_token = JSONObject.parseObject(data).getString("access_token"); HttpResponse response;
log.info("视频查看人员登陆token为:{}", access_token); try{
return access_token; response = HttpUtil.createGet(pathConfiguration.getMonitorsPath()+"/"+stationId).execute();
} }
catch (RuntimeException e) {
throw new ServiceException(e.getMessage());
}
Assert.isTrue(HttpServletResponse.SC_OK == response.getStatus(),()->{
throw new ServiceException("调用获取海康威视站点下监测点列表接口失败!");
});
List<HikMonitorResp> monitorList = JSONArray.parseArray(response.body(), HikMonitorResp.class);
logger.info("HikVideo:monitor:info",JSON.toJSONString(monitorList));
return monitorList.stream().collect(Collectors.groupingBy(HikMonitorResp::getDevice));
}
@Override @Override
public List<JSONObject> getHikVisionStations() { public List<StationVideoTypeEntity> getVideoCount(String code,List<String> videoType,String videoOwerType) {
Assert.isTrue(StringUtil.isNotBlank(pathConfiguration.getStationsPath()), () -> { LambdaQueryWrapper<StationVideoTypeEntity> queryWrapper = new LambdaQueryWrapper<>();
throw new ServiceException("nacos中未配置海康威视请求地址!"); if (StringUtil.isNotBlank(code)) {
}); queryWrapper.eq(StationVideoTypeEntity::getStationId, code);
HttpResponse response; }
try { if (CollectionUtil.isNotEmpty(videoType)) {
response = HttpUtil.createGet(pathConfiguration.getStationsPath()).execute(); queryWrapper.in(StationVideoTypeEntity::getVideoType, videoType);
} catch (Exception e) { }
logger.error("getHikVisionStations", e.getMessage()); if (StringUtil.isNotBlank(videoOwerType)) {
return Lists.newArrayList(); queryWrapper.eq(StationVideoTypeEntity::getVideoOwerType, videoOwerType);
// throw new ServiceException(e.getMessage()); }
} if (ObjectUtil.isNotEmpty(this.baseMapper.selectCount(queryWrapper))){
if (HttpServletResponse.SC_OK == response.getStatus()) { List<StationVideoTypeEntity> stationVideoTypeEntities = this.baseMapper.selectList(queryWrapper);
return JSONArray.parseArray(response.body(), JSONObject.class); return stationVideoTypeEntities;
} }else {
return Lists.newArrayList(); return new ArrayList<>();
} }
}
@Override @Override
public Map<HikDeviceResp, List<HikMonitorResp>> getMonitorsByStation(String stationId) { public StationVideoTypeEntity getById(Long id,int streamType){
Assert.isTrue(StringUtil.isNotBlank(pathConfiguration.getMonitorsPath()), () -> { StationVideoTypeEntity stationVideoTypeEntity = this.getById(id);
throw new ServiceException("nacos中未配置海康威视请求地址!"); if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){
}); try{
HttpResponse response; /**视频监控秘钥**/
try { stationVideoTypeEntity.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewURL(
response = HttpUtil.createGet(pathConfiguration.getMonitorsPath() + "/" + stationId).execute(); stationVideoTypeEntity.getVideoHost()
} catch (RuntimeException e) { , stationVideoTypeEntity.getAppKey()
throw new ServiceException(e.getMessage()); , stationVideoTypeEntity.getAppSecret()
} , stationVideoTypeEntity.getPointCode()
Assert.isTrue(HttpServletResponse.SC_OK == response.getStatus(), () -> { , DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE,stationVideoTypeEntity.getType())
throw new ServiceException("调用获取海康威视站点下监测点列表接口失败!"); , streamType
}); ));
List<HikMonitorResp> monitorList = JSONArray.parseArray(response.body(), HikMonitorResp.class); }
logger.info("HikVideo:monitor:info", JSON.toJSONString(monitorList)); catch (Exception e){
return monitorList.stream().collect(Collectors.groupingBy(HikMonitorResp::getDevice)); stationVideoTypeEntity.setLiveSourceAddress(null);
} }
}
return stationVideoTypeEntity;
}
@Override @Override
public List<StationVideoTypeEntity> getVideoCount(String code, List<String> videoType, String videoOwerType) { public List<VideoMonitorVO> getVideoMonitor() {
LambdaQueryWrapper<StationVideoTypeEntity> queryWrapper = new LambdaQueryWrapper<>(); List<VideoMonitorVO> videoMonitorVOList = this.baseMapper.getVideoMonitor();
if (StringUtil.isNotBlank(code)) { if(CollectionUtil.isEmpty(videoMonitorVOList)){
queryWrapper.eq(StationVideoTypeEntity::getStationId, code); return new ArrayList<>();
} }
if (CollectionUtil.isNotEmpty(videoType)) { return videoMonitorVOList.stream().map(item->{
queryWrapper.in(StationVideoTypeEntity::getVideoType, videoType); if(CollectionUtil.isEmpty(item.getChildren())){
} return item;
if (StringUtil.isNotBlank(videoOwerType)) { }
queryWrapper.eq(StationVideoTypeEntity::getVideoOwerType, videoOwerType); item.setChildren(item.getChildren().stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationVideoTypeVO::getName))), ArrayList::new)));
} return item;
if (ObjectUtil.isNotEmpty(this.baseMapper.selectCount(queryWrapper))) { }).collect(Collectors.toList());
List<StationVideoTypeEntity> stationVideoTypeEntities = this.baseMapper.selectList(queryWrapper); }
return stationVideoTypeEntities;
} else {
return new ArrayList<>();
}
}
@Override @Override
public StationVideoTypeEntity getById(Long id, int streamType) { public List<VideoMonitorVO> getVideoMonitor(String type) {
StationVideoTypeEntity stationVideoTypeEntity = this.getById(id); List<StationEntity> agencyStationList = this.baseMapper.getAgencyStationsByVideo(type);
if (ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1) { if(CollectionUtil.isEmpty(agencyStationList)) {
try { return null;
/**视频监控秘钥**/ }
stationVideoTypeEntity.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewURL( return agencyStationList.stream()
stationVideoTypeEntity.getVideoHost() .map(stationEntity -> BeanUtil.copy(stationEntity,VideoMonitorVO.class))
, stationVideoTypeEntity.getAppKey() .map(videoMonitorVO -> {
, stationVideoTypeEntity.getAppSecret() LambdaQueryWrapper<StationVideoTypeEntity> qw = Wrappers.<StationVideoTypeEntity>lambdaQuery()
, stationVideoTypeEntity.getPointCode() .eq(StationVideoTypeEntity::getStationId, videoMonitorVO.getCode())
, DictCache.getValue(StationConstants.STATION_VIDEO_TYPE_CODE, stationVideoTypeEntity.getType()) .orderByAsc(StationVideoTypeEntity::getSort);
, streamType if(StringUtil.isNotBlank(type)) {
)); qw.eq(StationVideoTypeEntity::getVideoType,type);
} catch (Exception e) { }
stationVideoTypeEntity.setLiveSourceAddress(null); List<StationVideoTypeVO> children = JSONArray.parseArray(JSONArray.toJSONString(this.list(qw)),StationVideoTypeVO.class);
} videoMonitorVO.setChildren(children);
} return videoMonitorVO;
return stationVideoTypeEntity; }).collect(Collectors.toList());
} }
@Override /**
public List<VideoMonitorVO> getVideoMonitor() { * 水利监控视频
List<VideoMonitorVO> videoMonitorVOList = this.baseMapper.getVideoMonitor(); * @return
if (CollectionUtil.isEmpty(videoMonitorVOList)) { */
return new ArrayList<>(); @Override
} public WaterMonitorVideoVo waterMonitorVideo() {
return videoMonitorVOList.stream().map(item -> { WaterMonitorVideoVo video = new WaterMonitorVideoVo();
if (CollectionUtil.isEmpty(item.getChildren())) { List<StationVideoTypeEntity> left = this.list(Wrappers.<StationVideoTypeEntity>lambdaQuery().
return item; in(StationVideoTypeEntity::getId,Arrays.asList(28483776900235440L,28483776900235463L, 28483776900235466L)));
} if(CollectionUtil.isNotEmpty(left)){
item.setChildren(item.getChildren().stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationVideoTypeVO::getName))), ArrayList::new))); video.setLeft(left.stream().peek(item->{
return item; try {
}).collect(Collectors.toList()); item.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(item.getVideoHost(), item.getAppKey(), item.getAppSecret(), item.getPointCode(), 1));
} }
catch(Exception e) {
@Override log.error("视频点位【"+item.getPointCode()+"】获取地址失败");
public List<VideoMonitorVO> getVideoMonitor(String type) { }
List<StationEntity> agencyStationList = this.baseMapper.getAgencyStationsByVideo(type);
if (CollectionUtil.isEmpty(agencyStationList)) {
return null;
}
return agencyStationList.stream()
.map(stationEntity -> BeanUtil.copy(stationEntity, VideoMonitorVO.class))
.map(videoMonitorVO -> {
LambdaQueryWrapper<StationVideoTypeEntity> qw = Wrappers.<StationVideoTypeEntity>lambdaQuery()
.eq(StationVideoTypeEntity::getStationId, videoMonitorVO.getCode())
.orderByAsc(StationVideoTypeEntity::getSort);
if (StringUtil.isNotBlank(type)) {
qw.eq(StationVideoTypeEntity::getVideoType, type);
}
List<StationVideoTypeVO> children = JSONArray.parseArray(JSONArray.toJSONString(this.list(qw)), StationVideoTypeVO.class);
videoMonitorVO.setChildren(children);
return videoMonitorVO;
}).collect(Collectors.toList());
}
/**
* 水利监控视频
*
* @return
*/
@Override
public WaterMonitorVideoVo waterMonitorVideo() {
WaterMonitorVideoVo video = new WaterMonitorVideoVo();
List<StationVideoTypeEntity> left = this.list(Wrappers.<StationVideoTypeEntity>lambdaQuery().
in(StationVideoTypeEntity::getId, videoLeft));
if (CollectionUtil.isNotEmpty(left)) {
video.setLeft(left.stream().peek(item -> {
try {
item.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(item.getVideoHost(), item.getAppKey(), item.getAppSecret(), item.getPointCode(), 1));
} catch (Exception e) {
log.error("视频点位【" + item.getPointCode() + "】获取地址失败");
}
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
List<StationVideoTypeEntity> right = this.list(Wrappers.<StationVideoTypeEntity>lambdaQuery(). List<StationVideoTypeEntity> right = this.list(Wrappers.<StationVideoTypeEntity>lambdaQuery().
in(StationVideoTypeEntity::getId, videoRight)); in(StationVideoTypeEntity::getId,Arrays.asList(28483776900235468L,28483776900235467L,28483776900235472L)));
if (CollectionUtil.isNotEmpty(right)) { if(CollectionUtil.isNotEmpty(right)){
video.setRight(right.stream().peek(item -> { video.setRight(right.stream().peek(item->{
try { try {
item.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(item.getVideoHost(), item.getAppKey(), item.getAppSecret(), item.getPointCode(), 1)); item.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(item.getVideoHost(), item.getAppKey(), item.getAppSecret(), item.getPointCode(), 1));
} catch (Exception e) { }
log.error("视频点位【" + item.getPointCode() + "】获取地址失败"); catch(Exception e) {
} log.error("视频点位【"+item.getPointCode()+"】获取地址失败");
}
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
return video; return video;
} }
} }

241
hzims-service/weather/src/main/java/com/hnac/hzims/weather/schedule/StationWeatherSchedule.java

@ -1,13 +1,16 @@
package com.hnac.hzims.weather.schedule; package com.hnac.hzims.weather.schedule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hnac.hzims.hzimsweather.constants.WeatherConstant;
import com.hnac.hzims.hzimsweather.entity.DailyHeWeatherEntity; import com.hnac.hzims.hzimsweather.entity.DailyHeWeatherEntity;
import com.hnac.hzims.hzimsweather.entity.VStationEntity; import com.hnac.hzims.hzimsweather.entity.VStationEntity;
import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.Daily;
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse;
import com.hnac.hzims.weather.service.HeWeatherHistoricalService;
import com.hnac.hzims.weather.service.HeWeatherWeatherService; import com.hnac.hzims.weather.service.HeWeatherWeatherService;
import com.hnac.hzims.weather.service.IDailyHeWeatherService; import com.hnac.hzims.weather.service.IDailyHeWeatherService;
import com.hnac.hzims.weather.service.IStationService; import com.hnac.hzims.weather.service.IStationService;
@ -16,13 +19,23 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.*; import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.STATION_DAILY_WEATHER;
import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.STATION_3D_WEATHER;
import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.STATION_NOW_WEATHER;
import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.STATION_7D_WEATHER;
/** /**
* @author hx * @author hx
@ -32,118 +45,120 @@ import static com.hnac.hzims.hzimsweather.constants.XxlJobConstant.*;
@Slf4j @Slf4j
public class StationWeatherSchedule { public class StationWeatherSchedule {
private final HeWeatherWeatherService weatherService; private final HeWeatherWeatherService weatherService;
private final IDailyHeWeatherService dailyHeWeatherService; private final IDailyHeWeatherService dailyHeWeatherService;
private final IStationService stationService; private final IStationService stationService;
/** /**
* 获取各站点下七日内天气 存入缓存 * 获取各站点下七日内天气 存入缓存
* * @Scheduled(cron = "0 10 0/12 * * ?")
* @return * @return
* @throws InterruptedException * @throws InterruptedException
* @Scheduled(cron = "0 10 0/12 * * ?") */
*/ @XxlJob(STATION_7D_WEATHER)
@XxlJob(STATION_7D_WEATHER) public ReturnT<String> save7dWeather(String param) throws InterruptedException {
public ReturnT<String> save7dWeather(String param) throws InterruptedException { List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null);
List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null); ExecutorService executorService = new ThreadPoolExecutor(10,stationEntityList.size(),0,TimeUnit.SECONDS,new LinkedBlockingDeque<>());
ExecutorService executorService = new ThreadPoolExecutor(10, stationEntityList.size(), 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); CountDownLatch downLatch = new CountDownLatch(stationEntityList.size());
CountDownLatch downLatch = new CountDownLatch(stationEntityList.size()); executorService.execute(()->stationEntityList.forEach(vStationEntity -> {
executorService.execute(() -> stationEntityList.forEach(vStationEntity -> { try{
try { XxlJobLogger.log(vStationEntity.getName()+"获取七日天气开始,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
XxlJobLogger.log(vStationEntity.getName() + "获取七日天气开始,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd();
String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd(); HeWeatherWeatherDailyResponse weatherDailyResponse = weatherService.getWeather7d(location);
HeWeatherWeatherDailyResponse weatherDailyResponse = weatherService.getWeather7d(location); if(weatherDailyResponse.getCode().isOk()) {
if (weatherDailyResponse.getCode().isOk()) { List<Daily> dailyList = weatherDailyResponse.getDaily();
List<Daily> dailyList = weatherDailyResponse.getDaily(); List<DailyHeWeatherEntity> weatherEntityList = Lists.newArrayList();
List<DailyHeWeatherEntity> weatherEntityList = Lists.newArrayList(); for (Daily daily : dailyList) {
for (Daily daily : dailyList) { //查询数据库内是否存在这天的天气
//查询数据库内是否存在这天的天气 DailyHeWeatherEntity entity = JSONObject.parseObject(JSON.toJSONString(daily),DailyHeWeatherEntity.class);
DailyHeWeatherEntity entity = JSONObject.parseObject(JSON.toJSONString(daily), DailyHeWeatherEntity.class); DailyHeWeatherEntity dailyHeWeatherEntity = dailyHeWeatherService.getOne(Wrappers.<DailyHeWeatherEntity>lambdaQuery()
DailyHeWeatherEntity dailyHeWeatherEntity = dailyHeWeatherService.getOne(Wrappers.<DailyHeWeatherEntity>lambdaQuery() .eq(DailyHeWeatherEntity::getStationCode,vStationEntity.getCode())
.eq(DailyHeWeatherEntity::getStationCode, vStationEntity.getCode()) .eq(DailyHeWeatherEntity::getFxDate,entity.getFxDate())
.eq(DailyHeWeatherEntity::getFxDate, entity.getFxDate()) .last("limit 1;")
.last("limit 1;") );
); if(ObjectUtil.isNotEmpty(dailyHeWeatherEntity)) {
if (ObjectUtil.isNotEmpty(dailyHeWeatherEntity)) { entity.setId(dailyHeWeatherEntity.getId());
entity.setId(dailyHeWeatherEntity.getId()); }
} else { else {
entity.setStationCode(vStationEntity.getCode()); entity.setStationCode(vStationEntity.getCode());
entity.setDeptId(vStationEntity.getRefDept()); entity.setDeptId(vStationEntity.getRefDept());
entity.setTenantId(vStationEntity.getTenantId()); entity.setTenantId(vStationEntity.getTenantId());
entity.setCreateUser(vStationEntity.getCreateUser()); entity.setCreateUser(vStationEntity.getCreateUser());
entity.setCreateDept(vStationEntity.getCreateDept()); entity.setCreateDept(vStationEntity.getCreateDept());
} }
weatherEntityList.add(entity); weatherEntityList.add(entity);
} }
dailyHeWeatherService.saveOrUpdateBatch(weatherEntityList); dailyHeWeatherService.saveOrUpdateBatch(weatherEntityList);
} }
} catch (Exception e) { }
log.error("{}获取七日天气失败,位置信息为:{},{}", vStationEntity.getName(), vStationEntity.getLgtd(), vStationEntity.getLttd()); catch (Exception e) {
log.error("获取七日天气失败", e); e.printStackTrace();
XxlJobLogger.log(vStationEntity.getName() + "获取七日天气失败,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); XxlJobLogger.log(vStationEntity.getName()+"获取七日天气失败,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
} finally { }
downLatch.countDown(); finally {
} downLatch.countDown();
})); }
downLatch.await(); }));
executorService.shutdown(); downLatch.await();
return ReturnT.SUCCESS; executorService.shutdown();
} return ReturnT.SUCCESS;
}
/** /**
* 获取各站点下三日内天气 存入缓存 @Scheduled(cron = "0 5 0/1 * * ?") * 获取各站点下三日内天气 存入缓存 @Scheduled(cron = "0 5 0/1 * * ?")
* * @return
* @return * @throws InterruptedException
* @throws InterruptedException */
*/ @XxlJob(STATION_3D_WEATHER)
@XxlJob(STATION_3D_WEATHER) public ReturnT<String> save3dWeather(String param) throws InterruptedException {
public ReturnT<String> save3dWeather(String param) throws InterruptedException { List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null);
List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null); ExecutorService executorService = new ThreadPoolExecutor(10,stationEntityList.size(),0,TimeUnit.SECONDS,new LinkedBlockingDeque<>());
ExecutorService executorService = new ThreadPoolExecutor(10, stationEntityList.size(), 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); CountDownLatch downLatch = new CountDownLatch(stationEntityList.size());
CountDownLatch downLatch = new CountDownLatch(stationEntityList.size()); executorService.execute(()->stationEntityList.forEach(vStationEntity -> {
executorService.execute(() -> stationEntityList.forEach(vStationEntity -> { try {
try { XxlJobLogger.log(vStationEntity.getName()+"获取三日天气开始,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
XxlJobLogger.log(vStationEntity.getName() + "获取三日天气开始,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd();
String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd(); weatherService.getWeather3d(location);
weatherService.getWeather3d(location); }
} catch (Exception e) { catch (Exception e) {
log.error("{}获取三日天气失败,位置信息为:{},{}", vStationEntity.getName(), vStationEntity.getLgtd(), vStationEntity.getLttd()); e.printStackTrace();
log.error("获取三日天气失败", e); XxlJobLogger.log(vStationEntity.getName()+"获取三日天气失败,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
XxlJobLogger.log(vStationEntity.getName() + "获取三日天气失败,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); }
} finally { finally {
downLatch.countDown(); downLatch.countDown();
} }
})); }));
downLatch.await(); downLatch.await();
executorService.shutdown(); executorService.shutdown();
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
/** /**
* 获取各站点下实况天气 存入缓存 @Scheduled(cron = "0 0 0/1 * * ?") * 获取各站点下实况天气 存入缓存 @Scheduled(cron = "0 0 0/1 * * ?")
* * @return
* @return * @throws InterruptedException
* @throws InterruptedException */
*/ @XxlJob(STATION_NOW_WEATHER)
@XxlJob(STATION_NOW_WEATHER) public ReturnT<String> saveNowWeather(String param) throws InterruptedException {
public ReturnT<String> saveNowWeather(String param) throws InterruptedException { List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null);
List<VStationEntity> stationEntityList = stationService.getStationWithLocation(null); ExecutorService executorService = new ThreadPoolExecutor(10,stationEntityList.size(),0,TimeUnit.SECONDS,new LinkedBlockingDeque<>());
ExecutorService executorService = new ThreadPoolExecutor(10, stationEntityList.size(), 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); CountDownLatch downLatch = new CountDownLatch(stationEntityList.size());
CountDownLatch downLatch = new CountDownLatch(stationEntityList.size()); executorService.execute(()->stationEntityList.forEach(vStationEntity -> {
executorService.execute(() -> stationEntityList.forEach(vStationEntity -> { try {
try { XxlJobLogger.log(vStationEntity.getName()+"获取实时天气开始,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
XxlJobLogger.log(vStationEntity.getName() + "获取实时天气开始,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd();
String location = vStationEntity.getLgtd() + "," + vStationEntity.getLttd(); weatherService.getWeatherNow(location);
weatherService.getWeatherNow(location); }
} catch (Exception e) { catch(Exception e) {
log.error("获取实时天气失败", e); e.printStackTrace();
XxlJobLogger.log(vStationEntity.getName() + "获取实时天气失败,位置信息为:" + vStationEntity.getLgtd() + "," + vStationEntity.getLttd()); XxlJobLogger.log(vStationEntity.getName()+"获取实时天气失败,位置信息为:"+ vStationEntity.getLgtd() + "," + vStationEntity.getLttd());
} finally { }
downLatch.countDown(); finally {
} downLatch.countDown();
})); }
downLatch.await(); }));
executorService.shutdown(); downLatch.await();
return ReturnT.SUCCESS; executorService.shutdown();
} return ReturnT.SUCCESS;
}
} }

Loading…
Cancel
Save