Commit 4e69edea authored by libin's avatar libin

行为日志记录

parent a89fb725
...@@ -4,10 +4,8 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz; ...@@ -4,10 +4,8 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO; import com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO;
import com.xxfc.platform.user.behavior.entity.BehaviorType; import com.xxfc.platform.user.behavior.entity.BehaviorType;
import com.xxfc.platform.user.behavior.mapper.BehaviorTypeMapper; import com.xxfc.platform.user.behavior.mapper.BehaviorTypeMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -20,14 +18,7 @@ import java.util.List; ...@@ -20,14 +18,7 @@ import java.util.List;
public class BehaviorTypeBiz extends BaseBiz<BehaviorTypeMapper, BehaviorType> { public class BehaviorTypeBiz extends BaseBiz<BehaviorTypeMapper, BehaviorType> {
public List<BehaviorTypeDTO> findBehaviorTypesByIds(List<Integer> typeIds){ public List<BehaviorTypeDTO> findBehaviorTypesByIds(List<Integer> typeIds){
List<BehaviorTypeDTO> behaviorTypeDTOS = new ArrayList<>(); return mapper.selectAllByIdList(typeIds);
List<BehaviorType> behaviorTypes = mapper.selectByIdList(typeIds);
BehaviorTypeDTO behaviorTypeDTO;
for (BehaviorType behaviorType : behaviorTypes) {
behaviorTypeDTO = new BehaviorTypeDTO();
BeanUtils.copyProperties(behaviorType,behaviorTypeDTO);
behaviorTypeDTOS.add(behaviorTypeDTO);
}
return behaviorTypeDTOS;
} }
} }
...@@ -84,6 +84,9 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -84,6 +84,9 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
} }
//根据活动id查询活动行为 //根据活动id查询活动行为
List<ActivityBehaviorDTO> activityBehaviorDTOS = activityBehaviorBiz.findActivityBehaviorsByActivityId(activityId); List<ActivityBehaviorDTO> activityBehaviorDTOS = activityBehaviorBiz.findActivityBehaviorsByActivityId(activityId);
if (CollectionUtils.isEmpty(activityBehaviorDTOS)){
return Collections.EMPTY_LIST;
}
List<Integer> behaviorTypeIds = activityBehaviorDTOS.stream().map(ActivityBehaviorDTO::getBehaviorTypeId).collect(Collectors.toList()); List<Integer> behaviorTypeIds = activityBehaviorDTOS.stream().map(ActivityBehaviorDTO::getBehaviorTypeId).collect(Collectors.toList());
//根据活动行为ids查询行为 //根据活动行为ids查询行为
List<BehaviorTypeDTO> behaviorTypeDTOS = behaviorTypeBiz.findBehaviorTypesByIds(behaviorTypeIds); List<BehaviorTypeDTO> behaviorTypeDTOS = behaviorTypeBiz.findBehaviorTypesByIds(behaviorTypeIds);
...@@ -97,89 +100,52 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -97,89 +100,52 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
for (BehaviorEnum behaviorEnum : behaviorEnums) { for (BehaviorEnum behaviorEnum : behaviorEnums) {
behaviorNoteCollectVo = new BehaviorNoteCollectVo(); behaviorNoteCollectVo = new BehaviorNoteCollectVo();
behaviorNoteCollectVo.setBehavior(codeAndName.get(behaviorEnum.getCode())); behaviorNoteCollectVo.setBehavior(codeAndName.get(behaviorEnum.getCode()));
if (isEmpty) { long default_p_total, default_p_avg;
behaviorNoteCollectVos.add(behaviorNoteCollectVo); ActionAcount actionAcount;
continue;
} else {
long default_p_total, default_p_avg, default_u_total, default_u_avg;
switch (behaviorEnum) { switch (behaviorEnum) {
case SUCCESS_INVIT: case SUCCESS_INVIT:
actionAcount = new ActionAcount();
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; actionAcount.setDefault_p_total(default_p_total);
default_u_avg = default_p_avg; actionAcount.setDefault_p_avg(default_p_avg);
actionAcount.setDefault_u_total(default_p_total);
actionAcount.setDefault_u_avg(default_p_avg);
break; break;
case SUCCESS_MORE_10_INVIT: case SUCCESS_MORE_10_INVIT:
actionAcount = new ActionAcount();
default_p_total = popularizeRelations.stream().collect(Collectors.groupingBy(ActivityPopularizeRelationDTO::getMajorUserId, Collectors.counting())).values().stream().filter(x -> x >= 10).count(); default_p_total = popularizeRelations.stream().collect(Collectors.groupingBy(ActivityPopularizeRelationDTO::getMajorUserId, Collectors.counting())).values().stream().filter(x -> x >= 10).count();
default_p_avg = default_p_total / between_day; default_p_avg = default_p_total / between_day;
default_u_total = default_p_total; actionAcount.setDefault_p_total(default_p_total);
default_u_avg = default_p_avg; actionAcount.setDefault_p_avg(default_p_avg);
actionAcount.setDefault_u_total(default_p_total);
actionAcount.setDefault_u_avg(default_p_avg);
break; break;
case APP_VISIT_COUNT: case APP_VISIT_COUNT:
actionAcount = new ActionAcount();
default_p_total = mapper.selectAppVvisitsByType(BehaviorEnum.APP_VISIT_COUNT.getCode()); default_p_total = mapper.selectAppVvisitsByType(BehaviorEnum.APP_VISIT_COUNT.getCode());
default_p_avg = default_p_total / between_day; default_p_avg = default_p_total / between_day;
default_u_total = default_p_total; actionAcount.setDefault_p_total(default_p_total);
default_u_avg = default_p_avg; actionAcount.setDefault_p_avg(default_p_avg);
actionAcount.setDefault_u_total(default_p_total);
actionAcount.setDefault_u_avg(default_p_avg);
break; break;
case BANNER_CLICK: 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: 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: 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: case DIALOG_WINDOW:
List<CustomerBehaviorNotes> dialogWindowData = behaviorTypeAndDataOfBizMap.get(BehaviorEnum.DIALOG_WINDOW); actionAcount = new ActionAcount(between_day, behaviorTypeAndDataOfBizMap).invoke(behaviorEnum);
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; break;
default: default:
//访问量 actionAcount = new ActionAcount(between_day, behaviorAndDataMap).invoke(behaviorEnum);
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;
//用户访问量
Set<CustomerBehaviorNotes> customerBehaviorsSet = new HashSet<>(typeIsEmpty ? Collections.EMPTY_SET : customerBehaviors);
default_u_total = customerBehaviorsSet.size();
default_u_avg = default_u_total / between_day;
break; break;
} }
behaviorNoteCollectVo.setP_count(default_p_total); behaviorNoteCollectVo.setP_count(actionAcount.getDefault_p_total());
behaviorNoteCollectVo.setP_avg_count(default_p_avg); behaviorNoteCollectVo.setP_avg_count(actionAcount.getDefault_p_avg());
behaviorNoteCollectVo.setU_count(default_u_total); behaviorNoteCollectVo.setU_count(actionAcount.getDefault_u_total());
behaviorNoteCollectVo.setU_avg_count(default_u_avg); behaviorNoteCollectVo.setU_avg_count(actionAcount.getDefault_u_avg());
behaviorNoteCollectVos.add(behaviorNoteCollectVo); behaviorNoteCollectVos.add(behaviorNoteCollectVo);
} }
}
return behaviorNoteCollectVos; return behaviorNoteCollectVos;
} }
...@@ -201,4 +167,72 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe ...@@ -201,4 +167,72 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
return ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime.get()), Instant.ofEpochMilli(endTime.get())); return ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime.get()), Instant.ofEpochMilli(endTime.get()));
} }
private class ActionAcount {
private long between_day;
private Map<Integer, List<CustomerBehaviorNotes>> behaviorMap;
private long default_p_total;
private long default_p_avg;
private long default_u_total;
private long default_u_avg;
public ActionAcount(long between_day, Map<Integer, List<CustomerBehaviorNotes>> behaviorMap) {
this.between_day = between_day;
this.behaviorMap = behaviorMap;
}
public ActionAcount() {
}
public ActionAcount invoke(BehaviorEnum behaviorEnum) {
List<CustomerBehaviorNotes> behaviorTypeData = behaviorMap.get(behaviorEnum.getCode());
boolean isEmpty = CollectionUtils.isEmpty(behaviorTypeData);
default_p_total = isEmpty ? 0 : behaviorTypeData.size();
default_p_avg = default_p_total / between_day;
Set<CustomerBehaviorNotes> behaviorTypeDataSet = new HashSet<>(isEmpty ? Collections.EMPTY_SET : behaviorTypeData);
default_u_total = behaviorTypeDataSet.size();
default_u_avg = default_u_total / between_day;
return this;
}
public long getDefault_p_total() {
return default_p_total;
}
public long getDefault_p_avg() {
return default_p_avg;
}
public long getDefault_u_total() {
return default_u_total;
}
public long getDefault_u_avg() {
return default_u_avg;
}
public void setBetween_day(long between_day) {
this.between_day = between_day;
}
public void setBehaviorMap(Map<Integer, List<CustomerBehaviorNotes>> behaviorMap) {
this.behaviorMap = behaviorMap;
}
public void setDefault_p_total(long default_p_total) {
this.default_p_total = default_p_total;
}
public void setDefault_p_avg(long default_p_avg) {
this.default_p_avg = default_p_avg;
}
public void setDefault_u_total(long default_u_total) {
this.default_u_total = default_u_total;
}
public void setDefault_u_avg(long default_u_avg) {
this.default_u_avg = default_u_avg;
}
}
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
* @data 2019/8/13 14:10 * @data 2019/8/13 14:10
*/ */
public interface ActivityBehaviorMapper extends Mapper<ActivityBehavior> { public interface ActivityBehaviorMapper extends Mapper<ActivityBehavior> {
@Select("select `behavior_type_id` from `activity_behavior` where `activity_id`=#{activityId}") @Select("select `activity_id`,`behavior_type_id` from `activity_behavior` where `activity_id`=#{activityId}")
@Results(value = { @Results(value = {
@Result(column = "activity_id",property = "activityId"), @Result(column = "activity_id",property = "activityId"),
@Result(column = "behavior_type_id",property = "behaviorTypeId") @Result(column = "behavior_type_id",property = "behaviorTypeId")
......
...@@ -18,7 +18,7 @@ import java.util.List; ...@@ -18,7 +18,7 @@ import java.util.List;
*/ */
public interface ActivityBehaviorRelationMapper extends Mapper<ActivityBehaviorRelation> { public interface ActivityBehaviorRelationMapper extends Mapper<ActivityBehaviorRelation> {
@Select("select * from `activity_behavior_relation` where `activity_id`=#{activityId}") @Select("select `type`,`biz_id`,`activity_id` from `activity_behavior_relation` where `activity_id`=#{activityId}")
@Results(value = { @Results(value = {
@Result(property = "type",column = "type"), @Result(property = "type",column = "type"),
@Result(property = "bizId",column = "biz_id"), @Result(property = "bizId",column = "biz_id"),
......
package com.xxfc.platform.user.behavior.mapper; package com.xxfc.platform.user.behavior.mapper;
import com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO;
import com.xxfc.platform.user.behavior.entity.BehaviorType; import com.xxfc.platform.user.behavior.entity.BehaviorType;
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.additional.idlist.IdListMapper; import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
...@@ -11,4 +18,11 @@ import tk.mybatis.mapper.common.Mapper; ...@@ -11,4 +18,11 @@ import tk.mybatis.mapper.common.Mapper;
* @data 2019/8/13 14:13 * @data 2019/8/13 14:13
*/ */
public interface BehaviorTypeMapper extends Mapper<BehaviorType>, IdListMapper<BehaviorType,Integer> { public interface BehaviorTypeMapper extends Mapper<BehaviorType>, IdListMapper<BehaviorType,Integer> {
@Select("<script>select `name`,`code` from behavior_type where `id` in <foreach collection='typeIds' open='(' item='typeId' separator=',' close=')'> #{typeId}</foreach></script>")
@Results(value = {
@Result(column = "name",property = "name"),
@Result(column ="code",property = "code")
})
List<BehaviorTypeDTO> selectAllByIdList(@Param("typeIds") List<Integer> typeIds);
} }
...@@ -45,6 +45,6 @@ ...@@ -45,6 +45,6 @@
<if test="endTime != null and startTime == null"> <if test="endTime != null and startTime == null">
and <![CDATA[ `crt_time` <= #{endTime}]]> and <![CDATA[ `crt_time` <= #{endTime}]]>
</if> </if>
and `type` in(0,1,2,3)
</select> </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