diff --git a/sql/mysql/iotdata.sql b/sql/mysql/iotdata.sql index ac0ce115b7..4a647804d4 100644 --- a/sql/mysql/iotdata.sql +++ b/sql/mysql/iotdata.sql @@ -27,34 +27,17 @@ CREATE TABLE `iot_iot_organization` CREATE TABLE `iot_device` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', - `device_config_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '设备配置id', `device_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '设备编号', `device_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '设备名称', `device_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '设备类型', - `siemens_series` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Siemens系列(S7-300、S7-1500)', - `siemens_connect_param` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)', - `read_cron_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读取任务方式(0无,1有)', - `read_repeat_value` int DEFAULT NULL COMMENT '读取任务时间间隔', - `read_repeat_unit` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读取任务时间间隔单位', - `read_cron` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读取任务时间表达式', - `write_cron_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '写入任务时间间隔', - `write_repeat_value` int DEFAULT NULL COMMENT '写入任务时间间隔', - `write_repeat_unit` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '写入任务时间间隔单位', - `write_cron` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '写入任务时间表达式', - `local_persistent` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '是否持久化(0不持久化,1持久化)', - `upload_rate` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '上传方式(1实时,2自定义)', - `rate_count` int DEFAULT NULL COMMENT '上传频率', - - `modbus_protocol` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'modbus协议类型(serial-rtu)', - `modbus_pattern` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'modbus模式(client)', - `port_name` varchar(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'modbus串口号', - `modbus_connect_param` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)', - `modbus_read_addr_gap` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读地址是否连续(0否,1是)', - - `is_upload` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '是否已下发(0下,1没下)', + `status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '状态', + `read_topic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读主题', + `write_topic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '写主题', `gateway_id` bigint NOT NULL COMMENT '网关id', - `org_id` bigint NOT NULL COMMENT '组织设备id', + `device_brand_id` bigint NOT NULL COMMENT '设备品牌id', + `off_line_duration` bigint NOT NULL COMMENT '离线间隔', + `last_online_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后上线时间', `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注', `is_enable` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', @@ -64,50 +47,26 @@ CREATE TABLE `iot_device` `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `tenant_id` bigint DEFAULT NULL COMMENT '租户id', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='物联设备表'; +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='物联设备表'; CREATE TABLE `iot_device_attribute` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', - `attribute_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '地址编码', - `address` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址', - `attribute_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '地址名称', + `attribute_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '属性编码', + `attribute_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '属性名称', + `address` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'PLC点位地址', `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址描述', - `address_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址类型', - `address_offset` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址偏移', - `address2_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址2类型', - `address2_offset` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址2偏移', - `group_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '所属组', - `group_id` int DEFAULT NULL COMMENT '所属组id', - `security_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '安全类别', - `io_status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读写状态', - `is_linear_transfer` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '是否线性换算(0是,1否)', - `data_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '数据类型', - `unit` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '单位', - `in_min_value` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '输入最小值', - `in_max_value` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '输入最大值', - `out_min_value` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '输出最小值', - `out_max_value` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '输出最大值', - `out_data_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '输出数据类型', - - `siemens_field_precision` int DEFAULT '0' COMMENT '精度', - `modbus_slave_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '站号', - `modbus_field_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '寄存器地址', - `modbus_address_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '寄存器类型', - `modbus_field_size` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '个数', - `modbus_field_precision` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '缩放因子(默认值为1,大于0的小数', - `modbus_field_order` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字节顺序', - `dept_id` int DEFAULT NULL COMMENT '组织机构', - `dept_name` varchar(255) DEFAULT NULL COMMENT '组织名称', - `source_data_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'mqtt进制类型binary,octal,hexadecimal,decimal', - `transfer_data_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '转化进制类型binary,octal,hexadecimal,decimal', - `cal_addresses` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址合并计算公式', - `factor` varchar(32) DEFAULT NULL COMMENT '系数', + `attribute_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址类型', + `io_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '读写方式', + `data_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '数据类型', + `data_type_remark` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '类型描述', + `data_unit` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '单位', + `data_formula` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '数据计算公式', `gateway_id` bigint NOT NULL COMMENT '网关id', `device_id` bigint NOT NULL COMMENT '设备id', - `org_id` bigint NOT NULL COMMENT '组织设备id', + `alert_id` bigint NOT NULL COMMENT '告警id', `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注', `is_enable` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用', @@ -118,8 +77,65 @@ CREATE TABLE `iot_device_attribute` `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `tenant_id` bigint DEFAULT NULL COMMENT '租户id', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='设备属性表'; +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='设备属性表'; + +CREATE TABLE `iot_alert` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', + `alert_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '编码', + `alert_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '名称', + `alert_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警类型', + `alert_level` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警等级', + `content` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警内容', + `condition` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警条件', + `condition_formula` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逻辑表达式', + + `alert_audio` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '告警音频', + `is_repeat` bit(1) NOT NULL DEFAULT b'1' COMMENT '重复告警', + `no_repeat_duration` bigint NOT NULL COMMENT '不重复间隔', + `is_enable` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint DEFAULT NULL COMMENT '租户id', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='告警配置'; +CREATE TABLE `iot_alert_record` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', + `alert_id` bigint NOT NULL COMMENT '告警ID', + `alert_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '编码', + `alert_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '名称', + `alert_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警类型', + `alert_level` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警等级', + `content` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警内容', + `condition` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '告警条件', + `condition_formula` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逻辑表达式', + + `alert_audio` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '告警音频', + `is_repeat` bit(1) NOT NULL DEFAULT b'1' COMMENT '重复告警', + `no_repeat_duration` bigint NOT NULL COMMENT '不重复间隔', + + `data_value` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '数据值', + `data_type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '数据类型', + `data_unit` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '单位', + `data_id` bigint NOT NULL COMMENT '来源ID', + `data_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '来源编码', + `data_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '来源名称', + `data_type_remark` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '描述', + + + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint DEFAULT NULL COMMENT '租户id', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='告警记录'; CREATE TABLE `iot_formula` diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/DeviceController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/DeviceController.java deleted file mode 100644 index 591fdbad1f..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/DeviceController.java +++ /dev/null @@ -1,152 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device; - -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DevicePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO; -import cn.iocoder.yudao.module.iot.service.device.DeviceService; -import cn.iocoder.yudao.module.iot.service.gateway.GatewayService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.io.IOException; -import java.util.List; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 物联设备") -@RestController -@RequestMapping("/iot/device") -@Validated -public class DeviceController { - - @Resource - private DeviceService deviceService; - @Resource - private GatewayService gatewayService; - - @PostMapping("/create") - @Operation(summary = "创建物联设备") - @PreAuthorize("@ss.hasPermission('iot:device:create')") - public CommonResult createDevice(@Valid @RequestBody DeviceSaveReqVO createReqVO) { - return success(deviceService.createDevice(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新物联设备") - @PreAuthorize("@ss.hasPermission('iot:device:update')") - public CommonResult updateDevice(@Valid @RequestBody DeviceSaveReqVO updateReqVO) { - deviceService.updateDevice(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除物联设备") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:device:delete')") - public CommonResult deleteDevice(@RequestParam("id") Long id) { - deviceService.deleteDevice(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得物联设备") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult getDevice(@RequestParam("id") Long id) { - DeviceDO device = deviceService.getDevice(id); - return success(BeanUtils.toBean(device, DeviceRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得物联设备分页") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult> getDevicePage(@Valid DevicePageReqVO pageReqVO) { - PageResult pageResult = deviceService.getDevicePage(pageReqVO); - return success(BeanUtils.toBean(pageResult, DeviceRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出物联设备 Excel") - @PreAuthorize("@ss.hasPermission('iot:device:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDeviceExcel(@Valid DevicePageReqVO pageReqVO, - HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = deviceService.getDevicePage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "物联设备.xls", "数据", DeviceRespVO.class, - BeanUtils.toBean(list, DeviceRespVO.class)); - } - - @GetMapping("/pushDevice") - @Operation(summary = "下发物联设备配置到网关") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:device:update')") - public CommonResult pushDevice(@RequestParam("id") Long id) { - DeviceDO device = deviceService.getDevice(id); - GatewayDO gatewayDO = gatewayService.getGateway(device.getGatewayId()); - return deviceService.pushDevice(device, gatewayDO); - } - // ==================== 子表(设备属性) ==================== - - @GetMapping("/device-attribute/page") - @Operation(summary = "获得设备属性分页") - @Parameter(name = "deviceId", description = "设备id") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult> getDeviceAttributePage(PageParam pageReqVO, - @RequestParam("deviceId") Long deviceId) { - return success(deviceService.getDeviceAttributePage(pageReqVO, deviceId)); - } - - @PostMapping("/device-attribute/create") - @Operation(summary = "创建设备属性") - @PreAuthorize("@ss.hasPermission('iot:device:create')") - public CommonResult createDeviceAttribute(@Valid @RequestBody DeviceAttributeDO deviceAttribute) { - DeviceDO deviceDO = deviceService.getDevice(deviceAttribute.getDeviceId()); - deviceAttribute.setDeviceCode(deviceDO.getDeviceCode()); - return success(deviceService.createDeviceAttribute(deviceAttribute)); - } - - @PutMapping("/device-attribute/update") - @Operation(summary = "更新设备属性") - @PreAuthorize("@ss.hasPermission('iot:device:update')") - public CommonResult updateDeviceAttribute(@Valid @RequestBody DeviceAttributeDO deviceAttribute) { - deviceService.updateDeviceAttribute(deviceAttribute); - return success(true); - } - - @DeleteMapping("/device-attribute/delete") - @Parameter(name = "id", description = "编号", required = true) - @Operation(summary = "删除设备属性") - @PreAuthorize("@ss.hasPermission('iot:device:delete')") - public CommonResult deleteDeviceAttribute(@RequestParam("id") Long id) { - deviceService.deleteDeviceAttribute(id); - return success(true); - } - - @GetMapping("/device-attribute/get") - @Operation(summary = "获得设备属性") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult getDeviceAttribute(@RequestParam("id") Long id) { - return success(deviceService.getDeviceAttribute(id)); - } - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java deleted file mode 100644 index d29b0d2659..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java +++ /dev/null @@ -1,128 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -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 DevicePageReqVO extends PageParam { - - @Schema(description = "设备配置id", example = "14050") - private String deviceConfigId; - - @Schema(description = "设备编号") - private String deviceCode; - - @Schema(description = "设备名称", example = "李四") - private String deviceName; - - @Schema(description = "设备类型", example = "2") - private String deviceType; - - @Schema(description = "Siemens系列(S7-300、S7-1500)") - private String siemensSeries; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String siemensConnectParam; - - @Schema(description = "读取任务方式(0无,1有)", example = "2") - private String readCronType; - - @Schema(description = "读取任务时间间隔") - private Integer readRepeatValue; - - @Schema(description = "读取任务时间间隔单位") - private String readRepeatUnit; - - @Schema(description = "读取任务时间表达式") - private String readCron; - - @Schema(description = "写入任务时间间隔", example = "1") - private String writeCronType; - - @Schema(description = "写入任务时间间隔") - private Integer writeRepeatValue; - - @Schema(description = "写入任务时间间隔单位") - private String writeRepeatUnit; - - @Schema(description = "写入任务时间表达式") - private String writeCron; - - @Schema(description = "是否持久化(0不持久化,1持久化)") - private String localPersistent; - - @Schema(description = "上传方式(1实时,2自定义)") - private String uploadRate; - - @Schema(description = "上传频率", example = "19796") - private Integer rateCount; - - @Schema(description = "modbus协议类型(serial-rtu)") - private String modbusProtocol; - - @Schema(description = "modbus模式(client)") - private String modbusPattern; - - @Schema(description = "modbus串口号", example = "李四") - private String portName; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String modbusConnectParam; - - @Schema(description = "读地址是否连续(0否,1是)") - private String modbusReadAddrGap; - - @Schema(description = "是否已下发(0下,1没下)") - private String isUpload; - - @Schema(description = "网关id", example = "6304") - private Long gatewayId; - - @Schema(description = "组织设备id", example = "23150") - private Long orgId; - - @Schema(description = "备注", example = "你猜") - private String remark; - - @Schema(description = "是否启用") - private Boolean isEnable; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - - @Schema(description = "数采设备类型", example = "2") - private String deviceUseType; - - @Schema(description = "ap_ip") - private String apIp; - - @Schema(description = "网桥ip") - private String gateBridgeIp; - - @Schema(description = "串口服务器IP") - private String comServerIp; - - @Schema(description = "串口服务器端口") - private String comServerPort; - - @Schema(description = "PLC控制器地址") - private String plcControllerIp; - - @Schema(description = "PLC触控屏地址") - private String plcScreenIp; - - @Schema(description = "i机台id", example = "18776") - private Long orgMachineId; -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java deleted file mode 100644 index 0be695a6e3..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java +++ /dev/null @@ -1,175 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 物联设备 Response VO") -@Data -@ExcelIgnoreUnannotated -public class DeviceRespVO { - - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8540") - @ExcelProperty("ID") - private Long id; - - @Schema(description = "设备配置id", example = "14050") - @ExcelProperty("设备配置id") - private String deviceConfigId; - - @Schema(description = "设备编号") - @ExcelProperty("设备编号") - private String deviceCode; - - @Schema(description = "设备名称", example = "李四") - @ExcelProperty("设备名称") - private String deviceName; - - @Schema(description = "设备类型", example = "2") - @ExcelProperty("设备类型") - private String deviceType; - - @Schema(description = "Siemens系列(S7-300、S7-1500)") - @ExcelProperty(value = "Siemens系列(S7-300、S7-1500)", converter = DictConvert.class) - @DictFormat("iot_siemens_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String siemensSeries; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - @ExcelProperty("连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String siemensConnectParam; - - @Schema(description = "读取任务方式(0无,1有)", example = "2") - @ExcelProperty(value = "读取任务方式(0无,1有)", converter = DictConvert.class) - @DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String readCronType; - - @Schema(description = "读取任务时间间隔") - @ExcelProperty("读取任务时间间隔") - private Integer readRepeatValue; - - @Schema(description = "读取任务时间间隔单位") - @ExcelProperty(value = "读取任务时间间隔单位", converter = DictConvert.class) - @DictFormat("iot_device_data_unit") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String readRepeatUnit; - - @Schema(description = "读取任务时间表达式") - @ExcelProperty("读取任务时间表达式") - private String readCron; - - @Schema(description = "写入任务时间间隔", example = "1") - @ExcelProperty("写入任务时间间隔") - private String writeCronType; - - @Schema(description = "写入任务时间间隔") - @ExcelProperty("写入任务时间间隔") - private Integer writeRepeatValue; - - @Schema(description = "写入任务时间间隔单位") - @ExcelProperty("写入任务时间间隔单位") - private String writeRepeatUnit; - - @Schema(description = "写入任务时间表达式") - @ExcelProperty("写入任务时间表达式") - private String writeCron; - - @Schema(description = "是否持久化(0不持久化,1持久化)") - @ExcelProperty(value = "是否持久化(0不持久化,1持久化)", converter = DictConvert.class) - @DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String localPersistent; - - @Schema(description = "上传方式(1实时,2自定义)") - @ExcelProperty(value = "上传方式(1实时,2自定义)", converter = DictConvert.class) - @DictFormat("iot_device_uploading_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String uploadRate; - - @Schema(description = "上传频率", example = "19796") - @ExcelProperty("上传频率") - private Integer rateCount; - - @Schema(description = "modbus协议类型(serial-rtu)") - @ExcelProperty(value = "modbus协议类型(serial-rtu)", converter = DictConvert.class) - @DictFormat("iot_modbus_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String modbusProtocol; - - @Schema(description = "modbus模式(client)") - @ExcelProperty(value = "modbus模式(client)", converter = DictConvert.class) - @DictFormat("iot_modbus_mold") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String modbusPattern; - - @Schema(description = "modbus串口号", example = "李四") - @ExcelProperty(value = "modbus串口号", converter = DictConvert.class) - @DictFormat("iot_modbus_port") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String portName; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - @ExcelProperty("连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String modbusConnectParam; - - @Schema(description = "读地址是否连续(0否,1是)") - @ExcelProperty(value = "读地址是否连续(0否,1是)", converter = DictConvert.class) - @DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String modbusReadAddrGap; - - @Schema(description = "是否已下发(0下,1没下)") - @ExcelProperty(value = "是否已下发(0下,1没下)", converter = DictConvert.class) - @DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String isUpload; - - @Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6304") - @ExcelProperty("网关id") - private Long gatewayId; - - @Schema(description = "组织设备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23150") - @ExcelProperty("组织设备id") - private Long orgId; - - @Schema(description = "备注", example = "你猜") - @ExcelProperty("备注") - private String remark; - - @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("是否启用") - private Boolean isEnable; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - - @Schema(description = "数采设备类型", example = "2") - @ExcelProperty(value = "数采设备类型", converter = DictConvert.class) - @DictFormat("iot_device_use_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private String deviceUseType; - - @Schema(description = "ap_ip") - @ExcelProperty("ap_ip") - private String apIp; - - @Schema(description = "网桥ip") - @ExcelProperty("网桥ip") - private String gateBridgeIp; - - @Schema(description = "串口服务器IP") - @ExcelProperty("串口服务器IP") - private String comServerIp; - - @Schema(description = "串口服务器端口") - @ExcelProperty("串口服务器端口") - private String comServerPort; - - @Schema(description = "PLC控制器地址") - @ExcelProperty("PLC控制器地址") - private String plcControllerIp; - - @Schema(description = "PLC触控屏地址") - @ExcelProperty("PLC触控屏地址") - private String plcScreenIp; - - @Schema(description = "i机台id", example = "18776") - @ExcelProperty("i机台id") - private Long orgMachineId; -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSaveReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSaveReqVO.java deleted file mode 100644 index 7532b51599..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSaveReqVO.java +++ /dev/null @@ -1,122 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 物联设备新增/修改 Request VO") -@Data -public class DeviceSaveReqVO { - - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8540") - private Long id; - - @Schema(description = "设备配置id", example = "14050") - private String deviceConfigId; - - @Schema(description = "设备编号") - private String deviceCode; - - @Schema(description = "设备名称", example = "李四") - private String deviceName; - - @Schema(description = "设备类型", example = "2") - private String deviceType; - - @Schema(description = "Siemens系列(S7-300、S7-1500)") - private String siemensSeries; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String siemensConnectParam; - - @Schema(description = "读取任务方式(0无,1有)", example = "2") - private String readCronType; - - @Schema(description = "读取任务时间间隔") - private Integer readRepeatValue; - - @Schema(description = "读取任务时间间隔单位") - private String readRepeatUnit; - - @Schema(description = "读取任务时间表达式") - private String readCron; - - @Schema(description = "写入任务时间间隔", example = "1") - private String writeCronType; - - @Schema(description = "写入任务时间间隔") - private Integer writeRepeatValue; - - @Schema(description = "写入任务时间间隔单位") - private String writeRepeatUnit; - - @Schema(description = "写入任务时间表达式") - private String writeCron; - - @Schema(description = "是否持久化(0不持久化,1持久化)") - private String localPersistent; - - @Schema(description = "上传方式(1实时,2自定义)") - private String uploadRate; - - @Schema(description = "上传频率", example = "19796") - private Integer rateCount; - - @Schema(description = "modbus协议类型(serial-rtu)") - private String modbusProtocol; - - @Schema(description = "modbus模式(client)") - private String modbusPattern; - - @Schema(description = "modbus串口号", example = "李四") - private String portName; - - @Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N)") - private String modbusConnectParam; - - @Schema(description = "读地址是否连续(0否,1是)") - private String modbusReadAddrGap; - - @Schema(description = "是否已下发(0下,1没下)") - private String isUpload; - - @Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6304") - @NotNull(message = "网关id不能为空") - private Long gatewayId; - - @Schema(description = "组织设备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23150") - @NotNull(message = "组织设备id不能为空") - private Long orgId; - - @Schema(description = "备注", example = "你猜") - private String remark; - - @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) - - private Boolean isEnable; - - @Schema(description = "数采设备类型", example = "2") - private String deviceUseType; - - @Schema(description = "ap_ip") - private String apIp; - - @Schema(description = "网桥ip") - private String gateBridgeIp; - - @Schema(description = "串口服务器IP") - private String comServerIp; - - @Schema(description = "串口服务器端口") - private String comServerPort; - - @Schema(description = "PLC控制器地址") - private String plcControllerIp; - - @Schema(description = "PLC触控屏地址") - private String plcScreenIp; - - @Schema(description = "i机台id", example = "18776") - private Long orgMachineId; -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ajreport/package-info.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ajreport/package-info.java deleted file mode 100644 index 2e66b32925..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ajreport/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:占位,待删除 - */ -package cn.iocoder.yudao.module.iot.dal.dataobject.ajreport; diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceAttributeDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceAttributeDO.java deleted file mode 100644 index 6c1352d17a..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceAttributeDO.java +++ /dev/null @@ -1,180 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * 设备属性 DO - * - * @author 内蒙必硕 - */ -@TableName("iot_device_attribute") -@KeySequence("iot_device_attribute_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DeviceAttributeDO extends BaseDO { - - /** - * ID - */ - @TableId - private Long id; - /** - * 地址编码 - */ - private String attributeCode; - /** - * 地址 - */ - private String address; - /** - * 地址名称 - */ - private String attributeName; - /** - * 地址描述 - */ - private String description; - /** - * 地址类型 - */ - private String addressType; - /** - * 地址偏移 - */ - private String addressOffset; - /** - * 地址2类型 - */ - private String address2Type; - /** - * 地址2偏移 - */ - private String address2Offset; - /** - * 所属组 - */ - private String groupName; - /** - * 所属组id - */ - private Integer groupId; - /** - * 安全类别 - */ - private String securityType; - /** - * 读写状态 - */ - private String ioStatus; - /** - * 是否线性换算(0是,1否) - *

- * 枚举 {@link TODO iot_1_or_0 对应的类} - */ - private String isLinearTransfer; - /** - * 数据类型 - *

- * 枚举 {@link TODO iot_device_data_type 对应的类} - */ - private String dataType; - /** - * 单位 - */ - private String unit; - /** - * 输入最小值 - */ - private String inMinValue; - /** - * 输入最大值 - */ - private String inMaxValue; - /** - * 输出最小值 - */ - private String outMinValue; - /** - * 输出最大值 - */ - private String outMaxValue; - /** - * 输出数据类型 - */ - private String outDataType; - /** - * 精度 - */ - private Integer siemensFieldPrecision; - /** - * 站号 - */ - private String modbusSlaveId; - /** - * 寄存器地址 - */ - private String modbusFieldAddress; - /** - * 寄存器类型 - */ - private String modbusAddressType; - /** - * 个数 - */ - private Integer modbusFieldSize; - /** - * 缩放因子(默认值为1,大于0的小数 - */ - private String modbusFieldPrecision; - /** - * 字节顺序 - */ - private String modbusFieldOrder; - /** - * mqtt进制类型binary,octal,hexadecimal,decimal - */ - private String sourceDataType; - /** - * 转化进制类型binary,octal,hexadecimal,decimal - *

- * 枚举 {@link TODO iot_device_data_transfer_type 对应的类} - */ - private String transferDataType; - /** - * 系数 - */ - private String factor; - /** - * 网关id - */ - private Long gatewayId; - /** - * 设备id - */ - private Long deviceId; - /** - * 设备code - */ - private String deviceCode; - /** - * 组织设备id - */ - private Long orgId; - /** - * 备注 - */ - private String remark; - /** - * 是否启用 - */ - private Boolean isEnable; - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceDO.java deleted file mode 100644 index 2f7358402a..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/DeviceDO.java +++ /dev/null @@ -1,180 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * 物联设备 DO - * - * @author 内蒙必硕 - */ -@TableName("iot_device") -@KeySequence("iot_device_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DeviceDO extends BaseDO { - - /** - * ID - */ - @TableId - private Long id; - /** - * 设备配置id - */ - private String deviceConfigId; - /** - * 设备编号 - */ - private String deviceCode; - /** - * 设备名称 - */ - private String deviceName; - /** - * 设备类型 - */ - private String deviceType; - /** - * Siemens系列(S7-300、S7-1500) - *

- * 枚举 {@link TODO iot_siemens_type 对应的类} - */ - private String siemensSeries; - /** - * 连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N) - */ - private String siemensConnectParam; - /** - * 读取任务方式(0无,1有) - *

- * 枚举 {@link TODO iot_1_or_0 对应的类} - */ - private String readCronType; - /** - * 读取任务时间间隔 - */ - private Integer readRepeatValue; - /** - * 读取任务时间间隔单位 - *

- * 枚举 {@link TODO iot_device_data_unit 对应的类} - */ - private String readRepeatUnit; - /** - * 读取任务时间表达式 - */ - private String readCron; - /** - * 写入任务时间间隔 - */ - private String writeCronType; - /** - * 写入任务时间间隔 - */ - private Integer writeRepeatValue; - /** - * 写入任务时间间隔单位 - */ - private String writeRepeatUnit; - /** - * 写入任务时间表达式 - */ - private String writeCron; - /** - * 是否持久化(0不持久化,1持久化) - *

- * 枚举 {@link TODO iot_1_or_0 对应的类} - */ - private String localPersistent; - /** - * 上传方式(1实时,2自定义) - *

- * 枚举 {@link TODO iot_device_uploading_type 对应的类} - */ - private String uploadRate; - /** - * 上传频率 - */ - private Integer rateCount; - /** - * modbus协议类型(serial-rtu) - *

- * 枚举 {@link TODO iot_modbus_type 对应的类} - */ - private String modbusProtocol; - /** - * modbus模式(client) - *

- * 枚举 {@link TODO iot_modbus_mold 对应的类} - */ - private String modbusPattern; - /** - * modbus串口号 - *

- * 枚举 {@link TODO iot_modbus_port 对应的类} - */ - private String portName; - /** - * 连接参数(波特率,数据位,停止位,校验位 例如:9600,8,1,N) - */ - private String modbusConnectParam; - /** - * 读地址是否连续(0否,1是) - *

- * 枚举 {@link TODO iot_1_or_0 对应的类} - */ - private String modbusReadAddrGap; - /** - * 是否已下发(0下,1没下) - *

- * 枚举 {@link TODO iot_1_or_0 对应的类} - */ - private String isUpload; - /** - * 网关id - */ - private Long gatewayId; - /** - * 组织设备id - */ - private Long orgId; - /** - * 备注 - */ - private String remark; - /** - * 是否启用 - */ - private Boolean isEnable; - //@Schema(description = "数采设备类型", example = "2") - private String deviceUseType; - - //@Schema(description = "ap_ip") - private String apIp; - - //@Schema(description = "网桥ip") - private String gateBridgeIp; - - //@Schema(description = "串口服务器IP") - private String comServerIp; - - //@Schema(description = "串口服务器端口") - private String comServerPort; - - //@Schema(description = "PLC控制器地址") - private String plcControllerIp; - - //@Schema(description = "PLC触控屏地址") - private String plcScreenIp; - - //@Schema(description = "i机台id", example = "18776") - private Long orgMachineId; -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ajreport/package-info.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ajreport/package-info.java deleted file mode 100644 index f56523c42e..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ajreport/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:占位,待删除 - */ -package cn.iocoder.yudao.module.iot.dal.mysql.ajreport; diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceAttributeMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceAttributeMapper.java deleted file mode 100644 index 2faf365f46..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceAttributeMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.device; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 设备属性 Mapper - * - * @author 内蒙必硕 - */ -@Mapper -public interface DeviceAttributeMapper extends BaseMapperX { - - default PageResult selectPage(PageParam reqVO, Long deviceId) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(DeviceAttributeDO::getDeviceId, deviceId) - .orderByDesc(DeviceAttributeDO::getId)); - } - - default int deleteByDeviceId(Long deviceId) { - return delete(DeviceAttributeDO::getDeviceId, deviceId); - } - - default List selectByDeviceId(Long deviceId) { - return selectList(DeviceAttributeDO::getDeviceId, deviceId); - } -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java deleted file mode 100644 index 5cd5cbf2d3..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java +++ /dev/null @@ -1,67 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.device; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DevicePageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 物联设备 Mapper - * - * @author 内蒙必硕 - */ -@Mapper -public interface DeviceMapper extends BaseMapperX { - - default PageResult selectPage(DevicePageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(DeviceDO::getDeviceConfigId, reqVO.getDeviceConfigId()) - .eqIfPresent(DeviceDO::getDeviceCode, reqVO.getDeviceCode()) - .likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName()) - .eqIfPresent(DeviceDO::getDeviceType, reqVO.getDeviceType()) - .eqIfPresent(DeviceDO::getSiemensSeries, reqVO.getSiemensSeries()) - .eqIfPresent(DeviceDO::getSiemensConnectParam, reqVO.getSiemensConnectParam()) - .eqIfPresent(DeviceDO::getReadCronType, reqVO.getReadCronType()) - .eqIfPresent(DeviceDO::getReadRepeatValue, reqVO.getReadRepeatValue()) - .eqIfPresent(DeviceDO::getReadRepeatUnit, reqVO.getReadRepeatUnit()) - .eqIfPresent(DeviceDO::getReadCron, reqVO.getReadCron()) - .eqIfPresent(DeviceDO::getWriteCronType, reqVO.getWriteCronType()) - .eqIfPresent(DeviceDO::getWriteRepeatValue, reqVO.getWriteRepeatValue()) - .eqIfPresent(DeviceDO::getWriteRepeatUnit, reqVO.getWriteRepeatUnit()) - .eqIfPresent(DeviceDO::getWriteCron, reqVO.getWriteCron()) - .eqIfPresent(DeviceDO::getLocalPersistent, reqVO.getLocalPersistent()) - .eqIfPresent(DeviceDO::getUploadRate, reqVO.getUploadRate()) - .eqIfPresent(DeviceDO::getRateCount, reqVO.getRateCount()) - .eqIfPresent(DeviceDO::getModbusProtocol, reqVO.getModbusProtocol()) - .eqIfPresent(DeviceDO::getModbusPattern, reqVO.getModbusPattern()) - .eqIfPresent(DeviceDO::getPortName, reqVO.getPortName()) - .eqIfPresent(DeviceDO::getModbusConnectParam, reqVO.getModbusConnectParam()) - .eqIfPresent(DeviceDO::getModbusReadAddrGap, reqVO.getModbusReadAddrGap()) - .eqIfPresent(DeviceDO::getIsUpload, reqVO.getIsUpload()) - .eqIfPresent(DeviceDO::getGatewayId, reqVO.getGatewayId()) - .eqIfPresent(DeviceDO::getOrgId, reqVO.getOrgId()) - .eqIfPresent(DeviceDO::getRemark, reqVO.getRemark()) - .eqIfPresent(DeviceDO::getIsEnable, reqVO.getIsEnable()) - .betweenIfPresent(DeviceDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(DeviceDO::getId)); - } - - default PageResult selectPage(PageParam reqVO, Long gatewayId) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(DeviceDO::getGatewayId, gatewayId) - .orderByDesc(DeviceDO::getId)); - } - - default int deleteByGatewayId(Long gatewayId) { - return delete(DeviceDO::getGatewayId, gatewayId); - } - - default List selectByGatewayId(Long gatewayId) { - return selectList(DeviceDO::getGatewayId, gatewayId); - } -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ajreport/package-info.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ajreport/package-info.java deleted file mode 100644 index 4e22bb8523..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ajreport/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:占位,待删除 - */ -package cn.iocoder.yudao.module.iot.service.ajreport; diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceService.java deleted file mode 100644 index 024cdb78e9..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceService.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DevicePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO; - -import javax.validation.Valid; - -/** - * 物联设备 Service 接口 - * - * @author 内蒙必硕 - */ -public interface DeviceService { - - /** - * 创建物联设备 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDevice(@Valid DeviceSaveReqVO createReqVO); - - /** - * 更新物联设备 - * - * @param updateReqVO 更新信息 - */ - void updateDevice(@Valid DeviceSaveReqVO updateReqVO); - - /** - * 删除物联设备 - * - * @param id 编号 - */ - void deleteDevice(Long id); - - /** - * 获得物联设备 - * - * @param id 编号 - * @return 物联设备 - */ - DeviceDO getDevice(Long id); - - /** - * 获得物联设备分页 - * - * @param pageReqVO 分页查询 - * @return 物联设备分页 - */ - PageResult getDevicePage(DevicePageReqVO pageReqVO); - - CommonResult pushDevice(DeviceDO deviceDO, GatewayDO gatewayDO); - // ==================== 子表(设备属性) ==================== - - /** - * 获得设备属性分页 - * - * @param pageReqVO 分页查询 - * @param deviceId 设备id - * @return 设备属性分页 - */ - PageResult getDeviceAttributePage(PageParam pageReqVO, Long deviceId); - - /** - * 创建设备属性 - * - * @param deviceAttribute 创建信息 - * @return 编号 - */ - Long createDeviceAttribute(@Valid DeviceAttributeDO deviceAttribute); - - /** - * 更新设备属性 - * - * @param deviceAttribute 更新信息 - */ - void updateDeviceAttribute(@Valid DeviceAttributeDO deviceAttribute); - - /** - * 删除设备属性 - * - * @param id 编号 - */ - void deleteDeviceAttribute(Long id); - - /** - * 获得设备属性 - * - * @param id 编号 - * @return 设备属性 - */ - DeviceAttributeDO getDeviceAttribute(Long id); - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java deleted file mode 100644 index d3bf5e83eb..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java +++ /dev/null @@ -1,189 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DevicePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO; -import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceAttributeMapper; -import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper; -import cn.iocoder.yudao.module.iot.framework.constant.DeviceTypeEnum; -import cn.iocoder.yudao.module.iot.framework.gateway.service.impl.TheGatewayServiceImpl; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_ATTRIBUTE_NOT_EXISTS; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_NOT_EXISTS; - -/** - * 物联设备 Service 实现类 - * - * @author 内蒙必硕 - */ -@Service -@Validated -public class DeviceServiceImpl implements DeviceService { - - @Resource - private DeviceMapper deviceMapper; - @Resource - private DeviceAttributeMapper deviceAttributeMapper; - - @Resource - private TheGatewayServiceImpl theGatewayService; - - @Override - public Long createDevice(DeviceSaveReqVO createReqVO) { - // 插入 - DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class); - deviceMapper.insert(device); - // 返回 - return device.getId(); - } - - @Override - public void updateDevice(DeviceSaveReqVO updateReqVO) { - // 校验存在 - validateDeviceExists(updateReqVO.getId()); - // 更新 - DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class); - deviceMapper.updateById(updateObj); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDevice(Long id) { - // 校验存在 - validateDeviceExists(id); - // 删除 - deviceMapper.deleteById(id); - - // 删除子表 - deleteDeviceAttributeByDeviceId(id); - } - - private void validateDeviceExists(Long id) { - if (deviceMapper.selectById(id) == null) { - throw exception(DEVICE_NOT_EXISTS); - } - } - - @Override - public DeviceDO getDevice(Long id) { - return deviceMapper.selectById(id); - } - - @Override - public PageResult getDevicePage(DevicePageReqVO pageReqVO) { - return deviceMapper.selectPage(pageReqVO); - } - - @Override - public CommonResult pushDevice(DeviceDO deviceDO, GatewayDO gatewayDO) { - if (DeviceTypeEnum.isSiemens(deviceDO.getDeviceType())) { - return siemensAdd(deviceDO, gatewayDO); - } else if (DeviceTypeEnum.isModbus(deviceDO.getDeviceType())) { - return modbusAdd(deviceDO, gatewayDO); - } else return CommonResult.error(500, "未知类型设备!"); - } - - public CommonResult siemensAdd(DeviceDO deviceDO, GatewayDO gatewayDO) { - if (gatewayDO != null && deviceDO != null && - deviceDO.getDeviceCode() != null && gatewayDO.getGatewayCode() != null) { - try { - //清除原本的西门子设备和点位数据 - theGatewayService.deleteSiemensEntity(gatewayDO, deviceDO); - //新增西门子设备 - theGatewayService.addSiemensEntity(gatewayDO, deviceDO); - //下发完成西门子设备后 下发对应设备的点位 - theGatewayService.addDeviceSiemensEntity(gatewayDO, deviceDO.getOrgMachineId(), deviceDO); - //修改下发标识 - deviceDO.setIsUpload("1"); - deviceMapper.updateById(deviceDO); - //启用设备 - //todo 启用有点问题 - theGatewayService.changeStatus(gatewayDO, deviceDO.getDeviceCode(), "siemens"); - return theGatewayService.compare(gatewayDO, deviceDO, "siemens"); - } catch (Exception e) { - e.getLocalizedMessage(); - } - } - return CommonResult.error(500, "设备或网关不存在!"); - } - - /*modbus设备下发*/ - public CommonResult modbusAdd(DeviceDO deviceDO, GatewayDO gatewayDO) { - if (deviceDO.getDeviceCode() != null && gatewayDO.getGatewayCode() != null) { - try { - //清除原本的Modbus设备和点位数据 - theGatewayService.deleteModbusEntity(gatewayDO, deviceDO.getDeviceCode()); - //新增Modbus - theGatewayService.addModbusEntity(gatewayDO, deviceDO); - //下发完成Modbus设备后 下发对应设备的点位 - theGatewayService.addDeviceModbusEntity(gatewayDO, deviceDO); - //修改下发标识 - deviceDO.setIsUpload("1"); - deviceMapper.updateById(deviceDO); - //启用设备 - theGatewayService.changeStatus(gatewayDO, deviceDO.getDeviceCode(), "modbus"); - return theGatewayService.compare(gatewayDO, deviceDO, "modbus"); - - } catch (Exception e) { - e.getLocalizedMessage(); - } - } - return CommonResult.error(500, "设备或网关不存在!"); - } - // ==================== 子表(设备属性) ==================== - - @Override - public PageResult getDeviceAttributePage(PageParam pageReqVO, Long deviceId) { - return deviceAttributeMapper.selectPage(pageReqVO, deviceId); - } - - @Override - public Long createDeviceAttribute(DeviceAttributeDO deviceAttribute) { - deviceAttributeMapper.insert(deviceAttribute); - return deviceAttribute.getId(); - } - - @Override - public void updateDeviceAttribute(DeviceAttributeDO deviceAttribute) { - // 校验存在 - validateDeviceAttributeExists(deviceAttribute.getId()); - // 更新 - deviceAttributeMapper.updateById(deviceAttribute); - } - - @Override - public void deleteDeviceAttribute(Long id) { - // 校验存在 - validateDeviceAttributeExists(id); - // 删除 - deviceAttributeMapper.deleteById(id); - } - - @Override - public DeviceAttributeDO getDeviceAttribute(Long id) { - return deviceAttributeMapper.selectById(id); - } - - private void validateDeviceAttributeExists(Long id) { - if (deviceAttributeMapper.selectById(id) == null) { - throw exception(DEVICE_ATTRIBUTE_NOT_EXISTS); - } - } - - private void deleteDeviceAttributeByDeviceId(Long deviceId) { - deviceAttributeMapper.deleteByDeviceId(deviceId); - } - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml deleted file mode 100644 index 548b593d61..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImplTest.java b/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImplTest.java deleted file mode 100644 index a3d8891126..0000000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImplTest.java +++ /dev/null @@ -1,231 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO; -import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; - -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; -import static org.junit.jupiter.api.Assertions.*; - -/** - * {@link DeviceServiceImpl} 的单元测试类 - * - * @author 内蒙必硕 - */ -@Import(DeviceServiceImpl.class) -public class DeviceServiceImplTest extends BaseDbUnitTest { - - @Resource - private DeviceServiceImpl deviceService; - - @Resource - private DeviceMapper deviceMapper; - - @Test - public void testCreateDevice_success() { - // 准备参数 - DeviceSaveReqVO createReqVO = randomPojo(DeviceSaveReqVO.class).setId(null); - - // 调用 - Long deviceId = deviceService.createDevice(createReqVO); - // 断言 - assertNotNull(deviceId); - // 校验记录的属性是否正确 - DeviceDO device = deviceMapper.selectById(deviceId); - assertPojoEquals(createReqVO, device, "id"); - } - - @Test - public void testUpdateDevice_success() { - // mock 数据 - DeviceDO dbDevice = randomPojo(DeviceDO.class); - deviceMapper.insert(dbDevice);// @Sql: 先插入出一条存在的数据 - // 准备参数 - DeviceSaveReqVO updateReqVO = randomPojo(DeviceSaveReqVO.class, o -> { - o.setId(dbDevice.getId()); // 设置更新的 ID - }); - - // 调用 - deviceService.updateDevice(updateReqVO); - // 校验是否更新正确 - DeviceDO device = deviceMapper.selectById(updateReqVO.getId()); // 获取最新的 - assertPojoEquals(updateReqVO, device); - } - - @Test - public void testUpdateDevice_notExists() { - // 准备参数 - DeviceSaveReqVO updateReqVO = randomPojo(DeviceSaveReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> deviceService.updateDevice(updateReqVO), DEVICE_NOT_EXISTS); - } - - @Test - public void testDeleteDevice_success() { - // mock 数据 - DeviceDO dbDevice = randomPojo(DeviceDO.class); - deviceMapper.insert(dbDevice);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbDevice.getId(); - - // 调用 - deviceService.deleteDevice(id); - // 校验数据不存在了 - assertNull(deviceMapper.selectById(id)); - } - - @Test - public void testDeleteDevice_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> deviceService.deleteDevice(id), DEVICE_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetDevicePage() { - // mock 数据 - DeviceDO dbDevice = randomPojo(DeviceDO.class, o -> { // 等会查询到 - o.setDeviceConfigId(null); - o.setDeviceCode(null); - o.setDeviceName(null); - o.setDeviceType(null); - o.setSiemensSeries(null); - o.setSiemensConnectParam(null); - o.setReadCronType(null); - o.setReadRepeatValue(null); - o.setReadRepeatUnit(null); - o.setReadCron(null); - o.setWriteCronType(null); - o.setWriteRepeatValue(null); - o.setWriteRepeatUnit(null); - o.setWriteCron(null); - o.setLocalPersistent(null); - o.setUploadRate(null); - o.setRateCount(null); - o.setModbusProtocol(null); - o.setModbusPattern(null); - o.setPortName(null); - o.setModbusConnectParam(null); - o.setModbusReadAddrGap(null); - o.setIsUpload(null); - o.setGatewayId(null); - o.setOrgId(null); - o.setRemark(null); - o.setIsEnable(null); - o.setCreateTime(null); - }); - deviceMapper.insert(dbDevice); - // 测试 deviceConfigId 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceConfigId(null))); - // 测试 deviceCode 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceCode(null))); - // 测试 deviceName 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceName(null))); - // 测试 deviceType 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceType(null))); - // 测试 siemensSeries 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setSiemensSeries(null))); - // 测试 siemensConnectParam 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setSiemensConnectParam(null))); - // 测试 readCronType 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadCronType(null))); - // 测试 readRepeatValue 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadRepeatValue(null))); - // 测试 readRepeatUnit 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadRepeatUnit(null))); - // 测试 readCron 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadCron(null))); - // 测试 writeCronType 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteCronType(null))); - // 测试 writeRepeatValue 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteRepeatValue(null))); - // 测试 writeRepeatUnit 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteRepeatUnit(null))); - // 测试 writeCron 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteCron(null))); - // 测试 localPersistent 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setLocalPersistent(null))); - // 测试 uploadRate 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setUploadRate(null))); - // 测试 rateCount 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setRateCount(null))); - // 测试 modbusProtocol 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusProtocol(null))); - // 测试 modbusPattern 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusPattern(null))); - // 测试 portName 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setPortName(null))); - // 测试 modbusConnectParam 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusConnectParam(null))); - // 测试 modbusReadAddrGap 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusReadAddrGap(null))); - // 测试 isUpload 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setIsUpload(null))); - // 测试 gatewayId 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setGatewayId(null))); - // 测试 orgId 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setOrgId(null))); - // 测试 remark 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setRemark(null))); - // 测试 isEnable 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setIsEnable(null))); - // 测试 createTime 不匹配 - deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setCreateTime(null))); - // 准备参数 - DevicePageReqVO reqVO = new DevicePageReqVO(); - reqVO.setDeviceConfigId(null); - reqVO.setDeviceCode(null); - reqVO.setDeviceName(null); - reqVO.setDeviceType(null); - reqVO.setSiemensSeries(null); - reqVO.setSiemensConnectParam(null); - reqVO.setReadCronType(null); - reqVO.setReadRepeatValue(null); - reqVO.setReadRepeatUnit(null); - reqVO.setReadCron(null); - reqVO.setWriteCronType(null); - reqVO.setWriteRepeatValue(null); - reqVO.setWriteRepeatUnit(null); - reqVO.setWriteCron(null); - reqVO.setLocalPersistent(null); - reqVO.setUploadRate(null); - reqVO.setRateCount(null); - reqVO.setModbusProtocol(null); - reqVO.setModbusPattern(null); - reqVO.setPortName(null); - reqVO.setModbusConnectParam(null); - reqVO.setModbusReadAddrGap(null); - reqVO.setIsUpload(null); - reqVO.setGatewayId(null); - reqVO.setOrgId(null); - reqVO.setRemark(null); - reqVO.setIsEnable(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - - // 调用 - PageResult pageResult = deviceService.getDevicePage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbDevice, pageResult.getList().get(0)); - } - -} \ No newline at end of file