Sfoglia il codice sorgente

定时任务开发

anderx 1 anno fa
parent
commit
4a3739714d

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

@@ -3,10 +3,10 @@ package com.goafanti.common.dao;
 import com.goafanti.common.model.UserTransferLog;
 import com.goafanti.customer.bo.transferListBo;
 import com.goafanti.user.bo.InputUserChannel;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.Date;
 import java.util.List;
-import org.apache.ibatis.annotations.Param;
 
 public interface UserTransferLogMapper {
     /**
@@ -54,4 +54,5 @@ public interface UserTransferLogMapper {
 	void insertUserLog(@Param("aid")String aid, @Param("transferId")String transferId, @Param("date")Date date);
 
 	void insertUserLockLog(@Param("aid")String aid, @Param("transferId")String transferId, @Param("date")Date date);
+
 }

+ 5 - 2
src/main/java/com/goafanti/common/enums/NoticeStatus.java

@@ -82,8 +82,11 @@ public enum NoticeStatus {
 	COMPLETES_PROJECT(73,"项目完成通知"),
 	EXPENSE_NOTICE(74,"报销审核通知"),
 	EXPENSE_COMPLETE(75,"报销审核完成"),
-	RESTRICT_PROJECT_LOSE30(76,"限时项目释放(30天)"),
-	RESTRICT_PROJECT_LOSE270(77,"限时项目释放(270天)"),
+	RESTRICT_PROJECT_LOSE30(76,"限时私有项目释放(30天)"),
+	RESTRICT_PROJECT_LOSE270(77,"限时签单项目释放(270天)"),
+
+	RESTRICT_PROJECT_LOSE30_REMIND(78,"限时私有项目释放提醒"),
+	RESTRICT_PROJECT_LOSE270_REMIND(79,"限时签单项目释放提醒"),
 	OTHER(0, "其他");
 
 	private NoticeStatus(Integer code, String desc) {

+ 4 - 1
src/main/java/com/goafanti/common/mapper/UserTransferLogMapper.xml

@@ -208,5 +208,8 @@ select id,aid, #{transferId},13,#{date} from user where share_type =0 and aid =
 	left join user_lock_release b on a.id=b.uid
 	where a.share_type =2 and a.aid= #{aid} and b.`type` =1
   </insert>
-  
+  <insert id="insertRestrictBatch">
+
+  </insert>
+
 </mapper>

+ 12 - 0
src/main/java/com/goafanti/common/model/UserTransferLog.java

@@ -216,4 +216,16 @@ public class UserTransferLog implements Serializable {
 		sb.append("]");
 		return sb.toString();
 	}
+
+	public UserTransferLog() {
+	}
+
+	public UserTransferLog( String uid, String aid, String pid,  Integer type,  String remarks, Date createTime) {
+		this.uid = uid;
+		this.aid = aid;
+		this.pid = pid;
+		this.type = type;
+		this.remarks = remarks;
+		this.createTime = createTime;
+	}
 }

+ 69 - 16
src/main/java/com/goafanti/common/task/ReleaseUserTask.java

@@ -7,11 +7,13 @@ import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.AdminUserCountMapper;
 import com.goafanti.common.dao.NoticeMapper;
 import com.goafanti.common.dao.RestrictProjectMapper;
+import com.goafanti.common.dao.UserTransferLogMapper;
 import com.goafanti.common.enums.NoticeStatus;
 import com.goafanti.common.enums.NoticeTypes;
 import com.goafanti.common.model.AdminUserCount;
 import com.goafanti.common.model.Notice;
 import com.goafanti.common.model.User;
+import com.goafanti.common.model.UserTransferLog;
 import com.goafanti.common.utils.AsyncUtils;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.StringUtils;
@@ -25,6 +27,7 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 
@@ -52,13 +55,16 @@ public class ReleaseUserTask {
 	@Autowired
 	private RestrictProjectMapper restProjectMapper;
 
+	@Autowired
+	private UserTransferLogMapper userTransferLogMapper;
+
 	/**
 	 * 每天凌晨一点
 	 *
 	 */
-//	@Scheduled(cron = "0 52 10  * * ?")
+	@Scheduled(cron = "0 31 14  * * ?")
 //	@RequestMapping("/open/test")
-	@Scheduled(cron = "0 0 1  * * ?")
+//	@Scheduled(cron = "0 0 1  * * ?")
 	public void startTask() {
 		try {
 			List<User> userList = userService.selectUserByRoleName("营销员", "营销经理");
@@ -76,7 +82,9 @@ public class ReleaseUserTask {
 	private void pushRestrictProject(List<User> userList) {
 		LoggerUtils.debug(getClass(), "==============限时项目丢失开始============");
 		List<Notice> ln = new ArrayList<>();
+		List<UserTransferLog> lu=new ArrayList<>();
 		LocalDateTime now = LocalDateTime.now();
+		Date date = new Date();
 		List<Integer> list = new ArrayList<>();
 		for (User u : userList) {
 			if (StringUtils.isNotBlank(u.getId())) {
@@ -84,25 +92,47 @@ public class ReleaseUserTask {
 				for (OutRestrictProject rp : rpList) {
 						LocalDateTime lockTime = rp.getLockTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime();
 					if (rp.getType()==1){
-						LocalDateTime endTime = lockTime.plusDays(30);
-						long between = ChronoUnit.DAYS.between(now, endTime);
-						if (between==0){
-							ln.add(new Notice(UUID.randomUUID().toString(),new Date(), 0, rp.getAid(),
-									NoticeStatus.RESTRICT_PROJECT_LOSE30.getCode(),
-									String.format("您的客户[%s]限时私有项目[%s]丢失!",rp.getUserName(), rp.getProjectName())
+						LocalDateTime endTime2 = lockTime.plusDays(15);
+						long between2 = ChronoUnit.DAYS.between(now, endTime2);
+						if (between2==0){
+							ln.add(new Notice(UUID.randomUUID().toString(),date, 0, rp.getAid(),
+									NoticeStatus.RESTRICT_PROJECT_LOSE30_REMIND.getCode(),
+									String.format("您的客户[%s]限时私有项目[%s]还有15天即将丢失!",rp.getUserName(), rp.getProjectName())
 									,rp.getUid()));
-							list.add(rp.getId());
+						}else {
+							LocalDateTime endTime = lockTime.plusDays(30);
+							long between = ChronoUnit.DAYS.between(now, endTime);
+							if (between==0){
+								ln.add(new Notice(UUID.randomUUID().toString(),date, 0, rp.getAid(),
+										NoticeStatus.RESTRICT_PROJECT_LOSE30.getCode(),
+										String.format("您的客户[%s]限时私有项目[%s]已丢失!",rp.getUserName(), rp.getProjectName())
+										,rp.getUid()));
+								list.add(rp.getId());
+								lu.add(new UserTransferLog(rp.getUid(), rp.getAid(), rp.getPid(), 18, "限时项目释放(30天)",date));
+							}
 						}
+
 					}else if (rp.getType()==2){
-						LocalDateTime endTime = lockTime.plusDays(270);
-						long between = ChronoUnit.DAYS.between(now, endTime);
-						if (between==0){
-							ln.add(new Notice(UUID.randomUUID().toString(),new Date(), 0, rp.getAid(),
-									NoticeStatus.RESTRICT_PROJECT_LOSE270.getCode(),
-									String.format("您的客户[%s]限时签单项目[%s]已丢失!",rp.getUserName(), rp.getProjectName())
+						LocalDateTime endTime2 = lockTime.plusDays(255);
+						long between2 = ChronoUnit.DAYS.between(now, endTime2);
+						if (between2==0){
+							ln.add(new Notice(UUID.randomUUID().toString(),date, 0, rp.getAid(),
+									NoticeStatus.RESTRICT_PROJECT_LOSE270_REMIND.getCode(),
+									String.format("您的客户[%s]限时签单项目[%s]还有15天即将丢失!",rp.getUserName(), rp.getProjectName())
 									,rp.getUid()));
-							list.add(rp.getId());
+						}else{
+							LocalDateTime endTime = lockTime.plusDays(270);
+							long between = ChronoUnit.DAYS.between(now, endTime);
+							if (between==0){
+								ln.add(new Notice(UUID.randomUUID().toString(),date, 0, rp.getAid(),
+										NoticeStatus.RESTRICT_PROJECT_LOSE270.getCode(),
+										String.format("您的客户[%s]限时签单项目[%s]已丢失!",rp.getUserName(), rp.getProjectName())
+										,rp.getUid()));
+								list.add(rp.getId());
+								lu.add(new UserTransferLog(rp.getUid(), rp.getAid(), rp.getPid(), 19, "限时项目释放(270天)",date));
+							}
 						}
+
 					}
 				}
 			}
@@ -110,9 +140,32 @@ public class ReleaseUserTask {
 		}
 		addNoticeBatch(ln);
 		pushReleaseRestrictProject(list);
+		addUserTransferLogBatch(lu);
 		LoggerUtils.debug(getClass(), "==============限时项目结束============");
 	}
 
+	private void addUserTransferLogBatch(List<UserTransferLog> list) {
+		List<UserTransferLog> list2 = new ArrayList<>();
+		int i=0;
+		for (UserTransferLog e : list) {
+			i++;
+			list2.add(e);
+			if(list2.size()==pointsDataLimit||i==list.size()){
+				userTransferLogMapper.insertList(list2);
+				list2.clear();
+			}
+		}
+	}
+
+	public static void main(String[] args) {
+		LocalDateTime now = LocalDateTime.now();
+		LocalDateTime endTime = LocalDateTime.of(2024,5,14,0,0);
+		endTime= endTime.minusDays(270);
+		long between = ChronoUnit.DAYS.between(now, endTime);
+		System.out.println(between);
+		System.out.println(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+	}
+
 	private void pushReleaseRestrictProject(List<Integer> list) {
 		List<Integer> list2 = new ArrayList<>();
 		int i=0;