feat:主动拍照增加定时任务推送通知

hunan
郭承 9 months ago
parent c30c5291bf
commit 09868ce503

@ -46,7 +46,7 @@ public class TerminalPhotoController extends BaseController {
@ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
@RequestMapping("/takePic")
@Log(title = "主动拍照", type = "查询")
public ResponseReult<TakePIcModel> takePic(@Validated TerminalPhotoVo vo) {
public ResponseReult<TakePIcModel> takePic(@RequestBody @Validated TerminalPhotoVo vo) {
ServiceBody<TakePIcModel> serviceBody = terminalPhotoService.takePic(vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
return ResponseReult.success(serviceBody.getData());

@ -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;
}

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

@ -162,4 +162,12 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<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>

@ -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();
}
}
}
}
}
}
}
}

@ -72,6 +72,9 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
@Autowired
CacheService cacheService;
// 记录主动拍照参数
public static Map<String, TermChannelModel> termChannelModelMap = new HashMap<>();
/**
* idid
*
@ -96,8 +99,8 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
list = terminalPhotoDao.selectPhotoList(terminalid, channelid, BigInteger.valueOf(start), BigInteger.valueOf(end));
List idlist = new ArrayList<>();
for (TerminalPhoto tp:list) {
if (tp.getOrginalId()!=null) {
for (TerminalPhoto tp : list) {
if (tp.getOrginalId() != null) {
idlist.add(tp.getOrginalId());
}
}
@ -302,8 +305,8 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
List idlist = new ArrayList<>();
for (TerminalPhoto tp:list) {
if (tp.getOrginalId()!=null) {
for (TerminalPhoto tp : list) {
if (tp.getOrginalId() != null) {
idlist.add(tp.getOrginalId());
}
}
@ -316,7 +319,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
});
imgarlarmsList = terminalImgAlarmsDao.selectAlarmsByTermidAndPhotoId(list, labellist);
}
beans = TerminalUtils.examPhotoBean(requestIp, list, terminalMap, lineMap, towerMap, termchannelMap, termchannelMapMap,imgarlarmsList);
beans = TerminalUtils.examPhotoBean(requestIp, list, terminalMap, lineMap, towerMap, termchannelMap, termchannelMapMap, imgarlarmsList);
model.setList(beans);
}
}
@ -427,6 +430,15 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
Integer channel = vo.getChannel();
Integer preset = vo.getPreset();
Integer captureType = vo.getCaptureType();
// 获取当前系统时间
Long currentTime = System.currentTimeMillis();
// 根据当前的装置id和通道id查询当前最新的图片时间
TerminalChannelMapper terminalChannelMapper = terminalChannelMapperDao.selectByTermIdAndChannelId(termId, channel);
if (null != terminalChannelMapper) {
Long photoTime = terminalChannelMapper.getPhotoTime().longValue();
termChannelModelMap.put(termId + "_" + channel, new TermChannelModel(termId, channel, photoTime, currentTime));
}
Map<Integer, Terminals> terminalMap = cacheService.getTerminalMap();
Terminals terminals = terminalMap.get(termId);
String cmdid = null;
@ -541,7 +553,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
List<TerminalPhotosModel.PhotosBean> beans = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list)) {
for (TerminalChannelMapper item : list) {
if (item.getPhotoId() !=null) {
if (item.getPhotoId() != null) {
photolist.add(item.getPhotoId());
}
}
@ -552,16 +564,16 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
Map<Integer, TowerDto> towerMap = cacheService.getTowerMap();
List<TerminalPhoto> photoList = new ArrayList<>();
if (photolist.size()>0) {
if (photolist.size() > 0) {
photoList = terminalPhotoDao.selectPhotosByIdList(photolist);
}
List<TerminalImgAlarmsDto> imgarlarmsList = new ArrayList<>();
if (photoList.size()>0) {
if (photoList.size() > 0) {
if (CollectionUtil.isNotEmpty(list)) {
List idlist = new ArrayList<>();
for (TerminalPhoto tp:photoList) {
if (tp.getOrginalId()!=null) {
for (TerminalPhoto tp : photoList) {
if (tp.getOrginalId() != null) {
idlist.add(tp.getOrginalId());
}
}
@ -575,7 +587,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
}
}
}
beans = TerminalUtils.setPhotoList(requestIp, list, lineMap, termchannelMapMap, terminalMap, termchannelMap, towerMap, photoList,imgarlarmsList);
beans = TerminalUtils.setPhotoList(requestIp, list, lineMap, termchannelMapMap, terminalMap, termchannelMap, towerMap, photoList, imgarlarmsList);
}
model.setList(beans);
PageInfo pageData = PageUtils.getPageData(list);
@ -672,8 +684,8 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
Map<String, TerminalChannelMapper> termchannelMapMap = cacheService.getTermChannelMapMap();
List idlist = new ArrayList<>();
for (TerminalPhoto tp:list) {
if (tp.getOrginalId()!=null) {
for (TerminalPhoto tp : list) {
if (tp.getOrginalId() != null) {
idlist.add(tp.getOrginalId());
}
}

Loading…
Cancel
Save