提交 b7c9acd7 作者: 谭志磊

合并,备份

上级 c7db2617
......@@ -11,22 +11,21 @@ import com.yiring.app.vo.video.VideoVo;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.util.StrUtils;
import com.yiring.common.vo.PageVo;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import org.locationtech.jts.geom.Point;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* @author tzl
......@@ -92,11 +91,30 @@ public class VideoServiceImpl implements VideoService {
if (has(videoParam.getUuid())) {
return Result.no(Status.BAD_REQUEST, "您输入的编号已存在");
}
//当修改跟国标相关联的信息时同步更新国标数据
// if (
// !video.getVideoName().equals(videoParam.getVideoName()) && !video.getM3u8().equals(videoParam.getM3u8())
// ) {
// gbClient.proxyDel("stream", video.getUuid(), gbCookie());
// }
}
BeanUtils.copyProperties(videoParam, video);
videoRepository.saveAndFlush(video);
//还需要同步修改国标28181中对应的摄像头信息
//将信息发送到队列,等待同步至国标
// StreamProxyItem streamProxyItem = StreamProxyItem
// .builder()
// .name(video.getVideoName())
// .app("stream")
// .stream(video.getUuid())
// .url(video.getM3u8())
// .mediaServerId("ZbnQN5csqxrPix7a")
// .enable(true)
// .enable_hls(true)
// .type(video.getM3u8().contains("sss") ? "ffmpeg" : "default")
// .timeout_ms(video.getM3u8().contains("sss") ? 60 : null)
// .build();
// JSONObject jsonObject = gbClient.proxySave(streamProxyItem, gbCookie());
// System.out.println(jsonObject);
return Result.ok();
}
......@@ -111,54 +129,143 @@ public class VideoServiceImpl implements VideoService {
}
@Override
public Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam, PageParam param) {
Page<Video> all = videoRepository.findAll(condition(videoQueryParam), PageParam.toPageable(param));
public Result<PageVo<VideoVo>> pageVideo(VideoQueryParam videoQueryParam) {
PageVo<VideoVo> resultVo = null;
//排序
Sort sort = Sort.by(Sort.Order.desc(Video.Fields.createTime));
//如果传分页参数则分页,否查全部数据
if (Objects.nonNull(videoQueryParam.getPageNo()) && Objects.nonNull(videoQueryParam.getPageSize())) {
//分页
Pageable pageable = PageRequest.of(videoQueryParam.getPageNo() - 1, videoQueryParam.getPageSize());
Page<Video> all = videoRepository.findAll(condition(videoQueryParam), pageable);
List<VideoVo> data = all
.get()
.map(video -> {
.map(car -> {
VideoVo vo = new VideoVo();
BeanUtils.copyProperties(car, vo);
return vo;
})
.collect(Collectors.toList());
resultVo = PageVo.build(data, all.getTotalElements());
} else {
List<Video> all = videoRepository.findAll(condition(videoQueryParam), sort);
List<VideoVo> data = all
.stream()
.map(car -> {
VideoVo vo = new VideoVo();
BeanUtils.copyProperties(video, vo);
BeanUtils.copyProperties(car, vo);
return vo;
})
.collect(Collectors.toList());
PageVo<VideoVo> vo = PageVo.build(data, all.getTotalElements());
return Result.ok(vo);
resultVo = PageVo.build(data, data.size());
}
return Result.ok(resultVo);
}
/**
* 条件查询
*
* @param videoQueryParam 筛选条件
* @return Specification
*/
@Override
public Specification<Video> condition(VideoQueryParam videoQueryParam) {
return (root, query, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (StrUtils.isNotBlank(videoQueryParam.getVideoName())) {
list.add(
criteriaBuilder.like(
root.get("videoName").as(String.class),
"%" + videoQueryParam.getVideoName() + "%"
)
);
}
if (StrUtils.isNotBlank(videoQueryParam.getUuid())) {
list.add(
criteriaBuilder.like(root.get("uuid").as(String.class), "%" + videoQueryParam.getUuid() + "%")
);
}
if (StrUtils.isNotBlank(videoQueryParam.getStatus())) {
list.add(criteriaBuilder.equal(root.get("uuid").as(String.class), videoQueryParam.getStatus()));
}
// if (StrUtils.isNotBlank(videoQueryParam.getVideoName())) {
// list.add(
// criteriaBuilder.like(
// root.get("videoName").as(String.class),
// "%" + videoQueryParam.getVideoName() + "%"
// )
// );
// }
//
// if (StrUtils.isNotBlank(videoQueryParam.getUuid())) {
// list.add(
// criteriaBuilder.like(root.get("uuid").as(String.class), "%" + videoQueryParam.getUuid() + "%")
// );
// }
//
// if (StrUtils.isNotBlank(videoQueryParam.getStatus())) {
// list.add(criteriaBuilder.equal(root.get("status").as(String.class), videoQueryParam.getStatus()));
// }
Predicate[] predicates = new Predicate[list.size()];
query.where(list.toArray(predicates));
return criteriaBuilder.and(list.toArray(predicates));
};
}
@Override
public List<Video> exportVideo(VideoQueryParam videoQueryParam) {
return videoRepository.findAll(condition(videoQueryParam));
}
@Override
public Result<String> importVideo(String sheet, MultipartFile file, Integer titleRow) {
return null;
}
// @Override
// public Result<String> importVideo(String sheet, MultipartFile file, Integer titleRow) {
//// String s = gbCookie();
// ExcelUtils<Video> util = new ExcelUtils<>(Video.class);
// List<Video> videos = null;
// try {
// InputStream inputStream = file.getInputStream();
// if(titleRow==null){
// titleRow=0;
// }
// videos = util.importExcel(sheet, inputStream,titleRow);
// } catch (Exception e) {
// e.printStackTrace();
// }
// if (videos != null) {
// videos.forEach(video -> {
// videoRepository
// .findOne((root, cq, cb) -> {
// List<Predicate> predicates = new ArrayList<>();
//
// if (StringUtils.isNotBlank(video.getUuid())) {
// predicates.add(cb.equal(root.get("uuid").as(String.class), video.getUuid()));
// }
// return cq.where(predicates.toArray(new Predicate[0])).getRestriction();
// })
// .ifPresent(one -> {
// //如果存在则操作修改
// video.setId(one.getId());
// //删除国标关联监控信息
//// gbClient.proxyDel("stream", video.getUuid(),s);
// });
// videoRepository.saveAndFlush(video);
// //导入监控点位后,还需要同步数据到国标28181
//// StreamProxyItem streamProxyItem = StreamProxyItem
//// .builder()
//// .name(video.getVideoName())
//// .app("stream")
//// .stream(video.getUuid())
//// .url(video.getM3u8())
//// .mediaServerId("ZbnQN5csqxrPix7a")
//// .enable(true)
//// .enable_hls(true)
//// .type(video.getM3u8().contains("sss") ? "default" : "ffmpeg")
//// .timeout_ms(video.getM3u8().contains("sss") ? 60 : null)
//// .build();
//// JSONObject jsonObject = gbClient.proxySave(streamProxyItem, gbCookie());
//// System.out.println(jsonObject);
// });
// }
// return Result.ok();
// }
boolean has(String uuid) {
Video video = Video.builder().uuid(uuid).build();
return videoRepository.count(Example.of(video)) > 0;
}
// //登录国标28181获取cookie
// String gbCookie() {
// Response response = gbClient.userLogin("admin", "21232f297a57a5a743894a0e4a801fc3");
// Collection<String> strings = response.headers().get("Set-Cookie");
// return strings.stream().filter(a -> a.contains("JSESSIONID")).collect(Collectors.joining(", "));
// }
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论