增加iText 7 核心模块

This commit is contained in:
2025-09-04 19:57:50 +08:00
parent 127059e934
commit ae3738c098
7 changed files with 567 additions and 454 deletions

View File

@ -250,8 +250,8 @@ springdoc:
packages-to-scan: org.dromara.design
- group: 13.工作流模块
packages-to-scan: org.dromara.workflow
- group: 14.罗成模块
packages-to-scan: org.dromara.cory
# - group: 14.罗成模块
# packages-to-scan: org.dromara.cory
- group: 15.无人机模块
packages-to-scan: org.dromara.drone
- group: 20.代码生成模块

View File

@ -88,8 +88,16 @@
<artifactId>layout</artifactId>
<version>7.2.5</version>
</dependency>
<!-- iText 7 核心模块必须layout依赖此模块 -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.2.5</version> <!-- 与layout版本严格一致 -->
</dependency>
<!-- 支持中文字体 -->
<!-- 支持中文字体 -->
<!-- <dependency>-->
<!-- <groupId>com.itextpdf</groupId>-->
<!-- <artifactId>itext-asian</artifactId>-->

View File

@ -0,0 +1,31 @@
package org.dromara.safety.bo.res;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.dromara.safety.bo.rests.WgzAppGetTestPaperTwo;
import java.io.Serializable;
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class WgzAppGetTestPaperRes implements Serializable {
/**
* 最大考试时间(分钟)
*/
private int maximum;
/**
* 单选题
*/
private WgzAppGetTestPaperTwo singleList;
/**
* 多选题
*/
private WgzAppGetTestPaperTwo multipleList;
/**
* 判断题
*/
private WgzAppGetTestPaperTwo estimateList;
}

View File

@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
/**
* 题库_题库类别
* 题库_题库类别Controller
*
* @author Lion Li
* @date 2025-09-03

View File

@ -0,0 +1,112 @@
package org.dromara.safety.controller.app;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.safety.bo.req.WgzAppSubmitATestPaperReq;
import org.dromara.safety.bo.res.WgzAppGetTestPaperRes;
import org.dromara.safety.bo.res.WgzAppSubmitATestPaperRes;
import org.dromara.safety.bo.res.WgzAppUserScoreQuery;
import org.dromara.safety.bo.rests.WgzAppGetTestPaperThree;
import org.dromara.safety.bo.rests.WgzAppGetTestPaperTwo;
import org.dromara.safety.domain.WgzQuestionsConfiguration;
import org.dromara.safety.service.IWgzQuestionBankService;
import org.dromara.safety.service.IWgzQuestionSaveService;
import org.dromara.safety.service.IWgzQuestionsConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author app 岗前培训 试卷
* @Date 2025/9/4 18:31
* @Version 1.0
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/safety/wgzShiJuan")
public class WgzShiJuan extends BaseController {
@Autowired
private IWgzQuestionsConfigurationService iWgzQuestionsConfigurationService;
@Autowired
private IWgzQuestionBankService iWgzQuestionBankService;
@Autowired
private IWgzQuestionSaveService iWgzQuestionSaveService;
/**
* 岗前培训·获取随机试卷
*/
// @SaCheckPermission("@ss.hasPermi('safety:wgzShiJuan:userGetTestPaper')")
@GetMapping("/WgzUserGetTestPaper")
public R<WgzAppGetTestPaperRes> userGetTestPaper() {
//1、获取配置信息
WgzQuestionsConfiguration configuration = iWgzQuestionsConfigurationService.appQueryLimitOne();
if (configuration == null) {
throw new RuntimeException("未查询到配置信息");
}
//2、随机获取数据返回id和score
Integer s = configuration.getSingleChoice();
Integer m = configuration.getMultipleChoice();
Integer e = configuration.getEstimate();
List<WgzAppGetTestPaperThree> sEntity = iWgzQuestionBankService.appQueryList(1, s);
List<WgzAppGetTestPaperThree> mEntity = iWgzQuestionBankService.appQueryList(2, m);
List<WgzAppGetTestPaperThree> eEntity = iWgzQuestionBankService.appQueryList(3, e);
//3、组装数据
WgzAppGetTestPaperRes res = new WgzAppGetTestPaperRes();
res.setSingleList(createQuestionSection("一、单选题", sEntity, configuration.getSingleScore(), s));
res.setMultipleList(createQuestionSection("二、多选题", mEntity, configuration.getMultipleScore(), m));
res.setEstimateList(createQuestionSection("三、判断题", eEntity, configuration.getEstimateScore(), e));
//4、设置最大考试时间
res.setMaximum(configuration.getAnswerTime());
return R.ok(res);
}
/**
* 【我的】【岗前培训】提交用户的试卷(只保存最高分的试卷信息)
*/
// @SaCheckPermission("safety:wzgQuestionCategory:WgzUserSubmitATestPaper")
@Log(title = "提交用户的试卷", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping("/WgzUserSubmitATestPaper")
public R<WgzAppSubmitATestPaperRes> userSubmitATestPaper(@Validated @RequestBody WgzAppSubmitATestPaperReq req) {
return R.ok(iWgzQuestionSaveService.userSubmitATestPaper(req));
}
/**
* 【我的】【岗前培训】分数查询
*/
// @SaCheckPermission("safety:wzgQuestionCategory:WgzUserScoreQuery")
@GetMapping("/WgzUserScoreQuery")
public R<WgzAppUserScoreQuery> userScoreQuery() {
Long userId = LoginHelper.getLoginUser().getUserId();
return R.ok(iWgzQuestionSaveService.userScoreQuery(userId));
}
/**
* 创建题目板块
* @param topicPrefix 板块标题前缀
* @param questions 题目列表
* @param score 每题分数
* @param questionCount 题目数量
* @return 题目板块实体
*/
private WgzAppGetTestPaperTwo createQuestionSection(String topicPrefix, List<WgzAppGetTestPaperThree> questions, Float score, int questionCount) {
WgzAppGetTestPaperTwo section = new WgzAppGetTestPaperTwo();
section.setTopic(String.format("%s共%d道题每小题%.2f分,共计%.2f分", topicPrefix, questionCount, score, questionCount * score));
questions.forEach(item -> item.setScore(score));
section.setList(questions);
return section;
}
}

