From 2e5f37b7f7417f6409997e4fd6fe2ffd60475bac Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 18 Mar 2024 13:37:07 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=9C=BA=E5=99=A8=E4=BA=BA=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E3=80=81=E6=95=B0=E6=8D=AE=E7=9C=8B=E6=9D=BF=E3=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspect/ai/controller/RobotController.java | 11 +++++- .../inspect/ai/dto/robot/RobotInstanceDTO.java | 7 ++-- .../hzinfo/inspect/ai/service/IRobotService.java | 5 +++ .../inspect/ai/service/impl/RobotServiceImpl.java | 41 +++++++++++++++++----- .../inspect/ai/vo/robot/RobotRealDataVO.java | 2 +- .../inspect/src/main/resources/db/2.0.0.sql.1 | 4 +-- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java index 12cec92..94139ed 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java @@ -148,10 +148,19 @@ public class RobotController extends BladeController { return R.status(st_robotService.generateDeviceInstance(device)); } - @PostMapping("/getRealDataByRobotCode") + @GetMapping("/getRealDataByRobotCode") @ApiOperationSupport(order = 11) @ApiOperation(value = "获取机器人各项属性实时数据", notes = "获取机器人各项属性实时数据") public R> getRealDataByRobotCode(@RequestParam @ApiParam(value = "机器人编号", required = true) String robotCode) { return R.data(st_robotService.getRealDataByRobotCode(robotCode)); } + + @GetMapping("/getRobotSoeData") + @ApiOperationSupport(order = 12) + @ApiOperation(value = "获取机器人告警", notes = "获取机器人告警") + public R getRobotSoeData(@RequestParam @ApiParam("机器人编号") String robotCode, + @RequestParam @ApiParam("开始时间") String startTime, + @RequestParam @ApiParam("结束时间") String endTime, Query query) { + return R.data(st_robotService.getRobotSoeData(robotCode,startTime,endTime,query)); + } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java index 9091112..95d2e77 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java @@ -22,13 +22,12 @@ public class RobotInstanceDTO implements Serializable { @NotBlank(message = "机器人名称不能为空") private String deviceName; + @ApiModelProperty("站点编号") + private String stationCode; + @ApiModelProperty("模型标识") private String modelSignage; - @ApiModelProperty("站点编号") - @NotBlank(message = "站点编号不能为空") - private String projectId; - @ApiModelProperty("标准设备需要传入密钥") private String secretKey; diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java index e05d8fc..67a9929 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java @@ -1,5 +1,6 @@ package com.hnac.hzinfo.inspect.ai.service; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.vo.RobotVO; @@ -7,8 +8,10 @@ import com.hnac.hzinfo.inspect.ai.vo.robot.RobotRealDataVO; import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO; import org.springblade.core.mp.base.BaseService; import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; +import org.springblade.core.mp.support.Query; import java.util.List; +import java.util.Map; /** * 服务类 @@ -37,4 +40,6 @@ public interface IRobotService extends BaseService { * @return 实时数据 */ List getRealDataByRobotCode(String robotCode); + + IPage getRobotSoeData(String robotCode, String startTime, String endTime, Query query); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java index 372ca23..647c8de 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzinfo.inspect.ai.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; @@ -29,14 +30,17 @@ import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; import com.hnac.hzinfo.inspect.ai.mapper.RobotMapper; import com.hnac.hzinfo.inspect.ai.service.IRobotService; import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.cache.ParamCache; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -81,7 +85,9 @@ public class RobotServiceImpl extends BaseServiceImpl device.setModelSignage(Func.isNotEmpty(device.getModelSignage()) ? device.getModelSignage() : modelSignage); VirtualDeviceDTO req = BeanUtil.copy(device, VirtualDeviceDTO.class); req.setIsStandard(1); + req.setProjectId(device.getStationCode()); req.setProtocolSignage("standard"); + req.setSecretKey(device.getSecretKey()); R saveResult = deviceClient.saveVirtualDevice(req); Assert.isTrue(saveResult.isSuccess(),() -> { throw new ServiceException("生成设备实例失败,报错信息为:" + saveResult.getMsg()); @@ -89,27 +95,46 @@ public class RobotServiceImpl extends BaseServiceImpl LambdaUpdateWrapper luw = Wrappers.lambdaUpdate() .set(RobotEntity::getIsDeviceInstance, true) .eq(RobotEntity::getCode, device.getDeviceCode()); - return this.update(luw); + this.update(luw); + return true; } } @Override public List getRealDataByRobotCode(String robotCode) { - Result> attrResult = deviceClient.getDeviceInstaceAttrsByDeviceCodes(Lists.newArrayList(robotCode)); - Assert.isTrue(attrResult.isSuccess(),() -> { - throw new ServiceException("获取设备实例物模型失败!"); - }); DeviceRealDataPO po = new DeviceRealDataPO(); po.setDeviceCode(robotCode); - po.setSignages(attrResult.getData().stream().map(DeviceInstanceAttrVO::getSignage).collect(Collectors.toList())); Result>>> realDataResult = deviceDataClient.getDeviceRealDataByCodes(Lists.newArrayList(po)); Assert.isTrue(realDataResult.isSuccess(),() -> { throw new ServiceException("获取设备实例实时数据失败!"); }); List result = realDataResult.getData().stream() .flatMap(l -> l.stream()) - .flatMap(m -> m.entrySet().stream().map(k -> BeanUtil.copy(m.get(k), RobotRealDataVO.class))) - .collect(Collectors.toList()); + .flatMap(m -> m.entrySet().stream().map(k -> { + RobotRealDataVO data = BeanUtil.copy(k.getValue(), RobotRealDataVO.class); + data.setAttrName(k.getValue().getN()); + return data; + })).collect(Collectors.toList()); + return result; + } + + @Override + public IPage getRobotSoeData(String robotCode, String startTime, String endTime, Query query) { + RobotEntity request = new RobotEntity(); + request.setCode(robotCode); + RobotEntity robot = this.getOne(Wrappers.lambdaQuery().eq(RobotEntity::getCode, robotCode)); + Assert.isTrue(ObjectUtil.isNotEmpty(robot) && StringUtil.isNotBlank(robot.getStationCode()),() -> { + throw new ServiceException("该机器人未绑定站点,无法获取告警数据!"); + }); + Result> deviceSoeDataResult = deviceDataClient.getDeviceSoeData(robot.getStationCode(), 1, robotCode, null, + startTime, endTime, true, query.getCurrent(), query.getSize()); + Assert.isTrue(deviceSoeDataResult.isSuccess(), () -> { + throw new ServiceException("获取机器人告警信息失败!"); + }); + Map deviceSoeData = deviceSoeDataResult.getData(); + IPage result = Condition.getPage(query); + result.setRecords((List) deviceSoeData.get("data")); + result.setTotal(Long.valueOf((int) deviceSoeData.get("total"))); return result; } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java index d3561c7..7a50091 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java @@ -11,7 +11,7 @@ import java.io.Serializable; @Data @EqualsAndHashCode -public class RobotRealDataVO extends RealDataRedisVO implements Serializable { +public class RobotRealDataVO implements Serializable { @ApiModelProperty("数据上送时间") private String ts; diff --git a/hzims-service/inspect/src/main/resources/db/2.0.0.sql.1 b/hzims-service/inspect/src/main/resources/db/2.0.0.sql.1 index dc27925..5fef62f 100644 --- a/hzims-service/inspect/src/main/resources/db/2.0.0.sql.1 +++ b/hzims-service/inspect/src/main/resources/db/2.0.0.sql.1 @@ -1,6 +1,6 @@ -ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` MODIFY COLUMN `CLAIM_STATUS` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '领用状态 0:未领用 1:已领用 每条任务可以存在多个用户,但是只有一个领用人' AFTER `USER_ID`; +ALTER TABLE `hz_st_ex_task_user` MODIFY COLUMN `CLAIM_STATUS` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '领用状态 0:未领用 1:已领用 每条任务可以存在多个用户,但是只有一个领用人' AFTER `USER_ID`; -ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` ADD COLUMN `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `TENANT_ID`; +ALTER TABLE `hz_st_ex_task_user` ADD COLUMN `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `TENANT_ID`; alter table `hz_st_ex_task` add column `hik_video_task_id` varchar(50) default null comment '海康录制视频任务ID'; alter table `hz_st_ex_task` add column `video_start_time` datetime default null comment '视频录制开始时间';