统计非注册用户信息任务
This commit is contained in:
+196
@@ -0,0 +1,196 @@
|
||||
package com.fangjia.job.youfang.document;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
/**
|
||||
* APP页面访问日志
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
@Document(collection="page_log")
|
||||
public class PageLog {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Field("uid")
|
||||
private Long uid;
|
||||
|
||||
/**
|
||||
* 访问的页面
|
||||
*/
|
||||
@Field("page")
|
||||
private String page;
|
||||
|
||||
/**
|
||||
* 访问时间
|
||||
*/
|
||||
@Field("c_date")
|
||||
private Date createDate;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
@Field("lng")
|
||||
private Double lng;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
@Field("lat")
|
||||
private Double lat;
|
||||
|
||||
/**
|
||||
* 省份
|
||||
*/
|
||||
@Field("province")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
@Field("city")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 区域
|
||||
*/
|
||||
@Field("region")
|
||||
private String region;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
@Field("addr")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 设备
|
||||
*/
|
||||
@Field("device")
|
||||
private String device;
|
||||
|
||||
/**
|
||||
* 型号
|
||||
*/
|
||||
@Field("model")
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 个推ID
|
||||
*/
|
||||
@Field("pcid")
|
||||
private String pushClientId;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(String page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public Double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng(Double lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public Double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(Double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(String device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getPushClientId() {
|
||||
return pushClientId;
|
||||
}
|
||||
|
||||
public void setPushClientId(String pushClientId) {
|
||||
this.pushClientId = pushClientId;
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.fangjia.job.youfang.document;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* 未注册用户
|
||||
*
|
||||
* @author zongzhimin
|
||||
*
|
||||
*/
|
||||
@Document(collection = "no_reg_upush_info")
|
||||
public class UnregisterUser {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
/**
|
||||
* 推送Id
|
||||
*/
|
||||
private String pid;
|
||||
/**
|
||||
* 设备Id
|
||||
*/
|
||||
private String device;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(String device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.fangjia.job.youfang.job;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import com.cxytiandi.jdbc.util.DateUtils;
|
||||
import com.cxytiandi.jdbc.util.PageBean;
|
||||
import com.dangdang.ddframe.job.api.ShardingContext;
|
||||
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||
import com.fangjia.job.common.util.DateUtilCustom;
|
||||
import com.fangjia.job.common.util.DingDingMessageUtil;
|
||||
import com.fangjia.job.youfang.document.PageLog;
|
||||
import com.fangjia.job.youfang.document.UnregisterUser;
|
||||
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
|
||||
import com.fangjia.job.youfang.service.PageLogService;
|
||||
/**
|
||||
* 根据PV日志统计出未注册的用户设备信息和推送信息
|
||||
*
|
||||
* 每天一次
|
||||
*
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class UnregisterUserJob implements SimpleJob {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(UnregisterUserJob.class);
|
||||
|
||||
@Autowired
|
||||
private PageLogService pageLogService;
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Autowired
|
||||
private EnterpriseProductUserService enterpriseProductUserService;
|
||||
|
||||
@Override
|
||||
public void execute(ShardingContext shardingContext) {
|
||||
try {
|
||||
logger.info("开始统计非注册用户");
|
||||
Map<String, String> dateMap = DateUtilCustom.getYesterday();
|
||||
Date start = DateUtils.str2Date(dateMap.get("start"));
|
||||
Date end = DateUtils.str2Date(dateMap.get("end"));
|
||||
Long count = pageLogService.queryForCount(start, end);
|
||||
logger.info("总数量:" + count);
|
||||
int pages = PageBean.calcPages(count, 1000);
|
||||
logger.info("总页数:" + pages);
|
||||
for (int i = 0; i < pages; i++) {
|
||||
logger.info("开始处理页数:" + i);
|
||||
List<PageLog> list = pageLogService.listForPage(start, end, i, 1000);
|
||||
for (PageLog pageLog : list) {
|
||||
if (StringUtils.isNotBlank(pageLog.getPushClientId())
|
||||
&& !enterpriseProductUserService.existsByPushId(pageLog.getPushClientId())
|
||||
&& !mongoTemplate.exists(Query.query(Criteria.where("pid").is(pageLog.getPushClientId())), UnregisterUser.class)) {
|
||||
UnregisterUser data = new UnregisterUser();
|
||||
data.setDevice(pageLog.getDevice());
|
||||
data.setPid(pageLog.getPushClientId());
|
||||
mongoTemplate.save(data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
logger.info("处理结束");
|
||||
} catch (Exception e) {
|
||||
logger.error("根据PV日志统计出未注册的用户设备信息和推送信息异常", e);
|
||||
DingDingMessageUtil.sendTextMessage("根据PV日志统计出未注册的用户设备信息和推送信息异常" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -36,4 +36,10 @@ public interface EnterpriseProductUserService {
|
||||
*/
|
||||
List<EnterpriseProductUser> queryByPage(int page, int limit);
|
||||
|
||||
/**
|
||||
* 判断推送ID是否存在于注册用户中
|
||||
* @param device
|
||||
* @return
|
||||
*/
|
||||
boolean existsByPushId(String pushID);
|
||||
}
|
||||
|
||||
+5
@@ -31,4 +31,9 @@ public class EnterpriseProductUserServiceImpl extends EntityService<EnterprisePr
|
||||
return super.listForPage(start, limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByPushId(String pushID) {
|
||||
return super.exists("push_client_id", pushID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.fangjia.job.youfang.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fangjia.job.youfang.document.PageLog;
|
||||
|
||||
public interface PageLogService {
|
||||
|
||||
List<PageLog> listForPage(Date start, Date end, int page, int size);
|
||||
|
||||
Long queryForCount(Date start, Date end);
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.fangjia.job.youfang.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fangjia.job.youfang.document.PageLog;
|
||||
|
||||
@Service
|
||||
public class PageLogServiceImpl implements PageLogService {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
public List<PageLog> listForPage(Date start, Date end, int page, int size) {
|
||||
Query query = Query.query(Criteria.where("createDate").gte(start).lt(end));
|
||||
query.with(new PageRequest(page, size));
|
||||
query.fields().include("device").include("pushClientId");
|
||||
return mongoTemplate.find(query, PageLog.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long queryForCount(Date start, Date end) {
|
||||
Query query = Query.query(Criteria.where("createDate").gte(start).lt(end));
|
||||
return mongoTemplate.count(query, PageLog.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,4 +123,14 @@
|
||||
|
||||
</job:simple>-->
|
||||
|
||||
<!-- 根据PV日志统计出未注册的用户设备信息和推送信息 -->
|
||||
<job:simple id="unregisterUserJob" class="com.fangjia.job.youfang.job.UnregisterUserJob" registry-center-ref="regCenter"
|
||||
sharding-total-count="1" cron="0 10 4 * * ?" sharding-item-parameters=""
|
||||
failover="true" description="【有房】 根据PV日志统计出未注册的用户设备信息和推送信息"
|
||||
overwrite="true" event-trace-rdb-data-source="elasticJobLog" job-exception-handler="com.fangjia.job.youfang.handler.CustomJobExceptionHandler">
|
||||
|
||||
<job:listener class="com.fangjia.job.youfang.listener.MessageElasticJobListener"></job:listener>
|
||||
|
||||
</job:simple>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user