caozixuan пре 3 година
родитељ
комит
e67e059bce

+ 11 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/result/TBStudentReportResult.java

@@ -48,6 +48,9 @@ public class TBStudentReportResult implements Serializable {
     @ApiModelProperty(value = "是否缺考")
     private Boolean absent;
 
+    @ApiModelProperty(value = "学号(密文)")
+    private String studentCodeEncoder;
+
     public String getCollegeName() {
         return collegeName;
     }
@@ -127,4 +130,12 @@ public class TBStudentReportResult implements Serializable {
     public void setStudentCode(String studentCode) {
         this.studentCode = studentCode;
     }
+
+    public String getStudentCodeEncoder() {
+        return studentCodeEncoder;
+    }
+
+    public void setStudentCodeEncoder(String studentCodeEncoder) {
+        this.studentCodeEncoder = studentCodeEncoder;
+    }
 }

+ 12 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/bean/result/TeachCollegeResult.java

@@ -24,6 +24,10 @@ public class TeachCollegeResult {
 
     @ApiModelProperty(value = "科目名称")
     private String courseName;
+
+    @ApiModelProperty(value = "学号(密文)")
+    private String studentCodeEncoder;
+
     @ExcelProperty(name = "课程(代码)", width = 40, index = 3)
     private String courseNameCode;
 
@@ -229,4 +233,12 @@ public class TeachCollegeResult {
     public void setCurrentStr(String currentStr) {
         this.currentStr = currentStr;
     }
+
+    public String getStudentCodeEncoder() {
+        return studentCodeEncoder;
+    }
+
+    public void setStudentCodeEncoder(String studentCodeEncoder) {
+        this.studentCodeEncoder = studentCodeEncoder;
+    }
 }

+ 13 - 1
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/service/impl/TBExamStudentServiceImpl.java

@@ -30,6 +30,7 @@ import com.qmth.teachcloud.report.business.enums.PublishStatusEnum;
 import com.qmth.teachcloud.report.business.enums.SemesterEnum;
 import com.qmth.teachcloud.report.business.mapper.*;
 import com.qmth.teachcloud.report.business.service.TBExamStudentService;
+import com.qmth.teachcloud.report.business.utils.EncrypAES;
 import org.apache.commons.lang3.StringUtils;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -188,6 +189,11 @@ public class TBExamStudentServiceImpl extends ServiceImpl<TBExamStudentMapper, T
         } else {
             listPage = tbExamStudentMapper.listTeachCollegeResult(new Page<>(pageNumber, pageSize), schoolId, Objects.nonNull(semester) ? semester.name() : null, examId, courseCode, current, inspectCollegeId, orgId, teacherId, studentParam, Objects.nonNull(sysUser.getOrgId()) ? Arrays.asList(sysUser.getOrgId()) : null, column, Objects.nonNull(order) ? order.name() : null);
         }
+        List<TeachCollegeResult> teachCollegeResultList = listPage.getRecords();
+        for (TeachCollegeResult teachCollegeResult : teachCollegeResultList) {
+            String code = teachCollegeResult.getStudentCode();
+            teachCollegeResult.setStudentCodeEncoder(EncrypAES.encrypt(code));
+        }
         return listPage;
     }
 
@@ -294,7 +300,13 @@ public class TBExamStudentServiceImpl extends ServiceImpl<TBExamStudentMapper, T
         if (schoolId == null) {
             schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         }
