Browse Source

定时任务

platform-api
4670101279 2 years ago
parent
commit
97d8014087
  1. 13
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java
  2. 44
      ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/ScImageUploadAlarm.java
  3. 18
      ruoyi-code/src/main/java/com/ruoyi/code/camera/mapper/ScImageUploadAlarmMapper.java
  4. 2
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/ICameraService.java
  5. 21
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/IScImageUploadAlarmService.java
  6. 17
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraServiceImpl.java
  7. 33
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/ScImageUploadAlarmServiceImpl.java
  8. 59
      ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java

13
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java

@ -126,18 +126,7 @@ public class CameraController extends BaseController @@ -126,18 +126,7 @@ public class CameraController extends BaseController
@RequestMapping("reboot/{id}")
public R reboot(@PathVariable("id") Long id){
Camera c = cameraService.getById(id);
if(StringUtils.isNotBlank(c.getLoginId())) {
System.out.println("reboot loginID:"+c.getLoginId());
NativeLong nl = new NativeLong(Long.parseLong(c.getLoginId()));
boolean result = CameraUtil.deal(nl);
if(result){
c.setLoginId("");
c.setStatus(0);
cameraService.updateById(c);
return R.ok("设备重启成功,请等待几分钟后重新使用");
}
}
return R.error("设备重启失败");
return cameraService.rebootByLoginId(c);
}

44
ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/ScImageUploadAlarm.java

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
package com.ruoyi.code.camera.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.IdType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ruoyi.common.annotation.Excel;
import java.io.Serializable;
import lombok.Data;
/**
* 图片上传预警对象 sc_image_upload_alarm
*
* @author ruoyi
* @date 2022-07-11
*/
@Data
@TableName("sc_image_upload_alarm")
public class ScImageUploadAlarm implements Serializable
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
@TableId(type = IdType.INPUT)
private Long id;
/** 摄像头序列好号 */
private String cameraSn;
/** 图片最新上传时间 */
private Date latestUploadTime;
/** 预警标识,0正常,1预警 */
private String flag;
/** 入库时间 */
private Date insertTime;
}

18
ruoyi-code/src/main/java/com/ruoyi/code/camera/mapper/ScImageUploadAlarmMapper.java

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
package com.ruoyi.code.camera.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.code.camera.domain.ScImageUploadAlarm;
/**
* Mapper接口
*
* @author ruoyi
* @date 2022-07-11
*/
@Mapper
public interface ScImageUploadAlarmMapper extends BaseMapper<ScImageUploadAlarm>
{
}

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

@ -22,6 +22,8 @@ public interface ICameraService extends IService<Camera> @@ -22,6 +22,8 @@ public interface ICameraService extends IService<Camera>
R register();
R rebootByLoginId(Camera c);
R outLine();
void online(String ip,int port,String username,String password,String devsn,String loginID);

21
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/IScImageUploadAlarmService.java

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
package com.ruoyi.code.camera.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.page.R;
import java.util.Map;
import com.ruoyi.code.camera.domain.ScImageUploadAlarm;
/**
* Service接口
*
* @author ruoyi
* @date 2022-07-11
*/
public interface IScImageUploadAlarmService extends IService<ScImageUploadAlarm>
{
/**
* 查询
*/
R queryPage(Map<String, Object> params);
}

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

