"git@gitlab.ruzhoukj.com:wujipeng/pipeline-network.git" did not exist on "38e3fcf2ad36c72d42a3e649e7aba798c52ba862"
Commit cd112ea9 authored by wujipeng's avatar wujipeng
Browse files

init

parents
Pipeline #346 canceled with stages
package com.platform.business.service.impl;
import com.google.common.collect.Lists;
import com.platform.business.model.entity.ClassSubjectEntity;
import com.platform.business.model.vo.HomeVO;
import com.platform.business.service.ClassStudentService;
import com.platform.business.service.ClassSubjectService;
import com.platform.business.service.HomeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author : wujipeng
* @date : 2025/9/4 13:42
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class HomeServiceImpl implements HomeService {
@Resource
private ClassSubjectService classSubjectService;
@Resource
private ClassStudentService classStudentService;
@Override
public List<HomeVO> recentTrainingPlan() {
List<HomeVO> homeList = Lists.newArrayList();
//查询课程
List<ClassSubjectEntity> classSubjectList = classSubjectService.list();
classSubjectList.forEach(classSubject -> {
HomeVO homeVO = new HomeVO();
homeVO.setDate(classSubject.getDate());
homeVO.setName(classSubject.getSubjectName());
homeVO.setClassId(classSubject.getClassId());
homeList.add(homeVO);
});
//查询人数
List<HomeVO> classStudentList = classStudentService.selectTraineesNumber();
Map<Integer, Integer> classStudentMap = classStudentList.stream().collect(Collectors.toMap(HomeVO::getClassId, HomeVO::getTraineesNumber));
for (HomeVO homeVO : homeList) {
homeVO.setTraineesNumber(classStudentMap.getOrDefault(homeVO.getClassId(), 0));
}
return homeList;
}
@Override
public List<HomeVO> yearPlanComplete() {
List<HomeVO> homeList = Lists.newArrayList();
//实训班次
homeList.add(HomeVO.builder().name("实训班次").build());
//实训人数
homeList.add(HomeVO.builder().name("实训人数").build());
//实训项目
homeList.add(HomeVO.builder().name("实训项目").build());
return homeList;
}
@Override
public List<HomeVO> currentCourseSituation() {
return null;
}
@Override
public List<HomeVO> todayCourse() {
return classStudentService.todayCourse();
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.PaperDistributionMapper;
import com.platform.business.model.entity.PaperDistributionEntity;
import com.platform.business.service.PaperDistributionService;
import org.springframework.stereotype.Service;
/**
* @author : wujipeng
* @date : 2025/10/30 10:32
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class PaperDistributionServiceImpl extends ServiceImpl<PaperDistributionMapper, PaperDistributionEntity> implements PaperDistributionService {
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.PaperRuleMapper;
import com.platform.business.model.entity.PaperRuleEntity;
import com.platform.business.service.PaperRuleService;
import org.springframework.stereotype.Service;
/**
* @author : wujipeng
* @date : 2025/11/3 15:16
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class PaperRuleServiceImpl extends ServiceImpl<PaperRuleMapper, PaperRuleEntity> implements PaperRuleService {
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.platform.business.mapper.QuestionBankMapper;
import com.platform.business.model.dto.QuestionBankDTO;
import com.platform.business.model.entity.QuestionBankEntity;
import com.platform.business.model.entity.QuestionSecondEntity;
import com.platform.business.model.entity.QuestionThirdEntity;
import com.platform.business.model.vo.QuestionBankVO;
import com.platform.business.model.vo.QuestionSecondVO;
import com.platform.business.service.QuestionBankService;
import com.platform.business.service.QuestionSecondService;
import com.platform.business.service.QuestionThirdService;
import com.platform.business.utils.ExcelUtil;
import com.platform.model.resp.Result;
import com.platform.utils.DozerUtils;
import com.platform.utils.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class QuestionBankBankServiceImpl extends ServiceImpl<QuestionBankMapper, QuestionBankEntity> implements QuestionBankService {
@Resource
private QuestionSecondService questionSecondService;
@Resource
private QuestionThirdService questionThirdService;
@Override
public List<QuestionBankVO> queryList(QuestionBankDTO questionBankDTO) {
return baseMapper.queryList(questionBankDTO);
}
@Override
public QuestionBankVO detail(int id) {
QuestionBankEntity questionBankEntity = getById(id);
if (questionBankEntity == null) {
return null;
}
QuestionBankVO questionBankVO = DozerUtils.convertBean(questionBankEntity, QuestionBankVO.class);
//查看题目明细
List<QuestionSecondVO> questionSecondVOList = questionSecondService.queryByQuestionId(id);
questionBankVO.setQuestionSecondList(questionSecondVOList);
return questionBankVO;
}
@Override
public boolean updateThirdScore(QuestionThirdEntity questionThirdEntity) {
//查看三级题信息
QuestionThirdEntity questionThirdEntityNew = questionThirdService.getById(questionThirdEntity.getId());
if (questionThirdEntityNew == null) {
return false;
}
questionThirdEntityNew.setScore(questionThirdEntity.getScore());
return questionThirdService.updateById(questionThirdEntityNew);
}
@Override
public QuestionBankEntity getByNoAndLevel(String id, String level) {
return baseMapper.selectOne(new LambdaQueryWrapper<QuestionBankEntity>()
.eq(QuestionBankEntity::getNo, id)
.eq(QuestionBankEntity::getLevel, level));
}
@Override
@Transactional
public Result<Boolean> importExcel(MultipartFile file) {
//检查文件名结尾是否为xlsx
if (!Objects.requireNonNull(file.getOriginalFilename()).endsWith("xlsx")) {
return Result.fail("请上传xlsx文件");
}
Sheet sheet;
try (XSSFWorkbook workbook = new XSSFWorkbook(ExcelUtil.convertMultipartFileToFile(file))) {
sheet = workbook.getSheetAt(0);
List<QuestionBankEntity> questionAll = Lists.newArrayList();
List<QuestionBankEntity> questionBankList = Lists.newArrayList();
List<QuestionSecondEntity> questionSecondList = Lists.newArrayList();
List<QuestionThirdEntity> questionThirdList = Lists.newArrayList();
//解析数据
analysis(sheet, questionAll);
//保存一级题目
Map<String, Integer> oneIdMap = oneQuestion(questionAll, questionBankList);
//保存二级题目
Map<String, Integer> twoIdMap = twoQuestion(questionAll, questionSecondList, oneIdMap);
//保存三级题目
threeQuestion(questionAll, questionThirdList, oneIdMap, twoIdMap);
} catch (Exception e) {
return Result.fail("导入失败");
}
return Result.data(true, "导入成功");
}
@Transactional
public Map<String, Integer> oneQuestion(List<QuestionBankEntity> questionAll, List<QuestionBankEntity> questionBankList) {
for (QuestionBankEntity questionBankEntity : questionAll) {
if (!questionBankEntity.getNo().contains("-")) {
questionBankList.add(questionBankEntity);
}
}
saveBatch(questionBankList);
//转化成以编号为键,id为值的map
Map<String, Integer> result = Maps.newHashMap();
for (QuestionBankEntity questionBankEntity : questionBankList) {
result.put(questionBankEntity.getNo(), questionBankEntity.getId());
}
return result;
}
@Transactional
public Map<String, Integer> twoQuestion(List<QuestionBankEntity> questionAll, List<QuestionSecondEntity> questionSecondList, Map<String, Integer> oneIdMap) {
for (QuestionBankEntity questionBank : questionAll) {
if (questionBank.getNo().contains("-")) {
if (!questionBank.getNo().split("-")[1].contains(".")) {
QuestionSecondEntity questionSecond = new QuestionSecondEntity();
//一级id
oneIdMap.forEach((k, v) -> {
if (questionBank.getNo().startsWith(k)) {
questionSecond.setQuestionId(v);
}
});
//内容
questionSecond.setTitle(questionBank.getTitle());
//分数
questionSecond.setScore(questionBank.getScore());
//编号
questionSecond.setNo(questionBank.getNo());
questionSecondList.add(questionSecond);
}
}
}
questionSecondService.saveBatch(questionSecondList);
//转化成以编号为键,id为值的map
Map<String, Integer> result = Maps.newHashMap();
for (QuestionSecondEntity questionSecondEntity : questionSecondList) {
result.put(questionSecondEntity.getNo(), questionSecondEntity.getId());
}
return result;
}
@Transactional
public void threeQuestion(List<QuestionBankEntity> questionAll, List<QuestionThirdEntity> questionThirdList, Map<String, Integer> oneIdMap, Map<String, Integer> twoIdMap) {
for (QuestionBankEntity questionBank : questionAll) {
if (questionBank.getNo().contains("-")) {
if (questionBank.getNo().split("-")[1].contains(".")) {
QuestionThirdEntity questionThird = new QuestionThirdEntity();
//编号
questionThird.setNo(questionBank.getNo());
//一级id
oneIdMap.forEach((k, v) -> {
if (questionBank.getNo().startsWith(k)) {
questionThird.setQuestionId(v);
}
});
//二级id
twoIdMap.forEach((k, v) -> {
if (questionBank.getNo().startsWith(k)) {
questionThird.setQuestionSecondId(v);
}
});
//内容
questionThird.setTitle(questionBank.getTitle());
//分数
questionThird.setScore(questionBank.getScore());
//答案
questionThird.setAnswer(questionBank.getAnswer());
//属性
questionThird.setNature(questionBank.getNature());
questionThirdList.add(questionThird);
}
}
}
questionThirdService.saveBatch(questionThirdList);
}
private void analysis(Sheet sheet, List<QuestionBankEntity> questionBankList) {
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
QuestionBankEntity questionBank = new QuestionBankEntity();
Row row = sheet.getRow(i);
//等级
questionBank.setLevel(ExcelUtil.getCellValueAsString(row.getCell(0)));
//编号
questionBank.setNo(ExcelUtil.getCellValueAsString(row.getCell(1)));
//试题名称
questionBank.setName(ExcelUtil.getCellValueAsString(row.getCell(2)));
//考核时间
String time = ExcelUtil.getCellValueAsString(row.getCell(3));
if (StringUtils.isNotEmpty(time)) {
time = time.replace("min", "");
questionBank.setTime(Integer.parseInt(time));
}
//题目类型
questionBank.setType(ExcelUtil.getCellValueAsString(row.getCell(4)));
//题目场景
questionBank.setScene(ExcelUtil.getCellValueAsString(row.getCell(5)));
//试题内容
questionBank.setTitle(ExcelUtil.getCellValueAsString(row.getCell(6)));
//答案内容
questionBank.setAnswer(ExcelUtil.getCellValueAsString(row.getCell(7)));
//得分
String score = ExcelUtil.getCellValueAsString(row.getCell(8));
if (StringUtils.isNotEmpty(score)) {
questionBank.setScore(Integer.valueOf(score));
}
//属性
questionBank.setNature(ExcelUtil.getCellValueAsString(row.getCell(9)));
questionBankList.add(questionBank);
}
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.QuestionSecondMapper;
import com.platform.business.model.entity.QuestionSecondEntity;
import com.platform.business.model.entity.QuestionThirdEntity;
import com.platform.business.model.vo.QuestionSecondVO;
import com.platform.business.service.QuestionSecondService;
import com.platform.business.service.QuestionThirdService;
import com.platform.utils.DozerUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class QuestionSecondServiceImpl extends ServiceImpl<QuestionSecondMapper, QuestionSecondEntity> implements QuestionSecondService {
@Resource
private QuestionThirdService questionThirdService;
@Override
public List<QuestionSecondVO> queryByQuestionId(int id) {
List<QuestionSecondVO> questionSecondVOList = DozerUtils.convertList(baseMapper.selectList(new LambdaQueryWrapper<QuestionSecondEntity>()
.eq(QuestionSecondEntity::getQuestionId, id)), QuestionSecondVO.class);
List<QuestionThirdEntity> questionThirdEntityList = questionThirdService.queryByQuestionId(id);
questionSecondVOList.forEach(questionSecondVO -> questionThirdEntityList.forEach(questionThirdEntity -> {
if (questionSecondVO.getId() == questionThirdEntity.getQuestionSecondId()) {
questionSecondVO.getQuestionThirdList().add(questionThirdEntity);
}
}));
return questionSecondVOList;
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.QuestionThirdMapper;
import com.platform.business.model.entity.QuestionThirdEntity;
import com.platform.business.service.QuestionThirdService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class QuestionThirdServiceImpl extends ServiceImpl<QuestionThirdMapper, QuestionThirdEntity> implements QuestionThirdService {
@Override
public List<QuestionThirdEntity> queryByQuestionId(int id) {
return baseMapper.selectList(new LambdaQueryWrapper<QuestionThirdEntity>()
.eq(QuestionThirdEntity::getQuestionId, id));
}
@Override
public List<QuestionThirdEntity> selectListInQuestionNo(List<String> questionNos) {
return baseMapper.selectListInQuestionNo(questionNos);
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.platform.business.mapper.StudentLevelCertMapper;
import com.platform.business.model.dto.StudentLevelCertDTO;
import com.platform.business.model.entity.StudentLevelCertEntity;
import com.platform.business.model.vo.StudentLevelCertVO;
import com.platform.business.service.BsFileService;
import com.platform.business.service.StudentLevelCertService;
import com.platform.business.utils.ExcelUtil;
import com.platform.model.resp.Result;
import com.platform.utils.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@Service
public class StudentLevelCertServiceImpl extends ServiceImpl<StudentLevelCertMapper, StudentLevelCertEntity>
implements StudentLevelCertService {
@Resource
private BsFileService bsFileService;
@Override
public List<StudentLevelCertEntity> queryByIdCard(String idCard) {
return baseMapper.selectList(new LambdaQueryWrapper<StudentLevelCertEntity>()
.eq(StudentLevelCertEntity::getIdCard, idCard));
}
@Override
public List<StudentLevelCertVO> queryList(StudentLevelCertDTO studentLevelCertDTO) {
return baseMapper.queryList(studentLevelCertDTO);
}
@Override
@Transactional
public Result<Boolean> importExcel(MultipartFile file) {
List<StudentLevelCertEntity> studentLevelCertList = Lists.newArrayList();
try (XSSFWorkbook sheets = new XSSFWorkbook(ExcelUtil.convertMultipartFileToFile(file))) {
for (Sheet sheet : sheets) {
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (row == null) {
continue;
}
//判断是否有序号
String SerialNumber = ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(0));
if (StringUtils.isEmpty(SerialNumber)) {
continue;
}
StudentLevelCertEntity studentLevelCert = new StudentLevelCertEntity();
studentLevelCert.setOccupation(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(1)));
studentLevelCert.setWorkType(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(2)));
studentLevelCert.setLevel(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(3)));
studentLevelCert.setUserName(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(4)));
studentLevelCert.setIdCard(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(5)));
studentLevelCert.setCertNo(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(6)));
studentLevelCert.setId(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(6)));
studentLevelCert.setIssueDate(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(7)));
studentLevelCert.setNo(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(8)));
studentLevelCert.setIssueDept(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(9)));
studentLevelCert.setFactory(ExcelUtil.getCellValueAsString(sheet.getRow(i).getCell(10)));
studentLevelCertList.add(studentLevelCert);
}
}
} catch (IOException | InvalidFormatException e) {
throw new RuntimeException(e);
}
return Result.data(saveOrUpdateBatch(studentLevelCertList));
}
@Override
public Object detail(String id) {
// StudentLevelCertEntity studentLevelCert = getById(id);
// if (studentLevelCert != null && StringUtils.isNotEmpty(studentLevelCert.getCertImage())) {
// BsFileEntity bsFile = bsFileService.getById(studentLevelCert.getCertImage());
// studentLevelCert.setCertImageName(bsFile.getFileName());
// }
// return studentLevelCert;
return getById(id);
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.SysLevelMapper;
import com.platform.business.model.dto.SysLevelDTO;
import com.platform.business.model.entity.SysLevelEntity;
import com.platform.business.model.vo.SysLevelVO;
import com.platform.business.service.SysLevelService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysLevelServiceImpl extends ServiceImpl<SysLevelMapper, SysLevelEntity> implements SysLevelService {
@Override
public List<SysLevelVO> queryList(SysLevelDTO sysLevelDTO) {
return baseMapper.queryList(sysLevelDTO);
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.platform.business.mapper.SysMenuMapper;
import com.platform.business.model.entity.SysMenuEntity;
import com.platform.business.service.SysMenuService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenuEntity> implements SysMenuService {
@Override
public List<SysMenuEntity> queryList() {
//查询一级菜单
List<SysMenuEntity> one = list(new LambdaQueryWrapper<SysMenuEntity>().eq(SysMenuEntity::getLev, 1));
for (SysMenuEntity sysMenuEntity : one) {
sysMenuEntity.setChild(Lists.newArrayList());
}
Map<Integer, SysMenuEntity> oneMap = one.stream().collect(Collectors.toMap(SysMenuEntity::getId, SysMenuEntity -> SysMenuEntity));
//查询二级菜单
List<SysMenuEntity> two = list(new LambdaQueryWrapper<SysMenuEntity>().eq(SysMenuEntity::getLev, 2));
for (SysMenuEntity sysMenuEntity : two) {
sysMenuEntity.setChild(Lists.newArrayList());
}
Map<Integer, SysMenuEntity> twoMap = two.stream().collect(Collectors.toMap(SysMenuEntity::getId, SysMenuEntity -> SysMenuEntity));
//查询三级菜单
List<SysMenuEntity> third = list(new LambdaQueryWrapper<SysMenuEntity>().eq(SysMenuEntity::getLev, 3));
for (SysMenuEntity sysMenuEntity : third) {
if(twoMap.containsKey(sysMenuEntity.getParentId())){
twoMap.get(sysMenuEntity.getParentId()).getChild().add(sysMenuEntity);
}
}
for (SysMenuEntity sysMenuEntity : two) {
if(oneMap.containsKey(sysMenuEntity.getParentId())){
oneMap.get(sysMenuEntity.getParentId()).getChild().add(sysMenuEntity);
}
}
return one;
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.SysPhoneRoleMapper;
import com.platform.business.model.entity.SysPhoneRoleEntity;
import com.platform.business.service.SysPhoneRoleService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysPhoneRoleServiceImpl extends ServiceImpl<SysPhoneRoleMapper, SysPhoneRoleEntity> implements SysPhoneRoleService {
@Override
public List<SysPhoneRoleEntity> queryByPhone(String phone) {
return baseMapper.queryByPhone(phone);
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.SysRoleAndMenuMapper;
import com.platform.business.model.entity.SysRoleAndMenuEntity;
import com.platform.business.model.vo.SysRoleAndMenuVO;
import com.platform.business.service.SysRoleAndMenuService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysRoleAndMenuServiceImpl extends ServiceImpl<SysRoleAndMenuMapper, SysRoleAndMenuEntity> implements SysRoleAndMenuService {
@Override
public List<SysRoleAndMenuVO> queryByRoleId(int id) {
return baseMapper.queryByRoleId(id);
}
}
package com.platform.business.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.platform.business.mapper.SysRoleMapper;
import com.platform.business.model.dto.SysRoleDTO;
import com.platform.business.model.entity.SysRoleAndMenuEntity;
import com.platform.business.model.entity.SysRoleEntity;
import com.platform.business.model.entity.SysUserAndRoleEntity;
import com.platform.business.model.vo.SysRoleAndMenuVO;
import com.platform.business.model.vo.SysRoleVO;
import com.platform.business.service.SysRoleAndMenuService;
import com.platform.business.service.SysRoleService;
import com.platform.business.service.SysUserAndRoleService;
import com.platform.model.resp.Result;
import com.platform.utils.DozerUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity> implements SysRoleService {
@Resource
private SysRoleAndMenuService sysRoleAndMenuService;
@Resource
private SysUserAndRoleService sysUserAndRoleService;
@Override
public List<SysRoleVO> queryList(SysRoleDTO sysRoleDTO) {
return DozerUtils.convertList(baseMapper.selectList(new LambdaQueryWrapper<>()), SysRoleVO.class);
}
@Override
public boolean saveRole(SysRoleDTO sysRoleDTO) {
SysRoleEntity sysRoleEntity = sysRoleDTO;
saveOrUpdate(sysRoleEntity);
//处理角色权限
if (sysRoleDTO.getId() != null) {
//删除角色与权限关联
sysRoleAndMenuService.remove(new LambdaQueryWrapper<SysRoleAndMenuEntity>()
.eq(SysRoleAndMenuEntity::getRoleId, sysRoleDTO.getId()));
}
//保存角色权限关联
List<Integer> menuIdList = sysRoleDTO.getMenuIdList();
if (CollUtil.isNotEmpty(menuIdList)) {
//初始化角色与权限关联集合
List<SysRoleAndMenuEntity> sysRoleAndMenuEntityList = Lists.newArrayList();
menuIdList.forEach(menuId -> {
SysRoleAndMenuEntity sysRoleAndMenuEntity = new SysRoleAndMenuEntity();
sysRoleAndMenuEntity.setMenuId(menuId);
sysRoleAndMenuEntity.setRoleId(sysRoleDTO.getId());
sysRoleAndMenuEntityList.add(sysRoleAndMenuEntity);
});
sysRoleAndMenuService.saveBatch(sysRoleAndMenuEntityList);
}
return true;
}
@Override
public SysRoleVO detail(int id) {
SysRoleVO sysRoleVO = DozerUtils.convertBean(getById(id), SysRoleVO.class);
if (sysRoleVO != null) {
//查看角色关联的菜单
List<SysRoleAndMenuVO> sysRoleAndMenuVOList = sysRoleAndMenuService.queryByRoleId(id);
sysRoleVO.setSysRoleAndMenuList(sysRoleAndMenuVOList);
}
return sysRoleVO;
}
@Override
public Result<Object> delete(int id) {
//查看是否有关联的用户
List<SysUserAndRoleEntity> sysUserAndRoleEntityList = sysUserAndRoleService.queryByRoleId(id);
if (CollUtil.isNotEmpty(sysUserAndRoleEntityList)) {
return Result.fail("已有账号绑定此角色,不可删除");
}
return Result.data(this.remove(new LambdaQueryWrapper<SysRoleEntity>().eq(SysRoleEntity::getId, id)));
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.SysUserAndRoleMapper;
import com.platform.business.model.entity.SysUserAndRoleEntity;
import com.platform.business.service.SysUserAndRoleService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysUserAndRoleServiceimpl extends ServiceImpl<SysUserAndRoleMapper, SysUserAndRoleEntity> implements SysUserAndRoleService {
@Override
public List<SysUserAndRoleEntity> queryByRoleId(int id) {
return baseMapper.selectList(new LambdaQueryWrapper<SysUserAndRoleEntity>()
.eq(SysUserAndRoleEntity::getRoleId, id));
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TeacherTeachRecordMapper;
import com.platform.business.model.entity.TeacherTeachRecordEntity;
import com.platform.business.service.TeacherTeachRecordService;
import org.springframework.stereotype.Service;
/**
* @author : wujipeng
* @date : 2025/9/10 14:07
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class TeacherTeachRecordServiceImpl extends ServiceImpl<TeacherTeachRecordMapper, TeacherTeachRecordEntity> implements TeacherTeachRecordService {
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TeacherWorkRecordMapper;
import com.platform.business.model.entity.TeacherWorkRecordEntity;
import com.platform.business.service.TeacherWorkRecordService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TeacherWorkRecordServiceImpl extends ServiceImpl<TeacherWorkRecordMapper, TeacherWorkRecordEntity> implements TeacherWorkRecordService {
@Override
public List<TeacherWorkRecordEntity> queryByUserId(String id) {
return baseMapper.selectList(new LambdaQueryWrapper<TeacherWorkRecordEntity>()
.eq(TeacherWorkRecordEntity::getUserId, id));
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.platform.business.mapper.TheoreticalLibraryMapper;
import com.platform.business.model.dto.TheoreticalLibraryDTO;
import com.platform.business.model.entity.TheoreticalLibraryEntity;
import com.platform.business.model.entity.TheoreticalPaperDetailEntity;
import com.platform.business.model.entity.TheoreticalPracticeStudentSimulationDetailEntity;
import com.platform.business.model.vo.TheoreticalLibraryVO;
import com.platform.business.service.TheoreticalLibraryService;
import com.platform.exception.BusinessException;
import com.platform.model.resp.Result;
import com.platform.utils.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author : wujipeng
* @date : 2025/10/29 15:16
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibraryMapper, TheoreticalLibraryEntity> implements TheoreticalLibraryService {
@Override
public void removeDirtyData() {
baseMapper.removeDirtyData();
}
@Override
public List<TheoreticalLibraryEntity> randomData(String scope, String type, Integer count, String firstLevelName, String secondLevelName) {
return baseMapper.randomData(scope, type, count, firstLevelName, secondLevelName);
}
@Override
public List<TheoreticalPaperDetailEntity> randomQuestions(String scope, String type, Integer count, String firstLevelName, String secondLevelName) {
return baseMapper.randomQuestions(scope, type, count, firstLevelName, secondLevelName);
}
@Override
public List<TheoreticalPracticeStudentSimulationDetailEntity> randomQuestionsSimulation(String scope, String type, Integer count, String firstLevelName, String secondLevelName) {
return baseMapper.randomQuestionsSimulation(scope, type, count, firstLevelName, secondLevelName);
}
@Override
@Transactional
public Result<Boolean> importTheoreticalLibrary(MultipartFile file) throws IOException {
//判断是否是技能竞赛
String scope;
String prefix;
int codeLev = 0;
if (Objects.requireNonNull(file.getOriginalFilename()).contains("技能竞赛")) {
scope = "技能竞赛";
prefix = "J";
//删除原始旧数据
remove(new LambdaQueryWrapper<TheoreticalLibraryEntity>().eq(TheoreticalLibraryEntity::getScope, scope));
return handleJn(file, prefix, codeLev, scope);
} else {
//判断是污水还是污泥
prefix = Objects.requireNonNull(file.getOriginalFilename()).contains("污水") ? "S" : "N";
codeLev = getCodeLev(file);
//范围
scope = Objects.requireNonNull(file.getOriginalFilename()).contains("污水") ? "污水" : "污泥";
switch (codeLev) {
case 1:
scope = scope + "一级";
break;
case 2:
scope = scope + "二级";
break;
case 3:
scope = scope + "三级";
break;
case 4:
scope = scope + "四级";
break;
case 5:
scope = scope + "五级";
break;
default:
return Result.fail("文件名需包含污水/污泥(一级~五级)、技能竞赛");
}
//删除原始旧数据
remove(new LambdaQueryWrapper<TheoreticalLibraryEntity>().eq(TheoreticalLibraryEntity::getScope, scope));
return handleWsWn(file, prefix, codeLev, scope);
}
}
@Transactional
public Result<Boolean> handleJn(MultipartFile file, String prefix, int codeLev, String scope) throws IOException {
List<TheoreticalLibraryEntity> theoreticalLibraryList = Lists.newArrayList();
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
Sheet sheet = workbook.getSheetAt(0);
//题型区分 1 判断题 2 单选题 3 多选题
int typeTip = 0;
//类型
String type = null;
//判断题数量
int judgmentCount = 0;
//单择题数量
int singleCount = 0;
//多选题数量
int multipleCount = 0;
for (int i = 10; i <= sheet.getLastRowNum(); i++) {
//答案
String answer = null;
//问题
String problem = null;
//单选题选项
String optionA = null;
String optionB = null;
String optionC = null;
String optionD = null;
String optionE = null;
//是否是题目
boolean isProblem = false;
Row row = sheet.getRow(i);
if (row == null) continue;
//展示层级
int count = 0;
//第一列
String column1 = getCellValueAsString(row.getCell(0));
if (StringUtils.isNotEmpty(column1)) {
count++;
}
//第二列
String column2 = getCellValueAsString(row.getCell(1));
if (StringUtils.isNotEmpty(column2)) {
count++;
}
//第三列
String column3 = getCellValueAsString(row.getCell(2));
if (StringUtils.isNotEmpty(column3)) {
count++;
}
//第四列
String column4 = getCellValueAsString(row.getCell(3));
if (StringUtils.isNotEmpty(column4)) {
count++;
}
//第五列
String column5 = getCellValueAsString(row.getCell(4));
if(i >= 1668){
System.out.println(i + ":" + column5);
}
//序号
String sequence = (column1 + column2 + column3 + column4).replaceAll("null", "");
//判断题型
if (column5.contains("判断题")) {
typeTip = 1;
type = "判断题";
} else if (column5.contains("单选题")) {
typeTip = 2;
type = "单选题";
} else if (column5.contains("多选题")) {
typeTip = 3;
type = "多选题";
} else {
isProblem = true;
if (typeTip == 1) {
answer = column5.contains("√") ? "√" : "×";
problem = column5.replaceAll("(" + answer + ")", "");
judgmentCount++;
} else if (typeTip == 2) {
singleCount++;
//获取单选题答案
answer = singleAnswer(column5);
if (StringUtils.isNotEmpty(answer)) {
problem = column5.replaceAll("(" + answer + ")", "( )");
if(ObjectUtils.isEmpty(sheet.getRow(i + 1))){
continue;
}
//拿到下一行内容并且跳过下一轮
String stringCellValue = getCellValueAsString(sheet.getRow(++i).getCell(4));
if (StringUtils.isNotEmpty(stringCellValue)) {
String replace = stringCellValue.replace("(A)", "").replace("(B)", "&&")
.replace("(C)", "&&").replace("(D)", "&&").replace(" ", "");
String[] split = replace.split("&&");
if (split.length == 4) {
optionD = split[3].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 3) {
optionC = split[2].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 2) {
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 1) {
optionA = split[0].replaceAll("\r\n?|\n", "");
}
}
}
} else if (typeTip == 3) {
multipleCount++;
//获取多选题答案
answer = multipleAnswer(column5);
if (StringUtils.isNotBlank(answer)) {
problem = column5.replaceAll("(" + answer + ")", "( )");
if(ObjectUtils.isEmpty(sheet.getRow(i + 1))){
continue;
}
//拿到下一行内容并且跳过下一轮
String stringCellValue = getCellValueAsString(sheet.getRow(++i).getCell(4));
String replace = stringCellValue.replace("(A)", "").replace("(B)", "&&")
.replace("(C)", "&&").replace("(D)", "&&").replace("(E)", "&&").replace(" ", "");
String[] split = replace.split("&&");
if (split.length == 5) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionD = split[3].replaceAll("\r\n?|\n", "");
optionE = split[4].replaceAll("\r\n?|\n", "");
} else if (split.length == 4) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionD = split[3].replaceAll("\r\n?|\n", "");
} else if (split.length == 3) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
} else if (split.length == 2) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
} else if (split.length == 1) {
optionA = split[0].replaceAll("\r\n?|\n", "");
}
}
}
}
//组装编号
String code = null;
if (StringUtils.isNotEmpty(type) && "判断题".equals(type) && isProblem) {
code = prefix + codeLev + "-" + typeTip + "." + judgmentCount;
} else if (StringUtils.isNotEmpty(type) && "单选题".equals(type) && isProblem) {
code = prefix + codeLev + "-" + typeTip + "." + singleCount;
} else if (StringUtils.isNotEmpty(type) && "多选题".equals(type) && isProblem) {
code = prefix + codeLev + "-" + typeTip + "." + multipleCount;
}
theoreticalLibraryList.add(TheoreticalLibraryEntity.builder()
.scope(scope)
.isProblem(isProblem)
.lev(count)
.sequence(sequence)
.code(code)
.firstLevelName("工业废水处理")
.secondLevelName("技能竞赛")
.thirdLevelName("废水处理技能竞赛")
.fourthLevelName("选拔赛")
.type(type)
.problem(problem)
.answer(answer)
.optionA(optionA)
.optionB(optionB)
.optionC(optionC)
.optionD(optionD)
.optionE(optionE)
.build());
}
saveBatch(theoreticalLibraryList);
//删除脏数据
removeDirtyData();
return Result.success("导入成功");
}
}
@Transactional
public Result<Boolean> handleWsWn(MultipartFile file, String prefix, int codeLev, String scope) throws IOException {
String firstLevelName = null;
String secondLevelName = null;
String thirdLevelName = null;
String fourthLevelName = null;
List<TheoreticalLibraryEntity> theoreticalLibraryList = Lists.newArrayList();
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
Sheet sheet = workbook.getSheetAt(0);
//题型区分 1 判断题 2 单选题 3 多选题
int typeTip = 0;
//类型
String type = null;
//判断题数量
int judgmentCount = 0;
//单择题数量
int singleCount = 0;
//多选题数量
int multipleCount = 0;
//code中心组成部分
String codeCenter = null;
for (int i = 4; i <= sheet.getLastRowNum(); i++) {
//答案
String answer = null;
//问题
String problem = null;
//单选题选项
String optionA = null;
String optionB = null;
String optionC = null;
String optionD = null;
String optionE = null;
//是否是题目
boolean isProblem = false;
Row row = sheet.getRow(i);
if (row == null) continue;
//展示层级
int count = 0;
//第一列
String column1 = getCellValueAsString(row.getCell(0));
if (StringUtils.isNotEmpty(column1)) {
count++;
}
//第二列
String column2 = getCellValueAsString(row.getCell(1));
if (StringUtils.isNotEmpty(column2)) {
count++;
}
//第三列
String column3 = getCellValueAsString(row.getCell(2));
if (StringUtils.isNotEmpty(column3)) {
count++;
}
//第四列
String column4 = getCellValueAsString(row.getCell(3));
if (StringUtils.isNotEmpty(column4)) {
count++;
}
//第五列
String column5 = getCellValueAsString(row.getCell(4));
//序号
String sequence = (column1 + column2 + column3 + column4).replaceAll("null", "");
//一到四级名称
if (count == 1) {
firstLevelName = column5;
secondLevelName = null;
thirdLevelName = null;
fourthLevelName = null;
type = null;
} else if (count == 2) {
secondLevelName = column5;
thirdLevelName = null;
fourthLevelName = null;
type = null;
} else if (count == 3) {
thirdLevelName = column5;
fourthLevelName = null;
type = null;
} else if (count == 4) {
fourthLevelName = column5;
type = null;
codeCenter = sequence;
judgmentCount = 0;
singleCount = 0;
multipleCount = 0;
} else {
//判断题型
if (column5.contains("判断题")) {
typeTip = 1;
type = "判断题";
} else if (column5.contains("单选题")) {
typeTip = 2;
type = "单选题";
} else if (column5.contains("多选题")) {
typeTip = 3;
type = "多选题";
} else {
isProblem = true;
if (typeTip == 1) {
answer = column5.contains("√") ? "√" : "×";
problem = column5.replaceAll("(" + answer + ")", "");
judgmentCount++;
} else if (typeTip == 2) {
singleCount++;
//获取单选题答案
answer = singleAnswer(column5);
if (StringUtils.isNotEmpty(answer)) {
problem = column5.replaceAll("(" + answer + ")", "( )");
//拿到下一行内容并且跳过下一轮
String stringCellValue = getCellValueAsString(sheet.getRow(++i).getCell(4));
System.out.println("单选题答案--------------" + stringCellValue);
if (StringUtils.isNotEmpty(stringCellValue)) {
String replace = stringCellValue.replace("(A)", "").replace("(B)", "&&")
.replace("(C)", "&&").replace("(D)", "&&").replace(" ", "");
String[] split = replace.split("&&");
if (split.length == 4) {
optionD = split[3].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 3) {
optionC = split[2].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 2) {
optionB = split[1].replaceAll("\r\n?|\n", "");
optionA = split[0].replaceAll("\r\n?|\n", "");
} else if (split.length == 1) {
optionA = split[0].replaceAll("\r\n?|\n", "");
}
}
}
} else if (typeTip == 3) {
multipleCount++;
//获取多选题答案
answer = multipleAnswer(column5);
if (StringUtils.isNotBlank(answer)) {
problem = column5.replaceAll("(" + answer + ")", "( )");
//拿到下一行内容并且跳过下一轮
String stringCellValue = getCellValueAsString(sheet.getRow(++i).getCell(4));
System.out.println("多选题答案--------------" + stringCellValue);
String replace = stringCellValue.replace("(A)", "").replace("(B)", "&&")
.replace("(C)", "&&").replace("(D)", "&&").replace("(E)", "&&").replace(" ", "");
String[] split = replace.split("&&");
if (split.length == 5) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionD = split[3].replaceAll("\r\n?|\n", "");
optionE = split[4].replaceAll("\r\n?|\n", "");
} else if (split.length == 4) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
optionD = split[3].replaceAll("\r\n?|\n", "");
} else if (split.length == 3) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
optionC = split[2].replaceAll("\r\n?|\n", "");
} else if (split.length == 2) {
optionA = split[0].replaceAll("\r\n?|\n", "");
optionB = split[1].replaceAll("\r\n?|\n", "");
} else if (split.length == 1) {
optionA = split[0].replaceAll("\r\n?|\n", "");
}
}
}
}
}
//组装编号
String code = null;
if (StringUtils.isNotEmpty(type) && "判断题".equals(type) && isProblem) {
code = prefix + codeLev + codeCenter + "-" + typeTip + "." + judgmentCount;
} else if (StringUtils.isNotEmpty(type) && "单选题".equals(type) && isProblem) {
code = prefix + codeLev + codeCenter + "-" + typeTip + "." + singleCount;
} else if (StringUtils.isNotEmpty(type) && "多选题".equals(type) && isProblem) {
code = prefix + codeLev + codeCenter + "-" + typeTip + "." + multipleCount;
}
theoreticalLibraryList.add(TheoreticalLibraryEntity.builder()
.scope(scope)
.isProblem(isProblem)
.lev(count)
.sequence(sequence)
.code(code)
.firstLevelName(firstLevelName)
.secondLevelName(secondLevelName)
.thirdLevelName(thirdLevelName)
.fourthLevelName(fourthLevelName)
.type(type)
.problem(problem)
.answer(answer)
.optionA(optionA)
.optionB(optionB)
.optionC(optionC)
.optionD(optionD)
.optionE(optionE)
.build());
}
saveBatch(theoreticalLibraryList);
//删除脏数据
removeDirtyData();
return Result.success("导入成功");
}
}
private String multipleAnswer(String column5) {
// 定义正则表达式匹配中文括号内的A-E字母组合
Pattern pattern = Pattern.compile("(([A-E]+))");
Matcher matcher = pattern.matcher(column5);
if (matcher.find()) {
return matcher.group(1);
} else {
return "";
}
}
@Override
public List<TheoreticalLibraryVO> pageData(TheoreticalLibraryDTO theoreticalLibraryDTO) {
return baseMapper.pageData(theoreticalLibraryDTO);
}
@Override
public Boolean updateData(TheoreticalLibraryDTO theoreticalLibraryDTO) {
//判断类型
if (theoreticalLibraryDTO.getType().equals("判断题") || theoreticalLibraryDTO.getType().equals("主观题")) {
return updateById(theoreticalLibraryDTO);
} else {
String problem = theoreticalLibraryDTO.getProblem();
// String[] split = problem.split("\r\n");
String[] split = problem.split("\n");
if (split.length > 4) {
TheoreticalLibraryEntity theoreticalLibrary = new TheoreticalLibraryEntity();
theoreticalLibrary.setId(theoreticalLibraryDTO.getId());
theoreticalLibrary.setScope(theoreticalLibraryDTO.getScope());
theoreticalLibrary.setFirstLevelName(theoreticalLibraryDTO.getFirstLevelName());
theoreticalLibrary.setSecondLevelName(theoreticalLibraryDTO.getSecondLevelName());
theoreticalLibrary.setThirdLevelName(theoreticalLibraryDTO.getThirdLevelName());
theoreticalLibrary.setFourthLevelName(theoreticalLibraryDTO.getFourthLevelName());
theoreticalLibrary.setType(theoreticalLibraryDTO.getType());
theoreticalLibrary.setCode(theoreticalLibraryDTO.getCode());
theoreticalLibrary.setProblem(split[0]);
theoreticalLibrary.setOptionA(split[1].replaceFirst("A.", ""));
theoreticalLibrary.setOptionB(split[2].replaceFirst("B.", ""));
theoreticalLibrary.setOptionC(split[3].replaceFirst("C.", ""));
theoreticalLibrary.setOptionD(split[4].replaceFirst("D.", ""));
theoreticalLibrary.setAnswer(theoreticalLibraryDTO.getAnswer());
theoreticalLibrary.setParticipate(theoreticalLibraryDTO.getParticipate());
return updateById(theoreticalLibrary);
} else {
throw new BusinessException("请检查修改过后的试题内容");
}
}
}
@Override
public void export(TheoreticalLibraryDTO theoreticalLibraryDTO, HttpServletResponse response) {
List<TheoreticalLibraryVO> theoreticalLibraryList = pageData(theoreticalLibraryDTO);
// 设置响应头
setupResponseHeader(response);
// 创建工作簿和工作表
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet1");
//表头样式
CellStyle headerStyle = createHeaderStyle(workbook);
//数据行样式
CellStyle dataStyle = createDataStyle(workbook);
//特殊数据行样式
CellStyle specialDataStyle = createSpecialDataStyle(workbook);
//表头
createHeaderRow(sheet, headerStyle);
//填充数据行
fillDataRows(sheet, dataStyle, specialDataStyle, theoreticalLibraryList);
//调整列宽
autoSizeColumns(sheet);
//写入响应流
writeToResponse(workbook, response);
}
@Override
public List<TheoreticalLibraryEntity> groupByChapter(String level) {
return baseMapper.groupByChapter(level);
}
private void setupResponseHeader(HttpServletResponse response) {
try {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("理论题.xlsx", StandardCharsets.UTF_8.toString()));
} catch (Exception e) {
throw new RuntimeException("设置响应头失败", e);
}
}
private CellStyle createHeaderStyle(Workbook workbook) {
Font font = workbook.createFont();
font.setBold(true);
CellStyle style = workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setWrapText(true);
return style;
}
private CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setWrapText(true);
return style;
}
private CellStyle createSpecialDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setWrapText(true);
return style;
}
private void createHeaderRow(Sheet sheet, CellStyle headerStyle) {
Row headerRow = sheet.createRow(0);
String[] headers = {"等级", "章", "节", "目", "点", "题型", "试题编号", "试题内容", "答案"};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(headerStyle);
}
}
private void fillDataRows(Sheet sheet, CellStyle dataStyle, CellStyle specialDataStyle, List<TheoreticalLibraryVO> theoreticalLibraryList) {
int rowNum = 1;
for (TheoreticalLibraryVO theoreticalLibrary : theoreticalLibraryList) {
Row row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(theoreticalLibrary.getScope());
row.createCell(1).setCellValue(theoreticalLibrary.getFirstLevelName());
row.createCell(2).setCellValue(theoreticalLibrary.getSecondLevelName());
row.createCell(3).setCellValue(theoreticalLibrary.getThirdLevelName());
row.createCell(4).setCellValue(theoreticalLibrary.getFourthLevelName());
row.createCell(5).setCellValue(theoreticalLibrary.getType());
row.createCell(6).setCellValue(theoreticalLibrary.getCode());
row.createCell(7).setCellValue(theoreticalLibrary.getProblem());
row.createCell(8).setCellValue(theoreticalLibrary.getAnswer());
// 应用样式到所有单元格
row.getCell(0).setCellStyle(dataStyle);
row.getCell(1).setCellStyle(dataStyle);
row.getCell(2).setCellStyle(dataStyle);
row.getCell(3).setCellStyle(dataStyle);
row.getCell(4).setCellStyle(dataStyle);
row.getCell(5).setCellStyle(dataStyle);
row.getCell(6).setCellStyle(dataStyle);
row.getCell(7).setCellStyle(specialDataStyle);
row.getCell(8).setCellStyle(dataStyle);
}
}
private void autoSizeColumns(Sheet sheet) {
sheet.setColumnWidth(0, 14 * 256);
sheet.setColumnWidth(1, 14 * 256);
sheet.setColumnWidth(2, 14 * 256);
sheet.setColumnWidth(3, 14 * 256);
sheet.setColumnWidth(4, 14 * 256);
sheet.setColumnWidth(5, 14 * 256);
sheet.setColumnWidth(6, 14 * 256);
sheet.setColumnWidth(7, 42 * 256);
sheet.setColumnWidth(8, 14 * 256);
}
private void writeToResponse(Workbook workbook, HttpServletResponse response) {
try {
workbook.write(response.getOutputStream());
workbook.close();
} catch (IOException e) {
throw new RuntimeException("写入响应流失败", e);
}
}
private static String singleAnswer(String column5) {
char[] charArray = column5.toCharArray();
if (charArray.length == 0) {
return null;
}
int answerIndex = 0;
for (int i = 0; i < charArray.length; i++) {
if (String.valueOf(charArray[i]).equals("(")) {
answerIndex = i + 1;
}
}
return String.valueOf(charArray[answerIndex]);
}
private static int getCodeLev(MultipartFile file) {
int codeLev = 0;
if (Objects.requireNonNull(file.getOriginalFilename()).contains("一级")) {
codeLev = 1;
} else if (Objects.requireNonNull(file.getOriginalFilename()).contains("二级")) {
codeLev = 2;
} else if (Objects.requireNonNull(file.getOriginalFilename()).contains("三级")) {
codeLev = 3;
} else if (Objects.requireNonNull(file.getOriginalFilename()).contains("四级")) {
codeLev = 4;
} else if (Objects.requireNonNull(file.getOriginalFilename()).contains("五级")) {
codeLev = 5;
}
return codeLev;
}
public static String getCellValueAsString(Cell cell) {
if (cell == null) {
return "";
}
DataFormatter formatter = new DataFormatter();
return formatter.formatCellValue(cell);
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TheoreticalPaperDetailMapper;
import com.platform.business.model.entity.TheoreticalPaperDetailEntity;
import com.platform.business.service.TheoreticalPaperDetailService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : wujipeng
* @date : 2025/11/3 16:53
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class TheoreticalPaperDetailServiceImpl extends ServiceImpl<TheoreticalPaperDetailMapper, TheoreticalPaperDetailEntity> implements TheoreticalPaperDetailService {
@Override
public List<TheoreticalPaperDetailEntity> selectDisorderly(String paperId) {
return baseMapper.selectDisorderly(paperId);
}
}
package com.platform.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TheoreticalPaperMapper;
import com.platform.business.model.dto.CombinationDTO;
import com.platform.business.model.dto.TheoreticalPaperDTO;
import com.platform.business.model.entity.PaperDistributionEntity;
import com.platform.business.model.entity.PaperRuleEntity;
import com.platform.business.model.entity.TheoreticalPaperDetailEntity;
import com.platform.business.model.entity.TheoreticalPaperEntity;
import com.platform.business.model.vo.CombinationVO;
import com.platform.business.model.vo.TheoreticalPaperVO;
import com.platform.business.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author : wujipeng
* @date : 2025/11/3 14:11
* @Version: 1.0
* @Desc : 描述信息
*/
@Slf4j
@Service
public class TheoreticalPaperServiceImpl extends ServiceImpl<TheoreticalPaperMapper, TheoreticalPaperEntity> implements TheoreticalPaperService {
@Resource
private PaperDistributionService paperDistributionService;
@Resource
private PaperRuleService paperRuleService;
@Resource
private TheoreticalLibraryService theoreticalLibraryService;
@Resource
private TheoreticalPaperDetailService theoreticalPaperDetailService;
@Override
public List<TheoreticalPaperVO> pageData(TheoreticalPaperDTO theoreticalPaperDTO) {
return baseMapper.pageData(theoreticalPaperDTO);
}
@Override
public CombinationVO auto(String lev) {
//判断题数量
int judgmentCount = 0;
//单选题数量
int singleCount = 0;
//多选题数量
int moreCount = 0;
//试题数量
int num = 0;
//试题总分
double sum = 0;
CombinationVO combination = new CombinationVO();
//配分规则
List<PaperRuleEntity> paperRuleList = paperRuleService.list(new LambdaQueryWrapper<PaperRuleEntity>().eq(PaperRuleEntity::getLev, lev));
Map<String, PaperRuleEntity> paperRuleMap = paperRuleList.stream().collect(Collectors.toMap(PaperRuleEntity::getType, PaperRuleEntity -> PaperRuleEntity));
//试题分布
List<PaperDistributionEntity> paperDistributionList = paperDistributionService.list(new LambdaQueryWrapper<PaperDistributionEntity>().eq(PaperDistributionEntity::getLev, lev));
for (PaperDistributionEntity paperDistribution : paperDistributionList) {
judgmentCount += paperDistribution.getJudgmentCount();
singleCount += paperDistribution.getSingleCount();
moreCount += paperDistribution.getMoreCount();
//试题数量
paperDistribution.setSum(paperDistribution.getJudgmentCount() + paperDistribution.getSingleCount() + paperDistribution.getMoreCount());
//配分小计
paperDistribution.setTotal(0.0);
if (paperRuleMap.containsKey("判断题")) {
paperDistribution.setTotal(paperDistribution.getJudgmentCount() * paperRuleMap.get("判断题").getEachQuestion());
}
if (paperRuleMap.containsKey("单选题")) {
paperDistribution.setTotal(paperDistribution.getTotal() + paperDistribution.getSingleCount() * paperRuleMap.get("单选题").getEachQuestion());
}
if (paperRuleMap.containsKey("多选题")) {
paperDistribution.setTotal(paperDistribution.getTotal() + paperDistribution.getMoreCount() * paperRuleMap.get("多选题").getEachQuestion());
}
}
combination.setPaperDistributionList(paperDistributionList);
for (PaperRuleEntity paperRuleEntity : paperRuleList) {
switch (paperRuleEntity.getType()) {
case "判断题":
paperRuleEntity.setNum(judgmentCount);
paperRuleEntity.setTotal(judgmentCount * paperRuleEntity.getEachQuestion());
num += judgmentCount;
break;
case "单选题":
paperRuleEntity.setNum(singleCount);
paperRuleEntity.setTotal(singleCount * paperRuleEntity.getEachQuestion());
num += singleCount;
break;
case "多选题":
paperRuleEntity.setNum(moreCount);
paperRuleEntity.setTotal(moreCount * paperRuleEntity.getEachQuestion());
num += moreCount;
break;
}
sum += paperRuleEntity.getTotal();
}
combination.setPaperRuleList(paperRuleList);
combination.setNum(num);
combination.setSum(sum);
return combination;
}
@Override
@Transactional
public Boolean create(CombinationDTO combinationDTO) {
List<PaperRuleEntity> paperRuleList = paperRuleService.list(new LambdaQueryWrapper<PaperRuleEntity>().eq(PaperRuleEntity::getLev, combinationDTO.getLev()));
Map<String, Double> paperRuleMap = paperRuleList.stream().collect(Collectors.toMap(PaperRuleEntity::getType, PaperRuleEntity::getEachQuestion));
//生成试卷主体
TheoreticalPaperEntity theoreticalPaper = new TheoreticalPaperEntity();
theoreticalPaper.setLev(combinationDTO.getLev());
theoreticalPaper.setName(combinationDTO.getName());
theoreticalPaper.setNum(combinationDTO.getNum());
theoreticalPaper.setSum(combinationDTO.getSum());
theoreticalPaper.setCreateType("自动组卷");
theoreticalPaper.setCreateUser(combinationDTO.getCreateUser());
theoreticalPaper.setCreateTime(new Date());
theoreticalPaper.setSequence(combinationDTO.getSequence());
save(theoreticalPaper);
//获取试题分布
List<PaperDistributionEntity> paperDistributionList = combinationDTO.getPaperDistributionList();
List<TheoreticalPaperDetailEntity> judgmentActual = randomQuestions(paperDistributionList, "判断题");
List<TheoreticalPaperDetailEntity> choiceActual = randomQuestions(paperDistributionList, "单选题");
List<TheoreticalPaperDetailEntity> moreActual = randomQuestions(paperDistributionList, "多选题");
judgmentActual.addAll(choiceActual);
judgmentActual.addAll(moreActual);
for (TheoreticalPaperDetailEntity theoreticalPaperDetailEntity : judgmentActual) {
theoreticalPaperDetailEntity.setPaperId(theoreticalPaper.getId());
theoreticalPaperDetailEntity.setScore(paperRuleMap.get(theoreticalPaperDetailEntity.getType()));
}
theoreticalPaperDetailService.saveBatch(judgmentActual);
return true;
}
@Override
public TheoreticalPaperVO detail(String id) {
TheoreticalPaperEntity theoreticalPaperEntity = getById(id);
TheoreticalPaperVO theoreticalPaperVO = BeanUtil.copyProperties(theoreticalPaperEntity, TheoreticalPaperVO.class);
List<TheoreticalPaperDetailEntity> theoreticalPaperDetailList = theoreticalPaperDetailService
.list(new LambdaQueryWrapper<TheoreticalPaperDetailEntity>().eq(TheoreticalPaperDetailEntity::getPaperId, id));
theoreticalPaperVO.setTheoreticalPaperDetailList(theoreticalPaperDetailList);
return theoreticalPaperVO;
}
@Override
public void export(String id, HttpServletResponse response) {
TheoreticalPaperEntity theoreticalPaper = getById(id);
List<TheoreticalPaperDetailEntity> theoreticalPaperDetailList = theoreticalPaperDetailService.list(new LambdaQueryWrapper<TheoreticalPaperDetailEntity>().eq(TheoreticalPaperDetailEntity::getPaperId, id));
String lev = theoreticalPaper.getLev();
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(lev + ".docx")) {
if (inputStream == null) {
log.error("资源文件未找到: " + lev + ".docx");
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
//读取Word文档
XWPFDocument document = new XWPFDocument(inputStream);
//分流数据
List<TheoreticalPaperDetailEntity> judgmentData = Lists.newArrayList();
List<TheoreticalPaperDetailEntity> choiceData = Lists.newArrayList();
List<TheoreticalPaperDetailEntity> moreData = Lists.newArrayList();
for (TheoreticalPaperDetailEntity theoreticalPaperDetail : theoreticalPaperDetailList) {
if ("判断题".equals(theoreticalPaperDetail.getType())) {
judgmentData.add(theoreticalPaperDetail);
} else if ("单选题".equals(theoreticalPaperDetail.getType())) {
choiceData.add(theoreticalPaperDetail);
} else if ("多选题".equals(theoreticalPaperDetail.getType())) {
moreData.add(theoreticalPaperDetail);
}
}
//替换占位符内容
String judgmentActual = generateJudgmentContent(judgmentData);
String choiceActual = generateChoiceContent(choiceData, judgmentData.size());
String moreActual = generateMoreContent(moreData, judgmentData.size() + choiceData.size());
replacePlaceholder(document, "{judgment}", judgmentActual);
replacePlaceholder(document, "{choice}", choiceActual);
replacePlaceholder(document, "{more}", moreActual);
// 设置响应头
String fileName = URLEncoder.encode("污水处理工(城镇" + lev.substring(0, 2) + "处理工)(" + lev.substring(2) + ")理论知识试卷.docx", "UTF-8");
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setCharacterEncoding("UTF-8");
// 输出文档到响应流
try (OutputStream outputStream = response.getOutputStream()) {
document.write(outputStream);
outputStream.flush();
}
document.close();
log.info("试卷导出成功");
} catch (IOException e) {
log.error("导出试卷失败", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
throw new RuntimeException("导出试卷失败", e);
}
}
private String generateMoreContent(List<TheoreticalPaperDetailEntity> moreData, Integer startNum) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < moreData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add(i + startNum + 1 + ". " + moreData.get(i).getProblem());
stringJoiner.add(" A、" + moreData.get(i).getOptionA());
stringJoiner.add(" B、" + moreData.get(i).getOptionB());
stringJoiner.add(" C、" + moreData.get(i).getOptionC());
stringJoiner.add(" D、" + moreData.get(i).getOptionD());
stringJoiner.add(" E、" + moreData.get(i).getOptionE());
}
return stringJoiner.toString();
}
private String generateMoreContentWithAnswer(List<TheoreticalPaperDetailEntity> moreData, Integer startNum) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < moreData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add(i + startNum + 1 + ". " + moreData.get(i).getProblem().replace("( )", "( " + moreData.get(i).getAnswer() + " )"));
stringJoiner.add(" A、" + moreData.get(i).getOptionA());
stringJoiner.add(" B、" + moreData.get(i).getOptionB());
stringJoiner.add(" C、" + moreData.get(i).getOptionC());
stringJoiner.add(" D、" + moreData.get(i).getOptionD());
stringJoiner.add(" E、" + moreData.get(i).getOptionE());
}
return stringJoiner.toString();
}
@Override
public void exportWithAnswer(String id, HttpServletResponse response) {
TheoreticalPaperEntity theoreticalPaper = getById(id);
List<TheoreticalPaperDetailEntity> theoreticalPaperDetailList = theoreticalPaperDetailService.list(new LambdaQueryWrapper<TheoreticalPaperDetailEntity>().eq(TheoreticalPaperDetailEntity::getPaperId, id));
String lev = theoreticalPaper.getLev();
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(lev + ".docx")) {
if (inputStream == null) {
log.error("资源文件未找到: " + lev + ".docx");
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
// 读取Word文档
XWPFDocument document = new XWPFDocument(inputStream);
//分流数据
List<TheoreticalPaperDetailEntity> judgmentData = Lists.newArrayList();
List<TheoreticalPaperDetailEntity> choiceData = Lists.newArrayList();
List<TheoreticalPaperDetailEntity> moreData = Lists.newArrayList();
for (TheoreticalPaperDetailEntity theoreticalPaperDetail : theoreticalPaperDetailList) {
if ("判断题".equals(theoreticalPaperDetail.getType())) {
judgmentData.add(theoreticalPaperDetail);
} else if ("单选题".equals(theoreticalPaperDetail.getType())) {
choiceData.add(theoreticalPaperDetail);
} else if ("多选题".equals(theoreticalPaperDetail.getType())) {
moreData.add(theoreticalPaperDetail);
}
}
// 替换占位符内容
String judgmentActual = generateJudgmentContentWithAnswer(judgmentData);
String choiceActual = generateChoiceContentWithAnswer(choiceData, judgmentData.size());
String moreActual = generateMoreContentWithAnswer(moreData, judgmentData.size() + choiceData.size());
replacePlaceholder(document, "{judgment}", judgmentActual);
replacePlaceholder(document, "{choice}", choiceActual);
replacePlaceholder(document, "{more}", moreActual);
// 设置响应头
String fileName = URLEncoder.encode("污水处理工(城镇" + lev.substring(0, 2) + "处理工)(" + lev.substring(2) + ")理论知识试卷答案.docx", "UTF-8");
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setCharacterEncoding("UTF-8");
// 输出文档到响应流
try (OutputStream outputStream = response.getOutputStream()) {
document.write(outputStream);
outputStream.flush();
}
document.close();
log.info("试卷导出成功");
} catch (IOException e) {
log.error("导出试卷失败", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
throw new RuntimeException("导出试卷失败", e);
}
}
@Override
public Boolean delete(String id) {
removeById(id);
return theoreticalPaperDetailService.remove(new LambdaQueryWrapper<TheoreticalPaperDetailEntity>().eq(TheoreticalPaperDetailEntity::getPaperId, id));
}
/**
* 生成判断题内容
*/
private String generateJudgmentContent(List<TheoreticalPaperDetailEntity> judgmentData) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < judgmentData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add("( ) " + (i + 1) + "." + judgmentData.get(i).getProblem());
}
return stringJoiner.toString();
}
/**
* 生成带答案的判断题内容
*/
private String generateJudgmentContentWithAnswer(List<TheoreticalPaperDetailEntity> judgmentData) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < judgmentData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add("( " + judgmentData.get(i).getAnswer() + " ) " + (i + 1) + "." + judgmentData.get(i).getProblem());
}
return stringJoiner.toString();
}
/**
* 生成选择题内容
*/
private String generateChoiceContent(List<TheoreticalPaperDetailEntity> choiceData, Integer startNum) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < choiceData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add(i + startNum + 1 + ". " + choiceData.get(i).getProblem());
stringJoiner.add(" A、" + choiceData.get(i).getOptionA());
stringJoiner.add(" B、" + choiceData.get(i).getOptionB());
stringJoiner.add(" C、" + choiceData.get(i).getOptionC());
stringJoiner.add(" D、" + choiceData.get(i).getOptionD());
}
return stringJoiner.toString();
}
/**
* 生成带答案的选择题内容
*/
private String generateChoiceContentWithAnswer(List<TheoreticalPaperDetailEntity> choiceData, Integer startNum) {
StringJoiner stringJoiner = new StringJoiner("\r\n");
for (int i = 0; i < choiceData.size(); i++) {
if (i == 0) {
stringJoiner.add("");
}
stringJoiner.add(i + startNum + 1 + ". " + choiceData.get(i).getProblem().replace("( )", "( " + choiceData.get(i).getAnswer() + " )"));
stringJoiner.add(" A、" + choiceData.get(i).getOptionA());
stringJoiner.add(" B、" + choiceData.get(i).getOptionB());
stringJoiner.add(" C、" + choiceData.get(i).getOptionC());
stringJoiner.add(" D、" + choiceData.get(i).getOptionD());
}
return stringJoiner.toString();
}
/**
* 替换文档中的占位符
*/
private void replacePlaceholder(XWPFDocument document, String placeholder, String replacement) {
// 替换段落中的占位符
for (XWPFParagraph paragraph : document.getParagraphs()) {
replaceInParagraphEnhanced(paragraph, placeholder, replacement);
}
}
/**
* 在段落中替换占位符(增强版)
* 此方法能更好地处理占位符被分割到多个Run的情况,并尽量保留格式
*/
private void replaceInParagraphEnhanced(XWPFParagraph paragraph, String placeholder, String replacement) {
List<XWPFRun> runs = paragraph.getRuns();
if (runs == null || runs.isEmpty()) {
return;
}
// 1. 合并段落的文本内容以进行检查
StringBuilder paragraphText = new StringBuilder();
for (XWPFRun run : runs) {
String text = run.getText(0);
if (text != null) {
paragraphText.append(text);
}
}
String fullText = paragraphText.toString();
// 2. 如果段落中包含占位符,才进行替换
if (fullText.contains(placeholder)) {
// 3. 寻找占位符的起始和结束位置(跨Run)
int startIndex = fullText.indexOf(placeholder);
int endIndex = startIndex + placeholder.length();
// 4. 遍历Run,定位占位符所在的Run范围
int currentPos = 0;
int startRunIndex = -1;
int endRunIndex = -1;
for (int i = 0; i < runs.size(); i++) {
XWPFRun run = runs.get(i);
String runText = run.getText(0);
if (runText == null) continue;
int runLength = runText.length();
// 判断当前Run是否包含占位符的起始部分
if (currentPos <= startIndex && currentPos + runLength > startIndex) {
startRunIndex = i;
}
// 判断当前Run是否包含占位符的结束部分
if (currentPos < endIndex && currentPos + runLength >= endIndex) {
endRunIndex = i;
break; // 找到结束Run后跳出循环
}
currentPos += runLength;
}
// 5. 如果成功定位到占位符所在的Run范围,则进行替换
if (startRunIndex != -1 && endRunIndex != -1) {
// 合并占位符所跨越的所有Run的文本
StringBuilder placeholderText = new StringBuilder();
for (int i = startRunIndex; i <= endRunIndex; i++) {
placeholderText.append(runs.get(i).getText(0));
}
// 在合并的文本中进行替换
String mergedText = placeholderText.toString();
String newText = mergedText.replace(placeholder, replacement);
// 清空原始Run的文本
for (int i = startRunIndex; i <= endRunIndex; i++) {
runs.get(i).setText("", 0);
}
// 将替换后的文本设置到第一个Run中(尽量保留其格式)
runs.get(startRunIndex).setText(newText, 0);
// 可选:删除之间多余的Run,但可能会影响格式,建议保留
// for (int i = endRunIndex; i > startRunIndex; i--) {
// paragraph.removeRun(i);
// }
}
}
}
//生成随机题目
private List<TheoreticalPaperDetailEntity> randomQuestions(List<PaperDistributionEntity> paperRuleList, String type) {
List<TheoreticalPaperDetailEntity> resultList = new ArrayList<>();
for (PaperDistributionEntity paperDistributionEntity : paperRuleList) {
List<TheoreticalPaperDetailEntity> theoreticalLibraryList = new ArrayList<>();
if ("判断题".equals(type)) {
theoreticalLibraryList = theoreticalLibraryService
.randomQuestions(paperDistributionEntity.getLev(), type, paperDistributionEntity.getJudgmentCount(), paperDistributionEntity.getChapter(), paperDistributionEntity.getSection());
} else if ("单选题".equals(type)) {
theoreticalLibraryList = theoreticalLibraryService
.randomQuestions(paperDistributionEntity.getLev(), type, paperDistributionEntity.getSingleCount(), paperDistributionEntity.getChapter(), paperDistributionEntity.getSection());
} else if ("多选题".equals(type)) {
theoreticalLibraryList = theoreticalLibraryService
.randomQuestions(paperDistributionEntity.getLev(), type, paperDistributionEntity.getMoreCount(), paperDistributionEntity.getChapter(), paperDistributionEntity.getSection());
}
resultList.addAll(theoreticalLibraryList);
}
return resultList;
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TheoreticalPaperStudentDetailMapper;
import com.platform.business.model.dto.TheoreticalPaperStudentDetailDTO;
import com.platform.business.model.entity.TheoreticalPaperStudentDetailEntity;
import com.platform.business.model.vo.TheoreticalPaperStudentDetailVO;
import com.platform.business.service.TheoreticalPaperStudentDetailService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : wujipeng
* @date : 2025/12/29 17:46
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class TheoreticalPaperStudentDetailServiceImpl extends ServiceImpl<TheoreticalPaperStudentDetailMapper, TheoreticalPaperStudentDetailEntity>
implements TheoreticalPaperStudentDetailService {
@Override
public List<TheoreticalPaperStudentDetailVO> process(int examId, String studentId) {
return baseMapper.process(examId, studentId);
}
@Override
public TheoreticalPaperStudentDetailVO questionDetail(String id) {
return baseMapper.questionDetail(id);
}
@Override
public TheoreticalPaperStudentDetailVO gradesQuestionDetail(String id) {
return baseMapper.gradesQuestionDetail(id);
}
@Override
public Boolean leaveBlank(TheoreticalPaperStudentDetailDTO theoreticalPaperStudentDetailDTO) {
return baseMapper.leaveBlank(theoreticalPaperStudentDetailDTO);
}
}
package com.platform.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.TheoreticalPracticeMapper;
import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.entity.*;
import com.platform.business.model.vo.TheoreticalPracticeStudentVO;
import com.platform.business.model.vo.TheoreticalPracticeVO;
import com.platform.business.service.*;
import com.platform.business.utils.ChineseNumberUtils;
import com.platform.business.utils.JwtTokenUtil;
import com.platform.exception.BusinessException;
import com.platform.model.resp.Result;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author : wujipeng
* @date : 2026/4/21 10:13
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPracticeMapper, TheoreticalPracticeEntity> implements TheoreticalPracticeService {
@Resource
private TheoreticalPracticeStudentService theoreticalPracticeStudentService;
@Resource
private HttpServletRequest request;
@Resource
private JwtTokenUtil jwtTokenUtil;
@Resource
private TheoreticalLibraryService theoreticalLibraryService;
@Resource
private TheoreticalPracticeStudentQuestionBankService theoreticalPracticeStudentQuestionBankService;
@Resource
private UserService userService;
@Override
public List<TheoreticalPracticeVO> page(TheoreticalPracticeDTO theoreticalPracticeDTO) {
List<TheoreticalPracticeVO> result = baseMapper.page(theoreticalPracticeDTO);
//判断状态
for (TheoreticalPracticeVO theoreticalPracticeVO : result) {
if (theoreticalPracticeVO.getIsClose()) {
theoreticalPracticeVO.setStatus("已手动关闭");
continue;
}
if (theoreticalPracticeVO.getStartTime().getTime() > System.currentTimeMillis()) {
theoreticalPracticeVO.setStatus("未开放");
} else if (theoreticalPracticeVO.getEndTime().getTime() < System.currentTimeMillis()) {
theoreticalPracticeVO.setStatus("已结束");
} else {
theoreticalPracticeVO.setStatus("已开放");
}
}
return result;
}
@Override
public TheoreticalPracticeVO detail(String id) {
List<TheoreticalPracticeStudentVO> studentList = theoreticalPracticeStudentService.selectStudentListByPracticeId(id);
TheoreticalPracticeVO theoreticalPracticeVO = baseMapper.detail(id);
theoreticalPracticeVO.setStudentList(studentList);
return theoreticalPracticeVO;
}
@Override
@Transactional
public Result<Boolean> saveOrUpdateData(TheoreticalPracticeDTO theoreticalPracticeDTO) {
if (StrUtil.isEmpty(theoreticalPracticeDTO.getId())) {
//查询当前登陆人信息
//判断是否有未完成的练习
long count = count(new LambdaQueryWrapper<TheoreticalPracticeEntity>()
.eq(TheoreticalPracticeEntity::getClassId, theoreticalPracticeDTO.getClassId())
.gt(TheoreticalPracticeEntity::getEndTime, new Date())
.eq(TheoreticalPracticeEntity::getIsClose, false)
);
if (count > 0) {
return Result.fail("当前班级有未完成的练习,不能重复创建");
}
theoreticalPracticeDTO.setCreateTime(new Date());
String token = request.getHeader("Authorization");
UserEntity user = userService.getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getPhoneNumber, jwtTokenUtil.getUsernameFromToken(token)));
theoreticalPracticeDTO.setCreator(user.getNickName());
theoreticalPracticeDTO.setCreatorId(user.getId());
save(theoreticalPracticeDTO);
} else {
updateById(theoreticalPracticeDTO);
}
List<TheoreticalPracticeStudentVO> studentList = theoreticalPracticeDTO.getStudentList();
if (!ObjectUtils.isEmpty(studentList)) {
//初始化学生理论练习题库
initStudentLibrary(theoreticalPracticeDTO.getLev(), studentList);
for (TheoreticalPracticeStudentVO theoreticalPracticeStudentVO : studentList) {
theoreticalPracticeStudentVO.setPracticeId(theoreticalPracticeDTO.getId());
}
theoreticalPracticeStudentService.saveOrUpdateBatch(BeanUtil.copyToList(studentList, TheoreticalPracticeStudentEntity.class));
}
return Result.data(Boolean.TRUE);
}
private void initStudentLibrary(String level, List<TheoreticalPracticeStudentVO> studentList) {
//获取章节
List<TheoreticalLibraryEntity> chapterList = theoreticalLibraryService.groupByChapter(level);
Map<String, String> chapterMap = chapterList.stream().collect(Collectors.toMap(key -> key.getFirstLevelName() + key.getSecondLevelName(), TheoreticalLibraryEntity::getSequence));
List<String> studentIds = new ArrayList<>();
List<TheoreticalLibraryEntity> theoreticalLibraryList = theoreticalLibraryService
.list(new LambdaQueryWrapper<TheoreticalLibraryEntity>()
.eq(TheoreticalLibraryEntity::getScope, level).eq(TheoreticalLibraryEntity::getIsProblem, true));
List<String> theoreticalPracticeStudentQuestionBankList = theoreticalPracticeStudentQuestionBankService.groupByStudentId();
for (TheoreticalPracticeStudentVO theoreticalPracticeStudentVO : studentList) {
if (!theoreticalPracticeStudentQuestionBankList.contains(theoreticalPracticeStudentVO.getStudentId())) {
studentIds.add(theoreticalPracticeStudentVO.getStudentId());
}
}
if (!studentIds.isEmpty()) {
List<TheoreticalPracticeStudentQuestionBankEntity> result = new ArrayList<>();
for (String studentId : studentIds) {
for (TheoreticalLibraryEntity theoreticalLibrary : theoreticalLibraryList) {
TheoreticalPracticeStudentQuestionBankEntity theoreticalPracticeStudentQuestionBank = new TheoreticalPracticeStudentQuestionBankEntity();
theoreticalPracticeStudentQuestionBank.setStudentId(studentId);
theoreticalPracticeStudentQuestionBank.setScope(theoreticalLibrary.getScope());
theoreticalPracticeStudentQuestionBank.setLev(theoreticalLibrary.getLev());
theoreticalPracticeStudentQuestionBank.setSequence(theoreticalLibrary.getSequence());
theoreticalPracticeStudentQuestionBank.setCode(theoreticalLibrary.getCode());
theoreticalPracticeStudentQuestionBank.setFirstLevelName(theoreticalLibrary.getFirstLevelName());
theoreticalPracticeStudentQuestionBank.setSecondLevelName(theoreticalLibrary.getSecondLevelName());
theoreticalPracticeStudentQuestionBank.setThirdLevelName(theoreticalLibrary.getThirdLevelName());
theoreticalPracticeStudentQuestionBank.setFourthLevelName(theoreticalLibrary.getFourthLevelName());
theoreticalPracticeStudentQuestionBank.setType(theoreticalLibrary.getType());
theoreticalPracticeStudentQuestionBank.setProblem(theoreticalLibrary.getProblem());
theoreticalPracticeStudentQuestionBank.setAnswer(theoreticalLibrary.getAnswer());
theoreticalPracticeStudentQuestionBank.setOptionA(theoreticalLibrary.getOptionA());
theoreticalPracticeStudentQuestionBank.setOptionB(theoreticalLibrary.getOptionB());
theoreticalPracticeStudentQuestionBank.setOptionC(theoreticalLibrary.getOptionC());
theoreticalPracticeStudentQuestionBank.setOptionD(theoreticalLibrary.getOptionD());
theoreticalPracticeStudentQuestionBank.setOptionE(theoreticalLibrary.getOptionE());
//设置章节
if("技能竞赛".equals(level)){
theoreticalPracticeStudentQuestionBank.setChapter("1");
theoreticalPracticeStudentQuestionBank.setSection("1");
} else {
if(chapterMap.containsKey(theoreticalLibrary.getFirstLevelName() + theoreticalLibrary.getSecondLevelName())){
String sequence = chapterMap.get(theoreticalLibrary.getFirstLevelName() + theoreticalLibrary.getSecondLevelName());
if(sequence.getBytes().length == 2){
theoreticalPracticeStudentQuestionBank.setChapter(String.valueOf(Integer.parseInt(String.valueOf(sequence.charAt(0))) + 1));
theoreticalPracticeStudentQuestionBank.setSection(sequence.substring(1));
}
}
}
result.add(theoreticalPracticeStudentQuestionBank);
}
}
theoreticalPracticeStudentQuestionBankService.saveBatch(result);
}
}
@Override
public Boolean close(TheoreticalPracticeDTO theoreticalPracticeDTO) {
theoreticalPracticeDTO.setIsClose(true);
return updateById(theoreticalPracticeDTO);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment