Przeglądaj źródła

Merge remote-tracking branch 'origin/dev' into dev

wangliang 4 lat temu
rodzic
commit
60e199ff97

+ 26 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/ExamFileUploadBean.java

@@ -0,0 +1,26 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("考试文件上传返回信息")
+public class ExamFileUploadBean {
+	@ApiModelProperty("文件上传成功后的访问地址")
+	private String url;
+	@ApiModelProperty("时间戳")
+	private Long uploadTime;
+	public String getUrl() {
+		return url;
+	}
+	public void setUrl(String url) {
+		this.url = url;
+	}
+	public Long getUploadTime() {
+		return uploadTime;
+	}
+	public void setUploadTime(Long uploadTime) {
+		this.uploadTime = uploadTime;
+	}
+
+	
+}

+ 17 - 3
themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java

@@ -1,14 +1,17 @@
 package com.qmth.themis.business.service;
 
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.web.multipart.MultipartFile;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.bean.exam.ExamFileUploadBean;
 import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.bean.exam.ExamStartBean;
 import com.qmth.themis.business.entity.TEExam;
 
-import java.util.List;
-import java.util.Map;
-
 /**
  * @Description: 考试批次 服务类
  * @Param:
@@ -94,4 +97,15 @@ public interface TEExamService extends IService<TEExam> {
 	 * @return
 	 */
 	public Integer audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count);
+
+	
+	/**文件上传
+	 * @param studentId
+	 * @param recordId
+	 * @param file
+	 * @param suffix
+	 * @param md5
+	 * @return
+	 */
+	public ExamFileUploadBean fileUpload(Long studentId, Long recordId, MultipartFile file, String suffix, String md5);
 }

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

@@ -1,18 +1,25 @@
 package com.qmth.themis.business.service.impl;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.UUID;
 
 import javax.annotation.Resource;
 
+import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.bean.exam.ExamFileUploadBean;
 import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.bean.exam.ExamStartBean;
 import com.qmth.themis.business.cache.RedisKeyHelper;
