排名推送相关
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.fangjia.job.common.base;
|
||||||
|
|
||||||
|
public class FangjiaConstant {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CitySendLog的推送类型 0.置顶咨询推送,1.小区推送 2.涨幅排行推送 3.跌幅排行推送 4.潜力排行推送
|
||||||
|
*/
|
||||||
|
public static final byte NEWS_SEND_TYPE = 0;
|
||||||
|
|
||||||
|
public static final byte HOUSING_ESTATE_SEND_TYPE = 1;
|
||||||
|
|
||||||
|
public static final byte INCREASE_SEND_TYPE = 2;
|
||||||
|
|
||||||
|
public static final byte DECLINES_SEND_TYPE = 3;
|
||||||
|
|
||||||
|
public static final byte POTENTIAL_SEND_TYPE = 4;
|
||||||
|
|
||||||
|
public static String FANGJIA_API_TOKEN = "F54F52381C49BB9EB4A33EB1B65604AE4B71A28AEE53518A94A2F360408B9056D57553931D15CE6DDE765562DAD286BA38E05A4CDAFC51C3D527A4959BF8E75A3B95DB7108FCEA340DDE61925616DB55118E1851E67D83EAD800460D100D6B667A4ED8EE67C8F7FB";
|
||||||
|
|
||||||
|
public static final int SUCCESS_RESPONSE_CODE = 200;
|
||||||
|
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
package com.fangjia.job.youfang.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CityNewPriceDto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上涨数量
|
||||||
|
*/
|
||||||
|
private Integer upCount;
|
||||||
|
/**
|
||||||
|
* 下跌量
|
||||||
|
*/
|
||||||
|
private Integer downCount;
|
||||||
|
/**
|
||||||
|
* 平均上涨幅度
|
||||||
|
*/
|
||||||
|
private Double avgUp;
|
||||||
|
/**
|
||||||
|
* 平均下跌幅度
|
||||||
|
*/
|
||||||
|
private Double avgDown;
|
||||||
|
|
||||||
|
private List<CityStatInfoDto> rets;
|
||||||
|
|
||||||
|
private List<RegionSellStatDto> regionRets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 城市年涨跌幅
|
||||||
|
*/
|
||||||
|
private Double yoy;
|
||||||
|
|
||||||
|
public Integer getUpCount() {
|
||||||
|
return upCount;
|
||||||
|
}
|
||||||
|
public void setUpCount(Integer upCount) {
|
||||||
|
this.upCount = upCount;
|
||||||
|
}
|
||||||
|
public Integer getDownCount() {
|
||||||
|
return downCount;
|
||||||
|
}
|
||||||
|
public void setDownCount(Integer downCount) {
|
||||||
|
this.downCount = downCount;
|
||||||
|
}
|
||||||
|
public Double getAvgUp() {
|
||||||
|
return avgUp;
|
||||||
|
}
|
||||||
|
public void setAvgUp(Double avgUp) {
|
||||||
|
this.avgUp = avgUp;
|
||||||
|
}
|
||||||
|
public Double getAvgDown() {
|
||||||
|
return avgDown;
|
||||||
|
}
|
||||||
|
public void setAvgDown(Double avgDown) {
|
||||||
|
this.avgDown = avgDown;
|
||||||
|
}
|
||||||
|
public List<CityStatInfoDto> getRets() {
|
||||||
|
return rets;
|
||||||
|
}
|
||||||
|
public void setRets(List<CityStatInfoDto> rets) {
|
||||||
|
this.rets = rets;
|
||||||
|
}
|
||||||
|
public List<RegionSellStatDto> getRegionRets() {
|
||||||
|
return regionRets;
|
||||||
|
}
|
||||||
|
public void setRegionRets(List<RegionSellStatDto> regionRets) {
|
||||||
|
this.regionRets = regionRets;
|
||||||
|
}
|
||||||
|
public Double getYoy() {
|
||||||
|
return yoy;
|
||||||
|
}
|
||||||
|
public void setYoy(Double yoy) {
|
||||||
|
this.yoy = yoy;
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.fangjia.job.youfang.dto;
|
||||||
|
|
||||||
|
import com.fangjia.job.common.base.ReponseData;
|
||||||
|
|
||||||
|
public class CityNewPriceResultDto extends ReponseData {
|
||||||
|
|
||||||
|
private CityNewPriceDto result;
|
||||||
|
|
||||||
|
public CityNewPriceDto getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResult(CityNewPriceDto result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+133
@@ -0,0 +1,133 @@
|
|||||||
|
package com.fangjia.job.youfang.dto;
|
||||||
|
|
||||||
|
public class CityStatInfoDto {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String city;
|
||||||
|
private Integer statDate;
|
||||||
|
private Integer avgPrice;
|
||||||
|
private Integer index;
|
||||||
|
private Double markup;
|
||||||
|
private Double rentRate;
|
||||||
|
private Double yoyMarkup;
|
||||||
|
// 全国涨幅排名
|
||||||
|
private int rangeLevel;
|
||||||
|
// 下跌概率(用潜力指数计算,大于50的是上涨概率,小于50的用100-指数=下跌概率)
|
||||||
|
private Integer downChance;
|
||||||
|
// 是否关注该城市(定位城市数据页面使用)
|
||||||
|
private boolean follow;
|
||||||
|
|
||||||
|
public boolean isFollow() {
|
||||||
|
return follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollow(boolean follow) {
|
||||||
|
this.follow = follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDownChance() {
|
||||||
|
if (index == null) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
if (index != null && index > 50) {
|
||||||
|
this.downChance = index;
|
||||||
|
} else {
|
||||||
|
this.downChance = 100 - index;
|
||||||
|
}
|
||||||
|
return downChance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownChance(Integer downChance) {
|
||||||
|
this.downChance = downChance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRangeLevel() {
|
||||||
|
return rangeLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRangeLevel(int rangeLevel) {
|
||||||
|
this.rangeLevel = rangeLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStatDate() {
|
||||||
|
return statDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatDate(Integer statDate) {
|
||||||
|
this.statDate = statDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAvgPrice() {
|
||||||
|
if (avgPrice == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return avgPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvgPrice(Integer avgPrice) {
|
||||||
|
this.avgPrice = avgPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIndex() {
|
||||||
|
if (index == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(Integer index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getMarkup() {
|
||||||
|
if (markup == null) {
|
||||||
|
return 0D;
|
||||||
|
}
|
||||||
|
return markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkup(Double markup) {
|
||||||
|
this.markup = markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getRentRate() {
|
||||||
|
return rentRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRentRate(Double rentRate) {
|
||||||
|
this.rentRate = rentRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getYoyMarkup() {
|
||||||
|
return yoyMarkup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYoyMarkup(Double yoyMarkup) {
|
||||||
|
this.yoyMarkup = yoyMarkup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 为实现深copy
|
||||||
|
@Override
|
||||||
|
public CityStatInfoDto clone() throws CloneNotSupportedException {
|
||||||
|
CityStatInfoDto dto = null;
|
||||||
|
dto = (CityStatInfoDto) super.clone();
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
package com.fangjia.job.youfang.dto;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class RegionSellStatDto {
|
||||||
|
private String id;
|
||||||
|
private String city;
|
||||||
|
private String region;
|
||||||
|
private Integer avgPrice;
|
||||||
|
private Integer date;
|
||||||
|
private Date updateDate;
|
||||||
|
private Double mom;
|
||||||
|
private Double yoy;
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
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 Integer getAvgPrice() {
|
||||||
|
return avgPrice;
|
||||||
|
}
|
||||||
|
public void setAvgPrice(Integer avgPrice) {
|
||||||
|
this.avgPrice = avgPrice;
|
||||||
|
}
|
||||||
|
public Integer getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
public void setDate(Integer date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
public Date getUpdateDate() {
|
||||||
|
return updateDate;
|
||||||
|
}
|
||||||
|
public void setUpdateDate(Date updateDate) {
|
||||||
|
this.updateDate = updateDate;
|
||||||
|
}
|
||||||
|
public Double getMom() {
|
||||||
|
return mom;
|
||||||
|
}
|
||||||
|
public void setMom(Double mom) {
|
||||||
|
this.mom = mom;
|
||||||
|
}
|
||||||
|
public Double getYoy() {
|
||||||
|
return yoy;
|
||||||
|
}
|
||||||
|
public void setYoy(Double yoy) {
|
||||||
|
this.yoy = yoy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+164
-12
@@ -1,34 +1,186 @@
|
|||||||
package com.fangjia.job.youfang.job;
|
package com.fangjia.job.youfang.job;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
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.beans.factory.annotation.Value;
|
||||||
import com.dangdang.ddframe.job.api.ShardingContext;
|
import com.dangdang.ddframe.job.api.ShardingContext;
|
||||||
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||||
|
import com.fangjia.job.common.base.FangjiaConstant;
|
||||||
|
import com.fangjia.job.common.util.RestApiCallUtils;
|
||||||
|
import com.fangjia.job.youfang.document.CitySendLog;
|
||||||
|
import com.fangjia.job.youfang.dto.CityNewPriceDto;
|
||||||
|
import com.fangjia.job.youfang.dto.CityNewPriceResultDto;
|
||||||
|
import com.fangjia.job.youfang.po.CityCollect;
|
||||||
|
import com.fangjia.job.youfang.remote.FshApiRemoteService;
|
||||||
import com.fangjia.job.youfang.service.CityCollectService;
|
import com.fangjia.job.youfang.service.CityCollectService;
|
||||||
import com.fangjia.job.youfang.service.CitySendLogService;
|
import com.fangjia.job.youfang.service.CitySendLogService;
|
||||||
import com.fangjia.job.youfang.service.PushMessageService;
|
import com.fangjia.job.youfang.dto.CityStatInfoDto;
|
||||||
import com.fangjia.job.youfang.service.PushRecordMessageService;
|
|
||||||
|
|
||||||
public class CityRankingSendJob implements SimpleJob {
|
public class CityRankingSendJob implements SimpleJob {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
|
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CityCollectService cityCollectService;
|
private CityCollectService cityCollectService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CitySendLogService citySendLogService;
|
private CitySendLogService citySendLogService;
|
||||||
|
|
||||||
|
@Value("${open.url}")
|
||||||
|
private String openApiUrl;
|
||||||
|
|
||||||
|
private static final int NUM = 10;// 排名前10
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ShardingContext context) {
|
public void execute(ShardingContext context) {
|
||||||
LOG.info("城市排名推送开始,context:"+context);
|
LOG.info("城市排名推送开始,context:" + context);
|
||||||
//1.查询
|
// 1.查询
|
||||||
//2.对比
|
// 查询全部城市
|
||||||
//3.发送
|
FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, openApiUrl);
|
||||||
//4.记录
|
CityNewPriceResultDto resultDto = fshApiRemoteService.getAllCitys(FangjiaConstant.FANGJIA_API_TOKEN);
|
||||||
|
List<CityStatInfoDto> topTenList = new ArrayList<CityStatInfoDto>();
|
||||||
|
List<CityStatInfoDto> bottomTenList = new ArrayList<CityStatInfoDto>();
|
||||||
|
List<CityStatInfoDto> potentialTenList = new ArrayList<CityStatInfoDto>();
|
||||||
|
// 排序,整理出涨幅,跌幅,潜力的前10
|
||||||
|
if (null != resultDto && resultDto.getCode() == FangjiaConstant.SUCCESS_RESPONSE_CODE) {
|
||||||
|
CityNewPriceDto dto = resultDto.getResult();
|
||||||
|
if (null != dto && null != dto.getRets()) {
|
||||||
|
List<CityStatInfoDto> rets = dto.getRets();
|
||||||
|
// 涨幅排序
|
||||||
|
List<CityStatInfoDto> upList = rets.stream()
|
||||||
|
.sorted((u1, u2) -> u2.getMarkup().compareTo(u1.getMarkup())).collect(Collectors.toList());
|
||||||
|
List<CityStatInfoDto> copyList = new ArrayList<CityStatInfoDto>();
|
||||||
|
Iterator<CityStatInfoDto> upIter = upList.iterator();
|
||||||
|
try {
|
||||||
|
// 涨幅排序深复制
|
||||||
|
while (upIter.hasNext()) {
|
||||||
|
copyList.add(upIter.next().clone());
|
||||||
|
}
|
||||||
|
// 涨幅前10
|
||||||
|
topTenList = copyList.subList(0, NUM);
|
||||||
|
// 跌幅前10
|
||||||
|
bottomTenList = copyList.subList(copyList.size() - NUM, copyList.size());
|
||||||
|
Collections.reverse(bottomTenList);// 涨幅后10名倒序
|
||||||
|
// 潜力排序
|
||||||
|
List<CityStatInfoDto> potentialList = rets.stream()
|
||||||
|
.sorted((u1, u2) -> u2.getIndex().compareTo(u1.getIndex())).collect(Collectors.toList());
|
||||||
|
potentialTenList = potentialList.subList(0, NUM);
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
// 深复制失败
|
||||||
|
LOG.error("深复制失败", e);
|
||||||
|
// 涨幅前10
|
||||||
|
topTenList = upList.subList(0, NUM);
|
||||||
|
// 跌幅前10
|
||||||
|
bottomTenList = upList.subList(copyList.size() - NUM, copyList.size());
|
||||||
|
Collections.reverse(bottomTenList);// 涨幅后10名倒序
|
||||||
|
// 深复制失败,再次访问,用新list做潜力排序
|
||||||
|
CityNewPriceResultDto resultDto2 = fshApiRemoteService
|
||||||
|
.getAllCitys(FangjiaConstant.FANGJIA_API_TOKEN);
|
||||||
|
CityNewPriceDto dto2 = resultDto2.getResult();
|
||||||
|
List<CityStatInfoDto> rets2 = dto2.getRets();
|
||||||
|
// 潜力排序
|
||||||
|
List<CityStatInfoDto> potentialList = rets2.stream()
|
||||||
|
.sorted((u1, u2) -> u2.getIndex().compareTo(u1.getIndex())).collect(Collectors.toList());
|
||||||
|
potentialTenList = potentialList.subList(0, NUM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 查询用户
|
||||||
|
List<CityCollect> cityList = cityCollectService.findAll();
|
||||||
|
// 用于性能节省的变量
|
||||||
|
String cityName = "";
|
||||||
|
Integer topRankings = null;
|
||||||
|
Integer bottomRankings = null;
|
||||||
|
Integer potentialRankings = null;
|
||||||
|
// 2.对比
|
||||||
|
for (CityCollect city : cityList) {
|
||||||
|
// cityList已排序好,如果cityName不变,则使用上个排名
|
||||||
|
if (cityName.equals(city.getCity())) {
|
||||||
|
try {
|
||||||
|
baseSend(city, topRankings, FangjiaConstant.INCREASE_SEND_TYPE);
|
||||||
|
sendRankings(city, bottomRankings, FangjiaConstant.INCREASE_SEND_TYPE);
|
||||||
|
sendRankings(city, potentialRankings, FangjiaConstant.POTENTIAL_SEND_TYPE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果cityName改变,则查询替换cityName和排名
|
||||||
|
cityName = city.getCity();
|
||||||
|
try {
|
||||||
|
topRankings = sendRankings(city, topTenList, FangjiaConstant.INCREASE_SEND_TYPE);
|
||||||
|
bottomRankings = sendRankings(city, bottomTenList, FangjiaConstant.DECLINES_SEND_TYPE);
|
||||||
|
potentialRankings = sendRankings(city, potentialTenList, FangjiaConstant.POTENTIAL_SEND_TYPE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首次遍历,并返回排名,没有则返回null
|
||||||
|
*
|
||||||
|
* @param city
|
||||||
|
* @param list
|
||||||
|
* @param sendType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Integer sendRankings(CityCollect city, List<CityStatInfoDto> list, byte sendType) {
|
||||||
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
||||||
|
if ((null == sendList || sendList.isEmpty()) && !list.isEmpty()) {
|
||||||
|
for (int i = 0; i <= list.size(); i++) {
|
||||||
|
if (city.getCity().equals(list.get(i).getCity())) {
|
||||||
|
int rankings = i + 1;// 排名
|
||||||
|
baseSend(city, rankings, sendType);
|
||||||
|
return rankings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 再次遍历,直接使用上次的排名
|
||||||
|
*
|
||||||
|
* @param city
|
||||||
|
* @param rankings
|
||||||
|
* @param sendType
|
||||||
|
*/
|
||||||
|
private void sendRankings(CityCollect city, Integer rankings, byte sendType) {
|
||||||
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
||||||
|
if ((null == sendList || sendList.isEmpty()) && null != rankings) {
|
||||||
|
baseSend(city, rankings, sendType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送并保存
|
||||||
|
*
|
||||||
|
* @param city
|
||||||
|
* @param rankings
|
||||||
|
* @param sendType
|
||||||
|
*/
|
||||||
|
private void baseSend(CityCollect city, Integer rankings, byte sendType) {
|
||||||
|
String title = null;
|
||||||
|
if (FangjiaConstant.INCREASE_SEND_TYPE == sendType) {
|
||||||
|
title = "全国城市涨幅排名第" + rankings + "位";
|
||||||
|
} else if (FangjiaConstant.DECLINES_SEND_TYPE == sendType) {
|
||||||
|
title = "全国城市跌幅排名第" + rankings + "位";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
title = "全国城市潜力排名第" + rankings + "位";
|
||||||
|
}
|
||||||
|
LOG.info("全国城市涨幅(跌幅、潜力)排名推送开始,uid:" + city.getUid() + ",city:" + city.getCity());
|
||||||
|
// 发送
|
||||||
|
// TODO
|
||||||
|
// 记录
|
||||||
|
citySendLogService.save(city.getCity(), city.getUid(), 0L, sendType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-6
@@ -1,16 +1,20 @@
|
|||||||
package com.fangjia.job.youfang.job;
|
package com.fangjia.job.youfang.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
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 com.dangdang.ddframe.job.api.ShardingContext;
|
import com.dangdang.ddframe.job.api.ShardingContext;
|
||||||
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||||
|
import com.fangjia.job.common.base.FangjiaConstant;
|
||||||
|
import com.fangjia.job.youfang.document.CitySendLog;
|
||||||
|
import com.fangjia.job.youfang.po.CityCollect;
|
||||||
|
import com.fangjia.job.youfang.po.News;
|
||||||
import com.fangjia.job.youfang.service.CityCollectService;
|
import com.fangjia.job.youfang.service.CityCollectService;
|
||||||
import com.fangjia.job.youfang.service.CitySendLogService;
|
import com.fangjia.job.youfang.service.CitySendLogService;
|
||||||
import com.fangjia.job.youfang.service.NewsService;
|
import com.fangjia.job.youfang.service.NewsService;
|
||||||
import com.fangjia.job.youfang.service.PushMessageService;
|
|
||||||
import com.fangjia.job.youfang.service.PushRecordMessageService;
|
|
||||||
|
|
||||||
public class HousingEstateNewsSendJob implements SimpleJob {
|
public class HousingEstateNewsSendJob implements SimpleJob {
|
||||||
|
|
||||||
@@ -28,10 +32,48 @@ public class HousingEstateNewsSendJob implements SimpleJob {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(ShardingContext context) {
|
public void execute(ShardingContext context) {
|
||||||
LOG.info("城市小区推送开始,context:"+context);
|
LOG.info("城市小区推送开始,context:"+context);
|
||||||
//1.查询
|
// 1.查询
|
||||||
//2.对比
|
List<CityCollect> cityList = cityCollectService.findAll();
|
||||||
//3.发送
|
String cityName = "";
|
||||||
//4.记录
|
List<News> newsList = null;
|
||||||
|
// 2.对比
|
||||||
|
for (CityCollect city : cityList) {
|
||||||
|
// cityList已排序好,如果cityName不变,则使用上个newsList
|
||||||
|
if (cityName.equals(city.getCity())) {
|
||||||
|
try {
|
||||||
|
sendNews(city, newsList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果cityName改变,则查询替换cityName和newsList
|
||||||
|
cityName = city.getCity();
|
||||||
|
newsList = newsService.findHousingEstate(cityName);
|
||||||
|
try {
|
||||||
|
sendNews(city, newsList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNews(CityCollect city, List<News> newsList) {
|
||||||
|
if (null != newsList && !newsList.isEmpty()) {
|
||||||
|
for (News n : newsList) {
|
||||||
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
||||||
|
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
|
||||||
|
// 未推送过的推送
|
||||||
|
if (null == sendList || sendList.isEmpty()) {
|
||||||
|
LOG.info("小区推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
|
||||||
|
// 3.发送
|
||||||
|
// TODO
|
||||||
|
// 4.记录
|
||||||
|
citySendLogService.save(city.getCity(), city.getUid(), n.getId(), FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-12
@@ -1,37 +1,77 @@
|
|||||||
package com.fangjia.job.youfang.job;
|
package com.fangjia.job.youfang.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
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 com.dangdang.ddframe.job.api.ShardingContext;
|
import com.dangdang.ddframe.job.api.ShardingContext;
|
||||||
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||||
|
import com.fangjia.job.common.base.FangjiaConstant;
|
||||||
|
import com.fangjia.job.youfang.document.CitySendLog;
|
||||||
|
import com.fangjia.job.youfang.po.CityCollect;
|
||||||
|
import com.fangjia.job.youfang.po.News;
|
||||||
import com.fangjia.job.youfang.service.CityCollectService;
|
import com.fangjia.job.youfang.service.CityCollectService;
|
||||||
import com.fangjia.job.youfang.service.CitySendLogService;
|
import com.fangjia.job.youfang.service.CitySendLogService;
|
||||||
import com.fangjia.job.youfang.service.NewsService;
|
import com.fangjia.job.youfang.service.NewsService;
|
||||||
import com.fangjia.job.youfang.service.PushMessageService;
|
|
||||||
import com.fangjia.job.youfang.service.PushRecordMessageService;
|
|
||||||
|
|
||||||
public class TopNewsSendJob implements SimpleJob {
|
public class TopNewsSendJob implements SimpleJob {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
|
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CityCollectService cityCollectService;
|
private CityCollectService cityCollectService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CitySendLogService citySendLogService;
|
private CitySendLogService citySendLogService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NewsService newsService;
|
private NewsService newsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ShardingContext context) {
|
public void execute(ShardingContext context) {
|
||||||
LOG.info("城市置顶咨询推送开始,context:"+context);
|
LOG.info("城市置顶咨询推送开始,context:" + context);
|
||||||
//1.查询
|
// 1.查询
|
||||||
//2.对比
|
List<CityCollect> cityList = cityCollectService.findAll();
|
||||||
//3.发送
|
String cityName = "";
|
||||||
//4.记录
|
List<News> newsList = null;
|
||||||
|
// 2.对比
|
||||||
|
for (CityCollect city : cityList) {
|
||||||
|
// cityList已排序好,如果cityName不变,则使用上个newsList
|
||||||
|
if (cityName.equals(city.getCity())) {
|
||||||
|
try {
|
||||||
|
sendNews(city, newsList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果cityName改变,则查询替换cityName和newsList
|
||||||
|
cityName = city.getCity();
|
||||||
|
newsList = newsService.findTopNews(cityName);
|
||||||
|
try {
|
||||||
|
sendNews(city, newsList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("推送失败!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNews(CityCollect city, List<News> newsList) {
|
||||||
|
if (null != newsList && !newsList.isEmpty()) {
|
||||||
|
for (News n : newsList) {
|
||||||
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
||||||
|
FangjiaConstant.NEWS_SEND_TYPE);
|
||||||
|
// 未推送过的推送
|
||||||
|
if (null == sendList || sendList.isEmpty()) {
|
||||||
|
LOG.info("新闻推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
|
||||||
|
// 3.发送
|
||||||
|
// TODO
|
||||||
|
// 4.记录
|
||||||
|
citySendLogService.save(city.getCity(), city.getUid(), n.getId(), FangjiaConstant.NEWS_SEND_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-14
@@ -6,6 +6,7 @@ import com.fangjia.job.common.base.Response;
|
|||||||
import com.fangjia.job.youfang.document.DistrictEvaluateSingleDto;
|
import com.fangjia.job.youfang.document.DistrictEvaluateSingleDto;
|
||||||
import com.fangjia.job.youfang.document.DistrictInfoDto;
|
import com.fangjia.job.youfang.document.DistrictInfoDto;
|
||||||
import com.fangjia.job.youfang.document.DistrictSearchSingleDto;
|
import com.fangjia.job.youfang.document.DistrictSearchSingleDto;
|
||||||
|
import com.fangjia.job.youfang.dto.CityNewPriceResultDto;
|
||||||
import com.fangjia.job.youfang.dto.DistrictDetailDto;
|
import com.fangjia.job.youfang.dto.DistrictDetailDto;
|
||||||
|
|
||||||
import feign.Param;
|
import feign.Param;
|
||||||
@@ -14,66 +15,77 @@ import feign.RequestLine;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* API调用接口定义
|
* API调用接口定义
|
||||||
|
*
|
||||||
* @author yinjihuan
|
* @author yinjihuan
|
||||||
*/
|
*/
|
||||||
public interface FshApiRemoteService {
|
public interface FshApiRemoteService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送月涨幅计算通知
|
* 发送月涨幅计算通知
|
||||||
|
*
|
||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /rest/houses/rose/month?token={token}")
|
@RequestLine("GET /rest/houses/rose/month?token={token}")
|
||||||
public Response sendHouseRoseMonthNotice(@Param("token")String token);
|
public Response sendHouseRoseMonthNotice(@Param("token") String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送租金提醒计算通知
|
* 发送租金提醒计算通知
|
||||||
|
*
|
||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /rest/houses/rent/notice?token={token}")
|
@RequestLine("GET /rest/houses/rent/notice?token={token}")
|
||||||
public Response sendHouseRentNotice(@Param("token")String token);
|
public Response sendHouseRentNotice(@Param("token") String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时估价操作,并算出周涨跌幅通知
|
* 定时估价操作,并算出周涨跌幅通知
|
||||||
|
*
|
||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /rest/houses/eval?token={token}")
|
@RequestLine("GET /rest/houses/eval?token={token}")
|
||||||
public Response evalAllHousePrice(@Param("token")String token);
|
public Response evalAllHousePrice(@Param("token") String token);
|
||||||
|
|
||||||
@RequestLine("GET /fsh/getAgencyInfo")
|
@RequestLine("GET /fsh/getAgencyInfo")
|
||||||
public Map<String,Object> getAgencyInfo(@QueryMap Map<String, Object> queryMap);
|
public Map<String, Object> getAgencyInfo(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取小区综合信息district_new_price
|
* 获取小区综合信息district_new_price
|
||||||
|
*
|
||||||
* @param queryMap
|
* @param queryMap
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /fsh/getDistrictNewPriceInfo")
|
@RequestLine("GET /fsh/getDistrictNewPriceInfo")
|
||||||
public DistrictEvaluateSingleDto getDistrictNewPriceInfo(@QueryMap Map<String, Object> queryMap);
|
public DistrictEvaluateSingleDto getDistrictNewPriceInfo(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小区详情
|
* 小区详情
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /fsh/detail")
|
@RequestLine("GET /fsh/detail")
|
||||||
public DistrictInfoDto detail(@QueryMap Map<String, Object> queryMap);
|
public DistrictInfoDto detail(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
//小区估价接口
|
// 小区估价接口
|
||||||
@RequestLine("GET /fsh/evaluate")
|
@RequestLine("GET /fsh/evaluate")
|
||||||
public DistrictSearchSingleDto evaluate(@QueryMap Map<String, Object> queryMap);
|
public DistrictSearchSingleDto evaluate(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新小区详情页面缓存数据
|
* 刷新小区详情页面缓存数据
|
||||||
|
*
|
||||||
* @param queryMap
|
* @param queryMap
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /district/details")
|
@RequestLine("GET /district/details")
|
||||||
public String refreshDistrictDetailPageData(@QueryMap Map<String, Object> queryMap);
|
public String refreshDistrictDetailPageData(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小区信息汇总
|
* 小区信息汇总
|
||||||
*/
|
*/
|
||||||
@RequestLine("GET /fsh/districtDetail")
|
@RequestLine("GET /fsh/districtDetail")
|
||||||
public DistrictDetailDto districtDetail(@QueryMap Map<String, Object> queryMap);
|
public DistrictDetailDto districtDetail(@QueryMap Map<String, Object> queryMap);
|
||||||
|
|
||||||
|
// 城市列表
|
||||||
|
@RequestLine("GET /quotations/cityList?token={token}")
|
||||||
|
public CityNewPriceResultDto getAllCitys(@Param("token") String token);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import com.fangjia.job.youfang.document.CitySendLog;
|
|||||||
|
|
||||||
public interface CitySendLogService {
|
public interface CitySendLogService {
|
||||||
|
|
||||||
void save(CitySendLog log);
|
void save(String city, Long uid, Long nId, byte sendType);
|
||||||
|
|
||||||
List<CitySendLog> find(long uid, Long newsId, Byte sendType);
|
List<CitySendLog> find(long uid, Long newsId, Byte sendType);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -1,4 +1,5 @@
|
|||||||
package com.fangjia.job.youfang.service;
|
package com.fangjia.job.youfang.service;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -18,7 +19,13 @@ public class CitySendLogServiceImpl implements CitySendLogService {
|
|||||||
private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(CitySendLog log) {
|
public void save(String city, Long uid, Long nId, byte sendType) {
|
||||||
|
CitySendLog log = new CitySendLog();
|
||||||
|
log.setCity(city);
|
||||||
|
log.setNewsId(nId);
|
||||||
|
log.setSendTime(new Date());
|
||||||
|
log.setSendType(sendType);
|
||||||
|
log.setUid(uid);
|
||||||
mongoTemplate.save(log);
|
mongoTemplate.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user