add device and alert

plp
chenshuichuan 2 years ago
parent 7450017d0c
commit 806174e2e3

@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
*/ */
public interface ErrorCodeConstants { public interface ErrorCodeConstants {
// ========== GoView 模块 1-003-000-000 ==========
ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备不存在"); ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备不存在");
ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备属性不存在"); ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备属性不存在");
ErrorCode FORMULA_NOT_EXISTS = new ErrorCode(1_003_000_000, "公式不存在"); ErrorCode FORMULA_NOT_EXISTS = new ErrorCode(1_003_000_000, "公式不存在");
@ -29,4 +28,6 @@ public interface ErrorCodeConstants {
ErrorCode FEEDBACK_NOT_EXISTS = new ErrorCode(1_003_000_001, "用户反馈不存在"); ErrorCode FEEDBACK_NOT_EXISTS = new ErrorCode(1_003_000_001, "用户反馈不存在");
ErrorCode MQTT_DATA_RECORD_NOT_EXISTS = new ErrorCode(1_003_000_003, "设备数据记录不存在"); ErrorCode MQTT_DATA_RECORD_NOT_EXISTS = new ErrorCode(1_003_000_003, "设备数据记录不存在");
ErrorCode ALERT_NOT_EXISTS = new ErrorCode(1_003_000_003, "告警配置不存在");
ErrorCode ALERT_RECORD_NOT_EXISTS = new ErrorCode(1_003_000_003, "告警记录不存在");
} }

