diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TermChannelModel.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TermChannelModel.java new file mode 100644 index 0000000..f0f0a8c --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TermChannelModel.java @@ -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; + +} diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/TermCtrlVo.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/TermCtrlVo.java new file mode 100644 index 0000000..fd77e62 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/TermCtrlVo.java @@ -0,0 +1,34 @@ +package com.shxy.xymanager_common.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.models.auth.In; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +@ApiModel(value = "装置控制对象", description = "装置控制对象描述") +public class TermCtrlVo { + + @ApiModelProperty(value = "装置编号", example = "123455") + private Integer termId; + + @ApiModelProperty(value = "通道编号", example = "123456") + private Integer channelId; + + @NotNull(message = "不能传入空值") + @ApiModelProperty(value = "控制对象数组", required = true) + private List list; + + @Data + public static class CtrlBean { + @ApiModelProperty(value = "命令key", example = "act") + private String name; + @ApiModelProperty(value = "命令value", example = "shecdule") + private String value; + } + +} diff --git a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalChannelMapperDao.java b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalChannelMapperDao.java index 9efa694..14e81af 100644 --- a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalChannelMapperDao.java +++ b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalChannelMapperDao.java @@ -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); + } \ No newline at end of file diff --git a/xymanager_dao/src/main/resources/mappers/TerminalChannelMapperDao.xml b/xymanager_dao/src/main/resources/mappers/TerminalChannelMapperDao.xml index de47267..a33b6e5 100644 --- a/xymanager_dao/src/main/resources/mappers/TerminalChannelMapperDao.xml +++ b/xymanager_dao/src/main/resources/mappers/TerminalChannelMapperDao.xml @@ -162,4 +162,12 @@ update_time = #{updateTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} + + + \ No newline at end of file diff --git a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/TermChannelTask.java b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/TermChannelTask.java new file mode 100644 index 0000000..db4e8d7 --- /dev/null +++ b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/timeTask/TermChannelTask.java @@ -0,0 +1,67 @@ +package com.shxy.xymanager_framework.timeTask; + +import com.shxy.xymanager_common.bean.ServiceBody; +import com.shxy.xymanager_common.entity.Terminals; +import com.shxy.xymanager_common.model.TermChannelModel; +import com.shxy.xymanager_framework.socket.WebSocketServer; +import com.shxy.xymanager_service.impl.TermSetServiceImpl; +import com.shxy.xymanager_service.service.TerminalPhotoService; +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.text.SimpleDateFormat; +import java.util.Iterator; +import java.util.Map; + +@Component +@Slf4j +public class TermChannelTask { + + @Autowired + TerminalPhotoService terminalPhotoService; + + @Resource + WebSocketServer webSocketServer; + + //超时时间 分钟 5 + Integer overtime = 1; + + //创建记录主动拍照参数 +// public static Map termChannelModelMap = new HashMap<>(); + + @Scheduled(fixedDelay = 10000) + public void queryTermChannelTime() { + Map termChannelModelMap = TermSetServiceImpl.termChannelModelMap; + //获取当前系统时间 + Long time = System.currentTimeMillis(); + if ( !termChannelModelMap.isEmpty() ) { + Iterator iterator = termChannelModelMap.keySet().iterator(); + + while ( iterator.hasNext() ) { + String key = iterator.next(); + TermChannelModel model = termChannelModelMap.get(key); + //开始拍照的时间 + 5分钟 + Long currentTime = model.getCurrentTime() + ( overtime * 60 * 1000); + if ( time >= currentTime ) { + iterator.remove(); + } else { + //调用查询最新照片 + Terminals terminals = terminalPhotoService.getTakePicPhotoStatus(model).getData(); + if ( terminals.checkInclude() ) { + String str = "装置:" + terminals.getCmdid() + " 在通道" + model.getChannelId() + "拍的最新图片已上传"; + webSocketServer.sendNotice(str); +// System.out.println(str); + iterator.remove(); + } + } + + + } + + } + } + +} diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TermSetServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TermSetServiceImpl.java index e92b310..2f9035d 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TermSetServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TermSetServiceImpl.java @@ -10,17 +10,20 @@ 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.enums.CommonStatus; import com.shxy.xymanager_common.exception.Asserts; import com.shxy.xymanager_common.model.ResolutionModel; import com.shxy.xymanager_common.model.TerminalScheduleRuleTimeListModel; +import com.shxy.xymanager_common.model.*; import com.shxy.xymanager_common.util.CmaUtil; import com.shxy.xymanager_common.util.MyDateUtils; import com.shxy.xymanager_common.util.StringUtils; import com.shxy.xymanager_common.util.xinyin.ProcessExecUtils; import com.shxy.xymanager_common.vo.*; import com.shxy.xymanager_dao.dao.RequestResultsDao; +import com.shxy.xymanager_dao.dao.TerminalChannelMapperDao; import com.shxy.xymanager_dao.dao.TerminalResolutionDao; import com.shxy.xymanager_service.service.CacheService; import com.shxy.xymanager_service.service.TermSetService; @@ -30,6 +33,7 @@ import org.springframework.stereotype.Service; import javax.validation.constraints.NotEmpty; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -52,6 +56,12 @@ public class TermSetServiceImpl implements TermSetService { @Autowired private RequestResultsDao requestResultsDao; + @Autowired + TerminalChannelMapperDao terminalChannelMapperDao; + + //记录主动拍照参数 + public static Map termChannelModelMap = new HashMap<>(); + @Override public ServiceBody alarmMark(VoiceCtrlVo vo) { String cmd = CmaUtil.alarmMark(vo.getCmdId(), vo.getCtrl()); @@ -74,5 +84,93 @@ public class TermSetServiceImpl implements TermSetService { return Asserts.success(model); } + + /** + * 调整焦距 + * + * @param vo + * @return + */ + @Override + public ServiceBody updateTermCamera(UpdateCameraVo vo) { + CmaRequestModel model = new CmaRequestModel(); + Integer termId = vo.getTermId(); + Integer channelId = vo.getChannelId(); + Integer type = vo.getType(); + Map terminalMap = newCacheService.getTerminalMap(); + Terminals terminals = terminalMap.get(termId); + String cmdid = null; + if (terminals != null) { + cmdid = terminals.getCmdid(); + } + int requestId = Constants.REQUEST_ID.addAndGet(1); + String cmd = CmaUtil.cameractrl(cmdid, channelId, requestId, type); + ProcessExecUtils.exec(cmd); + model.setRequestId(requestId); + return Asserts.success(model); + } + + /** + * 装置控制 + * + * @param vo + * @return + */ + @Override + public ServiceBody setTermCamera(TermCtrlVo vo) { + //返回对象 + CmaRequestModel model = new CmaRequestModel(); + //装置信息 + List list = vo.getList(); + //装置id + Integer termId = vo.getTermId(); + //通道id + Integer channelId = vo.getChannelId(); + //获取当前系统时间 + Long currentTime = System.currentTimeMillis(); + //根据当前的装置id和通道id查询当前最新的图片时间 + TerminalChannelMapper terminalChannelMapper = terminalChannelMapperDao.selectByTermIdAndChannelId(termId, channelId); + Long photoTime = terminalChannelMapper.getPhotoTime().longValue(); + + termChannelModelMap.put(termId + "_" + channelId, new TermChannelModel(termId, channelId, photoTime, currentTime)); + + Map terminalMap = newCacheService.getTerminalMap(); + Terminals terminals = terminalMap.get(termId); + String cmdid = null; + if (terminals != null) { + cmdid = terminals.getCmdid(); + } + int requestId = Constants.REQUEST_ID.addAndGet(1); + List cmd = CmaUtil.cmaCtrl(list, cmdid, requestId); + ProcessExecUtils.execArray(cmd); + model.setRequestId(requestId); + DateTime now = DateTime.now(); + model.setDate(now); + return Asserts.success(model); + + } + + @Override + public ServiceBody getTermCameraRequest(RequestIdVo vo) { + CmaRequestBackModel model = new CmaRequestBackModel(); + RequestResults results = requestResultsDao.selectByRequestId(vo.getRequestid()); + if (null != results) { + model.setSuccess(CommonStatus.EFFECTIVE.value()); + model.setId(results.getId()); + model.setTermId(results.getTermId()); + model.setRequestType(results.getRequestType()); + model.setRequestId(results.getRequestId()); + model.setClientId(results.getClientId()); + model.setRequestTime(results.getRequestTime()); + model.setData(results.getData()); + model.setFrameNo(results.getFrameNo()); + model.setScheduleStatus(results.getScheduleStatus()); + model.setResult(results.getResult()); + } else { + model.setSuccess(CommonStatus.DELETE.value()); + } + return Asserts.success(model); + } + } diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java index dc932c0..28ade26 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java @@ -713,4 +713,119 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService { } } + @Override + public ServiceBody uploadPhoto(MultipartFile file, Integer termid, String cmdid, Integer channel, BigInteger phototime) throws IOException { + DateTime date = MyDateUtils.date(phototime.longValue()); + int year = date.year(); + String mon = ""; + int month = date.monthBaseOne(); + if (month < 10) { + mon = "0" + month; + } + String daystr = ""; + int day = date.dayOfMonth(); + if (day < 10) { + daystr = "0" + day; + } + String sub = StrUtil.sub(cmdid, cmdid.length() - 2, cmdid.length()); + String location = C_PATH + year + "/" + mon + "/" + daystr + "/" + sub; + File saveFile = new File(location); + if (!saveFile.exists()) { + boolean mkdirs = saveFile.mkdirs(); + System.out.println("日期文件夹" + (mkdirs ? "创建成功" : "创建失败")); + } + File file1 = new File(saveFile.getAbsoluteFile() + "/" + file.getOriginalFilename()); + file.transferTo(file1); + TerminalPhoto record = new TerminalPhoto(); + record.setTermId(termid); + record.setPhotoTime((BigInteger.valueOf(MyDateUtils.TimeMillSecond2Second(date)))); + record.setChannelId(channel); + record.setOrginalId(BigInteger.valueOf(RandomUtil.randomLong())); + record.setPath(year + "/" + mon + "/" + daystr + "/" + sub + "/" + file.getOriginalFilename()); + record.setRecvTime(BigInteger.valueOf(MyDateUtils.TimeMillSecond2Second(date))); + record.setCreateTime(new Date()); + record.setChannelId(channel); + record.setMediaType(0); + record.setPresetId(255); + int i = terminalPhotoDao.insertSelective(record); + if (i != 0) { + return Asserts.success("上传成功"); + } else { + return Asserts.error("上传失败"); + } + } + + @Override + public PhotoDayModel getDayModel(Integer termid, Integer channelId, Long start, Long end) { + TerminalPhotoExample example = new TerminalPhotoExample(); + TerminalPhotoExample.Criteria criteria = example.createCriteria(); + criteria.andTermIdEqualTo(termid); + if (start != null) { + criteria.andPhotoTimeGreaterThanOrEqualTo(start); + } + if (end != null) { + criteria.andPhotoTimeLessThan(end); + } + if (channelId != null) { + criteria.andChannelIdEqualTo(channelId); + } + long count = terminalPhotoDao.countByExample(example); + + PhotoDayModel result = new PhotoDayModel(); + result.setPhotoCount(count); + if (count > 0) { + example.setOrderByClause("photo_time desc"); + PageHelper.startPage(1, 1); + List list = terminalPhotoDao.selectByExample(example); + TerminalPhoto last = list.get(0); + long lastrecv = last.getRecvTime().longValue(); + result.setLastRecvTime(new Date(lastrecv * 1000)); + long lastphoto = last.getPhotoTime().longValue(); + result.setLastPhotoTime(new Date(lastphoto * 1000)); + result.setLastChannelId(last.getChannelId()); + result.setLastPhotoPath(photoAddress + last.getPath()); + + example.setOrderByClause("photo_time asc"); + PageHelper.startPage(1, 1); + list = terminalPhotoDao.selectByExample(example); + TerminalPhoto first = list.get(0); + long firstrecv = first.getRecvTime().longValue(); + result.setFirstRecvTime(new Date(firstrecv * 1000)); + long firstphoto = first.getPhotoTime().longValue(); + result.setFirstPhotoTime(new Date(firstphoto * 1000)); + result.setFirstChannelId(first.getChannelId()); + result.setFirstPhotoPath(photoAddress + first.getPath()); + + long totalDays = DateUtil.getDifferenceInDays(result.getFirstPhotoTime(), result.getLastPhotoTime()); + result.setTotalDays(totalDays); + } + return result; + } + + + @Override + public ServiceBody 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 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); + } + } diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java index 830482a..04fee52 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java @@ -1,10 +1,12 @@ package com.shxy.xymanager_service.service; import com.shxy.xymanager_common.bean.ServiceBody; +import com.shxy.xymanager_common.entity.Terminals; import com.shxy.xymanager_common.model.*; import com.shxy.xymanager_common.vo.*; import java.util.Date; +import java.util.Map; /** * 装置图片接口 @@ -93,4 +95,30 @@ public interface TerminalPhotoService { * @return */ ServiceBody deletePicList(DeletePicVo vo); + + + + /** + * 图片上传 + * @param file + * @param termid + * @param cmdid + * @param phototime + * @return + */ + + ServiceBody uploadPhoto(MultipartFile file, Integer termid, String cmdid, Integer channel, BigInteger phototime) throws IOException; + + PhotoDayModel getDayModel(Integer termid, Integer channelId, Long start, Long end); + + ServiceBody getTestTerminalPhotoList(String requestIp); + + ServiceBody takeAlarm(TerminalPhotoTestVo vo); + + /** + * 获取最新图片 + * @param model + * @return + */ + ServiceBody getTakePicPhotoStatus(TermChannelModel model); }