From 88eaf665ba41c3340ee467086928f6561e4b6466 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 8 Mar 2024 15:07:03 +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=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzinfo/inspect/ai/entity/RobotEntity.java | 16 +++++ .../inspect/ai/controller/RobotController.java | 23 ++++++- .../inspect/ai/dto/robot/RobotInstanceDTO.java | 35 ++++++++++ .../hzinfo/inspect/ai/service/IRobotService.java | 19 ++++++ .../inspect/ai/service/impl/RobotServiceImpl.java | 79 ++++++++++++++++++++++ .../inspect/ai/vo/robot/RobotRealDataVO.java | 45 ++++++++++++ .../hzinfo/inspect/constants/ParamConstants.java | 11 +++ .../inspect/src/main/resources/db/2.0.0.sql.1 | 5 +- .../risk/controller/RiskCheckController.java | 2 +- 9 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/constants/ParamConstants.java diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/entity/RobotEntity.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/entity/RobotEntity.java index 3a02a3c..e179398 100644 --- a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/entity/RobotEntity.java +++ b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/entity/RobotEntity.java @@ -11,6 +11,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotBlank; import java.util.Date; import java.time.LocalDateTime; @@ -28,6 +30,10 @@ public class RobotEntity extends TenantEntity { private static final long serialVersionUID = 4503880134032836625L; + @ApiModelProperty(value = "站点编号") + @QueryField(condition = SqlCondition.EQUAL) + private String stationCode; + /** * 机器人用户ID */ @@ -35,11 +41,16 @@ public class RobotEntity extends TenantEntity { @ApiModelProperty(value = "机器人用户ID") private Long userId; + @ApiModelProperty("机器人编号") + @QueryField(condition = SqlCondition.LIKE) + private String code; + /** * 机器人带的摄像头ID */ @QueryField(condition = SqlCondition.EQUAL) @ApiModelProperty(value = "机器人带的摄像头ID, 多个摄像头通过 , 隔开") + @NotBlank private String cameraId; /** @@ -47,8 +58,13 @@ public class RobotEntity extends TenantEntity { */ @QueryField(condition = SqlCondition.LIKE) @ApiModelProperty(value = "机器人名称") + @NotBlank(message = "巡检机器人名称不能为空") private String name; + @ApiModelProperty(value = "是否绑定设备实例") + @QueryField(condition = SqlCondition.EQUAL) + private Boolean isDeviceInstance; + /** * 描述信息 */ 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 8454994..12cec92 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 @@ -7,26 +7,35 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.OperatorType; +import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.vo.robot.RobotAiReturnData; +import com.hnac.hzinfo.inspect.ai.vo.robot.RobotRealDataVO; import com.hnac.hzinfo.inspect.ai.vo.robot.RobotServerTaskParam; +import com.hnac.hzinfo.inspect.obj.utils.CodeUtils; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO; import io.swagger.annotations.*; import lombok.AllArgsConstructor; import javax.validation.Valid; import lombok.SneakyThrows; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.oss.OssTemplate; import org.springblade.core.oss.model.BladeFile; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; import com.hnac.hzinfo.inspect.ai.service.IRobotService; + +import java.util.List; import java.util.Map; /** @@ -80,6 +89,7 @@ public class RobotController extends BladeController { @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入st_robot") public R save(@Valid @RequestBody RobotEntity st_robot) { + st_robot.setCode("robot"+CodeUtils.randomCode()); return R.status(st_robotService.save(st_robot)); } @@ -131,6 +141,17 @@ public class RobotController extends BladeController { return R.data(bladeFile); } + @PostMapping("/generateDeviceInstance") + @ApiOperationSupport(order = 10) + @ApiOperation(value = "生成机器人设备实例", notes = "生成机器人设备实例") + public R generateDeviceInstance(@RequestBody @Validated RobotInstanceDTO device) { + return R.status(st_robotService.generateDeviceInstance(device)); + } - + @PostMapping("/getRealDataByRobotCode") + @ApiOperationSupport(order = 11) + @ApiOperation(value = "获取机器人各项属性实时数据", notes = "获取机器人各项属性实时数据") + public R> getRealDataByRobotCode(@RequestParam @ApiParam(value = "机器人编号", required = true) String robotCode) { + return R.data(st_robotService.getRealDataByRobotCode(robotCode)); + } } 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 new file mode 100644 index 0000000..9091112 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java @@ -0,0 +1,35 @@ +package com.hnac.hzinfo.inspect.ai.dto.robot; + + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Data +@EqualsAndHashCode +@ApiModel(value = "机器人设备实例DTO对象",description = "机器人设备实例DTO对象") +public class RobotInstanceDTO implements Serializable { + + @ApiModelProperty("设备编号") + @NotBlank(message = "机器人编号不能为空") + private String deviceCode; + + @ApiModelProperty("机器人名称") + @NotBlank(message = "机器人名称不能为空") + private String deviceName; + + @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 61a2397..e05d8fc 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,9 +1,15 @@ package com.hnac.hzinfo.inspect.ai.service; +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; +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 java.util.List; + /** * 服务类 * @@ -18,4 +24,17 @@ public interface IRobotService extends BaseService { */ RobotVO getDetailByUserId(Long userId); + /** + * 生成机器人设备实例 + * @param device 机器人设备实例DTO + * @return 生成结果 + */ + Boolean generateDeviceInstance(RobotInstanceDTO device); + + /** + * 获取机器人各项属性实时数据 + * @param robotCode 机器人编号 + * @return 实时数据 + */ + List getRealDataByRobotCode(String robotCode); } 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 c3c14ef..372ca23 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 @@ -1,15 +1,45 @@ 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.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseInstanceClient; +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; +import com.hnac.hzinfo.datasearch.device.IDeviceClient; +import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; +import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.vo.RobotVO; +import com.hnac.hzinfo.inspect.ai.vo.robot.RobotRealDataVO; import com.hnac.hzinfo.inspect.ai.wrapper.RobotWrapper; +import com.hnac.hzinfo.inspect.constants.ParamConstants; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.po.DeviceRealDataPO; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; +import com.hnac.hzinfo.sdk.v5.device.vo.RealDataRedisVO; +import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; 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.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +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.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 服务实现类 @@ -18,8 +48,13 @@ import org.springframework.stereotype.Service; */ @Service @AllArgsConstructor +@Slf4j public class RobotServiceImpl extends BaseServiceImpl implements IRobotService { + private final DeviceClient deviceClient; + private final IAnalyseDataSearchClient analyseDataSearchClient; + private final DeviceDataClient deviceDataClient; + /** * 根据用户id 获取 机器人信息 * @param userId @@ -35,4 +70,48 @@ public class RobotServiceImpl extends BaseServiceImpl RobotVO re = RobotWrapper.build().entityVO(robot); return re; } + + @Override + public Boolean generateDeviceInstance(RobotInstanceDTO device) { + if(deviceClient.isDeviceCodeExist(device.getDeviceCode()).getData()) { + throw new ServiceException("该机器人已经创建过设备实例,无需再创建!"); + } + else { + String modelSignage = ParamCache.getValue(ParamConstants.ROBOT_MODEL_CODE); + device.setModelSignage(Func.isNotEmpty(device.getModelSignage()) ? device.getModelSignage() : modelSignage); + VirtualDeviceDTO req = BeanUtil.copy(device, VirtualDeviceDTO.class); + req.setIsStandard(1); + req.setProtocolSignage("standard"); + R saveResult = deviceClient.saveVirtualDevice(req); + Assert.isTrue(saveResult.isSuccess(),() -> { + throw new ServiceException("生成设备实例失败,报错信息为:" + saveResult.getMsg()); + }); + LambdaUpdateWrapper luw = Wrappers.lambdaUpdate() + .set(RobotEntity::getIsDeviceInstance, true) + .eq(RobotEntity::getCode, device.getDeviceCode()); + return this.update(luw); + } + } + + @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()); + 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 new file mode 100644 index 0000000..d3561c7 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java @@ -0,0 +1,45 @@ +package com.hnac.hzinfo.inspect.ai.vo.robot; + + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.hnac.hzinfo.sdk.v5.device.vo.RealDataRedisVO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode +public class RobotRealDataVO extends RealDataRedisVO implements Serializable { + @ApiModelProperty("数据上送时间") + private String ts; + + @ApiModelProperty("实时数据") + private String v; + + @ApiModelProperty("上送数据质量,0为有效") + private String q; + + @JsonIgnore + private String n; + + @ApiModelProperty("物模型属性ID") + private String attrId; + + @JsonIgnore + private String realId; + + @JsonIgnore + private Long attrType; + + @ApiModelProperty("物模型属性标识") + @JsonIgnore + private String signage; + + @ApiModelProperty("物模型属性名称") + private String attrName; + + @ApiModelProperty("启停状态") + private Integer state; +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/constants/ParamConstants.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/constants/ParamConstants.java new file mode 100644 index 0000000..3f306d1 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/constants/ParamConstants.java @@ -0,0 +1,11 @@ +package com.hnac.hzinfo.inspect.constants; + +public interface ParamConstants { + + /**机器人模型编号**/ + String ROBOT_MODEL_CODE = "robot.model.code"; + + /**机器人状态属性**/ + String ROBOT_DEVICE_ATTR_ENABLE = "robot.device.attr.enable"; + +} 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 bedd5d8..11f6355 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 @@ -7,4 +7,7 @@ alter table `hz_st_ex_task` add column `video_start_time` datetime default null alter table `hz_st_ex_task` add column `video_end_time` datetime default null comment '视频录制开始时间'; alter table `hz_st_ex_task` add column `video_url` varchar(255) default null comment '手动录制视频地址'; -- 巡检摄像头管理添加设备编号 -alter table `hz_st_camera_info` add column `em_code` varchar(50) default null comment '设备编号'; \ No newline at end of file +alter table `hz_st_camera_info` add column `em_code` varchar(50) default null comment '设备编号'; +alter table `hz_st_robot` add column `code` varchar(50) default null comment '机器人编号'; +alter table `hz_st_robot` add column `station_code` varchar(50) default null comment '站点编号'; +alter table `hz_st_robot` add column `is_device_instance` tinyint(2) default 0 comment '是否绑定设备实例'; \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/controller/RiskCheckController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/controller/RiskCheckController.java index 9a1686e..17ae357 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/controller/RiskCheckController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/controller/RiskCheckController.java @@ -58,7 +58,7 @@ public class RiskCheckController extends BladeController { @ApiOperationSupport(order = 2) public R saveOrUpdateBatch(@RequestBody @Valid List req) { List riskCheckList = JSONArray.parseArray(JSON.toJSONString(req), RiskCheckEntity.class); - return R.status(riskCheckService.saveBatch(riskCheckList)); + return R.status(riskCheckService.saveOrUpdateBatch(riskCheckList)); } @DeleteMapping("/delete/{ids}")