Browse Source

Merge branch 'dev_v3.1.0' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev_v3.1.0

xiaof 3 years ago
parent
commit
e704763bd5
18 changed files with 498 additions and 81 deletions
  1. 2 2
      distributed-print/src/main/java/com/qmth/distributed/print/api/OpenApiController.java
  2. 58 13
      distributed-print/src/main/java/com/qmth/distributed/print/api/TSAuthController.java
  3. 7 7
      distributed-print/src/main/resources/application-dev.properties
  4. 30 4
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/params/BasicSemesterParams.java
  5. 34 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java
  6. 30 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/ReportOpenDomain.java
  7. 1 1
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/BasicSchool.java
  8. 2 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/ExceptionResultEnum.java
  9. 11 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicSemesterService.java
  10. 22 3
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicSemesterServiceImpl.java
  11. 72 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/AuthThirdUtil.java
  12. 2 2
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/HttpUtil.java
  13. 15 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ServletUtil.java
  14. 85 0
      teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/params/CourseParam.java
  15. 12 1
      teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/params/TBExamParam.java
  16. 3 3
      teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/service/impl/TBExamServiceImpl.java
  17. 107 40
      teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/OpenApiController.java
  18. 5 5
      teachcloud-report/src/main/resources/application-dev.properties

+ 2 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/OpenApiController.java

@@ -18,13 +18,13 @@ import javax.annotation.Resource;
 
 /**
  * <p>
- * 开放接口前端控制器
+ * 知学知考开放接口前端控制器
  * </p>
  *
  * @author wangliang
  * @since 2022-04-26
  */
-@Api(tags = "开放接口Controller")
+@Api(tags = "知学知考开放接口Controller")
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.open}")
 @Validated

+ 58 - 13
distributed-print/src/main/java/com/qmth/distributed/print/api/TSAuthController.java

@@ -1,6 +1,5 @@
 package com.qmth.distributed.print.api;
 
-import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
@@ -8,9 +7,9 @@ import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
 import com.qmth.boot.tools.signature.SignatureEntity;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.distributed.print.business.service.AuthInfoService;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
-import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.util.*;
 import io.swagger.annotations.*;
@@ -26,6 +25,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Objects;
 
 /**
@@ -49,6 +50,9 @@ public class TSAuthController {
     @Resource
     CommonCacheService commonCacheService;
 
+    @Resource
+    DictionaryConfig dictionaryConfig;
+
     @ApiOperation(value = "导出硬件信息")
     @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = Object.class)})
     @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)
@@ -85,23 +89,64 @@ public class TSAuthController {
     @ApiResponses({@ApiResponse(code = 200, message = "测试推送信息给教研分析", response = Objects.class)})
     @RequestMapping(value = "/test/push", method = RequestMethod.POST)
     public void testPush() throws IOException {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         Long schoolId = SystemConstant.getHeadOrUserSchoolId();
         BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("orgId", basicSchool.getId());
-        jsonObject.put("orgCode", basicSchool.getCode());
-        jsonObject.put("accessKey", basicSchool.getAccessKey());
-        jsonObject.put("accessSecret", basicSchool.getAccessSecret());
-        jsonObject.put("createId", sysUser.getId());
-        jsonObject.put("createUserName", sysUser.getRealName());
-        jsonObject.put("callbackUrl", "/api/admin/auth/test/callback");
         Long timestamp = System.currentTimeMillis();
-        String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, "/api/report/open/basic/examination/data", timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
-        String result = HttpUtil.postJson("http://127.0.0.1:7004/api/report/open/basic/examination/data", jsonObject.toJSONString(), accessToken, timestamp);
+//        /**
+//         * 测试推送学期
+//         */
+//        BasicSemesterParams basicSemesterParams = new BasicSemesterParams("测试学期1", System.currentTimeMillis(), System.currentTimeMillis() + 1L);
+//        String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, dictionaryConfig.reportOpenDomain().getSemesterApi(), timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+//        String result = HttpUtil.postJson(dictionaryConfig.reportOpenDomain().getHostUrl() + dictionaryConfig.reportOpenDomain().getSemesterApi(), JacksonUtil.parseJson(basicSemesterParams), accessToken, timestamp);
+//        if (Objects.nonNull(result)) {
+//            log.info("result:{}", JacksonUtil.parseJson(result));
+//        }
+
+//        /**
+//         * 测试推送考试
+//         */
+//        Map<String, Object> map = new HashMap<>();
+//        map.computeIfAbsent("examName", v -> "测试考试1");
+//        map.computeIfAbsent("examTime", v -> timestamp);
+//        map.computeIfAbsent("semesterId", v -> 262908000564412416L);
+//        String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, dictionaryConfig.reportOpenDomain().getExamApi(), timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+//        String result = HttpUtil.postJson(dictionaryConfig.reportOpenDomain().getHostUrl() + dictionaryConfig.reportOpenDomain().getExamApi(), JacksonUtil.parseJson(map), accessToken, timestamp);
+//        if (Objects.nonNull(result)) {
+//            log.info("result:{}", JacksonUtil.parseJson(result));
+//        }
+
+        /**
+         * 测试推送分析课程(试卷)
+         */
+        Map<String, Object> map = new HashMap<>();
+        map.computeIfAbsent("examId", v -> 262946761763454976L);
+        map.computeIfAbsent("courseCode", v -> 2022052700001L + "A");//试卷编号+卷型
+        map.computeIfAbsent("courseName", v -> "测试课程1");
+        map.computeIfAbsent("paperType", v -> "A");
+        map.computeIfAbsent("teachCollegeName", v -> "测试机构1");//机构名称
+        String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, dictionaryConfig.reportOpenDomain().getCourseApi(), timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+        String result = HttpUtil.postJson(dictionaryConfig.reportOpenDomain().getHostUrl() + dictionaryConfig.reportOpenDomain().getCourseApi(), JacksonUtil.parseJson(map), accessToken, timestamp);
         if (Objects.nonNull(result)) {
             log.info("result:{}", JacksonUtil.parseJson(result));
         }
+
+//        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+//        Long schoolId = SystemConstant.getHeadOrUserSchoolId();
+//        BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
+//        JSONObject jsonObject = new JSONObject();
+//        jsonObject.put("orgId", basicSchool.getId());
+//        jsonObject.put("orgCode", basicSchool.getCode());
+//        jsonObject.put("accessKey", basicSchool.getAccessKey());
+//        jsonObject.put("accessSecret", basicSchool.getAccessSecret());
+//        jsonObject.put("createId", sysUser.getId());
+//        jsonObject.put("createUserName", sysUser.getRealName());
+//        jsonObject.put("callbackUrl", "/api/admin/auth/test/callback");
+//        Long timestamp = System.currentTimeMillis();
+//        String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, "/api/report/open/basic/examination/data", timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+//        String result = HttpUtil.post("http://127.0.0.1:7004/api/report/open/basic/examination/data", jsonObject.toJSONString(), accessToken, timestamp);
+//        if (Objects.nonNull(result)) {
+//            log.info("result:{}", JacksonUtil.parseJson(result));
+//    }
     }
 
     @ApiOperation(value = "测试教研分析回调接口")

+ 7 - 7
distributed-print/src/main/resources/application-dev.properties

@@ -12,9 +12,9 @@ spring.application.name=distributed-print
 #\u6570\u636E\u6E90\u914D\u7F6E
 db.host=localhost
 db.port=3306
-db.name=distributed-clear-v3.0.2
+db.name=distributed-v3.0.1-test
 db.username=root
-db.password=88888888
+db.password=123456789
 
 #redis\u6570\u636E\u6E90\u914D\u7F6E
 com.qmth.redis.host=${db.host}
@@ -159,10 +159,7 @@ sync.config.markerSaveUrl=/api/exam/marker/save
 
 #com.qmth.solar.access-key=274f823e5f59410f8b3bb6edcd8e2b6e
 #com.qmth.solar.access-secret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
-com.qmth.solar.license=/Volumes/extend/\u542F\u660E/\u5206\u5E03\u5F0F\u5370\u5237/\u5206\u5E03\u5F0F\u5370\u5237&\u6559\u7814\u5206\u6790v3.0.2/tc-dev-wl.lic
-com.qmth.solar.access-key=274f823e5f59410f8b3bb6edcd8e2b6e
-com.qmth.solar.access-secret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
-#com.qmth.solar.license=/Volumes/extend/\u542F\u660E/\u5206\u5E03\u5F0F\u5370\u5237/\u5206\u5E03\u5F0F\u5370\u5237v3.0.2/tc-dev-wl.lic
+com.qmth.solar.license=/Volumes/extend/\u542F\u660E/\u5206\u5E03\u5F0F\u5370\u5237/\u5206\u5E03\u5F0F\u5370\u5237&\u6559\u7814\u5206\u6790v3.1.0/tc-dev-wl.lic
 
 sms.config.smsNormalCode=qmth
 sms.config.codeExpiredTime=2
