Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
e52b4520
物
物联大师
项目概览
rudern
/
物联大师
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
物
物联大师
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e52b4520
编写于
9月 01, 2020
作者:
J
Jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
将link保存到数据库中,记录 通道ID,方便查询状态,操作等
上级
3212e368
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
225 addition
and
24 deletion
+225
-24
dtu/channel.go
dtu/channel.go
+16
-9
dtu/link.go
dtu/link.go
+1
-2
dtu/misc.go
dtu/misc.go
+0
-1
portal/src/app/main/link-detail/link-detail.component.ts
portal/src/app/main/link-detail/link-detail.component.ts
+5
-2
portal/src/app/main/link-edit/link-edit.component.html
portal/src/app/main/link-edit/link-edit.component.html
+1
-0
portal/src/app/main/link-edit/link-edit.component.scss
portal/src/app/main/link-edit/link-edit.component.scss
+0
-0
portal/src/app/main/link-edit/link-edit.component.ts
portal/src/app/main/link-edit/link-edit.component.ts
+17
-0
portal/src/app/main/link/link.component.html
portal/src/app/main/link/link.component.html
+42
-1
portal/src/app/main/link/link.component.ts
portal/src/app/main/link/link.component.ts
+39
-2
portal/src/app/main/main.module.ts
portal/src/app/main/main.module.ts
+2
-1
types/link.go
types/link.go
+14
-0
web/api/connection.go
web/api/connection.go
+0
-1
web/api/link.go
web/api/link.go
+76
-0
web/api/router.go
web/api/router.go
+12
-5
未找到文件。
dtu/channel.go
浏览文件 @
e52b4520
...
@@ -3,10 +3,12 @@ package dtu
...
@@ -3,10 +3,12 @@ package dtu
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"github.com/zgwit/dtu-admin/storage"
"github.com/zgwit/dtu-admin/types"
"github.com/zgwit/dtu-admin/types"
"log"
"log"
"net"
"net"
"sync"
"sync"
"time"
)
)
...
@@ -16,13 +18,12 @@ type Channel struct {
...
@@ -16,13 +18,12 @@ type Channel struct {
Error
string
Error
string
listener
net
.
Listener
listener
net
.
Listener
packetConn
net
.
PacketConn
packetConn
net
.
PacketConn
packetIndexes
sync
.
Map
links
sync
.
Map
packetIndexes
sync
.
Map
//<Link>
//自增ID
links
sync
.
Map
increment
int64
}
}
func
NewChannel
(
channel
*
types
.
Channel
)
*
Channel
{
func
NewChannel
(
channel
*
types
.
Channel
)
*
Channel
{
...
@@ -110,7 +111,7 @@ func (c *Channel) accept() {
...
@@ -110,7 +111,7 @@ func (c *Channel) accept() {
func
(
c
*
Channel
)
receive
(
conn
net
.
Conn
)
{
func
(
c
*
Channel
)
receive
(
conn
net
.
Conn
)
{
client
:=
newConnection
(
conn
)
client
:=
newConnection
(
conn
)
client
.
channel
=
c
client
.
channel
=
c
c
.
store
Connection
(
client
)
c
.
store
Link
(
client
)
buf
:=
make
([]
byte
,
1024
)
buf
:=
make
([]
byte
,
1024
)
for
client
.
conn
!=
nil
{
for
client
.
conn
!=
nil
{
...
@@ -126,9 +127,15 @@ func (c *Channel) receive(conn net.Conn) {
...
@@ -126,9 +127,15 @@ func (c *Channel) receive(conn net.Conn) {
}
}
func
(
c
*
Channel
)
storeConnection
(
conn
*
Link
)
{
func
(
c
*
Channel
)
storeLink
(
conn
*
Link
)
{
c
.
increment
++
conn
.
ID
=
c
.
increment
lnk
:=
types
.
Link
{
Addr
:
conn
.
RemoteAddr
.
String
(),
Channel
:
c
.
ID
,
Created
:
time
.
Now
(),
}
storage
.
DB
(
"link"
)
.
Save
(
&
lnk
)
//根据ID保存
//根据ID保存
c
.
links
.
Store
(
c
.
ID
,
conn
)
c
.
links
.
Store
(
c
.
ID
,
conn
)
...
@@ -155,7 +162,7 @@ func (c *Channel) receivePacket() {
...
@@ -155,7 +162,7 @@ func (c *Channel) receivePacket() {
client
.
channel
=
c
client
.
channel
=
c
//根据ID保存
//根据ID保存
c
.
store
Connection
(
client
)
c
.
store
Link
(
client
)
//根据地址保存,收到UDP包之后,方便索引
//根据地址保存,收到UDP包之后,方便索引
c
.
packetIndexes
.
Store
(
key
,
client
)
c
.
packetIndexes
.
Store
(
key
,
client
)
...
...
dtu/link.go
浏览文件 @
e52b4520
...
@@ -45,8 +45,7 @@ func (l *Link) checkRegister(buf []byte) error {
...
@@ -45,8 +45,7 @@ func (l *Link) checkRegister(buf []byte) error {
}
}
}
}
//按序号保存索引,供外部使用
//TODO 更新数据库中 serial
connections
.
Store
(
serial
,
l
)
return
nil
return
nil
}
}
...
...
dtu/misc.go
浏览文件 @
e52b4520
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
var
channels
sync
.
Map
var
channels
sync
.
Map
var
connections
sync
.
Map
func
Channels
()
[]
*
Channel
{
func
Channels
()
[]
*
Channel
{
cs
:=
make
([]
*
Channel
,
0
)
cs
:=
make
([]
*
Channel
,
0
)
...
...
portal/src/app/main/link-detail/link-detail.component.ts
浏览文件 @
e52b4520
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Component
,
Input
,
OnInit
}
from
'
@angular/core
'
;
@
Component
({
@
Component
({
selector
:
'
app-link-detail
'
,
selector
:
'
app-link-detail
'
,
...
@@ -7,7 +7,10 @@ import { Component, OnInit } from '@angular/core';
...
@@ -7,7 +7,10 @@ import { Component, OnInit } from '@angular/core';
})
})
export
class
LinkDetailComponent
implements
OnInit
{
export
class
LinkDetailComponent
implements
OnInit
{
constructor
()
{
}
@
Input
()
link
:
any
=
{};
constructor
()
{
}
ngOnInit
():
void
{
ngOnInit
():
void
{
}
}
...
...
portal/src/app/main/link-edit/link-edit.component.html
0 → 100644
浏览文件 @
e52b4520
<p>
link-edit works!
</p>
portal/src/app/main/link-edit/link-edit.component.scss
0 → 100644
浏览文件 @
e52b4520
portal/src/app/main/link-edit/link-edit.component.ts
0 → 100644
浏览文件 @
e52b4520
import
{
Component
,
Input
,
OnInit
}
from
'
@angular/core
'
;
@
Component
({
selector
:
'
app-link-edit
'
,
templateUrl
:
'
./link-edit.component.html
'
,
styleUrls
:
[
'
./link-edit.component.scss
'
]
})
export
class
LinkEditComponent
implements
OnInit
{
@
Input
()
link
:
any
=
{};
constructor
()
{
}
ngOnInit
():
void
{
}
}
portal/src/app/main/link/link.component.html
浏览文件 @
e52b4520
<p>
link works!
</p>
<nz-space>
<nz-space-item>
<button
nz-button
(click)=
"load()"
>
<i
nz-icon
nzType=
"reload"
></i>
刷新
</button>
</nz-space-item>
</nz-space>
<nz-table
#basicTable
[nzData]=
"links"
>
<thead>
<tr>
<th>
ID
</th>
<th>
名称
</th>
<th>
序列号
</th>
<th>
地址
</th>
<th>
状态
</th>
<th>
创建时间
</th>
<th></th>
</tr>
</thead>
<tbody>
<tr
*ngFor=
"let data of basicTable.data"
>
<td>
{{ data.id }}
</td>
<td>
{{ data.name }}
</td>
<td>
{{ data.serial }}
</td>
<td>
{{ data.addr}}
</td>
<td>
</td>
<td>
{{ data.created | amDateFormat:'YYYY-MM-DD HH:mm:ss' }}
</td>
<td>
<a>
<i
nz-icon
nzType=
"delete"
></i>
</a>
<nz-divider
nzType=
"vertical"
></nz-divider>
<a
(click)=
"edit(data)"
>
<i
nz-icon
nzType=
"edit"
></i>
</a>
</td>
</tr>
</tbody>
</nz-table>
portal/src/app/main/link/link.component.ts
浏览文件 @
e52b4520
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Component
,
OnInit
,
ViewContainerRef
}
from
'
@angular/core
'
;
import
{
ApiService
}
from
"
../../api.service
"
;
import
{
NzDrawerService
,
NzModalService
}
from
"
ng-zorro-antd
"
;
import
{
LinkEditComponent
}
from
"
../link-edit/link-edit.component
"
;
import
{
LinkDetailComponent
}
from
"
../link-detail/link-detail.component
"
;
@
Component
({
@
Component
({
selector
:
'
app-link
'
,
selector
:
'
app-link
'
,
...
@@ -6,10 +10,43 @@ import { Component, OnInit } from '@angular/core';
...
@@ -6,10 +10,43 @@ import { Component, OnInit } from '@angular/core';
styleUrls
:
[
'
./link.component.scss
'
]
styleUrls
:
[
'
./link.component.scss
'
]
})
})
export
class
LinkComponent
implements
OnInit
{
export
class
LinkComponent
implements
OnInit
{
links
:
[];
constructor
()
{
}
constructor
(
private
as
:
ApiService
,
private
drawer
:
NzDrawerService
)
{
}
ngOnInit
():
void
{
ngOnInit
():
void
{
this
.
load
();
}
load
():
void
{
this
.
as
.
get
(
'
links
'
).
subscribe
(
res
=>
{
if
(
res
.
ok
)
{
this
.
links
=
res
.
data
;
}
});
}
}
edit
(
l
?):
void
{
this
.
drawer
.
create
({
nzTitle
:
l
?
'
编辑
'
:
'
创建
'
,
nzMaskClosable
:
false
,
nzWidth
:
500
,
nzContent
:
LinkEditComponent
,
nzContentParams
:
{
link
:
l
||
{}
}
});
}
detail
(
l
):
void
{
this
.
drawer
.
create
({
nzTitle
:
'
详情
'
,
// nzWidth: 400,
nzContent
:
LinkDetailComponent
,
nzContentParams
:
{
link
:
l
}
});
}
}
}
portal/src/app/main/main.module.ts
浏览文件 @
e52b4520
...
@@ -32,12 +32,13 @@ import {LinkDetailComponent} from './link-detail/link-detail.component';
...
@@ -32,12 +32,13 @@ import {LinkDetailComponent} from './link-detail/link-detail.component';
import
{
UserEditComponent
}
from
'
./user-edit/user-edit.component
'
;
import
{
UserEditComponent
}
from
'
./user-edit/user-edit.component
'
;
import
{
LinkMonitorComponent
}
from
'
./link-monitor/link-monitor.component
'
;
import
{
LinkMonitorComponent
}
from
'
./link-monitor/link-monitor.component
'
;
import
{
NzSpaceModule
}
from
"
ng-zorro-antd/space
"
;
import
{
NzSpaceModule
}
from
"
ng-zorro-antd/space
"
;
import
{
LinkEditComponent
}
from
"
./link-edit/link-edit.component
"
;
@
NgModule
({
@
NgModule
({
declarations
:
[
MainComponent
,
DashComponent
,
declarations
:
[
MainComponent
,
DashComponent
,
ChannelComponent
,
ChannelDetailComponent
,
ChannelEditComponent
,
ChannelComponent
,
ChannelDetailComponent
,
ChannelEditComponent
,
LinkComponent
,
LinkDetailComponent
,
LinkMonitorComponent
,
LinkComponent
,
LinkDetailComponent
,
LinkMonitorComponent
,
LinkEditComponent
,
UserComponent
,
UserEditComponent
,
UserComponent
,
UserEditComponent
,
PasswordComponent
],
PasswordComponent
],
imports
:
[
imports
:
[
...
...
types/link.go
0 → 100644
浏览文件 @
e52b4520
package
types
import
(
"time"
)
type
Link
struct
{
ID
int
`storm:"increment" json:"id"`
Name
string
`json:"name"`
Serial
string
`json:"serial" storm:"index"`
Addr
string
`json:"addr"`
Channel
int
`json:"channel"`
Created
time
.
Time
`json:"created"`
}
web/api/connection.go
已删除
100644 → 0
浏览文件 @
3212e368
package
api
web/api/link.go
0 → 100644
浏览文件 @
e52b4520
package
api
import
(
"github.com/gin-gonic/gin"
"github.com/zgwit/dtu-admin/storage"
"github.com/zgwit/dtu-admin/types"
"log"
)
func
links
(
ctx
*
gin
.
Context
)
{
var
cs
[]
types
.
Link
err
:=
storage
.
DB
(
"link"
)
.
All
(
&
cs
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
replyOk
(
ctx
,
cs
)
}
func
linkDelete
(
ctx
*
gin
.
Context
)
{
var
pid
paramId
if
err
:=
ctx
.
BindUri
(
&
pid
);
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
err
:=
storage
.
DB
(
"link"
)
.
DeleteStruct
(
&
types
.
Link
{
ID
:
pid
.
Id
})
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 删除服务
replyOk
(
ctx
,
nil
)
}
func
linkModify
(
ctx
*
gin
.
Context
)
{
var
link
types
.
Link
if
err
:=
ctx
.
ShouldBindJSON
(
&
link
);
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
log
.
Println
(
"update"
,
link
)
//TODO 不能全部字段更新,应该先取值,修改,再存入
err
:=
storage
.
DB
(
"link"
)
.
Update
(
&
link
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 重新启动服务
replyOk
(
ctx
,
link
)
}
func
linkGet
(
ctx
*
gin
.
Context
)
{
var
pid
paramId
if
err
:=
ctx
.
BindUri
(
&
pid
);
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
var
link
types
.
Link
err
:=
storage
.
DB
(
"link"
)
.
One
(
"ID"
,
pid
.
Id
,
&
link
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
replyOk
(
ctx
,
link
)
}
web/api/router.go
浏览文件 @
e52b4520
...
@@ -57,11 +57,18 @@ func RegisterRoutes(app *gin.RouterGroup) {
...
@@ -57,11 +57,18 @@ func RegisterRoutes(app *gin.RouterGroup) {
app
.
GET
(
"/channel/:id/start"
,
channelStart
)
app
.
GET
(
"/channel/:id/start"
,
channelStart
)
app
.
GET
(
"/channel/:id/stop"
,
channelStop
)
app
.
GET
(
"/channel/:id/stop"
,
channelStop
)
app
.
GET
(
"/channel/:id/connections"
)
app
.
GET
(
"/channel/:id/links"
)
app
.
POST
(
"/channel/:id/connections"
)
app
.
POST
(
"/channel/:id/links"
)
app
.
DELETE
(
"/channel/:id/connection/:id2"
)
//关闭连接
app
.
DELETE
(
"/channel/:id/link/:id2"
)
//关闭连接
app
.
GET
(
"/channel/:id/connection/:id2/statistic"
)
app
.
GET
(
"/channel/:id/link/:id2/statistic"
)
app
.
GET
(
"/channel/:id/connection/:id2/pipe"
)
//转Websocket透传
app
.
GET
(
"/channel/:id/link/:id2/pipe"
)
//转Websocket透传
app
.
GET
(
"/links"
,
links
)
app
.
DELETE
(
"/link/:id"
,
linkDelete
)
app
.
PUT
(
"/link/:id"
,
linkModify
)
app
.
GET
(
"/link/:id"
,
linkGet
)
//app.GET("/link/:id/watch", linkWatch)
//app.GET("/link/:id/stop", linkStop)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录