Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
demo-go
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭芳
demo-go
Commits
8d68ce9a
Commit
8d68ce9a
authored
Feb 21, 2023
by
彭芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[feat]: add return filed
parent
e4755882
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
13 deletions
+100
-13
page.go
internal/biz/common/page.go
+2
-2
error.go
internal/biz/errs/error.go
+34
-0
report.go
internal/biz/report.go
+0
-0
campaign.go
internal/data/campaign.go
+24
-5
base.go
internal/service/base.go
+17
-5
report.go
internal/service/report.go
+5
-1
second.go
internal/util/second.go
+18
-0
No files found.
internal/biz/common/page.go
View file @
8d68ce9a
...
...
@@ -8,8 +8,8 @@ const (
)
type
PageRequest
struct
{
Page
int
`form:"page" json:"page"
binding:"required"
`
// 页码
PageSize
int
`form:"page_size" json:"page_size"
binding:"required"
`
// 每页大小
Page
int
`form:"page" json:"page"`
// 页码
PageSize
int
`form:"page_size" json:"page_size" `
// 每页大小
OrderBy
string
// 排序字段
OrderByMode
string
// 排序方式 desc asc
}
...
...
internal/biz/errs/error.go
0 → 100644
View file @
8d68ce9a
package
errs
import
"fmt"
var
(
ErrorArgs
=
New
(
40001
,
"请求参数错误"
)
ServiceError
=
New
(
50000
,
"系统错误请稍后再试。"
)
)
type
Error
struct
{
Code
int
// 错误码
Msg
string
// 错误信息
}
func
(
e
*
Error
)
Error
()
string
{
return
e
.
Msg
}
func
(
e
*
Error
)
WithMessage
(
msg
string
)
*
Error
{
out
:=
&
Error
{
Code
:
e
.
Code
,
Msg
:
e
.
Msg
,
}
if
out
.
Msg
==
""
{
out
.
Msg
=
msg
}
else
{
out
.
Msg
=
fmt
.
Sprintf
(
"%s: %s"
,
e
.
Msg
,
msg
)
}
return
out
}
func
New
(
code
int
,
msg
string
)
*
Error
{
return
&
Error
{
Code
:
code
,
Msg
:
msg
}
}
internal/biz/report.go
View file @
8d68ce9a
This diff is collapsed.
Click to expand it.
internal/data/campaign.go
View file @
8d68ce9a
...
...
@@ -21,16 +21,35 @@ func NewReportRepo(data *Data, logger log.Logger) biz.CampaignRepo {
}
func
(
p
*
campaignRepo
)
List
(
ctx
context
.
Context
,
customerId
int64
,
req
*
biz
.
ListCampaignRequest
)
(
int64
,
biz
.
CampaignList
,
error
)
{
var
list
biz
.
CampaignList
db
:=
p
.
data
.
db
.
Table
(
"ads_report_campaign_day"
)
.
Select
(
"campaign_id, campaign_name"
)
.
Where
(
"customer_id = ?"
,
customerId
)
tableName
:=
"ads_report_campaign_day"
if
req
.
TimeGranularity
==
biz
.
StatTimeGranularityHourly
{
tableName
=
"ads_report_campaign_hour"
}
db
:=
p
.
data
.
db
.
Table
(
tableName
)
.
Select
(
"campaign_id, campaign_name, advertiser_id, date_long AS stat_datetime, cost, `show`, click, `convert`, "
+
"deep_convert, attribution_convert, attribution_deep_convert, download_start, download_finish, click_install, "
+
"install_finish, active, register, next_day_open, next_day_open_cost, next_day_open_rate, attribution_next_day_open_cnt,"
+
" game_addiction, pay_count, in_app_uv, in_app_detail_uv, in_app_cart, in_app_pay, in_app_order, attribution_game_pay_7d_count,"
+
" game_pay_count, total_play, valid_play, play_25_feed_break, play_50_feed_break, play_75_feed_break, play_100_feed_break, "
+
"play_duration_sum, attribution_active_pay_intra_one_day_count, attribution_active_pay_intra_one_day_amount, gmt_modified AS timestamp"
)
.
Where
(
"customer_id = ?"
,
customerId
)
.
Where
(
"is_delete = ?"
,
0
)
// add start_date and end_date condition
if
req
.
StartDate
!=
""
{
db
=
db
.
Where
(
"date_long >= ?"
,
req
.
StartDateLong
)
}
if
req
.
EndDate
!=
""
{
db
=
db
.
Where
(
"date_long <= ?"
,
req
.
EndDateLong
)
}
var
total
int64
if
err
:=
db
.
Count
(
&
total
)
.
Error
;
err
!=
nil
{
return
0
,
nil
,
err
}
if
err
:=
db
.
Limit
(
req
.
Limit
())
.
Offset
(
req
.
Offset
())
.
Scan
(
&
list
)
.
Error
;
err
!=
nil
{
var
list
biz
.
CampaignList
if
err
:=
db
.
Order
(
req
.
GetOrderBy
(
"id"
)
+
" "
+
req
.
GetOrderByMode
())
.
Limit
(
req
.
Limit
())
.
Offset
(
req
.
Offset
())
.
Scan
(
&
list
)
.
Error
;
err
!=
nil
{
return
total
,
nil
,
err
}
return
total
,
list
,
nil
...
...
internal/service/base.go
View file @
8d68ce9a
...
...
@@ -5,16 +5,28 @@ import (
"github.com/gin-gonic/gin"
"demo/internal/biz/errs"
"demo/internal/util"
)
// ResponseError 公共返回错误处理
func
ResponseError
(
c
*
gin
.
Context
,
err
error
)
{
c
.
AbortWithStatusJSON
(
http
.
StatusOK
,
gin
.
H
{
util
.
RequestKey
:
c
.
GetString
(
util
.
RequestKey
),
"code"
:
http
.
StatusInternalServerError
,
"message"
:
err
.
Error
(),
})
if
v
,
ok
:=
err
.
(
*
errs
.
Error
);
ok
{
if
v
.
Code
==
errs
.
ServiceError
.
Code
{
v
.
Msg
=
errs
.
ServiceError
.
Msg
}
c
.
AbortWithStatusJSON
(
http
.
StatusOK
,
gin
.
H
{
util
.
RequestKey
:
c
.
GetString
(
util
.
RequestKey
),
"code"
:
v
.
Code
,
"message"
:
v
.
Msg
,
})
}
else
{
c
.
AbortWithStatusJSON
(
http
.
StatusOK
,
gin
.
H
{
util
.
RequestKey
:
c
.
GetString
(
util
.
RequestKey
),
"code"
:
errs
.
ServiceError
.
Code
,
"message"
:
errs
.
ServiceError
.
Msg
,
})
}
}
// ResponseSuccess 返回成功参数
...
...
internal/service/report.go
View file @
8d68ce9a
...
...
@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"demo/internal/biz"
"demo/internal/biz/errs"
"demo/internal/util"
)
...
...
@@ -24,17 +25,20 @@ func NewReportService(uc *biz.ReportUsecase, logger log.Logger) *ReportService {
func
(
p
*
ReportService
)
ListCampaignData
(
ctx
*
gin
.
Context
)
{
var
req
biz
.
ListCampaignRequest
if
err
:=
ctx
.
ShouldBind
(
&
req
);
err
!=
nil
{
ResponseError
(
ctx
,
err
)
p
.
log
.
Error
(
"ShouldBind err:"
,
err
)
ResponseError
(
ctx
,
errs
.
ErrorArgs
)
return
}
customerIdStr
:=
ctx
.
GetString
(
util
.
CustomerId
)
customerId
,
err
:=
strconv
.
Atoi
(
customerIdStr
)
if
err
!=
nil
{
p
.
log
.
Error
(
"Atoi err:"
,
err
)
ResponseError
(
ctx
,
err
)
return
}
data
,
err
:=
p
.
uc
.
ListCampaignData
(
ctx
,
int64
(
customerId
),
&
req
)
if
err
!=
nil
{
p
.
log
.
Error
(
"ListCampaignData err:"
,
err
)
ResponseError
(
ctx
,
err
)
return
}
...
...
internal/util/second.go
0 → 100644
View file @
8d68ce9a
package
util
import
(
"strconv"
"time"
)
type
Second
int64
func
NewSecond
(
ts
...
time
.
Time
)
Second
{
t
:=
time
.
Now
()
if
len
(
ts
)
>
0
{
t
=
ts
[
0
]
}
v
:=
t
.
Format
(
`20060102150405`
)
minute
,
_
:=
strconv
.
Atoi
(
v
)
return
Second
(
minute
)
}
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