diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalController.java index e025574..5c891df 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalController.java @@ -6,6 +6,7 @@ import com.shxy.xymanager_common.base.ResponseReult; import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.bean.ServiceStatus; import com.shxy.xymanager_common.model.TerminalListModel; +import com.shxy.xymanager_common.model.TerminalModel; import com.shxy.xymanager_common.vo.*; import com.shxy.xymanager_service.service.TerminalService; import io.swagger.annotations.Api; @@ -91,6 +92,19 @@ public class TerminalController extends BaseController { } } + @ApiOperation(value = "获取装置信息", notes = "获取装置信息接口", httpMethod = "POST") + @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) + @RequestMapping("/getTerminalInfo") + @Log(title = "获取装置信息", type = "修改") + public ResponseReult getTerminalInfo(@RequestParam("termId") Integer termId) { + ServiceBody serviceBody = terminalService.getTerminalInfo(termId); + if (serviceBody.getCode() == ServiceStatus.SUCCESS) { + return ResponseReult.success(serviceBody.getData()); + } else { + return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); + } + } + } diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java index f9604dd..3395bb0 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; @Api(value = "图片接口", tags = "图片接口相关") @@ -52,8 +53,8 @@ public class TerminalPhotoController extends BaseController { @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) @RequestMapping("/getLatestPhoto") @Log(title = "获取最新图片", type = "查询") - public ResponseReult getLatestPhoto(@RequestBody @Validated TerminalPhotoVo vo) { - ServiceBody serviceBody = terminalPhotoService.getLatestPhoto(vo); + public ResponseReult getLatestPhoto(@RequestBody @Validated TerminalPhotoVo vo) { + ServiceBody serviceBody = terminalPhotoService.getLatestPhoto(vo); if (serviceBody.getCode() == ServiceStatus.SUCCESS) { return ResponseReult.success(serviceBody.getData()); } else { @@ -105,8 +106,8 @@ public class TerminalPhotoController extends BaseController { @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) @RequestMapping("/getReturnedPhoto") @Log(title = "最新图片查询", type = "查询") - public ResponseReult getReturnedPhoto(@RequestParam("termId") String termId) { - ServiceBody serviceBody = terminalPhotoService.getReturnedPhoto(termId); + public ResponseReult getReturnedPhoto(@RequestBody @Validated ReturnedPhotoVo vo) { + ServiceBody serviceBody = terminalPhotoService.getReturnedPhoto(vo); if (serviceBody.getCode() == ServiceStatus.SUCCESS) { return ResponseReult.success(serviceBody.getData()); } else { diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/dto/TerminalInfoDto.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/dto/TerminalInfoDto.java new file mode 100644 index 0000000..90f7e02 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/dto/TerminalInfoDto.java @@ -0,0 +1,29 @@ +package com.shxy.xymanager_common.dto; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class TerminalInfoDto implements Serializable { + private Integer termId; + + private Integer batteryCapacity; + + private Integer batteryVoltage; + + private Integer workingTime; + + private Integer floatingCharge; + + private Integer totalWorkingTime; + + private Integer connectionState; + + private Integer wsUpdateTime; + + private String cmId; + + private static final long serialVersionUID = 1L; + +} \ No newline at end of file diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TerminalModel.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TerminalModel.java new file mode 100644 index 0000000..18cf0a6 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/TerminalModel.java @@ -0,0 +1,42 @@ +package com.shxy.xymanager_common.model; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 设备信息列表 + */ +@Data +@ApiModel(value = "获取设备状态信息", description = "获取设备状态信息") +public class TerminalModel implements Serializable { + + @ApiModelProperty(value = "装置编号", example = "123456") + private Integer termId; + + @ApiModelProperty(value = "电池电量", example = "123456") + private Integer batteryCapacity; + + @ApiModelProperty(value = "电池电压", example = "123456") + private Integer batteryVoltage; + + @ApiModelProperty(value = "本次连续工作时间(小时)", example = "12345678") + private Integer workingTime; + + @ApiModelProperty(value = "浮充状态:充电 放电", example = "12345678") + private Integer floatingCharge; + + @ApiModelProperty(value = "工作总时间(小时)", example = "名称名称") + private Integer totalWorkingTime; + + @ApiModelProperty(value = "网络连接状态 ", example = "名称名称") + private Integer connectionState; + + @ApiModelProperty(value = "cmId", example = "123456") + private String cmId; + +} diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java index 1fc62c5..d22e17d 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java @@ -35,6 +35,7 @@ public class ProcessExecUtils while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } + result = sb.toString(); if(StringUtils.isNotBlank(result)){ log.info("查询最新结果:{}",result); } diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/ReturnedPhotoVo.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/ReturnedPhotoVo.java new file mode 100644 index 0000000..f6d8071 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/vo/ReturnedPhotoVo.java @@ -0,0 +1,21 @@ +package com.shxy.xymanager_common.vo; + +import cn.hutool.core.date.DateTime; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "返回图片查询", description = "返回图片查询") +public class ReturnedPhotoVo { + @NotNull(message = "不能传入空值") + @ApiModelProperty(value = "装置id", required = true, example = "A0001") + private Integer termId; + + + @ApiModelProperty(value = "手动拍照时间", required = true, example = "A0001") + private DateTime photoTime; +} diff --git a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalPhotoDao.java b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalPhotoDao.java index 026dd8b..5a2528a 100644 --- a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalPhotoDao.java +++ b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalPhotoDao.java @@ -27,7 +27,7 @@ public interface TerminalPhotoDao { int updateByPrimaryKey(TerminalPhoto record); - TerminalPhoto getLatestPhoto(@Param("termId") String termId); + BigInteger getLatestPhoto(@Param("termId") Integer termId); List selectPhotos(); diff --git a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalsDao.java b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalsDao.java index 765dfee..11725f1 100644 --- a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalsDao.java +++ b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/TerminalsDao.java @@ -1,5 +1,6 @@ package com.shxy.xymanager_dao.dao; +import com.shxy.xymanager_common.dto.TerminalInfoDto; import com.shxy.xymanager_common.entity.Terminals; import org.apache.ibatis.annotations.Param; @@ -24,4 +25,6 @@ public interface TerminalsDao { int updateByPrimaryKey(Terminals record); + TerminalInfoDto getTerminalInfo(@Param("termId")Integer termId); + } \ No newline at end of file diff --git a/xymanager_dao/src/main/resources/mappers/SystemConfigDao.xml b/xymanager_dao/src/main/resources/mappers/SystemConfigDao.xml index 6b4fe1f..9ac496c 100644 --- a/xymanager_dao/src/main/resources/mappers/SystemConfigDao.xml +++ b/xymanager_dao/src/main/resources/mappers/SystemConfigDao.xml @@ -5,12 +5,12 @@ - + - select - + photo_time photoTime from terminal_photos where term_id = #{termId} order by create_time desc limit 1 diff --git a/xymanager_dao/src/main/resources/mappers/TerminalsDao.xml b/xymanager_dao/src/main/resources/mappers/TerminalsDao.xml index 83193b1..e26ec54 100644 --- a/xymanager_dao/src/main/resources/mappers/TerminalsDao.xml +++ b/xymanager_dao/src/main/resources/mappers/TerminalsDao.xml @@ -333,4 +333,12 @@ update_time = #{updateat} where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file 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 57c4e1c..225f94d 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 @@ -247,20 +247,22 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService { } @Override - public ServiceBody getLatestPhoto(TerminalPhotoVo vo) { + public ServiceBody getLatestPhoto(TerminalPhotoVo vo) { /* Cma cma = new Cma(server, port);*/ - Boolean hasNew = false; - String cmd = "/usr/local/bin/xympadmn --server=127.0.0.1 --port=6891 --act=capture --cmdid=" + vo.getCmdid() + "\t" + "--channel=" + vo.getChannel() + "\t" + "--preset=255 --type=0"; - Integer result = ProcessExecUtils.exec(cmd); - hasNew = result == 0 ? true : false; + DateTime now = DateTime.now(); + String cmd = "/usr/local/bin/xympadmn --server=127.0.0.1 --port=6891 --act=capture --cmdid="+vo.getCmdid() +"\t" +"--channel="+ vo.getChannel() +"\t"+ "--preset=255 --type=0"; + ProcessExecUtils.exec(cmd); /* Boolean hasNew = cma.requestCapture(vo.getCmdid(), vo.getChannel(), vo.getPreset(), vo.getCaptureType());*/ - return Asserts.success(hasNew); + return Asserts.success(now); } @Override - public ServiceBody getReturnedPhoto(String termId) { - TerminalPhoto photo = terminalPhotoDao.getLatestPhoto(termId); - return Asserts.success(photo); + public ServiceBody getReturnedPhoto(ReturnedPhotoVo vo) { + Boolean hasNew = false; + BigInteger photoTime = terminalPhotoDao.getLatestPhoto(vo.getTermId()); + BigInteger localPhotoTime = MyDateUtils.TimeMillSecond2Second(vo.getPhotoTime()); + hasNew = photoTime.compareTo(localPhotoTime)<0?false:true; + return Asserts.success(hasNew); } /** @@ -317,10 +319,10 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService { @Override public ServiceBody getPhotoTime(TerminalPhotoTimeVo vo) { List dtoList = terminalPhotoDao.selectPhotoSchedule(vo); - Map> map = dtoList.stream().collect(Collectors.groupingBy(TerminalPhotoScheduleDto::getCmid)); - map.forEach((key, value) -> { + Map> map =dtoList.stream().collect(Collectors.groupingBy(TerminalPhotoScheduleDto :: getCmid)) ; + map.forEach((key,value) ->{ - for (int j = 0; j < value.size(); j++) { + for(int j = 0; j 0) { - span1 = (short) (span / 60); - span2 = (short) (span % 60); - } else if (span < 60) { - span1 = (short) 0; + Short span1 =-1; + Short span2 =-1; + if(span/60 > 0) { + span1 =(short)(span/60); + span2 =(short)(span % 60); + }else if(span<60 ){ + span1 = (short)0; span2 = span; } - String cmd = "/usr/local/bin/xympadmn --server=127.0.0.1 --port=6891 --act=schedule --cmdid=" + key + "\t" + "--channel=" + vo.getChannel() + "\t" - + "--group=3 --hour1=" + startHour + "\t" + "--min1=" + startMin + "\t" + "--preset1=255 --hour2=" + endTimeHour + "\t" + "--min2=" + endTimeMin + "\t" - + "--preset2=255 --hour3=" + span1 + "\t" + "--min3=" + span2 + "\t" + "--preset3=255"; - ProcessExecUtils.exec(cmd); + String cmd = "/usr/local/bin/xympadmn --server=127.0.0.1 --port=6891 --act=schedule --cmdid="+key +"\t" +"--channel="+ vo.getChannel() +"\t" + + "--group=3 --hour1=" + startHour +"\t"+ "--min1=" + startMin +"\t"+ "--preset1=255 --hour2=" + endTimeHour +"\t"+ "--min2=" + endTimeMin +"\t" + +"--preset2=255 --hour3=" + span1 +"\t" + "--min3=" + span2 +"\t"+"--preset3=255"; + ProcessExecUtils.exec(cmd); - } - ; + }; }); diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalServiceImpl.java index c500112..6feb757 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalServiceImpl.java @@ -5,12 +5,14 @@ import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollectionUtil; import com.github.pagehelper.PageInfo; import com.shxy.xymanager_common.bean.ServiceBody; +import com.shxy.xymanager_common.dto.TerminalInfoDto; import com.shxy.xymanager_common.entity.TerminalChannelMapper; import com.shxy.xymanager_common.entity.TerminalStatus; 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.TerminalListModel; +import com.shxy.xymanager_common.model.TerminalModel; import com.shxy.xymanager_common.page.PageUtils; import com.shxy.xymanager_common.vo.*; import com.shxy.xymanager_dao.dao.TerminalChannelMapperDao; @@ -20,6 +22,7 @@ import com.shxy.xymanager_dao.dao.TerminalsDao; import com.shxy.xymanager_service.interaction.Cma; import com.shxy.xymanager_service.service.TerminalService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -178,6 +181,16 @@ public class TerminalServiceImpl implements TerminalService { // } } + @Override + public ServiceBody getTerminalInfo(Integer termId) { + TerminalModel model = new TerminalModel(); + TerminalInfoDto dto = terminalsDao.getTerminalInfo(termId); + if(null!=dto) { + BeanUtils.copyProperties(dto, model); + } + return Asserts.success(model); + } + } 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 2377d19..a4a4bb6 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 @@ -8,6 +8,8 @@ import com.shxy.xymanager_common.model.TerminalPhotoSelectListModel; import com.shxy.xymanager_common.model.TerminalPhotosModel; import com.shxy.xymanager_common.vo.*; +import java.util.Date; + /** * 装置图片接口 * @@ -40,15 +42,15 @@ public interface TerminalPhotoService { * * @return */ - ServiceBody getLatestPhoto(TerminalPhotoVo vo); + ServiceBody getLatestPhoto(TerminalPhotoVo vo); /** - * 根据通道和装置id获取最新图片 + * 获取最新图片 * * @return */ - ServiceBody getReturnedPhoto(String termId); + ServiceBody getReturnedPhoto(ReturnedPhotoVo vo); /** * 图片轮询接口 diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalService.java index 6f49c30..7638dd8 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalService.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalService.java @@ -2,6 +2,7 @@ package com.shxy.xymanager_service.service; import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.model.TerminalListModel; +import com.shxy.xymanager_common.model.TerminalModel; import com.shxy.xymanager_common.vo.*; /** @@ -48,4 +49,7 @@ public interface TerminalService { */ ServiceBody resetTerminal(TerminalIdVo vo); + + ServiceBody getTerminalInfo(Integer termId); + }