wcs设备注册

This commit is contained in:
cbs 2025-01-03 15:54:13 +08:00
parent 1a0881f0ad
commit bb03dd010f
22 changed files with 688 additions and 50 deletions

View File

@ -46,6 +46,7 @@
<spring.boot.version>2.7.18</spring.boot.version>
<mapstruct.version>1.6.2</mapstruct.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mqtt.version>1.2.5</mqtt.version>
</properties>
<dependencyManagement>
@ -69,6 +70,12 @@
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${mqtt.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -24,18 +24,46 @@
</dependency>
<!-- 依赖服务 -->
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-system-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-grpc-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-grpc-lib</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.12</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.grpc.service.api;
package cn.iocoder.yudao.module.grpc.api;
import cn.iocoder.yudao.module.grpc.api.GrpcServiceApi;
import cn.iocoder.yudao.module.grpc.service.geometry.GeometryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

View File

@ -3,14 +3,16 @@ package cn.iocoder.yudao.module.grpc.service.geometry;
import com.google.protobuf.DoubleValue;
import device.proto.model.common.Geometry;
import device.proto.model.common.Types;
import device.proto.robotics.nav.ChassisNavigationControlService;
import device.proto.robotics.nav.ChassisNavigationServiceGrpc;
import io.grpc.Channel;
import device.proto.api.al.robotics.universal.nav.ChassisNavigationServiceGrpc;
import lombok.extern.slf4j.Slf4j;
import net.devh.springboot.autoconfigure.grpc.client.GrpcClient;
import org.springframework.stereotype.Service;
import java.util.Iterator;
@Slf4j
@Service
public class GeometryServiceImpl implements GeometryService{
@ -19,18 +21,17 @@ public class GeometryServiceImpl implements GeometryService{
@Override
public String onVehiclePoseUpdated() {
log.info("测试GRPC连接");
ChassisNavigationServiceGrpc.ChassisNavigationServiceBlockingStub myServiceStub
= ChassisNavigationServiceGrpc.newBlockingStub(this.serverChannel);
Iterator<Geometry.Pose2d> pose2dIterator = myServiceStub.onVehiclePoseUpdated(null);
while (pose2dIterator.hasNext()) {
Geometry.Pose2d next = pose2dIterator.next();
System.out.println("返回的 " + next);
Iterator<ChassisNavigationControlService.Response> responseIterator = myServiceStub.onVehiclePoseUpdated(null);
while (responseIterator.hasNext()) {
log.info("机车推送的消息 :{}",responseIterator.next());
}
DoubleValue build = DoubleValue.newBuilder().build();
Types.Nothing nothing = myServiceStub.forkControl(build);
return nothing.toString();
ChassisNavigationControlService.Response response = myServiceStub.forkControl(build);
return response.toString();
}

View File

@ -1,7 +1,31 @@
# grpc配置
grpc:
# grpc clienT相关配置
client:
# 是服务端配置的名字GrpcClient注解会用到
ChassisNavigationService:
# gRPC服务端地址
host: 192.168.10.78
port: 6914
# 是否开启保持连接(长连接)
enableKeepAlive: true
# 保持连接时长默认20s
keepAliveTimeout: 20
# 没有RPC调用时是否保持连接默认false可禁用避免额外消耗CPU
keepAliveWithoutCalls: false
# 客户端负载均衡策略(round_robin默认, pick_first)
defaultLoadBalancingPolicy: round_robin
# 通信类型
# plaintext | plaintext_upgrade | tls
# 明文通信且http/2 | 明文通信且升级http/1.1为http/2 | 使用TLSALPN/NPN通信
negotiationType: plaintext
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
server-addr: localhost:8848 # Nacos 服务器地址
username: # Nacos 账号
password: # Nacos 密码
discovery: # 【配置中心】配置项

View File

@ -1,26 +1,3 @@
# grpc配置
grpc:
# grpc clienT相关配置
client:
# 是服务端配置的名字GrpcClient注解会用到
ChassisNavigationService:
# gRPC服务端地址
host: 192.168.10.211
port: 6914
# 是否开启保持连接(长连接)
enableKeepAlive: true
# 保持连接时长默认20s
keepAliveTimeout: 20
# 没有RPC调用时是否保持连接默认false可禁用避免额外消耗CPU
keepAliveWithoutCalls: false
# 客户端负载均衡策略(round_robin默认, pick_first)
defaultLoadBalancingPolicy: round_robin
# 通信类型
# plaintext | plaintext_upgrade | tls
# 明文通信且http/2 | 明文通信且升级http/1.1为http/2 | 使用TLSALPN/NPN通信
negotiationType: plaintext
spring:
application:
@ -45,7 +22,7 @@ spring:
fail-on-empty-beans: false # 允许序列化无属性的 Bean
server:
port: 48082
port: 48084
debug: false

View File

@ -7,7 +7,7 @@ spring:
# active: prod
server:
port: 48082
port: 48084
# 日志文件配置。注意,如果 logging.file.name 不放在 bootstrap.yaml 配置文件,而是放在 application.yaml 中,会导致出现 LOG_FILE_IS_UNDEFINED 文件
logging:

View File

@ -1,32 +1,69 @@
syntax = "proto3";
package device.proto.api.al.robotics.universal.nav;
package device.proto.robotics.nav;
option csharp_namespace = "Al.Proto.Api.Robotics.Nav";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "model/common/geometry.proto";
import "model/common/types.proto";
import "google/protobuf/struct.proto";
//姿
//2d位姿
message Pose2d {
double x = 1; //x
double y = 2; //y
double yaw = 3; //
}
message NavigateThroughPosesRequest {
//姿
repeated device.proto.model.common.Pose2d pose2ds = 1;
repeated Pose2d pose2ds = 1;
}
//
message JoyAgvRequest {
//x方向的速度
double vx = 1;
//y方向的速度
double vy = 2;
//
double angle = 3;
}
message Response {
//
string status_code = 1;
//
string message = 2;
//
google.protobuf.Struct data = 3;
}
service ChassisNavigationService {
//姿
rpc OnVehiclePoseUpdated(google.protobuf.Empty) returns (stream device.proto.model.common.Pose2d) {}
rpc OnVehiclePoseUpdated(google.protobuf.Empty) returns (stream Response) {}
//姿
rpc OnTrackingPoseUpdated(google.protobuf.Empty) returns (stream device.proto.model.common.Pose2d) {}
rpc OnTrackingPoseUpdated(google.protobuf.Empty) returns (stream Response) {}
//姿
rpc NavigateToPose(device.proto.model.common.Pose2d) returns (device.proto.model.common.Nothing) {}
rpc NavigateToPose(Pose2d) returns (Response) {}
//
rpc NavigateThroughPoses(NavigateThroughPosesRequest) returns (device.proto.model.common.Nothing) {}
rpc NavigateThroughPoses(NavigateThroughPosesRequest) returns (Response) {}
//
rpc ForkControl(google.protobuf.DoubleValue) returns (device.proto.model.common.Nothing) {}
rpc ForkControl(google.protobuf.DoubleValue) returns (Response) {}
//
rpc OnRobotStateUpdated(google.protobuf.Empty) returns (stream Response) {}
//IMU数据的更新
rpc OnChassesMainImuDataUpdated(google.protobuf.Empty) returns (stream Response) {}
//
rpc OnChassesOdometryUpdated(google.protobuf.Empty) returns (stream Response) {}
//
rpc OnPerceptionLaserOdometryUpdated(google.protobuf.Empty) returns (stream Response) {}
//
rpc OnWheelOdometryUpdated(google.protobuf.Empty) returns (stream Response) {}
//
rpc OnRobotFaultStatusUpdated(google.protobuf.Empty) returns (stream Response) {}
//
rpc JoyAgvControl(JoyAgvRequest) returns (Response) {}
//
rpc JoyForkControl(google.protobuf.Struct) returns (Response) {}
}

View File

@ -45,7 +45,6 @@
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>

View File

@ -163,4 +163,8 @@ public interface ErrorCodeConstants {
// ========== 站内信发送 1-002-028-000 ==========
ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_028_000, "模板参数({})缺失");
// ========== 设备信息 1-002-029-000 ==========
ErrorCode INFORMATION_NOT_EXISTS = new ErrorCode(1_002_029_001, "设备信息不存在");
ErrorCode INFORMATION_MAC_EXIST = new ErrorCode(1_002_029_002, "此Mac地址已经存在");
ErrorCode INFORMATION_MAC_INPUT = new ErrorCode(1_002_029_003, "请输入Mac地址");
}

View File

@ -35,6 +35,11 @@
<artifactId>yudao-module-infra-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-grpc-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>

View File

@ -0,0 +1,96 @@
package cn.iocoder.yudao.module.system.controller.admin.information;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationRespVO;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
import cn.iocoder.yudao.module.system.service.information.DeviceInformationService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 设备信息")
@RestController
@RequestMapping("/system/device/information")
@Validated
public class DeviceInformationController {
@Resource
private DeviceInformationService informationService;
@PostMapping("/create")
@Operation(summary = "创建设备信息")
@PreAuthorize("@ss.hasPermission('device:information:create')")
public CommonResult<Long> createInformation(@Valid @RequestBody DeviceInformationSaveReqVO createReqVO) {
return success(informationService.createInformation(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新设备信息")
@PreAuthorize("@ss.hasPermission('device:information:update')")
public CommonResult<Boolean> updateInformation(@Valid @RequestBody DeviceInformationSaveReqVO updateReqVO) {
informationService.updateInformation(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除设备信息")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('device:information:delete')")
public CommonResult<Boolean> deleteInformation(@RequestParam("id") Long id) {
informationService.deleteInformation(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得设备信息")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('device:information:query')")
public CommonResult<DeviceInformationRespVO> getInformation(@RequestParam("id") Long id) {
DeviceInformationDO information = informationService.getInformation(id);
return success(BeanUtils.toBean(information, DeviceInformationRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得设备信息分页")
@PreAuthorize("@ss.hasPermission('device:information:query')")
public CommonResult<PageResult<DeviceInformationRespVO>> getInformationPage(@Valid DeviceInformationPageReqVO pageReqVO) {
PageResult<DeviceInformationDO> pageResult = informationService.getInformationPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DeviceInformationRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出设备信息 Excel")
@PreAuthorize("@ss.hasPermission('device:information:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportInformationExcel(@Valid DeviceInformationPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DeviceInformationDO> list = informationService.getInformationPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "设备信息.xls", "数据", DeviceInformationRespVO.class,
BeanUtils.toBean(list, DeviceInformationRespVO.class));
}
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.system.controller.admin.information.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 设备信息分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class DeviceInformationPageReqVO extends PageParam {
@Schema(description = "设备类型1充电桩、2输送线、 3码垛机、4拆垛机、5自动门、6提升机、7信号灯、8按钮盒", example = "2")
private Integer deviceType;
@Schema(description = "设备编号")
private String deviceNo;
@Schema(description = "mac地址")
private String macAddress;
@Schema(description = "上传图片附件", example = "https://www.iocoder.cn")
private String url;
@Schema(description = "图片设置1默认图片、2上传图片、 3不显示图片")
private Integer pictureConfig;
@Schema(description = "设备状态1在线、2离线、 3异常", example = "1")
private Integer deviceStatus;
@Schema(description = "设备启用禁用0禁用、1启用")
private Integer deviceEnable;
@Schema(description = "设备协议")
private String deviceAgreement;
@Schema(description = "设备最后通讯时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] deviceLastTime;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.system.controller.admin.information.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 设备信息 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DeviceInformationRespVO {
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14335")
@ExcelProperty("主键ID")
private Long id;
@Schema(description = "设备类型1充电桩、2输送线、 3码垛机、4拆垛机、5自动门、6提升机、7信号灯、8按钮盒", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("设备类型1充电桩、2输送线、 3码垛机、4拆垛机、5自动门、6提升机、7信号灯、8按钮盒")
private Integer deviceType;
@Schema(description = "设备编号")
@ExcelProperty("设备编号")
private String deviceNo;
@Schema(description = "mac地址")
@ExcelProperty("mac地址")
private String macAddress;
@Schema(description = "上传图片附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
@ExcelProperty("上传图片附件")
private String url;
@Schema(description = "图片设置1默认图片、2上传图片、 3不显示图片")
@ExcelProperty("图片设置1默认图片、2上传图片、 3不显示图片")
private Integer pictureConfig;
@Schema(description = "设备状态1在线、2离线、 3异常", example = "1")
@ExcelProperty("设备状态1在线、2离线、 3异常")
private Integer deviceStatus;
@Schema(description = "设备启用禁用0禁用、1启用")
@ExcelProperty("设备启用禁用0禁用、1启用")
private Integer deviceEnable;
@Schema(description = "设备协议")
@ExcelProperty("设备协议")
private String deviceAgreement;
@Schema(description = "设备最后通讯时间")
@ExcelProperty("设备最后通讯时间")
private LocalDateTime deviceLastTime;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.system.controller.admin.information.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 设备信息新增/修改 Request VO")
@Data
public class DeviceInformationSaveReqVO {
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14335")
private Long id;
@Schema(description = "设备类型1充电桩、2输送线、 3码垛机、4拆垛机、5自动门、6提升机、7信号灯、8按钮盒", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "设备类型不能为空")
private Integer deviceType;
@Schema(description = "设备编号")
private String deviceNo;
@Schema(description = "mac地址")
private String macAddress;
@Schema(description = "上传图片附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
private String url;
@Schema(description = "图片设置1默认图片、2上传图片、 3不显示图片")
private Integer pictureConfig;
@Schema(description = "设备状态1在线、2离线、 3异常", example = "1")
private Integer deviceStatus;
@Schema(description = "设备启用禁用0禁用、1启用")
private Integer deviceEnable;
@Schema(description = "设备协议")
private String deviceAgreement;
@Schema(description = "设备最后通讯时间")
private LocalDateTime deviceLastTime;
}

View File

@ -0,0 +1,68 @@
package cn.iocoder.yudao.module.system.dal.dataobject.information;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 设备信息 DO
*
* @author 陈宾顺
*/
@TableName("device_information")
@KeySequence("device_information_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceInformationDO extends BaseDO {
/**
* 主键ID
*/
@TableId
private Long id;
/**
* 设备类型1充电桩2输送线 3码垛机4拆垛机5自动门6提升机7信号灯8按钮盒
*/
private Integer deviceType;
/**
* 设备编号
*/
private String deviceNo;
/**
* mac地址
*/
private String macAddress;
/**
* 上传图片附件
*/
private String url;
/**
* 图片设置1默认图片2上传图片 3不显示图片
*/
private Integer pictureConfig;
/**
* 设备状态1在线2离线 3异常
*/
private Integer deviceStatus;
/**
* 设备启用禁用0禁用1启用
*/
private Integer deviceEnable;
/**
* 设备协议
*/
private String deviceAgreement;
/**
* 设备最后通讯时间
*/
private LocalDateTime deviceLastTime;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.system.dal.mysql.information;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 设备信息 Mapper
*
* @author 陈宾顺
*/
@Mapper
public interface DeviceInformationMapper extends BaseMapperX<DeviceInformationDO> {
default PageResult<DeviceInformationDO> selectPage(DeviceInformationPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceInformationDO>()
.eqIfPresent(DeviceInformationDO::getDeviceType, reqVO.getDeviceType())
.eqIfPresent(DeviceInformationDO::getDeviceNo, reqVO.getDeviceNo())
.eqIfPresent(DeviceInformationDO::getMacAddress, reqVO.getMacAddress())
.eqIfPresent(DeviceInformationDO::getUrl, reqVO.getUrl())
.eqIfPresent(DeviceInformationDO::getPictureConfig, reqVO.getPictureConfig())
.eqIfPresent(DeviceInformationDO::getDeviceStatus, reqVO.getDeviceStatus())
.eqIfPresent(DeviceInformationDO::getDeviceEnable, reqVO.getDeviceEnable())
.eqIfPresent(DeviceInformationDO::getDeviceAgreement, reqVO.getDeviceAgreement())
.betweenIfPresent(DeviceInformationDO::getDeviceLastTime, reqVO.getDeviceLastTime())
.betweenIfPresent(DeviceInformationDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DeviceInformationDO::getId));
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.system.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum DeviceInformationType {
CHARGING_STATION(1, "充电桩"),
Conveyor_line(2, "输送线"),
PALLETIZER(3, "码垛机"),
DISMANTLING_MACHINE(4, "拆垛机"),
AUTOMATIC_DOOR(5, "自动门"),
HOIST(6, "提升机"),
SIGNAL_LIGHT(7, "信号灯"),
BUTTON_BOX(8, "按钮盒");
/**
* 类型
*/
private final Integer type;
/**
* 说明
*/
private final String source;
}

View File

@ -0,0 +1,10 @@
package cn.iocoder.yudao.module.system.framework.grpc.config;
import cn.iocoder.yudao.module.grpc.api.GrpcServiceApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {GrpcServiceApi.class})
public class GrpcConfiguration {
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.system.service.information;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
/**
* 设备信息 Service 接口
*
* @author 陈宾顺
*/
public interface DeviceInformationService {
/**
* 创建设备信息
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createInformation(@Valid DeviceInformationSaveReqVO createReqVO);
/**
* 更新设备信息
*
* @param updateReqVO 更新信息
*/
void updateInformation(@Valid DeviceInformationSaveReqVO updateReqVO);
/**
* 删除设备信息
*
* @param id 编号
*/
void deleteInformation(Long id);
/**
* 获得设备信息
*
* @param id 编号
* @return 设备信息
*/
DeviceInformationDO getInformation(Long id);
/**
* 获得设备信息分页
*
* @param pageReqVO 分页查询
* @return 设备信息分页
*/
PageResult<DeviceInformationDO> getInformationPage(DeviceInformationPageReqVO pageReqVO);
}

View File

@ -0,0 +1,100 @@
package cn.iocoder.yudao.module.system.service.information;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.grpc.api.GrpcServiceApi;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
import cn.iocoder.yudao.module.system.dal.mysql.information.DeviceInformationMapper;
import cn.iocoder.yudao.module.system.enums.DeviceInformationType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* 设备信息 Service 实现类
*
* @author 陈宾顺
*/
@Service
@Validated
@Slf4j
public class DeviceInformationServiceImpl implements DeviceInformationService {
@Resource
private DeviceInformationMapper informationMapper;
@Resource
private GrpcServiceApi grpcServiceApi;
@Override
public Long createInformation(DeviceInformationSaveReqVO createReqVO) {
DeviceInformationPageReqVO pageReqVO = new DeviceInformationPageReqVO();
pageReqVO.setMacAddress(createReqVO.getMacAddress());
PageResult<DeviceInformationDO> pageResult = informationMapper.selectPage(pageReqVO);
if(ObjectUtil.isNotEmpty(pageResult.getList())){
throw exception(INFORMATION_MAC_EXIST);
}
//AGV需要判断机车是否接收到此Mac地址
if(DeviceInformationType.PALLETIZER.getType().equals(createReqVO.getDeviceType())
&& ObjectUtil.isEmpty(createReqVO.getMacAddress())){
throw exception(INFORMATION_MAC_INPUT);
}
if(DeviceInformationType.PALLETIZER.getType().equals(createReqVO.getDeviceType())){
String jiCheResponse = grpcServiceApi.onVehiclePoseUpdated();
log.info("调用GRPC查询机车信息返回 :{}",jiCheResponse);
}
// 插入
DeviceInformationDO information = BeanUtils.toBean(createReqVO, DeviceInformationDO.class);
information.setDeviceStatus(1);
information.setDeviceLastTime(LocalDateTime.now());
informationMapper.insert(information);
// 返回
return information.getId();
}
@Override
public void updateInformation(DeviceInformationSaveReqVO updateReqVO) {
// 校验存在
validateInformationExists(updateReqVO.getId());
// 更新
DeviceInformationDO updateObj = BeanUtils.toBean(updateReqVO, DeviceInformationDO.class);
informationMapper.updateById(updateObj);
}
@Override
public void deleteInformation(Long id) {
// 校验存在
validateInformationExists(id);
// 删除
informationMapper.deleteById(id);
}
private void validateInformationExists(Long id) {
if (informationMapper.selectById(id) == null) {
throw exception(INFORMATION_NOT_EXISTS);
}
}
@Override
public DeviceInformationDO getInformation(Long id) {
return informationMapper.selectById(id);
}
@Override
public PageResult<DeviceInformationDO> getInformationPage(DeviceInformationPageReqVO pageReqVO) {
return informationMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.system.dal.mysql.information.DeviceInformationMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>