Browse Source

机器人远程遥控

zhongwei
RnhaiWang 7 months ago
parent
commit
ea46d211fe
  1. 31
      hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/RemoteControlDTO.java
  2. 12
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java
  3. 6
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java
  4. 67
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java
  5. 3
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.java
  6. 13
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml
  7. 2
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java
  8. 5
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java

31
hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/RemoteControlDTO.java

@ -0,0 +1,31 @@
package com.hnac.hzinfo.inspect.ai.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.util.Map;
@Data
public class RemoteControlDTO {
@ApiModelProperty("站点编号")
@NotBlank
private String stationCode;
@ApiModelProperty("设备编码")
@NotBlank
private String deviceCode;
@ApiModelProperty("功能标识")
@NotBlank
private String signage;
@ApiModelProperty("参数列表")
@NotBlank
private Map<String, Object> params;
@ApiModelProperty("机器码")
@NotBlank
private String machineCode;
}

12
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotController.java

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzinfo.inspect.Constants; import com.hnac.hzinfo.inspect.Constants;
import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO;
import com.hnac.hzinfo.inspect.ai.vo.RemoteControlDTO;
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.RobotRealDataVO;
import com.hnac.hzinfo.inspect.ai.vo.robot.RobotServerTaskParam; import com.hnac.hzinfo.inspect.ai.vo.robot.RobotServerTaskParam;
@ -68,6 +69,8 @@ public class RobotController extends BladeController {
@Operate(label = "查看机器人详情",type = BusinessType.QUERY,ignore = false) @Operate(label = "查看机器人详情",type = BusinessType.QUERY,ignore = false)
public R<RobotEntity> detail(RobotEntity st_robot) { public R<RobotEntity> detail(RobotEntity st_robot) {
RobotEntity detail = st_robotService.getOne(Condition.getQueryWrapper(st_robot)); RobotEntity detail = st_robotService.getOne(Condition.getQueryWrapper(st_robot));
User user = UserCache.getUser(detail.getUserId());
detail.setUserName(Optional.ofNullable(user).map(User::getName).orElse(null));
return R.data(detail); return R.data(detail);
} }
@ -177,4 +180,13 @@ public class RobotController extends BladeController {
@RequestParam @ApiParam("结束时间") String endTime, Query query) { @RequestParam @ApiParam("结束时间") String endTime, Query query) {
return R.data(st_robotService.getRobotSoeData(robotCode,startTime,endTime,query)); return R.data(st_robotService.getRobotSoeData(robotCode,startTime,endTime,query));
} }
@PostMapping("/remoteControl")
@ApiOperationSupport(order = 13)
@ApiOperation(value = "机器人远程控制", notes = "机器人远程控制")
@Operate(label = "机器人远程控制",type = BusinessType.UPDATE,risk = Risk.HIGH,ignore = false)
public R sendToDevice(@RequestBody RemoteControlDTO dto) {
return R.data(st_robotService.remoteControl(dto));
}
} }

6
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IRobotService.java

@ -1,8 +1,10 @@
package com.hnac.hzinfo.inspect.ai.service; package com.hnac.hzinfo.inspect.ai.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData;
import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO;
import com.hnac.hzinfo.inspect.ai.vo.RemoteControlDTO;
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.vo.robot.RobotRealDataVO;
import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO; import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO;
@ -42,4 +44,8 @@ public interface IRobotService extends BaseService<RobotEntity> {
Map<String,List<RobotRealDataVO>> getRealDataByRobotCode(String robotCode); Map<String,List<RobotRealDataVO>> getRealDataByRobotCode(String robotCode);
IPage getRobotSoeData(String robotCode, String startTime, String endTime, Query query); IPage getRobotSoeData(String robotCode, String startTime, String endTime, Query query);
Object remoteControl(RemoteControlDTO dto);
} }

67
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/RobotServiceImpl.java

