From 3d27184a0011decfa2813ba33e6b6f0a484240ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E5=90=89=E6=AC=A2?= Date: Fri, 18 May 2018 14:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=9F=E9=87=91=E6=8F=90=E9=86=92=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../job/common/util/DateUtilCustom.java | 26 +++ .../job/youfang/job/HouseRentNoticeJob.java | 149 +++++++++++++++++- .../service/EnterpriseProductUserService.java | 2 + .../EnterpriseProductUserServiceImpl.java | 5 + .../job/youfang/service/HouseInfoService.java | 9 ++ .../youfang/service/HouseInfoServiceImpl.java | 7 + 6 files changed, 192 insertions(+), 6 deletions(-) diff --git a/fangjia-job/fangjia-job-common/src/main/java/com/fangjia/job/common/util/DateUtilCustom.java b/fangjia-job/fangjia-job-common/src/main/java/com/fangjia/job/common/util/DateUtilCustom.java index 34f5d34..7f9372d 100644 --- a/fangjia-job/fangjia-job-common/src/main/java/com/fangjia/job/common/util/DateUtilCustom.java +++ b/fangjia-job/fangjia-job-common/src/main/java/com/fangjia/job/common/util/DateUtilCustom.java @@ -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))); } diff --git a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/job/HouseRentNoticeJob.java b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/job/HouseRentNoticeJob.java index 7c382c8..02de523 100644 --- a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/job/HouseRentNoticeJob.java +++ b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/job/HouseRentNoticeJob.java @@ -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; /** * 房产租金提醒任务
@@ -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 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=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() queryAddUser(String start, String end); + + EnterpriseProductUser getById(Long id, String[] fields); } diff --git a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/EnterpriseProductUserServiceImpl.java b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/EnterpriseProductUserServiceImpl.java index 06bfdcf..eeab168 100644 --- a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/EnterpriseProductUserServiceImpl.java +++ b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/EnterpriseProductUserServiceImpl.java @@ -42,4 +42,9 @@ public class EnterpriseProductUserServiceImpl extends EntityService queryHousesByPage(int page, int limit, String[] fields); } diff --git a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/HouseInfoServiceImpl.java b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/HouseInfoServiceImpl.java index d5d5477..8b6ec74 100644 --- a/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/HouseInfoServiceImpl.java +++ b/fangjia-job/fangjia-job-youfang/src/main/java/com/fangjia/job/youfang/service/HouseInfoServiceImpl.java @@ -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 implements Ho } return sum; } + + @Override + public List queryHousesByPage(int page, int limit, String[] fields) { + int start = PageBean.page2Start(page, limit); + return super.listForPage(fields, "remove_status", 0, start, limit); + } }