添加设备查询和设备更新接口

This commit is contained in:
648540858
2024-03-13 23:16:01 +08:00
parent d78f76e58b
commit 4eb0163e43
11 changed files with 462 additions and 5 deletions

View File

@@ -8,6 +8,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "jt808设备")
public class JTDevice {
private int id;
/**
* 省域ID
*/
@@ -69,6 +71,14 @@ public class JTDevice {
private Double latitude;
@Schema(description = "创建时间")
private String createTime;
@Schema(description = "更新时间")
private String updateTime;
@Schema(description = "状态")
private boolean status;
public int getProvinceId() {
return provinceId;
@@ -149,4 +159,36 @@ public class JTDevice {
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

View File

@@ -1,15 +1,21 @@
package com.genersoft.iot.vmp.jt1078.config;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
import com.genersoft.iot.vmp.jt1078.proc.response.*;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* curl http://localhost:18080/api/jt1078/start/live/18864197066/1
@@ -26,6 +32,9 @@ public class JT1078Controller {
@Resource
JT1078Template jt1078Template;
@Resource
Ijt1078Service service;
/**
* jt1078Template 调用示例
*/
@@ -47,5 +56,26 @@ public class JT1078Controller {
return wvpResult;
}
@Operation(summary = "分页查询部标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "page", description = "当前页", required = true)
@Parameter(name = "count", description = "每页查询数量", required = true)
@Parameter(name = "query", description = "查询内容")
@Parameter(name = "online", description = "是否在线")
@GetMapping("/device/list")
public PageInfo<JTDevice> getDevices(int page, int count,
@RequestParam(required = false) String query,
@RequestParam(required = false) Boolean online) {
return service.getDeviceList(page, count, query, online);
}
@Operation(summary = "更新设备信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "device", description = "设备", required = true)
@PostMapping("/device/update")
public void updateDevice(JTDevice device){
assert device.getId() > 0;
assert device.getDeviceId() != null;
service.updateDevice(device);
}
}

View File

@@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.jt1078.dao;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface JTDeviceMapper {
@@ -25,4 +27,23 @@ public interface JTDeviceMapper {
"WHERE device_id=#{deviceId}"+
" </script>"})
void updateDevice(JTDevice device);
@Select(value = {" <script>" +
"SELECT * " +
"from " +
"wvp_jt_device jd " +
"WHERE " +
"1=1" +
" <if test='query != null'> AND (" +
"jd.province_id LIKE concat('%',#{query},'%') " +
"OR jd.city_id LIKE concat('%',#{query},'%') " +
"OR jd.maker_id LIKE concat('%',#{query},'%') " +
"OR jd.device_model LIKE concat('%',#{query},'%') " +
"OR jd.device_id LIKE concat('%',#{query},'%') " +
"OR jd.plate_no LIKE concat('%',#{query},'%')" +
")</if> " +
" <if test='online == true' > AND jd.status= true</if>" +
" <if test='online == false' > AND jd.status= false</if>" +
"ORDER BY jd.update_time " +
" </script>"})
List<JTDevice> getDeviceList(@Param("query") String query, @Param("online") Boolean online);
}

View File

@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.codec.netty.Jt808Handler;
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8100;
@@ -9,6 +10,8 @@ import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.Session;
import io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import java.io.UnsupportedEncodingException;
@@ -24,6 +27,7 @@ import java.util.UUID;
@MsgId(id = "0100")
public class J0100 extends Re {
private final static Logger log = LoggerFactory.getLogger(J0100.class);
private JTDevice device;
@Override
@@ -92,10 +96,16 @@ public class J0100 extends Re {
String authenticationCode = UUID.randomUUID().toString();
j8100.setCode(authenticationCode);
deviceInDb.setAuthenticationCode(authenticationCode);
deviceInDb.setStatus(true);
service.updateDevice(deviceInDb);
log.info("[注册成功] 设备: {}", device.getDeviceId());
}else {
log.info("[注册失败] 未授权设备: {}", device.getDeviceId());
j8100.setResult(J8100.FAIL);
// TODO 断开连接,清理资源
// 断开连接,清理资源
if (session.isRegistered()) {
session.unregister();
}
}
return j8100;
}

View File

@@ -1,9 +1,14 @@
package com.genersoft.iot.vmp.jt1078.service;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface Ijt1078Service {
JTDevice getDevice(String devId);
void updateDevice(JTDevice deviceInDb);
PageInfo<JTDevice> getDeviceList(int page, int count, String query, Boolean online);
}

View File

@@ -3,9 +3,14 @@ package com.genersoft.iot.vmp.jt1078.service.impl;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.dao.JTDeviceMapper;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class jt1078ServiceImpl implements Ijt1078Service {
@@ -20,6 +25,14 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override
public void updateDevice(JTDevice device) {
device.setUpdateTime(DateUtil.getNow());
jtDeviceMapper.updateDevice(device);
}
@Override
public PageInfo<JTDevice> getDeviceList(int page, int count, String query, Boolean online) {
PageHelper.startPage(page, count);
List<JTDevice> all = jtDeviceMapper.getDeviceList(query, online);
return new PageInfo<>(all);
}
}

View File

@@ -111,4 +111,9 @@ public class Session {
",ip=" + channel.remoteAddress() +
']';
}
public void unregister() {
channel.close();
SessionManager.INSTANCE.remove(this.devId);
}
}

View File

@@ -124,4 +124,7 @@ public enum SessionManager {
return String.join("_", devId.replaceFirst("^0*", ""), respId, requestNo.toString());
}
public void remove(String devId) {
sessionMap.remove(devId);
}
}

View File

@@ -0,0 +1,322 @@
<template>
<div id="app" style="width: 100%">
<div class="page-header">
<div class="page-title">设备列表</div>
<div class="page-header-btn">
<el-button icon="el-icon-plus" size="mini" style="margin-right: 1rem;" type="primary" @click="add">添加设备
</el-button>
<el-button icon="el-icon-refresh-right" circle size="mini" :loading="getDeviceListLoading"
@click="getDeviceList()"></el-button>
</div>
</div>
<!--设备列表-->
<el-table :data="deviceList" style="width: 100%;font-size: 12px;" :height="winHeight" header-row-class-name="table-header">
<el-table-column prop="provinceId" label="省域ID" min-width="160">
</el-table-column>
<el-table-column prop="cityId" label="市县域ID" min-width="200" >
</el-table-column>
<el-table-column prop="makerId" label="制造商ID" min-width="200" >
</el-table-column>
<el-table-column prop="deviceModel" label="终端型号" min-width="200" >
</el-table-column>
<el-table-column prop="deviceId" label="终端ID" min-width="200" >
</el-table-column>
<el-table-column prop="plateColor" label="车牌颜色" min-width="200" >
</el-table-column>
<el-table-column prop="plateNo" label="车牌" min-width="200" >
</el-table-column>
<el-table-column label="状态" min-width="120">
<template slot-scope="scope">
<div slot="reference" class="name-wrapper">
<el-tag size="medium" v-if="scope.row.status">在线</el-tag>
<el-tag size="medium" type="info" v-if="!scope.row.status">离线</el-tag>
</div>
</template>
</el-table-column>
<el-table-column label="操作" min-width="450" fixed="right">
<template slot-scope="scope">
<el-divider direction="vertical"></el-divider>
<el-button size="medium" icon="el-icon-edit" type="text" @click="edit(scope.row)">编辑</el-button>
<el-divider direction="vertical"></el-divider>
<el-button size="medium" icon="el-icon-delete" type="text" @click="deleteDevice(scope.row)" style="color: #f56c6c">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
style="float: right"
@size-change="handleSizeChange"
@current-change="currentChange"
:current-page="currentPage"
:page-size="count"
:page-sizes="[15, 25, 35, 50]"
layout="total, sizes, prev, pager, next"
:total="total">
</el-pagination>
<deviceEdit ref="deviceEdit"></deviceEdit>
<syncChannelProgress ref="syncChannelProgress"></syncChannelProgress>
</div>
</template>
<script>
import uiHeader from '../layout/UiHeader.vue'
import deviceEdit from './dialog/deviceEdit.vue'
import syncChannelProgress from './dialog/SyncChannelProgress.vue'
export default {
name: 'app',
components: {
uiHeader,
deviceEdit,
syncChannelProgress,
},
data() {
return {
deviceList: [], //设备列表
currentDevice: {}, //当前操作设备对象
videoComponentList: [],
updateLooper: 0, //数据刷新轮训标志
currentDeviceChannelsLenth: 0,
winHeight: window.innerHeight - 200,
currentPage: 1,
count: 15,
total: 0,
getDeviceListLoading: false,
};
},
computed: {
getcurrentDeviceChannels: function () {
let data = this.currentDevice['channelMap'];
let channels = null;
if (data) {
channels = Object.keys(data).map(key => {
return data[key];
});
this.currentDeviceChannelsLenth = channels.length;
}
return channels;
}
},
mounted() {
this.initData();
this.updateLooper = setInterval(this.initData, 10000);
},
destroyed() {
this.$destroy('videojs');
clearTimeout(this.updateLooper);
},
methods: {
initData: function () {
this.getDeviceList();
},
currentChange: function (val) {
this.currentPage = val;
this.getDeviceList();
},
handleSizeChange: function (val) {
this.count = val;
this.getDeviceList();
},
getDeviceList: function () {
this.getDeviceListLoading = true;
this.$axios({
method: 'get',
url: `/api/jt1078/devices`,
params: {
page: this.currentPage,
count: this.count
}
}).then( (res)=> {
if (res.data.code === 0) {
this.total = res.data.data.total;
this.deviceList = res.data.data.list;
}
this.getDeviceListLoading = false;
}).catch( (error)=> {
console.error(error);
this.getDeviceListLoading = false;
});
},
deleteDevice: function (row) {
let msg = "确定删除此设备?"
if (row.online !== 0) {
msg = "在线设备删除后仍可通过注册再次上线。<br/>如需彻底删除请先将设备离线。<br/><strong>确定删除此设备?</strong>"
}
this.$confirm(msg, '提示', {
dangerouslyUseHTMLString: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
center: true,
type: 'warning'
}).then(() => {
this.$axios({
method: 'delete',
url: `/api/device/query/devices/${row.deviceId}/delete`
}).then((res) => {
this.getDeviceList();
}).catch((error) => {
console.error(error);
});
}).catch(() => {
});
},
showChannelList: function (row) {
this.$router.push(`/channelList/${row.deviceId}/0`);
},
showDevicePosition: function (row) {
this.$router.push(`/map?deviceId=${row.deviceId}`);
},
//gb28181平台对接
//刷新设备信息
refDevice: function (itemData) {
console.log("刷新对应设备:" + itemData.deviceId);
let that = this;
this.$axios({
method: 'get',
url: '/api/device/query/devices/' + itemData.deviceId + '/sync'
}).then((res) => {
console.log("刷新设备结果:" + JSON.stringify(res));
if (res.data.code !== 0) {
that.$message({
showClose: true,
message: res.data.msg,
type: 'error'
});
} else {
// that.$message({
// showClose: true,
// message: res.data.msg,
// type: 'success'
// });
this.$refs.syncChannelProgress.openDialog(itemData.deviceId)
}
that.initData()
}).catch((e) => {
console.error(e)
that.$message({
showClose: true,
message: e,
type: 'error'
});
});
},
getTooltipContent: async function (deviceId) {
let result = "";
await this.$axios({
method: 'get',
async: false,
url: `/api/device/query/${deviceId}/sync_status/`,
}).then((res) => {
if (res.data.code == 0) {
if (res.data.data.errorMsg !== null) {
result = res.data.data.errorMsg
} else if (res.data.msg !== null) {
result = res.data.msg
} else {
result = `同步中...[${res.data.data.current}/${res.data.data.total}]`;
}
}
})
return result;
},
transportChange: function (row) {
console.log(`修改传输方式为 ${row.streamMode}${row.deviceId} `);
let that = this;
this.$axios({
method: 'post',
url: '/api/device/query/transport/' + row.deviceId + '/' + row.streamMode
}).then(function (res) {
}).catch(function (e) {
});
},
edit: function (row) {
this.$refs.deviceEdit.openDialog(row, () => {
this.$refs.deviceEdit.close();
this.$message({
showClose: true,
message: "设备修改成功,通道字符集将在下次更新生效",
type: "success",
});
setTimeout(this.getDeviceList, 200)
})
},
add: function () {
this.$refs.deviceEdit.openDialog(null, () => {
this.$refs.deviceEdit.close();
this.$message({
showClose: true,
message: "添加成功",
type: "success",
});
setTimeout(this.getDeviceList, 200)
})
}
}
};
</script>
<style>
.videoList {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
}
.video-item {
position: relative;
width: 15rem;
height: 10rem;
margin-right: 1rem;
background-color: #000000;
}
.video-item-img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
height: 100%;
}
.video-item-img:after {
content: "";
display: inline-block;
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 3rem;
height: 3rem;
background-image: url("../assets/loading.png");
background-size: cover;
background-color: #000000;
}
.video-item-title {
position: absolute;
bottom: 0;
color: #000000;
background-color: #ffffff;
line-height: 1.5rem;
padding: 0.3rem;
width: 14.4rem;
}
</style>

View File

@@ -7,6 +7,7 @@
<el-menu-item index="/console">控制台</el-menu-item>
<el-menu-item index="/live">分屏监控</el-menu-item>
<el-menu-item index="/deviceList">国标设备</el-menu-item>
<el-menu-item index="/jtDeviceList">部标设备</el-menu-item>
<el-menu-item index="/map">电子地图</el-menu-item>
<el-menu-item index="/pushVideoList">推流列表</el-menu-item>
<el-menu-item index="/streamProxyList">拉流代理</el-menu-item>

View File

@@ -4,6 +4,7 @@ import Layout from "../layout/index.vue"
import console from '../components/console.vue'
import deviceList from '../components/DeviceList.vue'
import jtDeviceList from '../components/JTDeviceList.vue'
import channelList from '../components/channelList.vue'
import gbRecordDetail from '../components/GBRecordDetail.vue'
import pushVideoList from '../components/PushVideoList.vue'
@@ -53,6 +54,10 @@ export default new VueRouter({
path: '/deviceList',
component: deviceList,
},
{
path: '/jtDeviceList',
component: jtDeviceList,
},
{
path: '/pushVideoList',
component: pushVideoList,