@ -1,31 +1,31 @@
package com.hnac.hzinfo.inspect.ai.service.impl; package com.hnac.hzinfo.inspect.ai.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists; 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.Constants;
import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO; import com.hnac.hzinfo.inspect.ai.dto.robot.RobotInstanceDTO;
import com.hnac.hzinfo.inspect.ai.vo.RemoteControlDTO;
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.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.inspect.constants.ParamConstants;
import com.hnac.hzinfo.log.annotation.Business; import com.hnac.hzinfo.inspect.task.TaskContants;
import com.hnac.hzinfo.log.annotation.Operate; import com.hnac.hzinfo.inspect.task.entity.TaskEntity;
import com.hnac.hzinfo.log.contants.BusinessType; import com.hnac.hzinfo.inspect.task.service.ITaskService;
import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.core.response.Result;
import com.hnac.hzinfo.sdk.v5.control.ControlClient;
import com.hnac.hzinfo.sdk.v5.control.dto.ControlDTO;
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient;
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; 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.po.DeviceRealDataPO;
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; 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.RealDataRedisVO;
import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO; import com.hnac.hzinfo.sdk.v5.device.vo.VirtualDeviceDTO;
import com.hnac.hzinfo.sdk.v5.project.ProjectClient;
import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
@ -35,20 +35,14 @@ 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.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.*;
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.springblade.system.cache.ParamCache;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -62,8 +56,9 @@ import java.util.stream.Collectors;
public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity> implements IRobotService { public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity> implements IRobotService {
private final DeviceClient deviceClient; private final DeviceClient deviceClient;
private final IAnalyseDataSearchClient analyseDataSearchClient;
private final DeviceDataClient deviceDataClient; private final DeviceDataClient deviceDataClient;
private final ControlClient controlClient;
private final ProjectClient projectClient;
/** /**
* 根据用户id 获取 机器人信息 * 根据用户id 获取 机器人信息
@ -87,6 +82,14 @@ public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity>
throw new ServiceException("该机器人已经创建过设备实例,无需再创建!"); throw new ServiceException("该机器人已经创建过设备实例,无需再创建!");
} }
else { else {
Result<List<ProjectVO>> projectVOResult = projectClient.getProjectIds(Collections.singletonList(device.getStationCode()));
Assert.isTrue(projectVOResult.isSuccess(),() -> {
throw new ServiceException("获取站点信息失败!");
});
List<ProjectVO> projectVOList = projectVOResult.getData();
if (projectVOList==null||projectVOList.isEmpty()){
throw new ServiceException("数据平台不存在该站点信息!");
}
String modelSignage = ParamCache.getValue(ParamConstants.ROBOT_MODEL_CODE); String modelSignage = ParamCache.getValue(ParamConstants.ROBOT_MODEL_CODE);
device.setModelSignage(Func.isNotEmpty(device.getModelSignage()) ? device.getModelSignage() : modelSignage); device.setModelSignage(Func.isNotEmpty(device.getModelSignage()) ? device.getModelSignage() : modelSignage);
VirtualDeviceDTO req = BeanUtil.copy(device, VirtualDeviceDTO.class); VirtualDeviceDTO req = BeanUtil.copy(device, VirtualDeviceDTO.class);
@ -151,5 +154,31 @@ public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity>
return result; return result;
} }
@Override
public Object remoteControl(RemoteControlDTO dto) {
ControlDTO controlDTO=new ControlDTO();
BeanUtil.copy(dto,controlDTO);
controlDTO.setProjectId(dto.getStationCode());
controlDTO.setOperator(String.valueOf(AuthUtil.getUserId()));
Result<Object> result = controlClient.sendToDevice(controlDTO);
Assert.isTrue(result.isSuccess(),()->{
throw new ServiceException("修改遥控失败!");
});
RobotEntity robotEntity = this.getOne(new LambdaQueryWrapper<RobotEntity>().eq(RobotEntity::getCode, dto.getDeviceCode()));
//机器人停机任务置为未完成
List<String> taskStatus = Arrays.asList(TaskContants.TaskStatusEnum.INIT_STATUS.getStatus(), TaskContants.TaskStatusEnum.UNDERWAY_STATUS.getStatus(), TaskContants.TaskStatusEnum.PAUSE_STATUS.getStatus());
ITaskService taskService = SpringUtil.getBean(ITaskService.class);
List<TaskEntity> robotTaskEntities=taskService.getListByUserIdAndStatus(robotEntity.getUserId(),taskStatus,DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
if (!robotTaskEntities.isEmpty()){
robotTaskEntities.forEach(item->item.setStatus(Integer.valueOf(TaskContants.TaskStatusEnum.UNFINISH_STATUS.getStatus())));
taskService.saveOrUpdateBatch(robotTaskEntities);
}
return result.getData();
}
} }

3
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.java

@ -1,5 +1,6 @@
package com.hnac.hzinfo.inspect.task.mapper; package com.hnac.hzinfo.inspect.task.mapper;
import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity;
import com.hnac.hzinfo.inspect.task.dto.TaskDTO; import com.hnac.hzinfo.inspect.task.dto.TaskDTO;
import com.hnac.hzinfo.inspect.task.vo.TaskCountVO; import com.hnac.hzinfo.inspect.task.vo.TaskCountVO;
import com.hnac.hzinfo.inspect.task.vo.TaskOfflineVO; import com.hnac.hzinfo.inspect.task.vo.TaskOfflineVO;
@ -127,4 +128,6 @@ public interface TaskMapper extends UserDataScopeBaseMapper<TaskEntity> {
List<TaskOfflineVO> getTaskData(@Param("userIds") List<Long> userIds, @Param("currentDate") String currentDate); List<TaskOfflineVO> getTaskData(@Param("userIds") List<Long> userIds, @Param("currentDate") String currentDate);
List<TaskEntity> getSameDayTask(@Param("taskIds") List<Long> taskIds, @Param("status") String status,@Param("startDate") String startDate,@Param("endDate") String endDate); List<TaskEntity> getSameDayTask(@Param("taskIds") List<Long> taskIds, @Param("status") String status,@Param("startDate") String startDate,@Param("endDate") String endDate);
List<TaskEntity> getListByUserIdAndStatus(Long userId, String autoVideo, List<String> taskStatus,String time);
} }

13
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml

@ -452,4 +452,17 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<select id="getListByUserIdAndStatus" resultType="com.hnac.hzinfo.inspect.task.entity.TaskEntity">
select *
from hz_st_ex_task a
join hz_st_ex_task_user b on a.id=b.task_id
where a.AUTO_VIDEO=#{autoVideo} and b.user_id=#{userId} and a.status in
<foreach collection="taskStatus" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
<if test="time!=null and time!=''">
and PLAN_START_TIME &lt;= #{time}
</if>
</select>
</mapper> </mapper>

2
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java

@ -192,4 +192,6 @@ public interface ITaskService extends BaseService<TaskEntity> {
List<VoteChartVo> getTaskListStatistics(String startTime, String endTime,Long deptId); List<VoteChartVo> getTaskListStatistics(String startTime, String endTime,Long deptId);
List<InspectTaskExportVO> exportTaskList(TaskDTO task); List<InspectTaskExportVO> exportTaskList(TaskDTO task);
List<TaskEntity> getListByUserIdAndStatus(Long userId, List<String> taskStatus,String time);
} }

5
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java

@ -1188,4 +1188,9 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, TaskEntity> imp
return voteChartVo; return voteChartVo;
} }
@Override
public List<TaskEntity> getListByUserIdAndStatus(Long userId, List<String> taskStatus,String time) {
return this.baseMapper.getListByUserIdAndStatus(userId, PlanContants.InspectTypeEnum.ROBOT.getVal(),taskStatus,time);
}
} }

Loading…
Cancel
Save