Browse Source

新增时触发邮件提醒

anderx 4 years ago
parent
commit
79d73088ea

+ 5 - 17
src/main/java/com/goafanti/common/task/PatentTask.java

@@ -1,7 +1,6 @@
 package com.goafanti.common.task;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
@@ -79,22 +78,12 @@ public class PatentTask {
 			List<String> s4=new ArrayList<String>();
 			List<String> s5=new ArrayList<String>();
 			List<String> s6=new ArrayList<String>();
+			Date date=new Date();
 			for (PatentNewBo p : l) {
-				// 申请时间
-				Calendar end = Calendar.getInstance();
-				end.setTime(p.getEndDate());
-				Integer status = p.getStatus();
-				// 当前时间
-				Calendar now = Calendar.getInstance();
-				now.setTime(new Date());
-				now.set(Calendar.MILLISECOND, 0);
-				now.set(Calendar.HOUR_OF_DAY, 0);
-				now.clear(Calendar.MINUTE);
-				now.clear(Calendar.SECOND);
-				Date date=new Date();
+				Integer status=0;
 				// 计算相差日期
-				int count = (int) ((end.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
-				System.out.println(count+"==="+p.getStatus()+"========="+p.getPatentNo());
+				int count = patentNewService.countDays(p.getEndDate());
+				
 				boolean flag=false;
 				if (count > 60 && count <= 90&&p.getStatus()!=1) {
 					flag=true;
@@ -117,7 +106,6 @@ public class PatentTask {
 					status = 5;
 					s5.add(p.getId().toString());
 				}else if(count<0&&p.getSalesmanRemind()==1) {
-					System.out.println(p.getPatentNo());
 					s6.add(p.getId().toString());
 				}
 				if (flag) {
@@ -153,7 +141,7 @@ public class PatentTask {
 						continue;
 					} else {
 						PatentNewLog pl = new PatentNewLog();
-						String str = StrToString(str2,end.getTime(),status);
+						String str = StrToString(str2,p.getEndDate(),status);
 						pl.setContent(str);
 						pl.setCreateTime(new Date());
 						pl.setPid(p.getId());

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

@@ -1,5 +1,6 @@
 package com.goafanti.patent.service;
 
+import java.util.Date;
 import java.util.List;
 
 import org.springframework.web.multipart.MultipartFile;
@@ -46,5 +47,10 @@ public interface PatentNewService {
 
 	boolean checkTid(Integer tid);
 
+	int countDays(Date endDate);
+	
+	Integer getSatus(Date endDate);
+
+
 
 }

+ 103 - 9
src/main/java/com/goafanti/patent/service/impl/PatentNewServiceImpl.java

@@ -9,6 +9,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
@@ -29,8 +30,10 @@ import com.goafanti.common.dao.PatentNewMapper;
 import com.goafanti.common.dao.PatentPaymentDetailsMapper;
 import com.goafanti.common.dao.PatentYearPaymentMapper;
 import com.goafanti.common.dao.TOrderTaskMapper;
+import com.goafanti.common.enums.NoticeStatus;
 import com.goafanti.common.error.BusinessException;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.Notice;
 import com.goafanti.common.model.PatentNew;
 import com.goafanti.common.model.PatentNewLog;
 import com.goafanti.common.model.PatentPaymentDetails;
@@ -39,6 +42,7 @@ import com.goafanti.common.model.TOrderTask;
 import com.goafanti.common.utils.AsyncUtils;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.ExcelUtils;
+import com.goafanti.common.utils.SendEmailUtil;
 import com.goafanti.common.utils.excel.NewExcelUtil;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
@@ -46,6 +50,7 @@ import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.patent.bo.PatentNewBo;
 import com.goafanti.patent.enums.PatentType;
 import com.goafanti.patent.service.PatentNewService;
+
 @Service
 public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> implements PatentNewService {
 	@Autowired
@@ -214,6 +219,7 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
     			throw new BusinessException(new Error("未找到正确的参数。"));
 			}
     		List<PatentNew> list=new ArrayList<>();
+    		List<Notice> nl=new ArrayList<Notice>();
     		//循环除了第2行的所有行
     		for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
         		//获得当前行
@@ -276,34 +282,106 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 		        		throw new BusinessException(new Error("表格第"+(rowNum+1)+"行[专利编号]重复导入。"));
 		        	}
 		        }
+		        Date date=new Date();
 		        trb.setAid(TokenManager.getAdminId());
 		        trb.setInputId(trb.getAid());
-		        trb.setCreateTime(new Date());
-		        trb.setStatus(0);
+		        trb.setCreateTime(date);
 		        trb.setNewType(1);
 		        trb.setYears(getyear(trb));
+		        trb.setStatus(getSatus(trb.getEndDate()));
 		        trb.setPatentAmount(sumAmout(trb.getType(),trb.getTid(),trb.getYears()));
 		        list.add(trb);
+		        if (trb.getStatus()!=0) {
+		        	Notice n = addNotice(trb); 
+		        	n.setId(UUID.randomUUID().toString());
+		        	n.setCreateTime(date);
+		        	n.setReaded(0);// 未读
+		        	n.setNoticeType(NoticeStatus.TASK_PATENT_ERROR.getCode());
+					nl.add(n);
+				}
 		    }
     		
     		List<PatentNew> list2=new ArrayList<>();
     		for (int i = 0; i < list.size(); i++) {
-    			
     			list2.add(list.get(i));
     			if (50 == list2.size() || i == list.size() - 1) {
-    				if (list2.size() > 0) patentNewMapper.insertBatch(list2);
-    				list2.clear();
-    				try {
-    					Thread.sleep(500);
-    				} catch (InterruptedException e) {
-    					e.printStackTrace();
+    				if (list2.size() > 0) {
+    					patentNewMapper.insertBatch(list2);
     				}
+    				list2.clear();
+    				
     			}
     		}
+    		asyncUtils.addNoticeBatch(nl);
         }
         
     }
 
+	private Notice addNotice(PatentNew p) {
+		Notice n = new Notice();
+		Date date=new Date();
+		n.setId(UUID.randomUUID().toString());
+		n.setCreateTime(date);
+		n.setReaded(0);// 未读
+		n.setNoticeType(NoticeStatus.TASK_PATENT_ERROR.getCode());
+		Admin a = adminMapper.selectByPrimaryKey(p.getAid());
+		StringBuffer str2 = new StringBuffer();
+		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.setAid("1");
+			n.setContent(str2.toString());
+		} else if (!SendEmailUtil.isEmail(p.getEmail().trim())) {
+			str2.append(",管理员=").append(a.getName()).append(",邮箱不正确。");
+			n.setAid("1");
+			n.setContent(str2.toString());
+		} else {
+			PatentNewLog pl = new PatentNewLog();
+			String str = StrToString(str2,p.getEndDate(),p.getStatus());
+			pl.setContent(str);
+			pl.setCreateTime(new Date());
+			pl.setPid(p.getId());
+			patentNewLogMapper.insertSelective(pl);
+			n.setAid(p.getAid());
+			n.setNoticeType(NoticeStatus.TASK_PATENT_REMIND.getCode());
+			n.setContent(str);
+		}
+		return n;
+	}
+	
+	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;
+		if (status==1) days=90;
+		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) {
+			str.append(",续费时间还剩").append(days).append("天");
+		}
+		str.append(",截止时间[").append(DateUtils.formatDate(date, AFTConstants.YYYYMMDD)).append("]请在截止时间前通知客户!");
+		return str.toString();
+	}
+
+	public Integer getSatus(Date endDate) {
+		int count=countDays(endDate);
+		int status=0;
+		if (count > 60 && count <= 90) {
+			status=1;
+		} else if (count > 30 && count <= 60) {
+			status=2;
+		}else if (count > 15 && count <= 30) {
+			status=3;
+		}else if (count > 7 && count <= 15) {
+			status=4;
+		}else if (count>0&&count <= 7) {
+			status=5;
+		}
+		return status;
+	}
+
 	private Integer getyear(PatentNew p) {
 		Calendar c=Calendar.getInstance();
 		c.setTime(p.getApplyDate());
@@ -494,4 +572,20 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 		}
 		return false;
 	}
+
+	@Override
+	public int countDays(Date endDate) {
+		// 申请时间
+		Calendar end = Calendar.getInstance();
+		end.setTime(endDate);
+		// 当前时间
+		Calendar now = Calendar.getInstance();
+		now.setTime(new Date());
+		now.set(Calendar.MILLISECOND, 0);
+		now.set(Calendar.HOUR_OF_DAY, 0);
+		now.clear(Calendar.MINUTE);
+		now.clear(Calendar.SECOND);
+		int days=(int) ((end.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
+		return days;
+	}
 }