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
6c2aa150
authored
Jan 13, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
统计完成
parent
a34d2c46
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
226 additions
and
11 deletions
config/db.toml.demo
config/db.toml.pro.demo
special/activity_statistics/main.go
special/activity_statistics/model/gift_activity.go
special/activity_statistics/model/price_activity.go
special/activity_statistics/service/message.go
util/config.go
config/db.toml.demo
View file @
6c2aa150
...
...
@@ -11,6 +11,9 @@ dns="ichuntcms:ichuntcms#zsyM@tcp(192.168.2.232:3306)/ichuntcms?parseTime=true"
[Bom_databases]
dns="root:root@tcp(192.168.2.239:3306)/lie_bom?parseTime=true"
[Special_databases]
dns="root:root@tcp(192.168.2.239:3306)/lie_bom?parseTime=true"
[rabbitmq_ichunt]
queue_name="send_buyer_mail"
routing_key="send_buyer_mail"
...
...
config/db.toml.pro.demo
View file @
6c2aa150
...
...
@@ -12,6 +12,9 @@ dns="dtuser:dAtaL#ym2902m2lLX2y33@tcp(appdb-master.ichunt.db:3306)/icdata?parseT
[Bom_databases]
dns="BomUserIc:mLssyDxmsymBomy@tcp(172.18.137.21:3306)/liexin_bom?parseTime=true"
[Special_databases]
dns="root:root@tcp(192.168.2.239:3306)/lie_bom?parseTime=true"
[rabbitmq_ichunt]
queue_name="send_buyer_mail"
routing_key="send_buyer_mail"
...
...
special/activity_statistics/main.go
0 → 100644
View file @
6c2aa150
package
main
import
(
"flag"
"fmt"
_
"github.com/go-sql-driver/mysql"
"github.com/gohouse/gorose/v2"
"go-queue-server/special/activity_statistics/model"
"go-queue-server/util"
"time"
)
var
ConfigDir
string
var
LogDir
string
var
err
error
var
engine
*
gorose
.
Engin
var
specialEngine
*
gorose
.
Engin
func
init
()
{
initArgs
()
util
.
Init
(
ConfigDir
)
initDB
()
}
// 解析命令行参数
func
initArgs
()
{
//go run main.go -configDir xxx
flag
.
StringVar
(
&
ConfigDir
,
"configDir"
,
""
,
"配置文件"
)
flag
.
StringVar
(
&
LogDir
,
"logDir"
,
""
,
"配置文件"
)
flag
.
Parse
()
}
//初始化数据库
func
initDB
()
{
dsn
:=
util
.
Configs
.
Liexin_databases
.
Dns
specialDsn
:=
util
.
Configs
.
Special_databases
.
Dns
engine
,
err
=
gorose
.
Open
(
&
gorose
.
Config
{
Driver
:
"mysql"
,
Dsn
:
dsn
})
if
err
!=
nil
{
panic
(
err
)
}
specialEngine
,
err
=
gorose
.
Open
(
&
gorose
.
Config
{
Driver
:
"mysql"
,
Dsn
:
specialDsn
})
if
err
!=
nil
{
panic
(
err
)
}
}
func
DB
()
gorose
.
IOrm
{
return
engine
.
NewOrm
()
}
func
SpecialDB
()
gorose
.
IOrm
{
return
specialEngine
.
NewOrm
()
}
//有货提醒
func
main
()
{
//先去遍历数据库,全部过一遍
db
:=
DB
()
specialDb
:=
SpecialDB
()
defer
func
()
{
db
.
Close
()
specialDb
.
Close
()
}()
nowTime
:=
time
.
Now
()
.
Unix
()
//先去取出所有的正在进行的活动列表
var
giftActivityList
[]
model
.
GiftActivity
err
=
specialDb
.
Table
(
&
giftActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
Where
(
"end_time"
,
">"
,
nowTime
)
.
Select
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
for
_
,
activity
:=
range
giftActivityList
{
//一个个去统计
orderNum
,
_
:=
db
.
Table
(
"lie_order_gift"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Count
()
newUserNum
,
_
:=
db
.
Reset
()
.
Table
(
"lie_order_gift"
)
.
LeftJoin
(
"lie_user_main on lie_order_gift.user_id = lie_user_main.user_id"
)
.
Where
(
"lie_order_gift.activity_id"
,
activity
.
Id
)
.
Where
(
"lie_user_main.is_new"
,
1
)
.
Count
()
//先查询统计是否存在
count
,
_
:=
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Where
(
"type"
,
2
)
.
Count
()
data
:=
make
(
map
[
string
]
interface
{})
data
[
"order_num"
]
=
orderNum
data
[
"new_user_num"
]
=
newUserNum
data
[
"update_time"
]
=
time
.
Now
()
.
Unix
()
data
[
"activity_id"
]
=
activity
.
Id
data
[
"type"
]
=
2
if
count
>
0
{
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Data
(
data
)
.
Update
()
}
else
{
data
[
"create_time"
]
=
time
.
Now
()
.
Unix
()
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Data
(
data
)
.
Insert
()
}
}
//先去取出所有的正在进行的活动列表
var
priceActivityList
[]
model
.
PriceActivity
err
=
specialDb
.
Reset
()
.
Table
(
&
priceActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
Where
(
"end_time"
,
">"
,
nowTime
)
.
Select
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
fmt
.
Println
(
priceActivityList
)
for
_
,
activity
:=
range
priceActivityList
{
fmt
.
Println
(
activity
)
//一个个去统计(type=4代表是活动)
orderNum
,
_
:=
db
.
Reset
()
.
Table
(
"lie_order_items_price"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
GroupBy
(
"order_id"
)
.
Count
(
"id"
)
newUserNum
,
_
:=
db
.
Reset
()
.
Table
(
"lie_order_items_price"
)
.
LeftJoin
(
"lie_user_main on lie_order_items_price.user_id = lie_user_main.user_id"
)
.
Where
(
"lie_order_items_price.activity_id"
,
activity
.
Id
)
.
Where
(
"lie_user_main.is_new"
,
1
)
.
Where
(
"lie_order_items_price.type"
,
4
)
.
GroupBy
(
"order_id"
)
.
Count
(
"id"
)
////先查询统计是否存在
count
,
_
:=
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Where
(
"type"
,
1
)
.
Count
()
data
:=
make
(
map
[
string
]
interface
{})
data
[
"order_num"
]
=
orderNum
data
[
"new_user_num"
]
=
newUserNum
data
[
"update_time"
]
=
time
.
Now
()
.
Unix
()
data
[
"activity_id"
]
=
activity
.
Id
data
[
"type"
]
=
1
if
count
>
0
{
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Data
(
data
)
.
Update
()
}
else
{
data
[
"create_time"
]
=
time
.
Now
()
.
Unix
()
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Data
(
data
)
.
Insert
()
}
}
}
special/activity_statistics/model/gift_activity.go
0 → 100644
View file @
6c2aa150
package
model
type
GiftActivity
struct
{
Id
int
`gorose:"id"`
StartTime
int
`gorose:"start_time"`
EndTime
int
`gorose:"end_time"`
}
func
(
ga
*
GiftActivity
)
TableName
()
string
{
return
"lie_gift_activity"
}
special/activity_statistics/model/price_activity.go
0 → 100644
View file @
6c2aa150
package
model
import
(
"github.com/gohouse/gorose/v2"
"time"
)
type
PriceActivity
struct
{
Id
int
`gorose:"id"`
StartTime
int
`gorose:"start_time"`
EndTime
int
`gorose:"end_time"`
}
func
(
ga
*
PriceActivity
)
TableName
()
string
{
return
"lie_price_activity"
}
func
UpdateGoodsRemindStatus
(
db
gorose
.
IOrm
,
id
int64
,
remindStatus
int
)
(
err
error
)
{
_
,
err
=
db
.
Table
(
"lie_goods_remind"
)
.
Where
(
"id"
,
id
)
.
Data
(
map
[
string
]
interface
{}{
"status"
:
remindStatus
,
"last_remind_time"
:
time
.
Now
()
.
Unix
(),
})
.
Update
()
return
err
}
func
UpdateExpiredGoodsRemindStatus
(
db
gorose
.
IOrm
)
(
err
error
)
{
oneMonthAgeTimestamp
:=
time
.
Now
()
.
Unix
()
-
30
*
24
*
3600
_
,
err
=
db
.
Table
(
"lie_goods_remind"
)
.
Where
(
"add_time"
,
"<"
,
oneMonthAgeTimestamp
)
.
Data
(
map
[
string
]
interface
{}{
"status"
:
2
,
"last_remind_time"
:
time
.
Now
()
.
Unix
(),
})
.
Update
()
return
err
}
special/activity_statistics/service/message.go
0 → 100644
View file @
6c2aa150
package
service
import
(
"encoding/json"
"fmt"
"github.com/syyongx/php2go"
"go-queue-server/util"
"net/http"
"net/url"
"strconv"
"time"
)
const
ApiMd5Str
string
=
"fh6y5t4rr351d2c3bryi"
func
SendMessage
(
userId
int
,
content
string
)
bool
{
if
userId
!=
0
{
timeNow
:=
time
.
Now
()
.
Unix
()
requestContent
,
_
:=
json
.
Marshal
(
map
[
string
]
string
{
"content"
:
content
})
requestTel
,
_
:=
json
.
Marshal
([]
int
{
userId
})
resp
,
err
:=
http
.
PostForm
(
util
.
Configs
.
Api_domain
.
MessageUrl
,
url
.
Values
{
"data"
:
{
string
(
requestContent
)},
"touser"
:
{
string
(
requestTel
)},
"keyword"
:
{
"remind_goods"
},
"k1"
:
{
strconv
.
FormatInt
(
timeNow
,
10
)},
"k2"
:
{
php2go
.
Md5
(
php2go
.
Md5
(
strconv
.
FormatInt
(
timeNow
,
10
))
+
ApiMd5Str
)},
"is_ignore"
:
{
"0"
},
})
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
fmt
.
Print
(
err
)
return
false
}
}
return
true
}
util/config.go
View file @
6c2aa150
...
...
@@ -5,11 +5,12 @@ import (
)
//订制配置文件解析载体
type
Config
struct
{
type
Config
struct
{
Liexin_databases
*
LiexinMysqlConfig
LiexinLabel_databases
*
LiexinLabelMysqlConfig
Liexincms_databases
*
LiexinCmsMysqlConfig
Bom_databases
*
BomDatabasesMysqlConfig
Special_databases
*
SpecialDatabasesMysqlConfig
Rabbitmq_ichunt
*
RabbitmqIchunt
Rabbitmq_erp_label
*
RabbitmqErpLabel
Rabbitmq_order_push_stock
*
RabbitmqOrderPushStock
...
...
@@ -22,15 +23,14 @@ type Config struct{
Fengkong_domain
*
FengkongDomain
}
type
LiexinMysqlConfig
struct
{
type
LiexinMysqlConfig
struct
{
Dns
string
`toml:"dns"`
}
type
LiexinLabelMysqlConfig
struct
{
type
LiexinLabelMysqlConfig
struct
{
Dns
string
`toml:"dns"`
}
type
LiexinCmsMysqlConfig
struct
{
type
LiexinCmsMysqlConfig
struct
{
Dns
string
`toml:"dns"`
}
...
...
@@ -38,6 +38,10 @@ type BomDatabasesMysqlConfig struct {
Dns
string
`toml:"dns"`
}
type
SpecialDatabasesMysqlConfig
struct
{
Dns
string
`toml:"dns"`
}
type
RabbitmqIchunt
struct
{
QueueName
string
`toml:"queue_name"`
RoutingKey
string
`toml:"routing_key"`
...
...
@@ -71,7 +75,7 @@ type RabbitmqBomCreateOrder struct {
Dns
string
`toml:"dns"`
}
type
SendMail
struct
{
type
SendMail
struct
{
SendMailUrl
string
`toml:"send_mail"`
}
...
...
@@ -102,14 +106,14 @@ type FengkongDomain struct {
GoUrl
string
`toml:"go_url"`
}
var
Configs
*
Config
=
new
(
Config
)
var
Configs
*
Config
=
new
(
Config
)
func
Init
(
ConfigDir
string
){
func
Init
(
ConfigDir
string
)
{
//fmt.Println(ConfigDir+"config/config.toml")
var
err
error
_
,
err
=
toml
.
DecodeFile
(
ConfigDir
+
"config.toml"
,
Configs
)
_
,
err
=
toml
.
DecodeFile
(
ConfigDir
+
"db.toml"
,
Configs
)
if
err
!=
nil
{
_
,
err
=
toml
.
DecodeFile
(
ConfigDir
+
"config.toml"
,
Configs
)
_
,
err
=
toml
.
DecodeFile
(
ConfigDir
+
"db.toml"
,
Configs
)
if
err
!=
nil
{
panic
(
err
)
}
}
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