新增定时任务

This commit is contained in:
wuweida 2022-05-25 08:59:16 +08:00
parent 70dd511f4e
commit e2e75fec3f
4 changed files with 355 additions and 3 deletions

View File

@ -0,0 +1,19 @@
package com.hisense.monitormanage.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("t_booth")
public class Booth {
private String serial;
private String area;
private String boothName;
private String location;
private String manageTime;
private String captureTime;
private String channelCode;
private String gpsX;
private String gpsY;
private String channelName;
}

View File

@ -0,0 +1,13 @@
package com.hisense.monitormanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisense.monitormanage.entity.Booth;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface BoothMapper extends BaseMapper<Booth> {
@Select("select * from t_booth where capture_time = #{captureTime}")
List<Booth> selectBooth(String captureTime);
}

View File

@ -67,6 +67,9 @@ public class MonitorService {
@Autowired
private ChannelPictureMapper channelPictureMapper;
@Autowired
private BoothMapper boothMapper;
@Value("${hwx.file.work-path}")
private String fileDir;
@Value("${hwx.file.pic-host}")
@ -208,6 +211,318 @@ public class MonitorService {
}
}
@Scheduled(cron = "0 20 8 * * ? ")
public void screenShot3() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("8:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 50 8 * * ? ")
public void screenShot4() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("8:50");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 50 9 * * ? ")
public void screenShot5() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("9:50");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 20 11 * * ? ")
public void screenShot6() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("11:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 20 11 * * ? ")
public void screenShot7() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("11:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 20 12 * * ? ")
public void screenShot8() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("12:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 20 19 * * ? ")
public void screenShot9() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("19:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 20 20 * * ? ")
public void screenShot10() {
try {
log.info("[monitor-capture]: start capture1");
List<Booth> labels = boothMapper.selectBooth("20:20");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
BufferedImage bufferedImage = capturecreenshot(channelCode);
String fileName = channelCode + ".jpg";
ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName));
String picUrl = picHost + "/images/" + fileName;
ChannelPicture picture = new ChannelPicture();
picture.setChannelCode(channelCode);
picture.setPicUrl(picUrl);
/*picture.setInsertTime(new Date());
channelPictureMapper.insert(picture);*/
if (channelCode == null){
channelPictureMapper.insert(picture);
}else {
QueryWrapper<ChannelPicture> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("channel_code", channelCode);
picture.setInsertTime(new Date());
channelPictureMapper.update(picture, queryWrapper);
}
}catch (Exception e){
log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage());
}
});
log.info("[monitor-capture]: end capture1");
}catch (Exception exception){
exception.printStackTrace();
}
}
@Scheduled(cron = "0 0 8 1/1 * ?")
public void screenShot1() {
@ -215,7 +530,7 @@ public class MonitorService {
log.info("[monitor-capture]: start capture1");
List<ChannelLabelDto> labels = cameraChannelMapper.selectLabelAndChannel("1009,1008");
List<ChannelLabelDto> labels = cameraChannelMapper.selectLabelAndChannel("'',1008");
labels.forEach(label -> {
String channelCode = label.getChannelCode();
try {
@ -444,9 +759,9 @@ public class MonitorService {
Boolean isParent = (Boolean) result.get("isParent");
if (isParent){
CameraOrganization cameraOrganization = JSONObject.parseObject(JSONObject.toJSONString(result), CameraOrganization.class);
/*CameraOrganization cameraOrganization = JSONObject.parseObject(JSONObject.toJSONString(result), CameraOrganization.class);
cameraOrgenMapper.insert(cameraOrganization);
cameraOrgenMapper.insert(cameraOrganization);*/
videoService((String) result.get("id"),path + sep + result.get("name"));
}else {

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hisense.monitormanage.mapper.BoothMapper">
</mapper>