@ -0,0 +1,139 @@
package cn.iocoder.yudao.module.iot.controller.admin.alert;
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.constraints.*;
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.*;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.AlertDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.module.iot.service.alert.AlertService;
@Tag(name = "管理后台 - 告警配置")
@RestController
@RequestMapping("/iot/alert")
@Validated
public class AlertController {
@Resource
private AlertService alertService;
@PostMapping("/create")
@Operation(summary = "创建告警配置")
@PreAuthorize("@ss.hasPermission('iot:alert:create')")
public CommonResult<Long> createAlert(@Valid @RequestBody AlertSaveReqVO createReqVO) {
return success(alertService.createAlert(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新告警配置")
@PreAuthorize("@ss.hasPermission('iot:alert:update')")
public CommonResult<Boolean> updateAlert(@Valid @RequestBody AlertSaveReqVO updateReqVO) {
alertService.updateAlert(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除告警配置")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:alert:delete')")
public CommonResult<Boolean> deleteAlert(@RequestParam("id") Long id) {
alertService.deleteAlert(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得告警配置")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:alert:query')")
public CommonResult<AlertRespVO> getAlert(@RequestParam("id") Long id) {
AlertDO alert = alertService.getAlert(id);
return success(BeanUtils.toBean(alert, AlertRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得告警配置分页")
@PreAuthorize("@ss.hasPermission('iot:alert:query')")
public CommonResult<PageResult<AlertRespVO>> getAlertPage(@Valid AlertPageReqVO pageReqVO) {
PageResult<AlertDO> pageResult = alertService.getAlertPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AlertRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出告警配置 Excel")
@PreAuthorize("@ss.hasPermission('iot:alert:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportAlertExcel(@Valid AlertPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<AlertDO> list = alertService.getAlertPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "告警配置.xls", "数据", AlertRespVO.class,
BeanUtils.toBean(list, AlertRespVO.class));
}
// ==================== 子表(告警记录) ====================
@GetMapping("/alert-record/page")
@Operation(summary = "获得告警记录分页")
@Parameter(name = "alertId", description = "告警ID")
@PreAuthorize("@ss.hasPermission('iot:alert:query')")
public CommonResult<PageResult<AlertRecordDO>> getAlertRecordPage(PageParam pageReqVO,
@RequestParam("alertId") Long alertId) {
return success(alertService.getAlertRecordPage(pageReqVO, alertId));
}
@PostMapping("/alert-record/create")
@Operation(summary = "创建告警记录")
@PreAuthorize("@ss.hasPermission('iot:alert:create')")
public CommonResult<Long> createAlertRecord(@Valid @RequestBody AlertRecordDO alertRecord) {
return success(alertService.createAlertRecord(alertRecord));
}
@PutMapping("/alert-record/update")
@Operation(summary = "更新告警记录")
@PreAuthorize("@ss.hasPermission('iot:alert:update')")
public CommonResult<Boolean> updateAlertRecord(@Valid @RequestBody AlertRecordDO alertRecord) {
alertService.updateAlertRecord(alertRecord);
return success(true);
}
@DeleteMapping("/alert-record/delete")
@Parameter(name = "id", description = "编号", required = true)
@Operation(summary = "删除告警记录")
@PreAuthorize("@ss.hasPermission('iot:alert:delete')")
public CommonResult<Boolean> deleteAlertRecord(@RequestParam("id") Long id) {
alertService.deleteAlertRecord(id);
return success(true);
}
@GetMapping("/alert-record/get")
@Operation(summary = "获得告警记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:alert:query')")
public CommonResult<AlertRecordDO> getAlertRecord(@RequestParam("id") Long id) {
return success(alertService.getAlertRecord(id));
}
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.controller.admin.alert.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 AlertPageReqVO extends PageParam {
@Schema(description = "编码")
private String alertCode;
@Schema(description = "名称", example = "李四")
private String alertName;
@Schema(description = "告警类型", example = "2")
private String alertType;
@Schema(description = "告警等级")
private String alertLevel;
@Schema(description = "告警内容")
private String content;
@Schema(description = "告警条件")
private String condition;
@Schema(description = "逻辑表达式")
private String conditionFormula;
@Schema(description = "告警音频")
private String alertAudio;
@Schema(description = "重复告警")
private Boolean isRepeat;
@Schema(description = "不重复间隔")
private Long noRepeatDuration;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.iot.controller.admin.alert.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 告警配置 Response VO")
@Data
@ExcelIgnoreUnannotated
public class AlertRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "28840")
@ExcelProperty("ID")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("编码")
private String alertCode;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("名称")
private String alertName;
@Schema(description = "告警类型", example = "2")
@ExcelProperty(value = "告警类型", converter = DictConvert.class)
@DictFormat("iot_alert_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String alertType;
@Schema(description = "告警等级")
@ExcelProperty(value = "告警等级", converter = DictConvert.class)
@DictFormat("iot_alert_level") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String alertLevel;
@Schema(description = "告警内容")
@ExcelProperty("告警内容")
private String content;
@Schema(description = "告警条件")
@ExcelProperty("告警条件")
private String condition;
@Schema(description = "逻辑表达式")
@ExcelProperty("逻辑表达式")
private String conditionFormula;
@Schema(description = "告警音频", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("告警音频")
private String alertAudio;
@Schema(description = "重复告警", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "重复告警", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isRepeat;
@Schema(description = "不重复间隔", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("不重复间隔")
private Long noRepeatDuration;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "是否启用", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.controller.admin.alert.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
@Schema(description = "管理后台 - 告警配置新增/修改 Request VO")
@Data
public class AlertSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "28840")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "编码不能为空")
private String alertCode;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotEmpty(message = "名称不能为空")
private String alertName;
@Schema(description = "告警类型", example = "2")
private String alertType;
@Schema(description = "告警等级")
private String alertLevel;
@Schema(description = "告警内容")
private String content;
@Schema(description = "告警条件")
private String condition;
@Schema(description = "逻辑表达式")
private String conditionFormula;
@Schema(description = "告警音频", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "告警音频不能为空")
private String alertAudio;
@Schema(description = "重复告警", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "重复告警不能为空")
private Boolean isRepeat;
@Schema(description = "不重复间隔", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "不重复间隔不能为空")
private Long noRepeatDuration;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
}

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.iot.controller.admin.alertrecord;
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.constraints.*;
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.*;
import cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.module.iot.service.alertrecord.AlertRecordService;
@Tag(name = "管理后台 - 告警记录")
@RestController
@RequestMapping("/iot/alert-record")
@Validated
public class AlertRecordController {
@Resource
private AlertRecordService alertRecordService;
@PostMapping("/create")
@Operation(summary = "创建告警记录")
@PreAuthorize("@ss.hasPermission('iot:alert-record:create')")
public CommonResult<Long> createAlertRecord(@Valid @RequestBody AlertRecordSaveReqVO createReqVO) {
return success(alertRecordService.createAlertRecord(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新告警记录")
@PreAuthorize("@ss.hasPermission('iot:alert-record:update')")
public CommonResult<Boolean> updateAlertRecord(@Valid @RequestBody AlertRecordSaveReqVO updateReqVO) {
alertRecordService.updateAlertRecord(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除告警记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:alert-record:delete')")
public CommonResult<Boolean> deleteAlertRecord(@RequestParam("id") Long id) {
alertRecordService.deleteAlertRecord(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得告警记录")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:alert-record:query')")
public CommonResult<AlertRecordRespVO> getAlertRecord(@RequestParam("id") Long id) {
AlertRecordDO alertRecord = alertRecordService.getAlertRecord(id);
return success(BeanUtils.toBean(alertRecord, AlertRecordRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得告警记录分页")
@PreAuthorize("@ss.hasPermission('iot:alert-record:query')")
public CommonResult<PageResult<AlertRecordRespVO>> getAlertRecordPage(@Valid AlertRecordPageReqVO pageReqVO) {
PageResult<AlertRecordDO> pageResult = alertRecordService.getAlertRecordPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AlertRecordRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出告警记录 Excel")
@PreAuthorize("@ss.hasPermission('iot:alert-record:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportAlertRecordExcel(@Valid AlertRecordPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<AlertRecordDO> list = alertRecordService.getAlertRecordPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "告警记录.xls", "数据", AlertRecordRespVO.class,
BeanUtils.toBean(list, AlertRecordRespVO.class));
}
}

@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.iot.controller.admin.alertrecord.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 AlertRecordPageReqVO extends PageParam {
@Schema(description = "编码")
private String alertCode;
@Schema(description = "名称", example = "赵六")
private String alertName;
@Schema(description = "告警类型", example = "2")
private String alertType;
@Schema(description = "告警等级")
private String alertLevel;
@Schema(description = "告警内容")
private String content;
@Schema(description = "告警条件")
private String condition;
@Schema(description = "逻辑表达式")
private String conditionFormula;
@Schema(description = "数据值")
private String dataValue;
@Schema(description = "数据类型", example = "1")
private String dataType;
@Schema(description = "单位")
private String dataUnit;
@Schema(description = "描述", example = "你说的对")
private String dataTypeRemark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "告警ID", example = "16965")
private Long alertId;
@Schema(description = "告警音频")
private String alertAudio;
@Schema(description = "重复告警")
private Boolean isRepeat;
@Schema(description = "不重复间隔")
private Long noRepeatDuration;
@Schema(description = "来源ID", example = "19268")
private Long dataId;
@Schema(description = "来源编码")
private String dataCode;
@Schema(description = "来源名称", example = "芋艿")
private String dataName;
}

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 告警记录 Response VO")
@Data
@ExcelIgnoreUnannotated
public class AlertRecordRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31176")
@ExcelProperty("ID")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("编码")
private String alertCode;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@ExcelProperty("名称")
private String alertName;
@Schema(description = "告警类型", example = "2")
@ExcelProperty(value = "告警类型", converter = DictConvert.class)
@DictFormat("iot_alert_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String alertType;
@Schema(description = "告警等级")
@ExcelProperty(value = "告警等级", converter = DictConvert.class)
@DictFormat("iot_alert_level") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String alertLevel;
@Schema(description = "告警内容")
@ExcelProperty("告警内容")
private String content;
@Schema(description = "告警条件")
@ExcelProperty("告警条件")
private String condition;
@Schema(description = "逻辑表达式")
@ExcelProperty("逻辑表达式")
private String conditionFormula;
@Schema(description = "数据值")
@ExcelProperty("数据值")
private String dataValue;
@Schema(description = "数据类型", example = "1")
@ExcelProperty(value = "数据类型", converter = DictConvert.class)
@DictFormat("iot_device_data_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String dataType;
@Schema(description = "单位")
@ExcelProperty("单位")
private String dataUnit;
@Schema(description = "描述", example = "你说的对")
@ExcelProperty("描述")
private String dataTypeRemark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "告警ID", example = "16965")
@ExcelProperty("告警ID")
private Long alertId;
@Schema(description = "告警音频")
@ExcelProperty("告警音频")
private String alertAudio;
@Schema(description = "重复告警")
@ExcelProperty(value = "重复告警", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isRepeat;
@Schema(description = "不重复间隔")
@ExcelProperty("不重复间隔")
private Long noRepeatDuration;
@Schema(description = "来源ID", example = "19268")
@ExcelProperty("来源ID")
private Long dataId;
@Schema(description = "来源编码")
@ExcelProperty("来源编码")
private String dataCode;
@Schema(description = "来源名称", example = "芋艿")
@ExcelProperty("来源名称")
private String dataName;
}

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 告警记录新增/修改 Request VO")
@Data
public class AlertRecordSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31176")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "编码不能为空")
private String alertCode;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@NotEmpty(message = "名称不能为空")
private String alertName;
@Schema(description = "告警类型", example = "2")
private String alertType;
@Schema(description = "告警等级")
private String alertLevel;
@Schema(description = "告警内容")
private String content;
@Schema(description = "告警条件")
private String condition;
@Schema(description = "逻辑表达式")
private String conditionFormula;
@Schema(description = "数据值")
private String dataValue;
@Schema(description = "数据类型", example = "1")
private String dataType;
@Schema(description = "单位")
private String dataUnit;
@Schema(description = "描述", example = "你说的对")
private String dataTypeRemark;
@Schema(description = "告警ID", example = "16965")
private Long alertId;
@Schema(description = "告警音频")
private String alertAudio;
@Schema(description = "重复告警")
private Boolean isRepeat;
@Schema(description = "不重复间隔")
private Long noRepeatDuration;
@Schema(description = "来源ID", example = "19268")
private Long dataId;
@Schema(description = "来源编码")
private String dataCode;
@Schema(description = "来源名称", example = "芋艿")
private String dataName;
}

@ -0,0 +1,139 @@
package cn.iocoder.yudao.module.iot.controller.admin.device;
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.constraints.*;
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.*;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute.DeviceAttributeDO;
import cn.iocoder.yudao.module.iot.service.device.DeviceService;
@Tag(name = "管理后台 - 物联设备")
@RestController
@RequestMapping("/iot/device")
@Validated
public class DeviceController {
@Resource
private DeviceService deviceService;
@PostMapping("/create")
@Operation(summary = "创建物联设备")
@PreAuthorize("@ss.hasPermission('iot:device:create')")
public CommonResult<Long> createDevice(@Valid @RequestBody DeviceSaveReqVO createReqVO) {
return success(deviceService.createDevice(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新物联设备")
@PreAuthorize("@ss.hasPermission('iot:device:update')")
public CommonResult<Boolean> 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<Boolean> 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<DeviceRespVO> 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<PageResult<DeviceRespVO>> getDevicePage(@Valid DevicePageReqVO pageReqVO) {
PageResult<DeviceDO> 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<DeviceDO> list = deviceService.getDevicePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物联设备.xls", "数据", DeviceRespVO.class,
BeanUtils.toBean(list, DeviceRespVO.class));
}
// ==================== 子表(设备属性) ====================
@GetMapping("/device-attribute/page")
@Operation(summary = "获得设备属性分页")
@Parameter(name = "deviceId", description = "设备id")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<PageResult<DeviceAttributeDO>> 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<Long> createDeviceAttribute(@Valid @RequestBody DeviceAttributeDO deviceAttribute) {
return success(deviceService.createDeviceAttribute(deviceAttribute));
}
@PutMapping("/device-attribute/update")
@Operation(summary = "更新设备属性")
@PreAuthorize("@ss.hasPermission('iot:device:update')")
public CommonResult<Boolean> 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<Boolean> 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<DeviceAttributeDO> getDeviceAttribute(@RequestParam("id") Long id) {
return success(deviceService.getDeviceAttribute(id));
}
}

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.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 DevicePageReqVO extends PageParam {
@Schema(description = "设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "赵六")
private String deviceName;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "状态", example = "1")
private String status;
@Schema(description = "读主题")
private String readTopic;
@Schema(description = "写主题")
private String writeTopic;
@Schema(description = "网关id", example = "16311")
private Long gatewayId;
@Schema(description = "设备品牌id", example = "24731")
private Long deviceBrandId;
@Schema(description = "离线间隔")
private Long offLineDuration;
@Schema(description = "最后上线时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] lastOnlineTime;
@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;
}

@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 物联设备 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DeviceRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26404")
@ExcelProperty("ID")
private Long id;
@Schema(description = "设备编号")
@ExcelProperty("设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "赵六")
@ExcelProperty("设备名称")
private String deviceName;
@Schema(description = "设备类型", example = "2")
@ExcelProperty(value = "设备类型", converter = DictConvert.class)
@DictFormat("iot_device_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String deviceType;
@Schema(description = "状态", example = "1")
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat("iot_gateway_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String status;
@Schema(description = "读主题")
@ExcelProperty("读主题")
private String readTopic;
@Schema(description = "写主题")
@ExcelProperty("写主题")
private String writeTopic;
@Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "16311")
@ExcelProperty("网关id")
private Long gatewayId;
@Schema(description = "设备品牌id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24731")
@ExcelProperty("设备品牌id")
private Long deviceBrandId;
@Schema(description = "离线间隔", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("离线间隔")
private Long offLineDuration;
@Schema(description = "最后上线时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("最后上线时间")
private LocalDateTime lastOnlineTime;
@Schema(description = "备注", example = "你说的对")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "是否启用", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.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;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute.DeviceAttributeDO;
@Schema(description = "管理后台 - 物联设备新增/修改 Request VO")
@Data
public class DeviceSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26404")
private Long id;
@Schema(description = "设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "赵六")
private String deviceName;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "状态", example = "1")
private String status;
@Schema(description = "读主题")
private String readTopic;
@Schema(description = "写主题")
private String writeTopic;
@Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "16311")
@NotNull(message = "网关id不能为空")
private Long gatewayId;
@Schema(description = "设备品牌id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24731")
@NotNull(message = "设备品牌id不能为空")
private Long deviceBrandId;
@Schema(description = "离线间隔", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "离线间隔不能为空")
private Long offLineDuration;
@Schema(description = "最后上线时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "最后上线时间不能为空")
private LocalDateTime lastOnlineTime;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
}

@ -0,0 +1,83 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.alert;
import lombok.*;
import java.util.*;
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("iot_alert")
@KeySequence("iot_alert_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlertDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String alertCode;
/**
*
*/
private String alertName;
/**
*
*
* {@link TODO iot_alert_type }
*/
private String alertType;
/**
*
*
* {@link TODO iot_alert_level }
*/
private String alertLevel;
/**
*
*/
private String content;
/**
*
*/
private String condition;
/**
*
*/
private String conditionFormula;
/**
*
*/
private String alertAudio;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isRepeat;
/**
*
*/
private Long noRepeatDuration;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isEnable;
}

@ -0,0 +1,111 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord;
import lombok.*;
import java.util.*;
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("iot_alert_record")
@KeySequence("iot_alert_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlertRecordDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String alertCode;
/**
*
*/
private String alertName;
/**
*
*
* {@link TODO iot_alert_type }
*/
private String alertType;
/**
*
*
* {@link TODO iot_alert_level }
*/
private String alertLevel;
/**
*
*/
private String content;
/**
*
*/
private String condition;
/**
*
*/
private String conditionFormula;
/**
*
*/
private String dataValue;
/**
*
*
* {@link TODO iot_device_data_type }
*/
private String dataType;
/**
*
*/
private String dataUnit;
/**
*
*/
private String dataTypeRemark;
/**
* ID
*/
private Long alertId;
/**
*
*/
private String alertAudio;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isRepeat;
/**
*
*/
private Long noRepeatDuration;
/**
* ID
*/
private Long dataId;
/**
*
*/
private String dataCode;
/**
*
*/
private String dataName;
}

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute;
import lombok.*;
import java.util.*;
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("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 attributeName;
/**
* PLC
*/
private String address;
/**
*
*/
private String description;
/**
*
*
* {@link TODO mes_data_type }
*/
private String attributeType;
/**
*
*
* {@link TODO iot_attribute_io_type }
*/
private String ioType;
/**
*
*
* {@link TODO iot_device_data_type }
*/
private String dataType;
/**
*
*/
private String dataTypeRemark;
/**
*
*/
private String dataUnit;
/**
*
*/
private String dataFormula;
/**
* id
*/
private Long gatewayId;
/**
* id
*/
private Long deviceId;
/**
* id
*/
private Long alertId;
/**
*
*/
private String remark;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isEnable;
}

@ -0,0 +1,86 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.device;
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("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;
/**
*
*/
private String deviceCode;
/**
*
*/
private String deviceName;
/**
*
*
* {@link TODO iot_device_type }
*/
private String deviceType;
/**
*
*
* {@link TODO iot_gateway_status }
*/
private String status;
/**
*
*/
private String readTopic;
/**
*
*/
private String writeTopic;
/**
* id
*/
private Long gatewayId;
/**
* id
*/
private Long deviceBrandId;
/**
* 线
*/
private Long offLineDuration;
/**
* 线
*/
private LocalDateTime lastOnlineTime;
/**
*
*/
private String remark;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isEnable;
}

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.iot.dal.mysql.alert;
import java.util.*;
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.iot.dal.dataobject.alert.AlertDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface AlertMapper extends BaseMapperX<AlertDO> {
default PageResult<AlertDO> selectPage(AlertPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AlertDO>()
.eqIfPresent(AlertDO::getAlertCode, reqVO.getAlertCode())
.likeIfPresent(AlertDO::getAlertName, reqVO.getAlertName())
.eqIfPresent(AlertDO::getAlertType, reqVO.getAlertType())
.eqIfPresent(AlertDO::getAlertLevel, reqVO.getAlertLevel())
.eqIfPresent(AlertDO::getContent, reqVO.getContent())
.eqIfPresent(AlertDO::getCondition, reqVO.getCondition())
.eqIfPresent(AlertDO::getConditionFormula, reqVO.getConditionFormula())
.eqIfPresent(AlertDO::getAlertAudio, reqVO.getAlertAudio())
.eqIfPresent(AlertDO::getIsRepeat, reqVO.getIsRepeat())
.eqIfPresent(AlertDO::getNoRepeatDuration, reqVO.getNoRepeatDuration())
.eqIfPresent(AlertDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(AlertDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(AlertDO::getId));
}
}

@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.iot.dal.mysql.alertrecord;
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.alertrecord.vo.AlertRecordPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author
*/
@Mapper
public interface AlertRecordMapper extends BaseMapperX<AlertRecordDO> {
default PageResult<AlertRecordDO> selectPage(AlertRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AlertRecordDO>()
.eqIfPresent(AlertRecordDO::getAlertCode, reqVO.getAlertCode())
.likeIfPresent(AlertRecordDO::getAlertName, reqVO.getAlertName())
.eqIfPresent(AlertRecordDO::getAlertType, reqVO.getAlertType())
.eqIfPresent(AlertRecordDO::getAlertLevel, reqVO.getAlertLevel())
.eqIfPresent(AlertRecordDO::getContent, reqVO.getContent())
.eqIfPresent(AlertRecordDO::getCondition, reqVO.getCondition())
.eqIfPresent(AlertRecordDO::getConditionFormula, reqVO.getConditionFormula())
.eqIfPresent(AlertRecordDO::getDataValue, reqVO.getDataValue())
.eqIfPresent(AlertRecordDO::getDataType, reqVO.getDataType())
.eqIfPresent(AlertRecordDO::getDataUnit, reqVO.getDataUnit())
.eqIfPresent(AlertRecordDO::getDataTypeRemark, reqVO.getDataTypeRemark())
.betweenIfPresent(AlertRecordDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(AlertRecordDO::getAlertId, reqVO.getAlertId())
.eqIfPresent(AlertRecordDO::getAlertAudio, reqVO.getAlertAudio())
.eqIfPresent(AlertRecordDO::getIsRepeat, reqVO.getIsRepeat())
.eqIfPresent(AlertRecordDO::getNoRepeatDuration, reqVO.getNoRepeatDuration())
.eqIfPresent(AlertRecordDO::getDataId, reqVO.getDataId())
.eqIfPresent(AlertRecordDO::getDataCode, reqVO.getDataCode())
.likeIfPresent(AlertRecordDO::getDataName, reqVO.getDataName())
.orderByDesc(AlertRecordDO::getId));
}
default PageResult<AlertRecordDO> selectPage(PageParam reqVO, Long alertId) {
return selectPage(reqVO, new LambdaQueryWrapperX<AlertRecordDO>()
.eq(AlertRecordDO::getAlertId, alertId)
.orderByDesc(AlertRecordDO::getId));
}
default int deleteByAlertId(Long alertId) {
return delete(AlertRecordDO::getAlertId, alertId);
}
}

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.iot.dal.mysql.deviceattribute;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute.DeviceAttributeDO;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author
*/
@Mapper
public interface DeviceAttributeMapper extends BaseMapperX<DeviceAttributeDO> {
default PageResult<DeviceAttributeDO> selectPage(PageParam reqVO, Long deviceId) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceAttributeDO>()
.eq(DeviceAttributeDO::getDeviceId, deviceId)
.orderByDesc(DeviceAttributeDO::getId));
}
default int deleteByDeviceId(Long deviceId) {
return delete(DeviceAttributeDO::getDeviceId, deviceId);
}
}

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.iot.dal.mysql.device;
import java.util.*;
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.iot.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface DeviceMapper extends BaseMapperX<DeviceDO> {
default PageResult<DeviceDO> selectPage(DevicePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
.eqIfPresent(DeviceDO::getDeviceCode, reqVO.getDeviceCode())
.likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
.eqIfPresent(DeviceDO::getDeviceType, reqVO.getDeviceType())
.eqIfPresent(DeviceDO::getStatus, reqVO.getStatus())
.eqIfPresent(DeviceDO::getReadTopic, reqVO.getReadTopic())
.eqIfPresent(DeviceDO::getWriteTopic, reqVO.getWriteTopic())
.eqIfPresent(DeviceDO::getGatewayId, reqVO.getGatewayId())
.eqIfPresent(DeviceDO::getDeviceBrandId, reqVO.getDeviceBrandId())
.eqIfPresent(DeviceDO::getOffLineDuration, reqVO.getOffLineDuration())
.betweenIfPresent(DeviceDO::getLastOnlineTime, reqVO.getLastOnlineTime())
.eqIfPresent(DeviceDO::getRemark, reqVO.getRemark())
.eqIfPresent(DeviceDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(DeviceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DeviceDO::getId));
}
}

@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.iot.service.alert;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.AlertDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface AlertService {
/**
*
*
* @param createReqVO
* @return
*/
Long createAlert(@Valid AlertSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateAlert(@Valid AlertSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteAlert(Long id);
/**
*
*
* @param id
* @return
*/
AlertDO getAlert(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<AlertDO> getAlertPage(AlertPageReqVO pageReqVO);
// ==================== 子表(告警记录) ====================
/**
*
*
* @param pageReqVO
* @param alertId ID
* @return
*/
PageResult<AlertRecordDO> getAlertRecordPage(PageParam pageReqVO, Long alertId);
/**
*
*
* @param alertRecord
* @return
*/
Long createAlertRecord(@Valid AlertRecordDO alertRecord);
/**
*
*
* @param alertRecord
*/
void updateAlertRecord(@Valid AlertRecordDO alertRecord);
/**
*
*
* @param id
*/
void deleteAlertRecord(Long id);
/**
*
*
* @param id
* @return
*/
AlertRecordDO getAlertRecord(Long id);
}

@ -0,0 +1,126 @@
package cn.iocoder.yudao.module.iot.service.alert;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.AlertDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.alert.AlertMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.alertrecord.AlertRecordMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class AlertServiceImpl implements AlertService {
@Resource
private AlertMapper alertMapper;
@Resource
private AlertRecordMapper alertRecordMapper;
@Override
public Long createAlert(AlertSaveReqVO createReqVO) {
// 插入
AlertDO alert = BeanUtils.toBean(createReqVO, AlertDO.class);
alertMapper.insert(alert);
// 返回
return alert.getId();
}
@Override
public void updateAlert(AlertSaveReqVO updateReqVO) {
// 校验存在
validateAlertExists(updateReqVO.getId());
// 更新
AlertDO updateObj = BeanUtils.toBean(updateReqVO, AlertDO.class);
alertMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAlert(Long id) {
// 校验存在
validateAlertExists(id);
// 删除
alertMapper.deleteById(id);
// 删除子表
deleteAlertRecordByAlertId(id);
}
private void validateAlertExists(Long id) {
if (alertMapper.selectById(id) == null) {
throw exception(ALERT_NOT_EXISTS);
}
}
@Override
public AlertDO getAlert(Long id) {
return alertMapper.selectById(id);
}
@Override
public PageResult<AlertDO> getAlertPage(AlertPageReqVO pageReqVO) {
return alertMapper.selectPage(pageReqVO);
}
// ==================== 子表(告警记录) ====================
@Override
public PageResult<AlertRecordDO> getAlertRecordPage(PageParam pageReqVO, Long alertId) {
return alertRecordMapper.selectPage(pageReqVO, alertId);
}
@Override
public Long createAlertRecord(AlertRecordDO alertRecord) {
alertRecordMapper.insert(alertRecord);
return alertRecord.getId();
}
@Override
public void updateAlertRecord(AlertRecordDO alertRecord) {
// 校验存在
validateAlertRecordExists(alertRecord.getId());
// 更新
alertRecordMapper.updateById(alertRecord);
}
@Override
public void deleteAlertRecord(Long id) {
// 校验存在
validateAlertRecordExists(id);
// 删除
alertRecordMapper.deleteById(id);
}
@Override
public AlertRecordDO getAlertRecord(Long id) {
return alertRecordMapper.selectById(id);
}
private void validateAlertRecordExists(Long id) {
if (alertRecordMapper.selectById(id) == null) {
throw exception(ALERT_RECORD_NOT_EXISTS);
}
}
private void deleteAlertRecordByAlertId(Long alertId) {
alertRecordMapper.deleteByAlertId(alertId);
}
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.service.alertrecord;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface AlertRecordService {
/**
*
*
* @param createReqVO
* @return
*/
Long createAlertRecord(@Valid AlertRecordSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateAlertRecord(@Valid AlertRecordSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteAlertRecord(Long id);
/**
*
*
* @param id
* @return
*/
AlertRecordDO getAlertRecord(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<AlertRecordDO> getAlertRecordPage(AlertRecordPageReqVO pageReqVO);
}

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.iot.service.alertrecord;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.alertrecord.AlertRecordMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class AlertRecordServiceImpl implements AlertRecordService {
@Resource
private AlertRecordMapper alertRecordMapper;
@Override
public Long createAlertRecord(AlertRecordSaveReqVO createReqVO) {
// 插入
AlertRecordDO alertRecord = BeanUtils.toBean(createReqVO, AlertRecordDO.class);
alertRecordMapper.insert(alertRecord);
// 返回
return alertRecord.getId();
}
@Override
public void updateAlertRecord(AlertRecordSaveReqVO updateReqVO) {
// 校验存在
validateAlertRecordExists(updateReqVO.getId());
// 更新
AlertRecordDO updateObj = BeanUtils.toBean(updateReqVO, AlertRecordDO.class);
alertRecordMapper.updateById(updateObj);
}
@Override
public void deleteAlertRecord(Long id) {
// 校验存在
validateAlertRecordExists(id);
// 删除
alertRecordMapper.deleteById(id);
}
private void validateAlertRecordExists(Long id) {
if (alertRecordMapper.selectById(id) == null) {
throw exception(ALERT_RECORD_NOT_EXISTS);
}
}
@Override
public AlertRecordDO getAlertRecord(Long id) {
return alertRecordMapper.selectById(id);
}
@Override
public PageResult<AlertRecordDO> getAlertRecordPage(AlertRecordPageReqVO pageReqVO) {
return alertRecordMapper.selectPage(pageReqVO);
}
}

@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.iot.service.device;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute.DeviceAttributeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 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<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
// ==================== 子表(设备属性) ====================
/**
*
*
* @param pageReqVO
* @param deviceId id
* @return
*/
PageResult<DeviceAttributeDO> 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);
}

@ -0,0 +1,126 @@
package cn.iocoder.yudao.module.iot.service.device;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattribute.DeviceAttributeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.deviceattribute.DeviceAttributeMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceMapper deviceMapper;
@Resource
private DeviceAttributeMapper deviceAttributeMapper;
@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<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
return deviceMapper.selectPage(pageReqVO);
}
// ==================== 子表(设备属性) ====================
@Override
public PageResult<DeviceAttributeDO> 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);
}
}

@ -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.iot.dal.mysql.alert.AlertMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -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.iot.dal.mysql.alertrecord.AlertRecordMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -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.iot.dal.mysql.device.DeviceMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,174 @@
package cn.iocoder.yudao.module.iot.service.alert;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.AlertDO;
import cn.iocoder.yudao.module.iot.dal.mysql.alert.AlertMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
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 cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link AlertServiceImpl}
*
* @author
*/
@Import(AlertServiceImpl.class)
public class AlertServiceImplTest extends BaseDbUnitTest {
@Resource
private AlertServiceImpl alertService;
@Resource
private AlertMapper alertMapper;
@Test
public void testCreateAlert_success() {
// 准备参数
AlertSaveReqVO createReqVO = randomPojo(AlertSaveReqVO.class).setId(null);
// 调用
Long alertId = alertService.createAlert(createReqVO);
// 断言
assertNotNull(alertId);
// 校验记录的属性是否正确
AlertDO alert = alertMapper.selectById(alertId);
assertPojoEquals(createReqVO, alert, "id");
}
@Test
public void testUpdateAlert_success() {
// mock 数据
AlertDO dbAlert = randomPojo(AlertDO.class);
alertMapper.insert(dbAlert);// @Sql: 先插入出一条存在的数据
// 准备参数
AlertSaveReqVO updateReqVO = randomPojo(AlertSaveReqVO.class, o -> {
o.setId(dbAlert.getId()); // 设置更新的 ID
});
// 调用
alertService.updateAlert(updateReqVO);
// 校验是否更新正确
AlertDO alert = alertMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, alert);
}
@Test
public void testUpdateAlert_notExists() {
// 准备参数
AlertSaveReqVO updateReqVO = randomPojo(AlertSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> alertService.updateAlert(updateReqVO), ALERT_NOT_EXISTS);
}
@Test
public void testDeleteAlert_success() {
// mock 数据
AlertDO dbAlert = randomPojo(AlertDO.class);
alertMapper.insert(dbAlert);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbAlert.getId();
// 调用
alertService.deleteAlert(id);
// 校验数据不存在了
assertNull(alertMapper.selectById(id));
}
@Test
public void testDeleteAlert_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> alertService.deleteAlert(id), ALERT_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetAlertPage() {
// mock 数据
AlertDO dbAlert = randomPojo(AlertDO.class, o -> { // 等会查询到
o.setAlertCode(null);
o.setAlertName(null);
o.setAlertType(null);
o.setAlertLevel(null);
o.setContent(null);
o.setCondition(null);
o.setConditionFormula(null);
o.setAlertAudio(null);
o.setIsRepeat(null);
o.setNoRepeatDuration(null);
o.setIsEnable(null);
o.setCreateTime(null);
});
alertMapper.insert(dbAlert);
// 测试 alertCode 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setAlertCode(null)));
// 测试 alertName 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setAlertName(null)));
// 测试 alertType 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setAlertType(null)));
// 测试 alertLevel 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setAlertLevel(null)));
// 测试 content 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setContent(null)));
// 测试 condition 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setCondition(null)));
// 测试 conditionFormula 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setConditionFormula(null)));
// 测试 alertAudio 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setAlertAudio(null)));
// 测试 isRepeat 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setIsRepeat(null)));
// 测试 noRepeatDuration 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setNoRepeatDuration(null)));
// 测试 isEnable 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setIsEnable(null)));
// 测试 createTime 不匹配
alertMapper.insert(cloneIgnoreId(dbAlert, o -> o.setCreateTime(null)));
// 准备参数
AlertPageReqVO reqVO = new AlertPageReqVO();
reqVO.setAlertCode(null);
reqVO.setAlertName(null);
reqVO.setAlertType(null);
reqVO.setAlertLevel(null);
reqVO.setContent(null);
reqVO.setCondition(null);
reqVO.setConditionFormula(null);
reqVO.setAlertAudio(null);
reqVO.setIsRepeat(null);
reqVO.setNoRepeatDuration(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<AlertDO> pageResult = alertService.getAlertPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbAlert, pageResult.getList().get(0));
}
}

@ -0,0 +1,202 @@
package cn.iocoder.yudao.module.iot.service.alertrecord;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.alertrecord.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.alertrecord.AlertRecordDO;
import cn.iocoder.yudao.module.iot.dal.mysql.alertrecord.AlertRecordMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
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 cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link AlertRecordServiceImpl}
*
* @author
*/
@Import(AlertRecordServiceImpl.class)
public class AlertRecordServiceImplTest extends BaseDbUnitTest {
@Resource
private AlertRecordServiceImpl alertRecordService;
@Resource
private AlertRecordMapper alertRecordMapper;
@Test
public void testCreateAlertRecord_success() {
// 准备参数
AlertRecordSaveReqVO createReqVO = randomPojo(AlertRecordSaveReqVO.class).setId(null);
// 调用
Long alertRecordId = alertRecordService.createAlertRecord(createReqVO);
// 断言
assertNotNull(alertRecordId);
// 校验记录的属性是否正确
AlertRecordDO alertRecord = alertRecordMapper.selectById(alertRecordId);
assertPojoEquals(createReqVO, alertRecord, "id");
}
@Test
public void testUpdateAlertRecord_success() {
// mock 数据
AlertRecordDO dbAlertRecord = randomPojo(AlertRecordDO.class);
alertRecordMapper.insert(dbAlertRecord);// @Sql: 先插入出一条存在的数据
// 准备参数
AlertRecordSaveReqVO updateReqVO = randomPojo(AlertRecordSaveReqVO.class, o -> {
o.setId(dbAlertRecord.getId()); // 设置更新的 ID
});
// 调用
alertRecordService.updateAlertRecord(updateReqVO);
// 校验是否更新正确
AlertRecordDO alertRecord = alertRecordMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, alertRecord);
}
@Test
public void testUpdateAlertRecord_notExists() {
// 准备参数
AlertRecordSaveReqVO updateReqVO = randomPojo(AlertRecordSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> alertRecordService.updateAlertRecord(updateReqVO), ALERT_RECORD_NOT_EXISTS);
}
@Test
public void testDeleteAlertRecord_success() {
// mock 数据
AlertRecordDO dbAlertRecord = randomPojo(AlertRecordDO.class);
alertRecordMapper.insert(dbAlertRecord);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbAlertRecord.getId();
// 调用
alertRecordService.deleteAlertRecord(id);
// 校验数据不存在了
assertNull(alertRecordMapper.selectById(id));
}
@Test
public void testDeleteAlertRecord_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> alertRecordService.deleteAlertRecord(id), ALERT_RECORD_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetAlertRecordPage() {
// mock 数据
AlertRecordDO dbAlertRecord = randomPojo(AlertRecordDO.class, o -> { // 等会查询到
o.setAlertCode(null);
o.setAlertName(null);
o.setAlertType(null);
o.setAlertLevel(null);
o.setContent(null);
o.setCondition(null);
o.setConditionFormula(null);
o.setDataValue(null);
o.setDataType(null);
o.setDataUnit(null);
o.setDataTypeRemark(null);
o.setCreateTime(null);
o.setAlertId(null);
o.setAlertAudio(null);
o.setIsRepeat(null);
o.setNoRepeatDuration(null);
o.setDataId(null);
o.setDataCode(null);
o.setDataName(null);
});
alertRecordMapper.insert(dbAlertRecord);
// 测试 alertCode 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertCode(null)));
// 测试 alertName 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertName(null)));
// 测试 alertType 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertType(null)));
// 测试 alertLevel 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertLevel(null)));
// 测试 content 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setContent(null)));
// 测试 condition 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setCondition(null)));
// 测试 conditionFormula 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setConditionFormula(null)));
// 测试 dataValue 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataValue(null)));
// 测试 dataType 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataType(null)));
// 测试 dataUnit 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataUnit(null)));
// 测试 dataTypeRemark 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataTypeRemark(null)));
// 测试 createTime 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setCreateTime(null)));
// 测试 alertId 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertId(null)));
// 测试 alertAudio 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setAlertAudio(null)));
// 测试 isRepeat 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setIsRepeat(null)));
// 测试 noRepeatDuration 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setNoRepeatDuration(null)));
// 测试 dataId 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataId(null)));
// 测试 dataCode 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataCode(null)));
// 测试 dataName 不匹配
alertRecordMapper.insert(cloneIgnoreId(dbAlertRecord, o -> o.setDataName(null)));
// 准备参数
AlertRecordPageReqVO reqVO = new AlertRecordPageReqVO();
reqVO.setAlertCode(null);
reqVO.setAlertName(null);
reqVO.setAlertType(null);
reqVO.setAlertLevel(null);
reqVO.setContent(null);
reqVO.setCondition(null);
reqVO.setConditionFormula(null);
reqVO.setDataValue(null);
reqVO.setDataType(null);
reqVO.setDataUnit(null);
reqVO.setDataTypeRemark(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setAlertId(null);
reqVO.setAlertAudio(null);
reqVO.setIsRepeat(null);
reqVO.setNoRepeatDuration(null);
reqVO.setDataId(null);
reqVO.setDataCode(null);
reqVO.setDataName(null);
// 调用
PageResult<AlertRecordDO> pageResult = alertRecordService.getAlertRecordPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbAlertRecord, pageResult.getList().get(0));
}
}

@ -0,0 +1,178 @@
package cn.iocoder.yudao.module.iot.service.device;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
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 cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@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.setDeviceCode(null);
o.setDeviceName(null);
o.setDeviceType(null);
o.setStatus(null);
o.setReadTopic(null);
o.setWriteTopic(null);
o.setGatewayId(null);
o.setDeviceBrandId(null);
o.setOffLineDuration(null);
o.setLastOnlineTime(null);
o.setRemark(null);
o.setIsEnable(null);
o.setCreateTime(null);
});
deviceMapper.insert(dbDevice);
// 测试 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)));
// 测试 status 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setStatus(null)));
// 测试 readTopic 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadTopic(null)));
// 测试 writeTopic 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteTopic(null)));
// 测试 gatewayId 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setGatewayId(null)));
// 测试 deviceBrandId 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceBrandId(null)));
// 测试 offLineDuration 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setOffLineDuration(null)));
// 测试 lastOnlineTime 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setLastOnlineTime(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.setDeviceCode(null);
reqVO.setDeviceName(null);
reqVO.setDeviceType(null);
reqVO.setStatus(null);
reqVO.setReadTopic(null);
reqVO.setWriteTopic(null);
reqVO.setGatewayId(null);
reqVO.setDeviceBrandId(null);
reqVO.setOffLineDuration(null);
reqVO.setLastOnlineTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setRemark(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<DeviceDO> pageResult = deviceService.getDevicePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbDevice, pageResult.getList().get(0));
}
}

@ -1,28 +1,15 @@
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_device";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里 -- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_formula"; DELETE FROM "iot_formula";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_device_attribute";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_formula_detail"; DELETE FROM "iot_formula_detail";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_gateway"; DELETE FROM "iot_gateway";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_iot_organization"; DELETE FROM "iot_iot_organization";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_kanban"; DELETE FROM "iot_kanban";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_formula_record"; DELETE FROM "iot_formula_record";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_mqtt_record"; DELETE FROM "iot_mqtt_record";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里 -- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
@ -35,5 +22,10 @@ DELETE FROM "iot_frpc_proxy_server";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里 -- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_feedback"; DELETE FROM "iot_feedback";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里 DELETE FROM "iot_mqtt_data_record";
DELETE FROM "iot_mqtt_data_record";
DELETE FROM "iot_device";
DELETE FROM "iot_alert_record";
DELETE FROM "iot_alert";
DELETE FROM "iot_device_attribute";

@ -1,49 +1,3 @@
CREATE TABLE IF NOT EXISTS "iot_device"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"device_config_id" varchar,
"device_code" varchar,
"device_name" varchar,
"device_type" varchar,
"siemens_series" varchar,
"siemens_connect_param" varchar,
"read_cron_type" varchar,
"read_repeat_value" int,
"read_repeat_unit" varchar,
"read_cron" varchar,
"write_cron_type" varchar,
"write_repeat_value" int,
"write_repeat_unit" varchar,
"write_cron" varchar,
"local_persistent" varchar,
"upload_rate" varchar,
"rate_count" int,
"modbus_protocol" varchar,
"modbus_pattern" varchar,
"port_name" varchar,
"modbus_connect_param" varchar,
"modbus_read_addr_gap" varchar,
"is_upload" varchar,
"gateway_id" bigint NOT NULL,
"org_id" bigint NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
"device_use_type" varchar,
"ap_ip" varchar,
"gate_bridge_ip" varchar,
"com_server_ip" varchar,
"com_server_port" varchar,
"plc_controller_ip" varchar,
"plc_screen_ip" varchar,
"org_machine_id" bigint,
PRIMARY KEY ("id")
) COMMENT '物联设备表';
CREATE TABLE IF NOT EXISTS "iot_formula" CREATE TABLE IF NOT EXISTS "iot_formula"
( (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
@ -63,52 +17,7 @@ CREATE TABLE IF NOT EXISTS "iot_formula"
"tenant_id" bigint, "tenant_id" bigint,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '计算公式'; ) COMMENT '计算公式';
CREATE TABLE IF NOT EXISTS "iot_device_attribute"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"attribute_code" varchar NOT NULL,
"address" varchar,
"attribute_name" varchar NOT NULL,
"description" varchar,
"address_type" varchar,
"address_offset" varchar,
"address2_type" varchar,
"address2_offset" varchar,
"group_name" varchar,
"group_id" int,
"security_type" varchar,
"io_status" varchar,
"is_linear_transfer" varchar,
"data_type" varchar,
"unit" varchar,
"in_min_value" varchar,
"in_max_value" varchar,
"out_min_value" varchar,
"out_max_value" varchar,
"out_data_type" varchar,
"siemens_field_precision" int,
"modbus_slave_id" varchar,
"modbus_field_address" varchar,
"modbus_address_type" varchar,
"modbus_field_size" varchar,
"modbus_field_precision" varchar,
"modbus_field_order" varchar,
"source_data_type" varchar,
"transfer_data_type" varchar,
"factor" varchar,
"gateway_id" bigint NOT NULL,
"device_id" bigint NOT NULL,
"org_id" bigint NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '设备属性表';
CREATE TABLE IF NOT EXISTS "iot_formula_detail" CREATE TABLE IF NOT EXISTS "iot_formula_detail"
( (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
@ -302,3 +211,104 @@ CREATE TABLE IF NOT EXISTS "iot_mqtt_data_record"
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '设备数据记录'; ) COMMENT '设备数据记录';
CREATE TABLE IF NOT EXISTS "iot_alert"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"alert_code" varchar NOT NULL,
"alert_name" varchar NOT NULL,
"alert_type" varchar,
"alert_level" varchar,
"content" varchar,
"condition" varchar,
"condition_formula" varchar,
"alert_audio" varchar NOT NULL,
"is_repeat" bit NOT NULL,
"no_repeat_duration" bigint NOT NULL,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '告警配置';
CREATE TABLE IF NOT EXISTS "iot_alert_record"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"alert_code" varchar NOT NULL,
"alert_name" varchar NOT NULL,
"alert_type" varchar,
"alert_level" varchar,
"content" varchar,
"condition" varchar,
"condition_formula" varchar,
"data_value" varchar,
"data_type" varchar,
"data_unit" varchar,
"data_type_remark" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
"alert_id" bigint,
"alert_audio" varchar,
"is_repeat" bit,
"no_repeat_duration" bigint,
"data_id" bigint,
"data_code" varchar,
"data_name" varchar,
PRIMARY KEY ("id")
) COMMENT '告警记录';
CREATE TABLE IF NOT EXISTS "iot_device"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"device_code" varchar,
"device_name" varchar,
"device_type" varchar,
"status" varchar,
"read_topic" varchar,
"write_topic" varchar,
"gateway_id" bigint NOT NULL,
"device_brand_id" bigint NOT NULL,
"off_line_duration" bigint NOT NULL,
"last_online_time" varchar NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '物联设备表';
CREATE TABLE IF NOT EXISTS "iot_device_attribute"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"attribute_code" varchar NOT NULL,
"attribute_name" varchar NOT NULL,
"address" varchar,
"description" varchar,
"attribute_type" varchar,
"io_type" varchar,
"data_type" varchar,
"data_type_remark" varchar,
"data_unit" varchar,
"data_formula" varchar,
"gateway_id" bigint,
"device_id" bigint,
"alert_id" bigint,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '设备属性表';

Loading…
Cancel
Save