|
|
@@ -1,20 +1,86 @@
|
|
|
package com.goafanti.common.task;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import com.goafanti.common.constant.AFTConstants;
|
|
|
+import com.goafanti.common.utils.DateUtils;
|
|
|
import com.goafanti.common.utils.LoggerUtils;
|
|
|
+import com.goafanti.patent.bo.PatentExpireBO;
|
|
|
+import com.goafanti.patent.service.PatentInfoService;
|
|
|
|
|
|
@Component
|
|
|
public class PatentTask {
|
|
|
+ @Resource
|
|
|
+ private PatentInfoService patentInfoService;
|
|
|
+
|
|
|
+ private static final String LEAP_DAY = "02-29";
|
|
|
+
|
|
|
+ private static final String LEAP_DAY_ADD = "03-01";
|
|
|
+
|
|
|
/**
|
|
|
* "0 0 10 * * ?" 每天上午10点触发一次
|
|
|
*/
|
|
|
+
|
|
|
@Scheduled(cron = "0 0 10 * * ?")
|
|
|
public void run() {
|
|
|
LoggerUtils.debug(getClass(), "开始检查专利到期");
|
|
|
+ List<PatentExpireBO> peb = patentInfoService.selectExpireRecord();
|
|
|
+ if (null != peb && peb.size() > 0) {
|
|
|
+ for (PatentExpireBO p : peb) {
|
|
|
+ if (!StringUtils.isBlank(p.getFirstMobile()) && StringUtils.isNumeric(p.getFirstMobile())
|
|
|
+ && null != p.getPatentApplicationDate()) {
|
|
|
+ try {
|
|
|
+ if (disposeExprire(p)){
|
|
|
+ //TODO 发送短信
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
|
|
|
+ private Boolean disposeExprire(PatentExpireBO peb) throws ParseException{
|
|
|
+ Date addYear = disposeAddYear(peb.getPatentApplicationDate());//申请日5年后
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ if (addYear.getTime() - now.getTime().getTime() >= 0){
|
|
|
+ return disposeExprireDate(peb.getPatentApplicationDate(), now.getTime());
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean disposeExprireDate(Date apd, Date now){
|
|
|
+ String sApd = DateFormatUtils.format(apd, AFTConstants.YYYYMMDD).substring(5,9);
|
|
|
+ String sNow = DateFormatUtils.format(now, AFTConstants.YYYYMMDD).substring(5,9);
|
|
|
+ if (LEAP_DAY.equals(sApd)){
|
|
|
+ if (LEAP_DAY_ADD.equals(sNow)){
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (sApd.equals(sNow)){
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date disposeAddYear(Date s) throws ParseException{
|
|
|
+ String d = DateFormatUtils.format(s, AFTConstants.YYYYMMDD);
|
|
|
+ String suffix = d.substring(4, 9);
|
|
|
+ int year = Integer.parseInt(d.substring(0, 3));
|
|
|
+ int expireYear = year + 5;
|
|
|
+ String expireDate = expireYear + suffix;
|
|
|
+ return DateUtils.parseDate(expireDate, AFTConstants.YYYYMMDD);
|
|
|
+ }
|
|
|
+
|
|
|
}
|