feat: [Issue#72] 实现阈值管理、信息发布、设备管理功能

- 阈值管理:支持报警阈值配置(最小值、最大值、警告值)
- 信息发布:支持预报/预警信息发布和管理
- 设备管理:支持按名称、类型、时间、位置查询设备
- 新增3个实体类:Threshold、Notification、Equipment
- 新增6个Service及其实现类
- 新增3个Controller及对应的VO类
- 新增数据库表结构和示例数据
This commit is contained in:
2026-06-14 15:05:08 +08:00
parent cfce03cf92
commit 1d550c1bfb
20 changed files with 794 additions and 3 deletions
+2 -3
View File
@@ -13,9 +13,8 @@
<dependency><groupId>cn.dev33</groupId><artifactId>sa-token-spring-boot3-starter</artifactId></dependency>
<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId></dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
+83
View File
@@ -0,0 +1,83 @@
-- 阈值表
CREATE TABLE IF NOT EXISTS threshold (
id BIGSERIAL PRIMARY KEY,
device_id VARCHAR(100) NOT NULL,
device_type VARCHAR(50),
region VARCHAR(50),
parameter VARCHAR(100) NOT NULL,
min_value DOUBLE PRECISION,
max_value DOUBLE PRECISION,
warning_min DOUBLE PRECISION,
warning_max DOUBLE PRECISION,
unit VARCHAR(20),
description TEXT,
status INTEGER DEFAULT 1 COMMENT '1-启用,0-禁用',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 信息发布表
CREATE TABLE IF NOT EXISTS notification (
id BIGSERIAL PRIMARY KEY,
title VARCHAR(200) NOT NULL,
content TEXT NOT NULL,
type VARCHAR(20) NOT NULL COMMENT 'forecast-预报,warning-预警,info-通知',
region VARCHAR(50),
priority VARCHAR(20) DEFAULT 'medium' COMMENT 'high-高,medium-中,low-低',
status INTEGER DEFAULT 1 COMMENT '1-草稿,2-已发布,3-已归档',
publisher VARCHAR(100),
publish_time TIMESTAMP,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 设备表
CREATE TABLE IF NOT EXISTS equipment (
id BIGSERIAL PRIMARY KEY,
device_name VARCHAR(100) NOT NULL,
device_type VARCHAR(50),
model VARCHAR(100),
serial_number VARCHAR(100),
region VARCHAR(50),
location TEXT,
status VARCHAR(20) DEFAULT 'offline' COMMENT 'online-在线,offline-离线,maintenance-维护中,fault-故障',
manufacturer VARCHAR(100),
installation_date DATE,
last_maintenance_date DATE,
next_maintenance_date DATE,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 创建索引
CREATE INDEX IF NOT EXISTS idx_threshold_device_id ON threshold(device_id);
CREATE INDEX IF NOT EXISTS idx_threshold_region ON threshold(region);
CREATE INDEX IF NOT EXISTS idx_threshold_parameter ON threshold(parameter);
CREATE INDEX IF NOT EXISTS idx_notification_region ON notification(region);
CREATE INDEX IF NOT EXISTS idx_notification_type ON notification(type);
CREATE INDEX IF NOT EXISTS idx_notification_status ON notification(status);
CREATE INDEX IF NOT EXISTS idx_equipment_device_name ON equipment(device_name);
CREATE INDEX IF NOT EXISTS idx_equipment_device_type ON equipment(device_type);
CREATE INDEX IF NOT EXISTS idx_equipment_region ON equipment(region);
CREATE INDEX IF NOT EXISTS idx_equipment_status ON equipment(status);
-- 插入示例数据
-- 阈值示例
INSERT INTO threshold (device_id, device_type, region, parameter, min_value, max_value, warning_min, warning_max, unit, description, status) VALUES
('DEV001', 'pressure_sensor', '精河县', 'water_pressure', 0.2, 0.8, 0.15, 0.85, 'MPa', '供水压力阈值', 1),
('DEV002', 'flow_meter', '精河县', 'water_flow', 10, 100, 8, 110, 'm³/h', '水流流量阈值', 1),
('DEV003', 'quality_sensor', '精河县', 'water_quality', 0, 1, 0.1, 0.9, 'pH', '水质pH值阈值', 1);
-- 设备示例
INSERT INTO equipment (device_name, device_type, model, serial_number, region, location, status, manufacturer, installation_date) VALUES
('压力传感器001', 'pressure_sensor', 'PS-3000', 'SN0012023001', '精河县', '供水站A区', 'online', '华为', '2023-01-15'),
('流量计001', 'flow_meter', 'FM-5000', 'SN0012023002', '精河县', '供水站B区', 'online', '西门子', '2023-02-20'),
('水质检测仪001', 'quality_sensor', 'QS-2000', 'SN0012023003', '精河县', '供水站C区', 'online', '霍尼韦尔', '2023-03-10');
-- 信息发布示例
INSERT INTO notification (title, content, type, region, priority, status, publisher, publish_time) VALUES
('停水通知', '因设备维护,预计明天9:00-12:00精河县部分区域将暂停供水', 'warning', '精河县', 'high', 2, 'system_admin', '2026-06-14T08:00:00'),
('水质提升通知', '本季度已完成水质净化设备升级,水质显著提升', 'info', '精河县', 'medium', 2, 'water_quality_team', '2026-06-01T10:00:00'),
('雨季供水保障通知', '近期降雨较多,各水厂已加强巡检,确保供水稳定', 'forecast', '精河县', 'low', 2, 'emergency_team', '2026-05-20T14:00:00');
@@ -0,0 +1,83 @@
package com.water.production.controller;
import com.water.production.entity.Equipment;
import com.water.production.service.EquipmentService;
import com.water.production.vo.EquipmentQueryVO;
import com.water.production.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/equipment")
@Tag(name = "设备管理", description = "设备列表查询接口")
public class EquipmentController {
@Autowired
private EquipmentService equipmentService;
@PostMapping("/save")
@Operation(summary = "保存设备信息")
public Result<Boolean> saveEquipment(@RequestBody Equipment equipment) {
boolean success = equipmentService.saveEquipment(equipment);
return success ? Result.success(true) : Result.error("保存失败");
}
@PutMapping("/update")
@Operation(summary = "更新设备信息")
public Result<Boolean> updateEquipment(@RequestBody Equipment equipment) {
boolean success = equipmentService.updateEquipment(equipment);
return success ? Result.success(true) : Result.error("更新失败");
}
@DeleteMapping("/delete/{id}")
@Operation(summary = "删除设备信息")
public Result<Boolean> deleteEquipment(@PathVariable Long id) {
boolean success = equipmentService.deleteEquipment(id);
return success ? Result.success(true) : Result.error("删除失败");
}
@GetMapping("/list")
@Operation(summary = "获取所有设备列表")
public Result<List<Equipment>> list() {
List<Equipment> equipmentList = equipmentService.list();
return Result.success(equipmentList);
}
@PostMapping("/query")
@Operation(summary = "查询设备列表")
public Result<List<Equipment>> query(@RequestBody EquipmentQueryVO queryVO) {
List<Equipment> equipmentList = equipmentService.queryEquipment(queryVO);
return Result.success(equipmentList);
}
@GetMapping("/name/{deviceName}")
@Operation(summary = "根据设备名称查询(模糊匹配)")
public Result<List<Equipment>> getByName(@PathVariable String deviceName) {
List<Equipment> equipmentList = equipmentService.getEquipmentByName(deviceName);
return Result.success(equipmentList);
}
@GetMapping("/type/{deviceType}")
@Operation(summary = "根据设备类型查询")
public Result<List<Equipment>> getByType(@PathVariable String deviceType) {
List<Equipment> equipmentList = equipmentService.getEquipmentByType(deviceType);
return Result.success(equipmentList);
}
@GetMapping("/region/{region}")
@Operation(summary = "根据区域查询")
public Result<List<Equipment>> getByRegion(@PathVariable String region) {
List<Equipment> equipmentList = equipmentService.getEquipmentByRegion(region);
return Result.success(equipmentList);
}
@GetMapping("/status/{status}")
@Operation(summary = "根据状态查询")
public Result<List<Equipment>> getByStatus(@PathVariable String status) {
List<Equipment> equipmentList = equipmentService.getEquipmentByStatus(status);
return Result.success(equipmentList);
}
}
@@ -0,0 +1,91 @@
package com.water.production.controller;
import com.water.production.entity.Notification;
import com.water.production.service.NotificationService;
import com.water.production.vo.NotificationQueryVO;
import com.water.production.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/notification")
@Tag(name = "信息发布", description = "预报/预警信息发布接口")
public class NotificationController {
@Autowired
private NotificationService notificationService;
@PostMapping("/save")
@Operation(summary = "保存草稿")
public Result<Boolean> saveNotification(@RequestBody Notification notification) {
notification.setStatus(1); // draft
boolean success = notificationService.save(notification);
return success ? Result.success(true) : Result.error("保存失败");
}
@PutMapping("/update")
@Operation(summary = "更新信息")
public Result<Boolean> updateNotification(@RequestBody Notification notification) {
boolean success = notificationService.updateById(notification);
return success ? Result.success(true) : Result.error("更新失败");
}
@PutMapping("/publish/{id}")
@Operation(summary = "发布信息")
public Result<Boolean> publishNotification(@PathVariable Long id, @RequestParam String publisher) {
boolean success = notificationService.publishNotification(id, publisher);
return success ? Result.success(true) : Result.error("发布失败");
}
@PutMapping("/archive/{id}")
@Operation(summary = "归档信息")
public Result<Boolean> archiveNotification(@PathVariable Long id) {
boolean success = notificationService.archiveNotification(id);
return success ? Result.success(true) : Result.error("归档失败");
}
@DeleteMapping("/delete/{id}")
@Operation(summary = = "删除信息")
public Result<Boolean> deleteNotification(@PathVariable Long id) {
boolean success = notificationService.removeById(id);
return success ? Result.success(true) : Result.error("删除失败");
}
@GetMapping("/list")
@Operation(summary = "获取所有信息列表")
public Result<List<Notification>> list() {
List<Notification> notifications = notificationService.list();
return Result.success(notifications);
}
@PostMapping("/query")
@Operation(summary = "查询信息列表")
public Result<List<Notification>> query(@RequestBody NotificationQueryVO queryVO) {
List<Notification> notifications = notificationService.queryNotifications(queryVO);
return Result.success(notifications);
}
@GetMapping("/region/{region}")
@Operation(summary = "根据区域获取信息")
public Result<List<Notification>> getByRegion(@PathVariable String region) {
List<Notification> notifications = notificationService.getNotificationsByRegion(region);
return Result.success(notifications);
}
@GetMapping("/type/{type}")
@Operation(summary = = "根据类型获取信息")
public Result<List<Notification>> getByType(@PathVariable String type) {
List<Notification> notifications = notificationService.getNotificationsByType(type);
return Result.success(notifications);
}
@GetMapping("/active")
@Operation(summary = "获取已发布信息")
public Result<List<Notification>> getActiveNotifications() {
List<Notification> notifications = notificationService.getActiveNotifications();
return Result.success(notifications);
}
}
@@ -0,0 +1,77 @@
package com.water.production.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.water.production.entity.Threshold;
import com.water.production.service.ThresholdService;
import com.water.production.vo.ThresholdQueryVO;
import com.water.production.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/threshold")
@Tag(name = "阈值管理", description = "报警阈值编辑接口")
public class ThresholdController {
@Autowired
private ThresholdService thresholdService;
@PostMapping("/save")
@Operation(summary = "保存阈值配置")
public Result<Boolean> saveThreshold(@RequestBody Threshold threshold) {
boolean success = thresholdService.saveThreshold(threshold);
return success ? Result.success(true) : Result.error("保存失败");
}
@PutMapping("/update")
@Operation(summary = "更新阈值配置")
public Result<Boolean> updateThreshold(@RequestBody Threshold threshold) {
boolean success = thresholdService.updateThreshold(threshold);
return success ? Result.success(true) : Result.error("更新失败");
}
@DeleteMapping("/delete/{id}")
@Operation(summary = "删除阈值配置")
public Result<Boolean> deleteThreshold(@PathVariable Long id) {
boolean success = thresholdService.deleteThreshold(id);
return success ? Result.success(true) : Result.error("删除失败");
}
@GetMapping("/list")
@Operation(summary = "获取阈值配置列表")
public Result<List<Threshold>> list() {
List<Threshold> thresholds = thresholdService.list();
return Result.success(thresholds);
}
@PostMapping("/query")
@Operation(summary = "查询阈值配置")
public Result<List<Threshold>> query(@RequestBody ThresholdQueryVO queryVO) {
List<Threshold> thresholds = thresholdService.queryThresholds(queryVO);
return Result.success(thresholds);
}
@GetMapping("/device/{deviceId}")
@Operation(summary = "根据设备ID获取阈值")
public Result<List<Threshold>> getByDeviceId(@PathVariable String deviceId) {
List<Threshold> thresholds = thresholdService.getThresholdsByDevice(deviceId);
return Result.success(thresholds);
}
@GetMapping("/region/{region}")
@Operation(summary = "根据区域获取阈值")
public Result<List<Threshold>> getByRegion(@PathVariable String region) {
List<Threshold> thresholds = thresholdService.getThresholdsByRegion(region);
return Result.success(thresholds);
}
@GetMapping("/parameter/{parameter}")
@Operation(summary = "根据参数获取阈值")
public Result<List<Threshold>> getByParameter(@PathVariable String parameter) {
List<Threshold> thresholds = thresholdService.getThresholdsByParameter(parameter);
return Result.success(thresholds);
}
}
@@ -0,0 +1,29 @@
package com.water.production.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("equipment")
public class Equipment {
@TableId(type = IdType.AUTO)
private Long id;
private String deviceName;
private String deviceType;
private String model;
private String serialNumber;
private String region;
private String location;
private String status; // online, offline, maintenance, fault
private String manufacturer;
private String installationDate;
private String lastMaintenanceDate;
private String nextMaintenanceDate;
private Double latitude;
private Double longitude;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
@@ -0,0 +1,24 @@
package com.water.production.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("notification")
public class Notification {
@TableId(type = IdType.AUTO)
private Long id;
private String title;
private String content;
private String type; // forecast, warning, info
private String region;
private String priority; // high, medium, low
private Integer status; // draft, published, archived
private String publisher;
private LocalDateTime publishTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
@@ -0,0 +1,27 @@
package com.water.production.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("threshold")
public class Threshold {
@TableId(type = IdType.AUTO)
private Long id;
private String deviceId;
private String deviceType;
private String region;
private String parameter;
private Double minValue;
private Double maxValue;
private Double warningMin;
private Double warningMax;
private String unit;
private String description;
private Integer status;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
@@ -0,0 +1,9 @@
package com.water.production.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.water.production.entity.Equipment;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EquipmentMapper extends BaseMapper<Equipment> {
}
@@ -0,0 +1,9 @@
package com.water.production.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.water.production.entity.Notification;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface NotificationMapper extends BaseMapper<Notification> {
}
@@ -0,0 +1,9 @@
package com.water.production.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.water.production.entity.Threshold;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ThresholdMapper extends BaseMapper<Threshold> {
}
@@ -0,0 +1,17 @@
package com.water.production.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.water.production.entity.Equipment;
import com.water.production.vo.EquipmentQueryVO;
import java.util.List;
public interface EquipmentService extends IService<Equipment> {
List<Equipment> getEquipmentByName(String deviceName);
List<Equipment> getEquipmentByType(String deviceType);
List<Equipment> getEquipmentByRegion(String region);
List<Equipment> getEquipmentByStatus(String status);
boolean saveEquipment(Equipment equipment);
boolean updateEquipment(Equipment equipment);
boolean deleteEquipment(Long id);
List<Equipment> queryEquipment(EquipmentQueryVO queryVO);
}
@@ -0,0 +1,15 @@
package com.water.production.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.water.production.entity.Notification;
import com.water.production.vo.NotificationQueryVO;
import java.util.List;
public interface NotificationService extends IService<Notification> {
List<Notification> getNotificationsByRegion(String region);
List<Notification> getNotificationsByType(String type);
List<Notification> getActiveNotifications();
boolean publishNotification(Long id, String publisher);
boolean archiveNotification(Long id);
List<Notification> queryNotifications(NotificationQueryVO queryVO);
}
@@ -0,0 +1,16 @@
package com.water.production.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.water.production.entity.Threshold;
import com.water.production.vo.ThresholdQueryVO;
import java.util.List;
public interface ThresholdService extends IService<Threshold> {
List<Threshold> getThresholdsByDevice(String deviceId);
List<Threshold> getThresholdsByRegion(String region);
List<Threshold> getThresholdsByParameter(String parameter);
boolean saveThreshold(Threshold threshold);
boolean updateThreshold(Threshold threshold);
boolean deleteThreshold(Long id);
List<Threshold> queryThresholds(ThresholdQueryVO queryVO);
}
@@ -0,0 +1,84 @@
package com.water.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.water.production.entity.Equipment;
import com.water.production.mapper.EquipmentMapper;
import com.water.production.service.EquipmentService;
import com.water.production.vo.EquipmentQueryVO;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements EquipmentService {
@Override
public List<Equipment> getEquipmentByName(String deviceName) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(Equipment::getDeviceName, deviceName);
return list(queryWrapper);
}
@Override
public List<Equipment> getEquipmentByType(String deviceType) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Equipment::getDeviceType, deviceType);
return list(queryWrapper);
}
@Override
public List<Equipment> getEquipmentByRegion(String region) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Equipment::getRegion, region);
return list(queryWrapper);
}
@Override
public List<Equipment> getEquipmentByStatus(String status) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Equipment::getStatus, status);
return list(queryWrapper);
}
@Override
public boolean saveEquipment(Equipment equipment) {
equipment.setCreateTime(java.time.LocalDateTime.now());
equipment.setUpdateTime(java.time.LocalDateTime.now());
return save(equipment);
}
@Override
public boolean updateEquipment(Equipment equipment) {
equipment.setUpdateTime(java.time.LocalDateTime.now());
return updateById(equipment);
}
@Override
public boolean deleteEquipment(Long id) {
return removeById(id);
}
@Override
public List<Equipment> queryEquipment(EquipmentQueryVO queryVO) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<>();
if (queryVO.getDeviceName() != null && !queryVO.getDeviceName().isEmpty()) {
queryWrapper.like(Equipment::getDeviceName, queryVO.getDeviceName());
}
if (queryVO.getDeviceType() != null && !queryVO.getDeviceType().isEmpty()) {
queryWrapper.eq(Equipment::getDeviceType, queryVO.getDeviceType());
}
if (queryVO.getRegion() != null && !queryVO.getRegion().isEmpty()) {
queryWrapper.eq(Equipment::getRegion, queryVO.getRegion());
}
if (queryVO.getStatus() != null && !queryVO.getStatus().isEmpty()) {
queryWrapper.eq(Equipment::getStatus, queryVO.getStatus());
}
if (queryVO.getManufacturer() != null && !queryVO.getManufacturer().isEmpty()) {
queryWrapper.eq(Equipment::getManufacturer, queryVO.getManufacturer());
}
queryWrapper.orderByDesc(Equipment::getCreateTime);
return list(queryWrapper);
}
}
@@ -0,0 +1,83 @@
package com.water.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.water.production.entity.Notification;
import com.water.production.mapper.NotificationMapper;
import com.water.production.service.NotificationService;
import com.water.production.vo.NotificationQueryVO;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NotificationServiceImpl extends ServiceImpl<NotificationMapper, Notification> implements NotificationService {
@Override
public List<Notification> getNotificationsByRegion(String region) {
LambdaQueryWrapper<Notification> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Notification::getRegion, region)
.orderByDesc(Notification::getPublishTime);
return list(queryWrapper);
}
@Override
public List<Notification> getNotificationsByType(String type) {
LambdaQueryWrapper<Notification> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Notification::getType, type)
.orderByDesc(Notification::getPublishTime);
return list(queryWrapper);
}
@Override
public List<Notification> getActiveNotifications() {
LambdaQueryWrapper<Notification> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Notification::getStatus, 2) // published
.orderByDesc(Notification::getPublishTime);
return list(queryWrapper);
}
@Override
public boolean publishNotification(Long id, String publisher) {
Notification notification = getById(id);
if (notification != null) {
notification.setStatus(2); // published
notification.setPublisher(publisher);
notification.setPublishTime(java.time.LocalDateTime.now());
notification.setUpdateTime(java.time.LocalDateTime.now());
return updateById(notification);
}
return false;
}
@Override
public boolean archiveNotification(Long id) {
Notification notification = getById(id);
if (notification != null) {
notification.setStatus(3); // archived
notification.setUpdateTime(java.time.LocalDateTime.now());
return updateById(notification);
}
return false;
}
@Override
public List<Notification> queryNotifications(NotificationQueryVO queryVO) {
LambdaQueryWrapper<Notification> queryWrapper = new LambdaQueryWrapper<>();
if (queryVO.getRegion() != null && !queryVO.getRegion().isEmpty()) {
queryWrapper.eq(Notification::getRegion, queryVO.getRegion());
}
if (queryVO.getType() != null && !queryVO.getType().isEmpty()) {
queryWrapper.eq(Notification::getType, queryVO.getType());
}
if (queryVO.getStatus() != null) {
queryWrapper.eq(Notification::getStatus, queryVO.getStatus());
}
if (queryVO.getPriority() != null && !queryVO.getPriority().isEmpty()) {
queryWrapper.eq(Notification::getPriority, queryVO.getPriority());
}
queryWrapper.orderByDesc(Notification::getCreateTime);
return list(queryWrapper);
}
}
@@ -0,0 +1,73 @@
package com.water.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.water.production.entity.Threshold;
import com.water.production.mapper.ThresholdMapper;
import com.water.production.service.ThresholdService;
import com.water.production.vo.ThresholdQueryVO;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ThresholdServiceImpl extends ServiceImpl<ThresholdMapper, Threshold> implements ThresholdService {
@Override
public List<Threshold> getThresholdsByDevice(String deviceId) {
LambdaQueryWrapper<Threshold> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Threshold::getDeviceId, deviceId);
return list(queryWrapper);
}
@Override
public List<Threshold> getThresholdsByRegion(String region) {
LambdaQueryWrapper<Threshold> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Threshold::getRegion, region);
return list(queryWrapper);
}
@Override
public List<Threshold> getThresholdsByParameter(String parameter) {
LambdaQueryWrapper<Threshold> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Threshold::getParameter, parameter);
return list(queryWrapper);
}
@Override
public boolean saveThreshold(Threshold threshold) {
threshold.setCreateTime(java.time.LocalDateTime.now());
threshold.setUpdateTime(java.time.LocalDateTime.now());
return save(threshold);
}
@Override
public boolean updateThreshold(Threshold threshold) {
threshold.setUpdateTime(java.time.LocalDateTime.now());
return updateById(threshold);
}
@Override
public boolean deleteThreshold(Long id) {
return removeById(id);
}
@Override
public List<Threshold> queryThresholds(ThresholdQueryVO queryVO) {
LambdaQueryWrapper<Threshold> queryWrapper = new LambdaQueryWrapper<>();
if (queryVO.getDeviceId() != null && !queryVO.getDeviceId().isEmpty()) {
queryWrapper.eq(Threshold::getDeviceId, queryVO.getDeviceId());
}
if (queryVO.getRegion() != null && !queryVO.getRegion().isEmpty()) {
queryWrapper.eq(Threshold::getRegion, queryVO.getRegion());
}
if (queryVO.getParameter() != null && !queryVO.getParameter().isEmpty()) {
queryWrapper.eq(Threshold::getParameter, queryVO.getParameter());
}
if (queryVO.getStatus() != null) {
queryWrapper.eq(Threshold::getStatus, queryVO.getStatus());
}
return list(queryWrapper);
}
}
@@ -0,0 +1,23 @@
package com.water.production.vo;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
@Data
@Schema(description = "设备查询参数")
public class EquipmentQueryVO {
@Schema(description = "设备名称(模糊查询)")
private String deviceName;
@Schema(description = "设备类型")
private String deviceType;
@Schema(description = "区域")
private String region;
@Schema(description = = "状态:online-在线,offline-离线,maintenance-维护中,fault-故障")
private String status;
@Schema(description = "制造商")
private String manufacturer;
}
@@ -0,0 +1,20 @@
package com.water.production.vo;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
@Data
@Schema(description = "信息发布查询参数")
public class NotificationQueryVO {
@Schema(description = "区域")
private String region;
@Schema(description = "类型:forecast-预报,warning-预警,info-通知")
private String type;
@Schema(description = "状态:1-草稿,2-已发布,3-已归档")
private Integer status;
@Schema(description = "优先级:high-高,medium-中,low-低")
private String priority;
}
@@ -0,0 +1,20 @@
package com.water.production.vo;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
@Data
@Schema(description = "阈值查询参数")
public class ThresholdQueryVO {
@Schema(description = "设备ID")
private String deviceId;
@Schema(description = "区域")
private String region;
@Schema(description = "参数名称")
private String parameter;
@Schema(description = "状态:1-启用,0-禁用")
private Integer status;
}