Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
golang-queue-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
acfcbd1c
authored
Feb 02, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
fix
parents
2a281977
6d7b4d4a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
75 deletions
special/activity_view_statistics/logs/2021-02-02.log
special/activity_view_statistics/logs/2021-02-02.log.wf
special/activity_view_statistics/main.go
special/activity_view_statistics/logs/2021-02-02.log
0 → 100644
View file @
acfcbd1c
File mode changed
special/activity_view_statistics/logs/2021-02-02.log.wf
0 → 100644
View file @
acfcbd1c
2021-02-02 11:31:02.644 ERROR (main.go:main.(*RecvPro).Consumer:208) not found
2021-02-02 11:33:00.958 ERROR (main.go:main.(*RecvPro).Consumer:208) not found
2021-02-02 11:38:52.737 ERROR (main.go:main.(*RecvPro).Consumer:208) not found
2021-02-02 11:39:28.825 ERROR (main.go:main.(*RecvPro).Consumer:211) not found
2021-02-02 11:39:30.882 ERROR (main.go:main.(*RecvPro).Consumer:211) not found
2021-02-02 11:39:32.436 ERROR (main.go:main.(*RecvPro).Consumer:211) not found
2021-02-02 11:39:53.796 ERROR (main.go:main.(*RecvPro).Consumer:213) not found
2021-02-02 11:41:37.89 ERROR (main.go:main.(*RecvPro).Consumer:208) not found
special/activity_view_statistics/main.go
View file @
acfcbd1c
...
...
@@ -78,43 +78,70 @@ type RecvPro struct {
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
var
viewData
model
.
ViewData
//fmt.Println(string(dataByte))
if
err
=
json
.
Unmarshal
(
dataByte
,
&
view
Data
);
err
!=
nil
{
//获取队列数据
var
rbmqData
model
.
ViewData
if
err
=
json
.
Unmarshal
(
dataByte
,
&
rbmq
Data
);
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
return
}
//先去遍历数据库,全部过一遍
if
rbmqData
.
ActivityId
==
0
{
return
nil
}
var
(
historyData
model
.
HistoryData
mongoHistory
model
.
HistoryData
whereMap
map
[
string
]
interface
{}
)
//先去mongo查找
//if viewData.UserId != 0 {
// whereMap = bson.M{"activity_id": viewData.ActivityId, "user_id": viewData.UserId}
//} else {
whereMap
=
bson
.
M
{
"activity_id"
:
viewData
.
ActivityId
,
"unique_id"
:
viewData
.
UniqueId
}
//}
//先去mongo查找有没有存在的记录,unique_id是由3.0写到cookie的,过期时间为1年
whereMap
=
bson
.
M
{
"activity_id"
:
rbmqData
.
ActivityId
,
"unique_id"
:
rbmqData
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Find
(
whereMap
)
.
One
(
&
historyData
)
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
Find
(
whereMap
)
.
One
(
&
mongoHistory
)
//先去获取用户相关信息
var
(
mobile
string
isNewReg
int
adTag
string
)
if
rbmqData
.
UserId
!=
0
{
//找出用户相关的信息
var
user
model
.
UserMain
err
=
db
.
Reset
()
.
Table
(
&
user
)
.
Where
(
"user_id"
,
rbmqData
.
UserId
)
.
Select
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
return
}
//mysql数据操作
var
result
model
.
ActivityViewStatistics
err
=
specialDb
.
Reset
()
.
Table
(
&
result
)
.
Where
(
"activity_id"
,
viewData
.
ActivityId
)
.
Select
()
mobile
=
user
.
Mobile
adTag
=
user
.
RegRemark
//再去判断是否是这个活动注册的用户
var
userActivity
model
.
UserActivity
count
,
err
:=
db
.
Reset
()
.
Table
(
&
userActivity
)
.
Where
(
"activity_id"
,
rbmqData
.
ActivityId
)
.
Where
(
"user_id"
,
rbmqData
.
UserId
)
.
Count
()
if
err
!=
nil
{
fmt
.
Println
(
"110"
,
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
}
if
count
!=
0
{
isNewReg
=
1
}
}
//如果rbmq传过来的数据在mongo里面找不到,先去数据库查找活动是否存在
var
statistics
model
.
ActivityViewStatistics
err
=
specialDb
.
Reset
()
.
Table
(
&
statistics
)
.
Where
(
"activity_id"
,
rbmqData
.
ActivityId
)
.
Select
()
//活动不存在,则往数据库插入一条新的统计
if
statistics
.
ActivityId
==
0
{
var
loginNum
,
regNum
int
if
rbmqData
.
UserId
!=
0
{
loginNum
=
1
if
isNewReg
==
1
{
regNum
=
1
}
}
if
result
.
ActivityId
==
0
{
//先去数据库插入
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
ActivityId
:
view
Data
.
ActivityId
,
RegNum
:
0
,
LoginNum
:
0
,
ActivityId
:
rbmq
Data
.
ActivityId
,
RegNum
:
regNum
,
LoginNum
:
loginNum
,
CreateTime
:
int
(
time
.
Now
()
.
Unix
()),
}
_
,
err
=
specialDb
.
Reset
()
.
Table
(
"lie_activity_view_statistics"
)
.
Data
(
activityViewStatistics
)
.
Insert
()
...
...
@@ -124,19 +151,24 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
return
}
}
else
{
loginNum
:=
result
.
LoginNum
regNum
:=
result
.
RegNum
if
viewData
.
UserId
!=
0
{
loginNum
:=
statistics
.
LoginNum
regNum
:=
statistics
.
RegNum
//如果已经存在的mongo记录里面,已经存在了unique_id,但是user_id为空,同时新传过来的rbmq的数据的user_id不为空,就代表这个用户
//从未登录变成了登陆态,该活动的登陆人数+1,同时去判断该用户是否是这个活动注册的用户
if
mongoHistory
.
UserId
==
0
&&
rbmqData
.
UserId
!=
0
{
loginNum
++
if
isNewReg
==
1
{
regNum
++
}
}
//存在则去更新
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
ActivityId
:
view
Data
.
ActivityId
,
ActivityId
:
rbmq
Data
.
ActivityId
,
RegNum
:
regNum
,
LoginNum
:
loginNum
,
UpdateTime
:
int
(
time
.
Now
()
.
Unix
()),
}
_
,
err
=
specialDb
.
Reset
()
.
Table
(
"lie_activity_view_statistics"
)
.
Where
(
"activity_id"
,
view
Data
.
ActivityId
)
.
_
,
err
=
specialDb
.
Reset
()
.
Table
(
"lie_activity_view_statistics"
)
.
Where
(
"activity_id"
,
rbmq
Data
.
ActivityId
)
.
Data
(
activityViewStatistics
)
.
Update
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
...
...
@@ -144,68 +176,41 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
return
}
}
//如果mongo存在,更新mongo数据
if
historyData
.
UserId
!=
0
{
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
selector
:=
bson
.
M
{
"unique_id"
:
historyData
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
historyData
)
//如果已经存在的mongo记录里面,已经存在了unique_id,但是user_id为空,同时新传过来的rbmq的数据的user_id不为空
//此时只需要去更新mongo对应这条记录的user_id,mobile等信息
if
mongoHistory
.
UserId
!=
0
{
mongoHistory
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
selector
:=
bson
.
M
{
"unique_id"
:
mongoHistory
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
mongoHistory
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
}
}
else
{
var
(
mobile
string
isNewReg
int
adTag
string
)
if
viewData
.
UserId
!=
0
{
//找出用户相关的信息
var
user
model
.
UserMain
err
=
db
.
Reset
()
.
Table
(
&
user
)
.
Where
(
"user_id"
,
viewData
.
UserId
)
.
Select
()
if
err
!=
nil
{
fmt
.
Println
(
"用户相关的信息为空 : "
,
err
)
logger
.
Error
(
err
.
Error
())
}
mobile
=
user
.
Mobile
adTag
=
user
.
RegRemark
//再去判断是否是这个活动注册的用户
var
userActivity
model
.
UserActivity
count
,
err
:=
db
.
Reset
()
.
Table
(
&
userActivity
)
.
Where
(
"activity_id"
,
viewData
.
ActivityId
)
.
Where
(
"user_id"
,
viewData
.
UserId
)
.
Count
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
}
if
count
!=
0
{
isNewReg
=
1
}
}
historyData
:=
model
.
HistoryData
{
UniqueId
:
viewData
.
UniqueId
,
ActivityId
:
viewData
.
ActivityId
,
newData
:=
model
.
HistoryData
{
UniqueId
:
rbmqData
.
UniqueId
,
ActivityId
:
rbmqData
.
ActivityId
,
Mobile
:
mobile
,
UserId
:
view
Data
.
UserId
,
UserId
:
rbmq
Data
.
UserId
,
IsNewReg
:
isNewReg
,
AdTag
:
adTag
,
Source
:
view
Data
.
Source
,
VisitTime
:
view
Data
.
VisitTime
,
LastVisitTime
:
0
,
Pf
:
view
Data
.
Pf
,
Source
:
rbmq
Data
.
Source
,
VisitTime
:
rbmq
Data
.
VisitTime
,
LastVisitTime
:
int
(
time
.
Now
()
.
Unix
())
,
Pf
:
rbmq
Data
.
Pf
,
}
if
historyData
.
UniqueId
==
""
{
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Insert
(
&
history
Data
)
if
mongoHistory
.
UniqueId
==
""
{
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Insert
(
&
new
Data
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
}
}
else
{
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
selector
:=
bson
.
M
{
"unique_id"
:
historyData
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
historyData
)
selector
:=
bson
.
M
{
"unique_id"
:
mongoHistory
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
newData
)
if
err
!=
nil
{
fmt
.
Println
(
"205"
,
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment