xiatian 5 年 前
コミット
6389b8d146

+ 0 - 125
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/online/ActiveDataUtil.java

@@ -1,125 +0,0 @@
-package cn.com.qmth.examcloud.task.base.online;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class ActiveDataUtil {
-	private final static String spe="_";
-	private final static Long defTimeOut=5*60*1000L;
-	private final static Map<String, Map<Long, Long>> userActiveData = new ConcurrentHashMap<String, Map<Long, Long>>();
-	private final static Map<String, Map<Long, Long>> studentActiveData = new ConcurrentHashMap<String, Map<Long, Long>>();
-	private final static Map<String, Map<Long, Long>> examStudentActiveData = new ConcurrentHashMap<String, Map<Long, Long>>();
-
-	public static void updateUserActive(UserActive ac) {
-		String key = ac.getKey(spe);
-		Map<Long, Long> map = userActiveData.get(key);
-		if (map == null) {
-			map = new ConcurrentHashMap<Long, Long>();
-			userActiveData.put(key, map);
-		}
-		map.put(ac.getUserId(), ac.getActiveTime());
-	}
-	public static void updateStudentActive(StudentActive ac) {
-		String key = ac.getKey(spe);
-		Map<Long, Long> map = studentActiveData.get(key);
-		if (map == null) {
-			map = new ConcurrentHashMap<Long, Long>();
-			studentActiveData.put(key, map);
-		}
-		map.put(ac.getStudentId(), ac.getActiveTime());
-	}
-	public static void updateExamStudentActive(ExamStudentActive ac) {
-		String key = ac.getKey(spe);
-		Map<Long, Long> map = examStudentActiveData.get(key);
-		if (map == null) {
-			map = new ConcurrentHashMap<Long, Long>();
-			examStudentActiveData.put(key, map);
-		}
-		map.put(ac.getExamStudentId(), ac.getActiveTime());
-	}
-	private static void clearTimeOutUserActive(Long timeOut) {
-		if(timeOut==null) {
-			timeOut=defTimeOut;
-		}
-		Date d=new Date();
-		Long now=d.getTime();
-		for(Map<Long, Long> map:userActiveData.values()) {
-			for(Long k:map.keySet()) {
-				if(now-map.get(k)>timeOut) {
-					map.remove(k);
-				}
-			}
-		}
-	}
-	private static void clearTimeOutStudentActive(Long timeOut) {
-		if(timeOut==null) {
-			timeOut=defTimeOut;
-		}
-		Date d=new Date();
-		Long now=d.getTime();
-		for(Map<Long, Long> map:studentActiveData.values()) {
-			for(Long k:map.keySet()) {
-				if(now-map.get(k)>timeOut) {
-					map.remove(k);
-				}
-			}
-		}
-	}
-	private static void clearTimeOutExamStudentActive(Long timeOut) {
-		if(timeOut==null) {
-			timeOut=defTimeOut;
-		}
-		Date d=new Date();
-		Long now=d.getTime();
-		for(Map<Long, Long> map:examStudentActiveData.values()) {
-			for(Long k:map.keySet()) {
-				if(now-map.get(k)>timeOut) {
-					map.remove(k);
-				}
-			}
-		}
-	}
-	public static List<OnlineCount> getUserCount(Long timeOut){
-		clearTimeOutUserActive(timeOut);
-		List<OnlineCount> ret=new ArrayList<OnlineCount>();
-		for(String key:userActiveData.keySet()) {
-			OnlineCount oc=new OnlineCount();
-			String[] ks=key.split(spe);
-			oc.setRootOrgId(Long.valueOf(ks[0]));
-			oc.setOrgId(Long.valueOf(ks[1]));
-			oc.setOnlineCount(userActiveData.get(key).size());
-			ret.add(oc);
-		}
-		return ret;
-	}
-	public static List<OnlineCount> getStudentCount(Long timeOut){
-		clearTimeOutStudentActive(timeOut);
-		List<OnlineCount> ret=new ArrayList<OnlineCount>();
-		for(String key:studentActiveData.keySet()) {
-			OnlineCount oc=new OnlineCount();
-			String[] ks=key.split(spe);
-			oc.setRootOrgId(Long.valueOf(ks[0]));
-			oc.setOrgId(Long.valueOf(ks[1]));
-			oc.setOnlineCount(studentActiveData.get(key).size());
-			ret.add(oc);
-		}
-		return ret;
-	}
-	public static List<OnlineCount> getExamStudentCount(Long timeOut){
-		clearTimeOutExamStudentActive(timeOut);
-		List<OnlineCount> ret=new ArrayList<OnlineCount>();
-		for(String key:examStudentActiveData.keySet()) {
-			OnlineCount oc=new OnlineCount();
-			String[] ks=key.split(spe);
-			oc.setRootOrgId(Long.valueOf(ks[0]));
-			oc.setOrgId(Long.valueOf(ks[1]));
-			oc.setExamId(Long.valueOf(ks[2]));
-			oc.setOnlineCount(examStudentActiveData.get(key).size());
-			ret.add(oc);
-		}
-		return ret;
-	}
-}

