mirror of
https://gitee.com/iteaj/iboot.git
synced 2026-09-21 13:29:46 +08:00
新增dtu调试
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<properties>
|
||||
<iot.version>2.4.7</iot.version>
|
||||
<iot.version>2.4.8</iot.version>
|
||||
<!--当前项目的根目录, 用于代码生成器-->
|
||||
<project.root.path>${project.basedir}</project.root.path>
|
||||
</properties>
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RoleController extends BaseController {
|
||||
*/
|
||||
@GetMapping("allMenus")
|
||||
public Result<List<Menu>> allFunc() {
|
||||
return this.menuService.selectMenuTrees(null);
|
||||
return this.menuService.selectMenuTrees(new Menu());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.iteaj.iboot.msn.iot;
|
||||
|
||||
import com.iteaj.iboot.msn.iot.websocket.IotDebugListener;
|
||||
import org.apache.shiro.session.mgt.SessionManager;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@@ -9,5 +12,8 @@ import org.springframework.context.annotation.Profile;
|
||||
@MapperScan({"com.iteaj.iboot.msn.iot.mapper"})
|
||||
public class IotAutoConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public IotDebugListener iotDebugListener(SessionManager sessionManager) {
|
||||
return new IotDebugListener(sessionManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.iteaj.iboot.msn.iot.controller;
|
||||
|
||||
import java.util.List;
|
||||
import com.iteaj.framework.result.Result;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.iteaj.iboot.msn.iot.entity.DeviceChild;
|
||||
import com.iteaj.iboot.msn.iot.service.IDeviceChildService;
|
||||
import com.iteaj.framework.BaseController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 子设备管理
|
||||
* </p>
|
||||
*
|
||||
* @author iteaj
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/deviceChild")
|
||||
public class DeviceChildController extends BaseController {
|
||||
|
||||
private final IDeviceChildService deviceChildService;
|
||||
|
||||
public DeviceChildController(IDeviceChildService deviceChildService) {
|
||||
this.deviceChildService = deviceChildService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
* @param page 分页
|
||||
* @param entity 搜索条件
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public Result<IPage<DeviceChild>> list(Page<DeviceChild> page, DeviceChild entity) {
|
||||
return this.deviceChildService.page(page, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取编辑记录
|
||||
* @param id 记录id
|
||||
*/
|
||||
@GetMapping("/edit")
|
||||
public Result<DeviceChild> getById(Long id) {
|
||||
return this.deviceChildService.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或者更新记录
|
||||
* @param entity
|
||||
*/
|
||||
@PostMapping("/saveOrUpdate")
|
||||
public Result<Boolean> save(@RequestBody DeviceChild entity) {
|
||||
return this.deviceChildService.saveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定记录
|
||||
* @param idList
|
||||
*/
|
||||
@PostMapping("/del")
|
||||
public Result<Boolean> remove(@RequestBody List<Long> idList) {
|
||||
return this.deviceChildService.removeByIds(idList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 设备表
|
||||
@@ -30,9 +33,15 @@ public class Device extends BaseEntity {
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 设备uid
|
||||
*/
|
||||
private Long uid;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotBlank(message = "设备名称必填")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
@@ -58,6 +67,7 @@ public class Device extends BaseEntity {
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
@NotBlank(message = "设备编号必填")
|
||||
private String deviceSn;
|
||||
|
||||
private Date createTime;
|
||||
@@ -68,8 +78,9 @@ public class Device extends BaseEntity {
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 设备所属产品
|
||||
* 设备类型
|
||||
*/
|
||||
@NotNull(message = "设备类型必填")
|
||||
private Long deviceTypeId;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.iteaj.iboot.msn.iot.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.SqlCondition;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.iteaj.framework.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 子设备
|
||||
* </p>
|
||||
*
|
||||
* @author iteaj
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName("iot_device_child")
|
||||
public class DeviceChild extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 子设备名称
|
||||
*/
|
||||
@TableField(condition = SqlCondition.LIKE)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 设备uid
|
||||
*/
|
||||
private Long uid;
|
||||
|
||||
/**
|
||||
* 子设备编号
|
||||
*/
|
||||
private String childSn;
|
||||
|
||||
/**
|
||||
* 协议类型
|
||||
*/
|
||||
private String protocolType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.iteaj.iboot.msn.iot.mapper;
|
||||
|
||||
import com.iteaj.iboot.msn.iot.entity.DeviceChild;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 子设备 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author iteaj
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
public interface DeviceChildMapper extends BaseMapper<DeviceChild> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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="com.iteaj.iboot.msn.iot.mapper.DeviceChildMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.iteaj.iboot.msn.iot.entity.DeviceChild">
|
||||
<result column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="uid" property="uid" />
|
||||
<result column="child_sn" property="childSn" />
|
||||
<result column="protocol_type" property="protocolType" />
|
||||
<result column="create_time" property="createTime" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -6,6 +6,7 @@
|
||||
<resultMap id="BasicMap" type="com.iteaj.iboot.msn.iot.entity.Device">
|
||||
<result column="id" property="id" />
|
||||
<result column="ip" property="ip" />
|
||||
<result column="uid" property="uid" />
|
||||
<result column="name" property="name" />
|
||||
<result column="port" property="port" />
|
||||
<result column="model" property="model" />
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.iteaj.iboot.msn.iot.service;
|
||||
|
||||
import com.iteaj.iboot.msn.iot.entity.DeviceChild;
|
||||
import com.iteaj.framework.IBaseService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 子设备 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author iteaj
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
public interface IDeviceChildService extends IBaseService<DeviceChild> {
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.iteaj.iboot.msn.iot.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.iteaj.framework.result.DetailResult;
|
||||
import com.iteaj.framework.result.Result;
|
||||
import com.iteaj.iboot.msn.iot.consts.DeviceStatus;
|
||||
import com.iteaj.iboot.msn.iot.dto.DeviceDto;
|
||||
@@ -32,4 +33,11 @@ public interface IDeviceService extends IBaseService<Device> {
|
||||
* @param status
|
||||
*/
|
||||
void update(String deviceSn, DeviceStatus status);
|
||||
|
||||
/**
|
||||
* 获取指定设备编号的记录
|
||||
* @param deviceSn
|
||||
* @return
|
||||
*/
|
||||
DetailResult<Device> getByDeviceSn(String deviceSn);
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.iteaj.iboot.msn.iot.service.impl;
|
||||
|
||||
import com.iteaj.iboot.msn.iot.entity.DeviceChild;
|
||||
import com.iteaj.iboot.msn.iot.mapper.DeviceChildMapper;
|
||||
import com.iteaj.iboot.msn.iot.service.IDeviceChildService;
|
||||
import com.iteaj.framework.BaseServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 子设备 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author iteaj
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
@Service
|
||||
public class DeviceChildServiceImpl extends BaseServiceImpl<DeviceChildMapper, DeviceChild> implements IDeviceChildService {
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.iteaj.iboot.msn.iot.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.iteaj.framework.result.BooleanResult;
|
||||
import com.iteaj.framework.result.DetailResult;
|
||||
import com.iteaj.framework.result.PageResult;
|
||||
import com.iteaj.framework.result.Result;
|
||||
import com.iteaj.iboot.msn.iot.consts.DeviceStatus;
|
||||
@@ -29,10 +32,37 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> imp
|
||||
return new PageResult<>(getBaseMapper().pageOfDetail(page, entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanResult save(Device entity) {
|
||||
Device device = this.getByDeviceSn(entity.getDeviceSn()).getData();
|
||||
if(device != null) {
|
||||
return new BooleanResult(false).fail("设备编号已经存在["+entity.getDeviceSn()+"]");
|
||||
}
|
||||
|
||||
entity.setUid(IdWorker.getId());
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanResult updateById(Device entity) {
|
||||
Device device = this.getOne(Wrappers.<Device>lambdaQuery()
|
||||
.eq(Device::getDeviceSn, entity.getDeviceSn())
|
||||
.ne(Device::getId, entity.getId())).getData();
|
||||
if(device != null) {
|
||||
return new BooleanResult(false).fail("设备编号已经存在["+entity.getDeviceSn()+"]");
|
||||
}
|
||||
return super.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String deviceSn, DeviceStatus status) {
|
||||
update(Wrappers.<Device>lambdaUpdate()
|
||||
.set(Device::getStatus, status)
|
||||
.eq(Device::getDeviceSn, deviceSn));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DetailResult<Device> getByDeviceSn(String deviceSn) {
|
||||
return getOne(Wrappers.<Device>lambdaQuery().eq(Device::getDeviceSn, deviceSn));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.iteaj.iboot.msn.iot.websocket;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DebugModel {
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 客户端Sn
|
||||
*/
|
||||
private String clientSn;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.iteaj.iboot.msn.iot.websocket;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DtuDebugModel extends DebugModel{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.iteaj.iboot.msn.iot.websocket;
|
||||
|
||||
import com.iteaj.iot.CoreConst;
|
||||
import com.iteaj.iot.Message;
|
||||
import com.iteaj.iot.server.websocket.WebSocketServerListener;
|
||||
import com.iteaj.iot.server.websocket.impl.DefaultWebSocketServerComponent;
|
||||
import com.iteaj.iot.server.websocket.impl.DefaultWebSocketServerProtocol;
|
||||
import com.iteaj.iot.websocket.HttpRequestWrapper;
|
||||
import com.iteaj.iot.websocket.WebSocketFilter;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.Attribute;
|
||||
import org.apache.shiro.session.mgt.DefaultSessionKey;
|
||||
import org.apache.shiro.session.mgt.SessionManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class IotDebugListener implements WebSocketServerListener, WebSocketFilter<DefaultWebSocketServerComponent> {
|
||||
|
||||
private final SessionManager securityManager;
|
||||
|
||||
public IotDebugListener(SessionManager securityManager) {
|
||||
this.securityManager = securityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uri() {
|
||||
return "/iot/debug";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onText(DefaultWebSocketServerProtocol protocol) {
|
||||
String s = protocol.readText();
|
||||
protocol.response("accept");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(DefaultWebSocketServerProtocol protocol) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBinary(DefaultWebSocketServerProtocol protocol) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* websocket 鉴权
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HttpResponseStatus authentication(HttpRequest request) {
|
||||
String sessionId = this.getSessionId(request);
|
||||
if(sessionId != null) {
|
||||
try {
|
||||
securityManager.getSession(new DefaultSessionKey(sessionId));
|
||||
return HttpResponseStatus.OK;
|
||||
} catch (Exception e) {
|
||||
return HttpResponseStatus.UNAUTHORIZED;
|
||||
}
|
||||
}
|
||||
|
||||
return HttpResponseStatus.UNAUTHORIZED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册设备编号
|
||||
* @param head
|
||||
* @param equipCode
|
||||
* @param channel
|
||||
* @param component
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Message.MessageHead register(Message.MessageHead head, String equipCode, Channel channel, DefaultWebSocketServerComponent component) {
|
||||
if(equipCode == null) {
|
||||
Attribute<HttpRequestWrapper> request = channel.attr(CoreConst.WEBSOCKET_REQ);
|
||||
String sessionId = this.getSessionId(request.get().getRequest());
|
||||
head.setEquipCode(sessionId); // 使用sessionId作为设备编号
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
protected String getSessionId(HttpRequest request) {
|
||||
String cookie = request.headers().get("Cookie");
|
||||
return Arrays.stream(cookie.split(";"))
|
||||
.map(item -> item.split("="))
|
||||
.filter(item -> "JSESSIONID".equalsIgnoreCase(item[0].trim()))
|
||||
.findFirst().orElse(new String[]{null, null})[1];
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ iot:
|
||||
server:
|
||||
proxy:
|
||||
start: false
|
||||
websocket:
|
||||
start: true
|
||||
mqtt:
|
||||
default:
|
||||
host: broker-cn.emqx.io
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.iteaj.framework.result;
|
||||
|
||||
import com.iteaj.framework.exception.ServiceException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* create time: 2019/7/26
|
||||
@@ -32,27 +29,27 @@ public abstract class OptionalResult<E, _this extends AbstractResult<E>> extends
|
||||
return Optional.ofNullable(this.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Function#apply(Object) 直接返回响应的结果
|
||||
* @param function
|
||||
* @return
|
||||
*/
|
||||
public _this build(Function<E, Result> function) {
|
||||
if(null == function) throw new ServiceException("参数错误");
|
||||
|
||||
Result apply = function.apply(getData());
|
||||
return this.build(apply);
|
||||
public _this ok() {
|
||||
return this.ok(DMSG);
|
||||
}
|
||||
|
||||
public _this build(Result result) {
|
||||
this.setCode(result.getCode());
|
||||
this.setMessage(result.getMessage());
|
||||
public _this ok(String msg) {
|
||||
this.setCode(DCODE);
|
||||
this.setMessage(msg);
|
||||
return (_this) this;
|
||||
}
|
||||
|
||||
public _this build(long code, String message) {
|
||||
public _this fail() {
|
||||
return this.fail(HttpResult.DEFAULT_ERROR_CODE, HttpResult.DEFAULT_ERROR_MSG);
|
||||
}
|
||||
|
||||
public _this fail(String msg) {
|
||||
return this.fail(HttpResult.DEFAULT_ERROR_CODE, msg);
|
||||
}
|
||||
|
||||
public _this fail(long code, String msg) {
|
||||
this.setCode(code);
|
||||
this.setMessage(message);
|
||||
this.setMessage(msg);
|
||||
return (_this) this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user