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

This commit is contained in:
bayi
2018-05-18 15:25:10 +08:00
6 changed files with 192 additions and 6 deletions
@@ -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)));
}
@@ -1,15 +1,25 @@
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.po.EnterpriseProductUser;
import com.fangjia.job.youfang.po.HouseInfo;
import com.fangjia.job.youfang.service.EnterpriseProductUserService;
import com.fangjia.job.youfang.service.HouseInfoService;
/**
* 房产租金提醒任务<br>
@@ -23,10 +33,16 @@ public class HouseRentNoticeJob implements SimpleJob {
@Value("${fsh.url}")
private String fshApiUrl;
@Autowired
private HouseInfoService houseInfoService;
@Autowired
private EnterpriseProductUserService enterpriseProductUserService;
@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 +59,129 @@ 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 {
if("出租".equals(h.getLiveStatus())) {
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) {
if(houseInfo.getId().equals(107419093023326208L)){
System.out.println("a");
}
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) {
String pushMsg = DateUtils.date2Str(nextDay, "yyyy年MM月dd日") + "是您的到期收租日,又要有现金到账咯,请注意查收。详情请点击查看。";
System.err.println(pushMsg);
}
}
}
// 租房到期推送,提前一个月/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) {
String pushMsg = DateUtils.date2Str(leaseEndDate, "yyyy年MM月dd日") + "您的房子租期就到了,快来看看现在的市场租金价格吧。详情请点击查看。";
System.err.println(pushMsg);
EnterpriseProductUser user = enterpriseProductUserService.getById(Long.parseLong(house.getUid()), new String[] { "push_client_id" });
}
}
}
@@ -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);
}
}