+ 0 - 42
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/online/ExamStudentActive.java

@@ -1,42 +0,0 @@
-package cn.com.qmth.examcloud.task.base.online;
-
-public class ExamStudentActive {
-	private Long rootOrgId;
-	private Long orgId;
-	private Long examId;
-	private Long examStudentId;
-	private Long activeTime;
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-	public Long getOrgId() {
-		return orgId;
-	}
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-	public Long getExamId() {
-		return examId;
-	}
-	public void setExamId(Long examId) {
-		this.examId = examId;
-	}
-	public Long getExamStudentId() {
-		return examStudentId;
-	}
-	public void setExamStudentId(Long examStudentId) {
-		this.examStudentId = examStudentId;
-	}
-	public Long getActiveTime() {
-		return activeTime;
-	}
-	public void setActiveTime(Long activeTime) {
-		this.activeTime = activeTime;
-	}
-	public String getKey(String spe) {
-		return rootOrgId+spe+orgId+spe+examId;
-	}
-}

+ 0 - 33
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/online/OnlineCount.java

@@ -1,33 +0,0 @@
-package cn.com.qmth.examcloud.task.base.online;
-
-public class OnlineCount {
-	private Long examId;
-	private Long rootOrgId;
-	private Long orgId;
-	private Integer onlineCount;
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-	public Long getOrgId() {
-		return orgId;
-	}
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-	public Integer getOnlineCount() {
-		return onlineCount;
-	}
-	public void setOnlineCount(Integer onlineCount) {
-		this.onlineCount = onlineCount;
-	}
-	public Long getExamId() {
-		return examId;
-	}
-	public void setExamId(Long examId) {
-		this.examId = examId;
-	}
-	
-}

+ 0 - 35
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/online/StudentActive.java

@@ -1,35 +0,0 @@
-package cn.com.qmth.examcloud.task.base.online;
-
-public class StudentActive {
-	private Long rootOrgId;
-	private Long orgId;
-	private Long studentId;
-	private Long activeTime;
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-	public Long getOrgId() {
-		return orgId;
-	}
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-	public Long getStudentId() {
-		return studentId;
-	}
-	public void setStudentId(Long studentId) {
-		this.studentId = studentId;
-	}
-	public Long getActiveTime() {
-		return activeTime;
-	}
-	public void setActiveTime(Long activeTime) {
-		this.activeTime = activeTime;
-	}
-	public String getKey(String spe) {
-		return rootOrgId+spe+orgId;
-	}
-}

+ 0 - 35
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/online/UserActive.java

@@ -1,35 +0,0 @@
-package cn.com.qmth.examcloud.task.base.online;
-
-public class UserActive {
-	private Long rootOrgId;
-	private Long orgId;
-	private Long userId;
-	private Long activeTime;
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-	public Long getOrgId() {
-		return orgId;
-	}
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-	public Long getUserId() {
-		return userId;
-	}
-	public void setUserId(Long userId) {
-		this.userId = userId;
-	}
-	public Long getActiveTime() {
-		return activeTime;
-	}
-	public void setActiveTime(Long activeTime) {
-		this.activeTime = activeTime;
-	}
-	public String getKey(String spe) {
-		return rootOrgId+spe+orgId;
-	}
-}

+ 1 - 19
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/ExamStudentCountServiceImpl.java

@@ -1,15 +1,9 @@
 package cn.com.qmth.examcloud.task.service.impl;
 
-import java.util.Date;
-import java.util.List;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.core.reports.api.ExamStudentCountCloudService;
-import cn.com.qmth.examcloud.core.reports.api.request.AddOrUpdateExamStudentCountReq;
-import cn.com.qmth.examcloud.task.base.online.ActiveDataUtil;
-import cn.com.qmth.examcloud.task.base.online.OnlineCount;
 import cn.com.qmth.examcloud.task.service.ExamStudentCountService;
 
 @Service
@@ -19,19 +13,7 @@ public class ExamStudentCountServiceImpl implements ExamStudentCountService {
 
 	@Override
 	public void saveOnlieCount() {
-		List<OnlineCount> ret=ActiveDataUtil.getUserCount(null);
-		if(ret!=null) {
-			AddOrUpdateExamStudentCountReq req=new AddOrUpdateExamStudentCountReq();
-			Date now=new Date();
-			req.setBatchTime(now.getTime());
-			for(OnlineCount oc:ret) {
-				req.setRootOrgId(oc.getRootOrgId());
-				req.setOrgId(oc.getOrgId());
-				req.setExamId(oc.getExamId());
-				req.setOnlineCount(oc.getOnlineCount());
-				examStudentCountCloudService.addOrUpdateCount(req);
-			}
-		}
+		examStudentCountCloudService.saveCount();
 	}
 
 }

