Browse Source

# 机器人状态、数据看板功能

zhongwei
haungxing 9 months ago
parent
commit
88eaf665ba
  1. 16
      hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/entity/RobotEntity.java
  2. 23
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java
  3. 35
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/dto/robot/RobotInstanceDTO.java
  4. 19
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java
  5. 79
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java
  6. 45
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/vo/robot/RobotRealDataVO.java
  7. 11
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/constants/ParamConstants.java
  8. 5
      hzims-service/inspect/src/main/resources/db/2.0.0.sql.1
  9. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/controller/RiskCheckController.java

16
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 lombok.EqualsAndHashCode;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotBlank;
import java.util.Date; import java.util.Date;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -28,6 +30,10 @@ public class RobotEntity extends TenantEntity {
private static final long serialVersionUID = 4503880134032836625L; private static final long serialVersionUID = 4503880134032836625L;
@ApiModelProperty(value = "站点编号")
@QueryField(condition = SqlCondition.EQUAL)
private String stationCode;
/** /**
* 机器人用户ID * 机器人用户ID
*/ */
@ -35,11 +41,16 @@ public class RobotEntity extends TenantEntity {
@ApiModelProperty(value = "机器人用户ID") @ApiModelProperty(value = "机器人用户ID")
private Long userId; private Long userId;
@ApiModelProperty("机器人编号")
@QueryField(condition = SqlCondition.LIKE)
private String code;
/** /**
* 机器人带的摄像头ID * 机器人带的摄像头ID
*/ */
@QueryField(condition = SqlCondition.EQUAL) @QueryField(condition = SqlCondition.EQUAL)
@ApiModelProperty(value = "机器人带的摄像头ID, 多个摄像头通过 , 隔开") @ApiModelProperty(value = "机器人带的摄像头ID, 多个摄像头通过 , 隔开")
@NotBlank
private String cameraId; private String cameraId;
/** /**
@ -47,8 +58,13 @@ public class RobotEntity extends TenantEntity {
*/ */
@QueryField(condition = SqlCondition.LIKE) @QueryField(condition = SqlCondition.LIKE)
@ApiModelProperty(value = "机器人名称") @ApiModelProperty(value = "机器人名称")
@NotBlank(message = "巡检机器人名称不能为空")
private String name; private String name;
@ApiModelProperty(value = "是否绑定设备实例")
@QueryField(condition = SqlCondition.EQUAL)
private Boolean isDeviceInstance;
/** /**
* 描述信息 * 描述信息
*/ */

23
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.annotation.OperationAnnotation;
import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.BusinessType;
import com.hnac.hzims.common.logs.enums.OperatorType; 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.RobotAiReturnData;
import com.hnac.hzinfo.inspect.ai.vo.robot.RobotRealDataVO;
import com.hnac.hzinfo.inspect.ai.vo.robot.RobotServerTaskParam; 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 io.swagger.annotations.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import javax.validation.Valid; import javax.validation.Valid;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springblade.core.boot.ctrl.BladeController; 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.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.oss.OssTemplate; import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.model.BladeFile; import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; import com.hnac.hzinfo.inspect.ai.entity.RobotEntity;
import com.hnac.hzinfo.inspect.ai.service.IRobotService; import com.hnac.hzinfo.inspect.ai.service.IRobotService;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -80,6 +89,7 @@ public class RobotController extends BladeController {
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入st_robot") @ApiOperation(value = "新增", notes = "传入st_robot")
public R save(@Valid @RequestBody RobotEntity st_robot) { public R save(@Valid @RequestBody RobotEntity st_robot) {
st_robot.setCode("robot"+CodeUtils.randomCode());
return R.status(st_robotService.save(st_robot)); return R.status(st_robotService.save(st_robot));
} }
@ -131,6 +141,17 @@ public class RobotController extends BladeController {
return R.data(bladeFile); 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<List<RobotRealDataVO>> getRealDataByRobotCode(@RequestParam @ApiParam(value = "机器人编号", required = true) String robotCode) {
return R.data(st_robotService.getRealDataByRobotCode(robotCode));
}
} }

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

19
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; 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.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 org.springblade.core.mp.base.BaseService;
import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; import com.hnac.hzinfo.inspect.ai.entity.RobotEntity;
import java.util.List;
/** /**
* 服务类 * 服务类
* *
@ -18,4 +24,17 @@ public interface IRobotService extends BaseService<RobotEntity> {
*/ */
RobotVO getDetailByUserId(Long userId); RobotVO getDetailByUserId(Long userId);
/**
* 生成机器人设备实例
* @param device 机器人设备实例DTO
* @return 生成结果
*/
Boolean generateDeviceInstance(RobotInstanceDTO device);
/**
* 获取机器人各项属性实时数据
* @param robotCode 机器人编号
* @return 实时数据
*/
List<RobotRealDataVO> getRealDataByRobotCode(String robotCode);
} }

