Skip to content

Commit

Permalink
feat: 完成搜索页面展示
Browse files Browse the repository at this point in the history
  • Loading branch information
eddie murphy committed Nov 10, 2023
1 parent 05c773b commit f8f9af5
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ run:
--name sipgrep-go \
harbor:5000/wecloud/sipgrep-go:$(image_name)
t1:
http --verbose localhost:3000/api/v1/call BeginTime=="2023-10-31 00:00:00" EndTime=="2023-10-31 23:59:59"
http --verbose localhost:3000/api/v1/call BeginTime=="2023-11-05 00:00:00" EndTime=="2023-11-05 23:59:59"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"antd": "^5.10.2",
"axios": "^1.6.0",
"dayjs": "^1.11.10",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
89 changes: 41 additions & 48 deletions pkg/mysql/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,32 @@ const MaxUserAgentLength = 40

type Record struct {
// ID string `gorm:"type:char(22);not null;default ''"`
SipCallid string `gorm:"index;type:char(64);not null;default:''"`
SipMethod string `gorm:"index;type:char(20);not null;default:''"`
CreateTime time.Time `gorm:"index;type:datetime;not null;default:CURRENT_TIMESTAMP"`
ToUser string `gorm:"index;type:char(40);not null;default:''"`
LegUid string `gorm:"index;type:char(64);not null;default:''"`
FromUser string `gorm:"index;type:char(40);not null;default:''"`

FsCallid string `gorm:"type:char(64);not null; default:''"`

ResponseCode int `gorm:"type:int(11);not null;default:0"`
ResponseDesc string `gorm:"type:char(64);not null;default:''"`
CseqMethod string `gorm:"type:char(20);not null;default:''"`
CseqNumber int `gorm:"type:int(11);not null;default:0"`

FromHost string `gorm:"type:char(64);not null;default:''"`
ToHost string `gorm:"type:char(64);not null;default:''"`
SipProtocol uint `gorm:"type:int(11);not null;default:0"`
IsRequest uint `gorm:"type:int(11);not null;default:0"`
UserAgent string `gorm:"type:char(40);not null;default:''"`
SrcHost string `gorm:"type:char(32);not null;default:''"`
DstHost string `gorm:"type:char(32);not null;default:''"`
TimestampMicro uint32 `gorm:"type:int(11);not null;default:0"`
RawMsg string `gorm:"type:text;not null"`
SIPCallID string `gorm:"column:sip_call_id;index;type:char(64);not null;default:''"`
SIPMethod string `gorm:"column:sip_method;index;type:char(20);not null;default:''"`
CreateTime time.Time `gorm:"column:create_time;index;type:datetime;not null;default:CURRENT_TIMESTAMP"`
ToUser string `gorm:"column:to_user;index;type:char(40);not null;default:''"`
LegUid string `gorm:"column:leg_uid;index;type:char(64);not null;default:''"`
FromUser string `gorm:"column:from_user;index;type:char(40);not null;default:''"`

FsCallID string `gorm:"column:fs_call_id;type:char(64);not null; default:''"`

ResponseCode int `gorm:"column:response_code;type:int(11);not null;default:0"`
ResponseDesc string `gorm:"column:response_desc;type:char(64);not null;default:''"`
CSeqMethod string `gorm:"column:cseq_method;type:char(20);not null;default:''"`
CSeqNumber int `gorm:"column:cseq_number;type:int(11);not null;default:0"`

FromHost string `gorm:"column:from_host;type:char(64);not null;default:''"`
ToHost string `gorm:"column:to_host;type:char(64);not null;default:''"`
SIPProtocol uint `gorm:"column:sip_protocol;type:int(11);not null;default:0"`
UserAgent string `gorm:"column:user_agent;type:char(40);not null;default:''"`
SrcHost string `gorm:"column:src_host;type:char(32);not null;default:''"`
DstHost string `gorm:"column:dst_host;type:char(32);not null;default:''"`
TimestampMicro uint32 `gorm:"column:timestamp_micro;type:int(11);not null;default:0"`
RawMsg string `gorm:"column:raw_msg;type:text;not null"`
}

type CallTable struct {
Meta Record
Record
MsgCount int
}