@@ -45,234 +52,234 @@ import com.qmth.themis.common.exception.BusinessException;
  */
 @Service
 public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> implements TEExamService {
-    @Resource
-    TEExamMapper teExamMapper;
-
-    @Resource
-    TEExamActivityService teExamActivityService;
-
-    @Resource
-    TEExamStudentService teExamStudentService;
-
-    @Resource
-    TEExamCourseService teExamCourseService;
-
-    @Resource
-    TEExamPaperService teExamPaperService;
-
-    @Resource
-    TOeExamRecordService toeExamRecordService;
-
-    @Resource
-    RedisUtil redisUtil;
-
-    @Resource
-    SystemConfig systemConfig;
-
-    /**
-     * 查询考试批次
-     *
-     * @param iPage
-     * @param id
-     * @param code
-     * @param name
-     * @param mode
-     * @param enable
-     * @return
-     */
-    @Override
-    public IPage<TEExam> examQuery(IPage<Map> iPage, Long id, String code, String name, Integer mode, Integer enable) {
-        return teExamMapper.examQuery(iPage, id, code, name, mode, enable);
-    }
-
-    /**
-     * 获取考试待考列表
-     *
-     * @param studentId
-     * @param examId
-     * @param orgId
-     * @return
-     */
-    @Override
-    public List<Map> getWaitingExam(Long studentId, Long examId, Long orgId) {
-        List<Map> list = teExamMapper.getWaitingExam(studentId, examId, orgId);
-        if (Objects.nonNull(list) && list.size() > 0) {
-            for (int i = 0; i < list.size(); i++) {
-                Map m = list.get(i);
-                List<Map> teExamActivityList = teExamActivityService.getWaitingExam(studentId,
-                        Long.parseLong(String.valueOf(m.get("id"))),
-                        Long.parseLong(String.valueOf(m.get("examActivityId"))));
-                m.put("activities", teExamActivityList);
-            }
-        }
-        return list;
-    }
-
-    /**
-     * 获取考试待考列表
-     *
-     * @return
-     */
-    @Override
-    public List<Map> getWaitingExamForJob() {
-        return teExamMapper.getWaitingExamForJob();
-    }
-
-    @Transactional
-    @Override
-    public ExamPrepareBean prepare(Long studentId, Long examStudentId) {
-        ExamPrepareBean ret = null;
-        ExamStudentCacheBean es = null;
-        es = (ExamStudentCacheBean) redisUtil.get(RedisKeyHelper.examStudentCacheKey(examStudentId));
-        if (es == null) {
-            es = teExamStudentService.getExamStudnetCacheBean(examStudentId);
-        }
-        if (es == null) {
-            throw new BusinessException("未找到考试");
-        }
-
-        if (studentId.equals(es.getStudentId())) {
-            throw new BusinessException("考生Id和当前登录用户不一致");
-        }
-        if (es.getLeftExamCount() == 0) {
-            throw new BusinessException("没有剩余考试次数");
-        }
-        Long activityId = es.getExamActivityId();
-        ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
-        if (ac == null) {
-            throw new BusinessException("未找到场次");
-        }
-        Date now = new Date();
-        Long start = ac.getStartTime().getTime() - (ac.getPrepareSeconds() * 1000);
-        Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
-        if (now.getTime() < start) {
-            throw new BusinessException("没有到允许开考的时间");
-        }
-        if (now.getTime() > end) {
-            throw new BusinessException("允许开考的时间已结束");
-        }
-        ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
-        if (ec == null) {
-            throw new BusinessException("未找到考试科目");
-        }
-        if (ec.getPaperIds() == null) {
-            throw new BusinessException("考试科目未绑定试卷");
-        }
-        if (ec.getHasAnswer() == null || ec.getHasAnswer().intValue() == 0) {
-            throw new BusinessException("考试科目答案未补全");
-        }
-        // 根据权重选中试卷
-        Long paperId = ec.getPaperIds().get(getPaperByWeight(ec.getPaperWeight()));
-        ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(paperId);
-        if (ep == null) {
-            throw new BusinessException("未找到试卷:" + paperId);
-        }
-        if (StringUtils.isBlank(ep.getAnswerPath())) {
-            throw new BusinessException("试卷答案未上传:" + paperId);
-        }
-
-        // 写入次数
-        Integer serialNumber = es.getCurrentSerialNumber();
-        if (serialNumber == null) {
-            serialNumber = 0;
-        }
-        es.setCurrentSerialNumber(serialNumber + 1);
-
-        Long recordId = toeExamRecordService.saveByPrepare(es.getExamId(), es.getExamActivityId(), examStudentId,
-                paperId, es.getCurrentSerialNumber());
-
-        Integer leftExamCount = es.getLeftExamCount();
-        es.setLeftExamCount(leftExamCount - 1);
-
-        es.setCurrentRecordId(recordId);
-
-        ExamPrepareBean prepare = new ExamPrepareBean();
-        prepare.setRecordId(recordId);
-        prepare.setAudioPlayTime(ep.getAudioPlayTime());
-        prepare.setHasAudio((ep.getHasAudio() == null || ep.getHasAudio().intValue() == 0 ? false : true));
-        prepare.setObjectiveShuffle(
-                (ec.getObjectiveShuffle() == null || ec.getObjectiveShuffle().intValue() == 0 ? false : true));
-        prepare.setOptionShuffle(
-                (ec.getOptionShuffle() == null || ec.getOptionShuffle().intValue() == 0 ? false : true));
-        String paperurl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getPaperPath());
-        String structurl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getStructPath());
-        prepare.setPaperUrl(paperurl);
-        prepare.setStructUrl(structurl);
-
-        // 更新考生缓存
-        redisUtil.set(RedisKeyHelper.examStudentCacheKey(examStudentId), es);
-
-        return ret;
-    }
-
-    /**
-     * 根据设定几率取出一套试卷
-     */
-    private int getPaperByWeight(List<Double> paperWeight) {
-        // 从1开始
-        double r = Math.random();
-        for (int i = 0; i < paperWeight.size(); i++) {
-            r -= paperWeight.get(i);
-            if (r <= 0.0d) {
-                return i;// 选中
-            }
-        }
-
-        return -1;
-    }
-
-    @Transactional
-    @Override
-    public ExamStartBean start(Long studentId, Long recordId) {
-        ExamStartBean ret = null;
-        ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
-        if (er == null) {
-            throw new BusinessException("未找到考试记录");
-        }
-        ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
-                .get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
-        if (es == null) {
-            throw new BusinessException("未找到考生");
-        }
-        if (studentId.equals(es.getStudentId())) {
-            throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
-        }
-        Long activityId = es.getExamActivityId();
-        ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
-        if (ac == null) {
-            throw new BusinessException("未找到场次");
-        }
-        Date now = new Date();
-        Long start = ac.getStartTime().getTime();
-        Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
-        if (now.getTime() < start) {
-            throw new BusinessException("没有到允许开考的时间");
-        }
-        if (now.getTime() > end) {
-            throw new BusinessException("允许开考的时间已结束");
-        }
-
-        // 修改考试记录数据
-        er.setFirstStartTime(new Date());
-        er.setStatus(2);
-
-        ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(er.getPaperId());
-        if (ep == null) {
-            throw new BusinessException("未找到试卷");
-        }
-
-        ret = new ExamStartBean();
-        ret.setPaperDecryptSecret(ep.getDecryptSecret());
-        ret.setPaperDecryptVector(ep.getDecryptVector());
-
-        // 更新考试记录缓存
-        redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), er);
-
-        return ret;
-    }
-
-
-    @Transactional
+	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+	@Resource
+	TEExamMapper teExamMapper;
+
+	@Resource
+	TEExamActivityService teExamActivityService;
+
+	@Resource
+	TEExamStudentService teExamStudentService;
+
+	@Resource
+	TEExamCourseService teExamCourseService;
+
+	@Resource
+	TEExamPaperService teExamPaperService;
+
+	@Resource
+	TOeExamRecordService toeExamRecordService;
+
+	@Resource
+	RedisUtil redisUtil;
+
+	@Resource
+	SystemConfig systemConfig;
+
+	/**
+	 * 查询考试批次
+	 *
+	 * @param iPage
+	 * @param id
+	 * @param code
+	 * @param name
+	 * @param mode
+	 * @param enable
+	 * @return
+	 */
+	@Override
+	public IPage<TEExam> examQuery(IPage<Map> iPage, Long id, String code, String name, Integer mode, Integer enable) {
+		return teExamMapper.examQuery(iPage, id, code, name, mode, enable);
+	}
+
+	/**
+	 * 获取考试待考列表
+	 *
+	 * @param studentId
+	 * @param examId
+	 * @param orgId
+	 * @return
+	 */
+	@Override
+	public List<Map> getWaitingExam(Long studentId, Long examId, Long orgId) {
+		List<Map> list = teExamMapper.getWaitingExam(studentId, examId, orgId);
+		if (Objects.nonNull(list) && list.size() > 0) {
+			for (int i = 0; i < list.size(); i++) {
+				Map m = list.get(i);
+				List<Map> teExamActivityList = teExamActivityService.getWaitingExam(studentId,
+						Long.parseLong(String.valueOf(m.get("id"))),
+						Long.parseLong(String.valueOf(m.get("examActivityId"))));
+				m.put("activities", teExamActivityList);
+			}
+		}
+		return list;
+	}
+
+	/**
+	 * 获取考试待考列表
+	 *
+	 * @return
+	 */
+	@Override
+	public List<Map> getWaitingExamForJob() {
+		return teExamMapper.getWaitingExamForJob();
+	}
+
+	@Transactional
+	@Override
+	public ExamPrepareBean prepare(Long studentId, Long examStudentId) {
+		ExamPrepareBean ret = null;
+		ExamStudentCacheBean es = null;
+		es = (ExamStudentCacheBean) redisUtil.get(RedisKeyHelper.examStudentCacheKey(examStudentId));
+		if (es == null) {
+			es = teExamStudentService.getExamStudnetCacheBean(examStudentId);
+		}
+		if (es == null) {
+			throw new BusinessException("未找到考试");
+		}
+
+		if (studentId.equals(es.getStudentId())) {
+			throw new BusinessException("考生Id和当前登录用户不一致");
+		}
+		if (es.getLeftExamCount() == 0) {
+			throw new BusinessException("没有剩余考试次数");
+		}
+		Long activityId = es.getExamActivityId();
+		ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
+		if (ac == null) {
+			throw new BusinessException("未找到场次");
+		}
+		Date now = new Date();
+		Long start = ac.getStartTime().getTime() - (ac.getPrepareSeconds() * 1000);
+		Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
+		if (now.getTime() < start) {
+			throw new BusinessException("没有到允许开考的时间");
+		}
+		if (now.getTime() > end) {
+			throw new BusinessException("允许开考的时间已结束");
+		}
+		ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
+		if (ec == null) {
+			throw new BusinessException("未找到考试科目");
+		}
+		if (ec.getPaperIds() == null) {
+			throw new BusinessException("考试科目未绑定试卷");
+		}
+		if (ec.getHasAnswer() == null || ec.getHasAnswer().intValue() == 0) {
+			throw new BusinessException("考试科目答案未补全");
+		}
+		// 根据权重选中试卷
+		Long paperId = ec.getPaperIds().get(getPaperByWeight(ec.getPaperWeight()));
+		ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(paperId);
+		if (ep == null) {
+			throw new BusinessException("未找到试卷:" + paperId);
+		}
+		if (StringUtils.isBlank(ep.getAnswerPath())) {
+			throw new BusinessException("试卷答案未上传:" + paperId);
+		}
+
+		// 写入次数
+		Integer serialNumber = es.getCurrentSerialNumber();
+		if (serialNumber == null) {
+			serialNumber = 0;
+		}
+		es.setCurrentSerialNumber(serialNumber + 1);
+
+		Long recordId = toeExamRecordService.saveByPrepare(es.getExamId(), es.getExamActivityId(), examStudentId,
+				paperId, es.getCurrentSerialNumber());
+
+		Integer leftExamCount = es.getLeftExamCount();
+		es.setLeftExamCount(leftExamCount - 1);
+
+		es.setCurrentRecordId(recordId);
+
+		ExamPrepareBean prepare = new ExamPrepareBean();
+		prepare.setRecordId(recordId);
+		prepare.setAudioPlayTime(ep.getAudioPlayTime());
+		prepare.setHasAudio((ep.getHasAudio() == null || ep.getHasAudio().intValue() == 0 ? false : true));
+		prepare.setObjectiveShuffle(
+				(ec.getObjectiveShuffle() == null || ec.getObjectiveShuffle().intValue() == 0 ? false : true));
+		prepare.setOptionShuffle(
+				(ec.getOptionShuffle() == null || ec.getOptionShuffle().intValue() == 0 ? false : true));
+		String paperurl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getPaperPath());
+		String structurl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getStructPath());
+		prepare.setPaperUrl(paperurl);
+		prepare.setStructUrl(structurl);
+
+		// 更新考生缓存
+		redisUtil.set(RedisKeyHelper.examStudentCacheKey(examStudentId), es);
+
+		return ret;
+	}
+
+	/**
+	 * 根据设定几率取出一套试卷
+	 */
+	private int getPaperByWeight(List<Double> paperWeight) {
+		// 从1开始
+		double r = Math.random();
+		for (int i = 0; i < paperWeight.size(); i++) {
+			r -= paperWeight.get(i);
+			if (r <= 0.0d) {
+				return i;// 选中
+			}
+		}
+
+		return -1;
+	}
+
+	@Transactional
+	@Override
+	public ExamStartBean start(Long studentId, Long recordId) {
+		ExamStartBean ret = null;
+		ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
+		if (er == null) {
+			throw new BusinessException("未找到考试记录");
+		}
+		ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
+				.get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
+		if (es == null) {
+			throw new BusinessException("未找到考生");
+		}
+		if (studentId.equals(es.getStudentId())) {
+			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
+		}
+		Long activityId = es.getExamActivityId();
+		ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
+		if (ac == null) {
+			throw new BusinessException("未找到场次");
+		}
+		Date now = new Date();
+		Long start = ac.getStartTime().getTime();
+		Long end = ac.getStartTime().getTime() + (ac.getOpeningSeconds() * 1000);
+		if (now.getTime() < start) {
+			throw new BusinessException("没有到允许开考的时间");
+		}
+		if (now.getTime() > end) {
+			throw new BusinessException("允许开考的时间已结束");
+		}
+
+		// 修改考试记录数据
+		er.setFirstStartTime(new Date());
+		er.setStatus(2);
+
+		ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(er.getPaperId());
+		if (ep == null) {
+			throw new BusinessException("未找到试卷");
+		}
+
+		ret = new ExamStartBean();
+		ret.setPaperDecryptSecret(ep.getDecryptSecret());
+		ret.setPaperDecryptVector(ep.getDecryptVector());
+
+		// 更新考试记录缓存
+		redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), er);
+
+		return ret;
+	}
+
+	@Transactional
 	@Override
 	public Long studentPaperStruct(Long studentId, Long recordId, String content) {
 		ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
@@ -311,15 +318,16 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
 		if (studentId.equals(es.getStudentId())) {
 			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
 		}
-		ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil
-				.get(RedisKeyHelper.examAnswerKey(recordId),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
+		ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil.get(
+				RedisKeyHelper.examAnswerKey(recordId),
+				RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
 		if (answerCache == null) {
 			answerCache = new ExamStudentAnswerCacheBean();
 			answerCache.setContent(answer);
 			answerCache.setVersion(version);
 			answerCache.setDuration(durationSeconds);
-		}else {
-			if(version.longValue()<answerCache.getVersion().longValue()) {
+		} else {
+			if (version.longValue() < answerCache.getVersion().longValue()) {
 				throw new BusinessException("版本时间戳过期");
 			}
 			answerCache.setContent(answer);
@@ -327,7 +335,8 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
 			answerCache.setDuration(durationSeconds);
 		}
 		// 更新考生作答
-		redisUtil.set(RedisKeyHelper.examAnswerKey(recordId),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
+		redisUtil.set(RedisKeyHelper.examAnswerKey(recordId),
+				RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
 		return version;
 	}
 
@@ -347,9 +356,53 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
 			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
 		}
 		// 音频剩余播放次数缓存
-		redisUtil.set(RedisKeyHelper.audioLeftPlayCountKey(recordId),key, count);
-				
+		redisUtil.set(RedisKeyHelper.audioLeftPlayCountKey(recordId), key, count);
+
 		return count;
 	}
-	
+
+	@Override
+	public ExamFileUploadBean fileUpload(Long studentId, Long recordId, MultipartFile file, String suffix, String md5) {
+		ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
+		if (er == null) {
+			throw new BusinessException("未找到考试记录");
+		}
+		ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
+				.get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
+		if (es == null) {
+			throw new BusinessException("未找到考生");
+		}
+		if (studentId.equals(es.getStudentId())) {
+			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
+		}
+		String filePath = "upload/" + sdf.format(new Date()) + "/" + uuid() + ".json";
+		InputStream in = null;
+		try {
+			String fileMd5 = DigestUtils.md5Hex(file.getBytes());
+			if(!md5.equals(fileMd5)) {
+				throw new BusinessException("文件md5不一致");
+			}
+			in = file.getInputStream();
+			OssUtil.ossUploadStream(systemConfig.getOssEnv(3), filePath, in);
+			String url=systemConfig.getProperty("aliyun.oss.url")+"/"+filePath;
+			ExamFileUploadBean ret=new ExamFileUploadBean();
+			ret.setUrl(url);
+			ret.setUploadTime(new Date().getTime());
+			return ret;
+		} catch (IOException e) {
+			throw new BusinessException("文件读取出错");
+		} finally {
+			if (in != null) {
+				try {
+					in.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	private String uuid() {
+		return UUID.randomUUID().toString().replaceAll("-", "");
+	}
+
 }

+ 10 - 0
themis-business/src/main/java/com/qmth/themis/business/util/OssUtil.java

@@ -212,4 +212,14 @@ public class OssUtil {
         PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, path, file);
         ossClient.putObject(putObjectRequest);
     }
+    
+    public static void ossUploadStream(Map<String, Object> map, String path, InputStream inputStream) {
+        String endpoint = String.valueOf(map.get(SystemConstant.END_POINT));
+        String accessKeyId = String.valueOf(map.get(SystemConstant.ACCESS_KEY_ID));
+        String accessKeySecret = String.valueOf(map.get(SystemConstant.ACCESS_KEY_SECRET));
+        String bucketName = String.valueOf(map.get(SystemConstant.BUCKET));
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, path, inputStream);
+        ossClient.putObject(putObjectRequest);
+    }
 }

+ 22 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -10,8 +10,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.themis.business.bean.exam.ExamFileUploadBean;
 import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.bean.exam.ExamStartBean;
 import com.qmth.themis.business.constant.SystemConstant;
@@ -155,4 +157,24 @@ public class TEExamController {
 		}
 	}
 	
+	@ApiOperation(value = "文件上传")
+	@RequestMapping(value = "/file/upload", method = RequestMethod.POST)
+	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
+	public ExamFileUploadBean fileUpload(@ApiParam(value = "考试记录ID", required = true) @RequestParam Long recordId,
+			@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
+			@ApiParam(value = "后缀名", required = true) @RequestParam String suffix,
+			@ApiParam(value = "md5", required = true) @RequestParam String md5) {
+		TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
+		String lockKey = SystemConstant.REDIS_LOCK_STUDENT_PREFIX + teStudent.getId();
+		Boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
+		if (!lock) {
+			throw new BusinessException(ExceptionResultEnum.REQUEST_AWAIT);
+		}
+		try {
+			return teExamService.fileUpload(teStudent.getId(), recordId,file,suffix,md5);
+		} finally {
+			redisUtil.releaseLock(lockKey);
+		}
+	}
+	
 }