@ -11,6 +11,7 @@ import com.ruoyi.code.camera.service.ICameraService; @@ -11,6 +11,7 @@ import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.utils.StringUtils;
import com.sun.jna.NativeLong;
import org.springframework.stereotype.Service;
import utils.CameraUtil;
import utils.RegisterUtil;
import java.util.Date;
@ -62,6 +63,22 @@ public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> impleme @@ -62,6 +63,22 @@ public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> impleme
return R.error("服务启动失败");
}
@Override
public R rebootByLoginId(Camera c){
if(StringUtils.isNotBlank(c.getLoginId())) {
System.out.println("reboot loginID:"+c.getLoginId());
NativeLong nl = new NativeLong(Long.parseLong(c.getLoginId()));
boolean result = CameraUtil.deal(nl);
if(result){
c.setLoginId("");
c.setStatus(0);
updateById(c);
return R.ok("设备重启成功,请等待几分钟后重新使用");
}
}
return R.error("设备重启失败");
}
@Override
public R outLine(){
//清空所有摄像机状态

33
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/ScImageUploadAlarmServiceImpl.java

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
package com.ruoyi.code.camera.service.impl;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.Query;
import org.springframework.stereotype.Service;
import com.ruoyi.code.camera.mapper.ScImageUploadAlarmMapper;
import com.ruoyi.code.camera.domain.ScImageUploadAlarm;
import com.ruoyi.code.camera.service.IScImageUploadAlarmService;
/**
* Service业务层处理
*
* @author ruoyi
* @date 2022-07-11
*/
@Service("scImageUploadAlarmService")
public class ScImageUploadAlarmServiceImpl extends ServiceImpl<ScImageUploadAlarmMapper, ScImageUploadAlarm> implements IScImageUploadAlarmService
{
@Override
public R queryPage(Map<String, Object> params) {
IPage<ScImageUploadAlarm> page = this.page(
new Query<ScImageUploadAlarm>().getPage(params),
new QueryWrapper<ScImageUploadAlarm>()
);
return R.ok().put("count", page.getTotal()).put("data", page.getRecords());
}
}

59
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java

@ -2,7 +2,11 @@ package com.ruoyi.quartz.task; @@ -2,7 +2,11 @@ package com.ruoyi.quartz.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.domain.ScImageUploadAlarm;
import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.code.camera.service.IScImageUploadAlarmService;
import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.BeanUtil;
import com.sun.jna.NativeLong;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
@ -18,8 +22,6 @@ import java.util.List; @@ -18,8 +22,6 @@ import java.util.List;
@Component("ryTask")
public class RyTask
{
private ICameraService cameraService;
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
{
@ -36,7 +38,9 @@ public class RyTask @@ -36,7 +38,9 @@ public class RyTask
System.out.println("执行无参方法");
}
//定时获取4G信号强度
public void netRssiServer(){
ICameraService cameraService = BeanUtil.getBean(ICameraService.class);
List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("status","1").isNotNull("login_id"));
for (Camera c : list) {
@ -44,6 +48,57 @@ public class RyTask @@ -44,6 +48,57 @@ public class RyTask
c.setRssiLevel(level);
}
cameraService.updateBatchById(list);
}
//定时重启摄像机
public void rebootCamera(){
ICameraService cameraService = BeanUtil.getBean(ICameraService.class);
List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("status","1").isNotNull("login_id"));
for (Camera c : list) {
cameraService.rebootByLoginId(c);
sleep(10);
}
}
//重启注册服务
public void restartServer(){
ICameraService cameraService = BeanUtil.getBean(ICameraService.class);
List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("status","1").ne("login_id","").isNotNull("login_id"));
if(list.isEmpty()){
cameraService.register();
}
}
private static void sleep(int nTime)
{
try {
Thread.sleep(nTime * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//检测图片是否正常上次,未上传重启摄像机
public void checkCameraUpload(){
IScImageUploadAlarmService scImageUploadAlarmService = BeanUtil.getBean(IScImageUploadAlarmService.class);
ICameraService cameraService = BeanUtil.getBean(ICameraService.class);
List<ScImageUploadAlarm> alarms = scImageUploadAlarmService.list(new QueryWrapper<ScImageUploadAlarm>().eq("flag","1"));
for (ScImageUploadAlarm alarm : alarms) {
Camera c = cameraService.getOne(new QueryWrapper<Camera>().eq("devsn",alarm.getCameraSn()).eq("status","1").ne("login_id","").isNotNull("login_id"));
if(c != null){
System.out.println(c);
R result = cameraService.rebootByLoginId(c);
System.out.println(result);
sleep(10);
}
alarm.setFlag("0");
}
if(!alarms.isEmpty()){
scImageUploadAlarmService.updateBatchById(alarms);
}
}
}

Loading…
Cancel
Save