Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
e2008d2c
Commit
e2008d2c
authored
Aug 14, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户行为记录
parent
896fdd35
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
225 additions
and
20 deletions
+225
-20
ActivityBehaviorRelationDTO.java
...atform/user/behavior/dto/ActivityBehaviorRelationDTO.java
+31
-0
ActivityBehaviorRelation.java
...atform/user/behavior/entity/ActivityBehaviorRelation.java
+42
-0
ActivityBehaviorRelationBiz.java
...atform/user/behavior/biz/ActivityBehaviorRelationBiz.java
+23
-0
CustomerBehaviorNotesBiz.java
.../platform/user/behavior/biz/CustomerBehaviorNotesBiz.java
+82
-20
ActivityBehaviorRelationMapper.java
.../user/behavior/mapper/ActivityBehaviorRelationMapper.java
+28
-0
CustomerBehaviorNotesMapper.java
...orm/user/behavior/mapper/CustomerBehaviorNotesMapper.java
+2
-0
CustomerBehaviorNotesMapper.xml
...src/main/resources/mapper/CustomerBehaviorNotesMapper.xml
+17
-0
No files found.
xx-user-behavior-collect/xx-user-behavior-api/src/main/java/com/xxfc/platform/user/behavior/dto/ActivityBehaviorRelationDTO.java
0 → 100644
View file @
e2008d2c
package
com
.
xxfc
.
platform
.
user
.
behavior
.
dto
;
import
lombok.Data
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 17:05
*/
@Data
public
class
ActivityBehaviorRelationDTO
{
/**
* @see com.xxfc.platform.user.behavior.common.BehaviorEnum
* 行为类型
*/
private
Integer
type
;
/**
* 业务id (banner 精彩活动 app弹窗)
*/
private
Integer
bizId
;
/**
* 活动id
*/
private
Integer
activityId
;
}
xx-user-behavior-collect/xx-user-behavior-api/src/main/java/com/xxfc/platform/user/behavior/entity/ActivityBehaviorRelation.java
0 → 100644
View file @
e2008d2c
package
com
.
xxfc
.
platform
.
user
.
behavior
.
entity
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 17:05
*/
@Data
@Table
(
name
=
"activity_behavior_relation"
)
public
class
ActivityBehaviorRelation
{
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
private
Integer
id
;
/**
* @see com.xxfc.platform.user.behavior.common.BehaviorEnum
* 行为类型
*/
private
Integer
type
;
/**
* 业务id (banner 精彩活动 app弹窗)
*/
@Column
(
name
=
"biz_id"
)
private
Integer
bizId
;
/**
* 活动id
*/
@Column
(
name
=
"activity_id"
)
private
Integer
activityId
;
}
xx-user-behavior-collect/xx-user-behavior-server/src/main/java/com/xxfc/platform/user/behavior/biz/ActivityBehaviorRelationBiz.java
0 → 100644
View file @
e2008d2c
package
com
.
xxfc
.
platform
.
user
.
behavior
.
biz
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.xxfc.platform.user.behavior.dto.ActivityBehaviorRelationDTO
;
import
com.xxfc.platform.user.behavior.entity.ActivityBehaviorRelation
;
import
com.xxfc.platform.user.behavior.mapper.ActivityBehaviorRelationMapper
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 17:12
*/
@Service
public
class
ActivityBehaviorRelationBiz
extends
BaseBiz
<
ActivityBehaviorRelationMapper
,
ActivityBehaviorRelation
>
{
public
List
<
ActivityBehaviorRelationDTO
>
findActivityBehaviorRelationsByActivityId
(
Integer
activityId
){
return
mapper
.
selectAllByActivityId
(
activityId
);
}
}
xx-user-behavior-collect/xx-user-behavior-server/src/main/java/com/xxfc/platform/user/behavior/biz/CustomerBehaviorNotesBiz.java
View file @
e2008d2c
...
...
@@ -6,6 +6,7 @@ import com.xxfc.platform.activity.dto.ActivityPopularizeRelationDTO;
import
com.xxfc.platform.activity.feign.ActivityFeign
;
import
com.xxfc.platform.user.behavior.common.BehaviorEnum
;
import
com.xxfc.platform.user.behavior.dto.ActivityBehaviorDTO
;
import
com.xxfc.platform.user.behavior.dto.ActivityBehaviorRelationDTO
;
import
com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO
;
import
com.xxfc.platform.user.behavior.dto.CustomerBehaviorNoteDTO
;
import
com.xxfc.platform.user.behavior.entity.CustomerBehaviorNotes
;
...
...
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -39,6 +41,8 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
private
final
ActivityBehaviorBiz
activityBehaviorBiz
;
private
final
ActivityBehaviorRelationBiz
activityBehaviorRelationBiz
;
public
void
saveCustomerBehavior
(
CustomerBehaviorNoteDTO
customerBehaviorNoteDTO
)
{
CustomerBehaviorNotes
customerBehaviorNotes
=
new
CustomerBehaviorNotes
();
BeanUtils
.
copyProperties
(
customerBehaviorNoteDTO
,
customerBehaviorNotes
);
...
...
@@ -49,29 +53,47 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
public
List
<
BehaviorNoteCollectVo
>
findBehaviorCollectByActivityId
(
Integer
activityId
,
Long
startTime
,
Long
endTime
)
{
List
<
BehaviorNoteCollectVo
>
behaviorNoteCollectVos
=
new
ArrayList
<>();
List
<
CustomerBehaviorNotes
>
customerBehaviorNotes
=
mapper
.
selectByActivityIdAndTime
(
activityId
,
startTime
,
endTime
);
//获取时间间隔
AtomicLong
startAtomic
=
new
AtomicLong
(
startTime
==
null
?
0
:
startTime
);
AtomicLong
endAtomic
=
new
AtomicLong
(
endTime
==
null
?
0
:
endTime
);
long
between_day
=
getBetweenDayAndprocessStartTimeAndEndTime
(
activityId
,
startAtomic
,
endAtomic
);
between_day
=
Math
.
abs
(
between_day
)
==
0
?
1
:
Math
.
abs
(
between_day
);
List
<
CustomerBehaviorNotes
>
customerBehaviorNotes
=
mapper
.
selectByActivityIdAndTime
(
activityId
,
startAtomic
.
get
(),
endAtomic
.
get
());
boolean
isEmpty
=
CollectionUtils
.
isEmpty
(
customerBehaviorNotes
);
List
<
ActivityPopularizeRelationDTO
>
popularizeRelations
=
new
ArrayList
<>();
Map
<
Integer
,
List
<
CustomerBehaviorNotes
>>
behaviorAndDataMap
=
null
;
if
(!
isEmpty
)
{
//邀请成功记录
popularizeRelations
=
activityFeign
.
findActivityPopularizeRelationByActivityIdAndTime
(
activityId
,
start
Time
,
endTime
);
popularizeRelations
=
activityFeign
.
findActivityPopularizeRelationByActivityIdAndTime
(
activityId
,
start
Atomic
.
get
(),
endAtomic
.
get
()
);
behaviorAndDataMap
=
customerBehaviorNotes
.
stream
().
collect
(
Collectors
.
groupingBy
(
CustomerBehaviorNotes:
:
getType
,
Collectors
.
toList
()));
}
//根据活动id查询出对应业务id
List
<
ActivityBehaviorRelationDTO
>
activityBehaviorRelations
=
activityBehaviorRelationBiz
.
findActivityBehaviorRelationsByActivityId
(
activityId
);
List
<
Integer
>
bizIds
=
activityBehaviorRelations
.
stream
().
map
(
ActivityBehaviorRelationDTO:
:
getBizId
).
collect
(
Collectors
.
toList
());
//获取时间间隔
long
between_day
=
getBetween_day
(
activityId
,
startTime
,
endTime
);
between_day
=
Math
.
abs
(
between_day
)
==
0
?
1
:
Math
.
abs
(
between_day
);
//根据业务id查询出行为记录
Map
<
Integer
,
List
<
CustomerBehaviorNotes
>>
behaviorTypeAndDataOfBizMap
=
new
HashMap
<>();
if
(
CollectionUtils
.
isNotEmpty
(
bizIds
))
{
List
<
CustomerBehaviorNotes
>
customerBehaviorNotesbiz
=
mapper
.
selectAllByTypeIdsAndTime
(
bizIds
,
startAtomic
.
get
(),
endAtomic
.
get
());
//业务数据转换map
if
(
CollectionUtils
.
isNotEmpty
(
customerBehaviorNotesbiz
))
{
behaviorTypeAndDataOfBizMap
=
customerBehaviorNotesbiz
.
stream
().
collect
(
Collectors
.
groupingBy
(
CustomerBehaviorNotes:
:
getType
,
Collectors
.
toList
()));
}
}
//根据活动id查询活动行为
List
<
ActivityBehaviorDTO
>
activityBehaviorDTOS
=
activityBehaviorBiz
.
findActivityBehaviorsByActivityId
(
activityId
);
List
<
Integer
>
behaviorTypeIds
=
activityBehaviorDTOS
.
stream
().
map
(
ActivityBehaviorDTO:
:
getBehaviorTypeId
).
collect
(
Collectors
.
toList
());
//根据活动行为ids查询行为
List
<
BehaviorTypeDTO
>
behaviorTypeDTOS
=
behaviorTypeBiz
.
findBehaviorTypesByIds
(
behaviorTypeIds
);
List
<
Integer
>
behaviorCodes
=
behaviorTypeDTOS
.
stream
().
map
(
BehaviorTypeDTO:
:
getCode
).
collect
(
Collectors
.
toList
());
//过滤出活动行为的枚举类
Set
<
BehaviorEnum
>
behaviorEnums
=
EnumSet
.
allOf
(
BehaviorEnum
.
class
).
stream
().
filter
(
behaviorEnum
->
behaviorCodes
.
contains
(
behaviorEnum
.
getCode
())).
collect
(
Collectors
.
toSet
());
//数据转换为行为码与行为名称Map
Map
<
Integer
,
String
>
codeAndName
=
behaviorTypeDTOS
.
stream
().
collect
(
Collectors
.
toMap
(
BehaviorTypeDTO:
:
getCode
,
BehaviorTypeDTO:
:
getName
));
BehaviorNoteCollectVo
behaviorNoteCollectVo
;
BehaviorNoteCollectVo
behaviorNoteCollectVo
;
for
(
BehaviorEnum
behaviorEnum
:
behaviorEnums
)
{
behaviorNoteCollectVo
=
new
BehaviorNoteCollectVo
();
behaviorNoteCollectVo
.
setBehavior
(
codeAndName
.
get
(
behaviorEnum
.
getCode
()));
...
...
@@ -99,9 +121,49 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
default_u_total
=
default_p_total
;
default_u_avg
=
default_p_avg
;
break
;
case
BANNER_CLICK:
List
<
CustomerBehaviorNotes
>
bannerClickData
=
behaviorTypeAndDataOfBizMap
.
get
(
BehaviorEnum
.
BANNER_CLICK
.
getCode
());
boolean
isEmptyofBannerClick
=
CollectionUtils
.
isEmpty
(
bannerClickData
);
default_p_total
=
isEmptyofBannerClick
?
0
:
bannerClickData
.
size
();
default_p_avg
=
default_p_total
/
between_day
;
Set
<
CustomerBehaviorNotes
>
bannerClickDataSet
=
new
HashSet
<>(
isEmptyofBannerClick
?
Collections
.
EMPTY_SET
:
bannerClickData
);
default_u_total
=
bannerClickDataSet
.
size
();
default_u_avg
=
default_u_total
/
between_day
;
break
;
case
WONDERFUL_ACTIVITY_CLICK:
List
<
CustomerBehaviorNotes
>
wonderfulActivityClickData
=
behaviorTypeAndDataOfBizMap
.
get
(
BehaviorEnum
.
WONDERFUL_ACTIVITY_CLICK
.
getCode
());
boolean
isEmptyofwonderful
=
CollectionUtils
.
isEmpty
(
wonderfulActivityClickData
);
default_p_total
=
isEmptyofwonderful
?
0
:
wonderfulActivityClickData
.
size
();
default_p_avg
=
default_p_total
/
between_day
;
Set
<
CustomerBehaviorNotes
>
wonderfulActivityClickDataSet
=
new
HashSet
<>(
isEmptyofwonderful
?
Collections
.
EMPTY_SET
:
wonderfulActivityClickData
);
default_u_total
=
wonderfulActivityClickDataSet
.
size
();
default_u_avg
=
default_u_total
/
between_day
;
break
;
case
DIALOG_WINDOW_TO:
List
<
CustomerBehaviorNotes
>
dialogWindowToData
=
behaviorTypeAndDataOfBizMap
.
get
(
BehaviorEnum
.
DIALOG_WINDOW_TO
);
boolean
isEmptyofdialogwindowto
=
CollectionUtils
.
isEmpty
(
dialogWindowToData
);
default_p_total
=
isEmptyofdialogwindowto
?
0
:
dialogWindowToData
.
size
();
default_p_avg
=
default_p_total
/
between_day
;
Set
<
CustomerBehaviorNotes
>
dialogWindowtoSet
=
new
HashSet
<>(
isEmptyofdialogwindowto
?
Collections
.
EMPTY_SET
:
dialogWindowToData
);
default_u_total
=
dialogWindowtoSet
.
size
();
default_u_avg
=
default_u_total
/
between_day
;
break
;
case
DIALOG_WINDOW:
List
<
CustomerBehaviorNotes
>
dialogWindowData
=
behaviorTypeAndDataOfBizMap
.
get
(
BehaviorEnum
.
DIALOG_WINDOW
);
boolean
isEmptyofdialogwindow
=
CollectionUtils
.
isEmpty
(
dialogWindowData
);
default_p_total
=
isEmptyofdialogwindow
?
0
:
dialogWindowData
.
size
();
default_p_avg
=
default_p_total
/
between_day
;
Set
<
CustomerBehaviorNotes
>
dialogWindowSet
=
new
HashSet
<>(
isEmptyofdialogwindow
?
Collections
.
EMPTY_SET
:
dialogWindowData
);
default_u_total
=
dialogWindowSet
.
size
();
default_u_avg
=
default_u_total
/
between_day
;
break
;
default
:
//访问量
List
<
CustomerBehaviorNotes
>
customerBehaviors
=
behaviorAndDataMap
==
null
?
Collections
.
EMPTY_LIST
:
behaviorAndDataMap
.
get
(
behaviorEnum
.
getCode
());
List
<
CustomerBehaviorNotes
>
customerBehaviors
=
behaviorAndDataMap
.
get
(
behaviorEnum
.
getCode
());
boolean
typeIsEmpty
=
CollectionUtils
.
isEmpty
(
customerBehaviors
);
default_p_total
=
typeIsEmpty
?
0
:
customerBehaviors
.
size
();
default_p_avg
=
default_p_total
/
between_day
;
...
...
@@ -121,22 +183,22 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
return
behaviorNoteCollectVos
;
}
private
long
getBetween_day
(
Integer
activityId
,
Long
startTime
,
Long
endTime
)
{
long
between_day
=
0
;
if
(
startTime
!=
null
&&
endTime
!=
null
)
{
between_day
=
ChronoUnit
.
DAYS
.
between
(
Instant
.
ofEpochMilli
(
startTime
),
Instant
.
ofEpochMilli
(
endTime
));
}
else
{
private
long
getBetweenDayAndprocessStartTimeAndEndTime
(
Integer
activityId
,
AtomicLong
startTime
,
AtomicLong
endTime
)
{
if
(
startTime
.
get
()
==
0
||
endTime
.
get
()
==
0
)
{
ActivityListDTO
activityListDTO
=
activityFeign
.
findActivityStartTimeAndEndTimeById
(
activityId
);
if
(
startTime
!=
null
)
{
between_day
=
ChronoUnit
.
DAYS
.
between
(
Instant
.
ofEpochMilli
(
startTime
),
Instant
.
now
());
Instant
now
=
Instant
.
now
();
if
(
startTime
.
get
()
!=
0
)
{
endTime
.
set
(
now
.
toEpochMilli
());
}
if
(
endTime
!=
null
)
{
between_day
=
ChronoUnit
.
DAYS
.
between
(
Instant
.
ofEpochMilli
(
activityListDTO
.
getActivity_startTime
()),
Instant
.
ofEpochMilli
(
endTime
));
if
(
endTime
.
get
()
!=
0
)
{
startTime
.
set
(
activityListDTO
.
getActivity_startTime
(
));
}
if
(
startTime
==
null
&&
endTime
==
null
)
{
between_day
=
ChronoUnit
.
DAYS
.
between
(
Instant
.
ofEpochMilli
(
activityListDTO
.
getActivity_startTime
()),
Instant
.
now
());
if
(
startTime
.
get
()
==
0
&&
endTime
.
get
()
==
0
)
{
startTime
.
set
(
activityListDTO
.
getActivity_startTime
());
endTime
.
set
(
now
.
toEpochMilli
());
}
}
return
between_day
;
return
ChronoUnit
.
DAYS
.
between
(
Instant
.
ofEpochMilli
(
startTime
.
get
()),
Instant
.
ofEpochMilli
(
endTime
.
get
()))
;
}
}
\ No newline at end of file
xx-user-behavior-collect/xx-user-behavior-server/src/main/java/com/xxfc/platform/user/behavior/mapper/ActivityBehaviorRelationMapper.java
0 → 100644
View file @
e2008d2c
package
com
.
xxfc
.
platform
.
user
.
behavior
.
mapper
;
import
com.xxfc.platform.user.behavior.dto.ActivityBehaviorRelationDTO
;
import
com.xxfc.platform.user.behavior.entity.ActivityBehaviorRelation
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Result
;
import
org.apache.ibatis.annotations.Results
;
import
org.apache.ibatis.annotations.Select
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 17:11
*/
public
interface
ActivityBehaviorRelationMapper
extends
Mapper
<
ActivityBehaviorRelation
>
{
@Select
(
"select * from `activity_behavior_relation` where `activity_id`=#{activityId}"
)
@Results
(
value
=
{
@Result
(
property
=
"type"
,
column
=
"type"
),
@Result
(
property
=
"bizId"
,
column
=
"biz_id"
),
@Result
(
property
=
"activityId"
,
column
=
"activity_id"
)
})
List
<
ActivityBehaviorRelationDTO
>
selectAllByActivityId
(
@Param
(
"activityId"
)
Integer
activityId
);
}
xx-user-behavior-collect/xx-user-behavior-server/src/main/java/com/xxfc/platform/user/behavior/mapper/CustomerBehaviorNotesMapper.java
View file @
e2008d2c
...
...
@@ -18,4 +18,6 @@ public interface CustomerBehaviorNotesMapper extends Mapper<CustomerBehaviorNote
List
<
CustomerBehaviorNotes
>
selectByActivityIdAndTime
(
@Param
(
"activityId"
)
Integer
activityId
,
@Param
(
"startTime"
)
Long
startTime
,
@Param
(
"endTime"
)
Long
endTime
);
long
selectAppVvisitsByType
(
@Param
(
"code"
)
int
code
);
List
<
CustomerBehaviorNotes
>
selectAllByTypeIdsAndTime
(
@Param
(
"bizIds"
)
List
<
Integer
>
bizIds
,
@Param
(
"startTime"
)
Long
startTime
,
@Param
(
"endTime"
)
Long
endTime
);
}
xx-user-behavior-collect/xx-user-behavior-server/src/main/resources/mapper/CustomerBehaviorNotesMapper.xml
View file @
e2008d2c
...
...
@@ -30,4 +30,21 @@
<select
id=
"selectAppVvisitsByType"
resultType=
"long"
>
select count(id) from `customer_behavior_notes` where `type`=#{code}
</select>
<select
id=
"selectAllByTypeIdsAndTime"
resultMap=
"customerBehaviorNotesMap"
>
select * from `customer_behavior_notes` where `type_id` in
<foreach
collection=
"bizIds"
item=
"bizId"
open=
"("
close=
")"
separator=
","
>
#{bizId}
</foreach>
<if
test=
"startTime != null != null and endTime !=null"
>
and `crt_time` between #{startTime} and #{endTime}
</if>
<if
test=
"startTime != null and endTime == null"
>
and
<![CDATA[`crt_time` >= #{startTime}]]>
</if>
<if
test=
"endTime != null and startTime == null"
>
and
<![CDATA[ `crt_time` <= #{endTime}]]>
</if>
</select>
</mapper>
\ No newline at end of file
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