瀏覽代碼

客户端新增上传db文件

wangliang 1 年之前
父節點
當前提交
ded25710c8

+ 5 - 1
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java

@@ -225,7 +225,11 @@ public class TEExamController {
             }
             List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().eq(TEExamActivity::getExamId, teExam.getId()).eq(TEExamActivity::getEnable, 1));
             for (TEExamActivity t : teExamActivityList) {
-                themisCacheService.updateTodayExamListCache(t.getExamId().toString(), t.getId());
+                if (Objects.nonNull(t.getEnable()) && t.getEnable().intValue() == 1 && t.getFinishTime().longValue() > System.currentTimeMillis()) {
+                    themisCacheService.updateTodayExamListCache(t.getExamId().toString(), t.getId());
+                } else {
+                    themisCacheService.removeTodayExamListCache(t.getExamId().toString(), t.getId());
+                }
                 themisCacheService.updateOrgExamListCache(teExam.getOrgId().toString(), t.getExamId().toString(), t.getId());
             }
         } catch (Exception e) {

+ 1 - 0
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -107,6 +107,7 @@ public class SystemConstant {
     public static final String TENCENT_CLOUD_SDK_CALLBACK_TIME = "tencentcloud.sdk.callbackTime";
     public static final String TENCENT_CLOUD_SDK_TRTC_QUERY_URL = "tencentcloud.sdk.trtcQueryUrl";
     public static final String TENCENT_CLOUD_SDK_TRTC_REGION = "tencentcloud.sdk.trtcRegion";
+    public static final String CLIENT_DB_UPLOAD_LOCATION = "client.db.upload.location";
     public static final String CDN_URL = "cdn.url";
 
     public static final String DENY_LIST_FILE_NAME = "denyList.json";

+ 1 - 2
themis-business/src/main/java/com/qmth/themis/business/service/impl/TBAttachmentServiceImpl.java

@@ -127,8 +127,7 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 stringJoiner.add(File.separator).add(SystemConstant.getNanoId())
                         .add(tbAttachment.getType());
-                ossUtil.upload(ossUtil.isPublic(type), stringJoiner.toString(), file.getInputStream(),
-                        BinaryUtil.toBase64String(HexUtils.decodeHex(md5)));
+                ossUtil.upload(ossUtil.isPublic(type), stringJoiner.toString(), file.getInputStream(), md5);
             } else {//上传至服务器
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
                 File finalFile = new File(

+ 5 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamActivityServiceImpl.java

@@ -413,7 +413,11 @@ public class TEExamActivityServiceImpl extends ServiceImpl<TEExamActivityMapper,
             teExamActivityService.saveOrUpdateBatch(teExamActivityList);
 
             for (TEExamActivity ac : teExamActivityList) {
-                themisCacheService.updateTodayExamListCache(ac.getExamId().toString(), ac.getId());
+                if (Objects.nonNull(ac.getEnable()) && ac.getEnable().intValue() == 1 && ac.getFinishTime().longValue() > System.currentTimeMillis()) {
+                    themisCacheService.updateTodayExamListCache(ac.getExamId().toString(), ac.getId());
+                } else {
+                    themisCacheService.removeTodayExamListCache(ac.getExamId().toString(), ac.getId());
+                }
                 themisCacheService.updateOrgExamListCache(teExam.getOrgId().toString(), ac.getExamId().toString(), ac.getId());
                 teExamActivityService.updateExamActivityCacheBean(ac.getId());
             }

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -901,7 +901,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         InputStream in = null;
         try {
             in = file.getInputStream();
-            ossUtil.upload(true, filePath, in, BinaryUtil.toBase64String(HexUtils.decodeHex(md5)));
+            ossUtil.upload(true, filePath, in, md5);
             String url = ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + filePath;
             ExamFileUploadBean ret = new ExamFileUploadBean();
             ret.setUrl(url);

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -49,7 +49,6 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
      * @param roomCodeSet
      */
     @Override
-//    @Transactional
     public void examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet) {
         if (!CollectionUtils.isEmpty(roomCodeSet)) {
             for (String s : roomCodeSet) {
@@ -58,6 +57,7 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
                 this.examSummaryCommon(examId, examActivityId, s, teExamSummary);
             }
         } else {
+            //根据考试批次、场次统计信息
             TEExamSummary teExamSummary = this.baseMapper.examSummary(examId, examActivityId, null);
             this.examSummaryCommon(examId, examActivityId, null, teExamSummary);
         }

+ 0 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOrgSummaryServiceImpl.java

@@ -44,7 +44,6 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
      * @param examIdSet
      */
     @Override
-//    @Transactional
     public void orgSummary(Long orgId, List<Long> examIdSet) {
         if (orgId.longValue() == 0) {//全局机构
             Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java

@@ -145,7 +145,7 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
                 this.saveOrUpdate(student);
                 themisCacheService.updateStudentAccountCache(student.getId());
                 in = file.getInputStream();
-                ossUtil.upload(true, filePath, in, BinaryUtil.toBase64String(HexUtils.decodeHex(md5)));
+                ossUtil.upload(true, filePath, in, md5);
 //                String url = ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + filePath;
 //                StudentPhotoUploadResponseBean ret = new StudentPhotoUploadResponseBean();
 //                ret.setPhotoUrl(url);

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -830,6 +830,10 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
                 copyOnWriteArrayList.add(JacksonUtil.parseJson(new ExamListBean(examActivityId, roomCodeSet)));
                 redisUtil.set(SystemConstant.TODAY_EXAM_LIST_MAP_CACHE, examId, new LinkedList<>(copyOnWriteArrayList));
             }
+        } else {
+            CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList();
+            copyOnWriteArrayList.add(JacksonUtil.parseJson(new ExamListBean(examActivityId, null)));
+            redisUtil.set(SystemConstant.TODAY_EXAM_LIST_MAP_CACHE, examId, new LinkedList<>(copyOnWriteArrayList));
         }
     }
 

+ 8 - 0
themis-business/src/main/resources/db/log/1.2.8.log

@@ -112,6 +112,14 @@ ALTER TABLE t_e_exam_student DROP INDEX student_id;
 CREATE INDEX t_e_exam_student_exam_id_IDX USING BTREE ON t_e_exam_student (exam_id,exam_activity_id,room_code);
 CREATE INDEX t_e_exam_student_student_id_IDX USING BTREE ON t_e_exam_student (student_id,exam_activity_id,enable);
 
+INSERT INTO sys_config
+(id, org_id, config_key, config_name, config_value, enable, create_id, create_time, update_id, update_time, remark, sort, editor)
+VALUES(32, NULL, 'client.db.upload.location', '客户端上传db地址', '/oe-client/exception/db', 1, 1, NULL, NULL, NULL, NULL, 1, 0);
+
+UPDATE sys_config
+SET org_id=NULL, config_key='exam.no.auth.urls', config_name='exam无需鉴权的url', config_value='/webjars/**,/druid/**,/swagger-ui.html,/doc.html,/swagger-resources/**,/v2/api-docs,/webjars/springfox-swagger-ui/**,/api/oe/student/login,/api/oe/sys/env,/file/**,/upload/**,/client/**,/base_photo/**,/frontend/**,/api/oe/exam/short_code,/api/mobile/authorization,/api/oe/black/list/select,/api/oe/sys/school/list,/api/oe/sys/upload/package/callback,/api/oe/sys/file/upload', enable=1, create_id=1, create_time=NULL, update_id=NULL, update_time=NULL, remark=NULL, sort=1, editor=0
+WHERE id=17;
+
 /*删除进度查询菜单*/
 INSERT INTO t_b_role_privilege
 (id, role_code, privilege_id)

+ 38 - 8
themis-exam/src/main/java/com/qmth/themis/exam/api/SysController.java

@@ -4,6 +4,7 @@ import com.google.common.reflect.TypeToken;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.bean.exam.EnvBean;
+import com.qmth.themis.business.bean.exam.ExamFileUploadBean;
 import com.qmth.themis.business.bean.exam.OrgInfoBean;
 import com.qmth.themis.business.bean.exam.VersionBean;
 import com.qmth.themis.business.constant.SystemConstant;
@@ -16,6 +17,7 @@ import com.qmth.themis.business.enums.UploadFileEnum;
 import com.qmth.themis.business.service.TBClientVersionService;
 import com.qmth.themis.business.service.TBOrgService;
 import com.qmth.themis.business.service.ThemisCacheService;
+import com.qmth.themis.business.util.OssUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.GsonUtil;
@@ -26,17 +28,14 @@ import io.swagger.annotations.*;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
 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 org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
 
 @Api(tags = "系统信息Controller")
 @RestController
@@ -56,6 +55,9 @@ public class SysController {
     @Resource
     TBOrgService tbOrgService;
 
+    @Resource
+    OssUtil ossUtil;
+
     @ApiOperation(value = "获取环境接口")
     @RequestMapping(value = "/env", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "环境信息", response = Result.class)})
@@ -121,4 +123,32 @@ public class SysController {
         Optional.ofNullable(cdnUrl).orElseThrow(() -> new BusinessException("cdn地址未配置"));
         return ResultUtil.ok(tbClientVersionService.save(new TBClientVersion(tbOrg.getId(), cdnUrl.getConfigValue() + tbOrgBean.getPackagePath(), tbOrgBean.getDescription(), ClientVersionTypeEnum.UPLOAD)));
     }
+
+    @ApiOperation(value = "文件上传")
+    @RequestMapping(value = "/file/upload", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "试卷信息")})
+    public Result fileUpload(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
+                             @ApiParam(value = "md5", required = true) @RequestParam String md5,
+                             @ApiParam(value = "上传文件目录") @RequestParam(required = false) String fileDir) throws IOException {
+        InputStream in = null;
+        ExamFileUploadBean ret = new ExamFileUploadBean();
+        try {
+            SysConfig sysConfig = themisCacheService.addSysConfigCache(SystemConstant.CLIENT_DB_UPLOAD_LOCATION);
+            Optional.ofNullable(sysConfig).orElseThrow(() -> new BusinessException("未配置客户端上传db目录地址"));
+
+            StringJoiner stringJoiner = new StringJoiner("").add(sysConfig.getConfigValue());
+            stringJoiner = Objects.nonNull(fileDir) && !Objects.equals(fileDir.trim(), "") ? stringJoiner.add(File.separator).add(fileDir) : stringJoiner;
+            stringJoiner = stringJoiner.add(File.separator).add(file.getOriginalFilename());
+            in = file.getInputStream();
+            ossUtil.upload(true, stringJoiner.toString(), in, md5);
+            String url = ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + stringJoiner.toString();
+            ret.setUrl(url);
+            ret.setUploadTime(System.currentTimeMillis());
+        } catch (IOException e) {
+            throw new BusinessException("文件读取出错");
+        } finally {
+            in.close();
+        }
+        return ResultUtil.ok(ret);
+    }
 }