Commit 0e1f8e85 authored by jiaorz's avatar jiaorz

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	xx-user-behavior-collect/xx-user-behavior-server/src/main/java/com/xxfc/platform/user/behavior/biz/CustomerBehaviorNotesBiz.java
parents ef6943dc 896fdd35
......@@ -88,7 +88,7 @@ public class AppUserRelationBiz extends BaseBiz<AppUserRelationMapper,AppUserRel
}else {
//判断用户是否有有效的上线
log.info("----userId==="+userId+"----bindTime===="+bindTime+"----relation.getBindTime()==="+relation.getBindTime());
if(relation.getParentId()==null||relation.getParentId()==0||(relation.getIsForever()!=1&&relation.getBindTime()<bindTime)){
if(relation.getParentId()==null||relation.getParentId()==0||(relation.getIsForever()!=1&&validTime>0&&relation.getBindTime()<bindTime)){
relation.setParentId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
......
......@@ -16,7 +16,7 @@ public enum BehaviorEnum {
/**
* 立即前往(弹窗)
*/
DIALOG_WINDOW_TO(1, "立即前往(活动详情页)"),
DIALOG_WINDOW_TO(1, "立即前往(弹窗)"),
/**
* banner 点击
......@@ -31,7 +31,7 @@ public enum BehaviorEnum {
/**
* 注册
*/
REGISTRY(4, "注册"),
REGISTRY(4, "成功注册"),
/**
* 活动页面访问量
......@@ -46,7 +46,7 @@ public enum BehaviorEnum {
/**
* 分享
*/
SHARE(7, "分享"),
SHARE(7, "成功分享"),
/**
* App访问
......@@ -61,7 +61,12 @@ public enum BehaviorEnum {
/**
* 成功邀请人数大于10
*/
SUCCESS_MORE_10_INVIT(10,"成功邀请人数大于10");
SUCCESS_MORE_10_INVIT(10,"成功邀请人数大于10"),
/**
* 立即领取(活动详情页)
*/
IMMEDIATELY_TO_RECEIVE(11,"立即领取(活动详情页)");
BehaviorEnum(int code, String name) {
this.code = code;
......
package com.xxfc.platform.user.behavior.dto;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 14:16
*/
@Data
public class ActivityBehaviorDTO {
private Integer activityId;
private Integer behaviorTypeId;
}
package com.xxfc.platform.user.behavior.dto;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 14:16
*/
@Data
public class BehaviorTypeDTO {
private String name;
private Integer code;
}
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 14:02
*/
@Data
@Table(name = "activity_behavior")
public class ActivityBehavior {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
@Column(name = "activity_id")
private Integer activityId;
@Column(name = "behavior_type_id")
private Integer behaviorTypeId;
}
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 14:02
*/
@Data
@Table(name = "behavior_type")
public class BehaviorType {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "code")
private Integer code;
}
package com.xxfc.platform.user.behavior.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.user.behavior.dto.ActivityBehaviorDTO;
import com.xxfc.platform.user.behavior.entity.ActivityBehavior;
import com.xxfc.platform.user.behavior.mapper.ActivityBehaviorMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 14:10
*/
@Service
public class ActivityBehaviorBiz extends BaseBiz<ActivityBehaviorMapper, ActivityBehavior> {
public List<ActivityBehaviorDTO> findActivityBehaviorsByActivityId(Integer activityId){
return mapper.selectbyActivityId(activityId);
}
}
package com.xxfc.platform.user.behavior.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.user.behavior.dto.BehaviorTypeDTO;
import com.xxfc.platform.user.behavior.entity.BehaviorType;
import com.xxfc.platform.user.behavior.mapper.BehaviorTypeMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 14:09
*/
@Service
public class BehaviorTypeBiz extends BaseBiz<BehaviorTypeMapper, BehaviorType> {
public List<BehaviorTypeDTO> findBehaviorTypesByIds(List<Integer> typeIds){
List<BehaviorTypeDTO> behaviorTypeDTOS = new ArrayList<>();
List<BehaviorType> behaviorTypes = mapper.selectByIdList(typeIds);
BehaviorTypeDTO behaviorTypeDTO;
for (BehaviorType behaviorType : behaviorTypes) {
behaviorTypeDTO = new BehaviorTypeDTO();
BeanUtils.copyProperties(behaviorType,behaviorTypeDTO);
behaviorTypeDTOS.add(behaviorTypeDTO);
}
return behaviorTypeDTOS;
}
}
......@@ -5,6 +5,8 @@ import com.xxfc.platform.activity.dto.ActivityListDTO;
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.BehaviorTypeDTO;
import com.xxfc.platform.user.behavior.dto.CustomerBehaviorNoteDTO;
import com.xxfc.platform.user.behavior.entity.CustomerBehaviorNotes;
import com.xxfc.platform.user.behavior.mapper.CustomerBehaviorNotesMapper;
......@@ -33,6 +35,10 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
private final ActivityFeign activityFeign;
private final BehaviorTypeBiz behaviorTypeBiz;
private final ActivityBehaviorBiz activityBehaviorBiz;
public void saveCustomerBehavior(CustomerBehaviorNoteDTO customerBehaviorNoteDTO) {
CustomerBehaviorNotes customerBehaviorNotes = new CustomerBehaviorNotes();
BeanUtils.copyProperties(customerBehaviorNoteDTO, customerBehaviorNotes);
......@@ -43,35 +49,41 @@ 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);
List<CustomerBehaviorNotes> customerBehaviorNotes = mapper.selectByActivityIdAndTime(activityId, startTime, endTime);
boolean isEmpty = CollectionUtils.isEmpty(customerBehaviorNotes);
List<ActivityPopularizeRelationDTO> popularizeRelations = new ArrayList<>();
Map<Integer, List<CustomerBehaviorNotes>> behaviorAndDataMap = null;
if (!isEmpty) {
//邀请成功记录
popularizeRelations= activityFeign.findActivityPopularizeRelationByActivityIdAndTime(activityId, startTime, endTime);
behaviorAndDataMap= customerBehaviorNotes.stream().collect(Collectors.groupingBy(CustomerBehaviorNotes::getType, Collectors.toList()));
popularizeRelations = activityFeign.findActivityPopularizeRelationByActivityIdAndTime(activityId, startTime, endTime);
behaviorAndDataMap = customerBehaviorNotes.stream().collect(Collectors.groupingBy(CustomerBehaviorNotes::getType, Collectors.toList()));
}
//获取时间间隔
long between_day = getBetween_day(activityId, startTime, endTime);
between_day = Math.abs(between_day)==0?1:Math.abs(between_day);
EnumSet<BehaviorEnum> behaviorEnums = EnumSet.allOf(BehaviorEnum.class);
between_day = Math.abs(between_day) == 0 ? 1 : Math.abs(between_day);
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;
for (BehaviorEnum behaviorEnum : behaviorEnums) {
behaviorNoteCollectVo = new BehaviorNoteCollectVo();
behaviorNoteCollectVo.setBehavior(behaviorEnum.getName());
behaviorNoteCollectVo.setBehavior(codeAndName.get(behaviorEnum.getCode()));
if (isEmpty) {
behaviorNoteCollectVos.add(behaviorNoteCollectVo);
continue;
} 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) {
case SUCCESS_INVIT:
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_avg = default_p_avg;
break;
......@@ -81,14 +93,20 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
default_u_total = default_p_total;
default_u_avg = default_p_avg;
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:
//访问量
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);
default_p_total = typeIsEmpty?0:customerBehaviors.size();
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);
Set<CustomerBehaviorNotes> customerBehaviorsSet = new HashSet<>(typeIsEmpty ? Collections.EMPTY_SET : customerBehaviors);
default_u_total = customerBehaviorsSet.size();
default_u_avg = default_u_total / between_day;
break;
......@@ -105,18 +123,18 @@ public class CustomerBehaviorNotesBiz extends BaseBiz<CustomerBehaviorNotesMappe
private long getBetween_day(Integer activityId, Long startTime, Long endTime) {
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));
}else {
} else {
ActivityListDTO activityListDTO = activityFeign.findActivityStartTimeAndEndTimeById(activityId);
if (startTime!=null){
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime),Instant.now());
if (startTime != null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.now());
}
if (endTime!=null){
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()),Instant.ofEpochMilli(endTime));
if (endTime != null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()), Instant.ofEpochMilli(endTime));
}
if (startTime == null && endTime == null){
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()),Instant.now());
if (startTime == null && endTime == null) {
between_day = ChronoUnit.DAYS.between(Instant.ofEpochMilli(activityListDTO.getActivity_startTime()), Instant.now());
}
}
return between_day;
......
package com.xxfc.platform.user.behavior.mapper;
import com.xxfc.platform.user.behavior.dto.ActivityBehaviorDTO;
import com.xxfc.platform.user.behavior.entity.ActivityBehavior;
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 14:10
*/
public interface ActivityBehaviorMapper extends Mapper<ActivityBehavior> {
@Select("select `behavior_type_id` from `activity_behavior` where `activity_id`=#{activityId}")
@Results(value = {
@Result(column = "activity_id",property = "activityId"),
@Result(column = "behavior_type_id",property = "behaviorTypeId")
})
List<ActivityBehaviorDTO> selectbyActivityId(@Param("activityId") Integer activityId);
}
package com.xxfc.platform.user.behavior.mapper;
import com.xxfc.platform.user.behavior.entity.BehaviorType;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/13 14:13
*/
public interface BehaviorTypeMapper extends Mapper<BehaviorType>, IdListMapper<BehaviorType,Integer> {
}
......@@ -16,4 +16,6 @@ import java.util.List;
public interface CustomerBehaviorNotesMapper extends Mapper<CustomerBehaviorNotes> {
List<CustomerBehaviorNotes> selectByActivityIdAndTime(@Param("activityId") Integer activityId,@Param("startTime") Long startTime,@Param("endTime") Long endTime);
long selectAppVvisitsByType(@Param("code") int code);
}
......@@ -21,13 +21,13 @@ import java.util.Objects;
* @data 2019/8/12 14:14
*/
@RestController
@RequestMapping("customerBehaviorNotes")
@RequestMapping("/customerBehaviorNotes")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerBehaviorNotesController {
private final CustomerBehaviorNotesBiz customerBehaviorNotesBiz;
@PostMapping("app/unauth/save")
@PostMapping("/app/unauth/save")
public ObjectRestResponse<Void> saveCustomerBehavior(@RequestBody CustomerBehaviorNoteDTO customerBehaviorNoteDTO, AppUserDTO appUserDTO) {
if (Objects.nonNull(appUserDTO.getUserid())) {
customerBehaviorNoteDTO.setCustomerId(String.valueOf(appUserDTO.getUserid()));
......
......@@ -26,4 +26,8 @@
and <![CDATA[ `crt_time` <= #{endTime}]]>
</if>
</select>
<select id="selectAppVvisitsByType" resultType="long">
select count(id) from `customer_behavior_notes` where `type`=#{code}
</select>
</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