Merge branch 'FSHJOB1.2' into 'master'

Fshjob1.2

See merge request !24
This commit is contained in:
虞继恩
2018-05-23 17:47:01 +08:00
35 changed files with 1816 additions and 36 deletions
@@ -0,0 +1,28 @@
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 final int SUCCESS_RESPONSE_CODE = 200;
public static final int SEND_THREAD_NUM = 100;
public static final int OPEN_APP_TYPE = 0;
public static final int URL_SEND_TYPE = 2;
public static final int SEND_ERROR_LIMIT = 3; //失败尝试的上限
}
@@ -1,5 +1,6 @@
package com.fangjia.job.common.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -128,6 +129,31 @@ public class DateUtilCustom {
return map;
}
/**
* 计算两个日期之间相差的天数
* @param smdate 较小的时间
* @param bdate 较大的时间
* @return 相差天数
* @throws ParseException
*/
public static int between(Date smdate,Date bdate) {
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
smdate=sdf.parse(sdf.format(smdate));
bdate=sdf.parse(sdf.format(bdate));
Calendar cal = Calendar.getInstance();
cal.setTime(smdate);
long time1 = cal.getTimeInMillis();
cal.setTime(bdate);
long time2 = cal.getTimeInMillis();
long between_days=(time2-time1)/(1000*3600*24);
return Integer.parseInt(String.valueOf(between_days));
} catch (Exception e) {
return -1;
}
}
public static void main(String[] args) {
System.err.println(JsonUtils.toJson(getLatelyDate(3)));
}
+5
View File
@@ -71,6 +71,11 @@
<groupId>com.cxytiandi</groupId>
<artifactId>cxytiandi-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
@@ -0,0 +1,35 @@
package com.fangjia.job.youfang.document;
import java.util.Date;
import lombok.Data;
/**
* 城市相关推送记录
*
* @author user
*
*/
@Data
public class CitySendLog {
private String city;
private long uid;
private Long newsId;
private Date sendTime;
/*
* 0.置顶咨询推送,1.小区推送 2.涨幅排行推送 3.跌幅排行推送 4.潜力排行推送
*/
private byte sendType;
// 推送次数
private int sendNum;
// 推送状态
private Boolean sendStatus;
}
@@ -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;
}
}
@@ -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;
}
}
@@ -0,0 +1,152 @@
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 CityStatInfoDto() {
}
public CityStatInfoDto(String id, String city, Integer statDate, Integer avgPrice, Integer index, Double markup,
Double rentRate, Double yoyMarkup, int rangeLevel, Integer downChance, boolean follow) {
super();
this.id = id;
this.city = city;
this.statDate = statDate;
this.avgPrice = avgPrice;
this.index = index;
this.markup = markup;
this.rentRate = rentRate;
this.yoyMarkup = yoyMarkup;
this.rangeLevel = rangeLevel;
this.downChance = downChance;
this.follow = 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 {
return new CityStatInfoDto(this.id, this.city, this.statDate, this.avgPrice, this.index, this.markup,
this.rentRate, this.yoyMarkup, this.rangeLevel, this.downChance, this.follow);
}
}
@@ -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;
}
}
@@ -0,0 +1,251 @@
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.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.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.po.EnterpriseProductUser;
import com.fangjia.job.youfang.remote.FshApiRemoteService;
import com.fangjia.job.youfang.service.CityCollectService;
import com.fangjia.job.youfang.service.CitySendLogService;
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
import com.fangjia.job.youfang.service.PushMessageService;
import com.fangjia.job.youfang.dto.CityStatInfoDto;
import com.fangjia.job.youfang.param.PushMessageParam;
public class CityRankingSendJob implements SimpleJob {
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
@Autowired
private CityCollectService cityCollectService;
@Autowired
private CitySendLogService citySendLogService;
@Autowired
private EnterpriseProductUserService enterpriseProductUserService;
@Autowired
private PushMessageService pushMessageService;
@Value("${open.url}")
private String openApiUrl;
@Value("${FANGJIA_API_TOKEN}")
private String token;
private static final int NUM = 10;// 排名前10
private static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(FangjiaConstant.SEND_THREAD_NUM);
@Override
public void execute(ShardingContext context) {
LOG.info("城市排名推送开始,context:" + context);
// 1.查询
// 查询全部城市
FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, openApiUrl);
CityNewPriceResultDto resultDto = fshApiRemoteService.getAllCitys(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(upList.size() - NUM, upList.size());
Collections.reverse(bottomTenList);// 涨幅后10名倒序
// 深复制失败,再次访问,用新list做潜力排序
CityNewPriceResultDto resultDto2 = fshApiRemoteService.getAllCitys(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())) {
THREAD_POOL.execute(new MyThread(city, topRankings, bottomRankings, potentialRankings));
} 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, null);
return rankings;
}
}
}
return null;
}
/**
* 再次遍历(包含检查),直接使用上次的排名
*
* @param city
* @param rankings
* @param sendType
*/
private void sendAndInspect(CityCollect city, Integer rankings, byte sendType) {
if (null != rankings) {
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
if (null == sendList || sendList.isEmpty()) {
baseSend(city, rankings, sendType, null);// 首次
} else if (!sendList.get(0).getSendStatus()
&& sendList.get(0).getSendNum() < FangjiaConstant.SEND_ERROR_LIMIT) {
baseSend(city, rankings, sendType, sendList.get(0));
}
}
}
/**
* 发送并保存
*
* @param city
* @param rankings
* @param sendType
*/
private void baseSend(CityCollect city, Integer rankings, byte sendType, CitySendLog log) {
String title = null;
if (FangjiaConstant.INCREASE_SEND_TYPE == sendType) {
title = city.getCity() + ",全国城市涨幅排名第" + rankings + "位";
} else if (FangjiaConstant.DECLINES_SEND_TYPE == sendType) {
title = city.getCity() + ",全国城市跌幅排名第" + rankings + "位";
} else {
title = city.getCity() + ",全国城市潜力排名第" + rankings + "位";
}
LOG.info("全国城市涨幅(跌幅、潜力)排名推送开始,uid:" + city.getUid() + ",city:" + city.getCity());
// 发送
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
new String[] { "push_client_id" });
LOG.info(title);
PushMessageParam param = new PushMessageParam();
param.setTitle("排行榜提醒");
param.setContent(title);
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
param.setOperationPage("/views/house/cityDetail.html?city=" + city.getCity());
boolean result = false;
int sendNum = 1;
if (null != user) {
param.setPushClientId(user.getPushClientId());
result = pushMessageService.pushByReturn(param);
} else {
LOG.info("PushClientId查询不到,uid:" + city.getUid());
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;
}
// 记录
if (null == log) {
citySendLogService.save(city.getCity(), city.getUid(), 0L, sendType, result, sendNum);
} else {
log.setSendStatus(result);
log.setSendNum(log.getSendNum() + 1);
citySendLogService.update(log);
}
}
class MyThread extends Thread {
private Integer topRankings;
private Integer bottomRankings;
private Integer potentialRankings;
private CityCollect city;
public MyThread(CityCollect city, Integer topRankings, Integer bottomRankings, Integer potentialRankings) {
this.topRankings = topRankings;
this.bottomRankings = bottomRankings;
this.potentialRankings = potentialRankings;
this.city = city;
}
@Override
public void run() {
try {
sendAndInspect(city, topRankings, FangjiaConstant.INCREASE_SEND_TYPE);
sendAndInspect(city, bottomRankings, FangjiaConstant.INCREASE_SEND_TYPE);
sendAndInspect(city, potentialRankings, FangjiaConstant.POTENTIAL_SEND_TYPE);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
}
}
}
@@ -1,19 +1,31 @@
package com.fangjia.job.youfang.job;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.base.Response;
import com.fangjia.job.common.util.DingDingMessageUtil;
import com.fangjia.job.common.util.JsonUtils;
import com.fangjia.job.common.util.RestApiCallUtils;
import com.fangjia.job.youfang.remote.FshApiRemoteService;
import com.fangjia.job.common.core.FangjiaThreadPoolExecutor;
import com.fangjia.job.common.util.DateUtilCustom;
import com.fangjia.job.youfang.param.PushMessageParam;
import com.fangjia.job.youfang.po.EnterpriseProductUser;
import com.fangjia.job.youfang.po.HouseInfo;
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
import com.fangjia.job.youfang.service.HouseInfoService;
import com.fangjia.job.youfang.service.PushMessageService;
/**
* 房产租金提醒任务<br>
* 每天触发一次,逻辑在服务端
* 每天触发一次
* @author yinjihuan
*/
public class HouseRentNoticeJob implements SimpleJob {
@@ -23,10 +35,19 @@ public class HouseRentNoticeJob implements SimpleJob {
@Value("${fsh.url}")
private String fshApiUrl;
@Autowired
private HouseInfoService houseInfoService;
@Autowired
private EnterpriseProductUserService enterpriseProductUserService;
@Autowired
private PushMessageService pushMessageService;
@Override
public void execute(ShardingContext shardingContext) {
logger.info("开始执行HouseRentNoticeJob");
FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, fshApiUrl);
/*FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, fshApiUrl);
for (int i = 0; i < 300; i++) {
try {
Response response = fshApiRemoteService.sendHouseRentNotice("goojia123456");
@@ -43,8 +64,145 @@ public class HouseRentNoticeJob implements SimpleJob {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
}
}*/
long total = houseInfoService.queryHouseAllCount(1L);
logger.info("total:" + total);
int pages = PageBean.calcPages(total, 1000);
logger.info("pages:" + pages);
for (int i = 1; i <= pages; i++) {
logger.info("开始执行页数:" + i);
List<HouseInfo> houses = houseInfoService.queryHousesByPage(i, 1000,
new String[] { "id", "live_status", "lease_start_date", "lease_end_date", "uid", "rent_cycle", "rent_cycle_unit", "last_rent_date" });
final CountDownLatch latch = new CountDownLatch(houses.size());
for (HouseInfo house : houses) {
final HouseInfo h = house;
FangjiaThreadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
try {
int days = DateUtilCustom.between(new Date(), h.getLeaseEndDate());
if("出租".equals(h.getLiveStatus()) && days >= 0) {
rentPush(h);
rentEndPush(h);
}
} catch (Exception e) {
logger.error("定时推送收租通知异常:"+h.getId(), e);
} finally {
latch.countDown();
}
}
});
}
try {
latch.await();
} catch (InterruptedException e) {
logger.error("推送收租通知等待异常", e);
}
}
logger.info("HouseRentNoticeJob执行结束");
}
// 收租提醒,提前7天通知
private void rentPush(HouseInfo houseInfo) {
int unitMonth = houseInfo.getRentCycle() * 1;
if("季".equals(houseInfo.getRentCycleUnit())){
unitMonth = houseInfo.getRentCycle() * 3;
}else if("年".equals(houseInfo.getRentCycleUnit())){
unitMonth = houseInfo.getRentCycle() * 12;
}
//共多少月
if (houseInfo.getLeaseEndDate() == null || houseInfo.getLeaseStartDate() == null) {
return;
}
int months = (houseInfo.getLeaseEndDate().getYear() - houseInfo.getLeaseStartDate().getYear())*12 + (houseInfo.getLeaseEndDate().getMonth() - houseInfo.getLeaseStartDate().getMonth());
if(houseInfo.getLeaseEndDate().getDate()- houseInfo.getLeaseStartDate().getDate()>0){
months = months + 1;
}
//共多少期
int sumCycle = (int) Math.ceil(months*1.0/unitMonth);
Date date = new Date();
int months2 = (date.getYear() - houseInfo.getLeaseStartDate().getYear())*12 + (date.getMonth() - houseInfo.getLeaseStartDate().getMonth());
int count = (int) Math.floor(months2*1.0/unitMonth);
int stage = 0;
//第几期
if(count + 2<=sumCycle){
stage = count+2;//默认开始为一期,再加1是下一期
}else{
stage = sumCycle;//默认开始为一期,再加1是下一期
}
Date nextDay = null;
if(count + 1<sumCycle){
nextDay = org.apache.commons.lang3.time.DateUtils.addMonths(houseInfo.getLeaseStartDate(), (count+1)*unitMonth);
nextDay.setDate(houseInfo.getLastRentDate().getDate());
Date lastNextDay = org.apache.commons.lang3.time.DateUtils.addMonths(nextDay, -1*unitMonth);
date = org.apache.commons.lang3.time.DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
if(stage>=1 && date.getTime()<=lastNextDay.getTime()){
stage = stage-1;
nextDay = lastNextDay;
}
}else{
nextDay = org.apache.commons.lang3.time.DateUtils.addMonths(houseInfo.getLeaseStartDate(), (sumCycle-1)*unitMonth);
nextDay.setDate(houseInfo.getLastRentDate().getDate());
Date lastNextDay = org.apache.commons.lang3.time.DateUtils.addMonths(nextDay, -1*unitMonth);
date = org.apache.commons.lang3.time.DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
if(stage>=1 && date.getTime()<lastNextDay.getTime()){
stage = stage-1;
nextDay = org.apache.commons.lang3.time.DateUtils.addMonths(houseInfo.getLeaseStartDate(), (sumCycle-2)*unitMonth);
}
}
if (nextDay != null) {
int days = DateUtilCustom.between(new Date(), nextDay);
if (days == 7) {
EnterpriseProductUser user = enterpriseProductUserService.getById(Long.parseLong(houseInfo.getUid()), new String[] { "push_client_id" });
if (user == null) {
return;
}
String pushMsg = DateUtils.date2Str(nextDay, "yyyy年MM月dd日") + "是您的到期收租日,又要有现金到账咯,请注意查收。详情请点击查看。";
logger.info(pushMsg);
PushMessageParam param = new PushMessageParam();
param.setTitle("收租提醒");
param.setContent(pushMsg);
param.setOperation(2);
param.setOperationPage("/views/house/detail.html?houseId="+houseInfo.getId());
param.setPushClientId(user.getPushClientId());
pushMessageService.push(param);
}
}
}
// 租房到期推送,提前一个月/15天
private void rentEndPush(HouseInfo house) {
// 房子到期日期
Date leaseEndDate = house.getLeaseEndDate();
if (leaseEndDate == null) {
return;
}
// 判断当前时间距离到期日期的天数,在30天和15天的时候进行推送
int days = DateUtilCustom.between(new Date(), leaseEndDate);
if(days == 15 || days == 30) {
EnterpriseProductUser user = enterpriseProductUserService.getById(Long.parseLong(house.getUid()), new String[] { "push_client_id" });
String pushMsg = DateUtils.date2Str(leaseEndDate, "yyyy年MM月dd日") + "您的房子租期就到了,快来看看现在的市场租金价格吧。详情请点击查看。";
logger.info(pushMsg);
PushMessageParam param = new PushMessageParam();
param.setTitle("收租提醒");
param.setContent(pushMsg);
param.setOperation(2);
param.setOperationPage("/views/house/detail.html?houseId="+house.getId());
param.setPushClientId(user.getPushClientId());
pushMessageService.push(param);
}
}
}
@@ -0,0 +1,131 @@
package com.fangjia.job.youfang.job;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.dangdang.ddframe.job.api.ShardingContext;
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.param.PushMessageParam;
import com.fangjia.job.youfang.po.CityCollect;
import com.fangjia.job.youfang.po.EnterpriseProductUser;
import com.fangjia.job.youfang.po.News;
import com.fangjia.job.youfang.service.CityCollectService;
import com.fangjia.job.youfang.service.CitySendLogService;
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
import com.fangjia.job.youfang.service.NewsService;
import com.fangjia.job.youfang.service.PushMessageService;
public class HousingEstateNewsSendJob implements SimpleJob {
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
@Autowired
private CityCollectService cityCollectService;
@Autowired
private CitySendLogService citySendLogService;
@Autowired
private NewsService newsService;
@Autowired
private EnterpriseProductUserService enterpriseProductUserService;
@Autowired
private PushMessageService pushMessageService;
private static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(FangjiaConstant.SEND_THREAD_NUM);
@Override
public void execute(ShardingContext context) {
LOG.info("城市小区推送开始,context:" + context);
// 1.查询
List<CityCollect> cityList = cityCollectService.findAll();
String cityName = "";
List<News> newsList = null;
// 2.对比
for (CityCollect city : cityList) {
// cityList已排序好,如果cityName不变,则使用上个newsList
if (cityName.equals(city.getCity())) {
THREAD_POOL.execute(new MyThread(city, newsList));
} else {
// 如果cityName改变,则查询替换cityName和newsList
cityName = city.getCity();
newsList = newsService.findHousingEstate(cityName);
THREAD_POOL.execute(new MyThread(city, newsList));
}
}
}
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() || (!sendList.get(0).getSendStatus()
&& sendList.get(0).getSendNum() < FangjiaConstant.SEND_ERROR_LIMIT)) {
LOG.info("小区推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
// 3.发送
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
new String[] { "push_client_id" });
String pushMsg = n.getIntroduction();
LOG.info(pushMsg);
PushMessageParam param = new PushMessageParam();
param.setTitle(n.getTitle());
param.setContent(pushMsg);
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
param.setOperationPage("/views/district/detail.html?city=" + n.getRecommendDistrictCity()
+ "&region=" + n.getRecommendDistrictRegion() + "&name=" + n.getRecommendDistrictName());
boolean result = false;
int sendNum = 1;
if (null != user) {
param.setPushClientId(user.getPushClientId());
result = pushMessageService.pushByReturn(param);
} else {
LOG.info("PushClientId查询不到,uid:" + city.getUid());
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;// 不可推送的,次数直接置为3次,避免再次推送
}
// 4.记录
if (null == sendList || sendList.isEmpty()) {
citySendLogService.save(city.getCity(), city.getUid(), n.getId(),
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE, result, sendNum);
} else {
CitySendLog log = sendList.get(0);
log.setSendStatus(result);
log.setSendNum(log.getSendNum() + 1);
citySendLogService.update(log);
}
}
}
}
}
class MyThread extends Thread {
private List<News> news;
private CityCollect city;
public MyThread(CityCollect city, List<News> news) {
this.news = news;
this.city = city;
}
@Override
public void run() {
try {
sendNews(city, news);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
}
}
}
@@ -0,0 +1,156 @@
package com.fangjia.job.youfang.job;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.fangjia.job.common.base.FangjiaConstant;
import com.fangjia.job.common.util.JsonUtils;
import com.fangjia.job.youfang.document.CitySendLog;
import com.fangjia.job.youfang.param.PushMessageParam;
import com.fangjia.job.youfang.po.CityCollect;
import com.fangjia.job.youfang.po.EnterpriseProductUser;
import com.fangjia.job.youfang.po.News;
import com.fangjia.job.youfang.service.CityCollectService;
import com.fangjia.job.youfang.service.CitySendLogService;
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
import com.fangjia.job.youfang.service.NewsService;
import com.fangjia.job.youfang.service.PushMessageService;
public class TopNewsSendJob implements SimpleJob {
private static final Logger LOG = LoggerFactory.getLogger(TopNewsSendJob.class);
@Autowired
private CityCollectService cityCollectService;
@Autowired
private CitySendLogService citySendLogService;
@Autowired
private NewsService newsService;
@Autowired
private EnterpriseProductUserService enterpriseProductUserService;
@Autowired
private PushMessageService pushMessageService;
private static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(FangjiaConstant.SEND_THREAD_NUM);
@Override
public void execute(ShardingContext context) {
LOG.info("城市置顶咨询推送开始,context:" + context);
// 1.查询
List<CityCollect> cityList = cityCollectService.findAll();
String cityName = "";
List<News> newsList = null;
// 2.对比
for (CityCollect city : cityList) {
// cityList已排序好,如果cityName不变,则使用上个newsList
if (cityName.equals(city.getCity())) {
THREAD_POOL.execute(new MyThread(city, newsList));
} else {
// 如果cityName改变,则查询替换cityName和newsList
cityName = city.getCity();
newsList = newsService.findTopNews(cityName);
THREAD_POOL.execute(new MyThread(city, newsList));
}
}
}
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()
|| (!sendList.get(0).getSendStatus()&&sendList.get(0).getSendNum() < FangjiaConstant.SEND_ERROR_LIMIT)) {
LOG.info("新闻推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
// 3.发送
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
new String[] { "push_client_id" });
String pushMsg = n.getIntroduction();
PushMessageParam param = new PushMessageParam();
param.setTitle(n.getTitle());
param.setContent(pushMsg);
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
switch (n.getType()) {
case "专题":
param.setOperationPage("/views/news/newsDetail.html?newsId=" + n.getId());
break;
case "新闻":
param.setOperationPage("/views/news/newsDetail.html?newsId=" + n.getId());
param.setUserId(city.getUid());
break;
case "推荐城市":
param.setOperationPage("/views/house/cityDetail.html?city=" + n.getCity());
break;
case "投票":
param.setOperation(FangjiaConstant.OPEN_APP_TYPE);
break;
case "活动":
param.setOperation(FangjiaConstant.OPEN_APP_TYPE);
break;
case "推荐小区":
param.setOperationPage(
"/views/district/detail.html?city=" + n.getRecommendDistrictCity() + "&region="
+ n.getRecommendDistrictRegion() + "&name=" + n.getRecommendDistrictName());
break;
default:
param.setOperationPage("/views/news/newsDetail.html?newsId=" + n.getId());
}
boolean result = false;
int sendNum = 1;
if (null != user) {
param.setPushClientId(user.getPushClientId());
LOG.info("param:" + JsonUtils.toJson(param));
result = pushMessageService.pushByReturn(param);
} else {
LOG.info("PushClientId查询不到,uid:" + city.getUid());
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;// 不可推送的,次数直接置为3次,避免再次推送
}
// 4.记录
if (null == sendList || sendList.isEmpty()) {
citySendLogService.save(city.getCity(), city.getUid(), n.getId(),
FangjiaConstant.NEWS_SEND_TYPE, result, sendNum);
} else {
CitySendLog log = sendList.get(0);
log.setSendStatus(result);
log.setSendNum(log.getSendNum() + 1);
citySendLogService.update(log);
}
}
}
}
}
class MyThread extends Thread {
private List<News> news;
private CityCollect city;
public MyThread(CityCollect city, List<News> news) {
this.news = news;
this.city = city;
}
@Override
public void run() {
try {
sendNews(city, news);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
}
}
}
@@ -90,7 +90,7 @@ public class UserAssetsLevelJob implements SimpleJob {
}
level.setName(name);
Long totalMoney = houseInfoService.queryUserManagerHouseTotalPrice(1L, user.getId()+"");
level.setAssets(DataUtil.getDoubleRound(2, totalMoney / 10000D));
level.setAssets(DataUtil.getDoubleRound(0, totalMoney / 10000D));
mongoTemplate.save(level);
}
}
@@ -0,0 +1,71 @@
package com.fangjia.job.youfang.param;
public class PushMessageParam {
// 标题
private String title;
// 内容
private String content;
// 通知操作(0:打开应用,1:打开指定页面,2:打开url)
private int operation;
// 当通知操作为打开具体页面时这个值就是页面的值,当为打开url时这个值就是url的值
private String operationPage;
// 推送ID
private String pushClientId;
// 推送给哪个用户
private Long userId;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getOperation() {
return operation;
}
public void setOperation(int operation) {
this.operation = operation;
}
public String getOperationPage() {
return operationPage;
}
public void setOperationPage(String operationPage) {
this.operationPage = operationPage;
}
public String getPushClientId() {
return pushClientId;
}
public void setPushClientId(String pushClientId) {
this.pushClientId = pushClientId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
}
@@ -0,0 +1,29 @@
package com.fangjia.job.youfang.po;
import java.io.Serializable;
import com.cxytiandi.jdbc.annotation.AutoId;
import com.cxytiandi.jdbc.annotation.Field;
import com.cxytiandi.jdbc.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "city_collect", author = "yinjihuan", desc = "城市收藏表")
public class CityCollect implements Serializable {
private static final long serialVersionUID = 5064195667364691855L;
@AutoId
@Field(value = "id", desc = "ID")
private Long id;
@Field(value = "city", desc = "城市")
private String city;
@Field(value = "add_time", desc = "保存时间")
private Data addTime;
@Field(value = "uid", desc = "用户ID")
private Long uid;
}
@@ -50,8 +50,8 @@ public class News implements Serializable {
@Field(value = "content", desc = "内容")
private String content;
@Field(value = "publish_status", desc = "是否已发布(0:未发布,1已发布)")
private int publishStatus;
// @Field(value = "publish_status", desc = "是否已发布(0:未发布,1已发布)")
// private int publishStatus;
@Field(value = "top_status", desc = "是否置顶(0否 1是)")
private int topStatus;
@@ -62,6 +62,9 @@ public class News implements Serializable {
@Field(value = "visit_count", desc = "浏览量")
private int visitCount;
@Field(value = "thumbs_up_count", desc = "点赞量")
private int thumbsUpCount;
@Field(value = "vote_favor_count", desc = "投票赞成数量")
private int voteFavorCount;
@@ -71,6 +74,42 @@ public class News implements Serializable {
@Field(value = "user_id", desc = "创建用户ID")
private Long userId;
@Field(value = "m_date", desc = "修改时间")
private Date mDate;
@Field(value = "tags", desc = "标签,多个下划线分割")
private String tags;
@Field(value = "vote_favor_text", desc = "投票赞成显示文字(投票类专有)")
private String voteFavorText;
@Field(value = "vote_no_favor_text", desc = "投票不赞成显示文字(投票类专有)")
private String voteNoFavorText;
@Field(value = "recommend_city", desc = "推荐城市,城市推荐才有此值")
private String recommendCity;
@Field(value = "recommend_city_tags", desc = "推荐城市的标签,下划线分割,城市推荐才有此值")
private String recommendCityTags;
@Field(value = "recommend_district_city", desc = "小区推荐咨询的城市")
private String recommendDistrictCity;
@Field(value = "recommend_district_region", desc = "小区推荐咨询的区域")
private String recommendDistrictRegion;
@Field(value = "recommend_district_name", desc = "小区推荐咨询的小区名")
private String recommendDistrictName;
@Field(value = "recommend_district_tags", desc = "小区推荐咨询的小区标签,下划线分割")
private String recommendDistrictTags;
@Field(value = "small_cover_img", desc = "封面缩略图")
private String smallCoverImg;
@Field(value = "init_visit_count", desc = "初始化浏览量")
private Integer initVisitCount;
public Long getId() {
return id;
}
@@ -175,13 +214,13 @@ public class News implements Serializable {
this.content = content;
}
public int getPublishStatus() {
return publishStatus;
}
public void setPublishStatus(int publishStatus) {
this.publishStatus = publishStatus;
}
// public int getPublishStatus() {
// return publishStatus;
// }
//
// public void setPublishStatus(int publishStatus) {
// this.publishStatus = publishStatus;
// }
public int getTopStatus() {
return topStatus;
@@ -230,4 +269,109 @@ public class News implements Serializable {
public void setUserId(Long userId) {
this.userId = userId;
}
public int getThumbsUpCount() {
return thumbsUpCount;
}
public void setThumbsUpCount(int thumbsUpCount) {
this.thumbsUpCount = thumbsUpCount;
}
public Date getMDate() {
return mDate;
}
public void setMDate(Date mDate) {
this.mDate = mDate;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getVoteFavorText() {
return voteFavorText;
}
public void setVoteFavorText(String voteFavorText) {
this.voteFavorText = voteFavorText;
}
public String getVoteNoFavorText() {
return voteNoFavorText;
}
public void setVoteNoFavorText(String voteNoFavorText) {
this.voteNoFavorText = voteNoFavorText;
}
public String getRecommendCity() {
return recommendCity;
}
public void setRecommendCity(String recommendCity) {
this.recommendCity = recommendCity;
}
public String getRecommendCityTags() {
return recommendCityTags;
}
public void setRecommendCityTags(String recommendCityTags) {
this.recommendCityTags = recommendCityTags;
}
public String getRecommendDistrictCity() {
return recommendDistrictCity;
}
public void setRecommendDistrictCity(String recommendDistrictCity) {
this.recommendDistrictCity = recommendDistrictCity;
}
public String getRecommendDistrictRegion() {
return recommendDistrictRegion;
}
public void setRecommendDistrictRegion(String recommendDistrictRegion) {
this.recommendDistrictRegion = recommendDistrictRegion;
}
public String getRecommendDistrictName() {
return recommendDistrictName;
}
public void setRecommendDistrictName(String recommendDistrictName) {
this.recommendDistrictName = recommendDistrictName;
}
public String getRecommendDistrictTags() {
return recommendDistrictTags;
}
public void setRecommendDistrictTags(String recommendDistrictTags) {
this.recommendDistrictTags = recommendDistrictTags;
}
public String getSmallCoverImg() {
return smallCoverImg;
}
public void setSmallCoverImg(String smallCoverImg) {
this.smallCoverImg = smallCoverImg;
}
public Integer getInitVisitCount() {
return initVisitCount;
}
public void setInitVisitCount(Integer initVisitCount) {
this.initVisitCount = initVisitCount;
}
}
@@ -0,0 +1,60 @@
package com.fangjia.job.youfang.po;
import java.io.Serializable;
import java.util.Date;
import com.cxytiandi.jdbc.annotation.AutoId;
import com.cxytiandi.jdbc.annotation.Field;
import com.cxytiandi.jdbc.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "push_message", author = "yinjihuan", desc = "推送消息表")
public class PushMessage implements Serializable {
private static final long serialVersionUID = -1101101524583976384L;
@AutoId
@Field(value = "id", desc = "ID")
private Long id;
@Field(value = "title", desc = "标题")
private String title;
@Field(value = "content", desc = "内容")
private String content;
@Field(value = "add_time", desc = "添加时间")
private Date addTime;
@Field(value = "save_status", desc = "用户消息列表是否留存(0不存,1存)")
private Integer saveStatus;
@Field(value = "operation", desc = "通知操作(0:打开应用,1:打开指定页面,2:打开url)")
private Integer operation;
@Field(value = "operation_page", desc = "当通知操作为打开具体页面时这个值就是页面的值,当为打开url时这个值就是url的值")
private String operationPage;
@Field(value = "user_range", desc = "通知用户范围(0:全部用户,1:部分用户)")
private Integer userRange;
@Field(value = "user_range_city", desc = "通知用户范围对应的城市")
private String userRangeCity;
@Field(value = "push_time", desc = "推送时间")
private Date pushTime;
@Field(value = "push_status", desc = "是否已推送(0未推送,1已推送)")
private Integer pushStatus;
@Field(value = "user_range_province", desc = "通知用户所在省份")
private String userRangeProvince;
@Field(value = "uid", desc = "创建用户ID")
private Long uid;
@Field(value = "user_range_city_code", desc = "个推城市码")
private String userRangeCityCode;
}
@@ -0,0 +1,33 @@
package com.fangjia.job.youfang.po;
import java.io.Serializable;
import java.util.Date;
import com.cxytiandi.jdbc.annotation.AutoId;
import com.cxytiandi.jdbc.annotation.Field;
import com.cxytiandi.jdbc.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "push_record_message", author = "yinjihuan", desc = "推送消息记录表")
public class PushRecordMessage implements Serializable {
private static final long serialVersionUID = 6736005034016737661L;
@AutoId
@Field(value = "id", desc = "ID")
private Long id;
@Field(value = "uid", desc = "用户ID")
private Long uid;
@Field(value = "mid", desc = "消息ID")
private Long mid;
@Field(value = "add_time", desc = "添加时间")
private Date addTime;
@Field(value = "read_status", desc = "是否已读 (0未读,1已读)")
private Integer readStatus;
}
@@ -6,6 +6,7 @@ import com.fangjia.job.common.base.Response;
import com.fangjia.job.youfang.document.DistrictEvaluateSingleDto;
import com.fangjia.job.youfang.document.DistrictInfoDto;
import com.fangjia.job.youfang.document.DistrictSearchSingleDto;
import com.fangjia.job.youfang.dto.CityNewPriceResultDto;
import com.fangjia.job.youfang.dto.DistrictDetailDto;
import feign.Param;
@@ -14,66 +15,84 @@ import feign.RequestLine;
/**
* API调用接口定义
*
* @author yinjihuan
*/
public interface FshApiRemoteService {
/**
* 发送月涨幅计算通知
*
* @param token
* @return
*/
@RequestLine("GET /rest/houses/rose/month?token={token}")
public Response sendHouseRoseMonthNotice(@Param("token")String token);
public Response sendHouseRoseMonthNotice(@Param("token") String token);
/**
* 发送租金提醒计算通知
*
* @param token
* @return
*/
@RequestLine("GET /rest/houses/rent/notice?token={token}")
public Response sendHouseRentNotice(@Param("token")String token);
public Response sendHouseRentNotice(@Param("token") String token);
/**
* 定时估价操作,并算出周涨跌幅通知
*
* @param token
* @return
*/
@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")
public Map<String,Object> getAgencyInfo(@QueryMap Map<String, Object> queryMap);
public Map<String, Object> getAgencyInfo(@QueryMap Map<String, Object> queryMap);
/**
* 获取小区综合信息district_new_price
*
* @param queryMap
* @return
*/
@RequestLine("GET /fsh/getDistrictNewPriceInfo")
public DistrictEvaluateSingleDto getDistrictNewPriceInfo(@QueryMap Map<String, Object> queryMap);
/**
* 小区详情
*/
@RequestLine("GET /fsh/detail")
public DistrictInfoDto detail(@QueryMap Map<String, Object> queryMap);
//小区估价接口
// 小区估价接口
@RequestLine("GET /fsh/evaluate")
public DistrictSearchSingleDto evaluate(@QueryMap Map<String, Object> queryMap);
/**
* 刷新小区详情页面缓存数据
*
* @param queryMap
* @return
*/
@RequestLine("GET /district/details")
public String refreshDistrictDetailPageData(@QueryMap Map<String, Object> queryMap);
/**
* 小区信息汇总
*/
@RequestLine("GET /fsh/districtDetail")
public DistrictDetailDto districtDetail(@QueryMap Map<String, Object> queryMap);
// 城市列表
@RequestLine("GET /quotations/cityList?token={token}")
public CityNewPriceResultDto getAllCitys(@Param("token") String token);
/**
* 消息推送接口
* @param queryMap
* @return
*/
@RequestLine("POST /rest/message/push")
public Response pushMessage(@QueryMap Map<String, Object> queryMap);
}
@@ -0,0 +1,11 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import com.fangjia.job.youfang.po.CityCollect;
public interface CityCollectService {
List<CityCollect> findAll();
}
@@ -0,0 +1,23 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.cxytiandi.jdbc.EntityService;
import com.cxytiandi.jdbc.Orders;
import com.cxytiandi.jdbc.Orders.OrderyType;
import com.fangjia.job.youfang.po.CityCollect;
@Service
public class CityCollectServiceImpl extends EntityService<CityCollect> implements CityCollectService {
private static final String ORDER_PARAM = "city";
@Override
public List<CityCollect> findAll() {
return super.list(new Orders[] { new Orders(ORDER_PARAM, OrderyType.ASC) });
// return super.list(new String[] {"uid"},new Object[] {"190075963655061504"},new Orders[] { new Orders(ORDER_PARAM, OrderyType.ASC) });
}
}
@@ -0,0 +1,14 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import com.fangjia.job.youfang.document.CitySendLog;
public interface CitySendLogService {
CitySendLog save(String city, Long uid, Long nId, byte sendType, Boolean sendStatus, int sendNum);
List<CitySendLog> find(long uid, Long newsId, Byte sendType);
void update(CitySendLog log);
}
@@ -0,0 +1,75 @@
package com.fangjia.job.youfang.service;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
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 org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import com.fangjia.job.youfang.document.CitySendLog;
@Service
public class CitySendLogServiceImpl implements CitySendLogService {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public CitySendLog save(String city, Long uid, Long nId, byte sendType, Boolean sendStatus, int sendNum) {
CitySendLog log = new CitySendLog();
log.setCity(city);
log.setNewsId(nId);
log.setSendTime(new Date());
log.setSendType(sendType);
log.setUid(uid);
log.setSendStatus(sendStatus);
log.setSendNum(sendNum);
mongoTemplate.save(log);
return log;
}
@Override
public List<CitySendLog> find(long uid, Long newsId, Byte sendType) {
if (null != newsId) {// 咨询推送
Query query = Query.query(Criteria.where("uid").is(uid).and("newsId").is(newsId));
return mongoTemplate.find(query, CitySendLog.class);
} else { // 排名推送,查当前一个月内的记录
Query query = Query.query(
Criteria.where("uid").is(uid).and("sendTime").gt(getMonthAgo()).and("sendType").is(sendType));
return mongoTemplate.find(query, CitySendLog.class);
}
}
/**
* 取一个月前的时间
*
* @return
*/
private Date getMonthAgo() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.MONTH, -1);
return c.getTime();
}
@Override
public void update(CitySendLog log) {
if (null != log.getNewsId()) {
mongoTemplate.updateFirst(
Query.query(Criteria.where("uid").is(log.getUid()).and("newsId").is(log.getNewsId())),
Update.update("sendNum", log.getSendNum()).set("sendStatus", log.getSendStatus()),
CitySendLog.class);
} else {
mongoTemplate.updateFirst(
Query.query(Criteria.where("uid").is(log.getUid()).and("sendTime").is(log.getSendTime())
.and("sendType").is(log.getSendType())),
Update.update("sendNum", log.getSendNum()).set("sendStatus", log.getSendStatus()),
CitySendLog.class);
}
}
}
@@ -44,4 +44,6 @@ public interface EnterpriseProductUserService {
boolean existsByPushId(String pushID);
List<EnterpriseProductUser> queryAddUser(String start, String end);
EnterpriseProductUser getById(Long id, String[] fields);
}
@@ -42,4 +42,9 @@ public class EnterpriseProductUserServiceImpl extends EntityService<EnterprisePr
return super.list(sql, new Object[] { start, end });
}
@Override
public EnterpriseProductUser getById(Long id, String[] fields) {
return super.getByParams(fields, new String[] { "id" }, new Object[] { id });
}
}
@@ -1,5 +1,6 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import java.util.Map;
import com.fangjia.job.youfang.po.HouseInfo;
@@ -106,4 +107,12 @@ public interface HouseInfoService {
* @return
*/
Long queryUserManagerHouseTotalPrice(Long eid, String uid);
/**
* 分页查询房产信息
* @param page
* @param limit
* @return
*/
List<HouseInfo> queryHousesByPage(int page, int limit, String[] fields);
}
@@ -7,6 +7,7 @@ import java.util.TreeMap;
import org.springframework.stereotype.Service;
import com.cxytiandi.jdbc.EntityService;
import com.cxytiandi.jdbc.util.PageBean;
import com.fangjia.job.youfang.po.HouseInfo;
@Service
@@ -122,5 +123,11 @@ public class HouseInfoServiceImpl extends EntityService<HouseInfo> implements Ho
}
return sum;
}
@Override
public List<HouseInfo> queryHousesByPage(int page, int limit, String[] fields) {
int start = PageBean.page2Start(page, limit);
return super.listForPage(fields, "remove_status", 0, start, limit);
}
}
@@ -1,19 +1,28 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import com.fangjia.job.youfang.po.News;
public interface NewsService {
/**
* 发布新闻
*
* @param date
* @return
*/
void pushNews(String date);
/**
* 下架新闻
*
* @param date
* @return
*/
void offlineNews(String date);
List<News> findTopNews(String city);
List<News> findHousingEstate(String city);
}
@@ -1,5 +1,7 @@
package com.fangjia.job.youfang.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.cxytiandi.jdbc.EntityService;
@@ -8,16 +10,34 @@ import com.fangjia.job.youfang.po.News;
@Service
public class NewsServiceImpl extends EntityService<News> implements NewsService {
private static final int TOP_STATUS = 1;
private static final int ON_LINE_STATUS = 1;
private static final String HOUSING_ESTATE_TYPE = "推荐小区";
@Override
public void pushNews(String date) {
String sql = "update news set `status`=1 where `status`=0 and deploy_time<='"+date+"'";
String sql = "update news set `status`=1 where `status`=0 and deploy_time<='" + date + "'";
super.getJdbcTemplate().execute(sql);
}
@Override
public void offlineNews(String date) {
String sql = "update news set `status`=2 where `status`=1 and offline_time<='"+date+"'";
String sql = "update news set `status`=2 where `status`=1 and offline_time<='" + date + "'";
super.getJdbcTemplate().execute(sql);
}
@Override
public List<News> findTopNews(String city) {
return super.list(new String[] { "status", "top_status", "city" },
new Object[] { ON_LINE_STATUS, TOP_STATUS, city });
}
@Override
public List<News> findHousingEstate(String city) {
return super.list(new String[] { "status", "type", "city" },
new Object[] { ON_LINE_STATUS, HOUSING_ESTATE_TYPE, city });
}
}
@@ -0,0 +1,19 @@
package com.fangjia.job.youfang.service;
import com.fangjia.job.youfang.param.PushMessageParam;
public interface PushMessageService {
/**
* 推送消息
* @param param
*/
void push(PushMessageParam param);
/**
* 推送消息
* @param param
*/
boolean pushByReturn(PushMessageParam param);
}
@@ -0,0 +1,67 @@
package com.fangjia.job.youfang.service;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.cxytiandi.jdbc.EntityService;
import com.fangjia.job.common.base.Response;
import com.fangjia.job.common.util.DingDingMessageUtil;
import com.fangjia.job.common.util.RestApiCallUtils;
import com.fangjia.job.youfang.param.PushMessageParam;
import com.fangjia.job.youfang.po.PushMessage;
import com.fangjia.job.youfang.remote.FshApiRemoteService;
@Service
public class PushMessageServiceImpl extends EntityService<PushMessage> implements PushMessageService {
private Logger logger = LoggerFactory.getLogger(PushMessageServiceImpl.class);
@Value("${fsh.url}")
private String fshApiUrl;
@Override
public void push(PushMessageParam param) {
FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, fshApiUrl);
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("token", "goojia123456");
params.put("title", param.getTitle());
params.put("content", param.getContent());
params.put("operation", param.getOperation());
params.put("operationPage", param.getOperationPage());
params.put("pushClientId", param.getPushClientId());
params.put("userId", param.getUserId());
fshApiRemoteService.pushMessage(params);
} catch (Exception e) {
logger.error("消息推送异常:", e);
DingDingMessageUtil.sendTextMessage("消息推送异常:" + e.getMessage());
}
}
@Override
public boolean pushByReturn(PushMessageParam param) {
FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, fshApiUrl);
boolean result = false;
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("token", "goojia123456");
params.put("title", param.getTitle());
params.put("content", param.getContent());
params.put("operation", param.getOperation());
params.put("operationPage", param.getOperationPage());
params.put("pushClientId", param.getPushClientId());
params.put("userId", param.getUserId());
Response res = fshApiRemoteService.pushMessage(params);
result = res.getStatus();
} catch (Exception e) {
logger.error("消息推送异常:", e);
DingDingMessageUtil.sendTextMessage("消息推送异常:" + e.getMessage());
}
return result;
}
}
@@ -0,0 +1,5 @@
package com.fangjia.job.youfang.service;
public interface PushRecordMessageService {
}
@@ -0,0 +1,11 @@
package com.fangjia.job.youfang.service;
import org.springframework.stereotype.Service;
import com.cxytiandi.jdbc.EntityService;
import com.fangjia.job.youfang.po.PushRecordMessage;
@Service
public class PushRecordMessageServiceImpl extends EntityService<PushRecordMessage> implements PushRecordMessageService {
}
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
@@ -141,6 +141,34 @@
<job:listener class="com.fangjia.job.youfang.listener.MessageElasticJobListener"></job:listener>
</job:simple>
<!-- 根据用户关注的城市推送该市的置顶咨询,一天一次(不重复推) -->
<job:simple id="topNewsSendJob" class="com.fangjia.job.youfang.job.TopNewsSendJob" registry-center-ref="regCenter"
sharding-total-count="1" cron="0 10 4 * * ?" 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>
<!-- 根据用户关注的城市推送该市的小区咨询,一天一次(不重复推) -->
<job:simple id="housingEstateNewsSendJob" class="com.fangjia.job.youfang.job.HousingEstateNewsSendJob" registry-center-ref="regCenter"
sharding-total-count="1" cron="0 10 4 * * ?" 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>
<!-- 根据用户关注的城市推送该市的排名信息,一天一次(前十,重复30天一推) -->
<job:simple id="cityRankingSendJob" class="com.fangjia.job.youfang.job.CityRankingSendJob" registry-center-ref="regCenter"
sharding-total-count="1" cron="0 10 5 * * ?" sharding-item-parameters=""
failover="true" description="【有房】 根据用户关注的城市推送该市的排名信息,一天一次(前十,重复30天一推)"
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>
+20
View File
@@ -81,7 +81,27 @@
<artifactId>feign-core</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>