79
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; package com.hnac.hzinfo.inspect.ai.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.RobotVO;
import com.hnac.hzinfo.inspect.ai.vo.robot.RobotRealDataVO;
import com.hnac.hzinfo.inspect.ai.wrapper.RobotWrapper; 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.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; import com.hnac.hzinfo.inspect.ai.entity.RobotEntity;
import com.hnac.hzinfo.inspect.ai.mapper.RobotMapper; import com.hnac.hzinfo.inspect.ai.mapper.RobotMapper;
import com.hnac.hzinfo.inspect.ai.service.IRobotService; import com.hnac.hzinfo.inspect.ai.service.IRobotService;
import org.springblade.core.mp.support.Condition; 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.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 @Service
@AllArgsConstructor @AllArgsConstructor
@Slf4j
public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity> implements IRobotService { public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity> implements IRobotService {
private final DeviceClient deviceClient;
private final IAnalyseDataSearchClient analyseDataSearchClient;
private final DeviceDataClient deviceDataClient;
/** /**
* 根据用户id 获取 机器人信息 * 根据用户id 获取 机器人信息
* @param userId * @param userId
@ -35,4 +70,48 @@ public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity>
RobotVO re = RobotWrapper.build().entityVO(robot); RobotVO re = RobotWrapper.build().entityVO(robot);
return re; 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<Long> saveResult = deviceClient.saveVirtualDevice(req);
Assert.isTrue(saveResult.isSuccess(),() -> {
throw new ServiceException("生成设备实例失败,报错信息为:" + saveResult.getMsg());
});
LambdaUpdateWrapper<RobotEntity> luw = Wrappers.<RobotEntity>lambdaUpdate()
.set(RobotEntity::getIsDeviceInstance, true)
.eq(RobotEntity::getCode, device.getDeviceCode());
return this.update(luw);
}
}
@Override
public List<RobotRealDataVO> getRealDataByRobotCode(String robotCode) {
Result<List<DeviceInstanceAttrVO>> 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<List<List<Map<String, RealDataRedisVO>>>> realDataResult = deviceDataClient.getDeviceRealDataByCodes(Lists.newArrayList(po));
Assert.isTrue(realDataResult.isSuccess(),() -> {
throw new ServiceException("获取设备实例实时数据失败!");
});
List<RobotRealDataVO> 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;
}
} }

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

11
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";
}

5
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_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_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 '设备编号'; 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 '是否绑定设备实例';

2
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) @ApiOperationSupport(order = 2)
public R saveOrUpdateBatch(@RequestBody @Valid List<RiskCheckDTO> req) { public R saveOrUpdateBatch(@RequestBody @Valid List<RiskCheckDTO> req) {
List<RiskCheckEntity> riskCheckList = JSONArray.parseArray(JSON.toJSONString(req), RiskCheckEntity.class); List<RiskCheckEntity> riskCheckList = JSONArray.parseArray(JSON.toJSONString(req), RiskCheckEntity.class);
return R.status(riskCheckService.saveBatch(riskCheckList)); return R.status(riskCheckService.saveOrUpdateBatch(riskCheckList));
} }
@DeleteMapping("/delete/{ids}") @DeleteMapping("/delete/{ids}")

Loading…
Cancel
Save