@@ -199,4 +196,7 @@ sms.config.aliyunSMSAuditRejectCode=SMS_237206063
 sms.config.aliyunSMSUploadStructureCode=SMS_237201068
 sms.config.aliyunSMSAuditCopyUserCode=SMS_237206065
 
-report.open.semesterApi=/api/report/open/semester_edit
+report.open.hostUrl=http://127.0.0.1:7004
+report.open.semesterApi=/api/report/open/semester_edit
+report.open.examApi=/api/report/open/exam_edit
+report.open.courseApi=/api/report/open/course_edit

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

@@ -3,12 +3,14 @@ package com.qmth.teachcloud.common.bean.params;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.teachcloud.common.annotation.DBVerify;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import io.swagger.annotations.ApiModelProperty;
 import org.hibernate.validator.constraints.Length;
 import org.hibernate.validator.constraints.Range;
 
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
+import java.util.Optional;
 
 /**
  * @Description: 基础学期参数
@@ -16,6 +18,7 @@ import java.io.Serializable;
  * @Date: 2021-11-01
  */
 public class BasicSemesterParams implements Serializable {
+
     @JsonSerialize(using = ToStringSerializer.class)
     @ApiModelProperty(value = "学期id(编辑时必填)")
     @DBVerify(value = "学期id(编辑时必填)")
@@ -23,23 +26,46 @@ public class BasicSemesterParams implements Serializable {
 
     @ApiModelProperty(value = "学期名称")
     @NotNull(message = "请输入学期名称")
-    @Length(min = 1,message = "请输入学期名称")
-    @DBVerify(value = "学期名称",required = true,min = 1,max = 50)
+    @Length(min = 1, message = "请输入学期名称")
+    @DBVerify(value = "学期名称", required = true, min = 1, max = 50)
     private String semesterName;
 
     @ApiModelProperty(value = "学期开始时间")
     @NotNull(message = "请选择学期开始时间")
     @Range(min = 1L, message = "请选择学期开始时间")
-    @DBVerify(value = "学期开始时间",required = true,min = 1)
+    @DBVerify(value = "学期开始时间", required = true, min = 1)
     private Long startTime;
 
     @ApiModelProperty(value = "学期结束时间")
     @NotNull(message = "请选择学期结束时间")
     @Range(min = 1L, message = "请选择学期结束时间")
-    @DBVerify(value = "学期结束时间",required = true,min = 1)
+    @DBVerify(value = "学期结束时间", required = true, min = 1)
     private Long endTime;
 
     public BasicSemesterParams() {
+
+    }
+
+    public BasicSemesterParams(String semesterName, Long startTime, Long endTime) {
+        this.semesterName = semesterName;
+        this.startTime = startTime;
+        this.endTime = endTime;
+    }
+
+    public BasicSemesterParams(Long id, String semesterName, Long startTime, Long endTime) {
+        this.id = id;
+        this.semesterName = semesterName;
+        this.startTime = startTime;
+        this.endTime = endTime;
+    }
+
+    /**
+     * 参数校验
+     */
+    public void validParams() {
+        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() {

+ 34 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -2,6 +2,7 @@ package com.qmth.teachcloud.common.contant;
 
 import com.qmth.boot.core.uid.service.UidService;
 import com.qmth.teachcloud.common.annotation.DBVerify;
+import com.qmth.teachcloud.common.bean.params.BasicSemesterParams;
 import com.qmth.teachcloud.common.bean.result.DBVerifyResult;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.entity.SysUser;
@@ -9,6 +10,8 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.TFCustomTypeEnum;
 import com.qmth.teachcloud.common.util.Base64Util;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.cglib.beans.BeanMap;
 
 import java.io.*;
 import java.lang.reflect.Field;
@@ -146,6 +149,7 @@ public class SystemConstant {
     public static final String HEADER_PLATFORM = "platform";
     public static final String HEADER_DEVICE_ID = "deviceId";
     public static final String TOKEN = "token";
+    public static final String SIGN = "sign";
 
     /**
      * redis
@@ -562,4 +566,34 @@ public class SystemConstant {
             }
         }
     }
+
+    /**
+     * 将对象装换为map
+     *
+     * @param bean
+     * @return
+     */
+    public static Map<String, Object> beanToMap(Object bean) {
+        Map map = new HashMap<>();
+        if (bean != null) {
+            BeanMap beanMap = BeanMap.create(bean);
+            for (Object key : beanMap.keySet()) {
+                map.put(String.valueOf(key), beanMap.get(key));
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 将map装换为javabean对象
+     *
+     * @param map
+     * @param bean
+     * @return
+     */
+    public static Object mapToBean(Map<String, Object> map, Object bean) {
+        BeanMap beanMap = BeanMap.create(bean);
+        beanMap.putAll(map);
+        return bean;
+    }
 }

+ 30 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/ReportOpenDomain.java

@@ -11,8 +11,38 @@ import java.io.Serializable;
  */
 public class ReportOpenDomain implements Serializable {
 
+    String hostUrl;
+
     String semesterApi;
 
+    String examApi;
+
+    String courseApi;
+
+    public String getHostUrl() {
+        return hostUrl;
+    }
+
+    public void setHostUrl(String hostUrl) {
+        this.hostUrl = hostUrl;
+    }
+
+    public String getExamApi() {
+        return examApi;
+    }
+
+    public void setExamApi(String examApi) {
+        this.examApi = examApi;
+    }
+
+    public String getCourseApi() {
+        return courseApi;
+    }
+
+    public void setCourseApi(String courseApi) {
+        this.courseApi = courseApi;
+    }
+
     public String getSemesterApi() {
         return semesterApi;
     }

+ 1 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/BasicSchool.java

@@ -26,7 +26,7 @@ public class BasicSchool extends BaseEntity implements Serializable {
     private String name;
 
     @ApiModelProperty(value = "是否启用,0:停用,1:启用")
-    private Boolean enable;
+    private Boolean enable = true;
 
     @TableField("access_key")
     private String accessKey;

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/ExceptionResultEnum.java

@@ -106,6 +106,8 @@ public enum ExceptionResultEnum {
 
     AUTH_INFO_ERROR(HttpStatus.UNAUTHORIZED, 4010009, "系统授权信息已过期,请联系系统管理员激活!"),
 
+    SIGN_INVALID(HttpStatus.UNAUTHORIZED, 4010010, "签名无效"),
+
     /**
      * 404
      */

+ 11 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicSemesterService.java

@@ -36,6 +36,17 @@ public interface BasicSemesterService extends IService<BasicSemester> {
      */
     Long saveBasicSemester(BasicSemesterParams basicSemesterParams) throws IllegalAccessException;
 
+    /**
+     * 基础学期编辑
+     *
+     * @param basicSemesterParams
+     * @param schoolId
+     * @param orgId
+     * @return
+     * @throws IllegalAccessException
+     */
+    Long saveBasicSemesterCommon(BasicSemesterParams basicSemesterParams, Long schoolId, Long orgId) throws IllegalAccessException;
+
     /**
      * 学期删除
      *

+ 22 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicSemesterServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -32,6 +33,10 @@ import java.util.stream.Collectors;
  */
 @Service
 public class BasicSemesterServiceImpl extends ServiceImpl<BasicSemesterMapper, BasicSemester> implements BasicSemesterService {
+
+    @Resource
+    BasicSemesterService basicSemesterService;
+
     @Override
     public IPage<BasicSemesterResult> basicSemesterPage(Long schoolId, int pageNumber, int pageSize) {
         return this.baseMapper.findBasicSemesterPage(new Page<>(pageNumber, pageSize), schoolId, null);
@@ -40,10 +45,24 @@ public class BasicSemesterServiceImpl extends ServiceImpl<BasicSemesterMapper, B
     @Transactional
     @Override
     public Long saveBasicSemester(BasicSemesterParams basicSemesterParams) throws IllegalAccessException {
-        SystemConstant.verifyDBFields(basicSemesterParams, basicSemesterParams.getClass());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        return basicSemesterService.saveBasicSemesterCommon(basicSemesterParams, sysUser.getSchoolId(), sysUser.getOrgId());
+    }
+
+    /**
+     * 保存公用
+     *
+     * @param basicSemesterParams
+     * @param schoolId
+     * @param orgId
+     * @return
+     * @throws IllegalAccessException
+     */
+    @Override
+    @Transactional
+    public Long saveBasicSemesterCommon(BasicSemesterParams basicSemesterParams, Long schoolId, Long orgId) throws IllegalAccessException {
+        SystemConstant.verifyDBFields(basicSemesterParams, basicSemesterParams.getClass());
         Long id = basicSemesterParams.getId();
-        Long schoolId = sysUser.getSchoolId();
         String semesterName = basicSemesterParams.getSemesterName();
         Long startTime = basicSemesterParams.getStartTime();
         Long endTime = basicSemesterParams.getEndTime();
@@ -78,7 +97,7 @@ public class BasicSemesterServiceImpl extends ServiceImpl<BasicSemesterMapper, B
             basicSemester.setCode(null);
             basicSemester.setStartTime(startTime);
             basicSemester.setEndTime(endTime);
-            basicSemester.setOrgId(sysUser.getOrgId());
+            basicSemester.setOrgId(orgId);
 
             QueryWrapper<BasicSemester> queryWrapper = new QueryWrapper<>();
             queryWrapper.lambda().eq(BasicSemester::getSchoolId, schoolId);

+ 72 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/AuthThirdUtil.java

@@ -0,0 +1,72 @@
+package com.qmth.teachcloud.common.util;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.boot.tools.signature.SignatureEntity;
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.entity.BasicSchool;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.service.BasicSchoolService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Optional;
+
+/**
+ * @Description: 第三方鉴权util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/5/27
+ */
+public class AuthThirdUtil {
+    private final static Logger log = LoggerFactory.getLogger(AuthThirdUtil.class);
+
+    /**
+     * 鉴权
+     *
+     * @return
+     */
+    public static BasicSchool hasPermission() {
+        BasicSchoolService basicSchoolService = SpringContextHolder.getBean(BasicSchoolService.class);
+        HttpServletRequest request = ServletUtil.getRequest();
+        String url = request.getServletPath();
+        //验证authorization
+        String authorization = ServletUtil.getRequestAuthorization();
+        Optional.ofNullable(authorization).orElseThrow(() -> ExceptionResultEnum.AUTHORIZATION_INVALID.exception());
+
+        Long expireTime = ServletUtil.getRequestTime();
+        Optional.ofNullable(expireTime).orElseThrow(() -> ExceptionResultEnum.TIME_INVALID.exception());
+
+        String method = request.getMethod();
+        final SignatureEntity info = SignatureEntity.parse(authorization, method, url, expireTime);
+        Optional.ofNullable(info).orElseThrow(() -> ExceptionResultEnum.AUTHORIZATION_ERROR.exception());
+
+        if (!url.equalsIgnoreCase(info.getUri())) {
+            log.warn("url faile: url error");
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        if (!method.equalsIgnoreCase(info.getMethod())) {
+            log.warn("method faile: method error");
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        if (info.getTimestamp() > expireTime) {
+            log.warn("Authorization faile: session has expired, expire time=" + expireTime);
+            throw ExceptionResultEnum.TIME_INVALID.exception();
+        }
+        if (SignatureType.SECRET != info.getType()) {
+            log.warn("Authorization faile: signature type is not Secret");
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
+        basicSchoolQueryWrapper.lambda().eq(BasicSchool::getAccessKey, info.getInvoker());
+        BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
+        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();
+        }
+        return basicSchool;
+    }
+}

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/HttpUtil.java

@@ -49,7 +49,7 @@ public class HttpUtil {
     public static String postJson(String url, String json, String secret, Long timestamp) throws IOException {
         // 构建post请求
         HttpPost post = new HttpPost(url);
-        post.setHeader("authorization-token", secret);
+        post.setHeader(SystemConstant.HEADER_AUTHORIZATION, secret);
         post.setHeader(SystemConstant.HEADER_TIME, String.valueOf(timestamp));
         post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8");
         post.setHeader("Accept", "application/json");
@@ -77,7 +77,7 @@ public class HttpUtil {
         HttpPost post = new HttpPost(url);
         post.setHeader(SystemConstant.HEADER_AUTHORIZATION, secret);
         post.setHeader(SystemConstant.HEADER_TIME, String.valueOf(timestamp));
-        post.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+        post.setHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=utf-8");
         // 构建请求参数
         List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
         if (params != null) {

+ 15 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ServletUtil.java

@@ -41,6 +41,21 @@ public class ServletUtil {
         httpResponse.getWriter().print(json);
     }
 
+    /**
+     * 获取请求的sign
+     *
+     * @return
+     */
+    public static String getRequestSign() {
+        try {
+            HttpServletRequest request = getRequest();
+            return Objects.isNull(request.getHeader(SystemConstant.SIGN)) ? request.getParameter(SystemConstant.SIGN) : request.getHeader(SystemConstant.SIGN);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            throw ExceptionResultEnum.SIGN_INVALID.exception();
+        }
+    }
+
     /**
      * 获取请求的token
      *

+ 85 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/params/CourseParam.java

@@ -0,0 +1,85 @@
+package com.qmth.teachcloud.report.business.bean.params;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.Optional;
+
+/**
+ * @Description: 课程参数
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/5/27
+ */
+public class CourseParam implements Serializable {
+
+    @ApiModelProperty(value = "考试id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long examId;
+
+    @ApiModelProperty(value = "课程编码,一个分析试卷的唯一标识")
+    private String courseCode;
+
+    @ApiModelProperty(value = "课程名称,分析试卷名称(可用课程名称-试卷唯一性标识)")
+    private String courseName;
+
+    @ApiModelProperty(value = "试卷类型没有就传'#'")
+    private String paperType = "#";
+
+    @ApiModelProperty(value = "开课机构名称(命题机构)")
+    private String teachCollegeName;
+
+    /**
+     * 参数校验
+     */
+    public void validParams() {
+        Optional.ofNullable(this.getExamId()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("考试id为空"));
+        Optional.ofNullable(this.getCourseCode()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("课程编码为空"));
+        Optional.ofNullable(this.getCourseName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("课程名称为空"));
+        Optional.ofNullable(this.getTeachCollegeName()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("开课机构名称为空"));
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(String paperType) {
+        this.paperType = paperType;
+    }
+
+    public String getTeachCollegeName() {
+        return teachCollegeName;
+    }
+
+    public void setTeachCollegeName(String teachCollegeName) {
+        this.teachCollegeName = teachCollegeName;
+    }
+}

+ 12 - 1
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/params/TBExamParam.java

@@ -2,11 +2,13 @@ package com.qmth.teachcloud.report.business.bean.params;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import io.swagger.annotations.ApiModelProperty;
 import org.hibernate.validator.constraints.Length;
 import org.hibernate.validator.constraints.Range;
 
 import javax.validation.constraints.NotNull;
+import java.util.Optional;
 
 /**
  * @Description: 考试参数
@@ -24,7 +26,7 @@ public class TBExamParam {
 
     @ApiModelProperty(value = "考试名称(2020~2021学年上学期期末考试)")
     @NotNull(message = "请输入考试名称")
-    @Length(min = 1,message = "请输入考试名称")
+    @Length(min = 1, message = "请输入考试名称")
     private String examName;
 
     @ApiModelProperty(value = "考试时间")
@@ -38,6 +40,15 @@ public class TBExamParam {
     @Range(min = 1L, message = "请输入所属学期id")
     private Long semesterId;
 
+    /**
+     * 参数校验
+     */
+    public void validParams() {
+        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() {
         return id;
     }

+ 3 - 3
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/service/impl/TBExamServiceImpl.java

@@ -6,7 +6,6 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSemester;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.BasicSemesterService;
-import com.qmth.teachcloud.common.util.DateDisposeUtils;
 import com.qmth.teachcloud.report.business.bean.params.TBExamParam;
 import com.qmth.teachcloud.report.business.entity.TBCloudExam;
 import com.qmth.teachcloud.report.business.entity.TBExam;
@@ -40,7 +39,7 @@ public class TBExamServiceImpl extends ServiceImpl<TBExamMapper, TBExam> impleme
         TBCloudExam tbCloudExam = tbCloudExamService.getById(cloudExamId);
         Long examId = tbCloudExam.getExamId();
         TBExam tbExam = this.getById(examId);
-        if (Objects.isNull(tbExam)){
+        if (Objects.isNull(tbExam)) {
             throw ExceptionResultEnum.ERROR.exception("未找到教研分析基础考试信息");
         }
         return tbExam;
@@ -49,7 +48,7 @@ public class TBExamServiceImpl extends ServiceImpl<TBExamMapper, TBExam> impleme
     @Override
     public Long findSchoolIdByExamId(Long examId) {
         TBExam tbExam = this.getById(examId);
-        if (Objects.isNull(tbExam)){
+        if (Objects.isNull(tbExam)) {
             throw ExceptionResultEnum.ERROR.exception("未找到考试id为 : " + examId + " 的考试");
         }
         return tbExam.getSchoolId();
@@ -81,6 +80,7 @@ public class TBExamServiceImpl extends ServiceImpl<TBExamMapper, TBExam> impleme
         tbExam.setExamName(examName);
         tbExam.setExamCode(DateFormatUtils.format(examTime, "yyyyMMdd"));
         tbExam.setSemesterId(semesterId);
+        tbExam.setExamTime(examTime);
         if (SystemConstant.longNotNull(id)) {
             // 编辑
             if (Objects.isNull(this.getById(id))) {

+ 107 - 40
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/OpenApiController.java

@@ -1,78 +1,145 @@
 package com.qmth.teachcloud.report.api;
 
-import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.boot.tools.signature.SignatureEntity;
-import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.teachcloud.common.bean.params.BasicSemesterParams;
 import com.qmth.teachcloud.common.contant.SystemConstant;
-import com.qmth.teachcloud.common.util.HttpUtil;
+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.CourseParam;
+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;
 import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 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>
- * 开放接口前端控制器
+ * 教研分析开放接口前端控制器
  * </p>
  *
  * @author wangliang
  * @since 2022-04-26
  */
-@Api(tags = "开放接口Controller")
+@Api(tags = "教研分析开放接口Controller")
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.open}")
 @Validated
-@Aac(auth = BOOL.FALSE)
 public class OpenApiController {
     private final static Logger log = LoggerFactory.getLogger(OpenApiController.class);
 
-    @ApiOperation(value = "接收基础考务数据")
-    @ApiResponses({@ApiResponse(code = 200, message = "推送基础考务数据", response = Object.class)})
-    @RequestMapping(value = "/basic/examination/data", method = RequestMethod.POST)
-    public Result basicExaminationData(@ApiParam(value = "接收基础考务数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
-        log.info("basicExaminationData进来了,result:{}", result);
+    @Resource
+    BasicSemesterService basicSemesterService;
+
+    @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 {
+        Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
         String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
-        log.info("decodeJson:{}", decodeJson);
-        if (Objects.nonNull(decodeJson)) {
-            JSONObject jsonObject = JSONObject.parseObject(decodeJson);
-            String callbackUrl = jsonObject.getString("callbackUrl");
-            String accessKey = jsonObject.getString("accessKey");
-            String accessSecret = jsonObject.getString("accessSecret");
-            if (Objects.nonNull(callbackUrl)) {
-                Double progress = 0D;
-                for (int i = 0; i < 11; i++) {
-                    progress += 10D;
-                    JSONObject dataObjectJson = new JSONObject();
-                    dataObjectJson.put("progress", progress);
-                    if (progress == 100D) {
-                        dataObjectJson.put("status", "FINISHED");
-                    } else {
-                        dataObjectJson.put("status", "RUNNING");
-                    }
-                    Long timestamp = System.currentTimeMillis();
-                    String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, callbackUrl, timestamp, accessKey, accessSecret);
-                    String callbackResult = HttpUtil.postJson("http://127.0.0.1:7001" + callbackUrl, dataObjectJson.toJSONString(), accessToken, timestamp);
-                    if (Objects.nonNull(callbackResult)) {
-                        log.info("callbackResult:{}", JacksonUtil.parseJson(callbackResult));
-                    }
-                    Thread.sleep(5000);
-                }
-            }
-        }
+        log.info("semesterEdit进来了,result:{}", decodeJson);
+        BasicSemesterParams basicSemesterParams = JacksonUtil.readJson(decodeJson, BasicSemesterParams.class);
+        Optional.ofNullable(basicSemesterParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
+        basicSemesterParams.validParams();
+        BasicSchool basicSchool = AuthThirdUtil.hasPermission();
+        return ResultUtil.ok(basicSemesterService.saveBasicSemesterCommon(basicSemesterParams, basicSchool.getId(), null));
+    }
+
+    @ApiOperation(value = "考试创建/更新接口")
+    @ApiResponses({@ApiResponse(code = 200, message = "考试创建/更新接口", response = Object.class)})
+    @RequestMapping(value = "/exam_edit", method = RequestMethod.POST)
+    @Aac(auth = BOOL.FALSE)
+    public Result examEdit(@ApiParam(value = "接收考试数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
+        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);
+        Optional.ofNullable(tbExamParam).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
+        tbExamParam.validParams();
+        BasicSchool basicSchool = AuthThirdUtil.hasPermission();
+        tbExamParam.setSchoolId(basicSchool.getId());
+        return ResultUtil.ok(tbExamService.editTBExam(tbExamParam));
+    }
+
+    @ApiOperation(value = "分析课程(试卷)创建/更新接口")
+    @ApiResponses({@ApiResponse(code = 200, message = "分析课程(试卷)创建/更新接口", response = Object.class)})
+    @RequestMapping(value = "/course_edit", method = RequestMethod.POST)
+    @Aac(auth = BOOL.FALSE)
+    @Transactional
+    public Result courseEdit(@ApiParam(value = "接收分析课程(试卷)数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
+        Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
+        String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
+        log.info("courseEdit进来了进来了,result:{}", decodeJson);
+        CourseParam courseParam = JacksonUtil.readJson(decodeJson, CourseParam.class);
+        courseParam.validParams();
+        BasicSchool basicSchool = AuthThirdUtil.hasPermission();
+        basicCourseService.createCourse(basicSchool.getId(), courseParam.getCourseCode(), courseParam.getCourseName());
+        tbExamCourseService.createCourse(basicSchool.getId(), courseParam.getExamId(), courseParam.getCourseCode(), courseParam.getCourseName(), courseParam.getPaperType(), courseParam.getTeachCollegeName());
         return ResultUtil.ok(true);
     }
+
+//    @ApiOperation(value = "接收基础考务数据")
+//    @ApiResponses({@ApiResponse(code = 200, message = "推送基础考务数据", response = Object.class)})
+//    @RequestMapping(value = "/basic/examination/data", method = RequestMethod.POST)
+//    public Result basicExaminationData(@ApiParam(value = "接收基础考务数据信息", required = true) @RequestBody String result) throws IOException, InterruptedException {
+//        log.info("basicExaminationData进来了,result:{}", result);
+//        String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
+//        log.info("decodeJson:{}", decodeJson);
+//        if (Objects.nonNull(decodeJson)) {
+//            JSONObject jsonObject = JSONObject.parseObject(decodeJson);
+//            String callbackUrl = jsonObject.getString("callbackUrl");
+//            String accessKey = jsonObject.getString("accessKey");
+//            String accessSecret = jsonObject.getString("accessSecret");
+//            if (Objects.nonNull(callbackUrl)) {
+//                Double progress = 0D;
+//                for (int i = 0; i < 11; i++) {
+//                    progress += 10D;
+//                    JSONObject dataObjectJson = new JSONObject();
+//                    dataObjectJson.put("progress", progress);
+//                    if (progress == 100D) {
+//                        dataObjectJson.put("status", "FINISHED");
+//                    } else {
+//                        dataObjectJson.put("status", "RUNNING");
+//                    }
+//                    Long timestamp = System.currentTimeMillis();
+//                    String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, callbackUrl, timestamp, accessKey, accessSecret);
+//                    String callbackResult = HttpUtil.postJson("http://127.0.0.1:7001" + callbackUrl, dataObjectJson.toJSONString(), accessToken, timestamp);
+//                    if (Objects.nonNull(callbackResult)) {
+//                        log.info("callbackResult:{}", JacksonUtil.parseJson(callbackResult));
+//                    }
+//                    Thread.sleep(5000);
+//                }
+//            }
+//        }
+//        return ResultUtil.ok(true);
+//    }
 }

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

@@ -13,10 +13,10 @@ spring.application.name=teachcloud-report
 #db.host=192.168.10.136
 db.host=localhost
 db.port=3306
-db.name=teachcloud_report_v3.0.2
+db.name=teachcloud-report-v3.1.0
 #db.name=teachcloud-report
 db.username=root
-db.password=88888888
+db.password=123456789
 
 #redis\u6570\u636E\u6E90\u914D\u7F6E
 com.qmth.redis.host=${db.host}
@@ -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
@@ -141,6 +141,6 @@ yun.mark.studentScoreApi=/api/exam/student/score
 
 print.open.callbackUrlApi=/api/admin/print/notify/analysis/progress
 
-com.qmth.solar.access-key=274f823e5f59410f8b3bb6edcd8e2b6e
-com.qmth.solar.access-secret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
+#com.qmth.solar.access-key=274f823e5f59410f8b3bb6edcd8e2b6e
+#com.qmth.solar.access-secret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
 #com.qmth.solar.license=/Users/king/Downloads/tc-dev-wl.lic