添加推送结果返回的方法及相应处理方法
This commit is contained in:
+2
@@ -23,4 +23,6 @@ public class FangjiaConstant {
|
|||||||
|
|
||||||
public static final int URL_SEND_TYPE = 2;
|
public static final int URL_SEND_TYPE = 2;
|
||||||
|
|
||||||
|
public static final int SEND_ERROR_LIMIT = 3; //失败尝试的上限
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -17,7 +17,7 @@ public class CitySendLog {
|
|||||||
|
|
||||||
private long uid;
|
private long uid;
|
||||||
|
|
||||||
private long newsId;
|
private Long newsId;
|
||||||
|
|
||||||
private Date sendTime;
|
private Date sendTime;
|
||||||
|
|
||||||
@@ -26,4 +26,10 @@ public class CitySendLog {
|
|||||||
*/
|
*/
|
||||||
private byte sendType;
|
private byte sendType;
|
||||||
|
|
||||||
|
// 推送次数
|
||||||
|
private int sendNum;
|
||||||
|
|
||||||
|
// 推送状态
|
||||||
|
private Boolean sendStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-9
@@ -144,11 +144,11 @@ public class CityRankingSendJob implements SimpleJob {
|
|||||||
private Integer sendRankings(CityCollect city, List<CityStatInfoDto> list, byte sendType) {
|
private Integer sendRankings(CityCollect city, List<CityStatInfoDto> list, byte sendType) {
|
||||||
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
||||||
if ((null == sendList || sendList.isEmpty()) && !list.isEmpty()) {
|
if ((null == sendList || sendList.isEmpty()) && !list.isEmpty()) {
|
||||||
//取排名并发送
|
// 取排名并发送
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
if (city.getCity().equals(list.get(i).getCity())) {
|
if (city.getCity().equals(list.get(i).getCity())) {
|
||||||
int rankings = i + 1;// 排名
|
int rankings = i + 1;// 排名
|
||||||
baseSend(city, rankings, sendType);
|
baseSend(city, rankings, sendType, null);
|
||||||
return rankings;
|
return rankings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,9 +164,14 @@ public class CityRankingSendJob implements SimpleJob {
|
|||||||
* @param sendType
|
* @param sendType
|
||||||
*/
|
*/
|
||||||
private void sendAndInspect(CityCollect city, Integer rankings, byte sendType) {
|
private void sendAndInspect(CityCollect city, Integer rankings, byte sendType) {
|
||||||
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
if (null != rankings) {
|
||||||
if ((null == sendList || sendList.isEmpty()) && null != rankings) {
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), null, sendType);
|
||||||
baseSend(city, rankings, 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +182,7 @@ public class CityRankingSendJob implements SimpleJob {
|
|||||||
* @param rankings
|
* @param rankings
|
||||||
* @param sendType
|
* @param sendType
|
||||||
*/
|
*/
|
||||||
private void baseSend(CityCollect city, Integer rankings, byte sendType) {
|
private void baseSend(CityCollect city, Integer rankings, byte sendType, CitySendLog log) {
|
||||||
String title = null;
|
String title = null;
|
||||||
if (FangjiaConstant.INCREASE_SEND_TYPE == sendType) {
|
if (FangjiaConstant.INCREASE_SEND_TYPE == sendType) {
|
||||||
title = city.getCity() + ",全国城市涨幅排名第" + rankings + "位";
|
title = city.getCity() + ",全国城市涨幅排名第" + rankings + "位";
|
||||||
@@ -196,15 +201,24 @@ public class CityRankingSendJob implements SimpleJob {
|
|||||||
param.setTitle("排行榜提醒");
|
param.setTitle("排行榜提醒");
|
||||||
param.setContent(title);
|
param.setContent(title);
|
||||||
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
|
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
|
||||||
param.setOperationPage("/views/house/cityDetail.html?city="+city.getCity());
|
param.setOperationPage("/views/house/cityDetail.html?city=" + city.getCity());
|
||||||
|
boolean result = false;
|
||||||
|
int sendNum = 1;
|
||||||
if (null != user) {
|
if (null != user) {
|
||||||
param.setPushClientId(user.getPushClientId());
|
param.setPushClientId(user.getPushClientId());
|
||||||
pushMessageService.push(param);
|
result = pushMessageService.pushByReturn(param);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
||||||
|
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;
|
||||||
}
|
}
|
||||||
// 记录
|
// 记录
|
||||||
citySendLogService.save(city.getCity(), city.getUid(), 0L, sendType);
|
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 {
|
class MyThread extends Thread {
|
||||||
|
|||||||
+18
-6
@@ -70,7 +70,8 @@ public class HousingEstateNewsSendJob implements SimpleJob {
|
|||||||
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
||||||
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
|
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
|
||||||
// 未推送过的推送
|
// 未推送过的推送
|
||||||
if (null == sendList || sendList.isEmpty()) {
|
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());
|
LOG.info("小区推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
|
||||||
// 3.发送
|
// 3.发送
|
||||||
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
|
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
|
||||||
@@ -81,17 +82,28 @@ public class HousingEstateNewsSendJob implements SimpleJob {
|
|||||||
param.setTitle(n.getTitle());
|
param.setTitle(n.getTitle());
|
||||||
param.setContent(pushMsg);
|
param.setContent(pushMsg);
|
||||||
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
|
param.setOperation(FangjiaConstant.URL_SEND_TYPE);
|
||||||
param.setOperationPage("/views/district/detail.html?city=" + n.getRecommendDistrictCity() + "®ion="
|
param.setOperationPage("/views/district/detail.html?city=" + n.getRecommendDistrictCity()
|
||||||
+ n.getRecommendDistrictRegion() + "&name=" + n.getRecommendDistrictName());
|
+ "®ion=" + n.getRecommendDistrictRegion() + "&name=" + n.getRecommendDistrictName());
|
||||||
|
|
||||||
|
boolean result = false;
|
||||||
|
int sendNum = 1;
|
||||||
if (null != user) {
|
if (null != user) {
|
||||||
param.setPushClientId(user.getPushClientId());
|
param.setPushClientId(user.getPushClientId());
|
||||||
pushMessageService.push(param);
|
result = pushMessageService.pushByReturn(param);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
||||||
|
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;// 不可推送的,次数直接置为3次,避免再次推送
|
||||||
}
|
}
|
||||||
// 4.记录
|
// 4.记录
|
||||||
citySendLogService.save(city.getCity(), city.getUid(), n.getId(),
|
if (null == sendList || sendList.isEmpty()) {
|
||||||
FangjiaConstant.HOUSING_ESTATE_SEND_TYPE);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-6
@@ -11,6 +11,7 @@ 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.common.base.FangjiaConstant;
|
||||||
|
import com.fangjia.job.common.util.JsonUtils;
|
||||||
import com.fangjia.job.youfang.document.CitySendLog;
|
import com.fangjia.job.youfang.document.CitySendLog;
|
||||||
import com.fangjia.job.youfang.param.PushMessageParam;
|
import com.fangjia.job.youfang.param.PushMessageParam;
|
||||||
import com.fangjia.job.youfang.po.CityCollect;
|
import com.fangjia.job.youfang.po.CityCollect;
|
||||||
@@ -70,14 +71,14 @@ public class TopNewsSendJob implements SimpleJob {
|
|||||||
for (News n : newsList) {
|
for (News n : newsList) {
|
||||||
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
List<CitySendLog> sendList = citySendLogService.find(city.getUid(), n.getId(),
|
||||||
FangjiaConstant.NEWS_SEND_TYPE);
|
FangjiaConstant.NEWS_SEND_TYPE);
|
||||||
// 未推送过的推送
|
// 未推送过的推送或推送失败次数少于三次
|
||||||
if (null == sendList || sendList.isEmpty()) {
|
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());
|
LOG.info("新闻推送开始。。。uid:" + city.getUid() + ",newsId:" + n.getId());
|
||||||
// 3.发送
|
// 3.发送
|
||||||
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
|
EnterpriseProductUser user = enterpriseProductUserService.getById(city.getUid(),
|
||||||
new String[] { "push_client_id" });
|
new String[] { "push_client_id" });
|
||||||
String pushMsg = n.getIntroduction();
|
String pushMsg = n.getIntroduction();
|
||||||
LOG.info(pushMsg);
|
|
||||||
PushMessageParam param = new PushMessageParam();
|
PushMessageParam param = new PushMessageParam();
|
||||||
param.setTitle(n.getTitle());
|
param.setTitle(n.getTitle());
|
||||||
param.setContent(pushMsg);
|
param.setContent(pushMsg);
|
||||||
@@ -107,15 +108,26 @@ public class TopNewsSendJob implements SimpleJob {
|
|||||||
default:
|
default:
|
||||||
param.setOperationPage("/views/news/newsDetail.html?newsId=" + n.getId());
|
param.setOperationPage("/views/news/newsDetail.html?newsId=" + n.getId());
|
||||||
}
|
}
|
||||||
|
boolean result = false;
|
||||||
|
int sendNum = 1;
|
||||||
if (null != user) {
|
if (null != user) {
|
||||||
param.setPushClientId(user.getPushClientId());
|
param.setPushClientId(user.getPushClientId());
|
||||||
//LOG.info("param:" + JsonUtils.toJson(param));
|
LOG.info("param:" + JsonUtils.toJson(param));
|
||||||
pushMessageService.push(param);
|
result = pushMessageService.pushByReturn(param);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
LOG.info("PushClientId查询不到,uid:" + city.getUid());
|
||||||
|
sendNum = FangjiaConstant.SEND_ERROR_LIMIT;// 不可推送的,次数直接置为3次,避免再次推送
|
||||||
}
|
}
|
||||||
// 4.记录
|
// 4.记录
|
||||||
citySendLogService.save(city.getCity(), city.getUid(), n.getId(), FangjiaConstant.NEWS_SEND_TYPE);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -6,7 +6,9 @@ import com.fangjia.job.youfang.document.CitySendLog;
|
|||||||
|
|
||||||
public interface CitySendLogService {
|
public interface CitySendLogService {
|
||||||
|
|
||||||
void save(String city, Long uid, Long nId, byte sendType);
|
CitySendLog save(String city, Long uid, Long nId, byte sendType, Boolean sendStatus, int sendNum);
|
||||||
|
|
||||||
List<CitySendLog> find(long uid, Long newsId, Byte sendType);
|
List<CitySendLog> find(long uid, Long newsId, Byte sendType);
|
||||||
|
|
||||||
|
void update(CitySendLog log);
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-1
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.fangjia.job.youfang.document.CitySendLog;
|
import com.fangjia.job.youfang.document.CitySendLog;
|
||||||
@@ -19,14 +20,17 @@ public class CitySendLogServiceImpl implements CitySendLogService {
|
|||||||
private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(String city, Long uid, Long nId, byte sendType) {
|
public CitySendLog save(String city, Long uid, Long nId, byte sendType, Boolean sendStatus, int sendNum) {
|
||||||
CitySendLog log = new CitySendLog();
|
CitySendLog log = new CitySendLog();
|
||||||
log.setCity(city);
|
log.setCity(city);
|
||||||
log.setNewsId(nId);
|
log.setNewsId(nId);
|
||||||
log.setSendTime(new Date());
|
log.setSendTime(new Date());
|
||||||
log.setSendType(sendType);
|
log.setSendType(sendType);
|
||||||
log.setUid(uid);
|
log.setUid(uid);
|
||||||
|
log.setSendStatus(sendStatus);
|
||||||
|
log.setSendNum(sendNum);
|
||||||
mongoTemplate.save(log);
|
mongoTemplate.save(log);
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,4 +56,21 @@ public class CitySendLogServiceImpl implements CitySendLogService {
|
|||||||
c.add(Calendar.MONTH, -1);
|
c.add(Calendar.MONTH, -1);
|
||||||
return c.getTime();
|
return c.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
|
@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()).update("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()).update("sendStatus", log.getSendStatus()),
|
||||||
|
CitySendLog.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -10,4 +10,10 @@ public interface PushMessageService {
|
|||||||
*/
|
*/
|
||||||
void push(PushMessageParam param);
|
void push(PushMessageParam param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送消息
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
boolean pushByReturn(PushMessageParam param);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.cxytiandi.jdbc.EntityService;
|
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.DingDingMessageUtil;
|
||||||
import com.fangjia.job.common.util.RestApiCallUtils;
|
import com.fangjia.job.common.util.RestApiCallUtils;
|
||||||
import com.fangjia.job.youfang.param.PushMessageParam;
|
import com.fangjia.job.youfang.param.PushMessageParam;
|
||||||
@@ -41,4 +42,26 @@ public class PushMessageServiceImpl extends EntityService<PushMessage> implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user