Browse Source

定时任务开发

anderx 4 years ago
parent
commit
e456fdc9b1

+ 2 - 0
src/main/java/com/goafanti/common/dao/PatentNewMapper.java

@@ -67,4 +67,6 @@ public interface PatentNewMapper {
 
 	String selectUserNameByTid(Integer tid);
 
+	void updateBatchStatusByid(@Param("list")List<String> list, @Param("status")Integer status);
+
 }

File diff suppressed because it is too large
+ 628 - 580
src/main/java/com/goafanti/common/mapper/PatentNewMapper.xml


+ 98 - 65
src/main/java/com/goafanti/common/task/PatentTask.java

@@ -73,11 +73,16 @@ public class PatentTask {
 			List<PatentNewBo> l = patentNewService.AllselectStartPatentNew();
 			List<Notice> nlist = new ArrayList<>();
 			List<PatentNewLog> logList = new ArrayList<>();
+			List<String> s1=new ArrayList<String>();
+			List<String> s2=new ArrayList<String>();
+			List<String> s3=new ArrayList<String>();
+			List<String> s4=new ArrayList<String>();
+			List<String> s5=new ArrayList<String>();
 			for (PatentNewBo p : l) {
 				// 申请时间
 				Calendar end = Calendar.getInstance();
 				end.setTime(p.getEndDate());
-				Integer status = 0;
+				Integer status = p.getStatus();
 				// 当前时间
 				Calendar now = Calendar.getInstance();
 				now.setTime(new Date());
@@ -88,46 +93,42 @@ public class PatentTask {
 				Date date=new Date();
 				// 计算相差日期
 				int count = (int) ((end.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
-				Notice n = new Notice();
-				n.setId(UUID.randomUUID().toString());
-				n.setCreateTime(date);
-				n.setReaded(0);// 未读
-				n.setNoticeType(NoticeStatus.TASK_PATENT_ERROR.getCode());
 				boolean flag=false;
-				if (count > 30 && count <= 90&&p.getStatus()!=1) {
+				if (count > 60 && count <= 90&&p.getStatus()!=1) {
 					flag=true;
 					status = 1;
-				} else if (count > 20 && count <= 30&&p.getStatus()!=2) {
+					s1.add(p.getId().toString());
+				} else if (count > 30 && count <= 60&&p.getStatus()!=2) {
 					flag=true;
 					status = 2;
-				}else if (count > 10 && count <= 20&&p.getStatus()!=3) {
+					s2.add(p.getId().toString());
+				}else if (count > 15 && count <= 30&&p.getStatus()!=3) {
 					flag=true;
 					status = 3;
-				}else if (count > 3 && count <= 10&&p.getStatus()!=4) {
+					s3.add(p.getId().toString());
+				}else if (count > 7 && count <= 15&&p.getStatus()!=4) {
 					flag=true;
 					status = 4;
+					s4.add(p.getId().toString());
+				}else if (count>0&&count <= 7&&p.getStatus()!=5) {
+					flag=true;
+					status = 5;
+					s4.add(p.getId().toString());
 				}
-				//取消3天,2天,1天提醒
-//				else if (count == 3&&p.getStatus()!=5) {
-//					flag=true;
-//					status = 5;
-//				}else if (count == 2&&p.getStatus()!=6) {
-//					flag=true;
-//					status = 6;
-//				}else if (count == 1&&p.getStatus()!=7) {
-//					flag=true;
-//					status = 7;
-//				}
 				if (flag) {
+					Notice n = new Notice();
+					n.setId(UUID.randomUUID().toString());
+					n.setCreateTime(date);
+					n.setReaded(0);// 未读
+					n.setNoticeType(NoticeStatus.TASK_PATENT_ERROR.getCode());
 					Admin a = adminService.selectByPrimaryKey(p.getAid());
 					StringBuffer str2 = new StringBuffer();
-					str2.append("专利编号=").append(p.getPatentNo()).append("名称=").append(p.getName()).append(",email=")
-							.append(p.getEmail().trim());
-					n.setContent(str2.toString());
+					str2.append("专利编号[").append(p.getPatentNo()).append("],名称[").append(p.getName()).append("],email[")
+							.append(p.getEmail().trim()).append("]");
 					if (a == null) {
 						str2.append(",aid=").append(p.getAid()).append(",找不到管理员。");
-						n.setContent(str2.toString());
 						n.setAid("1");
+						n.setContent(str2.toString());
 						nlist.add(n);
 						continue;
 					} else if (!SendEmailUtil.isEmail(p.getEmail().trim())) {
@@ -146,42 +147,29 @@ public class PatentTask {
 						nlist.add(n2);
 						continue;
 					} else {
-						String title = "提醒失败!对方邮箱不存在或者拒收!";
 						PatentNewLog pl = new PatentNewLog();
-						String str = StrToString(title, p.getEmail().trim(), p.getUserName() ,p.getName(),date,status);
+						String str = StrToString(str2,end.getTime(),status);
 						pl.setContent(str);
+						System.out.println(str);
 						pl.setCreateTime(new Date());
 						pl.setPid(p.getId());
 						logList.add(pl);
 						n.setAid(p.getAid());
+						n.setNoticeType(NoticeStatus.TASK_PATENT_REMIND.getCode());
 						n.setContent(str);
 						nlist.add(n);
 					}
 				}
 			}
-			if (!nlist.isEmpty()) {
-				List<Notice> newList = new ArrayList<>();
-				for (int i = 0; i < nlist.size(); i++) {
-					newList.add(nlist.get(i));
-					if (pointsDataLimit == newList.size() || i == nlist.size() - 1) {
-						if (newList.size() > 0) asyncUtils.addNoticeBatch(newList);
-						Thread.sleep(2000);
-						newList.clear();
-					}
-				}
-			}
-			if (!logList.isEmpty()) {
-				List<PatentNewLog> logList2 = new ArrayList<>();
-				for (int i = 0; i < logList.size(); i++) {
-					logList2.add(logList.get(i));
-					if (pointsDataLimit == logList2.size() || i == logList.size() - 1) {
-						if (logList2.size() > 0) patentNewService.insertLogBatch(logList2);
-						logList2.clear();
-						Thread.sleep(2000);
-					}
-				}
-
-			}
+			pushNotice(nlist);
+			pushPatentLog(logList);
+			//将不同状态的修改成不同状态
+			updatePatentNew(s1,1);
+			updatePatentNew(s2,2);
+			updatePatentNew(s3,3);
+			updatePatentNew(s4,4);
+			updatePatentNew(s5,5);
+			
 		} catch (Exception e) {
 			LoggerUtils.debug(getClass(), "=====================专利提醒失败======================");
 			Notice n = new Notice(UUID.randomUUID().toString(), new Date(), 0, "1",
@@ -192,28 +180,73 @@ public class PatentTask {
 
 		LoggerUtils.debug(getClass(), "=====================专利提醒结束======================");
 	}
+
+
+	private void pushNotice(List<Notice> nlist) throws InterruptedException {
+		if (!nlist.isEmpty()) {
+			List<Notice> newList = new ArrayList<>();
+			for (int i = 0; i < nlist.size(); i++) {
+				newList.add(nlist.get(i));
+				if (pointsDataLimit == newList.size() || i == nlist.size() - 1) {
+					if (newList.size() > 0) asyncUtils.addNoticeBatch(newList);
+					Thread.sleep(2000);
+					newList.clear();
+				}
+			}
+		}
+	}
+
+
+	private void pushPatentLog(List<PatentNewLog> logList) throws InterruptedException {
+		if (!logList.isEmpty()) {
+			List<PatentNewLog> logList2 = new ArrayList<>();
+			for (int i = 0; i < logList.size(); i++) {
+				logList2.add(logList.get(i));
+				if (pointsDataLimit == logList2.size() || i == logList.size() - 1) {
+					if (logList2.size() > 0) patentNewService.insertLogBatch(logList2);
+					Thread.sleep(2000);
+					logList2.clear();
+				}
+			}
+
+		}
+	}
 	
 
-	private String StrToString(String title, String email, String userName, String pname, Date date, Integer status) {
+	/**
+	 * 修改专利状态
+	 * @param s1
+	 * @param status
+	 * @throws InterruptedException 
+	 */
+	private void updatePatentNew(List<String> list, Integer status) throws InterruptedException {
+		if (!list.isEmpty()) {
+			List<String> l2 = new ArrayList<>();
+			for (int i = 0; i < list.size(); i++) {
+				l2.add(list.get(i));
+				if (pointsDataLimit == l2.size() || i == list.size() - 1) {
+					if (l2.size() > 0) patentNewService.updateBatchStatusByid(l2, status);
+					l2.clear();
+					Thread.sleep(2000);
+				}
+			}
+		}
+	}
+
+
+	private String StrToString(StringBuffer str, Date date, Integer status) {
 		//状态 0 未提醒 1 剩余90天 2剩余30天 3剩余20天 4剩余10天 5剩余3天 6剩余2天 7剩余1天
 		Integer days=0;
-		StringBuffer sb=new StringBuffer().append(title).append("客户[").append(userName).append("]专利[")
-				.append(pname).append("]");
 		if (status==1) days=90;
-		else if (status==2) days=30;
-		else if (status==3) days=20;
-		else if (status==4) days=10;
-		else if (status==5) days=3;
-		else if (status==6) days=2;
-		else if (status==7) days=1;
+		else if (status==2) days=60;
+		else if (status==3) days=30;
+		else if (status==4) days=15;
+		else if (status==5) days=7;
 		if(days>0) {
-			sb.append(",续费时间还剩").append(days).append("天");
+			str.append(",续费时间还剩").append(days).append("天");
 		}
-		sb.append(",已于").append(DateUtils.formatDate(date, AFTConstants.YYYYMMDDHHMMSS)).append("发送专利提醒至邮箱")
-			.append(email).append("!");
-				
-		
-		return sb.toString();
+		str.append(",截止时间[").append(DateUtils.formatDate(date, AFTConstants.YYYYMMDD)).append("]请在截止时间前通知客户!");
+		return str.toString();
 	}
 	
 

+ 2 - 0
src/main/java/com/goafanti/patent/service/PatentNewService.java

@@ -40,4 +40,6 @@ public interface PatentNewService {
 	  
 	Object updateBatch(String ids, Integer type);
 
+	void updateBatchStatusByid(List<String> l2, Integer status);
+
 }

+ 6 - 0
src/main/java/com/goafanti/patent/service/impl/PatentNewServiceImpl.java

@@ -395,4 +395,10 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 		patentNewMapper.updateBatch(ls);
 		return 1;
 	}
+
+	@Override
+	public void updateBatchStatusByid(List<String> l2, Integer status) {
+		patentNewMapper.updateBatchStatusByid(l2,status);
+		
+	}
 }