Expand Down Expand Up @@ -81,33 +80,27 @@ func BatchSaveInit() {

func Save(s *models.SIP) {
ua := s.UserAgent
isRequest := 0

if len(ua) > MaxUserAgentLength {
ua = ua[:MaxUserAgentLength]
}

if s.IsRequest {
isRequest = 1
}

RawMsg := *s.Raw

item := Record{
FsCallid: s.FSCallID,
FsCallID: s.FSCallID,
LegUid: s.UID,
SipMethod: s.Title,
SIPMethod: s.Title,
ResponseCode: s.ResponseCode,
ResponseDesc: s.ResponseDesc,
CseqMethod: s.CSeqMethod,
CseqNumber: s.CSeqNumber,
CSeqMethod: s.CSeqMethod,
CSeqNumber: s.CSeqNumber,
FromUser: s.FromUsername,
FromHost: s.FromDomain,
ToUser: util.ReverseString(s.ToUsername), // 被叫号码翻转后存储, 方便查询时不需要加前缀
ToHost: s.ToDomain,
SipCallid: s.CallID,
IsRequest: uint(isRequest),
SipProtocol: uint(s.Protocol),
SIPCallID: s.CallID,
SIPProtocol: uint(s.Protocol),
UserAgent: ua,
SrcHost: s.SrcAddr,
DstHost: s.DstAddr,
Expand Down Expand Up @@ -163,18 +156,18 @@ func Search(sql string) ([]CallTable, error) {
item := CallTable{}

err := rows.Scan(
&item.Meta.SipCallid,
&item.Meta.CreateTime,
&item.Meta.FromUser,
&item.Meta.FromHost,
&item.Meta.ToUser,
&item.Meta.ToHost,
&item.Meta.UserAgent,
&item.Meta.SipProtocol,
&item.Meta.SipMethod,
&item.Meta.CseqMethod,
&item.Meta.FsCallid,
&item.Meta.LegUid,
&item.SIPCallID,
&item.CreateTime,
&item.FromUser,
&item.FromHost,
&item.ToUser,
&item.ToHost,
&item.UserAgent,
&item.SIPProtocol,
&item.SIPMethod,
&item.CSeqMethod,
&item.FsCallID,
&item.LegUid,
&item.MsgCount,
)

Expand Down
14 changes: 7 additions & 7 deletions pkg/mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var SearchFields = []string{
"sip_callid",
"sip_call_id",
"create_time",
"from_user",
"from_host",
Expand All @@ -19,7 +19,7 @@ var SearchFields = []string{
"sip_protocol",
"sip_method",
"cseq_method",
"fs_callid",
"fs_call_Id",
"leg_uid",
"count(*) as msg_count",
}
Expand Down Expand Up @@ -56,7 +56,7 @@ func GetSearchSql(sp SearchParams) string {
conditions = append(conditions, fmt.Sprintf("from_host='%s'", sp.CallerDomain))
}
if sp.Callee != "" {
conditions = append(conditions, fmt.Sprintf("to_user='%s'", sp.Callee))
conditions = append(conditions, fmt.Sprintf("to_user like '%s'%%", sp.Callee))
}
if sp.CalleeDomain != "" {
conditions = append(conditions, fmt.Sprintf("to_host='%s'", sp.CalleeDomain))
Expand All @@ -66,13 +66,13 @@ func GetSearchSql(sp SearchParams) string {
conds := strings.Join(conditions, ",")
tableName := GetTableName(sp.BeginTime)

sql := fmt.Sprintf(`select %s from %s where sip_callid in (
select sip_callid from (
select distinct sip_callid from %s where %s
sql := fmt.Sprintf(`select %s from %s where sip_call_id in (
select sip_call_id from (
select distinct sip_call_id from %s where %s
limit %d
) tmp
)
group by sip_callid order by create_time desc`, columns, tableName, tableName, conds, env.Conf.PageLimit)
group by sip_call_id order by create_time desc`, columns, tableName, tableName, conds, env.Conf.PageLimit)

return sql
}
64 changes: 64 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,18 @@ import { FieldType, SearchForm } from './SearchFrom'
import SearchTable from './SearchTable'
import { useState } from 'react'
import { DataType } from './interface'
import axios from 'axios'

function App() {
const [calls, setCalls] = useState<DataType[]>([
{
time: '2010-10-10 10:10:10',
callerNo: '8001',
callerDomain: 'test.cc',
calleeNo: '8002',
calleeDomain: 'test.cc',
userAgent: 'MicroSIP',
sipCallID: '8389238293800990',
msgCount: 10,
},
])
const [calls, setCalls] = useState<DataType[]>([])

function Search(ft: FieldType) {
console.log('app', ft)
console.log(ft.timePicker)

const query = {
BeginTime: ft.datePicker.format('YYYY-MM-DD') + ' ' + ft.timePicker[0].format('HH:mm:ss'),
EndTime: ft.datePicker.format('YYYY-MM-DD') + ' ' + ft.timePicker[0].format('HH:mm:ss'),
EndTime: ft.datePicker.format('YYYY-MM-DD') + ' ' + ft.timePicker[1].format('HH:mm:ss'),
Caller: !!ft.caller ? ft.caller : undefined,
CallerDomain: ft.callerDomain,
// 被叫号码取反存储
Expand All @@ -33,6 +23,14 @@ function App() {
}

console.log(query)
axios
.get('/api/v1/call', {
params: query,
})
.then((res) => {
setCalls(res.data)
})
.catch()
}

return (
Expand Down
Loading

0 comments on commit f8f9af5

Please sign in to comment.