View File

@ -60,492 +60,454 @@ import java.util.regex.Pattern;
*/
@Service
public class WgzQuestionSaveServiceImpl extends ServiceImpl<WgzQuestionSaveMapper, WgzQuestionSave> implements IWgzQuestionSaveService {
@Autowired
private IWgzQuestionsConfigurationService iWgzQuestionsConfigurationService;
@Autowired
private IWgzQuestionBankService iWgzQuestionBankService;
@Autowired
private IWgzQuestionSavePdfService wgzQuestionSavePdfService;
@Resource
private ISysOssService ossService;
@Override
public WgzQuestionSave queryById(Long id) {
return null;
return getById(id);
}
@Override
public TableDataInfo<WgzQuestionSaveVo> queryPageList(WgzQuestionSaveBo bo, PageQuery pageQuery) {
return null;
LambdaQueryWrapper<WgzQuestionSave> lqw = buildQueryWrapper(bo);
Page<WgzQuestionSaveVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
@Override
public List<WgzQuestionSaveVo> queryList(WgzQuestionSaveBo bo) {
return List.of();
LambdaQueryWrapper<WgzQuestionSave> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<WgzQuestionSave> buildQueryWrapper(WgzQuestionSaveBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<WgzQuestionSave> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(WgzQuestionSave::getId);
lqw.eq(bo.getUserId() != null, WgzQuestionSave::getUserId, bo.getUserId());
lqw.eq(bo.getBankId() != null, WgzQuestionSave::getBankId, bo.getBankId());
lqw.eq(StringUtils.isNotBlank(bo.getAnswer()), WgzQuestionSave::getAnswer, bo.getAnswer());
lqw.eq(StringUtils.isNotBlank(bo.getCorrect()), WgzQuestionSave::getCorrect, bo.getCorrect());
lqw.eq(bo.getScore() != null, WgzQuestionSave::getScore, bo.getScore());
lqw.eq(StringUtils.isNotBlank(bo.getSign()), WgzQuestionSave::getSign, bo.getSign());
lqw.eq(bo.getTakeTime() != null, WgzQuestionSave::getTakeTime, bo.getTakeTime());
lqw.eq(bo.getTimeOut() != null, WgzQuestionSave::getTimeOut, bo.getTimeOut());
lqw.eq(StringUtils.isNotBlank(bo.getPass()), WgzQuestionSave::getPass, bo.getPass());
return lqw;
}
@Override
public Boolean insert(WgzQuestionSave bo) {
return null;
WgzQuestionSave add = BeanUtil.toBean(bo, WgzQuestionSave.class);
validEntityBeforeSave(add);
return save(add);
}
@Override
public Boolean update(WgzQuestionSave bo) {
return null;
WgzQuestionSave update = BeanUtil.toBean(bo, WgzQuestionSave.class);
validEntityBeforeSave(update);
return updateById(update);
}
/**
* 保存前的数据校验
*
* @param entity 实体类数据
*/
private void validEntityBeforeSave(WgzQuestionSave entity) {
//TODO 做一些数据校验,如唯一约束
}
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
return null;
if (isValid) {
//TODO 做一些业务上的校验,判断是否需要校验
}
return removeByIds(ids);
}
/**
* APP相关
* =================================================================================================================
* =================================================================================================================
* =================================================================================================================
*/
@Override
@Transactional(rollbackFor = Exception.class)
public WgzAppSubmitATestPaperRes userSubmitATestPaper(WgzAppSubmitATestPaperReq req) {
return null;
String coryPass = "";
int coryTimeOut = 0;
Long coryTakeTime = 0L;
Double corySumScore = 0.00;
/**
* 第一部分:计算并保存最高分试卷
*/
// 初始化第一次分数和当前考试的分数
double scoreOne = 0.00;
double scoreTwo = 0.00;
//1、获取上次考试的分数
Map<String, Object> spMap = baseMapper.getSumScoreAndPassAndSign(req.getUserId());
if (spMap != null) {
String pass = (String) spMap.get("pass");
if (pass != null && !pass.isEmpty()) {
String[] split = pass.split(",");
double float1 = Double.parseDouble(split[1]);
double sumScore = (double) spMap.get("sumScore");
scoreOne = 100.00 / float1 * sumScore;
}
}
//2、获取配置信息
WgzQuestionsConfiguration configuration = iWgzQuestionsConfigurationService.appQueryLimitOne();
//3、计算这次用户提交的试卷信息所得到的分数
List<WgzQuestionSave> bqs = new ArrayList<>();
Double fenshu = 0.0;
Integer number = 0;
Integer index = 0;
List<WgzAppSubmitATestPaperTwo> list = req.getList();
for (WgzAppSubmitATestPaperTwo data : list) {
String correct = "";
String pass = "";
// 获取题库的正确答案,然后和用户的答案作对比
WgzQuestionBank bqb = iWgzQuestionBankService.selectById(data.getBankId());
if (bqb == null) {
throw new RuntimeException("您的试卷被外星人卷走了!");
} else {
if (StringUtils.isEmpty(data.getAnswer())) {
throw new RuntimeException("您还有题未答完!");
}
if (bqb.getCorrectAnswer().toLowerCase().contains(data.getAnswer().toLowerCase())) {
correct = "1";
fenshu = fenshu + data.getScore();
number = number + 1;
} else {
correct = "2";
}
}
// 记录这次的及格线和总分
pass = configuration.getPassingScore().toString() + "," + configuration.getFullMark().toString();
WgzQuestionSave bqsTwo = new WgzQuestionSave();
bqsTwo.setUserId(req.getUserId());
bqsTwo.setBankId(data.getBankId());
bqsTwo.setAnswer(data.getAnswer());
bqsTwo.setCorrect(correct);
bqsTwo.setScore(data.getScore());
//这几条数据只在每张试卷的第一条数据中存储(重复的没必要每条都存储)
if (index == 0) {
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;
}
Double fullMark = configuration.getFullMark();
scoreTwo = 100.00 / fullMark * fenshu;
WgzAppSubmitATestPaperRes res = new WgzAppSubmitATestPaperRes();
res.setAnswerTime(configuration.getAnswerTime());
res.setTakeTime(req.getTakeTime());
res.setFullMark(fullMark);
res.setPassingScore(configuration.getPassingScore());
res.setScore(fenshu);
res.setNumber(number);
//4、两次卷子的分数对比,第一次的分数比第二次大那么第二次只返回结果;第二次的分数比第一次大那么删除第一次的数据再重新插入
if (scoreOne > scoreTwo) {
return res;
} else {
corySumScore = scoreTwo;
if (scoreOne == 0) {
// 插入新数据
super.saveBatch(bqs);
}
// 先查询当前用户是否有答题,有就把之前的删除(真删)
int deleteResult = baseMapper.delete(new LambdaQueryWrapper<WgzQuestionSave>().eq(WgzQuestionSave::getUserId, req.getUserId()));
if (deleteResult > 0) {
// 删除pdf
wgzQuestionSavePdfService.deleteByUserId(req.getUserId());
// 插入新数据
super.saveBatch(bqs);
}
}
/**
* 第二部分:分离出试卷信息
*/
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;
}
// 分离试卷信息
private ExaminationPaper separateTestInformation(Long userId, WgzQuestionsConfiguration configurationEntity) {
//1、组装数据
List<PdfEntity> we = baseMapper.pdfSc(userId);
if (!we.isEmpty()) {
String sumScore = baseMapper.pdfSumScore(userId);
Integer s = configurationEntity.getSingleChoice();
Integer m = configurationEntity.getMultipleChoice();
Integer e = configurationEntity.getEstimate();
ExaminationPaper rs = new ExaminationPaper()
.setPass(we.get(0).getPass())
.setSumScore(sumScore)
.setSign(we.get(0).getSign())
.setUserId(userId.toString())
.setUserName(we.get(0).getUserName());
ExaminationPaperOne one = new ExaminationPaperOne();
ExaminationPaperOne two = new ExaminationPaperOne();
ExaminationPaperOne three = new ExaminationPaperOne();
one.setTopic("一、单选题,共" + s + "道题,每小题" + configurationEntity.getSingleScore() + "分,共计" + configurationEntity.getSingleScore() * s + "");
two.setTopic("二、多选题,共" + m + "道题,每小题" + configurationEntity.getMultipleScore() + "分,共计" + configurationEntity.getMultipleScore() * m + "");
three.setTopic("三、判断题,共" + e + "道题,每小题" + configurationEntity.getEstimateScore() + "分,共计" + configurationEntity.getEstimateScore() * e + "");
List<ExaminationPaperTwo> sEntity = new ArrayList<>();
List<ExaminationPaperTwo> mEntity = new ArrayList<>();
List<ExaminationPaperTwo> eEntity = new ArrayList<>();
for (PdfEntity data : we) {
ExaminationPaperTwo sy = new ExaminationPaperTwo();
sy.setQuestionText(data.getQuestionText());
sy.setOptions(data.getOptions());
sy.setAnswer(data.getAnswer());
sy.setCorrectAnswer(data.getCorrectAnswer());
sy.setCorrect(data.getCorrect());
sy.setScore(data.getScore());
if (data.getQuestionType().equals("1")) {
sEntity.add(sy);
}
if (data.getQuestionType().equals("2")) {
mEntity.add(sy);
}
if (data.getQuestionType().equals("3")) {
eEntity.add(sy);
}
}
one.setList(sEntity);
two.setList(mEntity);
three.setList(eEntity);
rs.setSingle(one);
rs.setMultiple(two);
rs.setEstimate(three);
return rs;
}
throw new RuntimeException("未获取到试卷信息!");
}
// pdf生成
private String generateExamPaper(ExaminationPaper rs) throws IOException {
String fileName = DateUtils.datePath() + File.separator + rs.getUserId() + IdUtil.fastUUID() + ".pdf";
File desc = new File("file" + File.separator + "exam" + File.separator + fileName);
// 创建PDF文档
PdfWriter writer = new PdfWriter(desc);
PdfDocument pdfDoc = new PdfDocument(writer);
Document document = new Document(pdfDoc, PageSize.A4);
// 加载字体(确保 simhei.ttf 可用)
String fontPath = "fonts/simhei.ttf";
PdfFont simhei = PdfFontFactory.createFont(fontPath, PdfEncodings.IDENTITY_H);
PdfFont simheiBold = PdfFontFactory.createFont(fontPath, PdfEncodings.IDENTITY_H);
// 标题
document.setFont(simheiBold).setFontSize(36);
document.add(new Paragraph("《灵活用工岗前培训》")
.setTextAlignment(TextAlignment.CENTER));
document.add(new Paragraph("\n"));
// 考生信息
document.setFont(simhei).setFontSize(16);
document.add(new Paragraph("姓名: " + rs.getUserName()));
document.add(new Paragraph("及格线/总分: " + rs.getPass()));
document.add(new Paragraph("实际得分: " + rs.getSumScore()));
document.add(new Paragraph("\n"));
// 处理单选、多选、判断题
for (int i = 1; i <= 3; i++) {
ExaminationPaperOne ep;
if (i == 1) {
ep = rs.getSingle();
} else if (i == 2) {
ep = rs.getMultiple();
} else {
ep = rs.getEstimate();
}
document.setFont(simhei).setFontSize(20);
document.add(new Paragraph(ep.getTopic()));
document.setFont(simhei).setFontSize(12);
List<ExaminationPaperTwo> questionList = ep.getList();
for (int qIndex = 0; qIndex < questionList.size(); qIndex++) {
ExaminationPaperTwo data = questionList.get(qIndex);
String questionText = (i == 3) ?
(qIndex + 1) + "" + data.getQuestionText() + " " + data.getAnswer() + " "
: (qIndex + 1) + "" + replaceBrackets(data.getQuestionText(), data.getAnswer());
document.add(new Paragraph(questionText));
// 选项
String[] options = data.getOptions().split("@");
for (String option : options) {
document.add(new Paragraph(" " + option));
}
// 标记错误答案
if ("2".equals(data.getCorrect())) {
document.add(new Paragraph("正确答案为:" + data.getCorrectAnswer())
.setFontColor(ColorConstants.RED));
}
document.add(new Paragraph("\n"));
}
}
// // 签名部分
// document.add(new Paragraph("\n\n\n"));
// document.setFont(simheiBold).setFontSize(16);
// document.add(new Paragraph("签字:").setTextAlignment(TextAlignment.RIGHT));
// // 嵌入签名图片
// if (rs.getSign() != null && !rs.getSign().isEmpty()) {
// String signPath = Paths.get(System.getProperty("user.dir"), rs.getSign()).toString();
// File signFile = new File(signPath);
// if (signFile.exists()) {
// ImageData imageData = ImageDataFactory.create(signPath);
// Image image = new Image(imageData).scaleToFit(100, 50);
// document.add(image.setRotationAngle(Math.PI / 2));
// }
// }
document.close();
SysOssVo upload = ossService.upload(desc);
// 刪除本地文件
try {
boolean delete = desc.delete();
if (!delete) {
log.error("删除本地文件失败");
}
} catch (Exception e) {
log.error("删除本地文件失败", e);
}
return upload.getOssId().toString();
}
// 括号填充
private String replaceBrackets(String text, String replacement) {
Pattern pattern = Pattern.compile("\\s*\\s*\\s*");
Matcher matcher = pattern.matcher(text);
return matcher.replaceAll(" " + replacement + " ");
}
@Override
public WgzAppUserScoreQuery userScoreQuery(long userId) {
return null;
WgzAppUserScoreQuery res = new WgzAppUserScoreQuery();
//1、查询及格分和满分,为空表示暂无记录
LambdaQueryWrapper<WgzQuestionSave> wra = new LambdaQueryWrapper<WgzQuestionSave>()
.eq(WgzQuestionSave::getUserId, userId);
List<WgzQuestionSave> savaList = baseMapper.selectList(wra);
if (savaList.isEmpty()) {
res.setIsPass("3");
return res;
}
//2、查询用户答对的分数
float sumScore = baseMapper.getSumScore(userId);
//3、计算上次分数是否及格
String pass = savaList.get(0).getPass();
if (pass != null && !pass.isEmpty()) {
String[] split = pass.split(",");
float fullMark = Float.parseFloat(split[1]);
float passingGrade = Float.parseFloat(split[0]);
// // 100分 / 满分 * 答对的分数 = 当前分数
// double score = 100.00 / fullMark * sumScore;
// // 使用 DecimalFormat 保证分数最多1位小数
// DecimalFormat df = new DecimalFormat("#.#");
// score = Double.parseDouble(df.format(score));
// 当前分数 >= 及格线 = 及格 否则 不及格
if (sumScore >= passingGrade) {
res.setIsPass("1");
} else {
res.setIsPass("2");
}
res.setFullMark(fullMark);
res.setPassingScore(passingGrade);
}
res.setCurrentMinute(sumScore);
//4、获取pdf试卷信息
WgzQuestionSavePdf wgzQuestionSavePdf = wgzQuestionSavePdfService.queryByUserId(userId);
if (wgzQuestionSavePdf != null) {
res.setPdfStr(wgzQuestionSavePdf.getPath());
}
return res;
}
// @Override
// public BgtQuestionResult getResult(Long userId) {
//
// @Autowired
// private IWgzQuestionsConfigurationService iWgzQuestionsConfigurationService;
// BgtQuestionResult bgtQuestionResult = new BgtQuestionResult();
//
// @Autowired
// private IWgzQuestionBankService iWgzQuestionBankService;
// WgzUser byUserId = wgzUserService.findByUserId(userId);
// if(byUserId == null){
// throw new BaseException("用户不存在");
// }
// bgtQuestionResult.setAvatarName(byUserId.getAvatarName());
//
// @Autowired
// private IWgzQuestionSavePdfService wgzQuestionSavePdfService;
// LambdaQueryWrapper<WgzQuestionSave> wra = new LambdaQueryWrapper<WgzQuestionSave>()
// .eq(WgzQuestionSave::getUserId, userId);
// List<WgzQuestionSave> savaList = baseMapper.selectList(wra);
//
// @Resource
// private ISysOssService ossService;
// double score= 0d;
// int successNum = 0;
// int errorNum= 0;
// long time= 0L;
//
// @Override
// public WgzQuestionSave queryById(Long id) {
// return getById(id);
// }
// for (WgzQuestionSave wgzQuestionSave : savaList){
// if(wgzQuestionSave.getCorrect().equals("1")){
// score += wgzQuestionSave.getScore();
// successNum++;
// }else{
// errorNum++;
// }
// if(wgzQuestionSave.getTakeTime() != null){
// time += wgzQuestionSave.getTakeTime();
// }
// }
//
// @Override
// public TableDataInfo<WgzQuestionSaveVo> queryPageList(WgzQuestionSaveBo bo, PageQuery pageQuery) {
// LambdaQueryWrapper<WgzQuestionSave> lqw = buildQueryWrapper(bo);
// Page<WgzQuestionSaveVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
// return TableDataInfo.build(result);
// }
//
// @Override
// public List<WgzQuestionSaveVo> queryList(WgzQuestionSaveBo bo) {
// LambdaQueryWrapper<WgzQuestionSave> lqw = buildQueryWrapper(bo);
// return baseMapper.selectVoList(lqw);
// }
//
// private LambdaQueryWrapper<WgzQuestionSave> buildQueryWrapper(WgzQuestionSaveBo bo) {
// Map<String, Object> params = bo.getParams();
// LambdaQueryWrapper<WgzQuestionSave> lqw = Wrappers.lambdaQuery();
// lqw.orderByDesc(WgzQuestionSave::getId);
// lqw.eq(bo.getUserId() != null, WgzQuestionSave::getUserId, bo.getUserId());
// lqw.eq(bo.getBankId() != null, WgzQuestionSave::getBankId, bo.getBankId());
// lqw.eq(StringUtils.isNotBlank(bo.getAnswer()), WgzQuestionSave::getAnswer, bo.getAnswer());
// lqw.eq(StringUtils.isNotBlank(bo.getCorrect()), WgzQuestionSave::getCorrect, bo.getCorrect());
// lqw.eq(bo.getScore() != null, WgzQuestionSave::getScore, bo.getScore());
// lqw.eq(StringUtils.isNotBlank(bo.getSign()), WgzQuestionSave::getSign, bo.getSign());
// lqw.eq(bo.getTakeTime() != null, WgzQuestionSave::getTakeTime, bo.getTakeTime());
// lqw.eq(bo.getTimeOut() != null, WgzQuestionSave::getTimeOut, bo.getTimeOut());
// lqw.eq(StringUtils.isNotBlank(bo.getPass()), WgzQuestionSave::getPass, bo.getPass());
// return lqw;
// }
//
// @Override
// public Boolean insert(WgzQuestionSave bo) {
// WgzQuestionSave add = BeanUtil.toBean(bo, WgzQuestionSave.class);
// validEntityBeforeSave(add);
// return save(add);
// }
//
// @Override
// public Boolean update(WgzQuestionSave bo) {
// WgzQuestionSave update = BeanUtil.toBean(bo, WgzQuestionSave.class);
// validEntityBeforeSave(update);
// return updateById(update);
// }
//
// /**
// * 保存前的数据校验
// *
// * @param entity 实体类数据
// */
// private void validEntityBeforeSave(WgzQuestionSave entity) {
// //TODO 做一些数据校验,如唯一约束
// }
//
// @Override
// public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
// if (isValid) {
// //TODO 做一些业务上的校验,判断是否需要校验
// }
// return removeByIds(ids);
// }
//
// /**
// * APP相关
// * =================================================================================================================
// * =================================================================================================================
// * =================================================================================================================
// */
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WgzAppSubmitATestPaperRes userSubmitATestPaper(WgzAppSubmitATestPaperReq req) {
// String coryPass = "";
// int coryTimeOut = 0;
// Long coryTakeTime = 0L;
// Double corySumScore = 0.00;
// /**
// * 第一部分:计算并保存最高分试卷
// */
// // 初始化第一次分数和当前考试的分数
// double scoreOne = 0.00;
// double scoreTwo = 0.00;
// //1、获取上次考试的分数
// Map<String, Object> spMap = baseMapper.getSumScoreAndPassAndSign(req.getUserId());
// if (spMap != null) {
// String pass = (String) spMap.get("pass");
// if (pass != null && !pass.isEmpty()) {
// String[] split = pass.split(",");
// double float1 = Double.parseDouble(split[1]);
// double sumScore = (double) spMap.get("sumScore");
// scoreOne = 100.00 / float1 * sumScore;
// }
// }
// //2、获取配置信息
// WgzQuestionsConfiguration configuration = iWgzQuestionsConfigurationService.appQueryLimitOne();
// //3、计算这次用户提交的试卷信息所得到的分数
// List<WgzQuestionSave> bqs = new ArrayList<>();
// Double fenshu = 0.0;
// Integer number = 0;
// Integer index = 0;
// List<WgzAppSubmitATestPaperTwo> list = req.getList();
// for (WgzAppSubmitATestPaperTwo data : list) {
// String correct = "";
// String pass = "";
// // 获取题库的正确答案,然后和用户的答案作对比
// WgzQuestionBank bqb = iWgzQuestionBankService.selectById(data.getBankId());
// if (bqb == null) {
// throw new RuntimeException("您的试卷被外星人卷走了!");
// } else {
// if (StringUtils.isEmpty(data.getAnswer())) {
// throw new RuntimeException("您还有题未答完!");
// }
// if (bqb.getCorrectAnswer().toLowerCase().contains(data.getAnswer().toLowerCase())) {
// correct = "1";
// fenshu = fenshu + data.getScore();
// number = number + 1;
// } else {
// correct = "2";
// }
// }
// // 记录这次的及格线和总分
// pass = configuration.getPassingScore().toString() + "," + configuration.getFullMark().toString();
// WgzQuestionSave bqsTwo = new WgzQuestionSave();
// bqsTwo.setUserId(req.getUserId());
// bqsTwo.setBankId(data.getBankId());
// bqsTwo.setAnswer(data.getAnswer());
// bqsTwo.setCorrect(correct);
// bqsTwo.setScore(data.getScore());
// //这几条数据只在每张试卷的第一条数据中存储(重复的没必要每条都存储)
// if (index == 0) {
// 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;
// }
// Double fullMark = configuration.getFullMark();
// scoreTwo = 100.00 / fullMark * fenshu;
// WgzAppSubmitATestPaperRes res = new WgzAppSubmitATestPaperRes();
// res.setAnswerTime(configuration.getAnswerTime());
// res.setTakeTime(req.getTakeTime());
// res.setFullMark(fullMark);
// res.setPassingScore(configuration.getPassingScore());
// res.setScore(fenshu);
// res.setNumber(number);
// //4、两次卷子的分数对比,第一次的分数比第二次大那么第二次只返回结果;第二次的分数比第一次大那么删除第一次的数据再重新插入
// if (scoreOne > scoreTwo) {
// return res;
// } else {
// corySumScore = scoreTwo;
// if (scoreOne == 0) {
// // 插入新数据
// super.saveBatch(bqs);
// }
// // 先查询当前用户是否有答题,有就把之前的删除(真删)
// int deleteResult = baseMapper.delete(new LambdaQueryWrapper<WgzQuestionSave>().eq(WgzQuestionSave::getUserId, req.getUserId()));
// if (deleteResult > 0) {
// // 删除pdf
// wgzQuestionSavePdfService.deleteByUserId(req.getUserId());
// // 插入新数据
// super.saveBatch(bqs);
// }
// }
// /**
// * 第二部分:分离出试卷信息
// */
// 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;
// }
//
// // 分离试卷信息
// private ExaminationPaper separateTestInformation(Long userId, WgzQuestionsConfiguration configurationEntity) {
// //1、组装数据
// List<PdfEntity> we = baseMapper.pdfSc(userId);
// if (!we.isEmpty()) {
// String sumScore = baseMapper.pdfSumScore(userId);
// Integer s = configurationEntity.getSingleChoice();
// Integer m = configurationEntity.getMultipleChoice();
// Integer e = configurationEntity.getEstimate();
// ExaminationPaper rs = new ExaminationPaper()
// .setPass(we.get(0).getPass())
// .setSumScore(sumScore)
// .setSign(we.get(0).getSign())
// .setUserId(userId.toString())
// .setUserName(we.get(0).getUserName());
// ExaminationPaperOne one = new ExaminationPaperOne();
// ExaminationPaperOne two = new ExaminationPaperOne();
// ExaminationPaperOne three = new ExaminationPaperOne();
// one.setTopic("一、单选题,共" + s + "道题,每小题" + configurationEntity.getSingleScore() + "分,共计" + configurationEntity.getSingleScore() * s + "分");
// two.setTopic("二、多选题,共" + m + "道题,每小题" + configurationEntity.getMultipleScore() + "分,共计" + configurationEntity.getMultipleScore() * m + "分");
// three.setTopic("三、判断题,共" + e + "道题,每小题" + configurationEntity.getEstimateScore() + "分,共计" + configurationEntity.getEstimateScore() * e + "分");
// List<ExaminationPaperTwo> sEntity = new ArrayList<>();
// List<ExaminationPaperTwo> mEntity = new ArrayList<>();
// List<ExaminationPaperTwo> eEntity = new ArrayList<>();
// for (PdfEntity data : we) {
// ExaminationPaperTwo sy = new ExaminationPaperTwo();
// sy.setQuestionText(data.getQuestionText());
// sy.setOptions(data.getOptions());
// sy.setAnswer(data.getAnswer());
// sy.setCorrectAnswer(data.getCorrectAnswer());
// sy.setCorrect(data.getCorrect());
// sy.setScore(data.getScore());
// if (data.getQuestionType().equals("1")) {
// sEntity.add(sy);
// }
// if (data.getQuestionType().equals("2")) {
// mEntity.add(sy);
// }
// if (data.getQuestionType().equals("3")) {
// eEntity.add(sy);
// }
// }
// one.setList(sEntity);
// two.setList(mEntity);
// three.setList(eEntity);
// rs.setSingle(one);
// rs.setMultiple(two);
// rs.setEstimate(three);
// return rs;
// }
// throw new RuntimeException("未获取到试卷信息!");
// }
//
// // pdf生成
// private String generateExamPaper(ExaminationPaper rs) throws IOException {
// String fileName = DateUtils.datePath() + File.separator + rs.getUserId() + IdUtil.fastUUID() + ".pdf";
// File desc = new File("file" + File.separator + "exam" + File.separator + fileName);
// // 创建PDF文档
// PdfWriter writer = new PdfWriter(desc);
// PdfDocument pdfDoc = new PdfDocument(writer);
// Document document = new Document(pdfDoc, PageSize.A4);
//
// // 加载字体(确保 simhei.ttf 可用)
// String fontPath = "fonts/simhei.ttf";
// PdfFont simhei = PdfFontFactory.createFont(fontPath, PdfEncodings.IDENTITY_H);
// PdfFont simheiBold = PdfFontFactory.createFont(fontPath, PdfEncodings.IDENTITY_H);
//
// // 标题
// document.setFont(simheiBold).setFontSize(36);
//
// document.add(new Paragraph("《灵活用工岗前培训》")
// .setTextAlignment(TextAlignment.CENTER));
//
// document.add(new Paragraph("\n"));
//
// // 考生信息
// document.setFont(simhei).setFontSize(16);
// document.add(new Paragraph("姓名: " + rs.getUserName()));
// document.add(new Paragraph("及格线/总分: " + rs.getPass()));
// document.add(new Paragraph("实际得分: " + rs.getSumScore()));
// document.add(new Paragraph("\n"));
//
// // 处理单选、多选、判断题
// for (int i = 1; i <= 3; i++) {
// ExaminationPaperOne ep;
// if (i == 1) {
// ep = rs.getSingle();
// } else if (i == 2) {
// ep = rs.getMultiple();
// } else {
// ep = rs.getEstimate();
// }
//
// document.setFont(simhei).setFontSize(20);
// document.add(new Paragraph(ep.getTopic()));
//
// document.setFont(simhei).setFontSize(12);
// List<ExaminationPaperTwo> questionList = ep.getList();
// for (int qIndex = 0; qIndex < questionList.size(); qIndex++) {
// ExaminationPaperTwo data = questionList.get(qIndex);
// String questionText = (i == 3) ?
// (qIndex + 1) + "、" + data.getQuestionText() + " " + data.getAnswer() + " "
// : (qIndex + 1) + "、" + replaceBrackets(data.getQuestionText(), data.getAnswer());
//
// document.add(new Paragraph(questionText));
//
// // 选项
// String[] options = data.getOptions().split("@");
// for (String option : options) {
// document.add(new Paragraph(" " + option));
// }
//
// // 标记错误答案
// if ("2".equals(data.getCorrect())) {
// document.add(new Paragraph("正确答案为:" + data.getCorrectAnswer())
// .setFontColor(ColorConstants.RED));
// }
//
// document.add(new Paragraph("\n"));
// }
// }
//
//// // 签名部分
//// document.add(new Paragraph("\n\n\n"));
//// document.setFont(simheiBold).setFontSize(16);
//// document.add(new Paragraph("签字:").setTextAlignment(TextAlignment.RIGHT));
//// // 嵌入签名图片
//// if (rs.getSign() != null && !rs.getSign().isEmpty()) {
//// String signPath = Paths.get(System.getProperty("user.dir"), rs.getSign()).toString();
//// File signFile = new File(signPath);
//// if (signFile.exists()) {
//// ImageData imageData = ImageDataFactory.create(signPath);
//// Image image = new Image(imageData).scaleToFit(100, 50);
//// document.add(image.setRotationAngle(Math.PI / 2));
//// }
//// }
//
// document.close();
// SysOssVo upload = ossService.upload(desc);
// // 刪除本地文件
// try {
// boolean delete = desc.delete();
// if (!delete) {
// log.error("删除本地文件失败");
// }
// } catch (Exception e) {
// log.error("删除本地文件失败", e);
// }
// return upload.getOssId().toString();
// }
//
// // 括号填充
// private String replaceBrackets(String text, String replacement) {
// Pattern pattern = Pattern.compile("\\s*\\s*\\s*");
// Matcher matcher = pattern.matcher(text);
// return matcher.replaceAll(" " + replacement + " ");
// }
//
// @Override
// public WgzAppUserScoreQuery userScoreQuery(long userId) {
// WgzAppUserScoreQuery res = new WgzAppUserScoreQuery();
// //1、查询及格分和满分,为空表示暂无记录
// LambdaQueryWrapper<WgzQuestionSave> wra = new LambdaQueryWrapper<WgzQuestionSave>()
// .eq(WgzQuestionSave::getUserId, userId);
// List<WgzQuestionSave> savaList = baseMapper.selectList(wra);
// if (savaList.isEmpty()) {
// res.setIsPass("3");
// return res;
// }
// //2、查询用户答对的分数
// float sumScore = baseMapper.getSumScore(userId);
// //3、计算上次分数是否及格
// String pass = savaList.get(0).getPass();
// if (pass != null && !pass.isEmpty()) {
// String[] split = pass.split(",");
// float fullMark = Float.parseFloat(split[1]);
// float passingGrade = Float.parseFloat(split[0]);
//// // 100分 / 满分 * 答对的分数 = 当前分数
//// double score = 100.00 / fullMark * sumScore;
//// // 使用 DecimalFormat 保证分数最多1位小数
//// DecimalFormat df = new DecimalFormat("#.#");
//// score = Double.parseDouble(df.format(score));
// // 当前分数 >= 及格线 = 及格 否则 不及格
// if (sumScore >= passingGrade) {
// res.setIsPass("1");
// } else {
// res.setIsPass("2");
// }
// res.setFullMark(fullMark);
// res.setPassingScore(passingGrade);
// }
// res.setCurrentMinute(sumScore);
// //4、获取pdf试卷信息
// WgzQuestionSavePdf wgzQuestionSavePdf = wgzQuestionSavePdfService.queryByUserId(userId);
// if (wgzQuestionSavePdf != null) {
// res.setPdfStr(wgzQuestionSavePdf.getPath());
// }
// return res;
// }
//
//// @Override
//// public BgtQuestionResult getResult(Long userId) {
////
//// BgtQuestionResult bgtQuestionResult = new BgtQuestionResult();
////
//// WgzUser byUserId = wgzUserService.findByUserId(userId);
//// if(byUserId == null){
//// throw new BaseException("用户不存在");
//// }
//// bgtQuestionResult.setAvatarName(byUserId.getAvatarName());
////
//// LambdaQueryWrapper<WgzQuestionSave> wra = new LambdaQueryWrapper<WgzQuestionSave>()
//// .eq(WgzQuestionSave::getUserId, userId);
//// List<WgzQuestionSave> savaList = baseMapper.selectList(wra);
////
//// double score= 0d;
//// int successNum = 0;
//// int errorNum= 0;
//// long time= 0L;
////
//// for (WgzQuestionSave wgzQuestionSave : savaList){
//// if(wgzQuestionSave.getCorrect().equals("1")){
//// score += wgzQuestionSave.getScore();
//// successNum++;
//// }else{
//// errorNum++;
//// }
//// if(wgzQuestionSave.getTakeTime() != null){
//// time += wgzQuestionSave.getTakeTime();
//// }
//// }
////
//// bgtQuestionResult.setScore(score);
//// bgtQuestionResult.setSuccessNum(successNum);
//// bgtQuestionResult.setErrorNum(errorNum);
//// bgtQuestionResult.setTime(time);
//// return bgtQuestionResult;
//// }
// bgtQuestionResult.setScore(score);
// bgtQuestionResult.setSuccessNum(successNum);
// bgtQuestionResult.setErrorNum(errorNum);
// bgtQuestionResult.setTime(time);
// return bgtQuestionResult;
// }
}

View File

@ -31,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM
bus_bidding_limit_list AS a
where
a.project_id = #{projectId}
a.project_id = #{projectId} and unit_price is not NULL
<if test="planMonth != null and planMonth!='' ">
and DATE_FORMAT(a.create_time,'%Y-%m') = #{planMonth}
</if>