fix:优化主动拍照定时通知

dev
郭承 9 months ago
parent 600248817a
commit 9e56ed8515

@ -44,7 +44,5 @@ public interface TerminalChannelMapperDao {
int updateByPrimaryKey(TerminalChannelMapper record);
TerminalChannelMapper selectByTermIdAndChannelId(@Param("termId") Integer termId, @Param("channelId") Integer channelId);
}

@ -320,11 +320,4 @@
</if>
</select>
<select id="selectByTermIdAndChannelId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from terminal_channel_mapper
where term_id = #{termId} and channel_id = #{channelId}
</select>
</mapper>

@ -1,10 +1,14 @@
package com.shxy.xymanager_framework.timeTask;
import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.entity.TerminalChannelMapper;
import com.shxy.xymanager_common.entity.TerminalChannelMapperExample;
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.TermSetServiceImpl;
import com.shxy.xymanager_service.service.NewCacheService;
import com.shxy.xymanager_service.service.TerminalPhotoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +18,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Component
@ -21,41 +26,50 @@ import java.util.Map;
public class TermChannelTask {
@Autowired
TerminalPhotoService terminalPhotoService;
TerminalChannelMapperDao terminalChannelMapperDao;
@Autowired
NewCacheService newCacheService;
@Resource
WebSocketServer webSocketServer;
//超时时间 分钟 5
Integer overtime = 1;
Integer overtime = 5;
//创建记录主动拍照参数
// public static Map<String , TermChannelModel> termChannelModelMap = new HashMap<>();
@Scheduled(fixedDelay = 10000)
@Scheduled(fixedDelay = 30000)
public void queryTermChannelTime() {
Map<String , TermChannelModel> termChannelModelMap = TermSetServiceImpl.termChannelModelMap;
//获取当前系统时间
Long time = System.currentTimeMillis();
if ( !termChannelModelMap.isEmpty() ) {
Iterator<String> iterator = termChannelModelMap.keySet().iterator();
if (!TermSetServiceImpl.termChannelModelMap.isEmpty()) {
Iterator<String> iterator = TermSetServiceImpl.termChannelModelMap.keySet().iterator();
while ( iterator.hasNext() ) {
while (iterator.hasNext()) {
String key = iterator.next();
TermChannelModel model = termChannelModelMap.get(key);
TermChannelModel model = TermSetServiceImpl.termChannelModelMap.get(key);
//开始拍照的时间 + 5分钟
Long currentTime = model.getCurrentTime() + ( overtime * 60 * 1000);
if ( time >= currentTime ) {
Long currentTime = model.getCurrentTime() + (overtime * 60 * 1000);
if (System.currentTimeMillis() >= currentTime) {
iterator.remove();
} else {
//调用查询最新照片
Terminals terminals = terminalPhotoService.getTakePicPhotoStatus(model).getData();
if ( terminals.checkInclude() ) {
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);
if (terminalChannelMappers.size() > 0) {
Long photoTime = terminalChannelMappers.get(0).getPhotoTime().longValue();
if (photoTime > model.getPhotoTime()) {
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
Terminals terminals = terminalMap.get(model.getTermId());
String str = "装置:" + terminals.getCmdid() + " 在通道" + model.getChannelId() + "拍的最新图片已上传";
webSocketServer.sendNotice("photo",str);
// System.out.println(str);
webSocketServer.sendNotice("photo", str);
iterator.remove();
}
}
}

@ -8,10 +8,7 @@ import com.alibaba.fastjson.JSONObject;
import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.constant.Constants;
import com.shxy.xymanager_common.dto.PhotoTimeResultDto;
import com.shxy.xymanager_common.entity.RequestResults;
import com.shxy.xymanager_common.entity.Resolution;
import com.shxy.xymanager_common.entity.TerminalChannelMapper;
import com.shxy.xymanager_common.entity.Terminals;
import com.shxy.xymanager_common.entity.*;
import com.shxy.xymanager_common.enums.CommonStatus;
import com.shxy.xymanager_common.exception.Asserts;
import com.shxy.xymanager_common.model.*;
@ -129,11 +126,19 @@ public class TermSetServiceImpl implements TermSetService {
Integer channelId = vo.getChannelId();
//获取当前系统时间
Long currentTime = System.currentTimeMillis();
//根据当前的装置id和通道id查询当前最新的图片时间
TerminalChannelMapper terminalChannelMapper = terminalChannelMapperDao.selectByTermIdAndChannelId(termId, channelId);
Long photoTime = terminalChannelMapper.getPhotoTime().longValue();
TerminalChannelMapperExample terminalChannelMapperExample = new TerminalChannelMapperExample();
TerminalChannelMapperExample.Criteria criteria = terminalChannelMapperExample.createCriteria();
criteria.andTermIdEqualTo(termId);
criteria.andChannelIdEqualTo(channelId.byteValue());
//根据当前的装置id和通道id查询当前最新的图片时间
List<TerminalChannelMapper> terminalChannelMappers = terminalChannelMapperDao.selectByExample(terminalChannelMapperExample);
if ( terminalChannelMappers.size() > 0 ) {
Long photoTime = terminalChannelMappers.get(0).getPhotoTime().longValue();
termChannelModelMap.put(termId + "_" + channelId, new TermChannelModel(termId, channelId, photoTime, currentTime));
}
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
Terminals terminals = terminalMap.get(termId);

@ -1031,30 +1031,4 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
return result;
}
@Override
public ServiceBody<Terminals> getTakePicPhotoStatus(TermChannelModel model) {
Boolean hasNew = false;
Integer termId = model.getTermId();
Integer channelId = model.getChannelId();
Long photoTime = model.getPhotoTime();
if ( null == photoTime ) {
Asserts.fail("查询时间不能缺少");
}
TerminalChannelMapper mapper = terminalChannelMapperDao.selectByTermIdAndChannelId(termId, channelId);
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
Terminals terminals = terminalMap.get(termId);
if ( null != mapper ) {
if (mapper.getPhotoTime().longValue() > photoTime) {
hasNew = true;
}
}
terminals.setChecked(hasNew);
return Asserts.success(terminals);
}
}

@ -117,10 +117,5 @@ public interface TerminalPhotoService {
ServiceBody<String> takeAlarm(TerminalPhotoTestVo vo);
/**
*
* @param model
* @return
*/
ServiceBody<Terminals> getTakePicPhotoStatus(TermChannelModel model);
}

Loading…
Cancel
Save