Pārlūkot izejas kodu

项目计算、分数段修改接口

xiatian 6 gadi atpakaļ
vecāks
revīzija
77ad556bf8

+ 49 - 0
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/provider/ReportsComputeCloudServiceProvider.java

@@ -0,0 +1,49 @@
+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.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.task.api.ReportsComputeCloudService;
+import cn.com.qmth.examcloud.task.api.request.AddReportsComputeReq;
+import cn.com.qmth.examcloud.task.api.response.AddReportsComputeResp;
+import cn.com.qmth.examcloud.task.service.ReportsComputeService;
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+@Api(tags = "报表计算任务接口")
+@RestController
+@RequestMapping("${$rmp.cloud.task}" + "reportsCompute")
+public class ReportsComputeCloudServiceProvider extends ControllerSupport
+		implements
+		ReportsComputeCloudService {
+
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -8948562824083405677L;
+	@Autowired
+	private ReportsComputeService reportsComputeService;
+
+	@ApiOperation(value = "新增报表计算任务")
+	@PostMapping("/add")
+	@Override
+	public AddReportsComputeResp addReportsCompute(AddReportsComputeReq req) {
+		Long projectId=req.getProjectId();
+		if(projectId==null) {
+			throw new StatusException("10001", "projectId不能为空");
+		}
+		Long rootOrgId=req.getRootOrgId();
+		if(rootOrgId==null) {
+			throw new StatusException("10002", "rootOrgId不能为空");
+		}
+		reportsComputeService.add(projectId, rootOrgId);
+		return new AddReportsComputeResp();
+	}
+
+
+}

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

@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Repository;
 
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
+import cn.com.qmth.examcloud.task.dao.enums.ReportsComputeStatus;
 
 @Repository
 public interface ReportsComputeRepo
@@ -30,4 +31,6 @@ public interface ReportsComputeRepo
 	@Query(value = "update EC_T_REPORTS_COMPUTE t set t.status ='NONE' where t.status ='COMPUTING' ", nativeQuery = true)
 	@Modifying
 	public int initComputingJob();
+
+	public List<ReportsComputeEntity> findByProjectIdAndRootOrgIdAndStatus(Long projectId, Long rootOrgId,ReportsComputeStatus status);
 }

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

@@ -16,4 +16,5 @@ public interface ReportsComputeService {
 	public ReportsComputeEntity findById(Long id);
 	public void initReportsCompute();
 	public void clearStopingFlag(Long id);
+	public void add(Long projectId,Long rootOrgId);
 }

+ 32 - 17
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/ReportsComputeServiceImpl.java

@@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamStudentDataCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamStudentDataBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamStudentScoreDataBean;
@@ -55,10 +56,10 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 
 	@Autowired
 	private ExamStudentDataCloudService examStudentDataCloudService;
-	
+
 	@Autowired
 	private ExamCourseDataReportCloudService examCourseDataReportCloudService;
-	
+
 	@Autowired
 	private ExamOrgReportCloudService examOrgReportBeanCloudService;
 
@@ -129,7 +130,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			updateToFail(et, "考试id为空");
 			return;
 		}
-		
+
 		List<Long> examIds = Arrays.asList(pro.getExamIds().split(",")).stream().map(str -> Long.parseLong(str))
 				.collect(Collectors.toList());
 		Map<String, Object> result = new HashMap<String, Object>();
@@ -193,32 +194,32 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		// 判断任务终止
 		checkIsStoping(et.getId());
 		// 设置中心、课程、考试code和名称
-		//TODO
-		
+		// TODO
+
 		// 判断任务终止
 		checkIsStoping(et.getId());
-		
-		//清除旧数据
-		DeleteExamOrgReportByProjectReq dreq1=new DeleteExamOrgReportByProjectReq();
+
+		// 清除旧数据
+		DeleteExamOrgReportByProjectReq dreq1 = new DeleteExamOrgReportByProjectReq();
 		dreq1.setProjectId(pro.getId());
 		dreq1.setRootOrgId(pro.getRootOrgId());
 		examOrgReportBeanCloudService.deleteExamOrgReportByProject(dreq1);
-		
-		DeleteExamCourseDataReportByProjectReq dreq2=new DeleteExamCourseDataReportByProjectReq();
+
+		DeleteExamCourseDataReportByProjectReq dreq2 = new DeleteExamCourseDataReportByProjectReq();
 		dreq2.setProjectId(pro.getId());
 		dreq2.setRootOrgId(pro.getRootOrgId());
 		examCourseDataReportCloudService.deleteExamCourseDataReportByProject(dreq2);
-		
-		//保存计算结果
-		SaveExamOrgReportListReq req1=new SaveExamOrgReportListReq();
+
+		// 保存计算结果
+		SaveExamOrgReportListReq req1 = new SaveExamOrgReportListReq();
 		req1.setBeans(new ArrayList<ExamOrgReportBean>(examOrgReport.values()));
 		examOrgReportBeanCloudService.saveExamOrgReportList(req1);
-		
+
 		// 判断任务终止
 		checkIsStoping(et.getId());
-		
-		//保存计算结果
-		SaveExamCourseDataReportListReq req2=new SaveExamCourseDataReportListReq();
+
+		// 保存计算结果
+		SaveExamCourseDataReportListReq req2 = new SaveExamCourseDataReportListReq();
 		req2.setBeans(new ArrayList<ExamCourseDataReportBean>(examCourseDataReport.values()));
 		examCourseDataReportCloudService.saveExamCourseDataReportList(req2);
 	}
@@ -553,4 +554,18 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		jobStopFlag.remove(et.getId());
 	}
 
+	@Transactional
+	@Override
+	public void add(Long projectId, Long rootOrgId) {
+		List<ReportsComputeEntity> list=reportsComputeRepo.findByProjectIdAndRootOrgIdAndStatus(projectId,rootOrgId,ReportsComputeStatus.COMPUTING);
+		if(list!=null&&list.size()>0) {
+			throw new StatusException("10001", "该项目正在计算中");
+		}
+		ReportsComputeEntity e=new ReportsComputeEntity();
+		e.setProjectId(projectId);
+		e.setRootOrgId(rootOrgId);
+		e.setStatus(ReportsComputeStatus.NONE);
+		reportsComputeRepo.save(e);
+	}
+
 }