Browse Source

youhua

master
4670101279 2 years ago
parent
commit
ba3853b57c
  1. 6
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/ApiController.java
  2. 32
      ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java
  3. 2
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/ICameraService.java
  4. 42
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraServiceImpl.java
  5. 13
      ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

6
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/ApiController.java

@ -214,4 +214,10 @@ public class ApiController extends BaseController
cameraNetFtp.setLoginId(camera.getLoginId()); cameraNetFtp.setLoginId(camera.getLoginId());
return cameraNetFtpService.editNetCfg(cameraNetFtp); return cameraNetFtpService.editNetCfg(cameraNetFtp);
} }
@RequestMapping("/pullRtspPhoto")
public R pullRtspPhoto(){
cameraService.pullRtspPhoto();
return R.ok();
}
} }

32
ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java

@ -1,24 +1,12 @@
package com.ruoyi.code.camera.scheduled; package com.ruoyi.code.camera.scheduled;
import cn.hutool.core.util.RuntimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.domain.CameraBrand;
import com.ruoyi.code.camera.service.ICameraBrandService;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Component @Component
@Configuration @Configuration
@EnableScheduling @EnableScheduling
@ -27,26 +15,8 @@ public class RtspScreenshotTask {
@Autowired @Autowired
private ICameraService cameraService; private ICameraService cameraService;
@Autowired
private ICameraBrandService iCameraBrandService;
@Scheduled(cron = "0 0/5 * * * ?") @Scheduled(cron = "0 0/5 * * * ?")
public void rtspScreenshot(){ public void rtspScreenshot(){
String path = RuoYiConfig.getProfile() + File.separator; cameraService.pullRtspPhoto();
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + File.separator;
String currentTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) + ".jpg";
List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("access_type","1"));
for (Camera camera : list) {
CameraBrand cameraBrand = iCameraBrandService.getById(camera.getBrand());
String fileName = path+camera.getDevsn()+File.separator+currentDate;
File file = new File(fileName);
if (!file.exists()) {
file.mkdirs();
}
String ffmpeg = "ffmpeg -i \"rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+"\" -y -f image2 -t 0.001 \""+fileName+currentTime+"\"";
if(HttpUtils.checkPing(camera.getIp())){
RuntimeUtil.execForStr(ffmpeg);
}
}
} }
} }

2
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/ICameraService.java

@ -33,4 +33,6 @@ public interface ICameraService extends IService<Camera>
List<Camera> getCameraList(); List<Camera> getCameraList();
Camera getCameraBySid(Long sid); Camera getCameraBySid(Long sid);
void pullRtspPhoto();
} }

42
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraServiceImpl.java

@ -1,20 +1,28 @@
package com.ruoyi.code.camera.service.impl; package com.ruoyi.code.camera.service.impl;
import cn.hutool.core.util.RuntimeUtil;
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.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.camera.domain.CameraBrand;
import com.ruoyi.code.camera.service.ICameraBrandService;
import com.ruoyi.code.sctaationinfo.domain.ScStationInfo; import com.ruoyi.code.sctaationinfo.domain.ScStationInfo;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.page.R; import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.Query; import com.ruoyi.common.utils.Query;
import com.ruoyi.code.camera.domain.Camera; import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.mapper.CameraMapper; import com.ruoyi.code.camera.mapper.CameraMapper;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.sun.jna.NativeLong; import com.sun.jna.NativeLong;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import utils.CameraUtil; import utils.CameraUtil;
import utils.RegisterUtil; import utils.RegisterUtil;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,6 +37,9 @@ import java.util.Map;
public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> implements ICameraService public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> implements ICameraService
{ {
@Autowired
private ICameraBrandService iCameraBrandService;
@Override @Override
public R queryPage(Map<String, Object> params) { public R queryPage(Map<String, Object> params) {
IPage<Camera> page = baseMapper.queryPage( IPage<Camera> page = baseMapper.queryPage(
@ -144,4 +155,35 @@ public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> impleme
public Camera getCameraBySid(Long sid) { public Camera getCameraBySid(Long sid) {
return baseMapper.queryCameraBYSid(sid); return baseMapper.queryCameraBYSid(sid);
} }
@Override
public void pullRtspPhoto(){
String path = RuoYiConfig.getProfile() + File.separator;
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + File.separator;
String currentTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) + ".jpg";
List<Camera> list = list(new QueryWrapper<Camera>().eq("access_type","1"));
for (Camera camera : list) {
boolean isPing = HttpUtils.checkPing(camera.getIp());
System.out.println(camera.getIp()+" isPing = "+isPing);
if(isPing){
camera.setStatus(1);
CameraBrand cameraBrand = iCameraBrandService.getById(camera.getBrand());
String fileName = path+camera.getDevsn()+File.separator+currentDate;
File file = new File(fileName);
if (!file.exists()) {
file.mkdirs();
}
String ffmpeg = "ffmpeg -i rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+" -y -f image2 -t 0.001 "+fileName+currentTime+"";
System.out.println("ffmpeg="+ffmpeg);
RuntimeUtil.execForStr(ffmpeg);
}else{
camera.setStatus(0);
}
}
if(!list.isEmpty()){
updateBatchById(list);
}
System.out.println("ffmpeg 执行结束");
}
} }

13
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

@ -11,6 +11,7 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
@ -276,11 +277,17 @@ public class HttpUtils
} }
} }
private final static Pattern PATTERN= Pattern.compile("(\\d+ms)(\\s+)(TTL=\\d+)", Pattern.CASE_INSENSITIVE); private final static Pattern PATTERN= Pattern.compile("(\\d+ms)(\\s+)(ttl=\\d+)", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN2= Pattern.compile("(ttl=\\d+)", Pattern.CASE_INSENSITIVE);
public static boolean checkPing(String ip) { public static boolean checkPing(String ip) {
//若line含有=18ms TTL=16字样,说明已经ping通,返回true,否則返回false. //若line含有=18ms TTL=16字样,说明已经ping通,返回true,否則返回false.
String result = RuntimeUtil.execForStr("ping " + ip + " -n 2 -w 2000"); String cmd = "ping " + ip + " -c 2 -w 2000";
Matcher matcher = PATTERN.matcher(result); String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")){
cmd = "ping " + ip + " -n 2 -w 2000";
}
String result = RuntimeUtil.execForStr(cmd);
Matcher matcher = PATTERN2.matcher(result);
if (matcher.find()) { if (matcher.find()) {
return true; return true;
} }

Loading…
Cancel
Save