-        return tbExamStudentMapper.reportList(iPage, schoolId, examId, collegeId, courseCode, clazzId, absent, studentCode);
+        IPage<TBStudentReportResult> page = tbExamStudentMapper.reportList(iPage, schoolId, examId, collegeId, courseCode, clazzId, absent, studentCode);
+        List<TBStudentReportResult> tbStudentReportResultList = page.getRecords();
+        for (TBStudentReportResult tbStudentReportResult : tbStudentReportResultList) {
+            String code = tbStudentReportResult.getStudentCode();
+            tbStudentReportResult.setStudentCodeEncoder(EncrypAES.encrypt(code));
+        }
+        return page;
     }
 
     /**

+ 125 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/utils/AesUtil.java

@@ -0,0 +1,125 @@
+package com.qmth.teachcloud.report.business.utils;
+
+import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Base64;
+
+/**
+ * @Description: AES对称加密
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2019/10/11
+ */
+public class AesUtil {
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AesUtil.class);
+    private static final String AES_MODE = "AES/CBC/PKCS5Padding";
+    private static final String AES = "AES";
+
+
+    private static final String RULE = "123456790abcdefg";
+
+    /**
+     * 加密
+     *
+     * @param content
+     * @param strKey
+     * @param rule
+     * @return
+     * @throws Exception
+     */
+    private static byte[] encrypt(String content, String strKey, String rule) throws Exception {
+        SecretKeySpec skeySpec = getKey(strKey);
+        Cipher cipher = Cipher.getInstance(AES_MODE);
+        IvParameterSpec iv = new IvParameterSpec(rule.getBytes());//AES规则,可自定义,例如A-Z排序
+        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
+        return cipher.doFinal(content.getBytes());
+    }
+
+    /**
+     * 解密
+     *
+     * @param content
+     * @param strKey
+     * @param rule
+     * @return
+     * @throws Exception
+     */
+    private static String decrypt(byte[] content, String strKey, String rule) throws Exception {
+        SecretKeySpec skeySpec = getKey(strKey);
+        Cipher cipher = Cipher.getInstance(AES_MODE);
+        IvParameterSpec iv = new IvParameterSpec(rule.getBytes());//AES规则,可自定义,例如A-Z排序
+        cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
+        byte[] original = cipher.doFinal(content);
+        return new String(original);
+    }
+
+    /**
+     * 公钥
+     *
+     * @param strKey
+     * @return
+     * @throws Exception
+     */
+    private static SecretKeySpec getKey(String strKey) throws Exception {
+        byte[] arrBTmp = strKey.getBytes();
+        byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
+        for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
+            arrB[i] = arrBTmp[i];
+        }
+        return new SecretKeySpec(arrB, AES);
+    }
+
+    /**
+     * AES加密
+     *
+     * @param content
+     * @param encryptKey
+     * @return
+     * @throws Exception
+     */
+    public static String encoder(String content, String encryptKey, String rule) throws Exception {
+        if(StringUtils.isEmpty(rule)){
+            rule = RULE;
+        }
+//        LOGGER.info("AES加密前的内容:{},key:{}", content, encryptKey);
+        String encoderText = Base64.getEncoder().encodeToString(encrypt(content, encryptKey, RULE));
+//        LOGGER.info("AES加密后的文本:{}", encoderText);
+        return encoderText;
+    }
+
+    /**
+     * AES解密
+     *
+     * @param encryptStr
+     * @param decryptKey
+     * @return
+     * @throws Exception
+     */
+    public static String decoder(String encryptStr, String decryptKey, String rule) throws Exception {
+        if(StringUtils.isEmpty(rule)){
+            rule = RULE;
+        }
+//        LOGGER.info("AES解密前的内容:{},key:{}", encryptStr, decryptKey);
+        String decoderText = decrypt(Base64.getDecoder().decode(encryptStr), decryptKey, RULE);
+//        LOGGER.info("AES解密后的文本:{}", decoderText);
+        return decoderText;
+    }
+
+    public static void main(String[] args) throws Exception {
+//        String encoder = encoder("2019302130225", "1", null);
+//        System.out.println(encoder);
+//        String decoder = decoder(encoder, "1", null);
+//        System.out.println(decoder);
+
+
+        String encoder = Base64.getEncoder().encodeToString("".getBytes());
+        System.out.println(encoder);
+        String decoder = new String(Base64.getDecoder().decode(encoder));
+        System.out.println(decoder);
+    }
+}

+ 87 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/utils/EncrypAES.java

