Commit 1dc321a9 authored by libin's avatar libin

行为日志记录

parent 291a8ccf
...@@ -16,7 +16,7 @@ public enum BehaviorEnum { ...@@ -16,7 +16,7 @@ public enum BehaviorEnum {
/** /**
* 立即前往(弹窗) * 立即前往(弹窗)
*/ */
DIALOG_WINDOW_TO(1, "立即前往(活动详情页)"), DIALOG_WINDOW_TO(1, "立即前往(弹窗)"),
/** /**
* banner 点击 * banner 点击
...@@ -31,7 +31,7 @@ public enum BehaviorEnum { ...@@ -31,7 +31,7 @@ public enum BehaviorEnum {
/** /**
* 注册 * 注册
*/ */
REGISTRY(4, "注册"), REGISTRY(4, "成功注册"),
/** /**
* 活动页面访问量 * 活动页面访问量
...@@ -46,7 +46,7 @@ public enum BehaviorEnum { ...@@ -46,7 +46,7 @@ public enum BehaviorEnum {
/** /**
* 分享 * 分享
*/ */
SHARE(7, "分享"), SHARE(7, "成功分享"),
/** /**
* App访问 * App访问
...@@ -61,7 +61,12 @@ public enum BehaviorEnum { ...@@ -61,7 +61,12 @@ public enum BehaviorEnum {
/** /**
* 成功邀请人数大于10 * 成功邀请人数大于10
*/ */
SUCCESS_MORE_10_INVIT(10,"成功邀请人数大于10"); SUCCESS_MORE_10_INVIT(10,"成功邀请人数大于10"),
/**
* 立即领取(活动详情页)
*/
IMMEDIATELY_TO_RECEIVE(11,"立即领取(活动详情页)");
BehaviorEnum(int code, String name) { BehaviorEnum(int code, String name) {
this.code = code; this.code = code;
......
...@@ -5,6 +5,8 @@ import com.xxfc.platform.activity.dto.ActivityListDTO; ...@@ -5,6 +5,8 @@ import com.xxfc.platform.activity.dto.ActivityListDTO;
import com.xxfc.platform.activity.dto.ActivityPopularizeRelationDTO; import com.xxfc.platform.activity.dto.ActivityPopularizeRelationDTO;
import com.xxfc.platform.activity.feign.ActivityFeign; import com.xxfc.platform.activity.feign.ActivityFeign;
import com.xxfc.platform.user.behavior.common.BehaviorEnum; import com.xxfc.platform.user.behavior.common.BehaviorEnum;
import com.xxfc.platform.user.behavior.dto.ActivityBehaviorDTO;
import com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO;
import com.xxfc.platform.user.behavior.dto.CustomerBehaviorNoteDTO; import com.xxfc.platform.user.behavior.dto.CustomerBehaviorNoteDTO;
import com.xxfc.platform.user.behavior.entity.CustomerBehaviorNotes; import com.xxfc.platform.user.behavior.entity.CustomerBehaviorNotes;
import com.xxfc.platform.user.behavior.mapper.CustomerBehaviorNotesMapper; import com.xxfc.platform.user.behavior.mapper.CustomerBehaviorNotesMapper;
...@@ -33,6 +35,10 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -33,6 +35,10 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
private final ActivityFeign activityFeign; private final ActivityFeign activityFeign;
private final BehaviorTypeBiz behaviorTypeBiz;
private final ActivityBehaviorBiz activityBehaviorBiz;
public void saveCustomerBehavior(CustomerBehaviorNoteDTO customerBehaviorNoteDTO) { public void saveCustomerBehavior(CustomerBehaviorNoteDTO customerBehaviorNoteDTO) {
CustomerBehaviorNotes customerBehaviorNotes = new CustomerBehaviorNotes(); CustomerBehaviorNotes customerBehaviorNotes = new CustomerBehaviorNotes();
BeanUtils.copyProperties(customerBehaviorNoteDTO, customerBehaviorNotes); BeanUtils.copyProperties(customerBehaviorNoteDTO, customerBehaviorNotes);
...@@ -43,35 +49,41 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -43,35 +49,41 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
public List<BehaviorNoteCollectVo> findBehaviorCollectByActivityId(Integer activityId, Long startTime, Long endTime) { public List<BehaviorNoteCollectVo> findBehaviorCollectByActivityId(Integer activityId, Long startTime, Long endTime) {
List<BehaviorNoteCollectVo> behaviorNoteCollectVos = new ArrayList<>(); List<BehaviorNoteCollectVo> behaviorNoteCollectVos = new ArrayList<>();
List<CustomerBehaviorNotes> customerBehaviorNotes = mapper.selectByActivityIdAndTime(activityId,startTime,endTime); List<CustomerBehaviorNotes> customerBehaviorNotes = mapper.selectByActivityIdAndTime(activityId, startTime, endTime);
boolean isEmpty = CollectionUtils.isEmpty(customerBehaviorNotes); boolean isEmpty = CollectionUtils.isEmpty(customerBehaviorNotes);
List<ActivityPopularizeRelationDTO> popularizeRelations = new ArrayList<>(); List<ActivityPopularizeRelationDTO> popularizeRelations = new ArrayList<>();
Map<Integer, List<CustomerBehaviorNotes>> behaviorAndDataMap = null; Map<Integer, List<CustomerBehaviorNotes>> behaviorAndDataMap = null;
if (!isEmpty) { if (!isEmpty) {
//邀请成功记录 //邀请成功记录
popularizeRelations= activityFeign.findActivityPopularizeRelationByActivityIdAndTime(activityId, startTime, endTime); popularizeRelations = activityFeign.findActivityPopularizeRelationByActivityIdAndTime(activityId, startTime, endTime);
behaviorAndDataMap= customerBehaviorNotes.stream().collect(Collectors.groupingBy(CustomerBehaviorNotes::getType, Collectors.toList())); behaviorAndDataMap = customerBehaviorNotes.stream().collect(Collectors.groupingBy(CustomerBehaviorNotes::getType, Collectors.toList()));
} }
//获取时间间隔 //获取时间间隔
long between_day = getBetween_day(activityId, startTime, endTime); long between_day = getBetween_day(activityId, startTime, endTime);
between_day = Math.abs(between_day)==0?1:Math.abs(between_day); between_day = Math.abs(between_day) == 0 ? 1 : Math.abs(between_day);
EnumSet<BehaviorEnum> behaviorEnums = EnumSet.allOf(BehaviorEnum.class); List<ActivityBehaviorDTO> activityBehaviorDTOS = activityBehaviorBiz.findActivityBehaviorsByActivityId(activityId);
List<Integer> behaviorTypeIds = activityBehaviorDTOS.stream().map(ActivityBehaviorDTO::getBehaviorTypeId).collect(Collectors.toList());
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<Integer, String> codeAndName = behaviorTypeDTOS.stream().collect(Collectors.toMap(BehaviorTypeDTO::getCode, BehaviorTypeDTO::getName));
BehaviorNoteCollectVo behaviorNoteCollectVo; BehaviorNoteCollectVo behaviorNoteCollectVo;
for (BehaviorEnum behaviorEnum : behaviorEnums) { for (BehaviorEnum behaviorEnum : behaviorEnums) {
behaviorNoteCollectVo = new BehaviorNoteCollectVo(); behaviorNoteCollectVo = new BehaviorNoteCollectVo();
behaviorNoteCollectVo.setBehavior(behaviorEnum.getName()); behaviorNoteCollectVo.setBehavior(codeAndName.get(behaviorEnum.getCode()));
if (isEmpty) { if (isEmpty) {
behaviorNoteCollectVos.add(behaviorNoteCollectVo); behaviorNoteCollectVos.add(behaviorNoteCollectVo);
continue; continue;
} else { } else {
long default_p_total,default_p_avg,default_u_total,default_u_avg; long default_p_total, default_p_avg, default_u_total, default_u_avg;
switch (behaviorEnum) { switch (behaviorEnum) {
case SUCCESS_INVIT: case SUCCESS_INVIT:
default_p_total = popularizeRelations.size(); default_p_total = popularizeRelations.size();
default_p_avg= (default_p_total / between_day); default_p_avg = (default_p_total / between_day);
default_u_total = default_p_total; default_u_total = default_p_total;
default_u_avg = default_p_avg; default_u_avg = default_p_avg;
break; break;
...@@ -81,14 +93,20 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -81,14 +93,20 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
default_u_total = default_p_total; default_u_total = default_p_total;
default_u_avg = default_p_avg; default_u_avg = default_p_avg;
break; break;
case APP_VISIT_COUNT:
default_p_total = mapper.selectAppVvisitsByType(BehaviorEnum.APP_VISIT_COUNT.getCode());
default_p_avg = default_p_total / between_day;
default_u_total = default_p_total;
default_u_avg = default_p_avg;
break;
default: default:
//访问量 //访问量
List<CustomerBehaviorNotes> customerBehaviors = behaviorAndDataMap==null?Collections.EMPTY_LIST:behaviorAndDataMap.get(behaviorEnum.getCode()); List<CustomerBehaviorNotes> customerBehaviors = behaviorAndDataMap == null ? Collections.EMPTY_LIST : behaviorAndDataMap.get(behaviorEnum.getCode());
boolean typeIsEmpty = CollectionUtils.isEmpty(customerBehaviors); boolean typeIsEmpty = CollectionUtils.isEmpty(customerBehaviors);
default_p_total = typeIsEmpty?0:customerBehaviors.size(); default_p_total = typeIsEmpty ? 0 : customerBehaviors.size();
default_p_avg = default_p_total / between_day; default_p_avg = default_p_total / between_day;
//用户访问量 //用户访问量
Set<CustomerBehaviorNotes> customerBehaviorsSet = new HashSet<>(typeIsEmpty?Collections.EMPTY_SET:customerBehaviors); Set<CustomerBehaviorNotes> customerBehaviorsSet = new HashSet<>(typeIsEmpty ? Collections.EMPTY_SET : customerBehaviors);
default_u_total = customerBehaviorsSet.size(); default_u_total = customerBehaviorsSet.size();
default_u_avg = default_u_total / between_day; default_u_avg = default_u_total / between_day;
break; break;
...@@ -105,18 +123,18 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -105,18 +123,18 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
private long getBetween_day(Integer activityId, Long startTime, Long endTime) { private long getBetween_day(Integer activityId, Long startTime, Long endTime) {
long between_day = 0; long between_day = 0;
if (startTime!=null && endTime !=null){ if (startTime != null && endTime != null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.ofEpochMilli(endTime)); between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.ofEpochMilli(endTime));
}else { } else {
ActivityListDTO activityListDTO = activityFeign.findActivityStartTimeAndEndTimeById(activityId); ActivityListDTO activityListDTO = activityFeign.findActivityStartTimeAndEndTimeById(activityId);
if (startTime!=null){ if (startTime != null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime),Instant.now()); between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.now());
} }
if (endTime!=null){ if (endTime != null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()),Instant.ofEpochMilli(endTime)); between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()), Instant.ofEpochMilli(endTime));
} }
if (startTime == null && endTime == null){ if (startTime == null && endTime == null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()),Instant.now()); between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()), Instant.now());
} }
} }
return between_day; return between_day;
......
...@@ -16,4 +16,6 @@ import java.util.List; ...@@ -16,4 +16,6 @@ import java.util.List;
public interface CustomerBehaviorNotesMapper extends Mapper<CustomerBehaviorNotes> { public interface CustomerBehaviorNotesMapper extends Mapper<CustomerBehaviorNotes> {
List<CustomerBehaviorNotes> selectByActivityIdAndTime(@Param("activityId") Integer activityId,@Param("startTime") Long startTime,@Param("endTime") Long endTime); List<CustomerBehaviorNotes> selectByActivityIdAndTime(@Param("activityId") Integer activityId,@Param("startTime") Long startTime,@Param("endTime") Long endTime);
long selectAppVvisitsByType(@Param("code") int code);
} }
...@@ -26,4 +26,8 @@ ...@@ -26,4 +26,8 @@
and <![CDATA[ `crt_time` <= #{endTime}]]> and <![CDATA[ `crt_time` <= #{endTime}]]>
</if> </if>
</select> </select>
<select id="selectAppVvisitsByType" resultType="long">
select count(id) from `customer_behavior_notes` where `type`=#{code}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment