Browse Source

打标签任务

release_toaliyun_real
xiaohanzi 5 years ago
parent
commit
45222acd0a
4 changed files with 116 additions and 24 deletions
  1. +3
    -0
      mallinkAdmin/src/main/resources/db/migration/V202009161600__ppsRegulator.sql
  2. +61
    -18
      mallinkSchedule/src/main/java/com/iformall/schedule/WxCUserTagsSchedule.java
  3. +12
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java
  4. +40
    -5
      mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml

+ 3
- 0
mallinkAdmin/src/main/resources/db/migration/V202009161600__ppsRegulator.sql View File

@@ -13,3 +13,6 @@ from mall_user_info mui
left join mall_user_role mur on mui.id = mur.uid left join mall_user_role mur on mui.id = mur.uid
where mui.is_admin = 1 and mur.role_id is not null GROUP BY mur.role_id; where mui.is_admin = 1 and mur.role_id is not null GROUP BY mur.role_id;


ALTER TABLE `wx_c_user_basic_info`
ADD COLUMN `tag_scan_time` DATETIME COMMENT '标签定时扫描时间';


+ 61
- 18
mallinkSchedule/src/main/java/com/iformall/schedule/WxCUserTagsSchedule.java View File

@@ -1,16 +1,24 @@
package com.iformall.schedule; package com.iformall.schedule;


import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCUserBasicInfo;
import com.iformall.enums.EnumAssignTagsTrigger;
import com.iformall.service.WxCUserBasicInfoService;
import com.iformall.service.WxCUserTagsService;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;


import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCUserBasicInfo;
import com.iformall.domain.po.WxMall;
import com.iformall.enums.EnumAssignTagsTrigger;
import com.iformall.service.WxCUserBasicInfoService;
import com.iformall.service.WxCUserTagsService;
import com.iformall.service.WxMallService;



@Component @Component
public class WxCUserTagsSchedule { public class WxCUserTagsSchedule {
@@ -21,22 +29,57 @@ public class WxCUserTagsSchedule {


@Autowired @Autowired
WxCUserBasicInfoService wxCUserBasicInfoService; WxCUserBasicInfoService wxCUserBasicInfoService;
@Autowired
WxMallService wxMallService;


// TODO 先不执行打标签操作了, 数据量太大,导致数据库CPU 100% // TODO 先不执行打标签操作了, 数据量太大,导致数据库CPU 100%
//@Scheduled(cron = "0 0 0 25 * ?") // 每月25日凌晨01:00对会员列表扫描补录标签 //@Scheduled(cron = "0 0 0 25 * ?") // 每月25日凌晨01:00对会员列表扫描补录标签
//@Scheduled(cron = "0 */5 * * * ?") // 测试1分钟一次
@Scheduled(cron = "0 0 2 * * ?") // 测试1分钟一次
public void wxCUserTagsSchedule() { public void wxCUserTagsSchedule() {
WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo();

int pageIndex = 1;
final int pageSize = 1000;

PageInfo page;
do{
page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageIndex++, pageSize);
page.getList().stream().forEach(cubi -> {
wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_SCAN, cubi);
});
} while ((page.isHasNextPage()));
WxMall wxMall = new WxMall();
List<WxMall> malls = wxMallService.findList(wxMall);
for (WxMall mall : malls) {
WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo();
if (StringUtils.isBlank(mall.getParentTenantId())) {
wxCUserBasicInfo.setFinalTenantId(mall.getTenantId());
}else {
wxCUserBasicInfo.setFinalTenantId(mall.getParentTenantId());
}
Date curDate = new Date();
Calendar startC = Calendar.getInstance();
startC.setTime(curDate);
startC.add(Calendar.DAY_OF_YEAR, -30);
Calendar endC = Calendar.getInstance();
endC.setTime(curDate);
endC.add(Calendar.DAY_OF_YEAR, -5);
//5天内未扫描的,且只扫描1个月内未扫描的
wxCUserBasicInfo.setScanStartTime(startC.getTime());
wxCUserBasicInfo.setScanEndTime(endC.getTime());
//活跃时间在10天内的
Calendar startA = Calendar.getInstance();
startA.setTime(curDate);
startA.add(Calendar.DAY_OF_YEAR, -10);
wxCUserBasicInfo.setActiveStartTime(startA.getTime());
wxCUserBasicInfo.setActiveEndTime(curDate);
int pageIndex = 1;
final int pageSize = 5000;

PageInfo page;
do{
page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageIndex++, pageSize);
page.getList().stream().forEach(cubi -> {
try {
wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_SCAN, cubi);
}catch(Exception e) {
logger.error("wxCUserTagsSchedule error."+cubi.toString(),e);
}
});
} while ((page.isHasNextPage()));
}
} }
} }

+ 12
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java View File

@@ -73,6 +73,10 @@ public class WxCUserBasicInfo extends TenantEntity {
@Excel(name="上次活跃时间",width = 20,format="yyyy-MM-dd", orderNum = "8") @Excel(name="上次活跃时间",width = 20,format="yyyy-MM-dd", orderNum = "8")
@io.swagger.annotations.ApiModelProperty(value="上次活跃时间",name="activeTime") @io.swagger.annotations.ApiModelProperty(value="上次活跃时间",name="activeTime")
private Date activeTime; private Date activeTime;
@TableField(exist = false)
private Date activeStartTime;
@TableField(exist = false)
private Date activeEndTime;


@Excel(name="注册时间",width = 20,format="yyyy-MM-dd", orderNum = "9") @Excel(name="注册时间",width = 20,format="yyyy-MM-dd", orderNum = "9")
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
@@ -106,9 +110,16 @@ public class WxCUserBasicInfo extends TenantEntity {


@io.swagger.annotations.ApiModelProperty(value = "状态0正常1锁定", name = "status") @io.swagger.annotations.ApiModelProperty(value = "状态0正常1锁定", name = "status")
private Integer status; private Integer status;
@io.swagger.annotations.ApiModelProperty(value = "标签扫描时间", name = "tagScanTime")
private Date tagScanTime;
@TableField(exist = false)
private Date scanStartTime;
@TableField(exist = false)
private Date scanEndTime;


@TableField(exist = false) @TableField(exist = false)
//@Excel(name="标签",width = 50,orderNum = "10")
@Excel(name="标签",width = 50,orderNum = "10")
private String tagNames; private String tagNames;






+ 40
- 5
mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml View File

@@ -26,13 +26,13 @@
<result column="act_record" jdbcType="INTEGER" property="actRecord"/> <result column="act_record" jdbcType="INTEGER" property="actRecord"/>
<result column="score_date" jdbcType="TIMESTAMP" property="scoreDate"/> <result column="score_date" jdbcType="TIMESTAMP" property="scoreDate"/>
<result column="status" jdbcType="INTEGER" property="status"/> <result column="status" jdbcType="INTEGER" property="status"/>
<result column="tag_scan_time" jdbcType="TIMESTAMP" property="tagScanTime"/>
</resultMap> </resultMap>


<sql id="allColumns"> <sql id="allColumns">
distinct wcubi.`id`,wcubi.`phone`,wcubi.`birthdate`,wcubi.`education`,wcubi.`sex`,wcubi.`email`, distinct wcubi.`id`,wcubi.`phone`,wcubi.`birthdate`,wcubi.`education`,wcubi.`sex`,wcubi.`email`,
wcubi.`address`,wcubi.`poins`,wcubi.`tag_id`,wcubi.`create_date`,wcubi.`update_date`, wcubi.`address`,wcubi.`poins`,wcubi.`tag_id`,wcubi.`create_date`,wcubi.`update_date`,
wcubi.`final_tenant_id`,wcubi.`name`,wcubi.`nick_name`,
wcubi.`final_tenant_id`,wcubi.`name`,wcubi.`nick_name`,wcubi.`tag_scan_time`,
wcubi.`avatar_url`,wcubi.`credit`,wcubi.`active_time`,wcubi.`login_count`,wcubi.`act_record` wcubi.`avatar_url`,wcubi.`credit`,wcubi.`active_time`,wcubi.`login_count`,wcubi.`act_record`
,(select level from wx_level_config ,(select level from wx_level_config
where poins >= points and tenant_id=wcubi.final_tenant_id where poins >= points and tenant_id=wcubi.final_tenant_id
@@ -40,7 +40,7 @@
</sql> </sql>
<sql id="allSimpleColumns"> <sql id="allSimpleColumns">
`id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`,
`id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`,`tag_scan_time`,
`create_date`,`update_date`,`tenant_id`,`parent_tenant_id`,`name`,`nick_name`,`credit`,`active_time`,`act_record` `create_date`,`update_date`,`tenant_id`,`parent_tenant_id`,`name`,`nick_name`,`credit`,`active_time`,`act_record`
</sql> </sql>


@@ -109,6 +109,14 @@
<if test=" null != startTime and null!=endTime"> <if test=" null != startTime and null!=endTime">
and wcubi.`create_date` between #{startTime} and #{endTime} and wcubi.`create_date` between #{startTime} and #{endTime}
</if> </if>

<if test=" null != scanStartTime and null!=scanEndTime">
and wcubi.`tag_scan_time` between #{scanStartTime} and #{scanEndTime}
</if>
<if test=" null != activeStartTime and null!=activeEndTime">
and wcubi.`active_time` between #{activeStartTime} and #{activeEndTime}
</if>
<if test=" null != status "> <if test=" null != status ">
and wcubi.`status` = #{status} and wcubi.`status` = #{status}
@@ -204,6 +212,14 @@
and wcubi.`create_date` between #{basicInfo.startTime} and #{basicInfo.endTime} and wcubi.`create_date` between #{basicInfo.startTime} and #{basicInfo.endTime}
</if> </if>


<if test=" null != scanStartTime and null!=scanEndTime">
and wcubi.`tag_scan_time` between #{scanStartTime} and #{scanEndTime}
</if>
<if test=" null != activeStartTime and null!=activeEndTime">
and wcubi.`active_time` between #{activeStartTime} and #{activeEndTime}
</if>
<if test=" null != basicInfo.status "> <if test=" null != basicInfo.status ">
and wcubi.`status` = #{basicInfo.status} and wcubi.`status` = #{basicInfo.status}
</if> </if>
@@ -390,7 +406,7 @@


<sql id="allColumnsOfScoreList"> <sql id="allColumnsOfScoreList">
distinct cub.id,cub.phone,cub.birthdate,cub.education,cub.sex,cub.email,cub.address,cub.poins,cub.tag_id, distinct cub.id,cub.phone,cub.birthdate,cub.education,cub.sex,cub.email,cub.address,cub.poins,cub.tag_id,
cub.create_date,cub.update_date,cub.name,cub.level,cub.nick_name,cub.score_date,cub.final_tenant_id
cub.create_date,cub.update_date,cub.name,cub.level,cub.nick_name,cub.score_date,cub.final_tenant_id,cub.tag_scan_time
</sql> </sql>


<select id="findListByScore" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultMap="BaseResultMap"> <select id="findListByScore" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultMap="BaseResultMap">
@@ -605,11 +621,12 @@
<result column="credit" jdbcType="INTEGER" property="credit"/> <result column="credit" jdbcType="INTEGER" property="credit"/>
<result column="tags" jdbcType="VARCHAR" property="tags"/> <result column="tags" jdbcType="VARCHAR" property="tags"/>
<result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/> <result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/>
<result column="tag_scan_time" jdbcType="TIMESTAMP" property="tagScanTime"/>
</resultMap> </resultMap>


<sql id="allVoColumns"> <sql id="allVoColumns">
distinct cu.`id`,cu.`phone`,cu.`birthdate`,cu.`education`,cu.`sex`,cu.`email`,cu.`address`,cu.`poins`,cu.`tag_id`, distinct cu.`id`,cu.`phone`,cu.`birthdate`,cu.`education`,cu.`sex`,cu.`email`,cu.`address`,cu.`poins`,cu.`tag_id`,
cu.`create_date`,cu.`update_date`,cu.`name`,cu.`level`,cu.`nick_name`,
cu.`create_date`,cu.`update_date`,cu.`name`,cu.`level`,cu.`nick_name`,cu.`tag_scan_time`,
cut.`tags`,cu.`credit`,cu.`active_time`,cu.`act_record`,cu.`final_tenant_id` cut.`tags`,cu.`credit`,cu.`active_time`,cu.`act_record`,cu.`final_tenant_id`
</sql> </sql>


@@ -674,6 +691,15 @@
<if test=" null != startTime and null!=endTime"> <if test=" null != startTime and null!=endTime">
and cu.`create_date` between #{startTime} and #{endTime} and cu.`create_date` between #{startTime} and #{endTime}
</if> </if>
<if test=" null != scanStartTime and null!=scanEndTime">
and wcubi.`tag_scan_time` between #{scanStartTime} and #{scanEndTime}
</if>
<if test=" null != activeStartTime and null!=activeEndTime">
and wcubi.`active_time` between #{activeStartTime} and #{activeEndTime}
</if>
<if test=" null != ids "> <if test=" null != ids ">
and cu.id in and cu.id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
@@ -745,6 +771,15 @@
<if test=" null != basicInfo.startTime and null != basicInfo.endTime"> <if test=" null != basicInfo.startTime and null != basicInfo.endTime">
and cu.`create_date` between #{basicInfo.startTime} and #{basicInfo.endTime} and cu.`create_date` between #{basicInfo.startTime} and #{basicInfo.endTime}
</if> </if>
<if test=" null != scanStartTime and null!=scanEndTime">
and wcubi.`tag_scan_time` between #{scanStartTime} and #{scanEndTime}
</if>
<if test=" null != activeStartTime and null!=activeEndTime">
and wcubi.`active_time` between #{activeStartTime} and #{activeEndTime}
</if>
<if test=" null != basicInfo.ids "> <if test=" null != basicInfo.ids ">
and cu.id in and cu.id in
<foreach collection="basicInfo.ids" index="index" item="idItem" open="(" separator="," close=")"> <foreach collection="basicInfo.ids" index="index" item="idItem" open="(" separator="," close=")">


Loading…
Cancel
Save