42 changed files with 1441 additions and 378 deletions
@ -0,0 +1,55 @@
|
||||
package com.mh; |
||||
|
||||
import com.mh.common.core.domain.entity.MqttSubscription; |
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.framework.mqtt.service.IMqttTopicService; |
||||
import com.mh.system.service.mqtt.IMqttSubscriptionService; |
||||
import org.springframework.boot.ApplicationArguments; |
||||
import org.springframework.boot.ApplicationRunner; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 项目初始化之后的系列操作 |
||||
* @date 2025-02-14 16:35:50 |
||||
*/ |
||||
@Component |
||||
public class MHRunner implements ApplicationRunner { |
||||
|
||||
private final IMqttSubscriptionService iMqttSubscriptionService; |
||||
|
||||
private final IMqttTopicService iMqttTopicService; |
||||
|
||||
public MHRunner(IMqttSubscriptionService iMqttSubscriptionService, IMqttTopicService iMqttTopicService) { |
||||
this.iMqttSubscriptionService = iMqttSubscriptionService; |
||||
this.iMqttTopicService = iMqttTopicService; |
||||
} |
||||
|
||||
@Override |
||||
public void run(ApplicationArguments args) throws Exception { |
||||
// 初始化mqtt订阅记录
|
||||
initializeMqttSubscription(); |
||||
} |
||||
|
||||
/** |
||||
* 初始化mqtt订阅记录 |
||||
*/ |
||||
private void initializeMqttSubscription() { |
||||
MqttSubscription mqttSubscription = new MqttSubscription(); |
||||
mqttSubscription.setStatus("0"); |
||||
List<MqttSubscription> mqttSubscriptions = iMqttSubscriptionService.selectMqttSubList(mqttSubscription); |
||||
for (MqttSubscription subscription : mqttSubscriptions) { |
||||
try { |
||||
if (!StringUtils.isEmpty(subscription.getTopic())) { |
||||
iMqttTopicService.subscribe(subscription.getTopic(), subscription.getQos()); |
||||
} |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,113 @@
|
||||
package com.mh.web.controller.mqtt; |
||||
|
||||
import com.mh.common.annotation.Log; |
||||
import com.mh.common.core.controller.BaseController; |
||||
import com.mh.common.core.domain.AjaxResult; |
||||
import com.mh.common.core.domain.entity.MqttSubscription; |
||||
import com.mh.common.core.page.TableDataInfo; |
||||
import com.mh.common.enums.BusinessType; |
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.framework.mqtt.service.IMqttTopicService; |
||||
import com.mh.system.service.mqtt.IMqttSubscriptionService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description mqtt持久化controller |
||||
* @date 2025-02-14 14:07:45 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/mqtt/subs") |
||||
public class MqttSubsController extends BaseController { |
||||
|
||||
@Autowired |
||||
private IMqttSubscriptionService iMqttSubscriptionService; |
||||
|
||||
@Autowired |
||||
private IMqttTopicService mqttTopicService; |
||||
|
||||
/** |
||||
* 获取mqtt订阅记录列表内容数据 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:mqtt:list')") |
||||
@GetMapping("/list") |
||||
public TableDataInfo list(MqttSubscription mqttSubscription) { |
||||
startPage(); |
||||
List<MqttSubscription> list = iMqttSubscriptionService.selectMqttSubList(mqttSubscription); |
||||
return getDataTable(list); |
||||
} |
||||
|
||||
/** |
||||
* 根据mqtt订阅记录id获取详细信息 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:mqtt:query')") |
||||
@GetMapping(value = "/{subsId}") |
||||
public AjaxResult getInfo(@PathVariable String subsId) { |
||||
return success(iMqttSubscriptionService.selectMqttSubById(subsId)); |
||||
} |
||||
|
||||
/** |
||||
* 新增mqtt订阅记录 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:mqtt:add')") |
||||
@Log(title = "mqtt订阅记录管理", businessType = BusinessType.INSERT) |
||||
@PostMapping |
||||
public AjaxResult add(@Validated @RequestBody MqttSubscription mqttSubscription) { |
||||
mqttSubscription.setCreateBy(getUsername()); |
||||
String[] subscribedTopics = mqttTopicService.getSubscribedTopics(); |
||||
boolean exists = Arrays.stream(subscribedTopics).anyMatch(val -> val.equals(mqttSubscription.getTopic())); |
||||
if (!exists) { |
||||
int i = iMqttSubscriptionService.insertMqttSub(mqttSubscription); |
||||
mqttTopicService.subscribe(mqttSubscription.getTopic(), mqttSubscription.getQos()); |
||||
return toAjax(i); |
||||
} |
||||
return AjaxResult.error("topic已存在"); |
||||
} |
||||
|
||||
/** |
||||
* 修改mqtt订阅记录信息 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:mqtt:edit')") |
||||
@Log(title = "mqtt订阅记录管理", businessType = BusinessType.UPDATE) |
||||
@PutMapping |
||||
public AjaxResult edit(@Validated @RequestBody MqttSubscription mqttSubscription) { |
||||
mqttSubscription.setUpdateBy(getUsername()); |
||||
// 判断是否停用订阅
|
||||
mqttSubscription.setUpdateTime(new Date()); |
||||
int result = iMqttSubscriptionService.updateMqttSub(mqttSubscription); |
||||
MqttSubscription mqttSubscription1 = iMqttSubscriptionService.selectMqttSubById(mqttSubscription.getId()); |
||||
if (mqttSubscription.getStatus().equals("1")) { |
||||
mqttTopicService.unsubscribe(mqttSubscription.getTopic()); |
||||
} else if (!Objects.equals(mqttSubscription.getQos(), mqttSubscription1.getQos()) && mqttSubscription.getStatus().equals("0")) { |
||||
mqttTopicService.unsubscribe(mqttSubscription.getTopic()); |
||||
mqttTopicService.subscribe(mqttSubscription.getTopic(), mqttSubscription.getQos()); |
||||
} |
||||
return toAjax(result); |
||||
} |
||||
|
||||
/** |
||||
* 删除mqtt订阅记录管理 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:mqtt:remove')") |
||||
@Log(title = "mqtt订阅记录管理", businessType = BusinessType.DELETE) |
||||
@DeleteMapping("/{subsIdIds}") |
||||
public AjaxResult remove(@PathVariable String[] subsIdIds) { |
||||
// 删除订阅也是直接解绑
|
||||
for (String acId : subsIdIds) { |
||||
MqttSubscription mqttSubscription = iMqttSubscriptionService.selectMqttSubById(acId); |
||||
mqttTopicService.unsubscribe(mqttSubscription.getTopic()); |
||||
} |
||||
return toAjax(iMqttSubscriptionService.deleteMqttSubByIds(subsIdIds)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.mh.common.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project NewZhujiang_Server |
||||
* @description 控制设备日志详情 |
||||
* @date 2023/8/8 11:50:48 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface ControlDeviceAno { |
||||
|
||||
String value(); |
||||
|
||||
boolean isAop() default true; |
||||
|
||||
} |
@ -0,0 +1,87 @@
|
||||
package com.mh.common.core.domain.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备控制日历类 |
||||
* @date 2025-02-13 17:32:27 |
||||
*/ |
||||
@TableName("device_control_log") |
||||
public class DeviceControlLog { |
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID) |
||||
private String id; |
||||
private String deviceName; |
||||
private String controlType; |
||||
private String controlContent; |
||||
private String createUser; |
||||
private Date createTime; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getDeviceName() { |
||||
return deviceName; |
||||
} |
||||
|
||||
public void setDeviceName(String deviceName) { |
||||
this.deviceName = deviceName; |
||||
} |
||||
|
||||
public String getControlType() { |
||||
return controlType; |
||||
} |
||||
|
||||
public void setControlType(String controlType) { |
||||
this.controlType = controlType; |
||||
} |
||||
|
||||
public String getControlContent() { |
||||
return controlContent; |
||||
} |
||||
|
||||
public void setControlContent(String controlContent) { |
||||
this.controlContent = controlContent; |
||||
} |
||||
|
||||
public String getCreateUser() { |
||||
return createUser; |
||||
} |
||||
|
||||
public void setCreateUser(String createUser) { |
||||
this.createUser = createUser; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("id", id) |
||||
.append("deviceName", deviceName) |
||||
.append("controlType", controlType) |
||||
.append("controlContent", controlContent) |
||||
.append("createUser", createUser) |
||||
.append("createTime", createTime) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,114 @@
|
||||
package com.mh.common.core.domain.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import com.mh.common.core.domain.BaseEntity; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description mqtt订阅管理 |
||||
* @date 2025-02-14 13:47:07 |
||||
*/ |
||||
@TableName("mqtt_subscription") |
||||
public class MqttSubscription extends BaseEntity { |
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID) |
||||
private String id; |
||||
|
||||
private String topic; |
||||
|
||||
private Short qos; |
||||
|
||||
private String clientId; |
||||
|
||||
private String status; |
||||
|
||||
@TableField(exist = false) |
||||
private String searchValue; |
||||
|
||||
/** 请求参数 */ |
||||
@TableField(exist = false) |
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
||||
private Map<String, Object> params; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getTopic() { |
||||
return topic; |
||||
} |
||||
|
||||
public void setTopic(String topic) { |
||||
this.topic = topic; |
||||
} |
||||
|
||||
public Short getQos() { |
||||
return qos; |
||||
} |
||||
|
||||
public void setQos(Short qos) { |
||||
this.qos = qos; |
||||
} |
||||
|
||||
public String getClientId() { |
||||
return clientId; |
||||
} |
||||
|
||||
public void setClientId(String clientId) { |
||||
this.clientId = clientId; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
@Override |
||||
public String getSearchValue() { |
||||
return searchValue; |
||||
} |
||||
|
||||
@Override |
||||
public void setSearchValue(String searchValue) { |
||||
this.searchValue = searchValue; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Object> getParams() { |
||||
return params; |
||||
} |
||||
|
||||
@Override |
||||
public void setParams(Map<String, Object> params) { |
||||
this.params = params; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("id", id) |
||||
.append("topic", topic) |
||||
.append("qos", qos) |
||||
.append("clientId", clientId) |
||||
.append("status", status) |
||||
.append("searchValue", searchValue) |
||||
.append("params", params) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.mh.common.core.domain.entity; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @title : |
||||
* @description 接收前端传过来的指令 |
||||
* @updateTime 2020-05-28 |
||||
* @throws : |
||||
*/ |
||||
@Setter |
||||
@Getter |
||||
public class OrderEntity { |
||||
|
||||
private Integer id; |
||||
private String param; |
||||
private Integer type; // 0:修改频率,
|
||||
// 1:修改开关状态,
|
||||
// 2: 关闭冷却泵之前,查询最近关闭的冷却塔时间
|
||||
// 3:群控手自动模式切换
|
||||
// 4:修改温度
|
||||
// 5:修改压力
|
||||
// 6:手动,半自动切换
|
||||
// 7:一键启动、
|
||||
private String otherName; // 别称
|
||||
|
||||
public OrderEntity() { |
||||
} |
||||
|
||||
public OrderEntity(Integer id, String param, Integer type, String otherName) { |
||||
this.id = id; |
||||
this.param = param; |
||||
this.type = type; |
||||
this.otherName = otherName; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("id", id) |
||||
.append("param", param) |
||||
.append("type", type) |
||||
.append("otherName", otherName) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.mh.common.enums; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project NewZhujiang_Server |
||||
* @description 操作控制类型 |
||||
* @date 2023/8/8 15:07:40 |
||||
*/ |
||||
public enum ControlTypeEnum { |
||||
|
||||
// 0:修改频率,
|
||||
// 1:修改开关状态 0:关闭,1:启动,
|
||||
// 2: 关闭冷却泵之前,查询最近关闭的冷却塔时间
|
||||
// 3:群控手自动模式切换
|
||||
// 4:修改温度
|
||||
// 5:修改压力
|
||||
control1(0,"修改频率"), |
||||
control2(1,"修改开关状态"), |
||||
control3(2,"关闭冷却泵之前,查询最近关闭的冷却塔时间"), |
||||
control4(3,"群控手自动模式切换"), |
||||
control5(4,"修改温度"), |
||||
control6(5,"修改压力") |
||||
; |
||||
|
||||
private Integer type; |
||||
|
||||
private String control; |
||||
|
||||
ControlTypeEnum() { |
||||
} |
||||
|
||||
ControlTypeEnum(Integer type, String control) { |
||||
this.type = type; |
||||
this.control = control; |
||||
} |
||||
|
||||
public Integer getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(Integer type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getControl() { |
||||
return control; |
||||
} |
||||
|
||||
public void setControl(String control) { |
||||
this.control = control; |
||||
} |
||||
|
||||
public static String getByType(Integer type) { |
||||
for (ControlTypeEnum value : values()) { |
||||
if (null != type && Objects.equals(value.getType(), type)) { |
||||
return value.getControl(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,117 @@
|
||||
package com.mh.framework.aspectj; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.mh.common.annotation.ControlDeviceAno; |
||||
import com.mh.common.core.domain.entity.DeviceControlLog; |
||||
import com.mh.common.core.domain.entity.OrderEntity; |
||||
import com.mh.common.enums.ControlTypeEnum; |
||||
import com.mh.common.utils.SecurityUtils; |
||||
import com.mh.system.service.device.IDeviceControlLogService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.Signature; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Before; |
||||
import org.aspectj.lang.annotation.Pointcut; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project NewZhujiang_Server |
||||
* @description 设备控制详情内容 |
||||
* @date 2023/8/8 11:55:54 |
||||
*/ |
||||
@Slf4j |
||||
@Aspect |
||||
@Component |
||||
public class ControlDeviceAspect { |
||||
|
||||
@Autowired |
||||
private IDeviceControlLogService deviceControlLogService; |
||||
|
||||
@Pointcut(value = "execution(* com.mh.*.controller..*(..)) && @annotation(com.mh.common.annotation.ControlDeviceAno)") |
||||
public void executionMethod(){} |
||||
|
||||
@Pointcut(value = "execution(* com.mh.*.controller..*(..)) && @annotation(com.mh.common.annotation.ControlDeviceAno)") |
||||
public void executionNote(){} |
||||
|
||||
@Before("executionMethod()") |
||||
public void controlBefore(JoinPoint joinPoint) { |
||||
log.info("前置通知"); |
||||
Object[] args = joinPoint.getArgs(); |
||||
for (Object arg : args) { |
||||
log.info("获取到对应的参数==>{}",arg); |
||||
} |
||||
} |
||||
|
||||
@Around(value = "execution(* com.mh.*.controller..*(..)) && @annotation(com.mh.common.annotation.ControlDeviceAno)") |
||||
public Object controlBeforeNote(ProceedingJoinPoint joinPoint) throws Throwable { |
||||
// 通知签名
|
||||
Signature signature = joinPoint.getSignature(); |
||||
MethodSignature msg = (MethodSignature) signature; |
||||
Object target = joinPoint.getTarget(); |
||||
// 获取注解标注的方法
|
||||
Method method = target.getClass().getMethod(msg.getName(), msg.getParameterTypes()); |
||||
// 通过方法获取注解
|
||||
ControlDeviceAno annotation = method.getAnnotation(ControlDeviceAno.class); |
||||
// Object proceed;
|
||||
// 获取参数
|
||||
Object[] args = joinPoint.getArgs(); |
||||
log.info("注解方法标注值=={}", annotation.value()); |
||||
log.info("注解方法标注=={}", annotation.isAop()); |
||||
for (Object arg : args) { |
||||
log.info("方法内的参数==>{}", arg); |
||||
if (Objects.isNull(arg)) { |
||||
continue; |
||||
} |
||||
String string = JSON.toJSON(arg).toString(); |
||||
List<OrderEntity> collect = JSON.parseArray(string, OrderEntity.class); |
||||
if (!CollectionUtils.isEmpty(collect)) { |
||||
for (OrderEntity orderEntity : collect) { |
||||
// DeviceMessageDTO deviceMessageDTO = deviceDisplayService.queryDeviceStatusByDeviceId(String.valueOf(orderEntity.getId()));
|
||||
DeviceControlLog deviceControlLog = new DeviceControlLog(); |
||||
// if (null != deviceMessageDTO) {
|
||||
// deviceControlLogEntity.setDeviceName(deviceMessageDTO.getLabel());
|
||||
// }
|
||||
deviceControlLog.setDeviceName(orderEntity.getOtherName()); |
||||
deviceControlLog.setControlType(ControlTypeEnum.getByType(orderEntity.getType())); |
||||
// 根据id查询对应的注册地址信息
|
||||
if (null != orderEntity.getType() && orderEntity.getType() == 1) { |
||||
// 修改开关状态
|
||||
deviceControlLog.setControlContent(orderEntity.getParam().equals("0")?"关闭":"开启"); |
||||
} else if (null != orderEntity.getType() && orderEntity.getType() == 0) { |
||||
// 修改频率
|
||||
deviceControlLog.setControlContent(orderEntity.getParam()); |
||||
} else if (null != orderEntity.getType() && orderEntity.getType() == 3) { |
||||
// 修改手动获取全自动
|
||||
deviceControlLog.setControlContent(orderEntity.getParam().equals("0")?"关闭全自动":"开启全自动"); |
||||
} |
||||
deviceControlLog.setCreateUser(SecurityUtils.getUsername()); |
||||
deviceControlLog.setCreateTime(new Date()); |
||||
deviceControlLogService.insertData(deviceControlLog); |
||||
} |
||||
} |
||||
} |
||||
// if (!annotation.isAop()) {
|
||||
// log.info("你无需处理当前注解内容");
|
||||
// proceed = joinPoint.proceed();
|
||||
// } else {
|
||||
// log.info("进入aop判断");
|
||||
// proceed = joinPoint.proceed();
|
||||
//
|
||||
// }
|
||||
return joinPoint.proceed(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.mh.system.mapper.device; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.mh.common.core.domain.entity.DeviceControlLog; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备日志控制类 |
||||
* @date 2025-02-13 17:35:45 |
||||
*/ |
||||
@Mapper |
||||
public interface DeviceControlLogMapper extends BaseMapper<DeviceControlLog> { |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.mh.system.mapper.mqtt; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.mh.common.core.domain.entity.MqttSubscription; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description mqtt订阅mapper类 |
||||
* @date 2025-02-14 14:00:58 |
||||
*/ |
||||
@Mapper |
||||
public interface MqttSubscriptionMapper extends BaseMapper<MqttSubscription> { |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.mh.system.service.device; |
||||
|
||||
|
||||
import com.mh.common.core.domain.entity.DeviceControlLog; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备控制日志记录类 |
||||
* @date 2025-02-13 17:28:39 |
||||
*/ |
||||
public interface IDeviceControlLogService { |
||||
|
||||
/** |
||||
* 插入值 |
||||
* @param deviceControlLog |
||||
*/ |
||||
void insertData(DeviceControlLog deviceControlLog); |
||||
|
||||
/** |
||||
* 根据查询内容查询 |
||||
* @param deviceControlLog |
||||
* @return |
||||
*/ |
||||
List<DeviceControlLog> findPage(DeviceControlLog deviceControlLog); |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.mh.system.service.device.impl; |
||||
|
||||
import com.mh.common.core.domain.entity.DeviceControlLog; |
||||
import com.mh.system.mapper.device.DeviceControlLogMapper; |
||||
import com.mh.system.service.device.IDeviceControlLogService; |
||||
import jakarta.annotation.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备日志控制实现类 |
||||
* @date 2025-02-13 17:34:43 |
||||
*/ |
||||
@Service |
||||
public class DeviceControlLogServiceImpl implements IDeviceControlLogService { |
||||
|
||||
@Resource |
||||
private DeviceControlLogMapper deviceControlLogMapper; |
||||
|
||||
@Override |
||||
public void insertData(DeviceControlLog deviceControlLog) { |
||||
deviceControlLogMapper.insert(deviceControlLog); |
||||
} |
||||
|
||||
@Override |
||||
public List<DeviceControlLog> findPage(DeviceControlLog deviceControlLog) { |
||||
return List.of(); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.mh.system.service.mqtt; |
||||
|
||||
import com.mh.common.core.domain.entity.MqttSubscription; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description mqtt订阅管理 |
||||
* @date 2025-02-14 13:58:37 |
||||
*/ |
||||
public interface IMqttSubscriptionService { |
||||
|
||||
List<MqttSubscription> selectMqttSubList(MqttSubscription mqttSubscription); |
||||
|
||||
MqttSubscription selectMqttSubById(String msId); |
||||
|
||||
int insertMqttSub(MqttSubscription mqttSubscription); |
||||
|
||||
int updateMqttSub(MqttSubscription mqttSubscription); |
||||
|
||||
int deleteMqttSubByIds(String[] msIds); |
||||
|
||||
} |
@ -0,0 +1,73 @@
|
||||
package com.mh.system.service.mqtt.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.mh.common.core.domain.entity.MqttSubscription; |
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.system.mapper.mqtt.MqttSubscriptionMapper; |
||||
import com.mh.system.service.mqtt.IMqttSubscriptionService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description mqtt订阅实现类 |
||||
* @date 2025-02-14 13:59:27 |
||||
*/ |
||||
@Service |
||||
public class MqttSubscriptionServiceImpl implements IMqttSubscriptionService { |
||||
|
||||
private final MqttSubscriptionMapper mqttSubscriptionMapper; |
||||
|
||||
@Autowired |
||||
public MqttSubscriptionServiceImpl(MqttSubscriptionMapper mqttSubscriptionMapper) { |
||||
this.mqttSubscriptionMapper = mqttSubscriptionMapper; |
||||
} |
||||
|
||||
@Override |
||||
public List<MqttSubscription> selectMqttSubList(MqttSubscription mqttSubscription) { |
||||
if (mqttSubscription == null) { |
||||
return List.of(); |
||||
} |
||||
QueryWrapper<MqttSubscription> queryWrapper = new QueryWrapper<>(); |
||||
// 订阅主题
|
||||
if (!StringUtils.isEmpty(mqttSubscription.getTopic())) { |
||||
queryWrapper.like("topic", mqttSubscription.getTopic()); |
||||
} |
||||
// 状态
|
||||
if (!StringUtils.isEmpty(mqttSubscription.getStatus())) { |
||||
queryWrapper.eq("status", mqttSubscription.getStatus()); |
||||
} |
||||
queryWrapper.orderByDesc("create_time"); |
||||
return mqttSubscriptionMapper.selectList(queryWrapper); |
||||
} |
||||
|
||||
@Override |
||||
public MqttSubscription selectMqttSubById(String msId) { |
||||
return mqttSubscriptionMapper.selectById(msId); |
||||
} |
||||
|
||||
@Override |
||||
public int insertMqttSub(MqttSubscription mqttSubscription) { |
||||
return mqttSubscriptionMapper.insert(mqttSubscription); |
||||
} |
||||
|
||||
@Override |
||||
public int updateMqttSub(MqttSubscription mqttSubscription) { |
||||
return mqttSubscriptionMapper.updateById(mqttSubscription); |
||||
} |
||||
|
||||
@Override |
||||
public int deleteMqttSubByIds(String[] msIds) { |
||||
if (msIds != null && msIds.length > 0) { |
||||
for (String msId : msIds) { |
||||
mqttSubscriptionMapper.deleteById(msId); |
||||
} |
||||
return msIds.length; |
||||
} |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.mh.system.service.operation; |
||||
|
||||
import com.mh.common.core.domain.AjaxResult; |
||||
import com.mh.common.core.domain.entity.OrderEntity; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 操作设备服务类 |
||||
* @date 2025-02-14 09:30:47 |
||||
*/ |
||||
public interface IOperationDeviceService { |
||||
|
||||
String operationDevice(List<OrderEntity> changeValues); |
||||
|
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.mh.system.service.operation.impl; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.mh.common.constant.Constants; |
||||
import com.mh.common.core.domain.entity.OrderEntity; |
||||
import com.mh.common.model.request.AdvantechDatas; |
||||
import com.mh.common.model.response.AdvantechResponse; |
||||
import com.mh.common.utils.DateUtils; |
||||
import com.mh.system.service.operation.IOperationDeviceService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备操作实现类 |
||||
* @date 2025-02-14 09:32:34 |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
public class OperationDeviceServiceImpl implements IOperationDeviceService { |
||||
|
||||
@Override |
||||
public String operationDevice(List<OrderEntity> changeValues) { |
||||
// 拼接发送的报文
|
||||
AdvantechResponse<AdvantechDatas> sendData = new AdvantechResponse<>(); |
||||
try { |
||||
List<AdvantechDatas> advantechDatas = getAdvantechDatas(changeValues); |
||||
sendData.setW(advantechDatas); |
||||
sendData.setTs(DateUtils.dateToTsStr()); |
||||
} catch (Exception e) { |
||||
log.error("发送mqtt控制设备指令失败", e); |
||||
return Constants.FAIL; |
||||
} |
||||
return JSONObject.toJSONString(sendData); |
||||
} |
||||
|
||||
private static List<AdvantechDatas> getAdvantechDatas(List<OrderEntity> changeValues) { |
||||
List<AdvantechDatas> advantechDatas = new ArrayList<>(); |
||||
for (OrderEntity changeValue : changeValues) { |
||||
// 获取报文
|
||||
String message = changeValue.getParam(); |
||||
// 获取报文类型
|
||||
Integer type = changeValue.getType(); |
||||
// 获取报文其他信息
|
||||
String otherName = changeValue.getOtherName(); |
||||
// 发送报文
|
||||
AdvantechDatas data = new AdvantechDatas(); |
||||
data.setTag(otherName); |
||||
data.setValue(message); |
||||
advantechDatas.add(data); |
||||
} |
||||
return advantechDatas; |
||||
} |
||||
} |
Loading…
Reference in new issue