+98
@@ -0,0 +1,98 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 用户资产排名
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
@Document(collection="user_assets_level")
|
||||
public class UserAssetsLevel {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Field("uid")
|
||||
private Long uid;
|
||||
|
||||
/**
|
||||
* 用户名(有昵称就显示昵称,无就用手机号码中间4为格式化成*,比如:182****2009)
|
||||
*/
|
||||
@Field("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排名
|
||||
*/
|
||||
@Field("level")
|
||||
private int level;
|
||||
|
||||
/**
|
||||
* 资产总额(万元)
|
||||
*/
|
||||
@Field("assets")
|
||||
private double assets;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Field("m_time")
|
||||
private Date modifyTime;
|
||||
|
||||
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 getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public double getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
public void setAssets(double assets) {
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
public Date getModifyTime() {
|
||||
return modifyTime;
|
||||
}
|
||||
|
||||
public void setModifyTime(Date modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.fangjia.job.youfang.job;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
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.data.mongodb.core.query.Update;
|
||||
|
||||
import com.cxytiandi.jdbc.Orders;
|
||||
import com.cxytiandi.jdbc.Orders.OrderyType;
|
||||
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.DataUtil;
|
||||
import com.fangjia.job.common.util.DingDingMessageUtil;
|
||||
import com.fangjia.job.youfang.document.UserAssetsLevel;
|
||||
import com.fangjia.job.youfang.po.EnterpriseProductUser;
|
||||
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
|
||||
import com.fangjia.job.youfang.service.HouseInfoService;
|
||||
|
||||
/**
|
||||
* 用户资产排名任务,每天统计一次<br>
|
||||
* 根据用户管理的房产的总价值来进行排名
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class UserAssetsLevelJob implements SimpleJob {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(UserAssetsLevelJob.class);
|
||||
|
||||
@Autowired
|
||||
private EnterpriseProductUserService enterpriseProductUserService;
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Autowired
|
||||
private HouseInfoService houseInfoService;
|
||||
|
||||
@Override
|
||||
public void execute(ShardingContext shardingContext) {
|
||||
logger.info("开始执行UserAssetsLevelJob");
|
||||
long total = enterpriseProductUserService.queryCount();
|
||||
int pages = PageBean.calcPages(total, 1000);
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
List<EnterpriseProductUser> users = enterpriseProductUserService.queryByPage(i, 1000);
|
||||
for (EnterpriseProductUser user : users) {
|
||||
try {
|
||||
processStat(user);
|
||||
} catch (Exception e) {
|
||||
logger.error("用户资产排名任务异常", e);
|
||||
DingDingMessageUtil.sendTextMessage("用户资产排名任务异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 更新排名
|
||||
Query query = new Query();
|
||||
query.fields().include("_id");
|
||||
query.with(new Sort(new Order(Direction.DESC, "assets")));
|
||||
List<UserAssetsLevel> list = mongoTemplate.find(query, UserAssetsLevel.class);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
mongoTemplate.updateFirst(Query.query(Criteria.where("_id").is(list.get(i).getId())), Update.update("level", i + 1), UserAssetsLevel.class);
|
||||
}
|
||||
logger.info("UserAssetsLevelJob执行结束");
|
||||
}
|
||||
|
||||
private void processStat(EnterpriseProductUser user) {
|
||||
UserAssetsLevel level = mongoTemplate.findOne(Query.query(Criteria.where("uid").is(user.getId())), UserAssetsLevel.class);
|
||||
if (level == null) {
|
||||
level = new UserAssetsLevel();
|
||||
}
|
||||
level.setUid(user.getId());
|
||||
level.setModifyTime(new Date());
|
||||
String name = "未知";
|
||||
if (StringUtils.isNotBlank(user.getWechatNickname())) {
|
||||
name = user.getWechatNickname();
|
||||
} else {
|
||||
if(StringUtils.isNotBlank(user.getMobile())){
|
||||
name = user.getMobile().replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
|
||||
}
|
||||
}
|
||||
level.setName(name);
|
||||
Long totalMoney = houseInfoService.queryUserManagerHouseTotalPrice(1L, user.getId()+"");
|
||||
level.setAssets(DataUtil.getDoubleRound(2, totalMoney / 10000D));
|
||||
mongoTemplate.save(level);
|
||||
}
|
||||
}
|
||||
+7
@@ -99,4 +99,11 @@ public interface HouseInfoService {
|
||||
*/
|
||||
HouseInfo findHighLevelHouseInfo(Long eid, String uid);
|
||||
|
||||
/**
|
||||
* 查询用户自己管理的有效房产总价值
|
||||
* @param eid
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
Long queryUserManagerHouseTotalPrice(Long eid, String uid);
|
||||
}
|
||||
|
||||
+10
@@ -112,5 +112,15 @@ public class HouseInfoServiceImpl extends EntityService<HouseInfo> implements Ho
|
||||
return super.getByParams(new String[] { "level" }, new String[] { "eid", "uid" ,"remove_status"},
|
||||
new Object[] { eid, uid, 0 }, HouseInfo.level_orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long queryUserManagerHouseTotalPrice(Long eid, String uid) {
|
||||
String sql = "select sum(total_price) from house_info where eid = ? and uid = ? and remove_status = 0 and house_status = 0";
|
||||
Long sum = super.getJdbcTemplate().queryForObject(sql, Long.class, new Object[] { eid, uid });
|
||||
if (sum == null) {
|
||||
return 0L;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,4 +133,14 @@
|
||||
|
||||
</job:simple>
|
||||
|
||||
<!-- 用户资产排名任务,每天统计一次, 根据用户管理的房产的总价值来进行排名 -->
|
||||
<job:simple id="userAssetsLevelJob" class="com.fangjia.job.youfang.job.UserAssetsLevelJob" registry-center-ref="regCenter"
|
||||
sharding-total-count="1" cron="0 30 0 * * ?" sharding-item-parameters=""
|
||||
failover="true" description="【有房】 用户资产排名任务,每天统计一次, 根据用户管理的房产的总价值来进行排名"
|
||||
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