Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
marketing
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
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
dingjy
marketing
Commits
cf34b22d
Commit
cf34b22d
authored
Apr 12, 2024
by
dingjy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
b5785b3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
153 additions
and
0 deletions
+153
-0
ClickbackService.java
.../java/com/lwby/marketing/controller/ClickbackService.java
+153
-0
No files found.
src/main/java/com/lwby/marketing/controller/ClickbackService.java
0 → 100644
View file @
cf34b22d
package
com
.
lwby
.
marketing
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableSet
;
import
com.lwby.marketing.notify.Media
;
import
com.lwby.marketing.util.CacheKeyUtils
;
import
com.lwby.marketing.util.ResultConstant
;
import
com.lwby.marketing.vo.ClientInfo
;
import
com.lwby.marketing.vo.DeliveryDeviceInfo
;
import
com.lwby.marketing.vo.NovelAction
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
@RestController
@Slf4j
@RequestMapping
(
value
=
"/clickback"
)
public
class
ClickbackService
{
final
static
ImmutableSet
<
String
>
filter
=
ImmutableSet
.
of
(
"click.special.param:00000000-0000-0000-0000-000000000000"
,
"9f89c84a559f573636a47ff8daed0d33"
,
"__IMEI__"
,
"null"
,
"NULL"
);
final
static
ImmutableMap
<
String
,
Integer
>
RESULT_SUCCESS
=
ImmutableMap
.
of
(
"status"
,
ResultConstant
.
CALL_BACK_SUCCESS
);
final
static
int
bookIdExpireTime
=
604800
;
@Resource
public
RedisTemplate
<
String
,
String
>
redisTemplate
;
@RequestMapping
(
"/jrtt"
)
@ResponseBody
public
Object
jrttClick
(
@RequestParam
Map
<
String
,
String
>
params
){
NovelAction
action
=
full
(
params
);
for
(
DeviceType
type:
DeviceType
.
values
()){
String
deviceIdKey
=
type
.
getDeviceId
(
action
.
getClientInfo
());
if
(
null
!=
deviceIdKey
){
DeliveryDeviceInfo
ddi
=
action
.
getDeliveryDeviceInfo
();
if
(
StringUtils
.
isNotEmpty
(
ddi
.
getDj_channel
()))
{
redisTemplate
.
opsForValue
().
set
(
CacheKeyUtils
.
getChannelByDeviceIdKeyAndPlatformId
(
deviceIdKey
,
ddi
.
getPlatform_id
()),
JSON
.
toJSONString
(
Integer
.
parseInt
(
ddi
.
getDj_channel
())),
bookIdExpireTime
,
TimeUnit
.
SECONDS
);
if
(
StringUtils
.
isNotEmpty
(
ddi
.
getBook_id
())
&&
StringUtils
.
isNumeric
(
ddi
.
getBook_id
()))
{
redisTemplate
.
opsForValue
().
set
(
CacheKeyUtils
.
getDeliveryBookIdCacheKey
(
deviceIdKey
,
ddi
.
getPlatform_id
()),
JSON
.
toJSONString
(
ddi
.
getBook_id
()),
bookIdExpireTime
,
TimeUnit
.
SECONDS
);
if
(
StringUtils
.
isNotEmpty
(
ddi
.
getPartId
())
&&
StringUtils
.
isNumeric
(
ddi
.
getPartId
()))
{
redisTemplate
.
opsForValue
().
set
(
CacheKeyUtils
.
getDeliveryPartIdCacheKey
(
deviceIdKey
,
ddi
.
getPlatform_id
()),
JSON
.
toJSONString
(
ddi
.
getPartId
()),
bookIdExpireTime
,
TimeUnit
.
SECONDS
);
}
}
}
redisTemplate
.
opsForValue
().
set
(
CacheKeyUtils
.
getClickKeyByIdfaAndPlatformId
(
deviceIdKey
,
ddi
.
getPlatform_id
()),
JSON
.
toJSONString
(
ddi
),
bookIdExpireTime
,
TimeUnit
.
SECONDS
);
break
;
}
}
return
RESULT_SUCCESS
;
}
public
NovelAction
full
(
Map
<
String
,
String
>
params
)
{
ClientInfo
clientInfo
=
new
ClientInfo
();
clientInfo
.
setImei
(
params
.
get
(
"imei"
));
clientInfo
.
setOaid
(
params
.
get
(
"oaid"
));
clientInfo
.
setIdfa
(
params
.
get
(
"idfa"
));
clientInfo
.
setClientIp
(
params
.
get
(
"ip"
));
clientInfo
.
setUa
(
params
.
get
(
"ua"
));
try
{
clientInfo
.
setPhoneModel
(
StringUtils
.
defaultIfEmpty
(
URLEncoder
.
encode
(
params
.
get
(
"model"
),
"utf-8"
),
null
));
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
e
);
}
DeliveryDeviceInfo
deliveryDeviceInfo
=
new
DeliveryDeviceInfo
();
deliveryDeviceInfo
.
setClick_time
(
System
.
currentTimeMillis
());
deliveryDeviceInfo
.
setAd_group_id
(
params
.
get
(
"campaign_id"
));
deliveryDeviceInfo
.
setAd_creative_id
(
params
.
get
(
"cid"
));
deliveryDeviceInfo
.
setAd_plan_id
(
params
.
get
(
"adid"
));
deliveryDeviceInfo
.
setMedia
(
Media
.
NOVEL_JRTT
.
name
);
deliveryDeviceInfo
.
setPlatform_id
(
params
.
get
(
"platform_id"
));
deliveryDeviceInfo
.
setDj_channel
(
params
.
get
(
"channel"
));
deliveryDeviceInfo
.
setBook_id
(
StringUtils
.
defaultIfBlank
(
params
.
get
(
"book"
),
StringUtils
.
defaultIfBlank
(
params
.
get
(
"books"
),
params
.
get
(
"book_id"
))));
deliveryDeviceInfo
.
setCallback_param
(
params
.
get
(
"callback_param"
));
if
(
Objects
.
isNull
(
deliveryDeviceInfo
.
getCallback_param
()))
{
deliveryDeviceInfo
.
setCallback_url
(
params
.
get
(
"callback_url"
));
}
deliveryDeviceInfo
.
setAdvertiser_id
(
params
.
get
(
"advertiser_id"
));
deliveryDeviceInfo
.
setUuid
(
UUID
.
randomUUID
().
toString
());
deliveryDeviceInfo
.
setAd_platform_type
(
params
.
get
(
"ad_platform_type"
));
deliveryDeviceInfo
.
setTarget_audience
(
params
.
get
(
"target_audience"
));
//通投智选union_site
deliveryDeviceInfo
.
setUnion_site
(
params
.
get
(
"union_site"
));
deliveryDeviceInfo
.
setPartId
(
params
.
get
(
"part_id"
));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的广告ID
deliveryDeviceInfo
.
setPromotion_id
(
StringUtils
.
defaultIfEmpty
(
params
.
get
(
"promotion_id"
),
null
));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的项目ID
deliveryDeviceInfo
.
setProject_id
(
StringUtils
.
defaultIfEmpty
(
params
.
get
(
"project_id"
),
null
));
//巨量广告体验版中的广告名称
deliveryDeviceInfo
.
setPromotion_name
(
StringUtils
.
defaultIfEmpty
(
params
.
get
(
"promotion_name"
),
null
));
//巨量广告体验版中的项目名称
deliveryDeviceInfo
.
setProject_name
(
StringUtils
.
defaultIfEmpty
(
params
.
get
(
"project_name"
),
null
));
//信息流投放广告来源(碎片 1 书籍 2)
deliveryDeviceInfo
.
setSource
(
Integer
.
valueOf
(
params
.
get
(
"source"
)));
return
new
NovelAction
(
clientInfo
,
deliveryDeviceInfo
);
}
enum
DeviceType
{
IMEI
(
"imei"
,(
c
)
->
isNotEmptyAndSNull
(
c
.
getImei
())?
c
.
getImei
():
null
),
OAID
(
"oaid"
,
(
c
)
->
isNotEmptyAndSNull
(
c
.
getOaid
())?
c
.
getOaid
():
null
),
IDFA
(
"idfa"
,(
c
)
->
isNotEmptyAndSNull
(
c
.
getIdfa
())?
c
.
getIdfa
():
null
),
IP_UA
(
"ipua"
,(
c
)
->
isNotEmptyAndSNull
(
c
.
getClientIp
())
&&
isNotEmptyAndSNull
(
c
.
getUa
())?
c
.
getClientIp
().
concat
(
StringUtils
.
substringBefore
(
c
.
getUa
(),
" Chrome/"
)):
null
),
IP_MODEL
(
"ipmodel"
,(
c
)
->
isNotEmptyAndSNull
(
c
.
getClientIp
())
&&
isNotEmptyAndSNull
(
c
.
getPhoneModel
())?
c
.
getClientIp
().
concat
(
c
.
getPhoneModel
()):
null
),
IP
(
"ip"
,(
c
)
->
isNotEmptyAndSNull
(
c
.
getClientIp
())?
c
.
getClientIp
():
null
);
private
String
value
;
private
Function
<
ClientInfo
,
String
>
fun
;
DeviceType
(
String
value
,
Function
<
ClientInfo
,
String
>
fun
)
{
this
.
value
=
value
;
this
.
fun
=
fun
;
}
public
String
getValue
()
{
return
this
.
value
;
}
public
String
getDeviceId
(
ClientInfo
clientInfo
){
return
fun
.
apply
(
clientInfo
);
}
private
static
boolean
isNotEmptyAndSNull
(
String
str
)
{
return
StringUtils
.
isNotEmpty
(
str
)
&&
!
filter
.
contains
(
str
);
}
}
}
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