xiatian 3 maanden geleden
bovenliggende
commit
2487cda6f0

+ 30 - 14
src/main/java/cn/com/qmth/am/bean/AiMarkingDto.java

@@ -1,22 +1,38 @@
 package cn.com.qmth.am.bean;
 
+import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.entity.StudentScoreEntity;
 
 public class AiMarkingDto {
-	private StudentScoreEntity scoreInfo;
-	private Integer retry=0;
-	public StudentScoreEntity getScoreInfo() {
-		return scoreInfo;
-	}
-	public void setScoreInfo(StudentScoreEntity scoreInfo) {
-		this.scoreInfo = scoreInfo;
-	}
-	public Integer getRetry() {
-		return retry;
-	}
-	public void setRetry(Integer retry) {
-		this.retry = retry;
-	}
 
+    private StudentScoreEntity scoreInfo;
+
+    private QuestionEntity question;
+
+    private Integer retry = 0;
+
+    public StudentScoreEntity getScoreInfo() {
+        return scoreInfo;
+    }
+
+    public void setScoreInfo(StudentScoreEntity scoreInfo) {
+        this.scoreInfo = scoreInfo;
+    }
+
+    public Integer getRetry() {
+        return retry;
+    }
+
+    public void setRetry(Integer retry) {
+        this.retry = retry;
+    }
+
+    public QuestionEntity getQuestion() {
+        return question;
+    }
+
+    public void setQuestion(QuestionEntity question) {
+        this.question = question;
+    }
 
 }

+ 8 - 0
src/main/java/cn/com/qmth/am/config/InitData.java

@@ -27,6 +27,14 @@ public class InitData implements CommandLineRunner {
         if (!dataDir.exists()) {
             dataDir.mkdir();
         }
+        File dir = new File(sysProperty.getDataDir() + "/" + "slice");
+        if (!dir.exists()) {
+            dir.mkdir();
+        }
+        File sheet = new File(sysProperty.getDataDir() + "/" + "sheet");
+        if (!sheet.exists()) {
+            sheet.mkdir();
+        }
         resetTaskStatus();
     }
 

+ 4 - 0
src/main/java/cn/com/qmth/am/dao/local/StudentScoreDao.java

@@ -2,6 +2,8 @@ package cn.com.qmth.am.dao.local;
 
 import java.util.List;
 
+import org.apache.ibatis.annotations.Param;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import cn.com.qmth.am.bean.StudentScoreInfo;
@@ -11,4 +13,6 @@ public interface StudentScoreDao extends BaseMapper<StudentScoreEntity> {
 
     List<StudentScoreInfo> getAllList();
 
+    void saveSheetPath(@Param("id") Long id, @Param("sheet") String sheet);
+
 }

+ 2 - 1
src/main/java/cn/com/qmth/am/service/DsMarkingService.java

@@ -2,13 +2,14 @@ package cn.com.qmth.am.service;
 
 import cn.com.qmth.am.bean.ds.AutoScoreRequest;
 import cn.com.qmth.am.bean.ds.AutoScoreResult;