@@ -0,0 +1,87 @@
+package com.qmth.teachcloud.report.business.utils;
+
+import org.apache.commons.codec.binary.Hex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author by xf
+ * @date 2019/11/25.
+ * DigestUtils.md5Hex进行md5加密
+ */
+public class EncrypAES {
+
+    private static final Logger logger = LoggerFactory.getLogger(EncrypAES.class);
+
+    private static final String KEY_ALGORITHM = "AES";
+    /**
+     * 加解密算法/工作模式/填充方式
+     */
+    private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
+
+
+    private static byte[] KEYBYTES = {0x31, 0x32, 0x33, 0x34, 0x35, 0x50, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
+
+
+    /**
+     * 加密
+     * @param value
+     * @return
+     */
+    public static String encrypt(String value) {
+        String s = null;
+        int mode = Cipher.ENCRYPT_MODE;
+        try {
+            Cipher cipher = initCipher(mode);
+            byte[] outBytes = cipher.doFinal(value.getBytes());
+            s = String.valueOf(Hex.encodeHex(outBytes));
+        } catch (Exception e) {
+            logger.error(e.getMessage());
+        }
+        return s;
+    }
+
+
+    /**
+     * 解密
+     * @param value
+     * @return
+     */
+    public static String decrypt(String value) {
+        String s = null;
+        int mode = Cipher.DECRYPT_MODE;
+        try {
+            Cipher cipher = initCipher(mode);
+            byte[] outBytes = cipher.doFinal(Hex.decodeHex(value.toCharArray()));
+            s = new String(outBytes);
+        } catch (Exception e) {
+            logger.error(e.getMessage());
+        }
+        return s;
+    }
+
+    private static Cipher initCipher(int mode) throws NoSuchAlgorithmException,
+            NoSuchPaddingException, InvalidKeyException {
+        Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
+        Key key = new SecretKeySpec(KEYBYTES, KEY_ALGORITHM);
+        cipher.init(mode, key);
+        return cipher;
+    }
+
+    public static void main(String[] args) {
+        String content = "12019302130225";
+        String en = encrypt(content);
+        System.out.println("en:" + en);
+
+        String de = decrypt(en);
+        System.out.println("de:" + de);
+    }
+
+}

+ 2 - 0
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/StudentReportController.java

@@ -10,6 +10,7 @@ import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.report.business.bean.result.TBExamStudentResult;
 import com.qmth.teachcloud.report.business.enums.SemesterEnum;
 import com.qmth.teachcloud.report.business.service.TBExamStudentService;
+import com.qmth.teachcloud.report.business.utils.EncrypAES;
 import io.swagger.annotations.*;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -52,6 +53,7 @@ public class StudentReportController {
     @Aac(auth = BOOL.FALSE)
     public Result reportResult(@ApiParam(value = "学校id", required = false) @RequestParam(required = false) String schoolId,
                                @ApiParam(value = "学号", required = true) @RequestParam String studentCode) {
+        studentCode = EncrypAES.decrypt(studentCode);
         return ResultUtil.ok(tbExamStudentService.reportResult(SystemConstant.convertIdToLong(schoolId), studentCode));
     }
 

+ 7 - 2
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/WudaOpenApiController.java

@@ -22,6 +22,8 @@ import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.report.business.cache.WhuUserAuthCacheUtil;
 import com.qmth.teachcloud.report.business.service.ReportCommonService;
+import com.qmth.teachcloud.report.business.utils.AesUtil;
+import com.qmth.teachcloud.report.business.utils.EncrypAES;
 import io.swagger.annotations.*;
 import org.apache.commons.lang3.StringUtils;
 import org.jasig.cas.client.authentication.AttributePrincipal;
@@ -42,6 +44,7 @@ import java.net.URLEncoder;
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
 import java.text.MessageFormat;
+import java.util.Base64;
 import java.util.Map;
 import java.util.Objects;
 
@@ -74,6 +77,7 @@ public class WudaOpenApiController {
         log.info("student request.getRemoteUser():{}", JacksonUtil.parseJson(request.getRemoteUser()));
         String uid = request.getRemoteUser();
         if (Objects.isNull(uid)) {
+
             throw ExceptionResultEnum.NOT_LOGIN.exception();
         }
         // 测试用代码 --- 开始 ---
@@ -91,8 +95,9 @@ public class WudaOpenApiController {
         BasicSchool basicSchool = cacheService.schoolCache(SystemConstant.SCHOOL_CODE);
         String testUrl = dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + uid + "/" + cn;
         log.info("test-stu-testUrl:{}", testUrl);
-        response.setHeader("Access-Control-Allow-Origin", "*");
-        response.sendRedirect(dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + uid);
+        String encoderUid = EncrypAES.encrypt(uid);
+        log.info("test-encoderUid:{}", encoderUid);
+        response.sendRedirect(dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + encoderUid);
     }
 
     @ApiOperation(value = "cas用户鉴权退出接口")