diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/RemoteControlDTO.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/RemoteControlDTO.java new file mode 100644 index 0000000..4c5cc15 --- /dev/null +++ b/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 params; + + @ApiModelProperty("机器码") + @NotBlank + private String machineCode; +} 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 740a04d..580aa59 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 @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzinfo.inspect.Constants; 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.RobotRealDataVO; 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) public R detail(RobotEntity 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); } @@ -177,4 +180,13 @@ public class RobotController extends BladeController { @RequestParam @ApiParam("结束时间") String endTime, Query 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)); + } } 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 ca7fc40..20f9d79 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,8 +1,10 @@ package com.hnac.hzinfo.inspect.ai.service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.RemoteControlDTO; 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; @@ -42,4 +44,8 @@ public interface IRobotService extends BaseService { Map> getRealDataByRobotCode(String robotCode); IPage getRobotSoeData(String robotCode, String startTime, String endTime, Query query); + + Object remoteControl(RemoteControlDTO dto); + + } 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 aa30f6b..f8313af 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,31 +1,31 @@ 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.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; -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.vo.RemoteControlDTO; 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.log.annotation.Business; -import com.hnac.hzinfo.log.annotation.Operate; -import com.hnac.hzinfo.log.contants.BusinessType; +import com.hnac.hzinfo.inspect.task.TaskContants; +import com.hnac.hzinfo.inspect.task.entity.TaskEntity; +import com.hnac.hzinfo.inspect.task.service.ITaskService; 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.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 com.hnac.hzinfo.sdk.v5.project.ProjectClient; +import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; 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 org.springblade.core.mp.support.Condition; 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.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.core.tool.utils.*; 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.Optional; -import java.util.function.Function; +import java.util.*; import java.util.stream.Collectors; /** @@ -62,8 +56,9 @@ import java.util.stream.Collectors; public class RobotServiceImpl extends BaseServiceImpl implements IRobotService { private final DeviceClient deviceClient; - private final IAnalyseDataSearchClient analyseDataSearchClient; private final DeviceDataClient deviceDataClient; + private final ControlClient controlClient; + private final ProjectClient projectClient; /** * 根据用户id 获取 机器人信息 @@ -87,6 +82,14 @@ public class RobotServiceImpl extends BaseServiceImpl throw new ServiceException("该机器人已经创建过设备实例,无需再创建!"); } else { + Result> projectVOResult = projectClient.getProjectIds(Collections.singletonList(device.getStationCode())); + Assert.isTrue(projectVOResult.isSuccess(),() -> { + throw new ServiceException("获取站点信息失败!"); + }); + List projectVOList = projectVOResult.getData(); + if (projectVOList==null||projectVOList.isEmpty()){ + throw new ServiceException("数据平台不存在该站点信息!"); + } String modelSignage = ParamCache.getValue(ParamConstants.ROBOT_MODEL_CODE); device.setModelSignage(Func.isNotEmpty(device.getModelSignage()) ? device.getModelSignage() : modelSignage); VirtualDeviceDTO req = BeanUtil.copy(device, VirtualDeviceDTO.class); @@ -151,5 +154,31 @@ public class RobotServiceImpl extends BaseServiceImpl 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 result = controlClient.sendToDevice(controlDTO); + Assert.isTrue(result.isSuccess(),()->{ + throw new ServiceException("修改遥控失败!"); + }); + + RobotEntity robotEntity = this.getOne(new LambdaQueryWrapper().eq(RobotEntity::getCode, dto.getDeviceCode())); + + //机器人停机任务置为未完成 + List 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 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(); + } + + + } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.java index 932cc16..ebfa615 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.java +++ b/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; +import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity; import com.hnac.hzinfo.inspect.task.dto.TaskDTO; import com.hnac.hzinfo.inspect.task.vo.TaskCountVO; import com.hnac.hzinfo.inspect.task.vo.TaskOfflineVO; @@ -127,4 +128,6 @@ public interface TaskMapper extends UserDataScopeBaseMapper { List getTaskData(@Param("userIds") List userIds, @Param("currentDate") String currentDate); List getSameDayTask(@Param("taskIds") List taskIds, @Param("status") String status,@Param("startDate") String startDate,@Param("endDate") String endDate); + + List getListByUserIdAndStatus(Long userId, String autoVideo, List taskStatus,String time); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml index 554313c..432259f 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/mapper/TaskMapper.xml @@ -452,4 +452,17 @@ + + diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java index df61c52..5dd62f1 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/ITaskService.java @@ -192,4 +192,6 @@ public interface ITaskService extends BaseService { List getTaskListStatistics(String startTime, String endTime,Long deptId); List exportTaskList(TaskDTO task); + + List getListByUserIdAndStatus(Long userId, List taskStatus,String time); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java index c9d29b8..a18d489 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java @@ -1188,4 +1188,9 @@ public class TaskServiceImpl extends BaseServiceImpl imp return voteChartVo; } + @Override + public List getListByUserIdAndStatus(Long userId, List taskStatus,String time) { + return this.baseMapper.getListByUserIdAndStatus(userId, PlanContants.InspectTypeEnum.ROBOT.getVal(),taskStatus,time); + } + }