Browse Source

Merge remote-tracking branch 'origin/master'

lideyin 5 years ago
parent
commit
e2e636b387

+ 26 - 4
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/controller/ReportsComputeController.java

@@ -1,17 +1,26 @@
 package cn.com.qmth.examcloud.task.api.controller;
 
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.task.base.bean.ReportsComputeBean;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
 import cn.com.qmth.examcloud.task.service.ReportsComputeService;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 
 @RestController
 @RequestMapping("${$rmp.ctr.task}" + "reportsCompute")
@@ -22,8 +31,8 @@ public class ReportsComputeController extends ControllerSupport {
 	ReportsComputeService reportsComputeService;
 
 	@ApiOperation(value = "终止计算任务")
-	@PostMapping("/stopJob")
-	public void stopJob(@RequestParam Long id){
+	@PostMapping("/stopJob/{id}")
+	public void stopJob(@PathVariable @ApiParam(value = "ID") Long id){
 		if (id == null) {
 			throw new StatusException("1000001", "计算任务id不能为空");
 		}
@@ -44,6 +53,19 @@ public class ReportsComputeController extends ControllerSupport {
 			throw new StatusException("1000004", "只能终止待处理和处理中的任务");
 		}
 	}
-
-
+    @GetMapping("page/{projectId}/{pageNo}/{pageSize}")
+    @ApiOperation(value = "计算任务列表分页查询")
+    public PageInfo<ReportsComputeBean> queryPage(@PathVariable @ApiParam(value = "项目ID") Long projectId,
+                                        @PathVariable @ApiParam(value = "pageNo = 1,2,3...") Integer pageNo, @PathVariable Integer pageSize) {
+    	User user=getAccessUser();
+    	return reportsComputeService.queryPage(projectId, pageNo, pageSize,user.getRootOrgId());
+    }
+    @ApiOperation(value="批量获取")
+	@GetMapping("/getList")
+	public List<ReportsComputeBean> getList(@RequestParam(required = true) String ids) {
+    	List<Long> pids = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+    	User user = getAccessUser();
+		return reportsComputeService.getList(pids, user.getRootOrgId());
+	}
 }

+ 2 - 1
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/provider/ReportsComputeCloudServiceProvider.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.task.api.provider;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -32,7 +33,7 @@ public class ReportsComputeCloudServiceProvider extends ControllerSupport
 	@ApiOperation(value = "新增报表计算任务")
 	@PostMapping("/add")
 	@Override
-	public AddReportsComputeResp addReportsCompute(AddReportsComputeReq req) {
+	public AddReportsComputeResp addReportsCompute(@RequestBody AddReportsComputeReq req) {
 		Long projectId=req.getProjectId();
 		if(projectId==null) {
 			throw new StatusException("10001", "projectId不能为空");

+ 100 - 0
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/bean/ReportsComputeBean.java

@@ -0,0 +1,100 @@
+package cn.com.qmth.examcloud.task.base.bean;
+
+import java.util.Date;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import cn.com.qmth.examcloud.task.base.enums.ReportsComputeStatus;
+
+public class ReportsComputeBean implements JsonSerializable {
+
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 4494598544057432645L;
+
+	private Long id;
+	
+	private Long projectId;
+	private Long rootOrgId;
+	private ReportsComputeStatus status;
+	private String statusName;
+	private Date startTime;
+	private Date creationTime;
+	private Date endTime;
+
+	private String errorDesc;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getProjectId() {
+		return projectId;
+	}
+
+	public void setProjectId(Long projectId) {
+		this.projectId = projectId;
+	}
+
+	public ReportsComputeStatus getStatus() {
+		return status;
+	}
+
+	public void setStatus(ReportsComputeStatus status) {
+		this.status = status;
+	}
+
+	public Date getStartTime() {
+		return startTime;
+	}
+
+	public void setStartTime(Date startTime) {
+		this.startTime = startTime;
+	}
+
+	public Date getEndTime() {
+		return endTime;
+	}
+
+	public void setEndTime(Date endTime) {
+		this.endTime = endTime;
+	}
+
+	public String getErrorDesc() {
+		return errorDesc;
+	}
+
+	public void setErrorDesc(String errorDesc) {
+		this.errorDesc = errorDesc;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getStatusName() {
+		return statusName;
+	}
+
+	public void setStatusName(String statusName) {
+		this.statusName = statusName;
+	}
+
+	public Date getCreationTime() {
+		return creationTime;
+	}
+
+	public void setCreationTime(Date creationTime) {
+		this.creationTime = creationTime;
+	}
+	
+}

+ 1 - 1
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/enums/ReportsComputeStatus.java → examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/enums/ReportsComputeStatus.java

@@ -1,4 +1,4 @@
-package cn.com.qmth.examcloud.task.dao.enums;
+package cn.com.qmth.examcloud.task.base.enums;
 public enum ReportsComputeStatus {
 
 	NONE("待处理"), COMPUTING("处理中"), SUCCESS("处理成功"), FAIL(

+ 8 - 3
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/ReportsComputeRepo.java

@@ -8,8 +8,8 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Repository;
 
+import cn.com.qmth.examcloud.task.base.enums.ReportsComputeStatus;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
-import cn.com.qmth.examcloud.task.dao.enums.ReportsComputeStatus;
 
 @Repository
 public interface ReportsComputeRepo
@@ -17,10 +17,10 @@ public interface ReportsComputeRepo
 			JpaRepository<ReportsComputeEntity, Long>,
 			JpaSpecificationExecutor<ReportsComputeEntity> {
 	@Query(value = "SELECT count(1) FROM EC_T_REPORTS_COMPUTE t "+
-			"WHERE t.status ='NONE'", nativeQuery = true)
+			"WHERE t.status ='NONE' or t.status ='STOPING' ", nativeQuery = true)
 	public int getTodoDataCount();
 	@Query(value = "SELECT t.* FROM EC_T_REPORTS_COMPUTE t "+
-			"WHERE t.id>?1 and t.status ='NONE' ORDER BY t.id limit ?2", nativeQuery = true)
+			"WHERE t.id>?1 and (t.status ='NONE' or t.status ='STOPING') ORDER BY t.id limit ?2", nativeQuery = true)
 	public List<ReportsComputeEntity> findTodoData(Long startId,Integer limit);
 	
 	@Query(value = "update EC_T_REPORTS_COMPUTE t set t.status ='STOPING' where t.id=?1 and (t.status ='COMPUTING' or t.status ='NONE') ", nativeQuery = true)
@@ -36,4 +36,9 @@ public interface ReportsComputeRepo
 	public int initComputingJob();
 
 	public List<ReportsComputeEntity> findByProjectIdAndRootOrgIdAndStatus(Long projectId, Long rootOrgId,ReportsComputeStatus status);
+
+	public List<ReportsComputeEntity> findByStatus(ReportsComputeStatus status);
+	
+	@Query(value = "select * from EC_T_REPORTS_COMPUTE where id in(?1) and root_org_id=?2 ", nativeQuery = true)
+	public List<ReportsComputeEntity> getByIds(List<Long> ids, Long rootOrgId);
 }

+ 1 - 1
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/entity/ReportsComputeEntity.java

@@ -14,7 +14,7 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.validation.constraints.NotNull;
 
-import cn.com.qmth.examcloud.task.dao.enums.ReportsComputeStatus;
+import cn.com.qmth.examcloud.task.base.enums.ReportsComputeStatus;
 import cn.com.qmth.examcloud.web.jpa.JpaEntity;
 
 @Entity

+ 4 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/ReportsComputeService.java

@@ -2,6 +2,8 @@ package cn.com.qmth.examcloud.task.service;
 
 import java.util.List;
 
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
+import cn.com.qmth.examcloud.task.base.bean.ReportsComputeBean;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
 
 public interface ReportsComputeService {
@@ -17,4 +19,6 @@ public interface ReportsComputeService {
 	public void initReportsCompute();
 	public void clearStopingFlag(Long id);
 	public void add(Long projectId,Long rootOrgId);
+	public PageInfo<ReportsComputeBean> queryPage(Long projectId,Integer pageNo,Integer pageSize,Long rootOrgId);
+	public List<ReportsComputeBean> getList(List<Long> pids, Long rootOrgId);
 }

+ 95 - 25
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/ReportsComputeServiceImpl.java

@@ -11,12 +11,22 @@ import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import javax.persistence.criteria.Predicate;
 import javax.transaction.Transactional;
 
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
+import com.google.common.collect.Lists;
+
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
 import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
@@ -43,16 +53,18 @@ import cn.com.qmth.examcloud.core.reports.api.request.GetProjectInfoBeanReq;
 import cn.com.qmth.examcloud.core.reports.api.request.SaveExamCourseDataReportListReq;
 import cn.com.qmth.examcloud.core.reports.api.request.SaveExamOrgReportListReq;
 import cn.com.qmth.examcloud.core.reports.api.request.UpdateProjectCourseOrgCountReq;
+import cn.com.qmth.examcloud.core.reports.api.request.UpdateProjectStatusByIdsReq;
 import cn.com.qmth.examcloud.core.reports.api.request.UpdateProjectStatusReq;
 import cn.com.qmth.examcloud.core.reports.api.response.GetProjectInfoBeanResp;
 import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamsByIdListReq;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamsByIdListResp;
+import cn.com.qmth.examcloud.task.base.bean.ReportsComputeBean;
+import cn.com.qmth.examcloud.task.base.enums.ReportsComputeStatus;
 import cn.com.qmth.examcloud.task.base.util.BatchGetDataUtil;
 import cn.com.qmth.examcloud.task.dao.ReportsComputeRepo;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
-import cn.com.qmth.examcloud.task.dao.enums.ReportsComputeStatus;
 import cn.com.qmth.examcloud.task.service.ReportsComputeService;
 import cn.com.qmth.examcloud.task.service.dto.TopicScoreDto;
 import cn.com.qmth.examcloud.task.service.exception.ReportsComputeStopException;
@@ -92,8 +104,22 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 	@Transactional
 	@Override
 	public void initReportsCompute() {
-		reportsComputeRepo.initComputingJob();
-		reportsComputeRepo.initStopingJob();
+		List<ReportsComputeEntity> cs = reportsComputeRepo.findByStatus(ReportsComputeStatus.COMPUTING);
+		UpdateProjectStatusByIdsReq req = new UpdateProjectStatusByIdsReq();
+		if (cs != null && cs.size() > 0) {
+			reportsComputeRepo.initComputingJob();
+			List<Long> cids = cs.stream().map(c -> c.getProjectId()).collect(Collectors.toList());
+			req.setComputingProjectIds(cids);
+		}
+		List<ReportsComputeEntity> ss = reportsComputeRepo.findByStatus(ReportsComputeStatus.STOPING);
+		if (ss != null && ss.size() > 0) {
+			reportsComputeRepo.initStopingJob();
+			List<Long> sids = ss.stream().map(c -> c.getProjectId()).collect(Collectors.toList());
+			req.setStopingProjectIds(sids);
+		}
+		if(req.getComputingProjectIds()!=null||req.getStopingProjectIds()!=null) {
+			projectCloudService.updateProjectStatusByIds(req);
+		}
 	}
 
 	@Override
@@ -203,7 +229,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			bean.setCdi(getPercentage(bean.getStd(), bean.getAvgScore()));
 			bean.setAvgScore(getTwoDecimal(bean.getAvgScore()));
 		}
-		
+
 		// 判断任务终止
 		checkIsStoping(et.getId());
 		// 计算basePaperId对应的难度系数
@@ -252,9 +278,9 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		SaveExamCourseDataReportListReq req2 = new SaveExamCourseDataReportListReq();
 		req2.setBeans(new ArrayList<ExamCourseDataReportBean>(examCourseDataReport.values()));
 		examCourseDataReportCloudService.saveExamCourseDataReportList(req2);
-		
-		//保存项目课程数量、中心数量
-		UpdateProjectCourseOrgCountReq req=new UpdateProjectCourseOrgCountReq();
+
+		// 保存项目课程数量、中心数量
+		UpdateProjectCourseOrgCountReq req = new UpdateProjectCourseOrgCountReq();
 		req.setProjectId(pro.getId());
 		req.setOrgCount(ordIds.size());
 		req.setCourseCount(courseIds.size());
@@ -341,39 +367,40 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 
 	private Double avgDifficultyDegree(String dataKey, Map<String, Set<String>> basePapers,
 			Map<String, Double> basePapersDegree) {
-		//考试课程对应的basePapers
+		// 考试课程对应的basePapers
 		Set<String> set = basePapers.get(dataKey);
-		if (set == null||set.size()==0) {
+		if (set == null || set.size() == 0) {
 			return null;
 		}
 		double total = 0.0;
-		//算平均难度时剔除没有难度系数的试卷
-		int nullCount=0;
+		// 算平均难度时剔除没有难度系数的试卷
+		int nullCount = 0;
 		for (String s : set) {
-			Double td=basePapersDegree.get(s);
-			if(td==null) {
+			Double td = basePapersDegree.get(s);
+			if (td == null) {
 				nullCount++;
-			}else {
+			} else {
 				total = total + basePapersDegree.get(s);
 			}
 		}
-		if(nullCount==set.size()) {
+		if (nullCount == set.size()) {
 			return null;
 		}
-		return getTwoDecimal(total / (set.size()-nullCount));
+		return getTwoDecimal(total / (set.size() - nullCount));
 	}
 
 	private Double difficultyDegree(Map<String, TopicScoreDto> map) {
-		//剔除整张卷子没有小题答题的
-		if(map==null||map.size()==0) {
+		// 剔除整张卷子没有小题答题的
+		if (map == null || map.size() == 0) {
 			return null;
 		}
 		double totalAvg = 0.0;
 		double totalFull = 0.0;
 		for (String k : map.keySet()) {
 			TopicScoreDto dto = map.get(k);
-			if(dto.getTotal()==0) {
-				throw new StatusException("100001", "小题满分不能为0 QuestionId:"+dto.getQuestionId()+" QuestionOrder:"+dto.getQuestionOrder());
+			if (dto.getTotal() == 0) {
+				throw new StatusException("100001",
+						"小题满分不能为0 QuestionId:" + dto.getQuestionId() + " QuestionOrder:" + dto.getQuestionOrder());
 			}
 			totalAvg = totalAvg + dto.getAvg();
 			totalFull = totalFull + dto.getTotal();
@@ -457,8 +484,8 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			bean.setParticipantCount(bean.getParticipantCount() + 1);
 		}
 		// 及格人数
-		if (!st.getAbsent() && st.getScore()==null) {
-			throw new StatusException("10030","未缺考的考生分数不能为空 ExamStudentId:"+st.getExamStudentId());
+		if (!st.getAbsent() && st.getScore() == null) {
+			throw new StatusException("10030", "未缺考的考生分数不能为空 ExamStudentId:" + st.getExamStudentId());
 		}
 		if (!st.getAbsent() && st.getScore() >= pro.getPassScore()) {
 			bean.setPassCount(bean.getPassCount() + 1);
@@ -593,10 +620,10 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			}
 			// 考生小题得分详情
 			List<ExamStudentScoreDataBean> scoreDetails = st.getScoreDetails();
-			if(scoreDetails==null||scoreDetails.size()==0) {
-				throw new StatusException("10040","考生小题得分详情不能为空 ExamStudentId:"+st.getExamStudentId());
+			if (scoreDetails == null || scoreDetails.size() == 0) {
+				throw new StatusException("10040", "考生小题得分详情不能为空 ExamStudentId:" + st.getExamStudentId());
 			}
-			
+
 			// 计算每个小题的平均分
 			for (ExamStudentScoreDataBean b : scoreDetails) {
 				if (b.getScore() != null) {
@@ -714,6 +741,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 	public int getTodoDataCount() {
 		return reportsComputeRepo.getTodoDataCount();
 	}
+
 	private Double getPercentage(Double a, Double b) {
 		if (b == 0) {
 			return null;
@@ -722,6 +750,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		Double tem = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 		return tem;
 	}
+
 	private Double getTwoDecimal(Double b) {
 		if (b == null) {
 			return b;
@@ -730,4 +759,45 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		Double tem = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 		return tem;
 	}
+
+	@Override
+	public PageInfo<ReportsComputeBean> queryPage(Long projectId, Integer pageNo, Integer pageSize, Long rootOrgId) {
+		Specification<ReportsComputeEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
+
+			predicates.add(cb.equal(root.get("projectId"), projectId));
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		PageRequest pageRequest = PageRequest.of(pageNo - 1, pageSize, new Sort(Direction.DESC, "id"));
+
+		Page<ReportsComputeEntity> projects = reportsComputeRepo.findAll(specification, pageRequest);
+
+		List<ReportsComputeBean> ret = Lists.newArrayList();
+
+		for (ReportsComputeEntity cur : projects) {
+			ReportsComputeBean bean = new ReportsComputeBean();
+			BeanUtils.copyProperties(cur, bean);
+			bean.setStatusName(bean.getStatus().getDesc());
+			ret.add(bean);
+		}
+		return new PageInfo<ReportsComputeBean>(projects, ret);
+	}
+
+	@Override
+	public List<ReportsComputeBean> getList(List<Long> pids, Long rootOrgId) {
+		List<ReportsComputeBean> ret=new ArrayList<ReportsComputeBean>();
+		List<ReportsComputeEntity> list=reportsComputeRepo.getByIds(pids, rootOrgId);
+		if(list!=null) {
+			for(ReportsComputeEntity pe:list) {
+				ReportsComputeBean bean = new ReportsComputeBean();
+				BeanUtils.copyProperties(pe, bean);
+				bean.setStatusName(bean.getStatus().getDesc());
+				ret.add(bean);
+			}
+		}
+		return ret;
+	}
 }

+ 4 - 0
examcloud-task-starter/src/main/java/cn/com/qmth/examcloud/task/starter/config/ExamCloudWebMvcConfigurer.java

@@ -6,7 +6,9 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
+import cn.com.qmth.examcloud.web.interceptor.ApiStatisticInterceptor;
 import cn.com.qmth.examcloud.web.interceptor.FirstInterceptor;
+import cn.com.qmth.examcloud.web.interceptor.SeqlockInterceptor;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.security.RequestPermissionInterceptor;
 import cn.com.qmth.examcloud.web.security.ResourceManager;
@@ -35,6 +37,8 @@ public class ExamCloudWebMvcConfigurer implements WebMvcConfigurer {
 		RequestPermissionInterceptor permissionInterceptor = new RequestPermissionInterceptor(
 				resourceManager, redisClient);
 		registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");
+		registry.addInterceptor(new SeqlockInterceptor(redisClient)).addPathPatterns("/**");
+		registry.addInterceptor(new ApiStatisticInterceptor()).addPathPatterns("/**");
 	}
 
 	@Override