+import cn.com.qmth.am.entity.QuestionEntity;
 
 /**
  * 类注释
  */
 public interface DsMarkingService {
 
-    AutoScoreResult autoScore(AutoScoreRequest req);
+    AutoScoreResult autoScore(AutoScoreRequest req, QuestionEntity q);
 
     String ocr(String base64);
 

+ 1 - 3
src/main/java/cn/com/qmth/am/service/StudentScoreService.java

@@ -1,11 +1,9 @@
 package cn.com.qmth.am.service;
 
 import java.util.List;
-import java.util.Map;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 
-import cn.com.qmth.am.bean.AnswerImageDto;
 import cn.com.qmth.am.bean.StudentScoreImageDto;
 import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.entity.StudentScoreEntity;
@@ -18,7 +16,7 @@ public interface StudentScoreService extends IService<StudentScoreEntity> {
 
     void updateAnswerErr(Long id, String string);
 
-    void createSlice(StudentScoreEntity score, QuestionEntity q, Map<Integer, AnswerImageDto> answerImages);
+    void createSlice(StudentScoreEntity score, QuestionEntity q);
 
     void ocr(StudentScoreImageDto dto);
 

+ 1 - 4
src/main/java/cn/com/qmth/am/service/StudentService.java

@@ -1,8 +1,5 @@
 package cn.com.qmth.am.service;
 
-import java.util.Map;
-
-import cn.com.qmth.am.bean.AnswerImageDto;
 import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.entity.StudentScoreEntity;
 
@@ -15,7 +12,7 @@ public interface StudentService {
 
     void buildImage(StudentScoreEntity score, QuestionEntity quetion);
 
-    void createSlice(StudentScoreEntity score, QuestionEntity quetion, Map<Integer, AnswerImageDto> answerImages);
+    void createSlice(StudentScoreEntity score, QuestionEntity quetion);
 
     void reset(Long examId, String subjectCode);
 

+ 37 - 26
src/main/java/cn/com/qmth/am/service/impl/DsMarkingServiceImpl.java

@@ -28,6 +28,8 @@ import cn.com.qmth.am.bean.ds.MarkingReq;
 import cn.com.qmth.am.bean.ds.OcrMessage;
 import cn.com.qmth.am.bean.ds.OcrReq;
 import cn.com.qmth.am.config.SysProperty;
+import cn.com.qmth.am.entity.QuestionEntity;
+import cn.com.qmth.am.enums.PromptTemplate;
 import cn.com.qmth.am.service.DsMarkingService;
 import cn.com.qmth.am.utils.FreeMarkerUtil;
 import cn.com.qmth.am.utils.HttpMethod;
@@ -96,8 +98,8 @@ public class DsMarkingServiceImpl implements DsMarkingService {
     // }
 
     @Override
-    public AutoScoreResult autoScore(AutoScoreRequest request) {
-        String question = FreeMarkerUtil.getDsMarkingReq(request);
+    public AutoScoreResult autoScore(AutoScoreRequest request, QuestionEntity q) {
+        String question = FreeMarkerUtil.getMarkingReq(request, q.getPromptTemplate());
         MarkingReq dreq = new MarkingReq(sysProperty.getMarkingModel());
         dreq.addMsg(ChatRole.user, question);
         String res = marking(dreq);
@@ -105,31 +107,40 @@ public class DsMarkingServiceImpl implements DsMarkingService {
         try {
             String text = result.getMessage().getContent();
             AutoScoreResult scoreResult = new AutoScoreResult();
-            // 依据总分与步骤分计算最大精度
-            int scale = Math.max(getDecimalPlaces(request.getIntervalScore()),
-                    getDecimalPlaces(request.getTotalScore()));
-            int stepCount = request.getStandardAnswer().size();
-            String scoreStr = null;
-            if (stepCount > 1) {
-                scoreStr = fomatStrByRex(text);
-            } else {
-                scoreStr = fomatStr(text);
-            }
-            String[] scores = StringUtils.split(scoreStr, ",");
-            double[] scoreArray = new double[stepCount];
-            for (int i = 0; i < stepCount; i++) {
+            if (PromptTemplate.COMMON.equals(q.getPromptTemplate())) {
+                // 依据总分与步骤分计算最大精度
+                int scale = Math.max(getDecimalPlaces(request.getIntervalScore()),
+                        getDecimalPlaces(request.getTotalScore()));
+                int stepCount = request.getStandardAnswer().size();
+                String scoreStr = null;
+                if (stepCount > 1) {
+                    scoreStr = fomatStrByRex(text);
+                } else {
+                    scoreStr = fomatStr(text);
+                }
+                String[] scores = StringUtils.split(scoreStr, ",");
+                double[] scoreArray = new double[stepCount];
+                for (int i = 0; i < stepCount; i++) {
+                    // 根据得分率与步骤总分计算实际得分,按最大精度保留小数位数
+                    double score = BigDecimal
+                            .valueOf(Math.min(Integer.parseInt(scores[i].trim()), 100)
+                                    * request.getStandardAnswer().get(i).getScore())
+                            .divide(BigDecimal.valueOf(100), scale, RoundingMode.HALF_UP).doubleValue();
+                    scoreArray[i] = score;
+                }
+                scoreResult.setStepScore(scoreArray);
+                scoreResult.setTotalScore(Arrays.stream(scoreArray).mapToObj(BigDecimal::new)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
+            } else if (PromptTemplate.TRANSLATION.equals(q.getPromptTemplate())) {
+                String scoreStr = fomatStr(text);
+                double[] scoreArray = new double[1];
                 // 根据得分率与步骤总分计算实际得分,按最大精度保留小数位数
-                double score = BigDecimal
-                        .valueOf(Math.min(Integer.parseInt(scores[i].trim()), 100)
-                                * request.getStandardAnswer().get(i).getScore())
-                        .divide(BigDecimal.valueOf(100), scale, RoundingMode.HALF_UP).doubleValue();
-                scoreArray[i] = score;
-            }
-            scoreResult.setStepScore(scoreArray);
-            scoreResult.setTotalScore(Arrays.stream(scoreArray).mapToObj(BigDecimal::new)
-                    .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
-            if ((scoreResult.getTotalScore() + "").length() > 4) {
-                log.error(" | " + res);
+                double score = Double.valueOf(scoreStr);
+                scoreArray[0] = score;
+                scoreResult.setStepScore(scoreArray);
+                scoreResult.setTotalScore(score);
+            } else {
+                throw new RuntimeException("模版类型错误");
             }
             return scoreResult;
         } catch (Exception e) {

+ 92 - 70
src/main/java/cn/com/qmth/am/service/impl/StudentScoreServiceImpl.java

@@ -1,8 +1,13 @@
 package cn.com.qmth.am.service.impl;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -16,15 +21,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.concurrent.service.ConcurrentService;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.retrofit.exception.RetrofitResponseError;
-import com.qmth.boot.core.solar.model.OrgInfo;
-import com.qmth.boot.core.solar.service.SolarService;
 import com.qmth.boot.tools.models.ByteArray;
 
 import cn.com.qmth.am.bean.AiMarkingDto;
@@ -53,10 +58,10 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
     private static final Logger log = LoggerFactory.getLogger(StudentScoreService.class);
 
     @Autowired
-    private SysProperty sysProperty;
+    private ConcurrentService concurrentService;
 
     @Autowired
-    private SolarService solarService;
+    private SysProperty sysProperty;
 
     @Autowired
     private DsMarkingService dsMarkingService;
@@ -122,24 +127,25 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 
     @Transactional
     @Override
-    public void createSlice(StudentScoreEntity score, QuestionEntity q, Map<Integer, AnswerImageDto> answerImages) {
+    public void createSlice(StudentScoreEntity score, QuestionEntity q) {
         StudentScoreImageDto dto = new StudentScoreImageDto();
         dto.setStudentScoreId(score.getId());
-        getSlice(score, q, answerImages, dto);
-        // saveSliceImage(score, dto.getImage());
+        getSlice(score, q, dto);
         ocr(dto);
+        saveSliceImage(q, score, dto.getImage());
     }
 
-    private void getSlice(StudentScoreEntity score, QuestionEntity q, Map<Integer, AnswerImageDto> answerImages,
-            StudentScoreImageDto dto) {
+    private void getSlice(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
         List<byte[]> ret = new ArrayList<>();
         String suff = null;
+        Map<Integer, AnswerImageDto> answerImages = new LinkedHashMap<>();
         for (ImageSlice s : q.getImageSlice()) {
             AnswerImageDto sheet = getSheet(score, q, s.getI(), answerImages);
             suff = sheet.getSuff();
             ret.add(ImageUtil.cutImage(sheet.getImage(), sheet.getSuff(), s.getX().intValue(), s.getY().intValue(),
                     s.getW().intValue(), s.getH().intValue()));
         }
+        saveSheetImage(q, score, answerImages);
         dto.setSuff(suff);
         if (ret.size() > 1) {
             dto.setImage(ImageUtil.joinImages(ret, suff));
@@ -161,7 +167,6 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
             String tem = url.split("\\?")[0];
             String suff = tem.substring(tem.lastIndexOf(".") + 1).toLowerCase();
             ret.setImage(ByteArray.fromUrl(url).value());
-            // saveSheetImage(score,pageIndex, ret.getImage());
             ret.setPageIndex(pageIndex);
             ret.setSuff(suff);
             answerImages.put(pageIndex, ret);
@@ -170,57 +175,75 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
             throw new RuntimeException(e);
         }
     }
-    // private void saveSheetImage(StudentScoreEntity s,Integer page,byte[] bs)
-    // {
-    // File dir=new File(sysProperty.getDataDir()+"/"+"sheet");
-    // if(!dir.exists()) {
-    // dir.mkdir();
-    // }
-    // File image=new
-    // File(dir.getAbsolutePath()+"/"+s.getStudentCode()+"-"+page+".jpg");
-    // if(image.exists()) {
-    // image.delete();
-    // }
-    // FileOutputStream out=null;
-    // try {
-    // out = new FileOutputStream(image);
-    // out.write(bs, 0, bs.length);
-    // out.flush();
-    // } catch (Exception e) {
-    // }finally {
-    // if(out!=null) {
-    // try {
-    // out.close();
-    // } catch (IOException e) {
-    // }
-    // }
-    // }
-    // }
-    // private void saveSliceImage(StudentScoreEntity s,byte[] bs) {
-    // File dir=new File(sysProperty.getDataDir()+"/"+"slice");
-    // if(!dir.exists()) {
-    // dir.mkdir();
-    // }
-    // File image=new
-    // File(dir.getAbsolutePath()+"/"+s.getStudentCode()+"-"+s.getMainNumber()+"-"+s.getSubNumber()+".jpg");
-    // if(image.exists()) {
-    // image.delete();
-    // }
-    // FileOutputStream out=null;
-    // try {
-    // out = new FileOutputStream(image);
-    // out.write(bs, 0, bs.length);
-    // out.flush();
-    // } catch (Exception e) {
-    // }finally {
-    // if(out!=null) {
-    // try {
-    // out.close();
-    // } catch (IOException e) {
-    // }
-    // }
-    // }
-    // }
+
+    private void saveSheetImage(QuestionEntity q, StudentScoreEntity s, Map<Integer, AnswerImageDto> answerImages) {
+        List<String> ss = new ArrayList<>();
+        for (AnswerImageDto ims : answerImages.values()) {
+            String path = "sheet/" + q.getExamId() + "/" + q.getSubjectCode() + "/" + q.getMainNumber() + "/"
+                    + q.getSubNumber() + "/" + s.getExamNumber() + "-" + ims.getPageIndex() + ".jpg";
+            ss.add(path);
+            File image = new File(sysProperty.getDataDir() + "/" + path);
+            if (image.exists()) {
+                continue;
+            }
+            boolean lock = concurrentService.getReadWriteLock(path).writeLock().tryLock();
+            if (lock) {
+                FileOutputStream out = null;
+                try {
+                    if (image.exists()) {
+                        continue;
+                    }
+                    byte[] bs = Arrays.copyOf(ims.getImage(), ims.getImage().length);
+                    out = new FileOutputStream(image);
+                    out.write(bs, 0, bs.length);
+                    out.flush();
+                } catch (Exception e) {
+                } finally {
+                    concurrentService.getReadWriteLock(path).writeLock().unlock();
+                    if (out != null) {
+                        try {
+                            out.close();
+                        } catch (IOException e) {
+                        }
+                    }
+                }
+            }
+        }
+        this.baseMapper.saveSheetPath(s.getId(), JSONArray.toJSONString(ss));
+    }
+
+    private void saveSliceImage(QuestionEntity q, StudentScoreEntity s, byte[] imageByte) {
+        String path = "slice/" + q.getExamId() + "/" + q.getSubjectCode() + "/" + q.getMainNumber() + "/"
+                + q.getSubNumber() + "/" + s.getExamNumber() + ".jpg";
+        updateSlice(s.getId(), path);
+        File image = new File(sysProperty.getDataDir() + "/" + path);
+        if (image.exists()) {
+            image.delete();
+        }
+        FileOutputStream out = null;
+        try {
+            byte[] bs = Arrays.copyOf(imageByte, imageByte.length);
+            out = new FileOutputStream(image);
+            out.write(bs, 0, bs.length);
+            out.flush();
+        } catch (Exception e) {
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    private void updateSlice(Long id, String path) {
+        UpdateWrapper<StudentScoreEntity> wrapper = new UpdateWrapper<>();
+        LambdaUpdateWrapper<StudentScoreEntity> lw = wrapper.lambda();
+        lw.set(StudentScoreEntity::getSlice, path);
+        lw.eq(StudentScoreEntity::getId, id);
+        this.update(wrapper);
+    }
 
     private String getImageUrl(StudentScoreEntity score, QuestionEntity q, Integer pageIndex) {
         return getImageUrlFromMarkingCloud(score, q, pageIndex);
@@ -279,8 +302,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
     @Override
     public void ocr(StudentScoreImageDto dto) {
         try {
-            OrgInfo org = solarService.getOrgList().get(0);
-            String ret = ocrDispose(dto, org);
+            String ret = ocrDispose(dto);
             if (ret != null) {
                 updateAnswer(dto.getStudentScoreId(), ret);
             } else {
@@ -301,7 +323,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
         this.update(wrapper);
     }
 
-    private String ocrDispose(StudentScoreImageDto dto, OrgInfo org) {
+    private String ocrDispose(StudentScoreImageDto dto) {
         try {
             String base64 = FileUtil.byteToBase64(dto.getImage(), dto.getSuff());
             String ret = dsMarkingService.ocr(base64);
@@ -318,7 +340,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
                         } catch (InterruptedException e1) {
                         }
                         dto.setRetry(dto.getRetry() + 1);
-                        return ocrDispose(dto, org);
+                        return ocrDispose(dto);
                     } else {
                         throw new StatusException("重试次数过多");
                     }
@@ -369,7 +391,6 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
         AiMarkingDto dto = new AiMarkingDto();
         dto.setScoreInfo(score);
         try {
-            OrgInfo org = solarService.getOrgList().get(0);
             QuestionEntity q = questionService.getById(score.getQuestionId());
             if (q == null) {
                 throw new StatusException("未找到试题信息");
@@ -377,6 +398,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
             if (CollectionUtils.isEmpty(q.getAnswer())) {
                 return;
             }
+            dto.setQuestion(q);
             AutoScoreEnRequest req = new AutoScoreEnRequest();
             req.setQuestionBody(q.getContent());
             req.setStandardAnswer(q.getAnswer());
@@ -385,7 +407,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
             req.setTotalScore(q.getFullScore());
             req.setIntervalScore(0.1);
             req.setQuestionTitle(q.getTitle());
-            AutoScoreResult ret = aiMarkingDispose(dto, org, req);
+            AutoScoreResult ret = aiMarkingDispose(dto, req);
             if (ret != null) {
                 updateScore(score.getId(), ret.getTotalScore());
             } else {
@@ -396,9 +418,9 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
         }
     }
 
-    private AutoScoreResult aiMarkingDispose(AiMarkingDto dto, OrgInfo org, AutoScoreEnRequest req) {
+    private AutoScoreResult aiMarkingDispose(AiMarkingDto dto, AutoScoreEnRequest req) {
         try {
-            return dsMarkingService.autoScore(req);
+            return dsMarkingService.autoScore(req, dto.getQuestion());
         } catch (Exception e) {
             log.error("aiScore异常", e);
             if (e instanceof RetrofitResponseError) {
@@ -410,7 +432,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
                         } catch (InterruptedException e1) {
                         }
                         dto.setRetry(dto.getRetry() + 1);
-                        return aiMarkingDispose(dto, org, req);
+                        return aiMarkingDispose(dto, req);
                     } else {
                         throw new StatusException("重试次数过多");
                     }

+ 3 - 7
src/main/java/cn/com/qmth/am/service/impl/StudentServiceImpl.java

@@ -1,8 +1,6 @@
 package cn.com.qmth.am.service.impl;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
@@ -13,7 +11,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.qmth.boot.core.exception.StatusException;
 
-import cn.com.qmth.am.bean.AnswerImageDto;
 import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.entity.StudentScoreEntity;
 import cn.com.qmth.am.enums.DataStatus;
@@ -64,20 +61,19 @@ public class StudentServiceImpl implements StudentService {
 
     @Override
     public void buildImage(StudentScoreEntity score, QuestionEntity quetion) {
-        Map<Integer, AnswerImageDto> answerImages = new HashMap<>();
         if (DataStatus.WAITING.equals(score.getAnswerStatus()) || DataStatus.FAILED.equals(score.getAnswerStatus())) {
-            studentService.createSlice(score, quetion, answerImages);
+            studentService.createSlice(score, quetion);
         }
     }
 
     @Override
-    public void createSlice(StudentScoreEntity score, QuestionEntity q, Map<Integer, AnswerImageDto> answerImages) {
+    public void createSlice(StudentScoreEntity score, QuestionEntity q) {
         if (q == null) {
             studentScoreService.updateAnswerErr(score.getId(), "未找到试题信息");
             return;
         }
         try {
-            studentScoreService.createSlice(score, q, answerImages);
+            studentScoreService.createSlice(score, q);
         } catch (Exception e) {
             if (e instanceof StatusException) {
                 studentScoreService.updateAnswerErr(score.getId(), e.getMessage());

+ 15 - 11
src/main/java/cn/com/qmth/am/utils/FreeMarkerUtil.java

@@ -1,9 +1,13 @@
 package cn.com.qmth.am.utils;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
 
 import cn.com.qmth.am.bean.ds.AutoScoreRequest;
+import cn.com.qmth.am.enums.PromptTemplate;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 
@@ -11,30 +15,30 @@ public class FreeMarkerUtil {
 
     private static final String ENCODING = "UTF-8";
 
-    private static Configuration config;
+    private static Configuration cfg;
 
-    private static Template dsMarkingReq;
+    private static Map<PromptTemplate, Template> ts = new HashMap<>();
 
     static {
 
-        config = new Configuration(Configuration.VERSION_2_3_25);
-        // 设置编码
-        config.setDefaultEncoding(ENCODING);
-        // 设置ftl模板路径
-        config.setClassForTemplateLoading(FreeMarkerUtil.class, "/templates/");
-
         try {
-            dsMarkingReq = config.getTemplate("ds_marking.ftl", ENCODING);
+            cfg = new Configuration(Configuration.VERSION_2_3_25);
+            // 设置编码
+            cfg.setDefaultEncoding(ENCODING);
+            cfg.setDirectoryForTemplateLoading(new File("./templates"));
+            for (PromptTemplate p : PromptTemplate.values()) {
+                ts.put(p, cfg.getTemplate(p.getCode()));
+            }
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
 
-    public static String getDsMarkingReq(AutoScoreRequest req) {
+    public static String getMarkingReq(AutoScoreRequest req, PromptTemplate p) {
         StringWriter result = null;
         try {
             result = new StringWriter();
-            dsMarkingReq.process(req, result);
+            ts.get(p).process(req, result);
             return result.toString();
         } catch (Exception e) {
             throw new RuntimeException(e);

+ 5 - 0
src/main/resources/mapper/StudentScoreMapper.xml

@@ -4,4 +4,9 @@
 	<select id="getAllList" resultType="cn.com.qmth.am.bean.StudentScoreInfo">
 		select t.question_id,t.exam_number from am_student_score t
 	</select>
+	
+	<update id="saveSheetPath">
+		update am_student_score t set t.sheet=#{sheet} where t.id=#{id}
+	</update>
+	
 </mapper>

+ 0 - 0
src/main/resources/templates/common.ftl → templates/common.ftl


+ 0 - 0
src/main/resources/templates/translation.ftl → templates/translation.ftl