Browse Source

推送考试方法

wangliang 3 years ago
parent
commit
d2a83b1508

+ 4 - 10
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/params/BasicSemesterParams.java

@@ -10,7 +10,7 @@ import org.hibernate.validator.constraints.Range;
 
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
-import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @Description: 基础学期参数
@@ -63,15 +63,9 @@ public class BasicSemesterParams implements Serializable {
      * 参数校验
      */
     public void validParams() {
-        if (Objects.isNull(this.getSemesterName())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("学期名称为空");
-        }
-        if (Objects.isNull(this.getStartTime())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("学期开始时间为空");
-        }
-        if (Objects.isNull(this.getEndTime())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("学期结束时间为空");
-        }
+        Optional.ofNullable(this.getSemesterName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期名称为空"));
+        Optional.ofNullable(this.getStartTime()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期开始时间为空"));
+        Optional.ofNullable(this.getEndTime()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期结束时间为空"));
     }
 
     public Long getId() {

+ 8 - 14
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/AuthThirdUtil.java

@@ -11,7 +11,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @Description: 第三方鉴权util
@@ -34,19 +34,15 @@ public class AuthThirdUtil {
         String url = request.getServletPath();
         //验证authorization
         String authorization = ServletUtil.getRequestAuthorization();
-        if (Objects.isNull(authorization)) {
-            throw ExceptionResultEnum.AUTHORIZATION_INVALID.exception();
-        }
+        Optional.ofNullable(authorization).orElseThrow(() -> ExceptionResultEnum.AUTHORIZATION_INVALID.exception());
+
         Long expireTime = ServletUtil.getRequestTime();
-        if (Objects.isNull(expireTime)) {
-            throw ExceptionResultEnum.TIME_INVALID.exception();
-        }
+        Optional.ofNullable(expireTime).orElseThrow(() -> ExceptionResultEnum.TIME_INVALID.exception());
+
         String method = request.getMethod();
         final SignatureEntity info = SignatureEntity.parse(authorization, method, url, expireTime);
-        if (Objects.isNull(info)) {
-            log.warn("Authorization faile: signature decode error");
-            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
-        }
+        Optional.ofNullable(info).orElseThrow(() -> ExceptionResultEnum.AUTHORIZATION_ERROR.exception());
+
         if (!url.equalsIgnoreCase(info.getUri())) {
             log.warn("url faile: url error");
             throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
@@ -66,9 +62,7 @@ public class AuthThirdUtil {
         QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
         basicSchoolQueryWrapper.lambda().eq(BasicSchool::getAccessKey, info.getInvoker());
         BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
-        if (Objects.isNull(basicSchool)) {
-            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception("没有学校信息");
-        }
+        Optional.ofNullable(basicSchool).orElseThrow(() -> ExceptionResultEnum.AUTHORIZATION_ERROR.exception("没有学校信息"));
         if (!info.validate(basicSchool.getAccessSecret())) {
             log.warn("Authorization faile: secret invalid, secret is " + basicSchool.getAccessSecret());
             throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();

+ 4 - 10
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/params/TBExamParam.java

@@ -8,7 +8,7 @@ import org.hibernate.validator.constraints.Length;
 import org.hibernate.validator.constraints.Range;
 
 import javax.validation.constraints.NotNull;
-import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @Description: 考试参数
@@ -44,15 +44,9 @@ public class TBExamParam {
      * 参数校验
      */
     public void validParams() {
-        if (Objects.isNull(this.getExamName())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("考试名称为空");
-        }
-        if (Objects.isNull(this.getExamTime())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("考试时间为空");
-        }
-        if (Objects.isNull(this.getSemesterId())) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("学期id为空");
-        }
+        Optional.ofNullable(this.getExamName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试名称为空"));
+        Optional.ofNullable(this.getExamTime()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试时间为空"));
+        Optional.ofNullable(this.getSemesterId()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学期id为空"));
     }
 
     public Long getId() {

+ 19 - 14
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/OpenApiController.java

@@ -7,12 +7,14 @@ import com.qmth.teachcloud.common.bean.params.BasicSemesterParams;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.service.BasicCourseService;
 import com.qmth.teachcloud.common.service.BasicSemesterService;
 import com.qmth.teachcloud.common.util.AuthThirdUtil;
 import com.qmth.teachcloud.common.util.JacksonUtil;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.report.business.bean.params.TBExamParam;
+import com.qmth.teachcloud.report.business.service.TBExamCourseService;
 import com.qmth.teachcloud.report.business.service.TBExamService;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
@@ -26,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.net.URLDecoder;
-import java.util.Objects;
+import java.util.Optional;
 
 /**
  * <p>
@@ -49,20 +51,22 @@ public class OpenApiController {
     @Resource
     TBExamService tbExamService;
 
+    @Resource
+    BasicCourseService basicCourseService;
+
+    @Resource
+    TBExamCourseService tbExamCourseService;
+
     @ApiOperation(value = "学期创建/更新接口")
     @ApiResponses({@ApiResponse(code = 200, message = "学期创建/更新接口", response = Object.class)})
     @RequestMapping(value = "/semester_edit", method = RequestMethod.POST)
     @Aac(auth = BOOL.FALSE)
     public Result semesterEdit(@ApiParam(value = "接收学期数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException, IllegalAccessException {
-        if (Objects.isNull(result)) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("数据为空");
-        }
+        Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
         String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
         log.info("semesterEdit进来了,result:{}", decodeJson);
         BasicSemesterParams basicSemesterParams = JacksonUtil.readJson(decodeJson, BasicSemesterParams.class);
-        if (Objects.isNull(basicSemesterParams)) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("转换后的数据为空");
-        }
+        Optional.ofNullable(basicSemesterParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
         basicSemesterParams.validParams();
         BasicSchool basicSchool = AuthThirdUtil.hasPermission();
         return ResultUtil.ok(basicSemesterService.saveBasicSemesterCommon(basicSemesterParams, basicSchool.getId(), null));
@@ -73,15 +77,11 @@ public class OpenApiController {
     @RequestMapping(value = "/exam_edit", method = RequestMethod.POST)
     @Aac(auth = BOOL.FALSE)
     public Result examEdit(@ApiParam(value = "接收考试数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
-        if (Objects.isNull(result)) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("数据为空");
-        }
+        Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
         String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
         log.info("examEdit进来了,result:{}", decodeJson);
         TBExamParam tbExamParam = JacksonUtil.readJson(decodeJson, TBExamParam.class);
-        if (Objects.isNull(tbExamParam)) {
-            throw ExceptionResultEnum.PARAMS_ERROR.exception("转换后的数据为空");
-        }
+        Optional.ofNullable(tbExamParam).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
         tbExamParam.validParams();
         BasicSchool basicSchool = AuthThirdUtil.hasPermission();
         tbExamParam.setSchoolId(basicSchool.getId());
@@ -92,7 +92,12 @@ public class OpenApiController {
     @ApiResponses({@ApiResponse(code = 200, message = "分析课程(试卷)创建/更新接口", response = Object.class)})
     @RequestMapping(value = "/course_edit", method = RequestMethod.POST)
     public Result courseEdit(@ApiParam(value = "接收分析课程(试卷)数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
-        log.info("courseEdit进来了,result:{}", result);
+        Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
+        String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
+        log.info("courseEdit进来了进来了,result:{}", decodeJson);
+        BasicSchool basicSchool = AuthThirdUtil.hasPermission();
+//        basicCourseService.createCourse(basicSchool.getId());
+
         return ResultUtil.ok(true);
     }
 

+ 1 - 1
teachcloud-report/src/main/resources/application-dev.properties

@@ -101,7 +101,7 @@ prefix.url.open=report/open
 
 #\u65E5\u5FD7\u914D\u7F6E
 com.qmth.logging.root-level=info
-com.qmth.logging.file-path=/ONLINE_EXAM/teachcloud-report/tomcat/logs/teachcloud-report.log
+com.qmth.logging.file-path=/Users/king/Downloads/teachcloud-report.log
 
 #\u5F15\u5165task\u914D\u7F6E\u6587\u4EF6
 spring.profiles.include=task