优化
This commit is contained in:
		| @ -0,0 +1,64 @@ | ||||
| package com.ruoyi.wgz.bo; | ||||
|  | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalTime; | ||||
| import java.time.LocalDate; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| import com.ruoyi.common.core.domain.BaseEntity; | ||||
|  | ||||
| /** | ||||
|  * 用户试卷存储pdf分页查询对象 wgz_question_save_pdf | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  * @date 2025-03-26 | ||||
|  */ | ||||
|  | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ApiModel("用户试卷存储pdf分页查询对象") | ||||
| public class WgzQuestionSavePdfQueryBo extends BaseEntity { | ||||
|  | ||||
| 	/** 分页大小 */ | ||||
| 	@ApiModelProperty("分页大小") | ||||
| 	private Integer pageSize; | ||||
| 	/** 当前页数 */ | ||||
| 	@ApiModelProperty("当前页数") | ||||
| 	private Integer pageNum; | ||||
| 	/** 排序列 */ | ||||
| 	@ApiModelProperty("排序列") | ||||
| 	private String orderByColumn; | ||||
| 	/** 排序的方向desc或者asc */ | ||||
| 	@ApiModelProperty(value = "排序的方向", example = "asc,desc") | ||||
| 	private String isAsc; | ||||
|  | ||||
|  | ||||
| 	/** 1线上 2线下 */ | ||||
| 	@ApiModelProperty("1线上 2线下") | ||||
| 	private String type; | ||||
| 	/** 用户主键ID */ | ||||
| 	@ApiModelProperty("用户主键ID") | ||||
| 	private Long userId; | ||||
| 	/** pdf路径 */ | ||||
| 	@ApiModelProperty("pdf路径") | ||||
| 	private String path; | ||||
| 	/** 及格线/总分(格式:60,100) */ | ||||
| 	@ApiModelProperty("及格线/总分(格式:60,100)") | ||||
| 	private String pass; | ||||
| 	/** 最大超时时间(单位/分钟) */ | ||||
| 	@ApiModelProperty("最大超时时间(单位/分钟)") | ||||
| 	private Long timeOut; | ||||
| 	/** 用时时间(时间戳/秒) */ | ||||
| 	@ApiModelProperty("用时时间(时间戳/秒)") | ||||
| 	private Long takeTime; | ||||
| 	/** 总得分 */ | ||||
| 	@ApiModelProperty("总得分") | ||||
| 	private Long sumScore; | ||||
|  | ||||
| } | ||||
| @ -32,6 +32,6 @@ public class WgzAppSubmitATestPaperRes implements Serializable { | ||||
| 	@ApiModelProperty("答对题数") | ||||
| 	private Integer number; | ||||
|  | ||||
| //	@ApiModelProperty("试卷") | ||||
| //	private String pdfStr; | ||||
| 	@ApiModelProperty("试卷") | ||||
| 	private String pdfStr; | ||||
| } | ||||
|  | ||||
| @ -24,4 +24,7 @@ public class WgzAppUserScoreQuery implements Serializable { | ||||
|  | ||||
| 	@ApiModelProperty("当前分") | ||||
| 	private float CurrentMinute; | ||||
|  | ||||
| 	@ApiModelProperty("试卷") | ||||
| 	private String pdfStr; | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,74 @@ | ||||
| package com.ruoyi.wgz.domain; | ||||
|  | ||||
| import com.ruoyi.common.annotation.Excel; | ||||
|  | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import com.baomidou.mybatisplus.annotation.*; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
| import lombok.experimental.Accessors; | ||||
| import java.io.Serializable; | ||||
| import java.util.Date; | ||||
| import java.math.BigDecimal; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalTime; | ||||
| import java.time.LocalDate; | ||||
|  | ||||
| /** | ||||
|  * 用户试卷存储pdf对象 wgz_question_save_pdf | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  * @date 2025-03-26 | ||||
|  */ | ||||
| @Data | ||||
| @NoArgsConstructor | ||||
| @Accessors(chain = true) | ||||
| @TableName("wgz_question_save_pdf") | ||||
| @ApiModel("用户试卷存储pdf视图对象") | ||||
| public class WgzQuestionSavePdf implements Serializable { | ||||
|  | ||||
|     private static final long serialVersionUID=1L; | ||||
|  | ||||
|     /** 主键iD */ | ||||
|     @ApiModelProperty("主键iD") | ||||
|     @TableId(value = "id") | ||||
|     private Long id; | ||||
|  | ||||
|     /** 1线上 2线下 */ | ||||
|     @Excel(name = "1线上 2线下") | ||||
|     @ApiModelProperty("1线上 2线下") | ||||
|     private String type; | ||||
|  | ||||
|     /** 用户主键ID */ | ||||
|     @Excel(name = "用户主键ID") | ||||
|     @ApiModelProperty("用户主键ID") | ||||
|     private Long userId; | ||||
|  | ||||
|     /** pdf路径 */ | ||||
|     @Excel(name = "pdf路径") | ||||
|     @ApiModelProperty("pdf路径") | ||||
|     private String path; | ||||
|  | ||||
|     /** 及格线/总分(格式:60,100) */ | ||||
|     @Excel(name = "及格线/总分" , readConverterExp = "格=式:60,100") | ||||
|     @ApiModelProperty("及格线/总分(格式:60,100)") | ||||
|     private String pass; | ||||
|  | ||||
|     /** 最大超时时间(单位/分钟) */ | ||||
|     @Excel(name = "最大超时时间" , readConverterExp = "单=位/分钟") | ||||
|     @ApiModelProperty("最大超时时间(单位/分钟)") | ||||
|     private int timeOut; | ||||
|  | ||||
|     /** 用时时间(时间戳/秒) */ | ||||
|     @Excel(name = "用时时间" , readConverterExp = "时=间戳/秒") | ||||
|     @ApiModelProperty("用时时间(时间戳/秒)") | ||||
|     private Long takeTime; | ||||
|  | ||||
|     /** 总得分 */ | ||||
|     @Excel(name = "总得分") | ||||
|     @ApiModelProperty("总得分") | ||||
|     private Double sumScore; | ||||
|  | ||||
| } | ||||
| @ -37,6 +37,6 @@ public interface WgzQuestionSaveMapper extends BaseMapperPlus<WgzQuestionSave> { | ||||
| 	String pdfSumScore (@Param("userId") Long userId); | ||||
|  | ||||
| 	// | ||||
| 	@Select("SELECT c.question_type,c.question_text,c.OPTIONS,a.answer,c.correct_answer,a.correct,a.score,a.sign,a.id,a.pass,b.username FROM wgz_question_save AS a LEFT JOIN wgz_user AS b ON b.user_id=a.user_id LEFT JOIN wgz_question_bank AS c ON a.bank_id=c.id WHERE a.user_id=#{userId}") | ||||
| 	@Select("SELECT c.question_type,c.question_text,c.OPTIONS,a.answer,c.correct_answer,a.correct,a.score,a.sign,a.id,a.pass,b.username as userName FROM wgz_question_save AS a LEFT JOIN wgz_user AS b ON b.user_id=a.user_id LEFT JOIN wgz_question_bank AS c ON a.bank_id=c.id WHERE a.user_id=#{userId}") | ||||
| 	List<PdfEntity> pdfSc (@Param("userId") Long userId); | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,18 @@ | ||||
| package com.ruoyi.wgz.mapper; | ||||
|  | ||||
| import com.ruoyi.wgz.domain.WgzQuestionSavePdf; | ||||
| import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; | ||||
| import com.ruoyi.common.core.mybatisplus.cache.MybatisPlusRedisCache; | ||||
| import org.apache.ibatis.annotations.CacheNamespace; | ||||
|  | ||||
| /** | ||||
|  * 用户试卷存储pdfMapper接口 | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  * @date 2025-03-26 | ||||
|  */ | ||||
| // 如使需切换数据源 请勿使用缓存 会造成数据不一致现象 | ||||
| @CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class) | ||||
| public interface WgzQuestionSavePdfMapper extends BaseMapperPlus<WgzQuestionSavePdf> { | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,65 @@ | ||||
| package com.ruoyi.wgz.service; | ||||
|  | ||||
| import com.ruoyi.wgz.domain.WgzQuestionSavePdf; | ||||
| import com.ruoyi.wgz.bo.WgzQuestionSavePdfQueryBo; | ||||
| import com.ruoyi.common.core.mybatisplus.core.IServicePlus; | ||||
| import com.ruoyi.common.core.page.TableDataInfo; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 用户试卷存储pdfService接口 | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  * @date 2025-03-26 | ||||
|  */ | ||||
| public interface IWgzQuestionSavePdfService extends IServicePlus<WgzQuestionSavePdf> { | ||||
|     /** | ||||
|      * 查询单个 | ||||
|      * @return | ||||
|      */ | ||||
|     WgzQuestionSavePdf queryById(Long  id); | ||||
|  | ||||
|     /** | ||||
|      * 查询列表 | ||||
|      */ | ||||
|     TableDataInfo<WgzQuestionSavePdf> queryPageList(WgzQuestionSavePdfQueryBo bo); | ||||
|  | ||||
|     /** | ||||
|      * 查询列表 | ||||
|      */ | ||||
|     List<WgzQuestionSavePdf> queryList(WgzQuestionSavePdfQueryBo bo); | ||||
|  | ||||
|     /** | ||||
|      * 根据新增业务对象插入用户试卷存储pdf | ||||
|      * @param bo 用户试卷存储pdf新增业务对象 | ||||
|      * @return | ||||
|      */ | ||||
|     Boolean insert(WgzQuestionSavePdf bo); | ||||
|  | ||||
|     /** | ||||
|      * 根据编辑业务对象修改用户试卷存储pdf | ||||
|      * @param bo 用户试卷存储pdf编辑业务对象 | ||||
|      * @return | ||||
|      */ | ||||
|     Boolean update(WgzQuestionSavePdf bo); | ||||
|  | ||||
|     /** | ||||
|      * 校验并删除数据 | ||||
|      * @param ids 主键集合 | ||||
|      * @param isValid 是否校验,true-删除前校验,false-不校验 | ||||
|      * @return | ||||
|      */ | ||||
|     Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); | ||||
|  | ||||
| 	/** | ||||
| 	 * APP相关 | ||||
| 	 * ================================================================================================================= | ||||
| 	 * ================================================================================================================= | ||||
| 	 * ================================================================================================================= | ||||
| 	 */ | ||||
|  | ||||
| 	//根据当前用户ID查询用户试卷存储pdf | ||||
| 	WgzQuestionSavePdf queryByUserId(Long userId); | ||||
| } | ||||
| @ -0,0 +1,98 @@ | ||||
| package com.ruoyi.wgz.service.impl; | ||||
|  | ||||
| import cn.hutool.core.bean.BeanUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
| import com.ruoyi.common.utils.PageUtils; | ||||
| import com.ruoyi.common.core.page.PagePlus; | ||||
| import com.ruoyi.common.core.page.TableDataInfo; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import com.ruoyi.wgz.bo.WgzQuestionSavePdfQueryBo; | ||||
| import com.ruoyi.wgz.domain.WgzQuestionSavePdf; | ||||
| import com.ruoyi.wgz.mapper.WgzQuestionSavePdfMapper; | ||||
| import com.ruoyi.wgz.service.IWgzQuestionSavePdfService; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Collection; | ||||
|  | ||||
| /** | ||||
|  * 用户试卷存储pdfService业务层处理 | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  * @date 2025-03-26 | ||||
|  */ | ||||
| @Service | ||||
| public class WgzQuestionSavePdfServiceImpl extends ServicePlusImpl<WgzQuestionSavePdfMapper, WgzQuestionSavePdf> implements IWgzQuestionSavePdfService { | ||||
|  | ||||
|     @Override | ||||
|     public WgzQuestionSavePdf queryById(Long id){ | ||||
|         return getById(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TableDataInfo<WgzQuestionSavePdf> queryPageList(WgzQuestionSavePdfQueryBo bo) { | ||||
|         Page<WgzQuestionSavePdf> result = page(PageUtils.buildPage(), buildQueryWrapper(bo)); | ||||
|         return PageUtils.buildDataInfo(result); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<WgzQuestionSavePdf> queryList(WgzQuestionSavePdfQueryBo bo) { | ||||
|         return list(buildQueryWrapper(bo)); | ||||
|     } | ||||
|  | ||||
|     private LambdaQueryWrapper<WgzQuestionSavePdf> buildQueryWrapper(WgzQuestionSavePdfQueryBo bo) { | ||||
|         Map<String, Object> params = bo.getParams(); | ||||
|         LambdaQueryWrapper<WgzQuestionSavePdf> lqw = Wrappers.lambdaQuery(); | ||||
|         lqw.eq(StrUtil.isNotBlank(bo.getType()), WgzQuestionSavePdf::getType, bo.getType()); | ||||
|         lqw.eq(bo.getUserId() != null, WgzQuestionSavePdf::getUserId, bo.getUserId()); | ||||
|         lqw.eq(StrUtil.isNotBlank(bo.getPath()), WgzQuestionSavePdf::getPath, bo.getPath()); | ||||
|         lqw.eq(StrUtil.isNotBlank(bo.getPass()), WgzQuestionSavePdf::getPass, bo.getPass()); | ||||
|         lqw.eq(bo.getTimeOut() != null, WgzQuestionSavePdf::getTimeOut, bo.getTimeOut()); | ||||
|         lqw.eq(bo.getTakeTime() != null, WgzQuestionSavePdf::getTakeTime, bo.getTakeTime()); | ||||
|         lqw.eq(bo.getSumScore() != null, WgzQuestionSavePdf::getSumScore, bo.getSumScore()); | ||||
|         return lqw; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean insert(WgzQuestionSavePdf bo) { | ||||
|         WgzQuestionSavePdf add = BeanUtil.toBean(bo, WgzQuestionSavePdf.class); | ||||
|         validEntityBeforeSave(add); | ||||
|         return save(add); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean update(WgzQuestionSavePdf bo) { | ||||
|         WgzQuestionSavePdf update = BeanUtil.toBean(bo, WgzQuestionSavePdf.class); | ||||
|         validEntityBeforeSave(update); | ||||
|         return updateById(update); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 保存前的数据校验 | ||||
|      * | ||||
|      * @param entity 实体类数据 | ||||
|      */ | ||||
|     private void validEntityBeforeSave(WgzQuestionSavePdf entity){ | ||||
|         //TODO 做一些数据校验,如唯一约束 | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { | ||||
|         if(isValid){ | ||||
|             //TODO 做一些业务上的校验,判断是否需要校验 | ||||
|         } | ||||
|         return removeByIds(ids); | ||||
|     } | ||||
|  | ||||
|  | ||||
| 	@Override | ||||
| 	public WgzQuestionSavePdf queryByUserId(Long userId) { | ||||
| 		LambdaQueryWrapper<WgzQuestionSavePdf> lqw = Wrappers.lambdaQuery(); | ||||
| 		lqw.eq(WgzQuestionSavePdf::getUserId, userId); | ||||
| 		return  baseMapper.selectOne(lqw); | ||||
| 	} | ||||
| } | ||||
| @ -1,12 +1,14 @@ | ||||
| package com.ruoyi.wgz.service.impl; | ||||
|  | ||||
| import cn.hutool.core.bean.BeanUtil; | ||||
| import cn.hutool.core.util.IdUtil; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
| import com.itextpdf.io.font.PdfEncodings; | ||||
| import com.itextpdf.io.image.ImageData; | ||||
| import com.itextpdf.io.image.ImageDataFactory; | ||||
| import com.itextpdf.kernel.colors.ColorConstants; | ||||
| import com.itextpdf.kernel.colors.DeviceRgb; | ||||
| import com.itextpdf.kernel.font.PdfFont; | ||||
| import com.itextpdf.kernel.font.PdfFontFactory; | ||||
| @ -16,24 +18,21 @@ import com.itextpdf.kernel.pdf.PdfWriter; | ||||
| import com.itextpdf.layout.Document; | ||||
| import com.itextpdf.layout.element.Image; | ||||
| import com.ruoyi.bgt.domain.vo.BgtQuestionResult; | ||||
| import com.ruoyi.common.config.RuoYiConfig; | ||||
| import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; | ||||
| import com.ruoyi.common.core.page.TableDataInfo; | ||||
| import com.ruoyi.common.exception.BaseException; | ||||
| import com.ruoyi.common.utils.DateUtils; | ||||
| import com.ruoyi.common.utils.PageUtils; | ||||
| import com.ruoyi.common.utils.file.FileUploadUtils; | ||||
| import com.ruoyi.wgz.bo.WgzQuestionSaveQueryBo; | ||||
| import com.ruoyi.wgz.bo.req.WgzAppSubmitATestPaperReq; | ||||
| import com.ruoyi.wgz.bo.res.WgzAppSubmitATestPaperRes; | ||||
| import com.ruoyi.wgz.bo.res.WgzAppUserScoreQuery; | ||||
| import com.ruoyi.wgz.bo.rests.*; | ||||
| import com.ruoyi.wgz.domain.WgzQuestionBank; | ||||
| import com.ruoyi.wgz.domain.WgzQuestionSave; | ||||
| import com.ruoyi.wgz.domain.WgzQuestionsConfiguration; | ||||
| import com.ruoyi.wgz.domain.WgzUser; | ||||
| import com.ruoyi.wgz.domain.*; | ||||
| import com.ruoyi.wgz.mapper.WgzQuestionSaveMapper; | ||||
| import com.ruoyi.wgz.service.IWgzQuestionBankService; | ||||
| import com.ruoyi.wgz.service.IWgzQuestionSaveService; | ||||
| import com.ruoyi.wgz.service.IWgzQuestionsConfigurationService; | ||||
| import com.ruoyi.wgz.service.IWgzUserService; | ||||
| import com.ruoyi.wgz.service.*; | ||||
| import com.itextpdf.layout.properties.TextAlignment; | ||||
| import com.itextpdf.layout.element.Paragraph; | ||||
| import org.aspectj.weaver.patterns.TypePatternQuestions; | ||||
| @ -44,6 +43,7 @@ import org.springframework.util.StringUtils; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| @ -70,6 +70,9 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 	@Autowired | ||||
| 	private IWgzUserService wgzUserService; | ||||
|  | ||||
| 	@Autowired | ||||
| 	private IWgzQuestionSavePdfService wgzQuestionSavePdfService; | ||||
|  | ||||
|     @Override | ||||
|     public WgzQuestionSave queryById(Long id){ | ||||
|         return getById(id); | ||||
| @ -134,6 +137,10 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 	@Override | ||||
| 	@Transactional | ||||
| 	public WgzAppSubmitATestPaperRes userSubmitATestPaper(WgzAppSubmitATestPaperReq req) { | ||||
| 		String coryPass = ""; | ||||
| 		int coryTimeOut = 0; | ||||
| 		Long coryTakeTime = 0L; | ||||
| 		Double corySumScore = 0.00; | ||||
| 		/** | ||||
| 		 * 第一部分:计算并保存最高分试卷 | ||||
| 		 */ | ||||
| @ -191,6 +198,10 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 				bqsTwo.setTakeTime(req.getTakeTime()); | ||||
| 				bqsTwo.setTimeOut(configuration.getAnswerTime()); | ||||
| 				bqsTwo.setPass(pass); | ||||
|  | ||||
| 				coryTakeTime = req.getTakeTime(); | ||||
| 				coryTimeOut = configuration.getAnswerTime(); | ||||
| 				coryPass = pass; | ||||
| 			} | ||||
| 			bqs.add(bqsTwo); | ||||
| 			index = index+1; | ||||
| @ -208,10 +219,10 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 		if (scoreOne > scoreTwo) { | ||||
| 			return res; | ||||
| 		} else { | ||||
| 			corySumScore = scoreTwo; | ||||
| 			if (scoreOne == 0){ | ||||
| 				// 插入新数据 | ||||
| 				super.saveBatch(bqs); | ||||
| 				return res; | ||||
| 			} | ||||
| 			// 先查询当前用户是否有答题,有就把之前的删除(真删) | ||||
| 			int deleteResult = baseMapper.delete(new LambdaQueryWrapper<WgzQuestionSave>().eq(WgzQuestionSave::getUserId, req.getUserId())); | ||||
| @ -223,15 +234,30 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 		/** | ||||
| 		 * 第二部分:分离出试卷信息 | ||||
| 		 */ | ||||
| //		String two = two(req.getUserId(), configuration); | ||||
| //		System.out.println("?????????       "+two); | ||||
| //		System.out.println("?????????       "+two); | ||||
| //		System.out.println("?????????       "+two); | ||||
| 		ExaminationPaper examinationPaper = separateTestInformation(req.getUserId(), configuration); | ||||
| 		/** | ||||
| 		 * 第三部分:生成pdf并存储到数据库中 | ||||
| 		 */ | ||||
| 		try { | ||||
| 			String xdPath = generateExamPaper(examinationPaper); | ||||
| 			res.setPdfStr(xdPath); | ||||
| 			WgzQuestionSavePdf wgzQuestionSavePdf = new WgzQuestionSavePdf() | ||||
| 				.setType("1") | ||||
| 				.setUserId(req.getUserId()) | ||||
| 				.setPath(xdPath) | ||||
| 				.setPass(coryPass) | ||||
| 				.setTimeOut(coryTimeOut) | ||||
| 				.setTakeTime(coryTakeTime) | ||||
| 				.setSumScore(corySumScore); | ||||
| 			wgzQuestionSavePdfService.insert(wgzQuestionSavePdf); | ||||
| 		}catch (Exception e1){ | ||||
| 			throw new RuntimeException("生成PDF试卷出现了意外,请重新提交!"); | ||||
| 		} | ||||
| 		return res; | ||||
| 	} | ||||
|  | ||||
| 	// 分离试卷信息 | ||||
| 	public String two(Long userId,WgzQuestionsConfiguration configurationEntity) { | ||||
| 	private ExaminationPaper separateTestInformation(Long userId,WgzQuestionsConfiguration configurationEntity) { | ||||
| 		//1、组装数据 | ||||
| 		List<PdfEntity> we = baseMapper.pdfSc(userId); | ||||
| 		if (!we.isEmpty()) { | ||||
| @ -243,7 +269,8 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 				.setPass(we.get(0).getPass()) | ||||
| 				.setSumScore(sumScore) | ||||
| 				.setSign(we.get(0).getSign()) | ||||
| 				.setUserId(userId.toString()); | ||||
| 				.setUserId(userId.toString()) | ||||
| 				.setUserName(we.get(0).getUserName()); | ||||
| 			ExaminationPaperOne one = new ExaminationPaperOne(); | ||||
| 			ExaminationPaperOne two = new ExaminationPaperOne(); | ||||
| 			ExaminationPaperOne three = new ExaminationPaperOne(); | ||||
| @ -277,21 +304,18 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 			rs.setSingle(one); | ||||
| 			rs.setMultiple(two); | ||||
| 			rs.setEstimate(three); | ||||
| 			//2、生成pdf | ||||
| 			try { | ||||
| 				return generateExamPaper(rs); | ||||
| 			}catch (Exception e1){ | ||||
| 				throw new RuntimeException("生成PDF试卷出现了意外,请重新提交!"); | ||||
| 			} | ||||
| 			return rs; | ||||
| 		} | ||||
| 		throw new RuntimeException("未获取到试卷信息!"); | ||||
| 	} | ||||
|  | ||||
| 	public String generateExamPaper(ExaminationPaper rs) throws IOException { | ||||
| 		String fileName = "exam_paper_" + System.currentTimeMillis() + ".pdf"; | ||||
| 		String outputPath = Paths.get(System.getProperty("user.dir"), fileName).toString(); | ||||
|  | ||||
| 		PdfWriter writer = new PdfWriter(outputPath); | ||||
| 	// pdf生成 | ||||
| 	private String generateExamPaper(ExaminationPaper rs) throws IOException { | ||||
| 		String fileName = DateUtils.datePath() + File.separator  + rs.getUserId() + IdUtil.fastUUID() + ".pdf"; | ||||
| 		File desc = new File(RuoYiConfig.getUploadPath() + File.separator + fileName); | ||||
| 		Path path = Paths.get(FileUploadUtils.callGetPathFileName(RuoYiConfig.getUploadPath(), fileName)); | ||||
| 		// 创建PDF文档 | ||||
| 		PdfWriter writer = new PdfWriter(desc); | ||||
| 		PdfDocument pdfDoc = new PdfDocument(writer); | ||||
| 		Document document = new Document(pdfDoc, PageSize.A4); | ||||
|  | ||||
| @ -348,7 +372,7 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 				// 标记错误答案 | ||||
| 				if ("2".equals(data.getCorrect())) { | ||||
| 					document.add(new Paragraph("正确答案为:" + data.getCorrectAnswer()) | ||||
| 						.setFontColor(com.itextpdf.kernel.colors.ColorConstants.RED)); | ||||
| 						.setFontColor(ColorConstants.RED)); | ||||
| 				} | ||||
|  | ||||
| 				document.add(new Paragraph("\n")); | ||||
| @ -371,10 +395,11 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| //		} | ||||
|  | ||||
| 		document.close(); | ||||
| 		return outputPath; | ||||
| 		return path.toString(); | ||||
| 	} | ||||
|  | ||||
| 	private static String replaceBrackets(String text, String replacement) { | ||||
| 	// 括号填充 | ||||
| 	private String replaceBrackets(String text, String replacement) { | ||||
| 		Pattern pattern = Pattern.compile("\\s*(\\s*)\\s*"); | ||||
| 		Matcher matcher = pattern.matcher(text); | ||||
| 		return matcher.replaceAll("(  " + replacement + "  )"); | ||||
| @ -414,7 +439,9 @@ public class WgzQuestionSaveServiceImpl extends ServicePlusImpl<WgzQuestionSaveM | ||||
| 			res.setPassingScore(passingGrade); | ||||
| 		} | ||||
| 		res.setCurrentMinute(sumScore); | ||||
| 		return res; | ||||
| 		//4、获取pdf试卷信息 | ||||
| 		WgzQuestionSavePdf wgzQuestionSavePdf = wgzQuestionSavePdfService.queryByUserId(userId); | ||||
| 		return res.setPdfStr(wgzQuestionSavePdf.getPath()); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
|  | ||||
| @ -0,0 +1,19 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper | ||||
| PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
| "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.ruoyi.wgz.mapper.WgzQuestionSavePdfMapper"> | ||||
|  | ||||
|     <resultMap type="com.ruoyi.wgz.domain.WgzQuestionSavePdf" id="WgzQuestionSavePdfResult"> | ||||
|         <result property="id" column="id"/> | ||||
|         <result property="type" column="type"/> | ||||
|         <result property="userId" column="user_id"/> | ||||
|         <result property="path" column="path"/> | ||||
|         <result property="pass" column="pass"/> | ||||
|         <result property="timeOut" column="time_out"/> | ||||
|         <result property="takeTime" column="take_time"/> | ||||
|         <result property="sumScore" column="sum_score"/> | ||||
|     </resultMap> | ||||
|  | ||||
|  | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user