|
@@ -0,0 +1,246 @@
|
|
|
+package com.huimv.admin.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.huimv.admin.common.utils.Result;
|
|
|
+import com.huimv.admin.common.utils.ResultCode;
|
|
|
+import com.huimv.admin.entity.SysCamera;
|
|
|
+import com.huimv.admin.entity.SysCameraBrand;
|
|
|
+import com.huimv.admin.entity.vo.*;
|
|
|
+import com.huimv.admin.mapper.SysCameraAreaMapper;
|
|
|
+import com.huimv.admin.mapper.SysCameraBrandMapper;
|
|
|
+import com.huimv.admin.mapper.SysCameraMapper;
|
|
|
+import com.huimv.admin.service.ISysCameraService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author author
|
|
|
+ * @since 2023-06-01
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SysCameraServiceImpl extends ServiceImpl<SysCameraMapper, SysCamera> implements ISysCameraService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysCameraMapper cameraBaseMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysCameraAreaMapper cameraAreaMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysCameraBrandMapper cameraBrandMapper;
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// private BaseScreenCameraAccountMapper cameraAccountMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listPage(CameraListVo cameraListVo) {
|
|
|
+ Integer current = cameraListVo.getCurrent();
|
|
|
+ String strchStr = cameraListVo.getStrchStr();
|
|
|
+ Integer size = cameraListVo.getSize();
|
|
|
+ Integer areaId = cameraListVo.getAreaId();
|
|
|
+ Integer brandId = cameraListVo.getBrandId();
|
|
|
+ Integer sort = cameraListVo.getSort();
|
|
|
+ Integer farmId = cameraListVo.getFarmId();
|
|
|
+ Integer isOnline = cameraListVo.getIsOnline();
|
|
|
+
|
|
|
+ QueryWrapper<SysCamera> wrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(strchStr)) {
|
|
|
+ wrapper.and(i -> i.like("camera_name", strchStr)
|
|
|
+ .or().like("camera_ip", strchStr));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (farmId != null) {
|
|
|
+ wrapper.eq("farm_id", farmId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (areaId != null) {
|
|
|
+ wrapper.eq("area_id", areaId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (brandId != null) {
|
|
|
+ wrapper.eq("brand_id", brandId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isOnline != null) {
|
|
|
+ wrapper.eq("is_online", isOnline);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sort == null) {
|
|
|
+ wrapper.orderByDesc("id");
|
|
|
+ } else if (sort == 1) {
|
|
|
+ wrapper.orderByDesc("sort");
|
|
|
+ } else {
|
|
|
+ wrapper.orderByAsc("sort");
|
|
|
+ }
|
|
|
+// wrapper.orderByDesc("id");
|
|
|
+ return new Result(ResultCode.SUCCESS, page(new Page<>(current, size), wrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List getCameraDetails(CameraListsVo cameraListsVo) throws InterruptedException {
|
|
|
+ List<Integer> cameraIds = cameraListsVo.getCameraIds();
|
|
|
+ CameraListVo cameraListVo = new CameraListsVo();
|
|
|
+ cameraListVo.setCurrent(1);
|
|
|
+ cameraListVo.setSize(10000);
|
|
|
+ cameraListVo.setStrchStr(cameraListsVo.getStrchStr());
|
|
|
+ cameraListVo.setAreaId(cameraListsVo.getAreaId());
|
|
|
+ cameraListVo.setBrandId(cameraListsVo.getBrandId());
|
|
|
+ cameraListVo.setSort(cameraListsVo.getSort());
|
|
|
+
|
|
|
+ if (cameraIds == null || cameraIds.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List cameraDetailsList = new ArrayList();
|
|
|
+ IPage<SysCamera> page = (IPage<SysCamera>) this.listPage(cameraListVo).getData();
|
|
|
+ List<SysCamera> list = page.getRecords();
|
|
|
+ int i = 0;
|
|
|
+ final String farmAppPort = "8081";
|
|
|
+ final String farmVideoApp = "/appleVideo/play?";
|
|
|
+ final String hlsMediaPort = "85";
|
|
|
+ for (Integer cameraId : cameraIds) {
|
|
|
+ for (SysCamera camera : list) {
|
|
|
+ if (cameraId.equals(camera.getId())) {
|
|
|
+
|
|
|
+ String cameraAccount = camera.getAccount();
|
|
|
+ String cameraPassword = camera.getPassword();
|
|
|
+ String camerIp = camera.getCameraIp();
|
|
|
+ String cameraName = camera.getCameraName();
|
|
|
+ Integer areaId = camera.getAreaId();
|
|
|
+ String url = cameraAreaMapper.selectById(areaId).getPublicUrl();
|
|
|
+ String rtsp;
|
|
|
+ SysCameraBrand cameraBrand = cameraBrandMapper.selectById(camera.getBrandId());
|
|
|
+ Integer type = cameraBrand.getStreamType();
|
|
|
+ if (type == 0) {
|
|
|
+ rtsp = cameraBrand.getMainStream();
|
|
|
+ } else {
|
|
|
+ rtsp = cameraBrand.getAssistStream();
|
|
|
+ }
|
|
|
+ CameraVo cameraVo = new CameraVo();
|
|
|
+ cameraVo.setId(camera.getId());
|
|
|
+ cameraVo.setAreaId(areaId);
|
|
|
+
|
|
|
+ cameraVo.setWsUrl("ws://" + url + "/camera_relay?tcpaddr=" + cameraAccount + "%3A" + cameraPassword + "%40" + camerIp /*+ "/h265/ch1/main/av_stream"*/);
|
|
|
+ cameraVo.setRtspUrl("rtsp://" + cameraAccount + ":" + cameraPassword + "@" + camerIp + rtsp);
|
|
|
+
|
|
|
+ cameraVo.setCameraName(cameraName);
|
|
|
+ cameraVo.setHttpUrl(handleHlsHttpUrl(url,cameraAccount,cameraPassword,camerIp,farmAppPort,farmVideoApp,hlsMediaPort));
|
|
|
+ if (i > 0) {
|
|
|
+ cameraVo.setLastId(list.get(i - 1).getId());
|
|
|
+ }
|
|
|
+ if (i < list.size() - 1) {
|
|
|
+ cameraVo.setNextId(list.get(i + 1).getId());
|
|
|
+ }
|
|
|
+ cameraDetailsList.add(cameraVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return cameraDetailsList;
|
|
|
+ }
|
|
|
+
|
|
|
+ //构造HlsHttp地址
|
|
|
+ private String handleHlsHttpUrl(String url, String cameraAccount, String cameraPassword, String camerIp, String farmAppPort, String farmVideoApp, String hlsMediaPort) {
|
|
|
+ url = url.substring(0, url.indexOf(":"));
|
|
|
+ url = "http://" + url;
|
|
|
+ //return url+":"+farmAppPort+farmVideoApp+"url="+cameraAccount + ":" + cameraPassword + "@" + camerIp+"&name="+"&dt=3000&targetUrl="+url+":"+hlsMediaPort;
|
|
|
+ return url + ":" + farmAppPort + farmVideoApp + "url=" + cameraAccount + ":" + cameraPassword + "@" + camerIp + "&dt=3000&targetUrl=" + url + ":" + hlsMediaPort;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result add(SysCamera camera) {
|
|
|
+ Integer areaId = camera.getAreaId();
|
|
|
+ Integer brandId = camera.getBrandId();
|
|
|
+
|
|
|
+ int brandName = this.count(new QueryWrapper<SysCamera>().eq("camera_name", camera.getCameraName()).eq("farm_id", camera.getFarmId()));
|
|
|
+ if (brandName > 0) {
|
|
|
+ return new Result(10001, "摄像头名称重复", false);
|
|
|
+ }
|
|
|
+ if (areaId != null) {
|
|
|
+ camera.setAreaName(cameraAreaMapper.selectById(areaId).getAreaName());
|
|
|
+ }
|
|
|
+ if (brandId != null) {
|
|
|
+ camera.setBrandName(cameraBrandMapper.selectById(brandId).getBrandName());
|
|
|
+ }
|
|
|
+ this.save(camera);
|
|
|
+
|
|
|
+ return new Result(10000, "添加成功", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updates(SysCamera camera) {
|
|
|
+ Integer areaId = camera.getAreaId();
|
|
|
+ Integer brandId = camera.getBrandId();
|
|
|
+ this.updateById(camera);
|
|
|
+ int brandName = this.count(new QueryWrapper<SysCamera>().eq("camera_name", camera.getCameraName()));
|
|
|
+ if (brandName > 1) {
|
|
|
+ return new Result(10001, "摄像头名称重复", false);
|
|
|
+ }
|
|
|
+ if (areaId != null) {
|
|
|
+ camera.setAreaName(cameraAreaMapper.selectById(areaId).getAreaName());
|
|
|
+ }
|
|
|
+ if (brandId != null) {
|
|
|
+ camera.setBrandName(cameraBrandMapper.selectById(brandId).getBrandName());
|
|
|
+ }
|
|
|
+ this.updateById(camera);
|
|
|
+ return new Result(10000, "修改成功", true);
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public Result initCamera(Integer farmId, Integer userId) {
|
|
|
+// BaseScreenCameraAccount cameraAccount = cameraAccountMapper.selectOne(new QueryWrapper<BaseScreenCameraAccount>().eq("farm_id", farmId).eq("account_id", userId));
|
|
|
+// Integer cameraId;
|
|
|
+// if (ObjectUtil.isEmpty(cameraAccount)) {
|
|
|
+// cameraId = this.getOne(new QueryWrapper<SysCamera>().eq("run_status", 1).eq("farm_id", farmId).last("limit 1")).getId();
|
|
|
+// } else {
|
|
|
+// cameraId = cameraAccount.getCameraId();
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// SysCamera camera = this.getById(cameraId);
|
|
|
+// if (camera.getRunStatus() == 0) {
|
|
|
+// return new Result(10001, "该摄像头已经被禁用", false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// return new Result(ResultCode.SUCCESS, getCameraVo(camera));
|
|
|
+// }
|
|
|
+
|
|
|
+ public CameraVo getCameraVo(SysCamera camera) {
|
|
|
+
|
|
|
+ String cameraAccount = camera.getAccount();
|
|
|
+ String cameraPassword = camera.getPassword();
|
|
|
+ String camerIp = camera.getCameraIp();
|
|
|
+ String cameraName = camera.getCameraName();
|
|
|
+ Integer areaId = camera.getAreaId();
|
|
|
+ String url = cameraAreaMapper.selectById(areaId).getPublicUrl();
|
|
|
+
|
|
|
+ String rtsp;
|
|
|
+ SysCameraBrand cameraBrand = cameraBrandMapper.selectById(camera.getBrandId());
|
|
|
+ Integer type = cameraBrand.getStreamType();
|
|
|
+ if (type == 0) {
|
|
|
+ rtsp = cameraBrand.getMainStream();
|
|
|
+ } else {
|
|
|
+ rtsp = cameraBrand.getAssistStream();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ CameraVo cameraVo = new CameraVo();
|
|
|
+ cameraVo.setAreaId(areaId);
|
|
|
+
|
|
|
+ cameraVo.setWsUrl("ws://" + url + "/camera_relay?tcpaddr=" + cameraAccount + "%3A" + cameraPassword + "%40" + camerIp);
|
|
|
+ cameraVo.setRtspUrl("rtsp://" + cameraAccount + ":" + cameraPassword + "@" + camerIp + rtsp);
|
|
|
+ cameraVo.setCameraName(cameraName);
|
|
|
+ return cameraVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|