Merge branch 'FSHJOB1.2' of 192.168.0.27:dev0/fangjia-job into FSHJOB1.2

This commit is contained in:
尹吉欢
2018-06-09 13:10:41 +08:00
5 changed files with 179 additions and 46 deletions
@@ -15,8 +15,8 @@ public class FangjiaConstant {
public static final byte POTENTIAL_SEND_TYPE = 4;
public static String FANGJIA_API_TOKEN = "F54F52381C49BB9EB4A33EB1B65604AE4B71A28AEE53518A94A2F360408B9056D57553931D15CE6DDE765562DAD286BA38E05A4CDAFC51C3D527A4959BF8E75A3B95DB7108FCEA340DDE61925616DB55118E1851E67D83EAD800460D100D6B667A4ED8EE67C8F7FB";
public static final int SUCCESS_RESPONSE_CODE = 200;
public static final int SEND_THREAD_NUM = 100;
}
@@ -4,6 +4,8 @@ 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;
@@ -17,10 +19,14 @@ 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 {
@@ -32,18 +38,29 @@ public class CityRankingSendJob implements SimpleJob {
@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(FangjiaConstant.FANGJIA_API_TOKEN);
CityNewPriceResultDto resultDto = fshApiRemoteService.getAllCitys(token);
List<CityStatInfoDto> topTenList = new ArrayList<CityStatInfoDto>();
List<CityStatInfoDto> bottomTenList = new ArrayList<CityStatInfoDto>();
List<CityStatInfoDto> potentialTenList = new ArrayList<CityStatInfoDto>();
@@ -80,8 +97,7 @@ public class CityRankingSendJob implements SimpleJob {
bottomTenList = upList.subList(copyList.size() - NUM, copyList.size());
Collections.reverse(bottomTenList);// 涨幅后10名倒序
// 深复制失败,再次访问,用新list做潜力排序
CityNewPriceResultDto resultDto2 = fshApiRemoteService
.getAllCitys(FangjiaConstant.FANGJIA_API_TOKEN);
CityNewPriceResultDto resultDto2 = fshApiRemoteService.getAllCitys(token);
CityNewPriceDto dto2 = resultDto2.getResult();
List<CityStatInfoDto> rets2 = dto2.getRets();
// 潜力排序
@@ -102,13 +118,7 @@ public class CityRankingSendJob implements SimpleJob {
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);
}
THREAD_POOL.execute(new MyThread(city, topRankings, bottomRankings, potentialRankings));
} else {
// 如果cityName改变,则查询替换cityName和排名
cityName = city.getCity();
@@ -169,18 +179,54 @@ public class CityRankingSendJob implements SimpleJob {
private void baseSend(CityCollect city, Integer rankings, byte sendType) {
String title = null;
if (FangjiaConstant.INCREASE_SEND_TYPE == sendType) {
title = "全国城市涨幅排名第" + rankings + "位";
title = city.getCity() + ",全国城市涨幅排名第" + rankings + "位";
} else if (FangjiaConstant.DECLINES_SEND_TYPE == sendType) {
title = "全国城市跌幅排名第" + rankings + "位";
title = city.getCity() + ",全国城市跌幅排名第" + rankings + "位";
} else {
title = "全国城市潜力排名第" + rankings + "位";
title = city.getCity() + ",全国城市潜力排名第" + rankings + "位";
}
LOG.info("全国城市涨幅(跌幅、潜力)排名推送开始,uid:" + city.getUid() + ",city:" + city.getCity());
// 发送
// TODO
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(1);
param.setOperationPage("");
param.setPushClientId(user.getPushClientId());
pushMessageService.push(param);
// 记录
citySendLogService.save(city.getCity(), city.getUid(), 0L, sendType);
}
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 {
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);
}
}
}
}
@@ -1,6 +1,8 @@
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;
@@ -10,28 +12,40 @@ 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);
LOG.info("城市小区推送开始,context:" + context);
// 1.查询
List<CityCollect> cityList = cityCollectService.findAll();
String cityName = "";
@@ -40,24 +54,16 @@ public class HousingEstateNewsSendJob implements SimpleJob {
for (CityCollect city : cityList) {
// cityList已排序好,如果cityName不变,则使用上个newsList
if (cityName.equals(city.getCity())) {
try {
sendNews(city, newsList);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
THREAD_POOL.execute(new MyThread(city, newsList));
} else {
// 如果cityName改变,则查询替换cityName和newsList
cityName = city.getCity();
newsList = newsService.findHousingEstate(cityName);
try {
sendNews(city, newsList);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
THREAD_POOL.execute(new MyThread(city, newsList));
}
}
}
private void sendNews(CityCollect city, List<News> newsList) {
if (null != newsList && !newsList.isEmpty()) {
for (News n : newsList) {
@@ -67,13 +73,42 @@ public class HousingEstateNewsSendJob implements SimpleJob {
if (null == sendList || sendList.isEmpty()) {
LOG.info("小区推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
// 3.发送
// TODO
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
new String[] { "push_client_id" });
String pushMsg = n.getContent();
LOG.info(pushMsg);
PushMessageParam param = new PushMessageParam();
param.setTitle(n.getTitle());
param.setContent(pushMsg);
param.setOperation(1);
param.setOperationPage("");
param.setPushClientId(user.getPushClientId());
pushMessageService.push(param);
// 4.记录
citySendLogService.save(city.getCity(), city.getUid(), n.getId(), FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
citySendLogService.save(city.getCity(), city.getUid(), n.getId(),
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
}
}
}
}
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);
}
}
}
}
@@ -1,18 +1,26 @@
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 TopNewsSendJob implements SimpleJob {
@@ -27,6 +35,14 @@ public class TopNewsSendJob implements SimpleJob {
@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);
@@ -38,20 +54,13 @@ public class TopNewsSendJob implements SimpleJob {
for (CityCollect city : cityList) {
// cityList已排序好,如果cityName不变,则使用上个newsList
if (cityName.equals(city.getCity())) {
try {
sendNews(city, newsList);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
THREAD_POOL.execute(new MyThread(city, newsList));
} else {
// 如果cityName改变,则查询替换cityName和newsList
cityName = city.getCity();
newsList = newsService.findTopNews(cityName);
try {
sendNews(city, newsList);
} catch (Exception e) {
LOG.error("推送失败!", e);
}
THREAD_POOL.execute(new MyThread(city, newsList));
}
}
}
@@ -65,7 +74,17 @@ public class TopNewsSendJob implements SimpleJob {
if (null == sendList || sendList.isEmpty()) {
LOG.info("新闻推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
// 3.发送
// TODO
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
new String[] { "push_client_id" });
String pushMsg = n.getContent();
LOG.info(pushMsg);
PushMessageParam param = new PushMessageParam();
param.setTitle(n.getTitle());
param.setContent(pushMsg);
param.setOperation(1);
param.setOperationPage("");
param.setPushClientId(user.getPushClientId());
pushMessageService.push(param);
// 4.记录
citySendLogService.save(city.getCity(), city.getUid(), n.getId(), FangjiaConstant.NEWS_SEND_TYPE);
}
@@ -74,4 +93,23 @@ public class TopNewsSendJob implements SimpleJob {
}
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);
}
}
}
}
+14
View File
@@ -90,4 +90,18 @@
</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>