anderx 1 год назад
Родитель
Сommit
f20f0131a2

+ 4 - 0
src/main/java/com/goafanti/common/dao/RestrictProjectMapper.java

@@ -29,4 +29,8 @@ public interface RestrictProjectMapper {
     RestrictProject selectByPid(InputRestrictProject in);
 
     List<OutRestrictProject> selectByUidAndAid(InputRestrictProject in);
+
+    List<OutRestrictProject> selectByUid(String id);
+
+    void updateRelease(List<Integer> list2);
 }

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

@@ -1,10 +1,10 @@
 package com.goafanti.common.enums;
 
+import org.apache.commons.lang3.StringUtils;
+
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.lang3.StringUtils;
-
 
 public enum NoticeStatus {
 	PATENTINFO(1, "专利申请管理"),
@@ -82,6 +82,8 @@ public enum NoticeStatus {
 	COMPLETES_PROJECT(73,"项目完成通知"),
 	EXPENSE_NOTICE(74,"报销审核通知"),
 	EXPENSE_COMPLETE(75,"报销审核完成"),
+	RESTRICT_PROJECT_LOSE30(76,"限时项目释放(30天)"),
+	RESTRICT_PROJECT_LOSE270(77,"限时项目释放(270天)"),
 	OTHER(0, "其他");
 
 	private NoticeStatus(Integer code, String desc) {

+ 16 - 0
src/main/java/com/goafanti/common/mapper/RestrictProjectMapper.xml

@@ -113,6 +113,7 @@
         where   id = #{id,jdbcType=INTEGER} 
     </update>
 
+
     <select id="selectByPid" resultMap="BaseResultMap">
         select
         <include refid="Base_Column_List" />
@@ -161,4 +162,19 @@
         where a.`type` >0
         <include refid="RestrictProjectSql"/>
     </select>
+    <select id="selectByUid" resultType="com.goafanti.business.bo.OutRestrictProject">
+        select b.id,b.type,b.lock_time lockTime,b.release_time releaseTime ,b.pid,a.bname projectName,
+               c.nickname userName ,d.name adminName,b.create_time createTime,b.uid,b.aid
+        from  restrict_project b left join business_project a on b.pid =a.id
+                 left join user c on b.uid=c.id left join admin d on b.aid=d.id
+        where  b.aid= #{aid,jdbcType=VARCHAR}
+    </select>
+
+    <update id="updateRelease">
+        update restrict_project set release_time = now(),type=0
+        where id  in
+        <foreach collection="list" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+    </update>
 </mapper>

+ 63 - 2
src/main/java/com/goafanti/common/task/ReleaseUserTask.java

@@ -1,10 +1,12 @@
 package com.goafanti.common.task;
 
+import com.goafanti.business.bo.OutRestrictProject;
 import com.goafanti.common.bo.EmailBo;
 import com.goafanti.common.bo.userDaysBo;
 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.enums.NoticeStatus;
 import com.goafanti.common.enums.NoticeTypes;
 import com.goafanti.common.model.AdminUserCount;
@@ -22,6 +24,8 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 
 
@@ -45,6 +49,9 @@ public class ReleaseUserTask {
 	@Autowired
 	private AdminUserCountMapper adminUserCountMapper;
 
+	@Autowired
+	private RestrictProjectMapper restProjectMapper;
+
 	/**
 	 * 每天凌晨一点
 	 *
@@ -55,16 +62,70 @@ public class ReleaseUserTask {
 	public void startTask() {
 		try {
 			List<User> userList = userService.selectUserByRoleName("营销员", "营销经理");
-			pushUserDays(userList);
+//			pushUserDays(userList);
 			Thread.sleep(2000);
-			updateUser(userList);
+//			updateUser(userList);
 			Thread.sleep(2000);
+			pushRestrictProject(userList);
 		} catch (InterruptedException e) {
 			e.printStackTrace();
 		}
 
 	}
 
+	private void pushRestrictProject(List<User> userList) {
+		LoggerUtils.debug(getClass(), "==============限时项目丢失开始============");
+		List<Notice> ln = new ArrayList<>();
+		LocalDateTime now = LocalDateTime.now();
+		List<Integer> list = new ArrayList<>();
+		for (User u : userList) {
+			if (StringUtils.isNotBlank(u.getId())) {
+				List<OutRestrictProject> rpList = restProjectMapper.selectByUid(u.getId());
+				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())
+									,rp.getUid()));
+							list.add(rp.getId());
+						}
+					}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())
+									,rp.getUid()));
+							list.add(rp.getId());
+						}
+					}
+				}
+			}
+
+		}
+		addNoticeBatch(ln);
+		pushReleaseRestrictProject(list);
+		LoggerUtils.debug(getClass(), "==============限时项目结束============");
+	}
+
+	private void pushReleaseRestrictProject(List<Integer> list) {
+		List<Integer> list2 = new ArrayList<>();
+		int i=0;
+		for (Integer e : list) {
+			i++;
+			list2.add(e);
+			if(list2.size()==pointsDataLimit||i==list.size()){
+				restProjectMapper.updateRelease(list2);
+				list2.clear();
+			}
+		}
+	}
+
 	private void pushUserDays(List<User> userList ) throws InterruptedException {
 		LoggerUtils.debug(getClass(), "==============客户提醒开始============");
 		List<Notice> ln = new ArrayList<>();