+ 1 - 18
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/StudentCountServiceImpl.java

@@ -1,15 +1,9 @@
 package cn.com.qmth.examcloud.task.service.impl;
 
-import java.util.Date;
-import java.util.List;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.core.reports.api.StudentCountCloudService;
-import cn.com.qmth.examcloud.core.reports.api.request.AddOrUpdateStudentCountReq;
-import cn.com.qmth.examcloud.task.base.online.ActiveDataUtil;
-import cn.com.qmth.examcloud.task.base.online.OnlineCount;
 import cn.com.qmth.examcloud.task.service.StudentCountService;
 
 @Service
@@ -19,18 +13,7 @@ public class StudentCountServiceImpl implements StudentCountService {
 
 	@Override
 	public void saveOnlieCount() {
-		List<OnlineCount> ret=ActiveDataUtil.getUserCount(null);
-		if(ret!=null) {
-			AddOrUpdateStudentCountReq req=new AddOrUpdateStudentCountReq();
-			Date now=new Date();
-			req.setBatchTime(now.getTime());
-			for(OnlineCount oc:ret) {
-				req.setRootOrgId(oc.getRootOrgId());
-				req.setOrgId(oc.getOrgId());
-				req.setOnlineCount(oc.getOnlineCount());
-				studentCountCloudService.addOrUpdateCount(req);
-			}
-		}
+		studentCountCloudService.saveCount();
 	}
 
 }

+ 1 - 18
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/UserCountServiceImpl.java

@@ -1,15 +1,9 @@
 package cn.com.qmth.examcloud.task.service.impl;
 
-import java.util.Date;
-import java.util.List;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.core.reports.api.UserCountCloudService;
-import cn.com.qmth.examcloud.core.reports.api.request.AddOrUpdateUserCountReq;
-import cn.com.qmth.examcloud.task.base.online.ActiveDataUtil;
-import cn.com.qmth.examcloud.task.base.online.OnlineCount;
 import cn.com.qmth.examcloud.task.service.UserCountService;
 
 @Service
@@ -19,18 +13,7 @@ public class UserCountServiceImpl implements UserCountService {
 
 	@Override
 	public void saveOnlieCount() {
-		List<OnlineCount> ret=ActiveDataUtil.getUserCount(null);
-		if(ret!=null) {
-			AddOrUpdateUserCountReq req=new AddOrUpdateUserCountReq();
-			Date now=new Date();
-			req.setBatchTime(now.getTime());
-			for(OnlineCount oc:ret) {
-				req.setRootOrgId(oc.getRootOrgId());
-				req.setOrgId(oc.getOrgId());
-				req.setOnlineCount(oc.getOnlineCount());
-				userCountCloudService.addOrUpdateCount(req);
-			}
-		}
+		userCountCloudService.saveCount();
 	}
 
 }

+ 29 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/job/StudentCumulativeCountTask.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.task.service.job;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import cn.com.qmth.examcloud.core.reports.api.StudentCumulativeCountCloudService;
+import cn.com.qmth.examcloud.web.task.AbstractTask;
+import cn.com.qmth.examcloud.web.task.ScheduleJob;
+import cn.com.qmth.examcloud.web.task.TaskTracker;
+
+@Component("studentCumulativeCountTask")
+public class StudentCumulativeCountTask extends AbstractTask {
+
+	@Autowired
+	StudentCumulativeCountCloudService studentCumulativeCountCloudService;
+
+	@Autowired
+	TaskTracker TaskTracker;
+	
+	@Override
+	public void run(ScheduleJob scheduleJob) throws Exception {
+		studentCumulativeCountCloudService.saveCount();
+	}
+
+	@Override
+	public TaskTracker getTaskTracker() {
+		return TaskTracker;
+	}
+}

+ 29 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/job/StudentTotalCountTask.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.task.service.job;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import cn.com.qmth.examcloud.core.reports.api.StudentTotalCountCloudService;
+import cn.com.qmth.examcloud.web.task.AbstractTask;
+import cn.com.qmth.examcloud.web.task.ScheduleJob;
+import cn.com.qmth.examcloud.web.task.TaskTracker;
+
+@Component("studentTotalCountTask")
+public class StudentTotalCountTask extends AbstractTask {
+
+	@Autowired
+	StudentTotalCountCloudService studentTotalCountCloudService;
+
+	@Autowired
+	TaskTracker TaskTracker;
+	
+	@Override
+	public void run(ScheduleJob scheduleJob) throws Exception {
+		studentTotalCountCloudService.compute();
+	}
+
+	@Override
+	public TaskTracker getTaskTracker() {
+		return TaskTracker;
+	}
+}