|
@@ -720,7 +720,7 @@ public class CollectApi {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 导出图片
|
|
|
|
|
|
+ * 分数图片导出
|
|
*
|
|
*
|
|
* @param imageType
|
|
* @param imageType
|
|
* @param areaId
|
|
* @param areaId
|
|
@@ -730,23 +730,20 @@ public class CollectApi {
|
|
* @param nameRule 1:考号+姓名,2:流水号
|
|
* @param nameRule 1:考号+姓名,2:流水号
|
|
* @param startScore
|
|
* @param startScore
|
|
* @param endScore
|
|
* @param endScore
|
|
- * @param request
|
|
|
|
- * @param response
|
|
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- @RequestMapping(value = "file/image/export", method = {RequestMethod.GET})
|
|
|
|
- public String imageExamNumberExport(@RequestParam Long workId,
|
|
|
|
- @RequestParam String imageType,
|
|
|
|
- @RequestParam Long areaId,
|
|
|
|
- @RequestParam String school,
|
|
|
|
- @RequestParam String examRoom,
|
|
|
|
- @RequestParam String subject,
|
|
|
|
- @RequestParam String nameRule,
|
|
|
|
- @RequestParam Integer startScore,
|
|
|
|
- @RequestParam Integer endScore,
|
|
|
|
- HttpServletRequest request,
|
|
|
|
- HttpServletResponse response) throws IOException {
|
|
|
|
|
|
+ @RequestMapping(value = "file/image/exportScorePictures", method = {RequestMethod.GET})
|
|
|
|
+ public String exportScorePictures(@RequestParam(defaultValue = "分数图片") String exportType,
|
|
|
|
+ @RequestParam Long workId,
|
|
|
|
+ @RequestParam String imageType,
|
|
|
|
+ @RequestParam Long areaId,
|
|
|
|
+ @RequestParam String school,
|
|
|
|
+ @RequestParam String examRoom,
|
|
|
|
+ @RequestParam String subject,
|
|
|
|
+ @RequestParam String nameRule,
|
|
|
|
+ @RequestParam Integer startScore,
|
|
|
|
+ @RequestParam Integer endScore) throws IOException {
|
|
if (StringUtils.isBlank(imageType)) {
|
|
if (StringUtils.isBlank(imageType)) {
|
|
throw new RuntimeException("请选择图片类型");
|
|
throw new RuntimeException("请选择图片类型");
|
|
}
|
|
}
|
|
@@ -773,11 +770,15 @@ public class CollectApi {
|
|
if (StringUtils.isNotBlank(examRoom)) {
|
|
if (StringUtils.isNotBlank(examRoom)) {
|
|
sql.append(" and s.exam_room = '").append(examRoom).append("'");
|
|
sql.append(" and s.exam_room = '").append(examRoom).append("'");
|
|
}
|
|
}
|
|
- if (startScore != null) {
|
|
|
|
- sql.append(" and p.score > ").append(startScore);
|
|
|
|
|
|
+ if (startScore != null && endScore != null) {
|
|
|
|
+ sql.append(" and p.score >= ").append(startScore);
|
|
|
|
+ sql.append(" and p.score <= ").append(endScore);
|
|
|
|
+ }
|
|
|
|
+ if (startScore != null && endScore == null) {
|
|
|
|
+ sql.append(" and p.score = ").append(startScore);
|
|
}
|
|
}
|
|
- if (startScore != null) {
|
|
|
|
- sql.append(" and p.score < ").append(endScore);
|
|
|
|
|
|
+ if (startScore == null && endScore != null) {
|
|
|
|
+ sql.append(" and p.score = ").append(endScore);
|
|
}
|
|
}
|
|
List<Map<String, Object>> paperList = jdbcTemplate.queryForList(sql.toString());
|
|
List<Map<String, Object>> paperList = jdbcTemplate.queryForList(sql.toString());
|
|
AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
@@ -798,16 +799,33 @@ public class CollectApi {
|
|
String path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject1
|
|
String path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject1
|
|
+ File.separator + areaCode;
|
|
+ File.separator + areaCode;
|
|
File file = new File(path + File.separator + fileName + ".jpg");
|
|
File file = new File(path + File.separator + fileName + ".jpg");
|
|
- //todo 图片存放路径要改 2020-08-08
|
|
|
|
- String exportDir = systemConfig.getLocalhostPath() + File.separator + "export" + File.separator + workId + File.separator + subject
|
|
|
|
- + File.separator + areaCode;
|
|
|
|
|
|
+ //组装导出目录
|
|
|
|
+ StringJoiner expSj = new StringJoiner(File.separator);
|
|
|
|
+ expSj.add(systemConfig.getLocalhostPath()).add("图片导出").add(exportType).add(String.valueOf(workId)).add(subject);
|
|
|
|
+ if (areaId != null) {
|
|
|
|
+ expSj.add(String.valueOf(areaId));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(school)) {
|
|
|
|
+ expSj.add(school);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(examRoom)) {
|
|
|
|
+ expSj.add(examRoom);
|
|
|
|
+ }
|
|
//原图或者水印图
|
|
//原图或者水印图
|
|
if (Objects.equals("1", imageType)) {
|
|
if (Objects.equals("1", imageType)) {
|
|
- exportDir = exportDir + File.separator + "sheet";
|
|
|
|
|
|
+ expSj.add("sheet");
|
|
} else if (Objects.equals("2", imageType)) {
|
|
} else if (Objects.equals("2", imageType)) {
|
|
- exportDir = exportDir + File.separator + "watermark";
|
|
|
|
|
|
+ expSj.add("watermark");
|
|
}
|
|
}
|
|
- File out = new File(exportDir);
|
|
|
|
|
|
+ //分数
|
|
|
|
+ if(startScore != null && endScore != null){
|
|
|
|
+ expSj.add(startScore + "-" + endScore);
|
|
|
|
+ } else if(startScore != null && endScore == null){
|
|
|
|
+ expSj.add(startScore.toString());
|
|
|
|
+ }else if(startScore == null && endScore != null){
|
|
|
|
+ expSj.add(endScore.toString());
|
|
|
|
+ }
|
|
|
|
+ File out = new File(expSj.toString());
|
|
if (!out.exists()) {
|
|
if (!out.exists()) {
|
|
out.mkdirs();
|
|
out.mkdirs();
|
|
}
|
|
}
|
|
@@ -822,7 +840,7 @@ public class CollectApi {
|
|
} else {
|
|
} else {
|
|
throw new RuntimeException("命名参数有误");
|
|
throw new RuntimeException("命名参数有误");
|
|
}
|
|
}
|
|
- File expFile = new File(exportDir + File.separator + outFileName + ".jpg");
|
|
|
|
|
|
+ File expFile = new File(expSj.toString() + File.separator + outFileName + ".jpg");
|
|
//水印图片
|
|
//水印图片
|
|
if (Objects.equals("1", imageType)) {
|
|
if (Objects.equals("1", imageType)) {
|
|
//读取指定路径下面的文件
|
|
//读取指定路径下面的文件
|
|
@@ -863,8 +881,118 @@ public class CollectApi {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 图片解密、重命名导出
|
|
|
|
+ *
|
|
|
|
+ * @param imageType
|
|
|
|
+ * @param areaId
|
|
|
|
+ * @param subject
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "file/image/exportDecryptPictures", method = {RequestMethod.GET})
|
|
|
|
+ public String exportDecryptPictures(@RequestParam(defaultValue = "图片解密") String exportType,
|
|
|
|
+ @RequestParam Long workId,
|
|
|
|
+ @RequestParam String imageType,
|
|
|
|
+ @RequestParam Long areaId,
|
|
|
|
+ @RequestParam String subject) throws IOException {
|
|
|
|
+ if (StringUtils.isBlank(imageType)) {
|
|
|
|
+ throw new RuntimeException("请选择图片类型");
|
|
|
|
+ }
|
|
|
|
+ if (areaId == null) {
|
|
|
|
+ throw new RuntimeException("请选择考点");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(subject)) {
|
|
|
|
+ throw new RuntimeException("请选择科目");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ OutputStream outputStream = null;
|
|
|
|
+ int count = 0;
|
|
|
|
+ try {
|
|
|
|
+ //首先根据workId和阶段去查所有试卷
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append("SELECT s.id studentId, p.work_id workId, p.subject, p.area_code areaCode, p.exam_number examNumber FROM paper p LEFT JOIN student s ON p.work_id = s.work_id AND p.exam_number = s.exam_number WHERE p.score is not null and p.work_id = ").append(workId).append(" AND p.subject = '").append(subject).append("'");
|
|
|
|
+ if (areaId != null) {
|
|
|
|
+ sql.append(" and p.area_code = ").append(areaId);
|
|
|
|
+ }
|
|
|
|
+ List<Map<String, Object>> paperList = jdbcTemplate.queryForList(sql.toString());
|
|
|
|
+ for (Map map : paperList) {
|
|
|
|
+ Long studentId = Long.valueOf(map.get("studentId").toString());
|
|
|
|
+ String subject0 = map.get("subject").toString();
|
|
|
|
+ Subject subject1 = Subject.valueOf(subject0);
|
|
|
|
+ String areaCode = map.get("areaCode").toString();
|
|
|
|
+ String examNumber = map.get("examNumber").toString();
|
|
|
|
+
|
|
|
|
+ String fileName = examNumber;
|
|
|
|
+ //图片加密、命名规则为随机码的,都是需要md5
|
|
|
|
+ if (ParamCache.paramMap.get(workId).getNameRule() == 1 || ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
|
+ fileName = MD5Util.getImageRuleMd5(workId, subject1.ordinal(), areaCode, examNumber, studentId);
|
|
|
|
+ }
|
|
|
|
+ String path;
|
|
|
|
+ if(Objects.equals("1", imageType)){
|
|
|
|
+ path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
|
|
+ + File.separator + areaCode;
|
|
|
|
+ } else if (Objects.equals("2", imageType)){
|
|
|
|
+ path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
|
|
+ + File.separator + areaCode;
|
|
|
|
+ } else {
|
|
|
|
+ throw new Exception("图片类型有误");
|
|
|
|
+ }
|
|
|
|
+ File file = new File(path + File.separator + fileName + ".jpg");
|
|
|
|
+ //组装导出目录
|
|
|
|
+ StringJoiner expSj = new StringJoiner(File.separator);
|
|
|
|
+ expSj.add(systemConfig.getLocalhostPath()).add("图片导出").add(exportType).add(String.valueOf(workId)).add(subject);
|
|
|
|
+ if (areaId != null) {
|
|
|
|
+ expSj.add(String.valueOf(areaId));
|
|
|
|
+ }
|
|
|
|
+ //原图或者裁剪图
|
|
|
|
+ if (Objects.equals("1", imageType)) {
|
|
|
|
+ expSj.add("sheet");
|
|
|
|
+ } else if (Objects.equals("2", imageType)) {
|
|
|
|
+ expSj.add("images");
|
|
|
|
+ }
|
|
|
|
+ File out = new File(expSj.toString());
|
|
|
|
+ if (!out.exists()) {
|
|
|
|
+ out.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ File expFile = new File(expSj.toString() + File.separator + examNumber + ".jpg");
|
|
|
|
+ //水印图片
|
|
|
|
+ //读取指定路径下面的文件
|
|
|
|
+ inputStream = new FileInputStream(file);
|
|
|
|
+ outputStream = new FileOutputStream(expFile);
|
|
|
|
+ if (ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
|
+ outputStream = SystemConstant.writeStream(inputStream, outputStream);
|
|
|
|
+ } else {
|
|
|
|
+ outputStream = SystemConstant.writeStreamFomal(inputStream, outputStream);
|
|
|
|
+ }
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ count++;
|
|
|
|
+
|
|
|
|
+ LOGGER.info("studentId:{},subjdect:{},md5:{}", studentId, subject1, fileName);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ //强制将缓存区的数据进行输出
|
|
|
|
+ if (Objects.nonNull(outputStream)) {
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ //关流
|
|
|
|
+ outputStream.close();
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(inputStream)) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return "导出照片成功,共导出了" + count + "张照片";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 生成分数水印图片
|
|
* 生成分数水印图片
|
|
|
|
+ *
|
|
* @param str
|
|
* @param str
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|