Antiloveg лет назад: 8
Родитель
Сommit
78e9098cde

+ 2 - 1
src/main/java/com/goafanti/common/mapper/PatentInfoMapper.xml

@@ -991,7 +991,8 @@
   <select id="selectExpireRecord"  resultType="com.goafanti.patent.bo.PatentExpireBO">	
   	select 
   		p.id, p.uid, p.patent_name as patentName, 
-  	    p.patent_application_date as patentApplicationDate, u.mobile
+  	    p.patent_application_date as patentApplicationDate, u.mobile,
+  	    p.serial_number as serialNumber
   	from patent_info p 
 		LEFT JOIN patent_cost pc on p.id = pc.pid
 		LEFT JOIN user u on u.id = p.uid

+ 46 - 12
src/main/java/com/goafanti/common/task/PatentTask.java

@@ -9,6 +9,7 @@ import javax.annotation.Resource;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
+import org.junit.Test;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -22,7 +23,6 @@ import com.aliyuncs.profile.IClientProfile;
 import com.aliyuncs.sms.model.v20160927.SingleSendSmsRequest;
 import com.aliyuncs.sms.model.v20160927.SingleSendSmsResponse;
 import com.goafanti.common.constant.AFTConstants;
-import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.patent.bo.PatentExpireBO;
@@ -32,23 +32,23 @@ import com.goafanti.patent.service.PatentInfoService;
 public class PatentTask {
 	@Resource
 	private PatentInfoService	patentInfoService;
-	
+
 	@Value(value = "${accessKey}")
-	private String					accessKey			= null;
+	private String				accessKey		= null;
 
 	@Value(value = "${accessSecret}")
-	private String					accessSecret		= null;
+	private String				accessSecret	= null;
 
 	private static final String	LEAP_DAY		= "02-29";
 
 	private static final String	LEAP_DAY_ADD	= "03-01";
 
 	/**
-	 * "0 0 10 * * ?" 每天上午10点触发一次
+	 * "0 0 6 * * ?" 每天上午6点触发一次
 	 */
 
-	@Scheduled(cron = "0 0 10 * * ?")
-	public void run() {
+	@Scheduled(cron = "0 0 6 * * ?")
+	public void exprireRun() {
 		LoggerUtils.debug(getClass(), "开始检查专利到期");
 		List<PatentExpireBO> peb = patentInfoService.selectExpireRecord();
 		if (null != peb && peb.size() > 0) {
@@ -58,23 +58,56 @@ public class PatentTask {
 						&& null != p.getPatentApplicationDate()) {
 					try {
 						if (disposeExprire(p)) {
-							sendMessage(mobile);
+							sendMessage(p);
+						}
+					} catch (ParseException e) {
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * "0 0 0 * * ?" 每天0点触发一次
+	 */
+	@Scheduled(cron = "0 0 0 * * ?")
+	public void annualFeeRun() {
+		LoggerUtils.debug(getClass(), "开始检查专利年费续缴");
+		List<PatentExpireBO> peb = patentInfoService.selectExpireRecord();
+		if (null != peb && peb.size() > 0) {
+			for (PatentExpireBO p : peb) {
+				String mobile = p.getMobile();
+				if (StringUtils.isNotBlank(mobile) && StringUtils.isNumeric(mobile)
+						&& null != p.getPatentApplicationDate()) {
+					try {
+						if (disposeExprire(p)) {
+							sendMessage(p);
 						}
 					} 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) {
+			now.add(Calendar.MONTH, -3);//提前三个月
 			return disposeExprireDate(peb.getPatentApplicationDate(), now.getTime());
 		}
 		return Boolean.FALSE;
 	}
+	
+	@Test
+	public void test(){
+		Calendar now = Calendar.getInstance();
+		now.add(Calendar.MONTH, -3);
+		System.out.println(DateFormatUtils.format(now.getTime(), AFTConstants.MMDD));
+	}
 
 	private Boolean disposeExprireDate(Date apd, Date now) {
 		String sApd = DateFormatUtils.format(apd, AFTConstants.MMDD);
@@ -95,8 +128,8 @@ public class PatentTask {
 		return DateUtils.parseDate((Integer.parseInt(DateFormatUtils.format(s, AFTConstants.YYYY)) + 5) + "-"
 				+ DateFormatUtils.format(s, AFTConstants.MMDD), AFTConstants.YYYYMMDD);
 	}
-	
-	private void sendMessage(String mobile){
+
+	private void sendMessage(PatentExpireBO p) {
 		IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKey, accessSecret);
 		try {
 			DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Sms", "sms.aliyuncs.com");
@@ -107,8 +140,9 @@ public class PatentTask {
 		try {
 			request.setSignName("阿凡提信息科技");// {\"code\":\""+mobileVerifyCode+"\"}
 			request.setTemplateCode("SMS_37845022");
-			//request.setParamString("{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"阿凡提信息科技\"}");
-			request.setRecNum(mobile);
+			request.setParamString(
+					"{\"code\":\"" + p.getSerialNumber() + p.getPatentName() + "\",\"product\":\"阿凡提信息科技\"}");
+			request.setRecNum(p.getMobile());
 			SingleSendSmsResponse httpResponse = client.getAcsResponse(request);
 		} catch (ServerException e) {
 			LoggerUtils.fmtError(getClass(), e, "服务器端手机短信异常:%s", e.getMessage());

+ 10 - 0
src/main/java/com/goafanti/patent/bo/PatentExpireBO.java

@@ -15,6 +15,8 @@ public class PatentExpireBO {
 	
 	private String uid;
 	
+	private Integer serialNumber;
+	
 	/**
 	 * 专利名称
 	 */
@@ -45,6 +47,14 @@ public class PatentExpireBO {
 	public void setUid(String uid) {
 		this.uid = uid;
 	}
+	
+	public Integer getSerialNumber() {
+		return serialNumber;
+	}
+
+	public void setSerialNumber(Integer serialNumber) {
+		this.serialNumber = serialNumber;
+	}
 
 	public String getPatentName() {
 		return patentName;

+ 1 - 1
src/main/resources/shiro_base_auth.ini

@@ -12,7 +12,7 @@
 /open/**=anon
 /favicon.ico=anon
 /static/**=anon
-/portal/search/**=anon
+/portal/**=anon
 /api/admin/**=admin,permission
 /api/user/**=login
 /admin/servicesManage/**=admin