|
@@ -1,27 +1,29 @@
|
|
|
package com.sckj.device.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.github.yulichang.query.MPJQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sckj.camera.manager.CameraProperties;
|
|
|
import com.sckj.common.TapholeAdminThreadLocal;
|
|
|
import com.sckj.common.core.AjaxResult;
|
|
|
+import com.sckj.common.exception.OperateException;
|
|
|
import com.sckj.common.validate.commons.PageValidate;
|
|
|
-import com.sckj.device.service.ITCameraService;
|
|
|
import com.sckj.device.validate.TCameraCreateValidate;
|
|
|
+import com.sckj.device.validate.TCameraUpdateDTO;
|
|
|
import com.sckj.device.validate.TCameraUpdateValidate;
|
|
|
import com.sckj.device.validate.TCameraSearchValidate;
|
|
|
+import com.sckj.device.vo.CameraDTO;
|
|
|
import com.sckj.device.vo.TCameraListedVo;
|
|
|
import com.sckj.device.vo.TCameraDetailVo;
|
|
|
-import com.sckj.common.config.GlobalConfig;
|
|
|
import com.sckj.common.core.PageResult;
|
|
|
import com.sckj.device.entity.TCamera;
|
|
|
import com.sckj.device.mapper.TCameraMapper;
|
|
|
-import com.sckj.common.util.ListUtils;
|
|
|
-import com.sckj.common.util.TimeUtils;
|
|
|
-import com.sckj.common.util.UrlUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -29,43 +31,45 @@ import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 摄像头实现类
|
|
|
+ *
|
|
|
* @author zhanghao
|
|
|
*/
|
|
|
@Service
|
|
|
-public class TCameraServiceImpl implements ITCameraService {
|
|
|
-
|
|
|
+public class TCameraServiceImpl extends ServiceImpl<TCameraMapper, TCamera> {
|
|
|
+
|
|
|
@Resource
|
|
|
TCameraMapper tCameraMapper;
|
|
|
|
|
|
/**
|
|
|
* 摄像头列表
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
- * @param pageValidate 分页参数
|
|
|
+ * @param pageValidate 分页参数
|
|
|
* @param searchValidate 搜索参数
|
|
|
* @return PageResult<TCameraListedVo>
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public PageResult<TCameraListedVo> list(PageValidate pageValidate, TCameraSearchValidate searchValidate) {
|
|
|
- Integer page = pageValidate.getPageNo();
|
|
|
+ Integer page = pageValidate.getPageNo();
|
|
|
Integer limit = pageValidate.getPageSize();
|
|
|
|
|
|
QueryWrapper<TCamera> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.orderByDesc("id");
|
|
|
|
|
|
tCameraMapper.setSearch(queryWrapper, searchValidate, new String[]{
|
|
|
- "=:no:str",
|
|
|
- "like:name:str",
|
|
|
- "=:model:str",
|
|
|
+ "=:no:str",
|
|
|
+ "like:name:str",
|
|
|
+ "=:model:str",
|
|
|
});
|
|
|
|
|
|
IPage<TCamera> iPage = tCameraMapper.selectPage(new Page<>(page, limit), queryWrapper.eq("type", "1"));
|
|
|
|
|
|
List<TCameraListedVo> list = new LinkedList<>();
|
|
|
- for(TCamera item : iPage.getRecords()) {
|
|
|
+ for (TCamera item : iPage.getRecords()) {
|
|
|
TCameraListedVo vo = new TCameraListedVo();
|
|
|
BeanUtils.copyProperties(item, vo);
|
|
|
list.add(vo);
|
|
@@ -77,16 +81,15 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
/**
|
|
|
* 摄像头详情
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param id 主键参数
|
|
|
* @return TCamera
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public TCameraDetailVo detail(Integer id) {
|
|
|
TCamera model = tCameraMapper.selectOne(
|
|
|
new QueryWrapper<TCamera>()
|
|
|
- .eq("id", id)
|
|
|
- .last("limit 1"));
|
|
|
+ .eq("id", id)
|
|
|
+ .last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在");
|
|
|
|
|
@@ -98,13 +101,12 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
/**
|
|
|
* 摄像头新增
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param createValidate 参数
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public int add(TCameraCreateValidate createValidate) {
|
|
|
TCamera model = new TCamera();
|
|
|
- if (!checkPortAndIp(createValidate.getPort(), createValidate.getIp())){
|
|
|
+ if (!checkPortAndIp(createValidate.getPort(), createValidate.getIp())) {
|
|
|
return 0;
|
|
|
}
|
|
|
model.setCreateTime(new Date(System.currentTimeMillis()));
|
|
@@ -125,19 +127,18 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
/**
|
|
|
* 摄像头编辑
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param updateValidate 参数
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public int edit(TCameraUpdateValidate updateValidate) {
|
|
|
TCamera model = tCameraMapper.selectOne(
|
|
|
new QueryWrapper<TCamera>()
|
|
|
- .eq("id", updateValidate.getId())
|
|
|
- .last("limit 1"));
|
|
|
+ .eq("id", updateValidate.getId())
|
|
|
+ .last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在!");
|
|
|
|
|
|
- if (!checkPortAndIp(updateValidate.getPort(), updateValidate.getIp())){
|
|
|
+ if (!checkPortAndIp(updateValidate.getPort(), updateValidate.getIp())) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -154,14 +155,14 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
return tCameraMapper.updateById(model);
|
|
|
}
|
|
|
|
|
|
- public boolean checkPortAndIp(String port, String ip){
|
|
|
- if (Integer.parseInt(port) > 65535 && Integer.parseInt(port) < 0){
|
|
|
+ public boolean checkPortAndIp(String port, String ip) {
|
|
|
+ if (Integer.parseInt(port) > 65535 && Integer.parseInt(port) < 0) {
|
|
|
return false;
|
|
|
}
|
|
|
String IP_PATTERN = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
|
|
|
Pattern pattern = Pattern.compile(IP_PATTERN);
|
|
|
Matcher matcher = pattern.matcher(ip);
|
|
|
- if (!matcher.matches()){
|
|
|
+ if (!matcher.matches()) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
@@ -170,15 +171,14 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
/**
|
|
|
* 摄像头删除
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param id 主键ID
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public void del(Integer id) {
|
|
|
TCamera model = tCameraMapper.selectOne(
|
|
|
new QueryWrapper<TCamera>()
|
|
|
- .eq("id", id)
|
|
|
- .last("limit 1"));
|
|
|
+ .eq("id", id)
|
|
|
+ .last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在!");
|
|
|
|
|
@@ -188,20 +188,93 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
/**
|
|
|
* 摄像头批量删除
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param ids 主键数组
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- @Override
|
|
|
public AjaxResult<Object> del_ex(List<Long> ids) {
|
|
|
List<TCamera> models = tCameraMapper.selectList(
|
|
|
new QueryWrapper<TCamera>()
|
|
|
.in("id", ids));
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(models)){
|
|
|
+ if (CollectionUtils.isEmpty(models)) {
|
|
|
return AjaxResult.failed("数据不存在");
|
|
|
}
|
|
|
tCameraMapper.delete(new QueryWrapper<TCamera>().in("id", ids));
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CameraProperties cameraProperties;
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> getCameraInfo() {
|
|
|
+ List<TCamera> cameraList = lambdaQuery().eq(TCamera::getType, "1").in(TCamera::getStatus, "1", "2").orderByAsc(TCamera::getSort).list();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<CameraDTO> collect = cameraList.stream().flatMap((item) -> {
|
|
|
+ CameraDTO dto = new CameraDTO();
|
|
|
+ BeanUtils.copyProperties(item, dto);
|
|
|
+ String channelNumberStr = 1 + "02"; //新通道(2012年之后设备,02代表子码流)
|
|
|
+ String rtspUrl = "rtsp://" + item.getAccount() + ":" + item.getPassword() + "@" + item.getIp() + ":" + item.getPortRtsp() + "/" + channelNumberStr + "?transportmode=unicast"; //新码流
|
|
|
+ dto.setRtspUrl(rtspUrl);
|
|
|
+ return Stream.of(dto);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ map.put("cameraList", collect);
|
|
|
+
|
|
|
+ List<CameraDTO> bannerList = new ArrayList<>();
|
|
|
+ for (CameraDTO cameraDTO : collect) {
|
|
|
+ if ("2".equals(cameraDTO.getStatus())) {
|
|
|
+ bannerList.add(cameraDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("bannerList", bannerList);
|
|
|
+ map.put("rtmpUrl", "http://" + cameraProperties.getRtmp().getWebrtchost());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> getCameraParamInfo() {
|
|
|
+ List<TCamera> cameraList = lambdaQuery().eq(TCamera::getType, "1").in(TCamera::getStatus, "1", "2").orderByAsc(TCamera::getSort).list();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<CameraDTO> collect = cameraList.stream().flatMap((item) -> {
|
|
|
+ CameraDTO dto = new CameraDTO();
|
|
|
+ BeanUtils.copyProperties(item, dto);
|
|
|
+ return Stream.of(dto);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<CameraDTO> normalList = new ArrayList<>();
|
|
|
+ List<CameraDTO> bannerList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (CameraDTO cameraDTO : collect) {
|
|
|
+ if ("1".equals(cameraDTO.getStatus())) {
|
|
|
+ normalList.add(cameraDTO);
|
|
|
+ }
|
|
|
+ if ("2".equals(cameraDTO.getStatus())) {
|
|
|
+ bannerList.add(cameraDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("normalList", normalList);
|
|
|
+ map.put("bannerList", bannerList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void updateBatchs(List<TCameraUpdateDTO> cameraList) {
|
|
|
+ for (TCameraUpdateDTO camera : cameraList) {
|
|
|
+ TCamera queryData = getById(camera.getId());
|
|
|
+ if (ObjectUtils.isEmpty(queryData)) {
|
|
|
+ throw new OperateException(String.format("传入的ID不存在:%s", camera.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<TCamera> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(TCamera::getId, camera.getId());
|
|
|
+ if (ObjectUtils.isNotEmpty(camera.getStatus())) {
|
|
|
+ wrapper.set(TCamera::getStatus, camera.getStatus());
|
|
|
+ }
|
|
|
+ if (camera.getSort() != null) {
|
|
|
+ wrapper.set(TCamera::getSort, camera.getSort());
|
|
|
+ }
|
|
|
+ update(wrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|