LoRa Gateway MQTT Bridge 代码提交

This commit is contained in:
xusd 2024-07-30 10:27:48 +08:00
parent 868ba69dba
commit 206922bb73
7 changed files with 252 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package com.ruoyi.gateway.lora.controller;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gateway.lora.domain.GatewayBridge;
import com.ruoyi.gateway.lora.service.IGatewayBridgeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Objects;
/**
* BridgeController
*
* @Author xusd
* @Date 2024/7/30 9:28
**/
@Controller
@RequestMapping("/lora/bridge")
public class GatewayBridgeController extends BaseController {
private String prefix = "lora/bridge";
@Autowired
private IGatewayBridgeService gatewayBridgeService;
@RequiresPermissions("lora:bridge:view")
@GetMapping()
public String bridge(ModelMap mmap)
{
GatewayBridge bridge = gatewayBridgeService.selectGatewayBridge();
if (Objects.isNull(bridge)){
bridge = new GatewayBridge();
}
mmap.put("gatewayBridge", bridge);
return prefix + "/bridge";
}
/**
* 修改保存Bridge
*/
@RequiresPermissions("gateway:bridge:edit")
@Log(title = "Bridge", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(GatewayBridge gatewayBridge)
{
return toAjax(gatewayBridgeService.updateGatewayBridge(gatewayBridge));
}
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.gateway.lora.domain;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
/**
* Bridge对象 gateway_bridge
*
* @Author xusd
* @Date 2024/7/30 9:24
**/
@Data
public class GatewayBridge extends BaseEntity {
/** IP地址 */
@Excel(name = "IP地址")
private String address;
/** 端口 */
@Excel(name = "端口")
private String port;
}

View File

@ -0,0 +1,27 @@
package com.ruoyi.gateway.lora.mapper;
import com.ruoyi.gateway.lora.domain.GatewayBridge;
/**
* @Author xusd
* @Date 2024/7/30 9:38
**/
public interface GatewayBridgeMapper {
/**
* 查询Bridge
*
* @return Bridge
*/
GatewayBridge selectGatewayBridge();
/**
* 修改Bridge
*
* @param gatewayBridge Bridge
* @return 结果
*/
int updateGatewayBridge(GatewayBridge gatewayBridge);
}

View File

@ -0,0 +1,27 @@
package com.ruoyi.gateway.lora.service;
import com.ruoyi.gateway.lora.domain.GatewayBridge;
/**
* @Author xusd
* @Date 2024/7/30 9:31
**/
public interface IGatewayBridgeService {
/**
* 查询Bridge
*
* @return Bridge
*/
GatewayBridge selectGatewayBridge();
/**
* 修改Bridge
*
* @param gatewayBridge Bridge
* @return 结果
*/
int updateGatewayBridge(GatewayBridge gatewayBridge);
}

View File

@ -0,0 +1,42 @@
package com.ruoyi.gateway.lora.service.impl;
import com.ruoyi.gateway.lora.domain.GatewayBridge;
import com.ruoyi.gateway.lora.mapper.GatewayBridgeMapper;
import com.ruoyi.gateway.lora.service.IGatewayBridgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Author xusd
* @Date 2024/7/30 9:36
**/
@Service
public class GatewayBridgeServiceImpl implements IGatewayBridgeService {
@Autowired
private GatewayBridgeMapper gatewayBridgeMapper;
/**
* 查询Bridge
*
* @return Bridge
*/
@Override
public GatewayBridge selectGatewayBridge()
{
return gatewayBridgeMapper.selectGatewayBridge();
}
/**
* 修改Bridge
*
* @param gatewayBridge Bridge
* @return 结果
*/
@Override
public int updateGatewayBridge(GatewayBridge gatewayBridge)
{
return gatewayBridgeMapper.updateGatewayBridge(gatewayBridge);
}
}

View File

@ -0,0 +1,29 @@
<?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.ruoyi.gateway.lora.mapper.GatewayBridgeMapper">
<resultMap type="GatewayBridge" id="GatewayBridgeResult">
<result property="address" column="address" />
<result property="port" column="port" />
</resultMap>
<sql id="selectGatewayBridgeVo">
select address, port from gateway_bridge
</sql>
<select id="selectGatewayBridge" parameterType="String" resultMap="GatewayBridgeResult">
<include refid="selectGatewayBridgeVo"/>
limit 1
</select>
<update id="updateGatewayBridge" parameterType="GatewayBridge">
update gateway_bridge
<trim prefix="SET" suffixOverrides=",">
address = #{address},
port = #{port},
</trim>
</update>
</mapper>

View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改Bridge')" />
</head>
<body class="white-bg">
<div style="border-bottom: darkgray 1px solid;margin: 20px 50px 0px;">
<div style="width: 100px;height: 30px;background: darkgray;text-align: center;line-height: 30px;user-select: none;">基本设置</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight ibox-content" style="margin-left: 300px;margin-right: 300px;">
<form class="form-horizontal m" id="form-bridge-edit" th:object="${gatewayBridge}">
<div class="form-group">
<label class="col-sm-3 control-label">IP地址</label>
<div class="col-sm-8">
<input name="address" th:field="*{address}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">端口:</label>
<div class="col-sm-8">
<input name="port" th:field="*{port}" class="form-control" type="text">
</div>
</div>
<div class="layui-layer-btn layui-layer-btn-">
<a onclick="submitHandler()" class="layui-layer-btn0">确定</a>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var prefix = ctx + "lora/bridge";
$("#form-bridge-edit").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
console.log($('#form-bridge-edit').serialize())
$.operate.save(prefix + "/edit", $('#form-bridge-edit').serialize());
}
}
</script>
</body>
</html>