【新增】生成笔试试卷,细节修改
This commit is contained in:
@@ -127,7 +127,61 @@
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
|
||||
</dependency>
|
||||
<!-- Apache POI 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-base</artifactId>
|
||||
<version>4.4.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-imaging</artifactId>
|
||||
<version>1.0-alpha3</version> <!-- 使用最新版本 -->
|
||||
</dependency>
|
||||
<!-- Adobe 官方 XMPCore 库 -->
|
||||
<dependency>
|
||||
<groupId>com.adobe.xmp</groupId>
|
||||
<artifactId>xmpcore</artifactId>
|
||||
<version>6.1.11</version> <!-- 最新稳定版 -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@@ -123,12 +123,12 @@ public class EducationPaperController
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据方案获取试卷
|
||||
* 根据方案获取试卷下拉
|
||||
*/
|
||||
@GetMapping(value = "/getPaperByTaskId")
|
||||
public CommonResult getPaperByTaskId(@RequestParam(value = "taskId") String taskId)
|
||||
{
|
||||
return CommonResult.success(educationPaperService.selectPaperByTaskId(taskId));
|
||||
return CommonResult.success(educationPaperService.selectPaperIdAndNumByTaskId(taskId));
|
||||
}
|
||||
|
||||
|
||||
@@ -216,4 +216,17 @@ public class EducationPaperController
|
||||
return CommonResult.success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载试卷
|
||||
* @param paperIds
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/addUpload/{paperIds}")
|
||||
public void downLoad(@PathVariable String[] paperIds, HttpServletResponse response) throws Exception {
|
||||
educationPaperService.downloadWord(paperIds,response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.paper.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PaperIdAndNum {
|
||||
private String num;
|
||||
private String paperId;
|
||||
}
|
@@ -73,6 +73,11 @@ public class EducationPaperScheme
|
||||
// @Excel(name = "小计分数")
|
||||
private String subtotalScore;
|
||||
|
||||
/**
|
||||
* 试卷呆鹅题号
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String upperCase;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package pc.exam.pp.module.exam.dal.mysql.paper;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -9,6 +10,7 @@ import pc.exam.pp.framework.common.pojo.PageResult;
|
||||
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperIdAndNum;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
|
||||
@@ -93,7 +95,7 @@ public interface EducationPaperMapper extends BaseMapperX<EducationPaper>
|
||||
|
||||
String selectTaskIdByPaperId(String paperId);
|
||||
|
||||
List<String> selectPaperByTaskId(String taskId);
|
||||
List<String> selectPaperByTaskId(String taskId);
|
||||
|
||||
public int updateEducationByids(@Param("strings")List<String> strings);
|
||||
|
||||
@@ -129,5 +131,8 @@ public interface EducationPaperMapper extends BaseMapperX<EducationPaper>
|
||||
.eq(EducationPaper::getStatus, 0)
|
||||
);
|
||||
}
|
||||
|
||||
List<PaperIdAndNum> selectPaperIdAndNumByTaskId(String taskId);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package pc.exam.pp.module.exam.service.paper;
|
||||
|
||||
|
||||
import cn.afterturn.easypoi.word.WordExportUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -9,6 +12,7 @@ import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
|
||||
import pc.exam.pp.framework.tenant.core.context.TenantContextHolder;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperIdAndNum;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.ExamPaperVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.StuInfoPaper;
|
||||
@@ -18,6 +22,10 @@ import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.SysFileMapper;
|
||||
import pc.exam.pp.module.exam.utils.uuid.IdUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.sql.Time;
|
||||
import java.util.*;
|
||||
|
||||
import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
@@ -456,6 +464,70 @@ public class EducationPaperServiceImpl implements IEducationPaperService
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadWord(String[] paperIds, HttpServletResponse response) throws Exception {
|
||||
|
||||
String paperId1 = paperIds[0];
|
||||
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(paperId1);
|
||||
String taskId = educationPaper.getTaskId();
|
||||
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
|
||||
List<EducationPaperScheme> educationPaperSchemes = educationPaperSchemeMapper.selectEducationPaperTaskByTaskId(taskId);
|
||||
|
||||
String[] chineseNumbers = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"};
|
||||
|
||||
for (int i = 0; i < educationPaperSchemes.size(); i++) {
|
||||
if (i < chineseNumbers.length) {
|
||||
educationPaperSchemes.get(i).setUpperCase((chineseNumbers[i]));
|
||||
} else {
|
||||
// 超过十个后可以追加逻辑,比如用“第十一”、“第十二”……
|
||||
educationPaperSchemes.get(i).setUpperCase("第" + (i + 1) + "项");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取模板文档
|
||||
String wordpath="/word/试卷1.docx";
|
||||
String homeDir = System.getProperty("user.dir");
|
||||
String wordrealpath=homeDir +wordpath;
|
||||
File realPath = new File(wordrealpath);
|
||||
//准备数据
|
||||
Map<String,Object> params =new HashMap<>();
|
||||
|
||||
params.put("paperNum",educationPaper.getNum());
|
||||
//获得考试时常
|
||||
Time time = educationPaperParam.getExamTime();
|
||||
int hours = time.getHours();
|
||||
int minutes = time.getMinutes();
|
||||
int totalMinutes = hours * 60 + minutes;
|
||||
|
||||
|
||||
|
||||
params.put("paperTime",totalMinutes);
|
||||
params.put("paperScore",educationPaper.getPaperScore());
|
||||
params.put("Schemes",educationPaperSchemes);
|
||||
XWPFDocument word = WordExportUtil.exportWord07(realPath.getPath(),params);
|
||||
System.out.println("wordxwpdf"+word);
|
||||
String filename = educationPaper.getNum()+".docx";
|
||||
|
||||
response.setHeader("Content-disposition","attachment;filename:"+new String(filename.getBytes(),"UTF-8"));
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
|
||||
|
||||
try {
|
||||
System.out.println("文件"+filename);
|
||||
word.write(response.getOutputStream());
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("错误"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PaperIdAndNum> selectPaperIdAndNumByTaskId(String taskId) {
|
||||
return educationPaperMapper.selectPaperIdAndNumByTaskId(taskId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,14 +1,18 @@
|
||||
package pc.exam.pp.module.exam.service.paper;
|
||||
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import pc.exam.pp.framework.common.pojo.PageResult;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperIdAndNum;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.ExamPaperVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.PaperListResponseVo;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 试卷Service接口
|
||||
@@ -92,5 +96,11 @@ public interface IEducationPaperService
|
||||
PageResult<EducationPaperStuDto> selectStuEducationPaperList(PaperPageVo paperPageVo);
|
||||
|
||||
ExamPaperVo stuInfoPaper(String taskid);
|
||||
|
||||
void downloadWord(String[] paperIds, HttpServletResponse response) throws Exception;
|
||||
|
||||
|
||||
List<PaperIdAndNum> selectPaperIdAndNumByTaskId(String taskId);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,11 @@
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="EducationPaper" id="PaperIdAndNumResult">
|
||||
<result property="paperId" column="paper_id" />
|
||||
<result property="num" column="num" />
|
||||
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="ExamQuestion" id="ExamQuestionResult">
|
||||
<result property="quId" column="qu_id" />
|
||||
@@ -119,6 +124,9 @@ select task_id from education_paper where paper_id=#{paperId}
|
||||
<select id="selectCountPaperList" resultType="java.lang.Integer">
|
||||
select count(*) from education_paper
|
||||
</select>
|
||||
<select id="selectPaperIdAndNumByTaskId" resultMap="PaperIdAndNumResult">
|
||||
select paper_id ,num from education_paper where task_id=#{taskId} and deleted ='0'
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertEducationPaper" parameterType="EducationPaper">
|
||||
|
@@ -42,7 +42,7 @@
|
||||
where scheme_id = #{schemeId}
|
||||
</select>
|
||||
<select id="selectEducationPaperTaskByTaskId" resultMap="EducationPaperSchemeResult">
|
||||
select * from education_paper_scheme where task_id =#{taskid}
|
||||
select * from education_paper_scheme where task_id =#{taskid} order by sort asc
|
||||
</select>
|
||||
|
||||
<insert id="insertEducationPaperScheme" parameterType="EducationPaperScheme">
|
||||
|
Reference in New Issue
Block a user