Browse Source

新专利定时任务

anderx 4 years ago
parent
commit
9a80b730fe

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

@@ -2,6 +2,7 @@ package com.goafanti.common.dao;
 
 import com.goafanti.common.model.PatentNew;
 import com.goafanti.common.model.PatentNewLog;
+import com.goafanti.patent.bo.PatentNewBo;
 
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
@@ -44,7 +45,7 @@ public interface PatentNewMapper {
 	 */
 	int updateByPrimaryKey(PatentNew record);
 
-	List<PatentNew> AllselectStartPatentNew();
+	List<PatentNewBo> AllselectStartPatentNew();
 	
 	List<PatentNew> AllselectEndPatentNew();
 

+ 3 - 2
src/main/java/com/goafanti/common/mapper/PatentNewMapper.xml

@@ -515,8 +515,9 @@
 	
 	<select id="AllselectStartPatentNew" resultMap="BaseResultMap">
     select 
-    <include refid="Base_Column_List" />
-    from patent_new where status &lt; 8
+    a.id,a.patent_no patentNo,a.name ,a.aid ,a.email ,a.end_date endDate,a.status ,c.buyer_name userName
+    from patent_new a left join t_order_task b on a.tid =b.id left join t_order_mid c on b.order_no=c.order_no 
+    where a.status &lt; 8
     </select>
     <select id="AllselectEndPatentNew" resultMap="BaseResultMap">
     select 

+ 11 - 122
src/main/java/com/goafanti/common/task/PatentTask.java

@@ -1,6 +1,5 @@
 package com.goafanti.common.task;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -10,9 +9,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.annotation.Resource;
-import javax.mail.SendFailedException;
 
-import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -21,20 +18,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.admin.service.AdminService;
-import com.goafanti.common.bo.EmailBo;
 import com.goafanti.common.constant.AFTConstants;
-import com.goafanti.common.dao.UserMapper;
 import com.goafanti.common.enums.NoticeStatus;
-import com.goafanti.common.enums.PatentCategoryStatus;
 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.User;
 import com.goafanti.common.utils.AsyncUtils;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.SendEmailUtil;
+import com.goafanti.patent.bo.PatentNewBo;
 import com.goafanti.patent.service.PatentNewService;
 
 
@@ -49,8 +42,6 @@ public class PatentTask {
 	@Resource
 	private AdminService adminService;
 	@Autowired
-	private UserMapper	userMapper;
-	@Autowired
 	private AsyncUtils	asyncUtils;
 	
 	
@@ -79,26 +70,14 @@ public class PatentTask {
 	public void patentRemind() {
 		LoggerUtils.debug(getClass(), "====================开始检查专利提醒==================");
 		try {
-			List<PatentNew> l = patentNewService.AllselectStartPatentNew();
+			List<PatentNewBo> l = patentNewService.AllselectStartPatentNew();
 			List<Notice> nlist = new ArrayList<>();
 			List<PatentNewLog> logList = new ArrayList<>();
-			for (PatentNew p : l) {
-				//因为改成数据关联字段修改
-				String userName ="";
+			for (PatentNewBo p : l) {
 				
-				if (p.getUid()!=null) {
-					User u =userMapper.selectByPrimaryKey(p.getUid());
-					if (u!=null) {
-						userName=u.getNickname();
-					}else {
-						userName=p.getApplicant();
-					}
-				}else {
-					userName=p.getApplicant();
-				}
 				// 申请时间
-				Calendar sq = Calendar.getInstance();
-				sq.setTime(p.getApplyDate());
+				Calendar end = Calendar.getInstance();
+				end.setTime(p.getEndDate());
 				Integer status = 0;
 				// 当前时间
 				Calendar now = Calendar.getInstance();
@@ -108,17 +87,8 @@ public class PatentTask {
 				now.clear(Calendar.MINUTE);
 				now.clear(Calendar.SECOND);
 				Date date=new Date();
-				// 提醒
-				Calendar ted = Calendar.getInstance();
-				// 先获取到目前多少天数,再计算出年限
-				int d = (int) ((now.getTimeInMillis() - sq.getTimeInMillis()) / (1000 * 3600 * 24));
-				int y = d / 365;
-				if (d % 365 > 0)
-					y++;
-				ted.setTime(sq.getTime());
-				ted.add(Calendar.YEAR, y);
 				// 计算相差日期
-				int count = (int) ((ted.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
+				int count = (int) ((end.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
 				Notice n = new Notice();
 				n.setId(UUID.randomUUID().toString());
 				n.setCreateTime(date);
@@ -153,7 +123,7 @@ public class PatentTask {
 					Admin a = adminService.selectByPrimaryKey(p.getAid());
 					StringBuffer str2 = new StringBuffer();
 					str2.append("专利编号=").append(p.getPatentNo()).append("名称=").append(p.getName()).append(",email=")
-							.append(p.getEmail());
+							.append(p.getEmail().trim());
 					n.setContent(str2.toString());
 					if (a == null) {
 						str2.append(",aid=").append(p.getAid()).append(",找不到管理员。");
@@ -177,27 +147,9 @@ public class PatentTask {
 						nlist.add(n2);
 						continue;
 					} else {
-						// 计算出年费金额,然后存入数据库
-						BigDecimal money = countMoney(y, p.getType());
-						
-						EmailBo emailBo = new EmailBo("专利提醒", p.getEmail().trim(),userName, "科德集团", a.getName(),
-								p.getName(), p.getPatentNo(), money.toString(), DateFormatUtils.format(ted, "yyyy-MM-dd"),status);
-						n.setNoticeType(NoticeStatus.TASK_PATENT_REMIND.getCode());
-						String title = "专利提醒成功!";
-						p.setStatus(status);// 提醒中
-						try {
-							asyncUtils.patentSend(emailBo);
-						} catch (SendFailedException e) {
-							// 如果邮件发送失败提醒
-							n.setNoticeType(NoticeStatus.TASK_PATENT_ERROR.getCode());
-							title = "提醒失败!对方邮箱不存在或者拒收!";
-							p.setStatus(0);
-						}
-						p.setPatentAmount(money);
-						p.setYears(y);
-						patentNewService.updatePatenNew(p);
+						String title = "提醒失败!对方邮箱不存在或者拒收!";
 						PatentNewLog pl = new PatentNewLog();
-						String str = StrToString(title, p.getEmail().trim(), userName ,p.getName(),date,status);
+						String str = StrToString(title, p.getEmail().trim(), p.getUserName() ,p.getName(),date,status);
 						pl.setContent(str);
 						pl.setCreateTime(new Date());
 						pl.setPid(p.getId());
@@ -265,44 +217,7 @@ public class PatentTask {
 		return sb.toString();
 	}
 	
-	/**
-	 * 
-	 * @param 年份
-	 * @param 分类
-	 * @return 金额
-	 */
-	
-	private static BigDecimal countMoney(Integer y, Integer type) {
-		int money=0;
-		if (type==PatentCategoryStatus.INVENTION.getCode()) {
-			if (y>0&&y<4) {
-				money=900;
-			}else if (y>3&&y<7) {
-				money=1200;
-			}else if (y>6&&y<10) {
-				money=2000;
-			}else if (y>9&&y<13) {
-				money=4000;
-			}else if (y>12&&y<16) {
-				money=6000;
-			}else if (y>15&&y<21) {
-				money=8000;
-			}
-		} else {
-			if (y>0&&y<4) {
-				money=600;
-			}else if (y>3&&y<6) {
-				money=900;
-			}else if (y>5&&y<9) {
-				money=1200;
-			}else if (y>8&&y<11) {
-				money=2000;
-			}
-		}
-		
-		return new BigDecimal(money);
-	}
-	
+
 	
 	
 	
@@ -334,31 +249,5 @@ public class PatentTask {
             htmlStr = delHTMLTag(htmlStr);
             htmlStr = htmlStr.replaceAll("&nbsp;", "");
             return htmlStr;
-        }
-        
-        
-        public static void main(String[] args) {
-        	// 申请时间一月份是0。
-			Calendar sq = Calendar.getInstance();
-			sq.set(2020, 7, 29);
-			System.out.println(DateUtils.formatDate(sq.getTime(), AFTConstants.YYYYMMDD));
-			// 当前时间
-			Calendar now = Calendar.getInstance();
-			now.setTime(new Date());
-			now.set(Calendar.MILLISECOND, 0);
-			// 提醒
-			Calendar ted = Calendar.getInstance();
-			// 先获取到目前多少天数,再计算出年限
-			int d = (int) ((now.getTimeInMillis() - sq.getTimeInMillis()) / (1000 * 3600 * 24));
-			System.out.println(d);
-			int y = d / 365;
-			if (d % 365 > 0)y++;
-			System.out.println(y);
-			ted.setTime(sq.getTime());
-			ted.add(Calendar.YEAR, y);
-			System.out.println(DateUtils.formatDate(ted.getTime(), AFTConstants.YYYYMMDD));
-			// 计算相差日期
-			int count = (int) ((ted.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 3600 * 24));
-			System.out.println(count);
-		}
+        }       
 }

+ 0 - 1
src/main/java/com/goafanti/common/utils/excel/NewExcelUtil.java

@@ -52,7 +52,6 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
 import org.apache.poi.xssf.usermodel.XSSFDataValidation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
 
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;

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

@@ -17,7 +17,7 @@ public interface PatentNewService {
 
 	Pagination<PatentNewBo> selectPatentNew(PatentNewBo p,Integer pageSize, Integer pageNo);
 	
-	List<PatentNew> AllselectStartPatentNew();
+	List<PatentNewBo> AllselectStartPatentNew();
 	
 	
 	int addPatenNewLog(PatentNewLog pl);

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

@@ -118,7 +118,7 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 	}
 
 	@Override
-	public List<PatentNew> AllselectStartPatentNew() {
+	public List<PatentNewBo> AllselectStartPatentNew() {
 		return patentNewMapper.AllselectStartPatentNew();
 	}