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
6d7b4d4a
authored
Feb 02, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复统计错误
parent
9eae0dd2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
76 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 @
6d7b4d4a
File mode changed
special/activity_view_statistics/logs/2021-02-02.log.wf
0 → 100644
View file @
6d7b4d4a
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 @
6d7b4d4a
...
@@ -78,40 +78,70 @@ type RecvPro struct {
...
@@ -78,40 +78,70 @@ type RecvPro struct {
}
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
var
viewData
model
.
ViewData
//获取队列数据
//fmt.Println(string(dataByte))
var
rbmqData
model
.
ViewData
if
err
=
json
.
Unmarshal
(
dataByte
,
&
view
Data
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
dataByte
,
&
rbmq
Data
);
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
return
return
}
}
//先去遍历数据库,全部过一遍
if
rbmqData
.
ActivityId
==
0
{
return
nil
}
var
(
var
(
historyData
model
.
HistoryData
mongoHistory
model
.
HistoryData
whereMap
map
[
string
]
interface
{}
whereMap
map
[
string
]
interface
{}
)
)
//先去mongo查找
//先去mongo查找有没有存在的记录,unique_id是由3.0写到cookie的,过期时间为1年
//if viewData.UserId != 0 {
whereMap
=
bson
.
M
{
"activity_id"
:
rbmqData
.
ActivityId
,
"unique_id"
:
rbmqData
.
UniqueId
}
// whereMap = bson.M{"activity_id": viewData.ActivityId, "user_id": viewData.UserId}
//} else {
whereMap
=
bson
.
M
{
"activity_id"
:
viewData
.
ActivityId
,
"unique_id"
:
viewData
.
UniqueId
}
//}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Find
(
whereMap
)
.
One
(
&
historyData
)
Find
(
whereMap
)
.
One
(
&
mongoHistory
)
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
fmt
.
Println
(
err
)
//先去获取用户相关信息
logger
.
Error
(
err
.
Error
())
var
(
return
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
())
}
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
(
err
)
logger
.
Error
(
err
.
Error
())
}
if
count
!=
0
{
isNewReg
=
1
}
}
}
//mysql数据操作
var
result
model
.
ActivityViewStatistics
//如果rbmq传过来的数据在mongo里面找不到,先去数据库查找活动是否存在
err
=
specialDb
.
Reset
()
.
Table
(
&
result
)
.
Where
(
"activity_id"
,
viewData
.
ActivityId
)
.
Select
()
var
statistics
model
.
ActivityViewStatistics
if
result
.
ActivityId
==
0
{
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
}
}
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
ActivityId
:
view
Data
.
ActivityId
,
ActivityId
:
rbmq
Data
.
ActivityId
,
RegNum
:
0
,
RegNum
:
regNum
,
LoginNum
:
0
,
LoginNum
:
loginNum
,
CreateTime
:
int
(
time
.
Now
()
.
Unix
()),
CreateTime
:
int
(
time
.
Now
()
.
Unix
()),
}
}
_
,
err
=
specialDb
.
Reset
()
.
Table
(
"lie_activity_view_statistics"
)
.
Data
(
activityViewStatistics
)
.
Insert
()
_
,
err
=
specialDb
.
Reset
()
.
Table
(
"lie_activity_view_statistics"
)
.
Data
(
activityViewStatistics
)
.
Insert
()
...
@@ -121,19 +151,24 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
...
@@ -121,19 +151,24 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
return
return
}
}
}
else
{
}
else
{
loginNum
:=
result
.
LoginNum
loginNum
:=
statistics
.
LoginNum
regNum
:=
result
.
RegNum
regNum
:=
statistics
.
RegNum
if
viewData
.
UserId
!=
0
{
//如果已经存在的mongo记录里面,已经存在了unique_id,但是user_id为空,同时新传过来的rbmq的数据的user_id不为空,就代表这个用户
//从未登录变成了登陆态,该活动的登陆人数+1,同时去判断该用户是否是这个活动注册的用户
if
mongoHistory
.
UserId
==
0
&&
rbmqData
.
UserId
!=
0
{
loginNum
++
loginNum
++
if
isNewReg
==
1
{
regNum
++
}
}
}
//存在则去更新
//存在则去更新
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
activityViewStatistics
:=
model
.
ActivityViewStatistics
{
ActivityId
:
view
Data
.
ActivityId
,
ActivityId
:
rbmq
Data
.
ActivityId
,
RegNum
:
regNum
,
RegNum
:
regNum
,
LoginNum
:
loginNum
,
LoginNum
:
loginNum
,
UpdateTime
:
int
(
time
.
Now
()
.
Unix
()),
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
()
Data
(
activityViewStatistics
)
.
Update
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -141,66 +176,39 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
...
@@ -141,66 +176,39 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
return
return
}
}
}
}
//如果已经存在的mongo记录里面,已经存在了unique_id,但是user_id为空,同时新传过来的rbmq的数据的user_id不为空
//如果mongo存在,更新mongo数据
//此时只需要去更新mongo对应这条记录的user_id,mobile等信息
if
historyData
.
UserId
!=
0
{
if
mongoHistory
.
UserId
!=
0
{
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
mongoHistory
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
selector
:=
bson
.
M
{
"unique_id"
:
mongoHistory
.
UniqueId
}
selector
:=
bson
.
M
{
"unique_id"
:
historyData
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
mongoHistory
)
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
historyData
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
}
}
}
else
{
}
else
{
var
(
mobile
string
newData
:=
model
.
HistoryData
{
isNewReg
int
UniqueId
:
rbmqData
.
UniqueId
,
adTag
string
ActivityId
:
rbmqData
.
ActivityId
,
)
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
,
Mobile
:
mobile
,
Mobile
:
mobile
,
UserId
:
view
Data
.
UserId
,
UserId
:
rbmq
Data
.
UserId
,
IsNewReg
:
isNewReg
,
IsNewReg
:
isNewReg
,
AdTag
:
adTag
,
AdTag
:
adTag
,
Source
:
view
Data
.
Source
,
Source
:
rbmq
Data
.
Source
,
VisitTime
:
view
Data
.
VisitTime
,
VisitTime
:
rbmq
Data
.
VisitTime
,
LastVisitTime
:
0
,
LastVisitTime
:
int
(
time
.
Now
()
.
Unix
())
,
Pf
:
view
Data
.
Pf
,
Pf
:
rbmq
Data
.
Pf
,
}
}
if
historyData
.
UniqueId
==
""
{
if
mongoHistory
.
UniqueId
==
""
{
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Insert
(
&
history
Data
)
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Insert
(
&
new
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
}
}
}
else
{
}
else
{
historyData
.
LastVisitTime
=
int
(
time
.
Now
()
.
Unix
())
selector
:=
bson
.
M
{
"unique_id"
:
mongoHistory
.
UniqueId
}
selector
:=
bson
.
M
{
"unique_id"
:
historyData
.
UniqueId
}
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
newData
)
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"activity_view_history"
)
.
Update
(
selector
,
&
historyData
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
logger
.
Error
(
err
.
Error
())
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