feat:主动拍照增加定时任务推送通知
parent
c30c5291bf
commit
09868ce503
@ -0,0 +1,28 @@
|
||||
package com.shxy.xymanager_common.model;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "记录拍照装置通道信息", description = "记录拍照装置通道信息描述")
|
||||
public class TermChannelModel implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "装置id", example = "123456")
|
||||
private Integer termId;
|
||||
|
||||
@ApiModelProperty(value = "通道id", example = "123456")
|
||||
private Integer channelId;
|
||||
|
||||
@ApiModelProperty(value = "拍照时间", example = "123456")
|
||||
private Long photoTime;
|
||||
|
||||
@ApiModelProperty(value = "当前时间", example = "123456")
|
||||
private Long currentTime;
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
|
||||
package com.shxy.xymanager_framework.timeTask;
|
||||
|
||||
import com.shxy.xymanager_common.entity.TerminalChannelMapper;
|
||||
import com.shxy.xymanager_common.entity.Terminals;
|
||||
import com.shxy.xymanager_common.model.TermChannelModel;
|
||||
import com.shxy.xymanager_dao.dao.TerminalChannelMapperDao;
|
||||
import com.shxy.xymanager_framework.socket.WebSocketServer;
|
||||
import com.shxy.xymanager_service.impl.TerminalPhotoServiceImpl;
|
||||
import com.shxy.xymanager_service.service.CacheService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TermChannelTask {
|
||||
|
||||
@Autowired
|
||||
TerminalChannelMapperDao terminalChannelMapperDao;
|
||||
|
||||
@Autowired
|
||||
CacheService cacheService;
|
||||
|
||||
@Resource
|
||||
WebSocketServer webSocketServer;
|
||||
|
||||
// 超时时间 分钟 5
|
||||
Integer overtime = 5;
|
||||
|
||||
// 创建记录主动拍照参数
|
||||
// public static Map<String , TermChannelModel> termChannelModelMap = new HashMap<>();
|
||||
|
||||
@Scheduled(fixedDelay = 30000)
|
||||
public void queryTermChannelTime() {
|
||||
if (!TerminalPhotoServiceImpl.termChannelModelMap.isEmpty()) {
|
||||
Iterator<String> iterator = TerminalPhotoServiceImpl.termChannelModelMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
TermChannelModel model = TerminalPhotoServiceImpl.termChannelModelMap.get(key);
|
||||
// 开始拍照的时间 + 5分钟
|
||||
Long currentTime = model.getCurrentTime() + (overtime * 60 * 1000);
|
||||
if (System.currentTimeMillis() >= currentTime) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
// TerminalChannelMapperExample terminalChannelMapperExample = new TerminalChannelMapperExample();
|
||||
// TerminalChannelMapperExample.Criteria criteria = terminalChannelMapperExample.createCriteria();
|
||||
// criteria.andTermIdEqualTo(model.getTermId());
|
||||
// criteria.andChannelIdEqualTo(model.getChannelId().byteValue());
|
||||
// 根据当前的装置id和通道id查询最新的图片时间
|
||||
// List<TerminalChannelMapper> terminalChannelMappers = terminalChannelMapperDao.selectByExample(terminalChannelMapperExample);
|
||||
TerminalChannelMapper terminalChannelMapper = terminalChannelMapperDao.selectByTermIdAndChannelId(model.getTermId(), model.getChannelId());
|
||||
if (null != terminalChannelMapper) {
|
||||
if (null != terminalChannelMapper.getPhotoTime()) {
|
||||
Long photoTime = terminalChannelMapper.getPhotoTime().longValue();
|
||||
if (photoTime > model.getPhotoTime()) {
|
||||
Map<Integer, Terminals> terminalMap = cacheService.getTerminalMap();
|
||||
Terminals terminals = terminalMap.get(model.getTermId());
|
||||
String str = "装置:" + terminals.getCmdid() + " 在通道" + model.getChannelId() + "拍的最新图片已上传";
|
||||
webSocketServer.sendNotice("photo", str);
|
||||
System.out.println(str);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue