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

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

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

@ -320,11 +320,4 @@
</if> </if>
</select> </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> </mapper>

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

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

@ -1031,30 +1031,4 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
return result; 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); ServiceBody<String> takeAlarm(TerminalPhotoTestVo vo);
/**
*
* @param model
* @return
*/
ServiceBody<Terminals> getTakePicPhotoStatus(TermChannelModel model);
} }

Loading…
Cancel
Save