diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsDocxController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsDocxController.java new file mode 100644 index 00000000..5225dea0 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsDocxController.java @@ -0,0 +1,83 @@ +package pc.exam.pp.module.exam.controller.admin.wps; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import pc.exam.pp.framework.common.enums.CommonStatusEnum; +import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxRespVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxSaveReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxSimpleRespVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsDocx; +import pc.exam.pp.module.exam.service.wps.docx.ExamWpsDocxService; + +import java.util.List; + +import static pc.exam.pp.framework.common.pojo.CommonResult.success; + +@Tag(name = "考试系统 - DOCX考点") +@RestController +@RequestMapping("/exam/docx") +@Validated +public class ExamWpsDocxController { + + @Resource + private ExamWpsDocxService examWpsDocxService; + + @PostMapping("create") + @Operation(summary = "创建Docx考点") + public CommonResult createDocx(@Valid @RequestBody DocxSaveReqVO createReqVO) { + Long DocxId = examWpsDocxService.createDocx(createReqVO); + return success(DocxId); + } + + @PutMapping("update") + @Operation(summary = "更新Docx考点") + public CommonResult updateDocx(@Valid @RequestBody DocxSaveReqVO updateReqVO) { + examWpsDocxService.updateDocx(updateReqVO); + return success(true); + } + + @DeleteMapping("delete") + @Operation(summary = "删除Docx考点") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult deleteDocx(@RequestParam("id") Long id) { + examWpsDocxService.deleteDocx(id); + return success(true); + } + + @GetMapping("/list") + @Operation(summary = "获取Docx考点列表") + public CommonResult> getDocxList(DocxListReqVO reqVO) { + List list = examWpsDocxService.getDocxList(reqVO); + return success(BeanUtils.toBean(list, DocxRespVO.class)); + } + + @GetMapping(value = {"/list-all-simple", "/simple-list"}) + @Operation(summary = "获取Docx考点精简信息列表", description = "只包含被开启的Docx考点,主要用于前端的下拉选项") + public CommonResult> getSimpleDocxList() { + List list = examWpsDocxService.getDocxList( + new DocxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); + return success(BeanUtils.toBean(list, DocxSimpleRespVO.class)); + } + + @GetMapping("/get") + @Operation(summary = "获得Docx考点信息") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult getDocx(@RequestParam("id") Long id) { + ExamWpsDocx Docx = examWpsDocxService.getDocx(id); + return success(BeanUtils.toBean(Docx, DocxRespVO.class)); + } + + @GetMapping("/getByNameList") + public CommonResult> getDocxByNameList(@RequestParam("title") String title) { + ExamWpsDocx Docx = examWpsDocxService.getDocxByTitle(title); + return success(BeanUtils.toBean(examWpsDocxService.getChildDocxList(Docx.getId()), DocxRespVO.class)); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxListReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxListReqVO.java new file mode 100644 index 00000000..731e8b51 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxListReqVO.java @@ -0,0 +1,14 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.docx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "考试模块 - PPT考点列表 Request VO") +@Data +public class DocxListReqVO { + + private String name; + + private Integer status; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxRespVO.java new file mode 100644 index 00000000..0e590b03 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxRespVO.java @@ -0,0 +1,40 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.docx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "考试模块 - PPT考点信息 Response VO") +@Data +public class DocxRespVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String dataType; + + private Integer isText; + + private String valueList; + + private Integer isTrue; + + private Integer titleType; + + private Integer isParameter; + + private LocalDateTime createTime; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSaveReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSaveReqVO.java new file mode 100644 index 00000000..57afeb3f --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSaveReqVO.java @@ -0,0 +1,36 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.docx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "考试模块 - PPT考点创建/修改 Request VO") +@Data +public class DocxSaveReqVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String dataType; + + private Integer isText; + + private String valueList; + + private Integer isTrue; + + private Integer titleType; + + private Integer isParameter; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSimpleRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSimpleRespVO.java new file mode 100644 index 00000000..73f2f10f --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/docx/DocxSimpleRespVO.java @@ -0,0 +1,20 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.docx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Schema(description = "考试模块 - 精简信息 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DocxSimpleRespVO { + + private Long id; + + private String name; + + private Long parentId; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsDocx.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsDocx.java new file mode 100644 index 00000000..48e88724 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsDocx.java @@ -0,0 +1,41 @@ +package pc.exam.pp.module.exam.dal.dataobject.wps; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import pc.exam.pp.framework.tenant.core.db.TenantBaseDO; + +import java.util.ArrayList; +import java.util.List; + +/** + * wps docx关系对应表 + * + * @author REN + */ +@TableName("exam_wps_docx") +@Data +@EqualsAndHashCode(callSuper = true) +public class ExamWpsDocx extends TenantBaseDO { + + public static final Long PARENT_ID_ROOT = 0L; + + @TableId + private Long id; + private String name; + private Long parentId; + private String title; + private Integer sort; + private String chineseName; + private String dataType; + private Integer status; + private String valueList; + private Integer isTrue; + private Integer isText; + private Integer titleType; + private Integer isParameter; + @TableField(exist = false) + private List children = new ArrayList<>(); +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsDocxMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsDocxMapper.java new file mode 100644 index 00000000..49e6454f --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsDocxMapper.java @@ -0,0 +1,36 @@ +package pc.exam.pp.module.exam.dal.mysql.wps; + +import org.apache.ibatis.annotations.Mapper; +import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; +import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxListReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsDocx; + +import java.util.Collection; +import java.util.List; + +@Mapper +public interface ExamWpsDocxMapper extends BaseMapperX { + + default List selectList(DocxListReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(ExamWpsDocx::getName, reqVO.getName()) + .eqIfPresent(ExamWpsDocx::getStatus, reqVO.getStatus())); + } + + default ExamWpsDocx selectByParentIdAndName(Long parentId, String name) { + return selectOne(ExamWpsDocx::getParentId, parentId, ExamWpsDocx::getName, name); + } + + default ExamWpsDocx selectByTitle(String title) { + return selectOne(ExamWpsDocx::getTitle, title); + } + + default Long selectCountByParentId(Long parentId) { + return selectCount(ExamWpsDocx::getParentId, parentId); + } + + default List selectListByParentId(Collection parentIds) { + return selectList(ExamWpsDocx::getParentId, parentIds); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDcxoServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDcxoServiceImpl.java new file mode 100644 index 00000000..6c98b067 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDcxoServiceImpl.java @@ -0,0 +1,221 @@ +package pc.exam.pp.module.exam.service.wps.docx; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import com.google.common.annotations.VisibleForTesting; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import pc.exam.pp.framework.common.enums.CommonStatusEnum; +import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsDocx; +import pc.exam.pp.module.exam.dal.mysql.wps.ExamWpsDocxMapper; + +import java.util.*; + +import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; +import static pc.exam.pp.framework.common.util.collection.CollectionUtils.convertSet; +import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*; + +/** + * Docx考点 Service 实现类 + * + * @author 朋辰 + */ +@Service +@Validated +@Slf4j +public class ExamWpsDcxoServiceImpl implements ExamWpsDocxService { + + @Resource + private ExamWpsDocxMapper DocxMapper; + + @Override + public Long createDocx(DocxSaveReqVO createReqVO) { + if (createReqVO.getParentId() == null) { + createReqVO.setParentId(ExamWpsDocx.PARENT_ID_ROOT); + } + // 校验父Docx考点的有效性 + validateParentDocx(null, createReqVO.getParentId()); + // 校验Docx考点名的唯一性 + validateDocxNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); + + // 插入Docx考点 + ExamWpsDocx Docx = BeanUtils.toBean(createReqVO, ExamWpsDocx.class); + DocxMapper.insert(Docx); + return Docx.getId(); + } + + @Override + public void updateDocx(DocxSaveReqVO updateReqVO) { + if (updateReqVO.getParentId() == null) { + updateReqVO.setParentId(ExamWpsDocx.PARENT_ID_ROOT); + } + // 校验自己存在 + validateDocxExists(updateReqVO.getId()); + // 校验父Docx考点的有效性 + validateParentDocx(updateReqVO.getId(), updateReqVO.getParentId()); + // 校验Docx考点名的唯一性 + validateDocxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); + + // 更新Docx考点 + ExamWpsDocx updateObj = BeanUtils.toBean(updateReqVO, ExamWpsDocx.class); + DocxMapper.updateById(updateObj); + } + + @Override + public void deleteDocx(Long id) { + // 校验是否存在 + validateDocxExists(id); + // 校验是否有子Docx考点 + if (DocxMapper.selectCountByParentId(id) > 0) { + throw exception(DOCX_EXITS_CHILDREN); + } + // 删除Docx考点 + DocxMapper.deleteById(id); + } + + @VisibleForTesting + void validateDocxExists(Long id) { + if (id == null) { + return; + } + ExamWpsDocx Docx = DocxMapper.selectById(id); + if (Docx == null) { + throw exception(DOCX_NOT_FOUND); + } + } + + @VisibleForTesting + void validateParentDocx(Long id, Long parentId) { + if (parentId == null || ExamWpsDocx.PARENT_ID_ROOT.equals(parentId)) { + return; + } + // 1. 不能设置自己为父Docx考点 + if (Objects.equals(id, parentId)) { + throw exception(DOCX_PARENT_ERROR); + } + // 2. 父Docx考点不存在 + ExamWpsDocx parent = DocxMapper.selectById(parentId); + if (parent == null) { + throw exception(DOCX_PARENT_NOT_EXITS); + } + // 3. 递归校验父Docx考点,如果父Docx考点是自己的子Docx考点,则报错,避免形成环路 + if (id == null) { // id 为空,说明新增,不需要考虑环路 + return; + } + for (int i = 0; i < Short.MAX_VALUE; i++) { + // 3.1 校验环路 + parentId = parent.getParentId(); + if (Objects.equals(id, parentId)) { + throw exception(DOCX_PARENT_IS_CHILD); + } + // 3.2 继续递归下一级父Docx考点 + if (parentId == null || ExamWpsDocx.PARENT_ID_ROOT.equals(parentId)) { + break; + } + parent = DocxMapper.selectById(parentId); + if (parent == null) { + break; + } + } + } + + @VisibleForTesting + void validateDocxNameUnique(Long id, Long parentId, String name) { + ExamWpsDocx dept = DocxMapper.selectByParentIdAndName(parentId, name); + if (dept == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的Docx考点 + if (id == null) { + throw exception(DOCX_NAME_DUPLICATE); + } + if (ObjectUtil.notEqual(dept.getId(), id)) { + throw exception(DOCX_NAME_DUPLICATE); + } + } + + @Override + public ExamWpsDocx getDocx(Long id) { + return DocxMapper.selectById(id); + } + + @Override + public ExamWpsDocx getDocxByTitle(String title) { + return DocxMapper.selectByTitle(title); + } + + @Override + public List getDocxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return DocxMapper.selectBatchIds(ids); + } + + @Override + public List getDocxList(DocxListReqVO reqVO) { + List list = DocxMapper.selectList(reqVO); + list.sort(Comparator.comparing(ExamWpsDocx::getSort)); + return list; + } + + @Override + public Map getDocxMap(Collection ids) { + return ExamWpsDocxService.super.getDocxMap(ids); + } + + @Override + public List getChildDocxList(Long id) { + return ExamWpsDocxService.super.getChildDocxList(id); + } + + @Override + public List getChildDocxList(Collection ids) { + List children = new LinkedList<>(); + // 遍历每一层 + Collection parentIds = ids; + for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 + // 查询当前层,所有的子Docx考点 + List Docxs = DocxMapper.selectListByParentId(parentIds); + // 1. 如果没有子Docx考点,则结束遍历 + if (CollUtil.isEmpty(Docxs)) { + break; + } + // 2. 如果有子Docx考点,继续遍历 + children.addAll(Docxs); + parentIds = convertSet(Docxs, ExamWpsDocx::getId); + } + return children; + } + + @Override + public Set getChildDocxIdListFromCache(Long id) { + List children = getChildDocxList(id); + return convertSet(children, ExamWpsDocx::getId); + } + + @Override + public void validateDocxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return; + } + // 获得信息 + Map DocxMap = getDocxMap(ids); + // 校验 + ids.forEach(id -> { + ExamWpsDocx Docx = DocxMap.get(id); + if (Docx == null) { + throw exception(DOCX_NOT_FOUND); + } + if (!CommonStatusEnum.ENABLE.getStatus().equals(Docx.getStatus())) { + throw exception(DOCX_NOT_ENABLE, Docx.getName()); + } + }); + } + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDocxService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDocxService.java new file mode 100644 index 00000000..2dfee638 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/docx/ExamWpsDocxService.java @@ -0,0 +1,117 @@ +package pc.exam.pp.module.exam.service.wps.docx; + +import pc.exam.pp.framework.common.util.collection.CollectionUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.docx.DocxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsDocx; + +import java.util.*; + +/** + * Docx考点 Service 接口 + * + * @author 朋辰 + */ +public interface ExamWpsDocxService { + + /** + * 创建Docx考点 + * + * @param createReqVO Docx考点信息 + * @return Docx考点编号 + */ + Long createDocx(DocxSaveReqVO createReqVO); + + /** + * 更新Docx考点 + * + * @param updateReqVO Docx考点信息 + */ + void updateDocx(DocxSaveReqVO updateReqVO); + + /** + * 删除Docx考点 + * + * @param id Docx考点编号 + */ + void deleteDocx(Long id); + + /** + * 获得Docx考点信息 + * + * @param id Docx考点编号 + * @return Docx考点信息 + */ + ExamWpsDocx getDocx(Long id); + + /** + * 获得Docx考点信息 + * + * @param title Docx考点标签 + * @return Docx考点信息 + */ + ExamWpsDocx getDocxByTitle(String title); + + /** + * 获得Docx考点信息数组 + * + * @param ids Docx考点编号数组 + * @return Docx考点信息数组 + */ + List getDocxList(Collection ids); + + /** + * 筛选Docx考点列表 + * + * @param reqVO 筛选条件请求 VO + * @return Docx考点列表 + */ + List getDocxList(DocxListReqVO reqVO); + + /** + * 获得指定编号的Docx考点 Map + * + * @param ids Docx考点编号数组 + * @return Docx考点 Map + */ + default Map getDocxMap(Collection ids) { + List list = getDocxList(ids); + return CollectionUtils.convertMap(list, ExamWpsDocx::getId); + } + + /** + * 获得指定Docx考点的所有子Docx考点 + * + * @param id Docx考点编号 + * @return 子Docx考点列表 + */ + default List getChildDocxList(Long id) { + return getChildDocxList(Collections.singleton(id)); + } + + /** + * 获得指定Docx考点的所有子Docx考点 + * + * @param ids Docx考点编号数组 + * @return 子Docx考点列表 + */ + List getChildDocxList(Collection ids); + + /** + * 获得所有子Docx考点,从缓存中 + * + * @param id 父Docx考点编号 + * @return 子Docx考点列表 + */ + Set getChildDocxIdListFromCache(Long id); + + /** + * 校验Docx考点们是否有效。如下情况,视为无效: + * 1. Docx考点编号不存在 + * 2. Docx考点被禁用 + * + * @param ids 角色编号数组 + */ + void validateDocxList(Collection ids); + +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java index 28ec342e..22eec29a 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java @@ -4,7 +4,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.module.infra.controller.admin.file.vo.file.FileUploadReqVO; import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsDocxInfoVo; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; @@ -14,6 +16,7 @@ import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; +import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; @@ -54,9 +57,9 @@ public class AutoWpsController { * wps word * @return 获取大类 */ - @GetMapping("/runWpsWord") - public CommonResult> runWpsWord(String path) throws Exception { - return CommonResult.success(judgementWpsWordService.programmingWpsWord(path)); + @PostMapping("/docxDataInfo") + public CommonResult> runWpsWord(FileUploadReqVO file) throws Exception { + return CommonResult.success(judgementWpsWordService.docxDataInfo(file.getFile())); } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WordController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WordController.java deleted file mode 100644 index dacc0220..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WordController.java +++ /dev/null @@ -1,85 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import pc.exam.pp.framework.common.enums.CommonStatusEnum; -import pc.exam.pp.framework.common.pojo.CommonResult; -import pc.exam.pp.framework.common.util.object.BeanUtils; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordRespVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSimpleRespVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.service.wps_word.WpsWordLinkService; - -import java.util.List; - -import static pc.exam.pp.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - wps_word") -@RestController -@RequestMapping("/wps/word") -@Validated -public class WordController { - - @Resource - private WpsWordLinkService wpsWordLinkService; - - @PostMapping("create") - @Operation(summary = "创建wps_word") - public CommonResult createWord(@Valid @RequestBody WordSaveReqVO createReqVO) { - Long wordId = wpsWordLinkService.createWord(createReqVO); - return success(wordId); - } - - @PutMapping("update") - @Operation(summary = "更新wps_word") - public CommonResult updateWord(@Valid @RequestBody WordSaveReqVO updateReqVO) { - wpsWordLinkService.updateWord(updateReqVO); - return success(true); - } - - @DeleteMapping("delete") - @Operation(summary = "删除wps_word") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - public CommonResult deleteWord(@RequestParam("id") Long id) { - wpsWordLinkService.deleteWord(id); - return success(true); - } - - @GetMapping("/list") - @Operation(summary = "获取wps_word列表") - public CommonResult> getWordList(WordListReqVO reqVO) { - List list = wpsWordLinkService.getWordList(reqVO); - return success(BeanUtils.toBean(list, WordRespVO.class)); - } - - @GetMapping(value = {"/list-all-simple", "/simple-list"}) - @Operation(summary = "获取wps_word精简信息列表", description = "只包含被开启的wps_word,主要用于前端的下拉选项") - public CommonResult> getSimpleWordList() { - List list = wpsWordLinkService.getWordList( - new WordListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); - return success(BeanUtils.toBean(list, WordSimpleRespVO.class)); - } - - @GetMapping("/get") - @Operation(summary = "获得wps_word信息") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - public CommonResult getWord(@RequestParam("id") Long id) { - WpsWordLinkDO word = wpsWordLinkService.getWord(id); - return success(BeanUtils.toBean(word, WordRespVO.class)); - } - - @GetMapping("/listInfo") - @Operation(summary = "获取wps_word子数据列表") - public CommonResult> getWordInfoList(WordListReqVO reqVO) { - List list = wpsWordLinkService.getWordInfoList(reqVO); - return success(BeanUtils.toBean(list, WordRespVO.class)); - } - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java index 3468cebf..1a39e7af 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java @@ -53,23 +53,23 @@ public class WpsController { public CommonResult> docxMaster(@RequestBody List wpsDocxInfoVos) throws Exception { return CommonResult.success(judgementWpsWordService.docxMaster(wpsDocxInfoVos)); } - /** - * wps word - * @return 判分 - */ - @PostMapping("/runWpsWordInfo") - public CommonResult> runWpsWordInfo(@RequestBody List wordReqDto) throws Exception { - return CommonResult.success(judgementWpsWordService.programmingInfo(wordReqDto)); - } - - /** - * wps word - * @return 判分 - */ - @GetMapping("/runWpsWord") - public CommonResult> runWpsWord(String path) throws Exception { - return CommonResult.success(judgementWpsWordService.programmingWpsWord(path)); - } +// /** +// * wps word +// * @return 判分 +// */ +// @PostMapping("/runWpsWordInfo") +// public CommonResult> runWpsWordInfo(@RequestBody List wordReqDto) throws Exception { +// return CommonResult.success(judgementWpsWordService.programmingInfo(wordReqDto)); +// } +// +// /** +// * wps word +// * @return 判分 +// */ +// @GetMapping("/runWpsWord") +// public CommonResult> runWpsWord(String path) throws Exception { +// return CommonResult.success(judgementWpsWordService.programmingWpsWord(path)); +// } /** * wps xlsx * @return 判分 diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java index 884f534f..20445788 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java @@ -22,7 +22,7 @@ import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService; import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService; import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperReqVo; import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperScoreInfoVo; -import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; +//import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; import pc.exam.pp.module.judgement.service.c_programming.JudgementService; import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService; import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/dataobject/wpsword/WpsWordLinkDO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/dataobject/wpsword/WpsWordLinkDO.java deleted file mode 100644 index 15d00166..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/dataobject/wpsword/WpsWordLinkDO.java +++ /dev/null @@ -1,71 +0,0 @@ -package pc.exam.pp.module.judgement.dal.dataobject.wpsword; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import pc.exam.pp.framework.common.enums.CommonStatusEnum; -import pc.exam.pp.framework.tenant.core.db.TenantBaseDO; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; - -import java.util.ArrayList; -import java.util.List; - -/** - * wps word关系对应表 - * - */ -@TableName("wps_word_link") -@Data -@EqualsAndHashCode(callSuper = true) -public class WpsWordLinkDO extends TenantBaseDO { - - public static final Long PARENT_ID_ROOT = 0L; - - /** - * 部门ID - */ - @TableId - private Long id; - /** - * 部门名称 - */ - private String name; - /** - * 父部门ID - * - * 关联 {@link #id} - */ - private Long parentId; - /** - * 显示顺序 - */ - private Integer sort; - /** - * 节点功能 - */ - private String nodeFunction; - /** - * 中文描述 - */ - private String toChinese; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; - private Integer isboo; - private Integer titleType; - private String unit; - private String page; - - @TableField(exist = false) - private List children = new ArrayList<>(); -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/mysql/wpsword/WpsWordLinkMapper.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/mysql/wpsword/WpsWordLinkMapper.java deleted file mode 100644 index 1594f148..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/dal/mysql/wpsword/WpsWordLinkMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -package pc.exam.pp.module.judgement.dal.mysql.wpsword; - -import org.apache.ibatis.annotations.Mapper; -import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; -import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; - -import java.util.Collection; -import java.util.List; - -@Mapper -public interface WpsWordLinkMapper extends BaseMapperX { - - default List selectList(WordListReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(WpsWordLinkDO::getName, reqVO.getName()) - .eq(reqVO.getBelongTo() != null, WpsWordLinkDO::getBelongTo, reqVO.getBelongTo()) - .eq(reqVO.getNodeFunction() != null, WpsWordLinkDO::getNodeFunction, reqVO.getNodeFunction()) - .eqIfPresent(WpsWordLinkDO::getStatus, reqVO.getStatus())); - } - - default WpsWordLinkDO selectByParentIdAndName(Long parentId, String name) { - return selectOne(WpsWordLinkDO::getParentId, parentId, WpsWordLinkDO::getName, name); - } - - default WpsWordLinkDO selectByNodeFunction(String nodeFunction) { - return selectOne(WpsWordLinkDO::getNodeFunction, nodeFunction); - } - - default List selectInfoList(Long id) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(WpsWordLinkDO::getParentId, id)); - } - - default Long selectCountByParentId(Long parentId) { - return selectCount(WpsWordLinkDO::getParentId, parentId); - } - - default List selectListByParentId(Collection parentIds) { - return selectList(WpsWordLinkDO::getParentId, parentIds); - } - - List selectTreeListByNodeFunction(); - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java index 251f9143..ff6938fd 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java @@ -1,38 +1,38 @@ -package pc.exam.pp.module.judgement.service.auto_tools; - -import pc.exam.pp.framework.common.pojo.CommonResult; - -import java.math.BigDecimal; - -public interface AutoToolsService { - - - // 文件自动上传 - - // Boolean autoFileTools(Long studentId, String paperId); - - /** - * 文件下载 - * @param fileUrl 文件url - * @param filePath 要下载的文件路径 - * @return 下载后的文件path - */ - String downloadStudentFile(String fileUrl, String filePath); - - // - - /** - * 解压文件 - * @param zipFilePath zip文件路径 - * @return 解压后的目录 - */ - String unzipToNamedFolder(String zipFilePath); - - /** - * 判分 - * @param stuId 学号 - * @param paperId 试卷ID - * @return 分数 - */ - CommonResult judgementScore(Long stuId, String paperId) throws Exception; -} +//package pc.exam.pp.module.judgement.service.auto_tools; +// +//import pc.exam.pp.framework.common.pojo.CommonResult; +// +//import java.math.BigDecimal; +// +//public interface AutoToolsService { +// +// +// // 文件自动上传 +// +// // Boolean autoFileTools(Long studentId, String paperId); +// +// /** +// * 文件下载 +// * @param fileUrl 文件url +// * @param filePath 要下载的文件路径 +// * @return 下载后的文件path +// */ +// String downloadStudentFile(String fileUrl, String filePath); +// +// // +// +// /** +// * 解压文件 +// * @param zipFilePath zip文件路径 +// * @return 解压后的目录 +// */ +// String unzipToNamedFolder(String zipFilePath); +// +// /** +// * 判分 +// * @param stuId 学号 +// * @param paperId 试卷ID +// * @return 分数 +// */ +// CommonResult judgementScore(Long stuId, String paperId) throws Exception; +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java index f8952a22..4df7f54c 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java @@ -1,474 +1,427 @@ -package pc.exam.pp.module.judgement.service.auto_tools; - -import cn.hutool.core.io.IoUtil; -import com.alibaba.excel.util.StringUtils; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.annotation.Resource; -import lombok.Data; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; -import pc.exam.pp.framework.common.pojo.CommonResult; -import pc.exam.pp.module.exam.dal.dataobject.EducationPaperQu; -import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme; -import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; -import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; -import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperInfoDO; -import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperScoreDO; -import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperMapper; -import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperQuMapper; -import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSchemeMapper; -import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; -import pc.exam.pp.module.exam.dal.mysql.student.StuPaperScoreMapper; -import pc.exam.pp.module.exam.service.paper.IEducationPaperQuService; -import pc.exam.pp.module.exam.service.question.IExamQuestionService; -import pc.exam.pp.module.exam.service.stuPaperInfo.StuPaperInfoService; -import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService; -import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService; -import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; -import pc.exam.pp.module.infra.service.config.ConfigService; -import pc.exam.pp.module.infra.service.file.FileService; -import pc.exam.pp.module.judgement.controller.service.browser.IBrowserServerice; -import pc.exam.pp.module.judgement.controller.service.file.IFileServerice; -import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice; -import pc.exam.pp.module.judgement.controller.utils.zip.ZipUtil; -import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; -import pc.exam.pp.module.judgement.service.c_programming.JudgementService; -import pc.exam.pp.module.judgement.service.choice.JudgementChoiceService; -import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService; -import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; -import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; -import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils; -import pc.exam.pp.module.judgement.utils.JudgementCUtils; -import pc.exam.pp.module.judgement.utils.multipartFile.CustomMultipartFile; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxSlidesVo; -import pc.exam.pp.module.judgement.utils.zipfile.FolderZipper; - -import java.io.*; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.net.URL; -import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; - -@Service -public class AutoToolsServiceImpl implements AutoToolsService{ - @Resource - private StuPaperFileService stuPaperFileService; - @Resource - private StuPaperInfoService stuPaperInfoService; - @Resource - ConfigService configService; - @Resource - IExamQuestionService examQuestionService; - @Resource - JudgementService judgementService; - @Resource - JudgementWpsWordService judgementWpsWordService; - @Resource - IMysqlServerice mysqlServerice; - @Resource - IFileServerice fileServerice; - @Resource - IBrowserServerice browserServerice; - @Resource - FileService fileService; - @Resource - StuPaperScoreService stuPaperScoreService; - @Resource - StuPaperScoreMapper stuPaperScoreMapper; - @Resource - JudgementChoiceService judgementChoiceService; - @Resource - private JudgementWpsPptxService judgementWpsPptxService; - @Resource - private JudgementWpsExcelService judgementWpsExcelService; - @Autowired - private EndStuMonitorUtils endStuMonitorUtils; - @Resource - EducationPaperQuMapper educationPaperQuMapper; - @Resource - ExamQuestionMapper examQuestionMapper; - @Resource - EducationPaperSchemeMapper educationPaperSchemeMapper; - @Resource - EducationPaperMapper educationPaperMapper; - @Override - public String downloadStudentFile(String fileUrl, String filePath) { - try { - URL url = new URL(fileUrl); - URLConnection connection = url.openConnection(); - - String fileName = new File(url.getPath()).getName(); - File dir = new File(filePath); - if (!dir.exists()) dir.mkdirs(); - - File saveFile = new File(dir, fileName); - - try (InputStream in = connection.getInputStream(); - FileOutputStream out = new FileOutputStream(saveFile)) { - - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - - System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath()); - return saveFile.getAbsolutePath(); - } - } catch (IOException e) { - System.err.println("❌ 下载失败: " + e.getMessage()); - return null; - } - } - - @Override - public String unzipToNamedFolder(String zipFilePath) { - File zipFile = new File(zipFilePath); - - if (!zipFile.exists() || !zipFile.getName().toLowerCase().endsWith(".zip")) { - System.err.println("❌ 无效 zip 文件: " + zipFilePath); - return null; - } - - String fileNameNoExt = zipFile.getName().replaceAll("(?i)\\.zip$", ""); - File extractDir = new File(zipFile.getParentFile(), fileNameNoExt); - if (!extractDir.exists()) extractDir.mkdirs(); - - // 指定编码(GBK 用于支持中文文件名,UTF-8 用于通用 ZIP) - try (ZipFile zf = new ZipFile(zipFile, "GBK")) { - Enumeration entries = zf.getEntries(); - while (entries.hasMoreElements()) { - ZipArchiveEntry entry = entries.nextElement(); - File outFile = new File(extractDir, entry.getName()); - - // 防止 Zip 穿越攻击 - if (!outFile.getCanonicalPath().startsWith(extractDir.getCanonicalPath())) { - throw new IOException("非法路径: " + entry.getName()); - } - - if (entry.isDirectory()) { - outFile.mkdirs(); - } else { - File parent = outFile.getParentFile(); - if (!parent.exists()) parent.mkdirs(); - - try (InputStream is = zf.getInputStream(entry); - OutputStream os = new FileOutputStream(outFile)) { - - byte[] buffer = new byte[4096]; - int len; - while ((len = is.read(buffer)) > 0) { - os.write(buffer, 0, len); - } - } - } - } - System.out.println("✅ 解压完成,目录:" + extractDir.getAbsolutePath()); - return extractDir.getAbsolutePath(); - - } catch (IOException e) { - System.err.println("❌ 解压失败: " + e.getMessage()); - return null; - } - } - - /** - * 试卷得整体判分 2025-06-24 暂不使用,期限,无限 - * @param stuId 学号 - * @param paperId 试卷ID - * @return 分数 - * @throws Exception 异常 - */ - @Override - public CommonResult judgementScore(Long stuId, String paperId) throws Exception { - // 先删除考试明细 - stuPaperScoreService.deleteStuPaperScore(stuId, paperId); - // 监控管理 生成选择题文件路径 - endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId); - // 获取平台文件参数 - ConfigDO config = configService.getConfigByKey("file_down_path"); - double score = 0; - // 1、通过学号,试卷ID查询文件路径 - List stuPaperFileDOList = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); - StuPaperFileDO stuPaperFileDO = null; - StuPaperFileDO noZipFileDO = null; - for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) { - if (stuPaperFileDOs.getType() == 1) { - noZipFileDO = stuPaperFileDOs; - - } - if (stuPaperFileDOs.getType() == 0) { - stuPaperFileDO = stuPaperFileDOs; - } - } - - List quList = new ArrayList<>(); - List quIds = educationPaperQuMapper.selectPaperQuByPaperId(paperId); - List examQuestionList = examQuestionMapper.selectExamQuestionListByQuIds(quIds); - List educationPaperSchemeList = educationPaperSchemeMapper.selectEducationPaperTaskByTaskId(educationPaperMapper.selectTaskIdByPaperId(paperId)); - List educationPaperQus = educationPaperQuMapper.selectPaperQuListByPaperId(paperId); - // 筛选出非选择题和选择题 - for (ExamQuestion examQuestion : examQuestionList) { - for (EducationPaperScheme educationPaperScheme : educationPaperSchemeList) { - if (examQuestion.getSubjectName().equals(educationPaperScheme.getSpName())) { - Optional result = educationPaperQus.stream().filter(strs -> Objects.equals(strs.getQuId(), examQuestion.getQuId())).findFirst(); - if (!result.isEmpty()) { - examQuestion.setQuScores(educationPaperScheme.getQuScores()); - examQuestion.setSort(result.get().getSort()); - quList.add(examQuestion); - break; - } - } - } - } - // 判断选择题文件是否存在 - if (noZipFileDO != null) { - // 1-1、 穿插选择题判分 - // 1-1-1、下载选择题文件 - String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue()); - File select_file = new File(select_qu); - // 1-1-2、读取内容转换成json - String select_string = readFileAsString(select_file.getPath()); - Stu stu = stringToJson(select_string); - if(stu!=null){ - // 1-1-3、进行选择题判分 - for (ExamQuestion examQuestion : quList) { - if ("选择题".equals(examQuestion.getSubjectName())) { - Optional result = stu.getQuestionResultMap().keySet().stream().filter(strs -> strs.equals(examQuestion.getQuId())).findFirst(); - if (!result.isEmpty()) { - String key = result.get(); - String value = stu.getQuestionResultMap().get(key); - // 查询该题的成绩 - StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, key); - // 判断是否做过该题 - boolean isNull = false; - if (stuPaperScoreDO == null) { - stuPaperScoreDO = new StuPaperScoreDO(); - stuPaperScoreDO.setStuId(stuId); - stuPaperScoreDO.setQuId(key); - stuPaperScoreDO.setPaperId(paperId); - stuPaperScoreDO.setSort(examQuestion.getSort()); - isNull = true; - } - double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), key, value, stuPaperScoreDO, isNull); - score += selectScore; - } else { - StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); - // 判断是否做过该题 - boolean isNull = false; - if (stuPaperScoreDO == null) { - stuPaperScoreDO = new StuPaperScoreDO(); - stuPaperScoreDO.setStuId(stuId); - stuPaperScoreDO.setQuId(examQuestion.getQuId()); - stuPaperScoreDO.setPaperId(paperId); - stuPaperScoreDO.setSort(examQuestion.getSort()); - isNull = true; - } - // 说明学生没有答题,直接给零分 - double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), examQuestion.getQuId(), "", stuPaperScoreDO, isNull); - score += selectScore; - } - } - } - } else { - // 如果结果是null的话,说明学生没有作答,直接全部0分 - for (ExamQuestion examQuestion : quList) { - if ("选择题".equals(examQuestion.getSubjectName())) { - StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); - // 判断是否做过该题 - boolean isNull = false; - if (stuPaperScoreDO == null) { - stuPaperScoreDO = new StuPaperScoreDO(); - stuPaperScoreDO.setStuId(stuId); - stuPaperScoreDO.setQuId(examQuestion.getQuId()); - stuPaperScoreDO.setPaperId(paperId); - stuPaperScoreDO.setSort(examQuestion.getSort()); - isNull = true; - } - // 说明学生没有答题,直接给零分 - double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), examQuestion.getQuId(), "", stuPaperScoreDO, isNull); - score += selectScore; - } - } - } - // 1-1-4、删除文件 - select_file.delete(); - } - // 2、判断文件路径是否存在 - if (stuPaperFileDO != null) { -// return CommonResult.error(100031, "试题文件没有上传,无法判分!"); - // 3、下载文件 - String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue()); - File zip_file = new File(patn); - // 4、获取到得是zip文件,需要解压 - String stuFilePath = ZipUtil.unzipToNamedFolder(patn); - // 5、解压之后得文件获取文件夹和文件 - File folder = new File(stuFilePath); - File[] files = folder.listFiles(); - String stu_files = null; - // 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容) - if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!"); - // if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!"); - if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!"); - // 判断学号是否正确 - if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常"); - // 5.2、查询试题ID - File folders = new File(files[0].getPath()); - File[] filess = folders.listFiles(); - if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!"); - if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!"); - if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!"); - // 判断学号是否正确 - if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常"); - // 5.3、查询出来所有试题 - File qu_files = new File(filess[0].getPath()); - // 所有试题文件夹 - File[] filess_qu = qu_files.listFiles(); - if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!"); - for (File file : filess_qu) { - // ** 接下来已经到了,每个课程题型了 file 得名称 - // 5.3、查询出来所有试题 - File cs_files = new File(file.getPath()); - // 所有试题文件夹 - File[] cs_file_list = cs_files.listFiles(); - if (cs_file_list!=null){ - for (File one_file : cs_file_list) { - // 6、根据试题ID查询试题详情 - String qu_id = file.getName(); - Optional result = quList.stream().filter(quLists -> quLists.getQuId().equals(qu_id)).findFirst(); - String quScore = result.get().getQuScores(); - ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id); - if (examQuestion != null) { - // 7、进行对应得判分 - // --- 7.1、查询试题文件 - File qu_file = new File(one_file.getPath()); - File[] qu_file_list = qu_file.listFiles(); - if (qu_file_list == null) continue; - // --- 7.2、通过文件名称进行判分 - for (File file_one : qu_file_list) { - // 判断名称 类似于 C语言程序设计。 课程+题型 - System.out.println(one_file.getName()); - StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); - // 判断是否做过该题 - boolean isNull = false; - if (stuPaperScoreDO == null) { - stuPaperScoreDO = new StuPaperScoreDO(); - stuPaperScoreDO.setStuId(stuId); - stuPaperScoreDO.setQuId(examQuestion.getQuId()); - stuPaperScoreDO.setPaperId(paperId); - stuPaperScoreDO.setSort(result.get().getSort()); - isNull = true; - } - if ("编程题".equals(one_file.getName().split("\\.")[0])) { - String judgementStr_C = ""; - SourceAndText cpojo = judgementService.ProgrammingC(Double.parseDouble(quScore), one_file.getPath(), file_one.getName(), examQuestion, judgementStr_C); - double c_score = cpojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += cpojo.getText(); - - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - - score += c_score; - stuPaperScoreDO.setScore(new BigDecimal(c_score)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (c_score == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (c_score == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(c_score+"C语言程序设计得分"); - break; - } - // wps 类型存在多级文文件夹,需要个性化设置 - if ("文字".equals(one_file.getName().split("\\.")[0])) { - if (file_one.getPath().contains("文档")) { - String judgementStrWord = ""; - SourceAndText wordpojo = judgementWpsWordService.judgementWpsWord(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrWord); - double wps_word_score = wordpojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += wordpojo.getText(); - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - score += wps_word_score; - stuPaperScoreDO.setScore(new BigDecimal(wps_word_score)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (wps_word_score == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (wps_word_score == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(wps_word_score+"wps_word得分"); - break; - } - } -// if ("演示".equals(one_file.getName().split("\\.")[0])) { +//package pc.exam.pp.module.judgement.service.auto_tools; +// +//import cn.hutool.core.io.IoUtil; +//import com.alibaba.excel.util.StringUtils; +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import jakarta.annotation.Resource; +//import lombok.Data; +//import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +//import org.apache.commons.compress.archivers.zip.ZipFile; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Service; +//import org.springframework.web.multipart.MultipartFile; +//import pc.exam.pp.framework.common.pojo.CommonResult; +//import pc.exam.pp.module.exam.dal.dataobject.EducationPaperQu; +//import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme; +//import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; +//import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; +//import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperInfoDO; +//import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperScoreDO; +//import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperMapper; +//import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperQuMapper; +//import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSchemeMapper; +//import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; +//import pc.exam.pp.module.exam.dal.mysql.student.StuPaperScoreMapper; +//import pc.exam.pp.module.exam.service.paper.IEducationPaperQuService; +//import pc.exam.pp.module.exam.service.question.IExamQuestionService; +//import pc.exam.pp.module.exam.service.stuPaperInfo.StuPaperInfoService; +//import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService; +//import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService; +//import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; +//import pc.exam.pp.module.infra.service.config.ConfigService; +//import pc.exam.pp.module.infra.service.file.FileService; +//import pc.exam.pp.module.judgement.controller.service.browser.IBrowserServerice; +//import pc.exam.pp.module.judgement.controller.service.file.IFileServerice; +//import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice; +//import pc.exam.pp.module.judgement.controller.utils.zip.ZipUtil; +//import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; +//import pc.exam.pp.module.judgement.service.c_programming.JudgementService; +//import pc.exam.pp.module.judgement.service.choice.JudgementChoiceService; +//import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService; +//import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; +//import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; +//import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils; +//import pc.exam.pp.module.judgement.utils.JudgementCUtils; +//import pc.exam.pp.module.judgement.utils.multipartFile.CustomMultipartFile; +//import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxSlidesVo; +//import pc.exam.pp.module.judgement.utils.zipfile.FolderZipper; +// +//import java.io.*; +//import java.math.BigDecimal; +//import java.math.RoundingMode; +//import java.net.URL; +//import java.net.URLConnection; +//import java.nio.file.Files; +//import java.nio.file.Paths; +//import java.util.*; +// +//@Service +//public class AutoToolsServiceImpl implements AutoToolsService{ +// @Resource +// private StuPaperFileService stuPaperFileService; +// @Resource +// private StuPaperInfoService stuPaperInfoService; +// @Resource +// ConfigService configService; +// @Resource +// IExamQuestionService examQuestionService; +// @Resource +// JudgementService judgementService; +// @Resource +// JudgementWpsWordService judgementWpsWordService; +// @Resource +// IMysqlServerice mysqlServerice; +// @Resource +// IFileServerice fileServerice; +// @Resource +// IBrowserServerice browserServerice; +// @Resource +// FileService fileService; +// @Resource +// StuPaperScoreService stuPaperScoreService; +// @Resource +// StuPaperScoreMapper stuPaperScoreMapper; +// @Resource +// JudgementChoiceService judgementChoiceService; +// @Resource +// private JudgementWpsPptxService judgementWpsPptxService; +// @Resource +// private JudgementWpsExcelService judgementWpsExcelService; +// @Autowired +// private EndStuMonitorUtils endStuMonitorUtils; +// @Resource +// EducationPaperQuMapper educationPaperQuMapper; +// @Resource +// ExamQuestionMapper examQuestionMapper; +// @Resource +// EducationPaperSchemeMapper educationPaperSchemeMapper; +// @Resource +// EducationPaperMapper educationPaperMapper; +// @Override +// public String downloadStudentFile(String fileUrl, String filePath) { +// try { +// URL url = new URL(fileUrl); +// URLConnection connection = url.openConnection(); +// +// String fileName = new File(url.getPath()).getName(); +// File dir = new File(filePath); +// if (!dir.exists()) dir.mkdirs(); +// +// File saveFile = new File(dir, fileName); +// +// try (InputStream in = connection.getInputStream(); +// FileOutputStream out = new FileOutputStream(saveFile)) { +// +// byte[] buffer = new byte[4096]; +// int bytesRead; +// while ((bytesRead = in.read(buffer)) != -1) { +// out.write(buffer, 0, bytesRead); +// } +// +// System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath()); +// return saveFile.getAbsolutePath(); +// } +// } catch (IOException e) { +// System.err.println("❌ 下载失败: " + e.getMessage()); +// return null; +// } +// } +// +// @Override +// public String unzipToNamedFolder(String zipFilePath) { +// File zipFile = new File(zipFilePath); +// +// if (!zipFile.exists() || !zipFile.getName().toLowerCase().endsWith(".zip")) { +// System.err.println("❌ 无效 zip 文件: " + zipFilePath); +// return null; +// } +// +// String fileNameNoExt = zipFile.getName().replaceAll("(?i)\\.zip$", ""); +// File extractDir = new File(zipFile.getParentFile(), fileNameNoExt); +// if (!extractDir.exists()) extractDir.mkdirs(); +// +// // 指定编码(GBK 用于支持中文文件名,UTF-8 用于通用 ZIP) +// try (ZipFile zf = new ZipFile(zipFile, "GBK")) { +// Enumeration entries = zf.getEntries(); +// while (entries.hasMoreElements()) { +// ZipArchiveEntry entry = entries.nextElement(); +// File outFile = new File(extractDir, entry.getName()); +// +// // 防止 Zip 穿越攻击 +// if (!outFile.getCanonicalPath().startsWith(extractDir.getCanonicalPath())) { +// throw new IOException("非法路径: " + entry.getName()); +// } +// +// if (entry.isDirectory()) { +// outFile.mkdirs(); +// } else { +// File parent = outFile.getParentFile(); +// if (!parent.exists()) parent.mkdirs(); +// +// try (InputStream is = zf.getInputStream(entry); +// OutputStream os = new FileOutputStream(outFile)) { +// +// byte[] buffer = new byte[4096]; +// int len; +// while ((len = is.read(buffer)) > 0) { +// os.write(buffer, 0, len); +// } +// } +// } +// } +// System.out.println("✅ 解压完成,目录:" + extractDir.getAbsolutePath()); +// return extractDir.getAbsolutePath(); +// +// } catch (IOException e) { +// System.err.println("❌ 解压失败: " + e.getMessage()); +// return null; +// } +// } +// +// /** +// * 试卷得整体判分 2025-06-24 暂不使用,期限,无限 +// * @param stuId 学号 +// * @param paperId 试卷ID +// * @return 分数 +// * @throws Exception 异常 +// */ +// @Override +// public CommonResult judgementScore(Long stuId, String paperId) throws Exception { +// // 先删除考试明细 +// stuPaperScoreService.deleteStuPaperScore(stuId, paperId); +// // 监控管理 生成选择题文件路径 +// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId); +// // 获取平台文件参数 +// ConfigDO config = configService.getConfigByKey("file_down_path"); +// double score = 0; +// // 1、通过学号,试卷ID查询文件路径 +// List stuPaperFileDOList = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); +// StuPaperFileDO stuPaperFileDO = null; +// StuPaperFileDO noZipFileDO = null; +// for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) { +// if (stuPaperFileDOs.getType() == 1) { +// noZipFileDO = stuPaperFileDOs; +// +// } +// if (stuPaperFileDOs.getType() == 0) { +// stuPaperFileDO = stuPaperFileDOs; +// } +// } +// +// List quList = new ArrayList<>(); +// List quIds = educationPaperQuMapper.selectPaperQuByPaperId(paperId); +// List examQuestionList = examQuestionMapper.selectExamQuestionListByQuIds(quIds); +// List educationPaperSchemeList = educationPaperSchemeMapper.selectEducationPaperTaskByTaskId(educationPaperMapper.selectTaskIdByPaperId(paperId)); +// List educationPaperQus = educationPaperQuMapper.selectPaperQuListByPaperId(paperId); +// // 筛选出非选择题和选择题 +// for (ExamQuestion examQuestion : examQuestionList) { +// for (EducationPaperScheme educationPaperScheme : educationPaperSchemeList) { +// if (examQuestion.getSubjectName().equals(educationPaperScheme.getSpName())) { +// Optional result = educationPaperQus.stream().filter(strs -> Objects.equals(strs.getQuId(), examQuestion.getQuId())).findFirst(); +// if (!result.isEmpty()) { +// examQuestion.setQuScores(educationPaperScheme.getQuScores()); +// examQuestion.setSort(result.get().getSort()); +// quList.add(examQuestion); +// break; +// } +// } +// } +// } +// // 判断选择题文件是否存在 +// if (noZipFileDO != null) { +// // 1-1、 穿插选择题判分 +// // 1-1-1、下载选择题文件 +// String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue()); +// File select_file = new File(select_qu); +// // 1-1-2、读取内容转换成json +// String select_string = readFileAsString(select_file.getPath()); +// Stu stu = stringToJson(select_string); +// if(stu!=null){ +// // 1-1-3、进行选择题判分 +// for (ExamQuestion examQuestion : quList) { +// if ("选择题".equals(examQuestion.getSubjectName())) { +// Optional result = stu.getQuestionResultMap().keySet().stream().filter(strs -> strs.equals(examQuestion.getQuId())).findFirst(); +// if (!result.isEmpty()) { +// String key = result.get(); +// String value = stu.getQuestionResultMap().get(key); +// // 查询该题的成绩 +// StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, key); +// // 判断是否做过该题 +// boolean isNull = false; +// if (stuPaperScoreDO == null) { +// stuPaperScoreDO = new StuPaperScoreDO(); +// stuPaperScoreDO.setStuId(stuId); +// stuPaperScoreDO.setQuId(key); +// stuPaperScoreDO.setPaperId(paperId); +// stuPaperScoreDO.setSort(examQuestion.getSort()); +// isNull = true; +// } +// double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), key, value, stuPaperScoreDO, isNull); +// score += selectScore; +// } else { +// StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); +// // 判断是否做过该题 +// boolean isNull = false; +// if (stuPaperScoreDO == null) { +// stuPaperScoreDO = new StuPaperScoreDO(); +// stuPaperScoreDO.setStuId(stuId); +// stuPaperScoreDO.setQuId(examQuestion.getQuId()); +// stuPaperScoreDO.setPaperId(paperId); +// stuPaperScoreDO.setSort(examQuestion.getSort()); +// isNull = true; +// } +// // 说明学生没有答题,直接给零分 +// double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), examQuestion.getQuId(), "", stuPaperScoreDO, isNull); +// score += selectScore; +// } +// } +// } +// } else { +// // 如果结果是null的话,说明学生没有作答,直接全部0分 +// for (ExamQuestion examQuestion : quList) { +// if ("选择题".equals(examQuestion.getSubjectName())) { +// StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); +// // 判断是否做过该题 +// boolean isNull = false; +// if (stuPaperScoreDO == null) { +// stuPaperScoreDO = new StuPaperScoreDO(); +// stuPaperScoreDO.setStuId(stuId); +// stuPaperScoreDO.setQuId(examQuestion.getQuId()); +// stuPaperScoreDO.setPaperId(paperId); +// stuPaperScoreDO.setSort(examQuestion.getSort()); +// isNull = true; +// } +// // 说明学生没有答题,直接给零分 +// double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), examQuestion.getQuId(), "", stuPaperScoreDO, isNull); +// score += selectScore; +// } +// } +// } +// // 1-1-4、删除文件 +// select_file.delete(); +// } +// // 2、判断文件路径是否存在 +// if (stuPaperFileDO != null) { +//// return CommonResult.error(100031, "试题文件没有上传,无法判分!"); +// // 3、下载文件 +// String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue()); +// File zip_file = new File(patn); +// // 4、获取到得是zip文件,需要解压 +// String stuFilePath = ZipUtil.unzipToNamedFolder(patn); +// // 5、解压之后得文件获取文件夹和文件 +// File folder = new File(stuFilePath); +// File[] files = folder.listFiles(); +// String stu_files = null; +// // 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容) +// if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!"); +// // if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!"); +// if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!"); +// // 判断学号是否正确 +// if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常"); +// // 5.2、查询试题ID +// File folders = new File(files[0].getPath()); +// File[] filess = folders.listFiles(); +// if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!"); +// if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!"); +// if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!"); +// // 判断学号是否正确 +// if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常"); +// // 5.3、查询出来所有试题 +// File qu_files = new File(filess[0].getPath()); +// // 所有试题文件夹 +// File[] filess_qu = qu_files.listFiles(); +// if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!"); +// for (File file : filess_qu) { +// // ** 接下来已经到了,每个课程题型了 file 得名称 +// // 5.3、查询出来所有试题 +// File cs_files = new File(file.getPath()); +// // 所有试题文件夹 +// File[] cs_file_list = cs_files.listFiles(); +// if (cs_file_list!=null){ +// for (File one_file : cs_file_list) { +// // 6、根据试题ID查询试题详情 +// String qu_id = file.getName(); +// Optional result = quList.stream().filter(quLists -> quLists.getQuId().equals(qu_id)).findFirst(); +// String quScore = result.get().getQuScores(); +// ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id); +// if (examQuestion != null) { +// // 7、进行对应得判分 +// // --- 7.1、查询试题文件 +// File qu_file = new File(one_file.getPath()); +// File[] qu_file_list = qu_file.listFiles(); +// if (qu_file_list == null) continue; +// // --- 7.2、通过文件名称进行判分 +// for (File file_one : qu_file_list) { +// // 判断名称 类似于 C语言程序设计。 课程+题型 +// System.out.println(one_file.getName()); +// StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId()); +// // 判断是否做过该题 +// boolean isNull = false; +// if (stuPaperScoreDO == null) { +// stuPaperScoreDO = new StuPaperScoreDO(); +// stuPaperScoreDO.setStuId(stuId); +// stuPaperScoreDO.setQuId(examQuestion.getQuId()); +// stuPaperScoreDO.setPaperId(paperId); +// stuPaperScoreDO.setSort(result.get().getSort()); +// isNull = true; +// } +// if ("编程题".equals(one_file.getName().split("\\.")[0])) { +// String judgementStr_C = ""; +// SourceAndText cpojo = judgementService.ProgrammingC(Double.parseDouble(quScore), one_file.getPath(), file_one.getName(), examQuestion, judgementStr_C); +// double c_score = cpojo.getScore(); +// String judgementStr = "

-----------------------------------------------------------

"; +// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +// judgementStr += cpojo.getText(); +// +// // 通过学号+试卷ID+试题ID进行查询 +// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +// if (stuPaperInfoDO != null) { +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +// } else { +// stuPaperInfoDO = new StuPaperInfoDO(); +// stuPaperInfoDO.setStuId(stuId); +// stuPaperInfoDO.setPaperId(paperId); +// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +// } +// +// score += c_score; +// stuPaperScoreDO.setScore(new BigDecimal(c_score)); +// // 原始正确分数 +// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +// // 判断题是否正确 +// if (c_score == Double.parseDouble(quScore)) { +// stuPaperScoreDO.setIsTrue(0); +// } else if (c_score == 0) { +// stuPaperScoreDO.setIsTrue(1); +// } else { +// stuPaperScoreDO.setIsTrue(2); +// } +// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +// if (isNull) { +// // 如果之前没做过,则插入该题的分数 +// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +// } else { +// // 如果之前做过,则更新该题的分数 +// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +// } +// System.out.println(c_score+"C语言程序设计得分"); +// break; +// } +// // wps 类型存在多级文文件夹,需要个性化设置 +// if ("文字".equals(one_file.getName().split("\\.")[0])) { // if (file_one.getPath().contains("文档")) { -// String judgementStrPptx = ""; -// SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrPptx); -// double wps_pptx_score = pptxpojo.getScore(); +// String judgementStrWord = ""; +// SourceAndText wordpojo = judgementWpsWordService.judgementWpsWord(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrWord); +// double wps_word_score = wordpojo.getScore(); // String judgementStr = "

-----------------------------------------------------------

"; // judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; -// judgementStr += pptxpojo.getText(); +// judgementStr += wordpojo.getText(); // // 通过学号+试卷ID+试题ID进行查询 // StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); // if (stuPaperInfoDO != null) { @@ -484,14 +437,14 @@ public class AutoToolsServiceImpl implements AutoToolsService{ // stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); // stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); // } -// score += wps_pptx_score; -// stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score)); +// score += wps_word_score; +// stuPaperScoreDO.setScore(new BigDecimal(wps_word_score)); // // 原始正确分数 // stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); // // 判断题是否正确 -// if (wps_pptx_score == Double.parseDouble(quScore)) { +// if (wps_word_score == Double.parseDouble(quScore)) { // stuPaperScoreDO.setIsTrue(0); -// } else if (wps_pptx_score == 0) { +// } else if (wps_word_score == 0) { // stuPaperScoreDO.setIsTrue(1); // } else { // stuPaperScoreDO.setIsTrue(2); @@ -504,20 +457,114 @@ public class AutoToolsServiceImpl implements AutoToolsService{ // // 如果之前做过,则更新该题的分数 // stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); // } -// System.out.println(wps_pptx_score+"wps_ppt得分"); +// System.out.println(wps_word_score+"wps_word得分"); // break; // } // } -// if ("表格".equals(one_file.getName().split("\\.")[0])) { -// double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion); -// score += wps_excel_score; -// stuPaperScoreDO.setScore(new BigDecimal(wps_excel_score)); +//// if ("演示".equals(one_file.getName().split("\\.")[0])) { +//// if (file_one.getPath().contains("文档")) { +//// String judgementStrPptx = ""; +//// SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrPptx); +//// double wps_pptx_score = pptxpojo.getScore(); +//// String judgementStr = "

-----------------------------------------------------------

"; +//// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +//// judgementStr += pptxpojo.getText(); +//// // 通过学号+试卷ID+试题ID进行查询 +//// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +//// if (stuPaperInfoDO != null) { +//// stuPaperInfoDO.setContent(judgementStr); +//// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +//// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +//// } else { +//// stuPaperInfoDO = new StuPaperInfoDO(); +//// stuPaperInfoDO.setStuId(stuId); +//// stuPaperInfoDO.setPaperId(paperId); +//// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +//// stuPaperInfoDO.setContent(judgementStr); +//// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +//// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +//// } +//// score += wps_pptx_score; +//// stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score)); +//// // 原始正确分数 +//// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +//// // 判断题是否正确 +//// if (wps_pptx_score == Double.parseDouble(quScore)) { +//// stuPaperScoreDO.setIsTrue(0); +//// } else if (wps_pptx_score == 0) { +//// stuPaperScoreDO.setIsTrue(1); +//// } else { +//// stuPaperScoreDO.setIsTrue(2); +//// } +//// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +//// if (isNull) { +//// // 如果之前没做过,则插入该题的分数 +//// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +//// } else { +//// // 如果之前做过,则更新该题的分数 +//// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +//// } +//// System.out.println(wps_pptx_score+"wps_ppt得分"); +//// break; +//// } +//// } +//// if ("表格".equals(one_file.getName().split("\\.")[0])) { +//// double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion); +//// score += wps_excel_score; +//// stuPaperScoreDO.setScore(new BigDecimal(wps_excel_score)); +//// // 原始正确分数 +//// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +//// // 判断题是否正确 +//// if (wps_excel_score == Double.parseDouble(quScore)) { +//// stuPaperScoreDO.setIsTrue(0); +//// } else if (wps_excel_score == 0) { +//// stuPaperScoreDO.setIsTrue(1); +//// } else { +//// stuPaperScoreDO.setIsTrue(2); +//// } +//// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +//// if (isNull) { +//// // 如果之前没做过,则插入该题的分数 +//// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +//// } else { +//// // 如果之前做过,则更新该题的分数 +//// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +//// } +//// System.out.println(wps_excel_score+"wps_excel得分"); +//// break; +//// } +// //windows文件处理 +// if ("文件处理".equals(one_file.getName().split("\\.")[0])) { +// String judgementStrFile = ""; +// File win_file = new File(one_file.getPath()); +// SourceAndText winfilepojo = fileServerice.run_file_point(Double.parseDouble(quScore),win_file, examQuestion, judgementStrFile); +// double win_file_score = winfilepojo.getScore(); +// String judgementStr = "

-----------------------------------------------------------

"; +// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +// judgementStr += winfilepojo.getText(); +// // 通过学号+试卷ID+试题ID进行查询 +// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +// if (stuPaperInfoDO != null) { +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +// } else { +// stuPaperInfoDO = new StuPaperInfoDO(); +// stuPaperInfoDO.setStuId(stuId); +// stuPaperInfoDO.setPaperId(paperId); +// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +// } +// score += win_file_score; +// stuPaperScoreDO.setScore(new BigDecimal(win_file_score)); // // 原始正确分数 // stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); // // 判断题是否正确 -// if (wps_excel_score == Double.parseDouble(quScore)) { +// if (win_file_score == Double.parseDouble(quScore)) { // stuPaperScoreDO.setIsTrue(0); -// } else if (wps_excel_score == 0) { +// } else if (win_file_score == 0) { // stuPaperScoreDO.setIsTrue(1); // } else { // stuPaperScoreDO.setIsTrue(2); @@ -530,220 +577,173 @@ public class AutoToolsServiceImpl implements AutoToolsService{ // // 如果之前做过,则更新该题的分数 // stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); // } -// System.out.println(wps_excel_score+"wps_excel得分"); +// System.out.println(win_file_score+"windows文件处理得分"); // break; // } - //windows文件处理 - if ("文件处理".equals(one_file.getName().split("\\.")[0])) { - String judgementStrFile = ""; - File win_file = new File(one_file.getPath()); - SourceAndText winfilepojo = fileServerice.run_file_point(Double.parseDouble(quScore),win_file, examQuestion, judgementStrFile); - double win_file_score = winfilepojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += winfilepojo.getText(); - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - score += win_file_score; - stuPaperScoreDO.setScore(new BigDecimal(win_file_score)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (win_file_score == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (win_file_score == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(win_file_score+"windows文件处理得分"); - break; - } - //浏览器操作 - // if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){ - if ("网络题".equals(one_file.getName().split("\\.")[0])) { - String judgementStrBrow = ""; - System.out.println(one_file); - File edge_file = new File(one_file.getPath()); - SourceAndText browsepojo= browserServerice.Judgement(Double.parseDouble(quScore),edge_file,examQuestion, judgementStrBrow); - double browse_score = browsepojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += browsepojo.getText(); - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - score += browse_score; - stuPaperScoreDO.setScore(new BigDecimal(browse_score)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (browse_score == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (browse_score == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(browse_score+"浏览器操作得分"); - - break; - } - if ("程序设计".equals(one_file.getName().split("\\.")[0])) { - String judgementStrMysql = ""; - System.out.println(one_file); - File mysql_file = new File(one_file.getPath()); - SourceAndText judgementpojo = mysqlServerice.Judgement(Double.parseDouble(quScore),mysql_file, examQuestion, judgementStrMysql); - double judgement = judgementpojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += judgementpojo.getText(); - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - score+=judgement; - stuPaperScoreDO.setScore(new BigDecimal(judgement)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (judgement == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (judgement == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(judgement+"mysql得分"); - break; - } - } - } - } - } - } - // 8、将解压之后得问及那继续重新压缩并上传到服务器,并删除文件和文件夹 - String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, "")); - File folderStuUpdateFile = new File(files[0].getPath()); - folderStuUpdateFile.delete(); - // 9、上传文件 - MultipartFile file = new CustomMultipartFile(zipPath); - String path = null; - fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())); - // 更新学生分数 - endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score); - // end、删除文件 - System.out.println(stuFilePath); - zip_file.delete(); - // folder.delete(); - deleteFolder(folder); - } - BigDecimal bd = new BigDecimal(Double.toString(score)); - // 保留两位小数并四舍五入 - bd = bd.setScale(2, RoundingMode.HALF_UP); - return CommonResult.success(bd); - } - public static void deleteFolder(File folder) { - if (folder.isDirectory()) { - File[] files = folder.listFiles(); - if (files != null) { - for (File file : files) { - deleteFolder(file); // 递归删除所有子文件/文件夹 - } - } - } - folder.delete(); // 删除空文件夹或文件 - } - /** - * 读取学生选择题答案 - * @param filePath 文件路径 - * @return 文本 - * @throws IOException 异常 - */ - public static String readFileAsString(String filePath) throws IOException { - return new String(Files.readAllBytes(Paths.get(filePath))); - } - - /** - * string to java对象 - * @param text 文本 - * @return java对象 - * @throws JsonProcessingException json异常 - */ - public static Stu stringToJson(String text) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); - Stu stu = mapper.readValue(text, Stu.class); - return stu; - } - - /** - * 转换Java对象 - */ - @Data - static class Stu { - private String stuId; - private String paperId; - private String taskId; - private Map questionResultMap; - } -} +// //浏览器操作 +// // if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){ +// if ("网络题".equals(one_file.getName().split("\\.")[0])) { +// String judgementStrBrow = ""; +// System.out.println(one_file); +// File edge_file = new File(one_file.getPath()); +// SourceAndText browsepojo= browserServerice.Judgement(Double.parseDouble(quScore),edge_file,examQuestion, judgementStrBrow); +// double browse_score = browsepojo.getScore(); +// String judgementStr = "

-----------------------------------------------------------

"; +// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +// judgementStr += browsepojo.getText(); +// // 通过学号+试卷ID+试题ID进行查询 +// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +// if (stuPaperInfoDO != null) { +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +// } else { +// stuPaperInfoDO = new StuPaperInfoDO(); +// stuPaperInfoDO.setStuId(stuId); +// stuPaperInfoDO.setPaperId(paperId); +// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +// } +// score += browse_score; +// stuPaperScoreDO.setScore(new BigDecimal(browse_score)); +// // 原始正确分数 +// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +// // 判断题是否正确 +// if (browse_score == Double.parseDouble(quScore)) { +// stuPaperScoreDO.setIsTrue(0); +// } else if (browse_score == 0) { +// stuPaperScoreDO.setIsTrue(1); +// } else { +// stuPaperScoreDO.setIsTrue(2); +// } +// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +// if (isNull) { +// // 如果之前没做过,则插入该题的分数 +// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +// } else { +// // 如果之前做过,则更新该题的分数 +// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +// } +// System.out.println(browse_score+"浏览器操作得分"); +// +// break; +// } +// if ("程序设计".equals(one_file.getName().split("\\.")[0])) { +// String judgementStrMysql = ""; +// System.out.println(one_file); +// File mysql_file = new File(one_file.getPath()); +// SourceAndText judgementpojo = mysqlServerice.Judgement(Double.parseDouble(quScore),mysql_file, examQuestion, judgementStrMysql); +// double judgement = judgementpojo.getScore(); +// String judgementStr = "

-----------------------------------------------------------

"; +// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +// judgementStr += judgementpojo.getText(); +// // 通过学号+试卷ID+试题ID进行查询 +// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +// if (stuPaperInfoDO != null) { +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +// } else { +// stuPaperInfoDO = new StuPaperInfoDO(); +// stuPaperInfoDO.setStuId(stuId); +// stuPaperInfoDO.setPaperId(paperId); +// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +// } +// score+=judgement; +// stuPaperScoreDO.setScore(new BigDecimal(judgement)); +// // 原始正确分数 +// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +// // 判断题是否正确 +// if (judgement == Double.parseDouble(quScore)) { +// stuPaperScoreDO.setIsTrue(0); +// } else if (judgement == 0) { +// stuPaperScoreDO.setIsTrue(1); +// } else { +// stuPaperScoreDO.setIsTrue(2); +// } +// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +// if (isNull) { +// // 如果之前没做过,则插入该题的分数 +// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +// } else { +// // 如果之前做过,则更新该题的分数 +// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +// } +// System.out.println(judgement+"mysql得分"); +// break; +// } +// } +// } +// } +// } +// } +// // 8、将解压之后得问及那继续重新压缩并上传到服务器,并删除文件和文件夹 +// String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, "")); +// File folderStuUpdateFile = new File(files[0].getPath()); +// folderStuUpdateFile.delete(); +// // 9、上传文件 +// MultipartFile file = new CustomMultipartFile(zipPath); +// String path = null; +// fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())); +// // 更新学生分数 +// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score); +// // end、删除文件 +// System.out.println(stuFilePath); +// zip_file.delete(); +// // folder.delete(); +// deleteFolder(folder); +// } +// BigDecimal bd = new BigDecimal(Double.toString(score)); +// // 保留两位小数并四舍五入 +// bd = bd.setScale(2, RoundingMode.HALF_UP); +// return CommonResult.success(bd); +// } +// public static void deleteFolder(File folder) { +// if (folder.isDirectory()) { +// File[] files = folder.listFiles(); +// if (files != null) { +// for (File file : files) { +// deleteFolder(file); // 递归删除所有子文件/文件夹 +// } +// } +// } +// folder.delete(); // 删除空文件夹或文件 +// } +// /** +// * 读取学生选择题答案 +// * @param filePath 文件路径 +// * @return 文本 +// * @throws IOException 异常 +// */ +// public static String readFileAsString(String filePath) throws IOException { +// return new String(Files.readAllBytes(Paths.get(filePath))); +// } +// +// /** +// * string to java对象 +// * @param text 文本 +// * @return java对象 +// * @throws JsonProcessingException json异常 +// */ +// public static Stu stringToJson(String text) throws JsonProcessingException { +// ObjectMapper mapper = new ObjectMapper(); +// Stu stu = mapper.readValue(text, Stu.class); +// return stu; +// } +// +// /** +// * 转换Java对象 +// */ +// @Data +// static class Stu { +// private String stuId; +// private String paperId; +// private String taskId; +// private Map questionResultMap; +// } +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java index f076ea46..1d88705d 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java @@ -29,5 +29,4 @@ public interface JudgementWpsExcelService { */ List programmingWpsExcel(String path) throws Exception; - SourceAndText judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java index c16fcd4b..3ed9aa09 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java @@ -11,13 +11,15 @@ import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; import pc.exam.pp.module.judgement.dal.mysql.wpsxlsx.WpsXlsxLinkMapper; -import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; +//import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.HtmlAppender; import pc.exam.pp.module.judgement.utils.wps_excel.WpsExcelUtils; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo; -import java.io.File; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; import java.util.List; @Service @@ -26,8 +28,8 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { @Resource WpsXlsxLinkMapper wpsXlsxLinkMapper; - @Resource - AutoToolsService autoToolsService; +// @Resource +// AutoToolsService autoToolsService; @Resource ConfigService configService; @@ -37,65 +39,43 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { // 1、获取文件临时下载路径 ConfigDO config = configService.getConfigByKey("file_down_path"); // 2、下载文件并返回文件完整路径 - String pathName = autoToolsService.downloadStudentFile(path, config.getValue()); + String pathName = downloadStudentFile(path, config.getValue()); List margins = WpsExcelUtils.wpsExcel(pathName, "1"); // 5、已经读取完得考点删除源文件 File file = new File(pathName); file.delete(); return margins; } + public String downloadStudentFile(String fileUrl, String filePath) { + try { + URL url = new URL(fileUrl); + URLConnection connection = url.openConnection(); - @Override - public SourceAndText judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception { - SourceAndText sourceAndText = new SourceAndText(); - // 1创建log文件txt,用于记录 - File pathCDir = new File(pathC); - File parentDir = pathCDir.getParentFile(); + String fileName = new File(url.getPath()).getName(); + File dir = new File(filePath); + if (!dir.exists()) dir.mkdirs(); - // 拼接同级目录下的目标文件路径 - String targetFilePath = new File(parentDir, "WPS_Xlsx判分过程.txt").getPath(); - LogFileUtils.createFile(targetFilePath); - LogFileUtils.writeLine("✅ 开始WPS_Xlsx判分"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 开始WPS_Xlsx判分"); - double wpsXlsxScore = 0; - List margins = WpsExcelUtils.wpsExcel(path, "0"); - // 3、获取答案得组成 - List answerList = examQuestion.getAnswerList(); - // 考点 sheetNumber@type@secondType@englishName@value - // 中文 sheetName@typeName@secondTypeName@chineseName@value - // 4、进行关联判断 - for (ExamQuestionAnswer examQuestionAnswer : answerList) { - boolean flag = false; - double one_sorce = 0; - for (WpsPptxJudgementDto xlsxInfoVo : margins) { - // 原始考点 - if (xlsxInfoVo.getContent().equals(examQuestionAnswer.getContent())) { - flag = true; - // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 - if (examQuestionAnswer.getScoreRate().equals("1")) { - // 说明权重相等,直接平分分数 - one_sorce = sorce / answerList.size(); - } else { - one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate()); - } - break; + File saveFile = new File(dir, fileName); + + try (InputStream in = connection.getInputStream(); + FileOutputStream out = new FileOutputStream(saveFile)) { + + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); } + + System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath()); + return saveFile.getAbsolutePath(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); } - wpsXlsxScore += one_sorce; - if (flag) { - LogFileUtils.writeLine("✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - } else { - LogFileUtils.writeLine("❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - } + } catch (IOException e) { + System.err.println("❌ 下载失败: " + e.getMessage()); + return null; } - LogFileUtils.writeLine("✅ 结束WPS_Xlsx判分,试题得分:" + wpsXlsxScore); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 结束WPS_Xlsx判分,试题得分:" + wpsXlsxScore); - sourceAndText.setText(judgementStr); - sourceAndText.setScore(wpsXlsxScore); - // 关闭已经打开得文件 - LogFileUtils.close(); - return sourceAndText; } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java index 56cc5d6b..f4f4986c 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java @@ -1,14 +1,8 @@ package pc.exam.pp.module.judgement.service.wps_pptx; -import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO; - -import java.io.IOException; import java.util.List; /** @@ -17,10 +11,9 @@ import java.util.List; public interface JudgementWpsPptxService { List programmingWpsPptx(String path) throws Exception; -// - SourceAndText judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception; // List getWpsPptxInfo(List pptxInfoPointsVos) throws IOException; List judgementWpsPptx(List judgementReq, String path) throws Exception; + } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java index 2cb5401a..9a579d47 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java @@ -8,7 +8,7 @@ import pc.exam.pp.module.exam.utils.file.LogFileUtils; import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; +//import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.HtmlAppender; import pc.exam.pp.module.judgement.utils.wps_pptx.JudgementWpsPPT; @@ -18,7 +18,9 @@ import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO; import pc.exam.pp.module.system.service.user.AdminUserService; -import java.io.IOException; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; import java.util.ArrayList; import java.util.List; @@ -30,8 +32,8 @@ import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.get @Service public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { - @Resource - AutoToolsService autoToolsService; +// @Resource +// AutoToolsService autoToolsService; @Resource ConfigService configService; @@ -63,7 +65,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { // pathName = config.getValue() + "\\" + user.getId() + "\\" + strPaht[strPaht.length - 1]; // } else { // 2、下载文件并返回文件完整路径 - pathName = autoToolsService.downloadStudentFile(path, config.getValue() + "\\" + user.getId()); + pathName = downloadStudentFile(path, config.getValue() + "\\" + user.getId()); // } // 4、pptx文件读取并返回考点及说明信息 // List margins = WpsPptxUtils.wpsPptx(pathName, paragraphList); @@ -74,65 +76,37 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { return pptxInfoList; } - @Override - public SourceAndText judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception { - SourceAndText sourceAndText = new SourceAndText(); - // 创建log文件txt,用于记录 - LogFileUtils.createFile(pathC + "/WPS_Word判分过程.txt"); - LogFileUtils.writeLine("✅ 开始WPS_Pptx判分"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 开始WPS_Pptx判分"); - double wpsPptScore = 0; - List judgementReq = new ArrayList<>(); - // 3、获取答案得组成 - List answerList = examQuestion.getAnswerList(); - for (ExamQuestionAnswer examQuestionAnswer : answerList) { - JudgementReqVo judgementReqVo = new JudgementReqVo(); - // 拆分数据、 - String[] pptxInfos = examQuestionAnswer.getContent().split("@!"); - judgementReqVo.setFileNama(pptxInfos[0]); - judgementReqVo.setParagraph(pptxInfos[1]); - judgementReqVo.setTitle(pptxInfos[2]); - judgementReqVo.setValueList(pptxInfos[3]); - judgementReqVo.setType(pptxInfos[4]); - judgementReqVo.setIsText(pptxInfos[5]); - judgementReqVo.setIsTrue(pptxInfos[6]); - judgementReqVo.setIsParameter(pptxInfos[7]); - judgementReqVo.setPath(path); - judgementReq.add(judgementReqVo); - } - List judgementDtos = JudgementWpsPPT.getValues(judgementReq); - // 4、进行关联判断 - for (ExamQuestionAnswer examQuestionAnswer : answerList) { - boolean flag = false; - double one_sorce = 0; - for (WpsPptxJudgementDto pptxJudgementDto : judgementDtos) { - if (pptxJudgementDto.getContent().equals(examQuestionAnswer.getContent())) { - flag = true; - // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 - if (examQuestionAnswer.getScoreRate().equals("1")) { - // 说明权重相等,直接平分分数 - one_sorce = sorce / answerList.size(); - } else { - one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate()); - } - break; + public String downloadStudentFile(String fileUrl, String filePath) { + try { + URL url = new URL(fileUrl); + URLConnection connection = url.openConnection(); + + String fileName = new File(url.getPath()).getName(); + File dir = new File(filePath); + if (!dir.exists()) dir.mkdirs(); + + File saveFile = new File(dir, fileName); + + try (InputStream in = connection.getInputStream(); + FileOutputStream out = new FileOutputStream(saveFile)) { + + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); } + + System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath()); + return saveFile.getAbsolutePath(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); } - wpsPptScore += one_sorce; - if (flag) { - LogFileUtils.writeLine("✅" + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - } else { - LogFileUtils.writeLine("❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - } + } catch (IOException e) { + System.err.println("❌ 下载失败: " + e.getMessage()); + return null; } - LogFileUtils.writeLine("✅ 结束WPS_Pptx判分,试题得分:" + wpsPptScore); - // 关闭已经打开得文件 - LogFileUtils.close(); - sourceAndText.setScore(wpsPptScore); - sourceAndText.setText(judgementStr); - return sourceAndText; } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java index ae8a1cd3..726968e4 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java @@ -2,11 +2,13 @@ package pc.exam.pp.module.judgement.service.wps_word; +import org.springframework.web.multipart.MultipartFile; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsDocxInfoVo; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; +import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; @@ -22,24 +24,19 @@ import java.util.List; public interface JudgementWpsWordService { List docxMaster(List wpsDocxInfoVos) throws Exception; - /** - * 获取word文件内得考点及描述 - * @param path minio文件路径 - * @return 文件内得考点及描述 - * @throws Exception 异常 - */ - List programmingWpsWord(String path) throws Exception; - List programmingInfo(List wpsWordReqDtos) throws Exception; + List docxDataInfo(MultipartFile file) throws Exception; + +// /** +// * 获取word文件内得考点及描述 +// * @param path minio文件路径 +// * @return 文件内得考点及描述 +// * @throws Exception 异常 +// */ +// List programmingWpsWord(String path) throws Exception; +// +// List programmingInfo(List wpsWordReqDtos) throws Exception; +// - /** - * 读取考生文件,与题型中要求进行判断 - * @param path 文件路径 - * @param examQuestion 试题参数 - * @param sorce 试题分数 - * @return 得分 - * @throws Exception 异常 - */ - SourceAndText judgementWpsWord(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java index 8778abd2..91f937b5 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java @@ -1,9 +1,8 @@ package pc.exam.pp.module.judgement.service.wps_word; - - import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer; import pc.exam.pp.module.exam.utils.file.LogFileUtils; @@ -14,13 +13,11 @@ import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordChineseFuncti import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper; -import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.HtmlAppender; -import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils; +import pc.exam.pp.module.judgement.utils.wps_word.docx4j.DocxConversion; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.DocxMaster; +import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; @@ -39,137 +36,56 @@ import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.get @Service public class JudgementWpsWordServiceImpl implements JudgementWpsWordService { - @Resource - WpsWordLinkMapper wpsWordLinkMapper; - - @Resource - AutoToolsService autoToolsService; - @Resource ConfigService configService; + @Resource private AdminUserService userService; @Override public List docxMaster(List wpsDocxInfoVos) throws Exception { -// String pathName = ""; -// ConfigDO config = configService.getConfigByKey("file_down_wps_word_path"); -// AdminUserDO user = userService.getUser(getLoginUserId()); -// // 2、下载文件并返回文件完整路径 -// pathName = autoToolsService.downloadStudentFile(path, config.getValue() + "\\" + user.getId()); return DocxMaster.docxMaster(wpsDocxInfoVos); } @Override - public List programmingWpsWord(String path) throws Exception { - String pathName = ""; - String[] strPaht = path.split("/"); - // 1、获取文件临时下载路径 - ConfigDO config = configService.getConfigByKey("file_down_wps_word_path"); - AdminUserDO user = userService.getUser(getLoginUserId()); -// Path paths = Paths.get(config.getValue() + "\\" + user.getId()); -// if (Files.exists(paths)) { -// pathName = config.getValue() + "\\" + user.getId() + "\\" + strPaht[strPaht.length - 1]; -// } else { - // 2、下载文件并返回文件完整路径 - pathName = autoToolsService.downloadStudentFile(path, config.getValue() + "\\" + user.getId()); -// } - // 4、docx文件读取并返回考点及说明信息 - List margins = WpsWordUtils.wpWord(pathName); - // 5、已经读取完得考点删除源文件 -// File file = new File(pathName); -// file.delete(); - return margins; + public List docxDataInfo(MultipartFile file) throws Exception { + return DocxConversion.DocxDataInfos(file); } - @Override - public List programmingInfo(List wordReqDto) throws Exception { -// List functionList = new ArrayList<>(); -// for (String function : wordReqDto.getFunction()) { -// WpsWordChineseFunctionDto functionDto = new WpsWordChineseFunctionDto(); -// functionDto.setFunction(function); -// WpsWordLinkDO wpsWordLinkDO = wpsWordLinkMapper.selectByNodeFunction(function); -// functionDto.setChineseName(wpsWordLinkDO.getToChinese()); -// functionList.add(functionDto); -// } - List judgementDtos = WpsWordUtils.getWordInfo(wordReqDto); - return judgementDtos; - } - - @Override - public SourceAndText judgementWpsWord(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception { - SourceAndText sourceAndText = new SourceAndText(); - // 创建log文件txt,用于记录 - LogFileUtils.createFile(pathC + "/WPS_Word判分过程.txt"); - LogFileUtils.writeLine("✅ 开始WPS_Word判分"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 开始WPS_Word判分"); - double wps_word_sorce = 0; - // 2、docx文件读取并返回考点及说明信息 -// List margins = WpsWordUtils.wps_word(path); - // 3、获取答案得组成 - List answerList = examQuestion.getAnswerList(); - // 4、进行关联判断 - for (ExamQuestionAnswer examQuestionAnswer : answerList) { - // 拆分数据、 - String[] wordInfos = examQuestionAnswer.getContent().split("-/"); - String[] chineseName = examQuestionAnswer.getContentIn().split("-"); - String[] typeList = examQuestionAnswer.getImage().split("-"); - // 创建拼接数据 - // 只取三层结构 - List wordReqDto = new ArrayList<>(); - WpsWordReqDto wpsWordReqDto = new WpsWordReqDto(); - wpsWordReqDto.setName(examQuestionAnswer.getContentIn()); - wpsWordReqDto.setEnglishName(wordInfos[0].split("]")[0] + "]"); - wpsWordReqDto.setFilePath(path); - // 存放类型 - wpsWordReqDto.setType(typeList[0]); - wpsWordReqDto.setBelongTo(typeList[1]); - wpsWordReqDto.setIsboo(typeList[2]); - wpsWordReqDto.setUnit(typeList[3]); - wpsWordReqDto.setFunction(wordInfos[0]); - wpsWordReqDto.setIsExam("1"); - wordReqDto.add(wpsWordReqDto); - System.out.println(examQuestionAnswer.getContentIn()); - System.out.println(examQuestionAnswer.getContent()); - List judgementDtos = WpsWordUtils.getWordInfo(wordReqDto); - boolean flag = false; - double one_sorce = 0; - for (WpsWordJudgementDto wordJudgementDto : judgementDtos) { - if (wordJudgementDto.getContent() != null) { -// for (String str : wordJudgementDto.getFunction()) { - int index = 0; - if (wordJudgementDto.getContent().equals(examQuestionAnswer.getContent())) { - flag = true; - // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 - if (examQuestionAnswer.getScoreRate().equals("1")) { - // 说明权重相等,直接平分分数 - one_sorce = sorce / answerList.size(); - } else { - one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate()); - } - break; - } -// } - } - } - wps_word_sorce += one_sorce; - if (flag) { - LogFileUtils.writeLine("✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); - - } else { - LogFileUtils.writeLine("❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); - - } - } - LogFileUtils.writeLine("✅ 结束WPS_Word判分,试题得分:" + wps_word_sorce); - // 关闭已经打开得文件 - LogFileUtils.close(); - sourceAndText.setScore(wps_word_sorce); - sourceAndText.setText(judgementStr); - - return sourceAndText; - } +// @Override +// public List programmingWpsWord(String path) throws Exception { +// String pathName = ""; +// String[] strPaht = path.split("/"); +// // 1、获取文件临时下载路径 +// ConfigDO config = configService.getConfigByKey("file_down_wps_word_path"); +// AdminUserDO user = userService.getUser(getLoginUserId()); +//// Path paths = Paths.get(config.getValue() + "\\" + user.getId()); +//// if (Files.exists(paths)) { +//// pathName = config.getValue() + "\\" + user.getId() + "\\" + strPaht[strPaht.length - 1]; +//// } else { +// // 2、下载文件并返回文件完整路径 +// pathName = autoToolsService.downloadStudentFile(path, config.getValue() + "\\" + user.getId()); +//// } +// // 4、docx文件读取并返回考点及说明信息 +// List margins = WpsWordUtils.wpWord(pathName); +// // 5、已经读取完得考点删除源文件 +//// File file = new File(pathName); +//// file.delete(); +// return margins; +// } +// +// @Override +// public List programmingInfo(List wordReqDto) throws Exception { +//// List functionList = new ArrayList<>(); +//// for (String function : wordReqDto.getFunction()) { +//// WpsWordChineseFunctionDto functionDto = new WpsWordChineseFunctionDto(); +//// functionDto.setFunction(function); +//// WpsWordLinkDO wpsWordLinkDO = wpsWordLinkMapper.selectByNodeFunction(function); +//// functionDto.setChineseName(wpsWordLinkDO.getToChinese()); +//// functionList.add(functionDto); +//// } +// List judgementDtos = WpsWordUtils.getWordInfo(wordReqDto); +// return judgementDtos; +// } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkService.java deleted file mode 100644 index 8d87834a..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkService.java +++ /dev/null @@ -1,120 +0,0 @@ -package pc.exam.pp.module.judgement.service.wps_word; - -import pc.exam.pp.framework.common.util.collection.CollectionUtils; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; - -import java.util.*; - -/** - * 节点 Service 接口 - * - * @author 朋辰 - */ -public interface WpsWordLinkService { - - /** - * 创建节点 - * - * @param createReqVO 节点信息 - * @return 节点编号 - */ - Long createWord(WordSaveReqVO createReqVO); - - /** - * 更新节点 - * - * @param updateReqVO 节点信息 - */ - void updateWord(WordSaveReqVO updateReqVO); - - /** - * 删除节点 - * - * @param id 节点编号 - */ - void deleteWord(Long id); - - /** - * 获得节点信息 - * - * @param id 节点编号 - * @return 节点信息 - */ - WpsWordLinkDO getWord(Long id); - - /** - * 获得节点信息数组 - * - * @param ids 节点编号数组 - * @return 节点信息数组 - */ - List getWordList(Collection ids); - - /** - * 筛选节点列表 - * - * @param reqVO 筛选条件请求 VO - * @return 节点列表 - */ - List getWordList(WordListReqVO reqVO); - - /** - * 筛选节点列表 - * - * @param reqVO 筛选条件请求 VO - * @return 节点列表 - */ - List getWordInfoList(WordListReqVO reqVO); - - /** - * 获得指定编号的节点 Map - * - * @param ids 节点编号数组 - * @return 节点 Map - */ - default Map getWordMap(Collection ids) { - List list = getWordList(ids); - return CollectionUtils.convertMap(list, WpsWordLinkDO::getId); - } - - /** - * 获得指定节点的所有子节点 - * - * @param id 节点编号 - * @return 子节点列表 - */ - default List getChildWordList(Long id) { - return getChildWordList(Collections.singleton(id)); - } - - /** - * 获得指定节点的所有子节点 - * - * @param ids 节点编号数组 - * @return 子节点列表 - */ - List getChildWordList(Collection ids); - - /** - * 获得所有子节点,从缓存中 - * - * @param id 父节点编号 - * @return 子节点列表 - */ - Set getChildWordIdListFromCache(Long id); - - /** - * 校验节点们是否有效。如下情况,视为无效: - * 1. 节点编号不存在 - * 2. 节点被禁用 - * - * @param ids 角色编号数组 - */ - void validateWordList(Collection ids); - - List getWordTreeList(); - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkServiceImpl.java deleted file mode 100644 index adacf0aa..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/WpsWordLinkServiceImpl.java +++ /dev/null @@ -1,246 +0,0 @@ -package pc.exam.pp.module.judgement.service.wps_word; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import com.google.common.annotations.VisibleForTesting; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; -import pc.exam.pp.framework.common.enums.CommonStatusEnum; -import pc.exam.pp.framework.common.util.object.BeanUtils; -import pc.exam.pp.framework.datapermission.core.annotation.DataPermission; -import pc.exam.pp.framework.tenant.core.aop.TenantIgnore; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; -import pc.exam.pp.module.system.dal.redis.RedisKeyConstants; - -import java.util.*; - -import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; -import static pc.exam.pp.framework.common.util.collection.CollectionUtils.convertSet; -import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*; - -/** - * 节点 Service 实现类 - * - */ -@Service -@Validated -@Slf4j -public class WpsWordLinkServiceImpl implements WpsWordLinkService { - - @Resource - private WpsWordLinkMapper wpsWordLinkMapper; - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_WORD_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public Long createWord(WordSaveReqVO createReqVO) { - if (createReqVO.getParentId() == null) { - createReqVO.setParentId(WpsWordLinkDO.PARENT_ID_ROOT); - } - // 校验父节点的有效性 - validateParentWord(null, createReqVO.getParentId()); - // 校验节点名的唯一性 - validateWordNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); - - // 插入节点 - WpsWordLinkDO wpsWordLinkDO = BeanUtils.toBean(createReqVO, WpsWordLinkDO.class); - wpsWordLinkMapper.insert(wpsWordLinkDO); - return wpsWordLinkDO.getId(); - } - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_WORD_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public void updateWord(WordSaveReqVO updateReqVO) { - if (updateReqVO.getParentId() == null) { - updateReqVO.setParentId(WpsWordLinkDO.PARENT_ID_ROOT); - } - // 校验自己存在 - validateWordExists(updateReqVO.getId()); - // 校验父节点的有效性 - validateParentWord(updateReqVO.getId(), updateReqVO.getParentId()); - // 校验节点名的唯一性 - validateWordNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); - - // 更新节点 - WpsWordLinkDO updateObj = BeanUtils.toBean(updateReqVO, WpsWordLinkDO.class); - wpsWordLinkMapper.updateById(updateObj); - } - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_WORD_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public void deleteWord(Long id) { - // 校验是否存在 - validateWordExists(id); - // 校验是否有子节点 - if (wpsWordLinkMapper.selectCountByParentId(id) > 0) { - throw exception(WORD_NOT_FOUND); - } - // 删除节点 - wpsWordLinkMapper.deleteById(id); - } - - @VisibleForTesting - void validateWordExists(Long id) { - if (id == null) { - return; - } - WpsWordLinkDO wpsWordLinkDO = wpsWordLinkMapper.selectById(id); - if (wpsWordLinkDO == null) { - throw exception(WORD_NOT_FOUND); - } - } - - @VisibleForTesting - void validateParentWord(Long id, Long parentId) { - if (parentId == null || WpsWordLinkDO.PARENT_ID_ROOT.equals(parentId)) { - return; - } - // 1. 不能设置自己为父节点 - if (Objects.equals(id, parentId)) { - throw exception(WORD_PARENT_ERROR); - } - // 2. 父节点不存在 - WpsWordLinkDO parentWord = wpsWordLinkMapper.selectById(parentId); - if (parentWord == null) { - throw exception(WORD_PARENT_NOT_EXITS); - } - // 3. 递归校验父节点,如果父节点是自己的子节点,则报错,避免形成环路 - if (id == null) { // id 为空,说明新增,不需要考虑环路 - return; - } - for (int i = 0; i < Short.MAX_VALUE; i++) { - // 3.1 校验环路 - parentId = parentWord.getParentId(); - if (Objects.equals(id, parentId)) { - throw exception(WORD_PARENT_IS_CHILD); - } - // 3.2 继续递归下一级父节点 - if (parentId == null || WpsWordLinkDO.PARENT_ID_ROOT.equals(parentId)) { - break; - } - parentWord = wpsWordLinkMapper.selectById(parentId); - if (parentWord == null) { - break; - } - } - } - - @VisibleForTesting - void validateWordNameUnique(Long id, Long parentId, String name) { - WpsWordLinkDO wpsWordLinkDO = wpsWordLinkMapper.selectByParentIdAndName(parentId, name); - if (wpsWordLinkDO == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的节点 - if (id == null) { - throw exception(WORD_NAME_DUPLICATE); - } - if (ObjectUtil.notEqual(wpsWordLinkDO.getId(), id)) { - throw exception(WORD_NAME_DUPLICATE); - } - } - - @Override - public WpsWordLinkDO getWord(Long id) { - return wpsWordLinkMapper.selectById(id); - } - - @Override - public List getWordList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return Collections.emptyList(); - } - return wpsWordLinkMapper.selectBatchIds(ids); - } - - @Override - public List getWordList(WordListReqVO reqVO) { - List list = wpsWordLinkMapper.selectList(reqVO); - list.sort(Comparator.comparing(WpsWordLinkDO::getSort)); - return list; - } - - @Override - public List getWordInfoList(WordListReqVO reqVO) { - List wordList = new ArrayList<>(); - WpsWordLinkDO data = wpsWordLinkMapper.selectByNodeFunction(reqVO.getNodeFunction()); - if (data == null) { - return Collections.emptyList(); - } - List wpsWordLinkDOS = wpsWordLinkMapper.selectInfoList(data.getId()); - // 在依次判断是否还有子数据 - for (WpsWordLinkDO wpsWordLinkDO : wpsWordLinkDOS) { - wordList.add(wpsWordLinkDO); - List datas = wpsWordLinkMapper.selectInfoList(wpsWordLinkDO.getId()); - if (datas != null) { - for (WpsWordLinkDO wpsWordLinkDO1 : datas) { - wordList.add(wpsWordLinkDO1); - } - } - } - return wordList; - } - - @Override - public List getChildWordList(Collection ids) { - List children = new LinkedList<>(); - // 遍历每一层 - Collection parentIds = ids; - for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 - // 查询当前层,所有的子节点 - List words = wpsWordLinkMapper.selectListByParentId(parentIds); - // 1. 如果没有子节点,则结束遍历 - if (CollUtil.isEmpty(words)) { - break; - } - // 2. 如果有子节点,继续遍历 - children.addAll(words); - parentIds = convertSet(words, WpsWordLinkDO::getId); - } - return children; - } - - @Override - @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存 - @Cacheable(cacheNames = RedisKeyConstants.WPS_WORD_CHILDREN_ID_LIST, key = "#id") - public Set getChildWordIdListFromCache(Long id) { - List children = getChildWordList(id); - return convertSet(children, WpsWordLinkDO::getId); - } - - @Override - public void validateWordList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 获得科室信息 - Map wordMap = getWordMap(ids); - // 校验 - ids.forEach(id -> { - WpsWordLinkDO word = wordMap.get(id); - if (word == null) { - throw exception(WORD_NOT_FOUND); - } - if (!CommonStatusEnum.ENABLE.getStatus().equals(word.getStatus())) { - throw exception(WORD_NOT_ENABLE, word.getName()); - } - }); - } - - @Override - @TenantIgnore - public List getWordTreeList() { - return wpsWordLinkMapper.selectTreeListByNodeFunction(); - } - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java index 14d3fb46..8a09584c 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java @@ -1,6 +1,5 @@ package pc.exam.pp.module.judgement.utils.tree; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; @@ -32,29 +31,7 @@ public class TreeUtils { // } // return roots; // } - - public static List buildTree(List flatList) { - Map nodeMap = new HashMap<>(); - List roots = new ArrayList<>(); - - // 先放入 map - for (WpsWordLinkDO node : flatList) { - nodeMap.put(Math.toIntExact(node.getId()), node); - } - - // 构建树关系 - for (WpsWordLinkDO node : flatList) { - if (node.getParentId() == 0) { - roots.add(node); - } else { - WpsWordLinkDO parent = nodeMap.get(node.getParentId().intValue()); - if (parent != null) { - parent.getChildren().add(node); - } - } - } - return roots; - } +// } public static List buildTreeXlsx(List flatList) { Map nodeMap = new HashMap<>(); List roots = new ArrayList<>(); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/WpsWordUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/WpsWordUtils.java index 179e2e9a..4daf5e57 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/WpsWordUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/WpsWordUtils.java @@ -1,1279 +1,1279 @@ -package pc.exam.pp.module.judgement.utils.wps_word; - -import org.apache.commons.io.IOUtils; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.xwpf.usermodel.*; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordChineseFunctionDto; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.utils.TwipConverter; -import pc.exam.pp.module.judgement.utils.wps_word.vo.*; -import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils; - -import javax.xml.namespace.QName; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.IntStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -/** - * @author REN - */ -public class WpsWordUtils { - public static String getStringRandom() { - String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - Random random = new Random(); - StringBuilder sb = new StringBuilder(); - - // 生成指定长度的随机字符字符串 - for (int i = 0; i < 10; i++) { - int randomIndex = random.nextInt(characters.length()); - // 随机字符 - sb.append(characters.charAt(randomIndex)); - } - return sb.toString(); - } - - public static List getWordInfo(List wpsWordReqDtos) throws Exception { - String filePath = wpsWordReqDtos.get(0).getFilePath(); - // 创建返回数组 - List judgementList = new ArrayList<>(); - // 创建文件路径数组 - List> filePathList = new ArrayList<>(); - for (WpsWordReqDto wpsWordReqDto : wpsWordReqDtos) { - try (OPCPackage pkg = OPCPackage.open(wpsWordReqDto.getFilePath()); - XWPFDocument document = new XWPFDocument(pkg)) { - for (PackagePart part : pkg.getParts()) { - String entryName = part.getPartName().getName(); - if (entryName.contains("word/_rels") && entryName.contains(".xml.rels")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - // 解析 xmlContent - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); - // 存放数据 - while (cursor.toNextSelection()) { - Map map = new HashMap<>(); - String rId = cursor.getAttributeText(new QName("Id")); - String target = cursor.getAttributeText(new QName("Target")); - map.put(rId, target); - filePathList.add(map); - } - } - } - } - XmlObject docXml = document.getDocument(); - XmlCursor cursor = docXml.newCursor(); - String nameSpace = WpsWordNameSpaces.getNameSpace(cursor.xmlText()); - // 需要联合查询数据,查询位置xml来获取准确的文件 - // 开始查询标签 - // 1、段落 - if ("0".equals(wpsWordReqDto.getBelongTo())) { - if (wpsWordReqDto.getFunction().contains("w:cols")) { - XmlCursor wColsCursor = cursor.newCursor(); - XmlCursor wColsCursors = null; - // 如果是分栏需要单独进行查询 - // 需要查找查询第几个段落 - String number = wpsWordReqDto.getFunction().split("]")[0]; - number = number.split("\\[")[1]; - boolean flag = true; - int numbers = Integer.parseInt(number); - while (flag) { - numbers += 1; - // 向下查询是否存在样式段落 - String nameSpaces = nameSpace + "(//w:p)["+numbers+"]"; - wColsCursor.selectPath(nameSpaces); - if (wColsCursor.toNextSelection()) { - if (wColsCursor.xmlText().contains("w:cols")) { - System.out.println(wColsCursor.xmlText()); - wColsCursors = wColsCursor.newCursor(); - flag = false; - } - } - if (numbers > 20) { - flag = false; - } - } - if (wColsCursors != null) { - String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1]; - System.out.println(wColsCursors.xmlText()); - wColsCursors.selectPath(nameSpaceCols); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - if (wColsCursors.toNextSelection()) { - String value = wColsCursors.getTextValue(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setScoreRate("1"); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - // 查询指定值,返回固定的文本 - judgementList.add(judgement); - } - } - } else { - String function = wpsWordReqDto.getFunction(); - String chineseName = wpsWordReqDto.getName(); - - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - // 1-1、创建新的数据组 - XmlCursor wpCursor = cursor.newCursor(); - wpCursor.selectPath(nameSpace + function); - if (wpCursor.toNextSelection()) { - if ("1".equals(wpsWordReqDto.getIsboo())) { - judgement.setContentIn(chineseName + "是"); - judgement.setContent(function + "-/true"); - } else { - String value = wpCursor.getTextValue(); - if (wpsWordReqDto.getName().contains("倾斜")) { - value = wpCursor.getAttributeText(new QName("w:val")); - value = value == null ? "是" : value == "0" ? "否" :value == "1" ? "是" : "否"; - } - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(chineseName + value); - judgement.setContent(function + "-/" + value); - } - judgement.setScoreRate("1"); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - // 查询指定值,返回固定的文本 - judgementList.add(judgement); - } else { - // 获取是否在对应的styles.xml里面 - wpCursor.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + "/w:pPr/w:pStyle/@w:val"); - if (wpCursor.toNextSelection()) { - String value = wpCursor.getTextValue(); - for (PackagePart part : pkg.getParts()) { - String entryName = part.getPartName().getName(); - if (entryName.contains("word/styles") && entryName.contains(".xml")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursorStyle = xmlObject.newCursor(); - String nameSpaceStyle = WpsWordNameSpaces.getNameSpace(cursorStyle.xmlText()); - cursorStyle.selectPath(nameSpaceStyle + ".//w:style[@w:styleId='"+value+"']"); - if (cursorStyle.toNextSelection()) { - String functions = wpsWordReqDto.getFunction().replace("/w:r/", ""); - if (functions.charAt(0) == '/') { - functions = ".//" + functions.split("]")[1]; - } else { - functions = "./" + functions.split("]")[1]; - } - - cursorStyle.selectPath(nameSpaceStyle + functions); - if (cursorStyle.toNextSelection()) { - - if ("1".equals(wpsWordReqDto.getIsboo())) { - judgement.setContentIn(chineseName + "是"); - judgement.setContent(function + "-/true"); - } else { - String valueStyle = cursorStyle.getTextValue(); - valueStyle = getValueType(wpsWordReqDto, valueStyle); - judgement.setContentIn(chineseName + valueStyle); - judgement.setContent(function + "-/" + valueStyle); - } - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - } - } - } else if ("1".equals(wpsWordReqDto.getIsboo())) { - judgement.setContentIn(chineseName + "否"); - judgement.setContent(function + "-/false"); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - - } - } - } - List headers = document.getHeaderList(); - List footers = document.getFooterList(); - // 2、节 - if ("1".equals(wpsWordReqDto.getBelongTo())) { - // 先要获取ID - XmlCursor sectPrCursor = docXml.newCursor(); - // 内外参数(0:内参数;1:外参数) - if ("1".equals(wpsWordReqDto.getType())) { - sectPrCursor.selectPath(nameSpace + wpsWordReqDto.getFunction().split("#")[0]); - String rId = ""; - String type = ""; - List headerFooterVos = new ArrayList<>(); - while (sectPrCursor.toNextSelection()) { - rId = sectPrCursor.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id")); - type = sectPrCursor.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "type")); - WordHeaderFooterVo headerFooterVo = new WordHeaderFooterVo(); - headerFooterVo.setRid(rId); - headerFooterVo.setType(type); - headerFooterVo.setXmlType(wpsWordReqDto.getFunction()); - headerFooterVos.add(headerFooterVo); - } - String fileName = ""; - for (Map str : filePathList) { - // 页眉页脚 - for (WordHeaderFooterVo headerVo : headerFooterVos) { - if (str.containsKey(headerVo.getRid())) { - fileName = str.get(headerVo.getRid()); - if (headerVo.getXmlType().contains("headerReference")) { - for (XWPFHeader header : headers) { - if (header.getPackagePart().getPartName().getName().contains(fileName)) { - // 2-1、针对不同的进行排查 - String chineseType = Objects.equals(headerVo.getType(), "default") ? "奇数页" : Objects.equals(headerVo.getType(), "even") ? "偶数页" : ""; - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - List headerpar = header.getParagraphs(); - XmlCursor headerXml = headerpar.get(0).getCTP().newCursor(); - if (wpsWordReqDto.getFunction().contains("w:page")) { - if (headerXml.xmlText().contains("PAGE")) { - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 是"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } else { - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 否"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } else if (wpsWordReqDto.getName().contains("水印")) { - if (wpsWordReqDto.getName().contains("水印类型")) { - if (headerXml.xmlText().contains("v:shape") && headerXml.xmlText().contains("v:textpath")) { - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 文字水印"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "文字水印" + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - if (wpsWordReqDto.getName().contains("文本")) { - headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@string"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - if (wpsWordReqDto.getName().contains("字体")) { - headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@style"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - Pattern pattern = Pattern.compile("font-family:([^;]+)"); - Matcher matcher = pattern.matcher(value); - if (matcher.find()) { - String fontFamily = matcher.group(1).trim(); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +fontFamily); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + fontFamily + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - if (wpsWordReqDto.getName().contains("字号")) { - headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@style"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - Pattern pattern = Pattern.compile("font-size:([^;]+)"); - Matcher matcher = pattern.matcher(value); - if (matcher.find()) { - String fontFamily = matcher.group(1).trim(); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +fontFamily); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + fontFamily + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - if (wpsWordReqDto.getName().contains("颜色")) { - headerXml.selectPath(nameSpace + "//v:shape/@fillcolor"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - if (wpsWordReqDto.getName().contains("透明度")) { - headerXml.selectPath(nameSpace + "//v:shape/v:fill/@opacity"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - while (value.length() < 8) { - value = "0" + value; - } - long bits = Long.parseLong(value, 16); - float opacityFloat = Float.intBitsToFloat((int) bits); - // 转为百分比(例如 0.3 -> 30%) - float opacityPercent = opacityFloat * 100; - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +opacityPercent); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + opacityPercent + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - if (wpsWordReqDto.getName().contains("版式")) { - headerXml.selectPath(nameSpace + "//v:shape/@style"); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - value = detectWatermarkLayout(value); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } else { - headerXml.selectPath(nameSpace + "./" + wpsWordReqDto.getFunction().split("#")[1]); - if (headerXml.toNextSelection()) { - String value = headerXml.getTextValue(); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - - } - - } - } else if (headerVo.getXmlType().contains("footerReference")) { - for (XWPFFooter footer : footers) { - if (footer.getPackagePart().getPartName().getName().contains(fileName)) { - // 2-1、针对不同的进行排查 - String chineseType = Objects.equals(headerVo.getType(), "default") ? "奇数页" : Objects.equals(headerVo.getType(), "even") ? "偶数页" : ""; - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - List footerpar = footer.getParagraphs(); - XmlCursor footerXml = footerpar.get(0).getCTP().newCursor(); - if (wpsWordReqDto.getFunction().contains("w:page")) { - if (footerXml.xmlText().contains("PAGE")) { - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 是"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "true" + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } else { - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 否"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } else { - footerXml.selectPath(nameSpace + "./" + wpsWordReqDto.getFunction().split("#")[1]); - if (footerXml.toNextSelection()) { - String value = footerXml.getTextValue(); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-"+value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - - } - } - } - } - } - } - } else { - // 需要查询主页面的方法 - XmlCursor sectPrXsml = docXml.newCursor(); - if (wpsWordReqDto.getUnit().contains("twipstolines")) { - String[] docGrid = wpsWordReqDto.getFunction().split("#"); - XmlCursor docGridXsml = sectPrXsml; - docGridXsml.selectPath(nameSpace + docGrid[0]); - String docGridValues = ""; - String topValues = ""; - String bottomValues = ""; - String allValues = ""; - if (docGridXsml.toNextSelection()) { - docGridValues = docGridXsml.getTextValue(); - } - XmlCursor pgMgXsml = sectPrXsml; - pgMgXsml.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + docGrid[1]); - if (pgMgXsml.toNextSelection()) { - topValues = pgMgXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "top")); - bottomValues = pgMgXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "bottom")); - } - XmlCursor allXsml = sectPrXsml; - pgMgXsml.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + docGrid[2]); - if (allXsml.toNextSelection()) { - allValues = allXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "h")); - } - Integer values = Integer.parseInt(allValues) - Integer.parseInt(bottomValues) - - Integer.parseInt(topValues); - Integer docGridValuesInt = values / Integer.parseInt(docGridValues); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + docGridValuesInt); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + docGridValuesInt); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } else if (wpsWordReqDto.getUnit().contains("paper_shape")) { - sectPrXsml.selectPath(nameSpace + wpsWordReqDto.getFunction()); - // 纸型 - if (sectPrXsml.toNextSelection()) { - String text = sectPrXsml.xmlText(); - String value = PageSizeDetector.detectPaperSize(text); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } else{ - sectPrXsml.selectPath(nameSpace + wpsWordReqDto.getFunction()); - if (sectPrXsml.toNextSelection()) { - String value = sectPrXsml.getTextValue(); - value = getValueType(wpsWordReqDto, value); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - } - // 3、图形 - if ("2".equals(wpsWordReqDto.getBelongTo())) { - if (wpsWordReqDto.getName().contains("环绕方式")) { - XmlCursor wpCursor = cursor.newCursor(); - wpCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); { - if (wpCursor.toNextSelection()) { - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - String text = wpCursor.xmlText(); - String value = getDrawingType(text); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + value.split("#")[1]); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value.split("#")[0]); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - // 查询指定值,返回固定的文本 - judgementList.add(judgement); - } - } - } else if (wpsWordReqDto.getName().contains("形状填充") && wpsWordReqDto.getName().contains("填充方式")) { - XmlCursor wpCursor = cursor.newCursor(); - wpCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); - if (wpCursor.toNextSelection()) { - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - String text = wpCursor.xmlText(); - String value = getValueType(wpsWordReqDto, text); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } else { - String function = ""; - if (wpsWordReqDto.getIsExam().equals("0")) { - String[] functionList = wpsWordReqDto.getFunction().split("#"); - if (wpsWordReqDto.getName().contains("图片")) { - function = functionList[0]; - } else { - function = wpsWordReqDto.getEnglishName() + functionList[1]; - } - } else { - function = wpsWordReqDto.getFunction(); - } - String chineseName = wpsWordReqDto.getName(); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - // 1-1、创建新的数据组 - XmlCursor wpCursor = cursor.newCursor(); - System.out.println(nameSpace + function); - wpCursor.selectPath(nameSpace + function); - if (wpCursor.toNextSelection()) { - if ("1".equals(wpsWordReqDto.getIsboo())) { - judgement.setContentIn(wpsWordReqDto.getName() + "是"); - judgement.setContent(function + "-/" + "true"); - - } else { - String value = wpCursor.getTextValue(); - value = getValueType(wpsWordReqDto, value); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(function + "-/" + value); - } - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - // 查询指定值,返回固定的文本 - judgementList.add(judgement); - } else { - // 参数类型(0:值;1:判断) - if ("1".equals(wpsWordReqDto.getIsboo())) { - judgement.setContentIn(wpsWordReqDto.getName() + "false"); - judgement.setContent(function + "-/" + "false"); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - - } - // 4、尾注 - if ("3".equals(wpsWordReqDto.getBelongTo())) { - if ("0".equals(wpsWordReqDto.getType())) { - if (wpsWordReqDto.getName().contains("插入尾注")) { - // 判断是否存在 - XmlCursor wpCursor = cursor.newCursor(); - wpCursor.selectPath(nameSpace + "//w:endnoteReference/@w:id"); - if (wpCursor.toNextSelection()) { - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + " 是"); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "true"); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } else { - for (PackagePart part : pkg.getParts()) { - String entryName = part.getPartName().getName(); - if (entryName.contains("word/endnotes") && entryName.contains(".xml")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursorEnd = xmlObject.newCursor(); - String namespace = WpsWordNameSpaces.getNameSpace(cursorEnd.xmlText()); - if (wpsWordReqDto.getName().contains("内容")) { - System.out.println(cursorEnd.xmlText()); - String value = cursorEnd.getTextValue(); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - } - } - } - // 表格属性 - if ("4".equals(wpsWordReqDto.getBelongTo())) { - XmlCursor tblCursor = cursor.newCursor(); - tblCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); - if (tblCursor.toNextSelection()) { - String value = tblCursor.getTextValue(); - value = getValueType(wpsWordReqDto, value); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - // 5、域 - if ("5".equals(wpsWordReqDto.getBelongTo())) { - XmlCursor yuCursor = cursor.newCursor(); - yuCursor.selectPath(nameSpace + wpsWordReqDto.getFunction().replace("/chao","")); - if (yuCursor.toNextSelection()) { - if (wpsWordReqDto.getName().contains("域代码")) { - String value = yuCursor.getTextValue(); - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - if (wpsWordReqDto.getName().contains("域类型")) { - String value = yuCursor.getTextValue(); - if (value.contains("HYPERLINK")) { - value = "连接和引用->打开并跳到指定文件"; - } - WpsWordJudgementDto judgement = new WpsWordJudgementDto(); - judgement.setContentIn(wpsWordReqDto.getName() + value); - judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); - judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); - judgement.setScoreRate("1"); - judgementList.add(judgement); - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return judgementList; - } - public static String getValueType(WpsWordReqDto wpsWordReqDto, String value) { - String values = value; - if (wpsWordReqDto.getUnit().contains("Filling_method")) { - if (value.contains("solidFill")) { - values = "纯色填充"; - } else if (value.contains("gradFill")) { - values = "渐变填充"; - } else if (value.contains("pattFill")) { - values = "图案填充"; - } else if (value.contains("blipFill")) { - values = "图片填充"; - } - } - if (wpsWordReqDto.getUnit().contains("twiptopt")) { - values = TwipConverter.formatDouble(TwipConverter.toPoints(Integer.parseInt(value))) + "磅"; - } - if (wpsWordReqDto.getUnit().contains("emustopt")) { - values = TwipConverter.formatDouble(TwipConverter.toEmus(Integer.parseInt(value))) + "磅"; - } - if (wpsWordReqDto.getUnit().contains("color")) { - values = ColorNameFinder.getColorName(value); - } - if (wpsWordReqDto.getUnit().contains("underline")) { - if ("double".equals(value)) { - values = "双下划线"; - } else if ("single".equals(value)) { - values = "单下划线"; - } else if ("none".equals(value)) { - values = "无下划线"; - } else if ("dotted".equals(value)) { - values = "点划线"; - } else if ("dottedHeavy".equals(value)) { - values = "粗点划线"; - } else if ("dash".equals(value)) { - values = "虚线"; - } else if ("dashedHeavy".equals(value)) { - values = "粗虚线"; - } else if ("dashLong".equals(value)) { - values = "长虚线"; - } - } - if (wpsWordReqDto.getUnit().contains("direction")) { - // 方向英文转换 - if ("landscape".equals(value)) { - values = "横向"; - } else if ("portrait".equals(value)) { - values = "纵向"; - } else if ("up".equals(value)) { - values = "上对齐"; - } else if ("down".equals(value)) { - values = "下对齐"; - } - } - if (value.contains("center")) { - values = "居中对齐"; - } - if (wpsWordReqDto.getUnit().contains("textdirection")) { - // 方向英文转换 - if ("left".equals(value)) { - values = "左对齐"; - } else if ("center".equals(value)) { - values = "居中对齐"; - } else if ("right".equals(value)) { - values = "右对齐"; - } else if ("both".equals(value)) { - values = "两端对齐"; - } - } - if (wpsWordReqDto.getUnit().contains("halfpt")) { - values = String.valueOf (Integer.parseInt(value) / 2); - } - if (wpsWordReqDto.getUnit().contains("shadowdirection")) { - ShadowDirectionUtils.ShadowDirection direction = ShadowDirectionUtils.getShadowDirection(Long.valueOf(value)); - values = direction.getLabel(); - } - if (wpsWordReqDto.getUnit().contains("ershifenzhiyi")) { - values = String.valueOf (Integer.parseInt(value) / 20); - } - if (wpsWordReqDto.getUnit().contains("duanluojianju")) { - if (Integer.parseInt(value) == 240) { - values = "1.5 倍行距"; - } else if (Integer.parseInt(value) == 360) { - values = "2 倍行距"; - } else if (Integer.parseInt(value) == 480) { - values = "3 倍行距"; - } - } - - return values; - } - - public static String detectWatermarkLayout(String style) { - if (style == null || !style.contains("rotation:")) { - return "水平"; - } - - try { - // 提取 rotation 的值 - String[] parts = style.split(";"); - for (String part : parts) { - part = part.trim(); - if (part.startsWith("rotation:")) { - String rotationStr = part.replace("rotation:", "").replace("f", "").trim(); - int rotationValue = Integer.parseInt(rotationStr); - - // 转换为角度(1度 = 65536) - int degrees = rotationValue / 65536; - - // 判断角度 - if (Math.abs(degrees) == 45) { - return "倾斜"; - } else { - return "水平"; - } - } - } - } catch (Exception e) { - return "解析出错:" + e.getMessage(); - } - - return "未知格式"; - } - - public static String getDrawingType(String text) { - String value =""; - if (text.contains("wp:wrapSquare")) { - value = "wp:wrapSquare" + "#" + "四周型环绕"; - } else if (text.contains("wp:wrapTight")) { - value = "wp:wrapTight" + "#" + "紧密型环绕"; - } else if (text.contains("wp:wrapThrough")) { - value = "wp:wrapThrough" + "#" + "穿越型环绕"; - } else if (text.contains("wp:wrapTopAndBottom")) { - value = "wp:wrapTopAndBottom" + "#" + "上下型环绕"; - } else if (text.contains("wp:wrapNone")) { - value = "wp:wrapNone" + "#" + "无环绕"; - } - return value; - } - public static void setWordInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List wordInfoReqVos) throws Exception { - WordInfoReqVo wordInfos = new WordInfoReqVo(); - wordInfos.setName(chineseName); - wordInfos.setEnglishName(englishName); - wordInfos.setFilePath(filePath); - wordInfos.setId(id); - wordInfos.setSelectName(selectName); - wordInfos.setParentId(parentId); - wordInfoReqVos.add(wordInfos); - } - - public static List wpWord(String filePath) throws Exception { - List wordInfoReqVos = new ArrayList<>(); - try (XWPFDocument document = new XWPFDocument(new FileInputStream(filePath))) { - String xmlString = XmlUtil.getDocumentXml(document); - String namespace = WpsWordNameSpaces.getNameSpace(xmlString); - XmlObject docXml = document.getDocument(); - // 1、获取文档段落W:P标签得数量,判断出一个有多少段 - XmlCursor wpCursor = docXml.newCursor(); - String wpPath = namespace + "/w:document/w:body/w:p"; - wpCursor.selectPath(wpPath); - int wpIndex = 0; - // 段落 - String firstIdWp = getStringRandom(); - setWordInfo("段落", "w:p", "w:p", filePath, firstIdWp, "0", wordInfoReqVos); - List wordSecondWp = new ArrayList<>(); - while (wpCursor.toNextSelection()) { - wpIndex ++; - // 段落属性 - if (!wpCursor.xmlText().contains("w:sectPr")) { - // 获取文本 - XmlCursor wpTextXml = wpCursor.newCursor(); - wpTextXml.selectPath(namespace + ".//w:r/w:t"); - if (wpTextXml.toNextSelection()) { - String secondIdWp = getStringRandom(); - String text = wpTextXml.getTextValue(); - text = shorten(text); - setWordInfo("段落" + wpIndex + ":" + text, "(//w:p)[" + wpIndex + "]", "w:pPr", filePath, secondIdWp, firstIdWp, wordInfoReqVos); - // 使用 。 判断句子 - String[] texts = text.split("。"); - int textsIndex = 0; - for (String s : texts) { - String thirdIdWp = getStringRandom(); - textsIndex ++; - s = shorten(s); - setWordInfo("句子" + textsIndex + ":" + s, "(//w:p)[" + wpIndex + "]", "w:r", filePath, thirdIdWp, secondIdWp, wordInfoReqVos); - } - } - } - } - // 2、页面 - XmlCursor wSectPrCursor = docXml.newCursor(); - String wSectPrPath = namespace + "//w:sectPr"; - wSectPrCursor.selectPath(wSectPrPath); - int wSectPrIndex = 0; - String firstIdSectPr = getStringRandom(); - setWordInfo("页面", "w:sectPr", "w:sectPr", filePath, firstIdSectPr, "", wordInfoReqVos); - List wordSecondWSectPr = new ArrayList<>(); - while (wSectPrCursor.toNextSelection()) { - wSectPrIndex ++; - String secondIdSectPr = getStringRandom(); - setWordInfo("节" + wSectPrIndex, "(//w:sectPr)[" + wSectPrIndex + "]", "w:sectPr", filePath, secondIdSectPr, firstIdSectPr, wordInfoReqVos); - } - // 3、图形 - XmlCursor wDrawingCursor = docXml.newCursor(); - String wDrawingPath = namespace + "//w:drawing"; - wDrawingCursor.selectPath(wDrawingPath); - int wDrawingIndex = 0; - String firstIdDrawing = getStringRandom(); - setWordInfo("图形", "w:drawing", "w:drawing", filePath, firstIdDrawing, "", wordInfoReqVos); - while (wDrawingCursor.toNextSelection()) { - wDrawingIndex ++; - String secondIdDrawing = getStringRandom(); - XmlCursor wDrawingXml = wDrawingCursor.newCursor(); - wDrawingXml.selectPath(namespace + ".//wp:anchor/wp:docPr/@name"); - if (wDrawingXml.toNextSelection()) { - setWordInfo("图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "(//w:drawing)[" + wDrawingIndex + "]", "w:drawing", filePath, secondIdDrawing, firstIdDrawing, wordInfoReqVos); - } - } - // 4、尾注 - XmlCursor endnoteReferenceCursor = docXml.newCursor(); - String endnoteReferencePath = namespace + "//w:endnoteReference"; - endnoteReferenceCursor.selectPath(endnoteReferencePath); - int endnoteReferenceIndex = 0; - String firstIdEndnoteReference = getStringRandom(); - while (endnoteReferenceCursor.toNextSelection()) { - if (endnoteReferenceIndex == 0) { - setWordInfo("引用", "w:endnoteReference", "w:endnoteReference", filePath, firstIdEndnoteReference, "", wordInfoReqVos); - } - endnoteReferenceIndex ++; - String secondIdEndnoteReference = getStringRandom(); - setWordInfo("尾注", "(//w:endnoteReference)[" + endnoteReferenceIndex + "]", "w:endnoteReference", filePath, secondIdEndnoteReference, firstIdEndnoteReference, wordInfoReqVos); - } - // 5、表格 - XmlCursor tblCursor = docXml.newCursor(); - String tblCursorPath = namespace + "//w:tbl"; - endnoteReferenceCursor.selectPath(tblCursorPath); - int tblIndex = 0; - String firstIdTbl = getStringRandom(); - while (endnoteReferenceCursor.toNextSelection()) { - if (tblIndex == 0) { - setWordInfo("表格", "w:endnoteReference", "w:endnoteReference", filePath, firstIdTbl, "", wordInfoReqVos); - } - tblIndex ++; - String secondIdTbl = getStringRandom(); - setWordInfo("表格:"+tblIndex, "(//w:tbl)[" + tblIndex + "]", "w:tbl", filePath, secondIdTbl, firstIdTbl, wordInfoReqVos); - } - // 5、域 - XmlCursor yuCursor = docXml.newCursor(); - String yuCursorPath = namespace + "//w:instrText"; - endnoteReferenceCursor.selectPath(yuCursorPath); - int yuIndex = 0; - String firstIdyu = getStringRandom(); - while (endnoteReferenceCursor.toNextSelection()) { - if (yuIndex == 0) { - setWordInfo("域", "w:instrText", "w:instrText", filePath, firstIdyu, "", wordInfoReqVos); - } - yuIndex ++; - String secondIdyu = getStringRandom(); - setWordInfo("域:"+yuIndex, "(//w:instrText)[" + yuIndex + "]", "w:instrText", filePath, secondIdyu, firstIdyu, wordInfoReqVos); - } - return wordInfoReqVos; - } - - } - - /** - * 获取文档段落W:P标签得数量,判断出一个有多少段 - * @param filePath 文件路径 - * @return List - * @throws Exception Exception - */ - public static List wps_word(String filePath) throws Exception { - List wordVO = new ArrayList<>(); - int count = 0; - // 1、路径初始化 - String xmlpath = ""; - String type = ""; - XWPFDocument document = new XWPFDocument(new FileInputStream(filePath)); - String xmlString = XmlUtil.getDocumentXml(document); - // 2、创建最全的命名空间 - Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); - Matcher matcher = pattern.matcher(xmlString); - Map namespaces = new HashMap<>(); - while (matcher.find()) { - // 如 w, wp, a - String prefix = matcher.group(1); - // 如 http://schemas.openxmlformats.org/... - String uri = matcher.group(2); - namespaces.put(prefix, uri); - } - StringBuilder xpathBuilder = new StringBuilder(); - namespaces.forEach((prefix, uri) -> - xpathBuilder.append("declare namespace ") - .append(prefix) - .append("='") - .append(uri) - .append("' ") - ); - // 2-1、获取出来最全的命名空间 - String allPathx = xpathBuilder.toString(); - // 3、获取CTDocument对象 - XmlObject docXml = document.getDocument(); - // 3-1、段落的树数据 -// List paragraphTree = TreeUtils.buildTree(paragraphList); - // 3-2、锚点的树数据 -// List anchorTree = TreeUtils.buildTree(anchorList); - // Word XML document - XmlObject xmlObject = document.getDocument(); -// for (WpsWordLinkDO anchor : anchorTree) { -// String xpathAnchor = allPathx + "//" + anchor.getName(); -// XmlCursor cursorAnchor = docXml.newCursor(); -// int index = 0; -// cursorAnchor.selectPath(xpathAnchor); -// while (cursorAnchor.toNextSelection()) { -// type = "图片"; -// index += 1; -// XmlCursor cursorAnchorXml = cursorAnchor.getObject().newCursor(); -// XmlCursor cursorAnchorText = cursorAnchor.getObject().newCursor(); -// // 首先:判断类型 1 :图片,2:文本框 -// cursorAnchorXml.selectPath(allPathx + ".//wp:anchor/wp:docPr/@id"); -// String typeValue = ""; -// while (cursorAnchorXml.toNextSelection()) { -// typeValue = cursorAnchorXml.getTextValue(); -// } -// String anchorName = "图片"; -// if (Objects.equals(typeValue, "2")) { -// type = "文本框"; -// System.out.println(cursorAnchorText.xmlText()); -// // 要获取文本框的文本 -// cursorAnchorText.selectPath(allPathx + ".//wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx"); -// while (cursorAnchorText.toNextSelection()) { -// System.out.println(cursorAnchorText.getObject().xmlText()); -// anchorName = cursorAnchorText.getTextValue(); -// } -// } -// cursorAnchorText.dispose(); -// cursorAnchorXml.dispose(); -// XmlObject paraObj = cursorAnchor.getObject(); -// for (WpsWordLinkDO root : anchor.getChildren()) { -// traverseTreeAndQueryXml(type, wordVO, anchor.getName(), anchorName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1); -// } -// } -// cursorAnchor.dispose(); -// } -// 创建一个list,存放word读取的数据(段落数据) -// for (WpsWordLinkDO paragraph : paragraphTree) { - type = "段落"; - // 段落划分 根据w:p标签 - // 到达参数节点,构造 XPath 路径查询它的值 - String wpPath = allPathx + "/w:document/w:body/w:p"; - XmlCursor cursor = docXml.newCursor(); - int index = 0; - cursor.selectPath(wpPath); - while (cursor.toNextSelection()) { - String rTextName = ""; - index += 1; - System.out.println(index); -// // 每一段进行赋值,进行判断 - XmlObject paraObj = cursor.getObject(); - String paraText = paraObj.xmlText(); - System.out.println(paraText); -// XmlCursor rCursor = paraObj.newCursor(); -// // 想要查询指定的path -// rCursor.selectPath(allPathx + ".//w:r/w:t"); -// while (rCursor.toNextSelection()) { -// XmlCursor rsCursor = rCursor.getObject().newCursor(); -// rTextName = rsCursor.getTextValue(); -// rsCursor.dispose(); -// } -// rCursor.dispose(); -// // 创建新的 -// for (WpsWordLinkDO root : paragraph.getChildren()) { -// traverseTreeAndQueryXml(type, wordVO, paragraph.getName(), rTextName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1); -// } -// } - - } - // 读取页眉的方法(需要通过页眉查询,水印,页眉文字等信息) -// List headers = document.getHeaderList(); -// for (XWPFHeader header : headers) { -// if (!Objects.equals(header.getText(), "")) { -// headerAndFooter(header, null, wordVO); -// } -// // 获取底层 XML 对象 -// CTHdrFtr ctHdrFtr = header._getHdrFtr(); // ✅ 正确方法 -// String xpath = allPathx + "//w:hdr/w:p/w:r/w:pict"; -// XmlCursor cursor = ctHdrFtr.newCursor(); -// cursor.selectPath(xpath); -// while (cursor.toNextSelection()) { -// // 查询 v:textpath 节点 -// cursor.selectPath( -// allPathx + -// ".//v:textpath" -// ); -// while (cursor.toNextSelection()) { -// XmlObject textpathObj = cursor.getObject(); -// String xml = textpathObj.xmlText(); -// WordVO attr_word = new WordVO(); +//package pc.exam.pp.module.judgement.utils.wps_word; // -// // 提取属性值 -// String stringAttr = cursor.getAttributeText(new javax.xml.namespace.QName("string")); -// String styleAttr = cursor.getAttributeText(new javax.xml.namespace.QName("style")); -// attr_word.setWordText("水印"); -// List attr = new ArrayList<>(); -// attr.add("水印文字 string 属性: " + stringAttr); -// attr.add("水印 style 属性: " + styleAttr); -// attr_word.setKeynoteChinese(attr); -// List path = new ArrayList<>(); -// path.add("name:"+stringAttr); -// path.add("style:"+styleAttr); -// attr_word.setExamKeynote(path); -// attr_word.setType("水印"); -// wordVO.add(attr_word); +//import org.apache.commons.io.IOUtils; +//import org.apache.poi.openxml4j.opc.OPCPackage; +//import org.apache.poi.openxml4j.opc.PackagePart; +//import org.apache.poi.xwpf.usermodel.*; +//import org.apache.xmlbeans.XmlCursor; +//import org.apache.xmlbeans.XmlObject; +//import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordChineseFunctionDto; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; +//import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; +//import pc.exam.pp.module.judgement.utils.TwipConverter; +//import pc.exam.pp.module.judgement.utils.wps_word.vo.*; +//import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils; +// +//import javax.xml.namespace.QName; +//import java.io.FileInputStream; +//import java.io.IOException; +//import java.io.InputStream; +//import java.nio.charset.StandardCharsets; +//import java.util.*; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +//import java.util.stream.IntStream; +//import java.util.zip.ZipEntry; +//import java.util.zip.ZipFile; +// +///** +// * @author REN +// */ +//public class WpsWordUtils { +// public static String getStringRandom() { +// String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +// Random random = new Random(); +// StringBuilder sb = new StringBuilder(); +// +// // 生成指定长度的随机字符字符串 +// for (int i = 0; i < 10; i++) { +// int randomIndex = random.nextInt(characters.length()); +// // 随机字符 +// sb.append(characters.charAt(randomIndex)); +// } +// return sb.toString(); +// } +// +// public static List getWordInfo(List wpsWordReqDtos) throws Exception { +// String filePath = wpsWordReqDtos.get(0).getFilePath(); +// // 创建返回数组 +// List judgementList = new ArrayList<>(); +// // 创建文件路径数组 +// List> filePathList = new ArrayList<>(); +// for (WpsWordReqDto wpsWordReqDto : wpsWordReqDtos) { +// try (OPCPackage pkg = OPCPackage.open(wpsWordReqDto.getFilePath()); +// XWPFDocument document = new XWPFDocument(pkg)) { +// for (PackagePart part : pkg.getParts()) { +// String entryName = part.getPartName().getName(); +// if (entryName.contains("word/_rels") && entryName.contains(".xml.rels")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// // 解析 xmlContent +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +// // 存放数据 +// while (cursor.toNextSelection()) { +// Map map = new HashMap<>(); +// String rId = cursor.getAttributeText(new QName("Id")); +// String target = cursor.getAttributeText(new QName("Target")); +// map.put(rId, target); +// filePathList.add(map); +// } +// } +// } +// } +// XmlObject docXml = document.getDocument(); +// XmlCursor cursor = docXml.newCursor(); +// String nameSpace = WpsWordNameSpaces.getNameSpace(cursor.xmlText()); +// // 需要联合查询数据,查询位置xml来获取准确的文件 +// // 开始查询标签 +// // 1、段落 +// if ("0".equals(wpsWordReqDto.getBelongTo())) { +// if (wpsWordReqDto.getFunction().contains("w:cols")) { +// XmlCursor wColsCursor = cursor.newCursor(); +// XmlCursor wColsCursors = null; +// // 如果是分栏需要单独进行查询 +// // 需要查找查询第几个段落 +// String number = wpsWordReqDto.getFunction().split("]")[0]; +// number = number.split("\\[")[1]; +// boolean flag = true; +// int numbers = Integer.parseInt(number); +// while (flag) { +// numbers += 1; +// // 向下查询是否存在样式段落 +// String nameSpaces = nameSpace + "(//w:p)["+numbers+"]"; +// wColsCursor.selectPath(nameSpaces); +// if (wColsCursor.toNextSelection()) { +// if (wColsCursor.xmlText().contains("w:cols")) { +// System.out.println(wColsCursor.xmlText()); +// wColsCursors = wColsCursor.newCursor(); +// flag = false; +// } +// } +// if (numbers > 20) { +// flag = false; +// } +// } +// if (wColsCursors != null) { +// String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1]; +// System.out.println(wColsCursors.xmlText()); +// wColsCursors.selectPath(nameSpaceCols); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// if (wColsCursors.toNextSelection()) { +// String value = wColsCursors.getTextValue(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setScoreRate("1"); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// // 查询指定值,返回固定的文本 +// judgementList.add(judgement); +// } +// } +// } else { +// String function = wpsWordReqDto.getFunction(); +// String chineseName = wpsWordReqDto.getName(); +// +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// // 1-1、创建新的数据组 +// XmlCursor wpCursor = cursor.newCursor(); +// wpCursor.selectPath(nameSpace + function); +// if (wpCursor.toNextSelection()) { +// if ("1".equals(wpsWordReqDto.getIsboo())) { +// judgement.setContentIn(chineseName + "是"); +// judgement.setContent(function + "-/true"); +// } else { +// String value = wpCursor.getTextValue(); +// if (wpsWordReqDto.getName().contains("倾斜")) { +// value = wpCursor.getAttributeText(new QName("w:val")); +// value = value == null ? "是" : value == "0" ? "否" :value == "1" ? "是" : "否"; +// } +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(chineseName + value); +// judgement.setContent(function + "-/" + value); +// } +// judgement.setScoreRate("1"); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// // 查询指定值,返回固定的文本 +// judgementList.add(judgement); +// } else { +// // 获取是否在对应的styles.xml里面 +// wpCursor.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + "/w:pPr/w:pStyle/@w:val"); +// if (wpCursor.toNextSelection()) { +// String value = wpCursor.getTextValue(); +// for (PackagePart part : pkg.getParts()) { +// String entryName = part.getPartName().getName(); +// if (entryName.contains("word/styles") && entryName.contains(".xml")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursorStyle = xmlObject.newCursor(); +// String nameSpaceStyle = WpsWordNameSpaces.getNameSpace(cursorStyle.xmlText()); +// cursorStyle.selectPath(nameSpaceStyle + ".//w:style[@w:styleId='"+value+"']"); +// if (cursorStyle.toNextSelection()) { +// String functions = wpsWordReqDto.getFunction().replace("/w:r/", ""); +// if (functions.charAt(0) == '/') { +// functions = ".//" + functions.split("]")[1]; +// } else { +// functions = "./" + functions.split("]")[1]; +// } +// +// cursorStyle.selectPath(nameSpaceStyle + functions); +// if (cursorStyle.toNextSelection()) { +// +// if ("1".equals(wpsWordReqDto.getIsboo())) { +// judgement.setContentIn(chineseName + "是"); +// judgement.setContent(function + "-/true"); +// } else { +// String valueStyle = cursorStyle.getTextValue(); +// valueStyle = getValueType(wpsWordReqDto, valueStyle); +// judgement.setContentIn(chineseName + valueStyle); +// judgement.setContent(function + "-/" + valueStyle); +// } +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// } +// } +// } else if ("1".equals(wpsWordReqDto.getIsboo())) { +// judgement.setContentIn(chineseName + "否"); +// judgement.setContent(function + "-/false"); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// +// } +// } +// } +// List headers = document.getHeaderList(); +// List footers = document.getFooterList(); +// // 2、节 +// if ("1".equals(wpsWordReqDto.getBelongTo())) { +// // 先要获取ID +// XmlCursor sectPrCursor = docXml.newCursor(); +// // 内外参数(0:内参数;1:外参数) +// if ("1".equals(wpsWordReqDto.getType())) { +// sectPrCursor.selectPath(nameSpace + wpsWordReqDto.getFunction().split("#")[0]); +// String rId = ""; +// String type = ""; +// List headerFooterVos = new ArrayList<>(); +// while (sectPrCursor.toNextSelection()) { +// rId = sectPrCursor.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id")); +// type = sectPrCursor.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "type")); +// WordHeaderFooterVo headerFooterVo = new WordHeaderFooterVo(); +// headerFooterVo.setRid(rId); +// headerFooterVo.setType(type); +// headerFooterVo.setXmlType(wpsWordReqDto.getFunction()); +// headerFooterVos.add(headerFooterVo); +// } +// String fileName = ""; +// for (Map str : filePathList) { +// // 页眉页脚 +// for (WordHeaderFooterVo headerVo : headerFooterVos) { +// if (str.containsKey(headerVo.getRid())) { +// fileName = str.get(headerVo.getRid()); +// if (headerVo.getXmlType().contains("headerReference")) { +// for (XWPFHeader header : headers) { +// if (header.getPackagePart().getPartName().getName().contains(fileName)) { +// // 2-1、针对不同的进行排查 +// String chineseType = Objects.equals(headerVo.getType(), "default") ? "奇数页" : Objects.equals(headerVo.getType(), "even") ? "偶数页" : ""; +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// List headerpar = header.getParagraphs(); +// XmlCursor headerXml = headerpar.get(0).getCTP().newCursor(); +// if (wpsWordReqDto.getFunction().contains("w:page")) { +// if (headerXml.xmlText().contains("PAGE")) { +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 是"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } else { +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 否"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } else if (wpsWordReqDto.getName().contains("水印")) { +// if (wpsWordReqDto.getName().contains("水印类型")) { +// if (headerXml.xmlText().contains("v:shape") && headerXml.xmlText().contains("v:textpath")) { +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 文字水印"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "文字水印" + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// if (wpsWordReqDto.getName().contains("文本")) { +// headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@string"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// if (wpsWordReqDto.getName().contains("字体")) { +// headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@style"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// Pattern pattern = Pattern.compile("font-family:([^;]+)"); +// Matcher matcher = pattern.matcher(value); +// if (matcher.find()) { +// String fontFamily = matcher.group(1).trim(); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +fontFamily); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + fontFamily + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// if (wpsWordReqDto.getName().contains("字号")) { +// headerXml.selectPath(nameSpace + "//v:shape/v:textpath/@style"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// Pattern pattern = Pattern.compile("font-size:([^;]+)"); +// Matcher matcher = pattern.matcher(value); +// if (matcher.find()) { +// String fontFamily = matcher.group(1).trim(); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +fontFamily); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + fontFamily + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// if (wpsWordReqDto.getName().contains("颜色")) { +// headerXml.selectPath(nameSpace + "//v:shape/@fillcolor"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// if (wpsWordReqDto.getName().contains("透明度")) { +// headerXml.selectPath(nameSpace + "//v:shape/v:fill/@opacity"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// while (value.length() < 8) { +// value = "0" + value; +// } +// long bits = Long.parseLong(value, 16); +// float opacityFloat = Float.intBitsToFloat((int) bits); +// // 转为百分比(例如 0.3 -> 30%) +// float opacityPercent = opacityFloat * 100; +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +opacityPercent); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + opacityPercent + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// if (wpsWordReqDto.getName().contains("版式")) { +// headerXml.selectPath(nameSpace + "//v:shape/@style"); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// value = detectWatermarkLayout(value); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } else { +// headerXml.selectPath(nameSpace + "./" + wpsWordReqDto.getFunction().split("#")[1]); +// if (headerXml.toNextSelection()) { +// String value = headerXml.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-" +value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// +// } +// +// } +// } else if (headerVo.getXmlType().contains("footerReference")) { +// for (XWPFFooter footer : footers) { +// if (footer.getPackagePart().getPartName().getName().contains(fileName)) { +// // 2-1、针对不同的进行排查 +// String chineseType = Objects.equals(headerVo.getType(), "default") ? "奇数页" : Objects.equals(headerVo.getType(), "even") ? "偶数页" : ""; +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// List footerpar = footer.getParagraphs(); +// XmlCursor footerXml = footerpar.get(0).getCTP().newCursor(); +// if (wpsWordReqDto.getFunction().contains("w:page")) { +// if (footerXml.xmlText().contains("PAGE")) { +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 是"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "true" + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } else { +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + " 否"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "false" + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } else { +// footerXml.selectPath(nameSpace + "./" + wpsWordReqDto.getFunction().split("#")[1]); +// if (footerXml.toNextSelection()) { +// String value = footerXml.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + chineseType + "-"+value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value + "-"+ headerVo.getType()); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// +// } +// } +// } +// } +// } +// } +// } else { +// // 需要查询主页面的方法 +// XmlCursor sectPrXsml = docXml.newCursor(); +// if (wpsWordReqDto.getUnit().contains("twipstolines")) { +// String[] docGrid = wpsWordReqDto.getFunction().split("#"); +// XmlCursor docGridXsml = sectPrXsml; +// docGridXsml.selectPath(nameSpace + docGrid[0]); +// String docGridValues = ""; +// String topValues = ""; +// String bottomValues = ""; +// String allValues = ""; +// if (docGridXsml.toNextSelection()) { +// docGridValues = docGridXsml.getTextValue(); +// } +// XmlCursor pgMgXsml = sectPrXsml; +// pgMgXsml.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + docGrid[1]); +// if (pgMgXsml.toNextSelection()) { +// topValues = pgMgXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "top")); +// bottomValues = pgMgXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "bottom")); +// } +// XmlCursor allXsml = sectPrXsml; +// pgMgXsml.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + docGrid[2]); +// if (allXsml.toNextSelection()) { +// allValues = allXsml.getAttributeText(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "h")); +// } +// Integer values = Integer.parseInt(allValues) - Integer.parseInt(bottomValues) +// - Integer.parseInt(topValues); +// Integer docGridValuesInt = values / Integer.parseInt(docGridValues); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + docGridValuesInt); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + docGridValuesInt); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } else if (wpsWordReqDto.getUnit().contains("paper_shape")) { +// sectPrXsml.selectPath(nameSpace + wpsWordReqDto.getFunction()); +// // 纸型 +// if (sectPrXsml.toNextSelection()) { +// String text = sectPrXsml.xmlText(); +// String value = PageSizeDetector.detectPaperSize(text); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } else{ +// sectPrXsml.selectPath(nameSpace + wpsWordReqDto.getFunction()); +// if (sectPrXsml.toNextSelection()) { +// String value = sectPrXsml.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// } +// // 3、图形 +// if ("2".equals(wpsWordReqDto.getBelongTo())) { +// if (wpsWordReqDto.getName().contains("环绕方式")) { +// XmlCursor wpCursor = cursor.newCursor(); +// wpCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); { +// if (wpCursor.toNextSelection()) { +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// String text = wpCursor.xmlText(); +// String value = getDrawingType(text); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + value.split("#")[1]); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value.split("#")[0]); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// // 查询指定值,返回固定的文本 +// judgementList.add(judgement); +// } +// } +// } else if (wpsWordReqDto.getName().contains("形状填充") && wpsWordReqDto.getName().contains("填充方式")) { +// XmlCursor wpCursor = cursor.newCursor(); +// wpCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); +// if (wpCursor.toNextSelection()) { +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// String text = wpCursor.xmlText(); +// String value = getValueType(wpsWordReqDto, text); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } else { +// String function = ""; +// if (wpsWordReqDto.getIsExam().equals("0")) { +// String[] functionList = wpsWordReqDto.getFunction().split("#"); +// if (wpsWordReqDto.getName().contains("图片")) { +// function = functionList[0]; +// } else { +// function = wpsWordReqDto.getEnglishName() + functionList[1]; +// } +// } else { +// function = wpsWordReqDto.getFunction(); +// } +// String chineseName = wpsWordReqDto.getName(); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// // 1-1、创建新的数据组 +// XmlCursor wpCursor = cursor.newCursor(); +// System.out.println(nameSpace + function); +// wpCursor.selectPath(nameSpace + function); +// if (wpCursor.toNextSelection()) { +// if ("1".equals(wpsWordReqDto.getIsboo())) { +// judgement.setContentIn(wpsWordReqDto.getName() + "是"); +// judgement.setContent(function + "-/" + "true"); +// +// } else { +// String value = wpCursor.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(function + "-/" + value); +// } +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// // 查询指定值,返回固定的文本 +// judgementList.add(judgement); +// } else { +// // 参数类型(0:值;1:判断) +// if ("1".equals(wpsWordReqDto.getIsboo())) { +// judgement.setContentIn(wpsWordReqDto.getName() + "false"); +// judgement.setContent(function + "-/" + "false"); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// +// } +// // 4、尾注 +// if ("3".equals(wpsWordReqDto.getBelongTo())) { +// if ("0".equals(wpsWordReqDto.getType())) { +// if (wpsWordReqDto.getName().contains("插入尾注")) { +// // 判断是否存在 +// XmlCursor wpCursor = cursor.newCursor(); +// wpCursor.selectPath(nameSpace + "//w:endnoteReference/@w:id"); +// if (wpCursor.toNextSelection()) { +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + " 是"); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + "true"); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } else { +// for (PackagePart part : pkg.getParts()) { +// String entryName = part.getPartName().getName(); +// if (entryName.contains("word/endnotes") && entryName.contains(".xml")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursorEnd = xmlObject.newCursor(); +// String namespace = WpsWordNameSpaces.getNameSpace(cursorEnd.xmlText()); +// if (wpsWordReqDto.getName().contains("内容")) { +// System.out.println(cursorEnd.xmlText()); +// String value = cursorEnd.getTextValue(); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// } +// } +// } +// // 表格属性 +// if ("4".equals(wpsWordReqDto.getBelongTo())) { +// XmlCursor tblCursor = cursor.newCursor(); +// tblCursor.selectPath(nameSpace + wpsWordReqDto.getFunction()); +// if (tblCursor.toNextSelection()) { +// String value = tblCursor.getTextValue(); +// value = getValueType(wpsWordReqDto, value); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// // 5、域 +// if ("5".equals(wpsWordReqDto.getBelongTo())) { +// XmlCursor yuCursor = cursor.newCursor(); +// yuCursor.selectPath(nameSpace + wpsWordReqDto.getFunction().replace("/chao","")); +// if (yuCursor.toNextSelection()) { +// if (wpsWordReqDto.getName().contains("域代码")) { +// String value = yuCursor.getTextValue(); +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// if (wpsWordReqDto.getName().contains("域类型")) { +// String value = yuCursor.getTextValue(); +// if (value.contains("HYPERLINK")) { +// value = "连接和引用->打开并跳到指定文件"; +// } +// WpsWordJudgementDto judgement = new WpsWordJudgementDto(); +// judgement.setContentIn(wpsWordReqDto.getName() + value); +// judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value); +// judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit()); +// judgement.setScoreRate("1"); +// judgementList.add(judgement); +// } +// } +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// return judgementList; +// } +// public static String getValueType(WpsWordReqDto wpsWordReqDto, String value) { +// String values = value; +// if (wpsWordReqDto.getUnit().contains("Filling_method")) { +// if (value.contains("solidFill")) { +// values = "纯色填充"; +// } else if (value.contains("gradFill")) { +// values = "渐变填充"; +// } else if (value.contains("pattFill")) { +// values = "图案填充"; +// } else if (value.contains("blipFill")) { +// values = "图片填充"; +// } +// } +// if (wpsWordReqDto.getUnit().contains("twiptopt")) { +// values = TwipConverter.formatDouble(TwipConverter.toPoints(Integer.parseInt(value))) + "磅"; +// } +// if (wpsWordReqDto.getUnit().contains("emustopt")) { +// values = TwipConverter.formatDouble(TwipConverter.toEmus(Integer.parseInt(value))) + "磅"; +// } +// if (wpsWordReqDto.getUnit().contains("color")) { +// values = ColorNameFinder.getColorName(value); +// } +// if (wpsWordReqDto.getUnit().contains("underline")) { +// if ("double".equals(value)) { +// values = "双下划线"; +// } else if ("single".equals(value)) { +// values = "单下划线"; +// } else if ("none".equals(value)) { +// values = "无下划线"; +// } else if ("dotted".equals(value)) { +// values = "点划线"; +// } else if ("dottedHeavy".equals(value)) { +// values = "粗点划线"; +// } else if ("dash".equals(value)) { +// values = "虚线"; +// } else if ("dashedHeavy".equals(value)) { +// values = "粗虚线"; +// } else if ("dashLong".equals(value)) { +// values = "长虚线"; +// } +// } +// if (wpsWordReqDto.getUnit().contains("direction")) { +// // 方向英文转换 +// if ("landscape".equals(value)) { +// values = "横向"; +// } else if ("portrait".equals(value)) { +// values = "纵向"; +// } else if ("up".equals(value)) { +// values = "上对齐"; +// } else if ("down".equals(value)) { +// values = "下对齐"; +// } +// } +// if (value.contains("center")) { +// values = "居中对齐"; +// } +// if (wpsWordReqDto.getUnit().contains("textdirection")) { +// // 方向英文转换 +// if ("left".equals(value)) { +// values = "左对齐"; +// } else if ("center".equals(value)) { +// values = "居中对齐"; +// } else if ("right".equals(value)) { +// values = "右对齐"; +// } else if ("both".equals(value)) { +// values = "两端对齐"; +// } +// } +// if (wpsWordReqDto.getUnit().contains("halfpt")) { +// values = String.valueOf (Integer.parseInt(value) / 2); +// } +// if (wpsWordReqDto.getUnit().contains("shadowdirection")) { +// ShadowDirectionUtils.ShadowDirection direction = ShadowDirectionUtils.getShadowDirection(Long.valueOf(value)); +// values = direction.getLabel(); +// } +// if (wpsWordReqDto.getUnit().contains("ershifenzhiyi")) { +// values = String.valueOf (Integer.parseInt(value) / 20); +// } +// if (wpsWordReqDto.getUnit().contains("duanluojianju")) { +// if (Integer.parseInt(value) == 240) { +// values = "1.5 倍行距"; +// } else if (Integer.parseInt(value) == 360) { +// values = "2 倍行距"; +// } else if (Integer.parseInt(value) == 480) { +// values = "3 倍行距"; +// } +// } +// +// return values; +// } +// +// public static String detectWatermarkLayout(String style) { +// if (style == null || !style.contains("rotation:")) { +// return "水平"; +// } +// +// try { +// // 提取 rotation 的值 +// String[] parts = style.split(";"); +// for (String part : parts) { +// part = part.trim(); +// if (part.startsWith("rotation:")) { +// String rotationStr = part.replace("rotation:", "").replace("f", "").trim(); +// int rotationValue = Integer.parseInt(rotationStr); +// +// // 转换为角度(1度 = 65536) +// int degrees = rotationValue / 65536; +// +// // 判断角度 +// if (Math.abs(degrees) == 45) { +// return "倾斜"; +// } else { +// return "水平"; +// } // } // } -// cursor.close(); +// } catch (Exception e) { +// return "解析出错:" + e.getMessage(); // } -// // 获取页脚 -// List footers = document.getFooterList(); -// for (XWPFFooter footer : footers) { -// if (!Objects.equals(footer.getText(), "")) { -// headerAndFooter(null, footer, wordVO); +// +// return "未知格式"; +// } +// +// public static String getDrawingType(String text) { +// String value =""; +// if (text.contains("wp:wrapSquare")) { +// value = "wp:wrapSquare" + "#" + "四周型环绕"; +// } else if (text.contains("wp:wrapTight")) { +// value = "wp:wrapTight" + "#" + "紧密型环绕"; +// } else if (text.contains("wp:wrapThrough")) { +// value = "wp:wrapThrough" + "#" + "穿越型环绕"; +// } else if (text.contains("wp:wrapTopAndBottom")) { +// value = "wp:wrapTopAndBottom" + "#" + "上下型环绕"; +// } else if (text.contains("wp:wrapNone")) { +// value = "wp:wrapNone" + "#" + "无环绕"; +// } +// return value; +// } +// public static void setWordInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List wordInfoReqVos) throws Exception { +// WordInfoReqVo wordInfos = new WordInfoReqVo(); +// wordInfos.setName(chineseName); +// wordInfos.setEnglishName(englishName); +// wordInfos.setFilePath(filePath); +// wordInfos.setId(id); +// wordInfos.setSelectName(selectName); +// wordInfos.setParentId(parentId); +// wordInfoReqVos.add(wordInfos); +// } +// +// public static List wpWord(String filePath) throws Exception { +// List wordInfoReqVos = new ArrayList<>(); +// try (XWPFDocument document = new XWPFDocument(new FileInputStream(filePath))) { +// String xmlString = XmlUtil.getDocumentXml(document); +// String namespace = WpsWordNameSpaces.getNameSpace(xmlString); +// XmlObject docXml = document.getDocument(); +// // 1、获取文档段落W:P标签得数量,判断出一个有多少段 +// XmlCursor wpCursor = docXml.newCursor(); +// String wpPath = namespace + "/w:document/w:body/w:p"; +// wpCursor.selectPath(wpPath); +// int wpIndex = 0; +// // 段落 +// String firstIdWp = getStringRandom(); +// setWordInfo("段落", "w:p", "w:p", filePath, firstIdWp, "0", wordInfoReqVos); +// List wordSecondWp = new ArrayList<>(); +// while (wpCursor.toNextSelection()) { +// wpIndex ++; +// // 段落属性 +// if (!wpCursor.xmlText().contains("w:sectPr")) { +// // 获取文本 +// XmlCursor wpTextXml = wpCursor.newCursor(); +// wpTextXml.selectPath(namespace + ".//w:r/w:t"); +// if (wpTextXml.toNextSelection()) { +// String secondIdWp = getStringRandom(); +// String text = wpTextXml.getTextValue(); +// text = shorten(text); +// setWordInfo("段落" + wpIndex + ":" + text, "(//w:p)[" + wpIndex + "]", "w:pPr", filePath, secondIdWp, firstIdWp, wordInfoReqVos); +// // 使用 。 判断句子 +// String[] texts = text.split("。"); +// int textsIndex = 0; +// for (String s : texts) { +// String thirdIdWp = getStringRandom(); +// textsIndex ++; +// s = shorten(s); +// setWordInfo("句子" + textsIndex + ":" + s, "(//w:p)[" + wpIndex + "]", "w:r", filePath, thirdIdWp, secondIdWp, wordInfoReqVos); +// } +// } +// } +// } +// // 2、页面 +// XmlCursor wSectPrCursor = docXml.newCursor(); +// String wSectPrPath = namespace + "//w:sectPr"; +// wSectPrCursor.selectPath(wSectPrPath); +// int wSectPrIndex = 0; +// String firstIdSectPr = getStringRandom(); +// setWordInfo("页面", "w:sectPr", "w:sectPr", filePath, firstIdSectPr, "", wordInfoReqVos); +// List wordSecondWSectPr = new ArrayList<>(); +// while (wSectPrCursor.toNextSelection()) { +// wSectPrIndex ++; +// String secondIdSectPr = getStringRandom(); +// setWordInfo("节" + wSectPrIndex, "(//w:sectPr)[" + wSectPrIndex + "]", "w:sectPr", filePath, secondIdSectPr, firstIdSectPr, wordInfoReqVos); +// } +// // 3、图形 +// XmlCursor wDrawingCursor = docXml.newCursor(); +// String wDrawingPath = namespace + "//w:drawing"; +// wDrawingCursor.selectPath(wDrawingPath); +// int wDrawingIndex = 0; +// String firstIdDrawing = getStringRandom(); +// setWordInfo("图形", "w:drawing", "w:drawing", filePath, firstIdDrawing, "", wordInfoReqVos); +// while (wDrawingCursor.toNextSelection()) { +// wDrawingIndex ++; +// String secondIdDrawing = getStringRandom(); +// XmlCursor wDrawingXml = wDrawingCursor.newCursor(); +// wDrawingXml.selectPath(namespace + ".//wp:anchor/wp:docPr/@name"); +// if (wDrawingXml.toNextSelection()) { +// setWordInfo("图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "(//w:drawing)[" + wDrawingIndex + "]", "w:drawing", filePath, secondIdDrawing, firstIdDrawing, wordInfoReqVos); +// } +// } +// // 4、尾注 +// XmlCursor endnoteReferenceCursor = docXml.newCursor(); +// String endnoteReferencePath = namespace + "//w:endnoteReference"; +// endnoteReferenceCursor.selectPath(endnoteReferencePath); +// int endnoteReferenceIndex = 0; +// String firstIdEndnoteReference = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (endnoteReferenceIndex == 0) { +// setWordInfo("引用", "w:endnoteReference", "w:endnoteReference", filePath, firstIdEndnoteReference, "", wordInfoReqVos); +// } +// endnoteReferenceIndex ++; +// String secondIdEndnoteReference = getStringRandom(); +// setWordInfo("尾注", "(//w:endnoteReference)[" + endnoteReferenceIndex + "]", "w:endnoteReference", filePath, secondIdEndnoteReference, firstIdEndnoteReference, wordInfoReqVos); +// } +// // 5、表格 +// XmlCursor tblCursor = docXml.newCursor(); +// String tblCursorPath = namespace + "//w:tbl"; +// endnoteReferenceCursor.selectPath(tblCursorPath); +// int tblIndex = 0; +// String firstIdTbl = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (tblIndex == 0) { +// setWordInfo("表格", "w:endnoteReference", "w:endnoteReference", filePath, firstIdTbl, "", wordInfoReqVos); +// } +// tblIndex ++; +// String secondIdTbl = getStringRandom(); +// setWordInfo("表格:"+tblIndex, "(//w:tbl)[" + tblIndex + "]", "w:tbl", filePath, secondIdTbl, firstIdTbl, wordInfoReqVos); +// } +// // 5、域 +// XmlCursor yuCursor = docXml.newCursor(); +// String yuCursorPath = namespace + "//w:instrText"; +// endnoteReferenceCursor.selectPath(yuCursorPath); +// int yuIndex = 0; +// String firstIdyu = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (yuIndex == 0) { +// setWordInfo("域", "w:instrText", "w:instrText", filePath, firstIdyu, "", wordInfoReqVos); +// } +// yuIndex ++; +// String secondIdyu = getStringRandom(); +// setWordInfo("域:"+yuIndex, "(//w:instrText)[" + yuIndex + "]", "w:instrText", filePath, secondIdyu, firstIdyu, wordInfoReqVos); +// } +// return wordInfoReqVos; +// } +// +// } +// +// /** +// * 获取文档段落W:P标签得数量,判断出一个有多少段 +// * @param filePath 文件路径 +// * @return List +// * @throws Exception Exception +// */ +// public static List wps_word(String filePath) throws Exception { +// List wordVO = new ArrayList<>(); +// int count = 0; +// // 1、路径初始化 +// String xmlpath = ""; +// String type = ""; +// XWPFDocument document = new XWPFDocument(new FileInputStream(filePath)); +// String xmlString = XmlUtil.getDocumentXml(document); +// // 2、创建最全的命名空间 +// Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); +// Matcher matcher = pattern.matcher(xmlString); +// Map namespaces = new HashMap<>(); +// while (matcher.find()) { +// // 如 w, wp, a +// String prefix = matcher.group(1); +// // 如 http://schemas.openxmlformats.org/... +// String uri = matcher.group(2); +// namespaces.put(prefix, uri); +// } +// StringBuilder xpathBuilder = new StringBuilder(); +// namespaces.forEach((prefix, uri) -> +// xpathBuilder.append("declare namespace ") +// .append(prefix) +// .append("='") +// .append(uri) +// .append("' ") +// ); +// // 2-1、获取出来最全的命名空间 +// String allPathx = xpathBuilder.toString(); +// // 3、获取CTDocument对象 +// XmlObject docXml = document.getDocument(); +// // 3-1、段落的树数据 +//// List paragraphTree = TreeUtils.buildTree(paragraphList); +// // 3-2、锚点的树数据 +//// List anchorTree = TreeUtils.buildTree(anchorList); +// // Word XML document +// XmlObject xmlObject = document.getDocument(); +//// for (WpsWordLinkDO anchor : anchorTree) { +//// String xpathAnchor = allPathx + "//" + anchor.getName(); +//// XmlCursor cursorAnchor = docXml.newCursor(); +//// int index = 0; +//// cursorAnchor.selectPath(xpathAnchor); +//// while (cursorAnchor.toNextSelection()) { +//// type = "图片"; +//// index += 1; +//// XmlCursor cursorAnchorXml = cursorAnchor.getObject().newCursor(); +//// XmlCursor cursorAnchorText = cursorAnchor.getObject().newCursor(); +//// // 首先:判断类型 1 :图片,2:文本框 +//// cursorAnchorXml.selectPath(allPathx + ".//wp:anchor/wp:docPr/@id"); +//// String typeValue = ""; +//// while (cursorAnchorXml.toNextSelection()) { +//// typeValue = cursorAnchorXml.getTextValue(); +//// } +//// String anchorName = "图片"; +//// if (Objects.equals(typeValue, "2")) { +//// type = "文本框"; +//// System.out.println(cursorAnchorText.xmlText()); +//// // 要获取文本框的文本 +//// cursorAnchorText.selectPath(allPathx + ".//wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx"); +//// while (cursorAnchorText.toNextSelection()) { +//// System.out.println(cursorAnchorText.getObject().xmlText()); +//// anchorName = cursorAnchorText.getTextValue(); +//// } +//// } +//// cursorAnchorText.dispose(); +//// cursorAnchorXml.dispose(); +//// XmlObject paraObj = cursorAnchor.getObject(); +//// for (WpsWordLinkDO root : anchor.getChildren()) { +//// traverseTreeAndQueryXml(type, wordVO, anchor.getName(), anchorName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1); +//// } +//// } +//// cursorAnchor.dispose(); +//// } +//// 创建一个list,存放word读取的数据(段落数据) +//// for (WpsWordLinkDO paragraph : paragraphTree) { +// type = "段落"; +// // 段落划分 根据w:p标签 +// // 到达参数节点,构造 XPath 路径查询它的值 +// String wpPath = allPathx + "/w:document/w:body/w:p"; +// XmlCursor cursor = docXml.newCursor(); +// int index = 0; +// cursor.selectPath(wpPath); +// while (cursor.toNextSelection()) { +// String rTextName = ""; +// index += 1; +// System.out.println(index); +//// // 每一段进行赋值,进行判断 +// XmlObject paraObj = cursor.getObject(); +// String paraText = paraObj.xmlText(); +// System.out.println(paraText); +//// XmlCursor rCursor = paraObj.newCursor(); +//// // 想要查询指定的path +//// rCursor.selectPath(allPathx + ".//w:r/w:t"); +//// while (rCursor.toNextSelection()) { +//// XmlCursor rsCursor = rCursor.getObject().newCursor(); +//// rTextName = rsCursor.getTextValue(); +//// rsCursor.dispose(); +//// } +//// rCursor.dispose(); +//// // 创建新的 +//// for (WpsWordLinkDO root : paragraph.getChildren()) { +//// traverseTreeAndQueryXml(type, wordVO, paragraph.getName(), rTextName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1); +//// } +//// } +// +// } +// // 读取页眉的方法(需要通过页眉查询,水印,页眉文字等信息) +//// List headers = document.getHeaderList(); +//// for (XWPFHeader header : headers) { +//// if (!Objects.equals(header.getText(), "")) { +//// headerAndFooter(header, null, wordVO); +//// } +//// // 获取底层 XML 对象 +//// CTHdrFtr ctHdrFtr = header._getHdrFtr(); // ✅ 正确方法 +//// String xpath = allPathx + "//w:hdr/w:p/w:r/w:pict"; +//// XmlCursor cursor = ctHdrFtr.newCursor(); +//// cursor.selectPath(xpath); +//// while (cursor.toNextSelection()) { +//// // 查询 v:textpath 节点 +//// cursor.selectPath( +//// allPathx + +//// ".//v:textpath" +//// ); +//// while (cursor.toNextSelection()) { +//// XmlObject textpathObj = cursor.getObject(); +//// String xml = textpathObj.xmlText(); +//// WordVO attr_word = new WordVO(); +//// +//// // 提取属性值 +//// String stringAttr = cursor.getAttributeText(new javax.xml.namespace.QName("string")); +//// String styleAttr = cursor.getAttributeText(new javax.xml.namespace.QName("style")); +//// attr_word.setWordText("水印"); +//// List attr = new ArrayList<>(); +//// attr.add("水印文字 string 属性: " + stringAttr); +//// attr.add("水印 style 属性: " + styleAttr); +//// attr_word.setKeynoteChinese(attr); +//// List path = new ArrayList<>(); +//// path.add("name:"+stringAttr); +//// path.add("style:"+styleAttr); +//// attr_word.setExamKeynote(path); +//// attr_word.setType("水印"); +//// wordVO.add(attr_word); +//// } +//// } +//// cursor.close(); +//// } +//// // 获取页脚 +//// List footers = document.getFooterList(); +//// for (XWPFFooter footer : footers) { +//// if (!Objects.equals(footer.getText(), "")) { +//// headerAndFooter(null, footer, wordVO); +//// } +//// } +//// // 邮件合并 +//// List email = getMailMergeFields(document); +//// if (!email.isEmpty()) { +//// // 使用了邮件合并功能 +//// WordVO email_word = new WordVO(); +//// email_word.setWordText("邮件合并"); +//// email_word.setExamKeynote(email); +//// email_word.setKeynoteChinese(email); +//// email_word.setType("邮件合并"); +//// wordVO.add(email_word); +//// } +// return wordVO; +// } +// // 页眉页脚 +// public static void headerAndFooter(XWPFHeader header, XWPFFooter footer, List wordVO) { +// if (header != null) { +// for (XWPFParagraph para : header.getParagraphs()) { +// for (XWPFRun run : para.getRuns()) { +// String text = run.getText(0); +// if (text != null) { +// WordVO wordVO1 = new WordVO(); +// wordVO1.setWordText(text); +// List style_list = new ArrayList<>(); +// style_list.add("font: " + run.getFontFamily()); +// style_list.add("size: " + run.getFontSize()); +// style_list.add("color: " + run.getColor()); +// style_list.add("both: " + run.isBold()); +// style_list.add("italic: " + run.isItalic()); +// wordVO1.setExamKeynote(style_list); +// List style_lists = new ArrayList<>(); +// style_lists.add("字体: " + run.getFontFamily()); +// style_lists.add("字号: " + run.getFontSize()); +// style_lists.add("颜色: " + run.getColor()); +// style_lists.add("加粗: " + run.isBold()); +// style_lists.add("斜体: " + run.isItalic()); +// wordVO1.setKeynoteChinese(style_lists); +// wordVO1.setType("页眉"); +// wordVO.add(wordVO1); +// } +// } // } // } -// // 邮件合并 -// List email = getMailMergeFields(document); -// if (!email.isEmpty()) { -// // 使用了邮件合并功能 -// WordVO email_word = new WordVO(); -// email_word.setWordText("邮件合并"); -// email_word.setExamKeynote(email); -// email_word.setKeynoteChinese(email); -// email_word.setType("邮件合并"); -// wordVO.add(email_word); -// } - return wordVO; - } - // 页眉页脚 - public static void headerAndFooter(XWPFHeader header, XWPFFooter footer, List wordVO) { - if (header != null) { - for (XWPFParagraph para : header.getParagraphs()) { - for (XWPFRun run : para.getRuns()) { - String text = run.getText(0); - if (text != null) { - WordVO wordVO1 = new WordVO(); - wordVO1.setWordText(text); - List style_list = new ArrayList<>(); - style_list.add("font: " + run.getFontFamily()); - style_list.add("size: " + run.getFontSize()); - style_list.add("color: " + run.getColor()); - style_list.add("both: " + run.isBold()); - style_list.add("italic: " + run.isItalic()); - wordVO1.setExamKeynote(style_list); - List style_lists = new ArrayList<>(); - style_lists.add("字体: " + run.getFontFamily()); - style_lists.add("字号: " + run.getFontSize()); - style_lists.add("颜色: " + run.getColor()); - style_lists.add("加粗: " + run.isBold()); - style_lists.add("斜体: " + run.isItalic()); - wordVO1.setKeynoteChinese(style_lists); - wordVO1.setType("页眉"); - wordVO.add(wordVO1); - } - } - } - } - if (footer != null) { - for (XWPFParagraph para : footer.getParagraphs()) { - for (XWPFRun run : para.getRuns()) { - String text = run.getText(0); - if (text != null) { - WordVO wordVO1 = new WordVO(); - wordVO1.setWordText(text); - List style_list = new ArrayList<>(); - style_list.add("font: " + run.getFontFamily()); - style_list.add("size: " + run.getFontSize()); - style_list.add("color: " + run.getColor()); - style_list.add("both: " + run.isBold()); - style_list.add("italic: " + run.isItalic()); - wordVO1.setExamKeynote(style_list); - List style_lists = new ArrayList<>(); - style_lists.add("字体: " + run.getFontFamily()); - style_lists.add("字号: " + run.getFontSize()); - style_lists.add("颜色: " + run.getColor()); - style_lists.add("加粗: " + run.isBold()); - style_lists.add("斜体: " + run.isItalic()); - wordVO1.setKeynoteChinese(style_lists); - wordVO1.setType("页脚"); - wordVO.add(wordVO1); - } - } - } - } - } - - /** - * @param type String 用来存放类型 - * @param wordVOs List 用来存放结果 - * @param firstTitle String 用来存放一级标题 - * @param text String 用来存放文本 - * @param xpath String 用来存放xpath - * @param node WpsWordLinkDO 用来存放节点 - * @param currentXml XmlObject 用来存放当前xml - * @param pathSoFar List 用来存放路径 - * @param pathChinese List 用来存放中文路径 - * @param index int 用来存放索引 - * @param beginIndex int 用来存放开始索引 - */ - public static void traverseTreeAndQueryXml(String type, List wordVOs, String firstTitle, String text, String xpath, WpsWordLinkDO node, XmlObject currentXml, List pathSoFar, List pathChinese, int index, int beginIndex) { - // 到达参数节点,构造 XPath 路径查询它的值 - if (beginIndex == 1) { - xpath += "./"; - } - pathSoFar.add(node.getName()); - pathChinese.add(node.getToChinese()); - - if (node.getType() == 1) { -// pathSoFar.remove(0); - xpath += String.join("/", pathSoFar); - try (XmlCursor cursors = currentXml.newCursor()) { -// System.out.println(xpath); -// System.out.println(cursors.xmlText()); - cursors.selectPath(xpath); - if (cursors.toNextSelection()) { -// System.out.println(cursors.xmlText()); -// cursors.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' //@w:firstLine"); -// if (cursors.toNextSelection()) { -// String texts = cursors.getTextValue(); -// System.out.println("值:" + texts); +// if (footer != null) { +// for (XWPFParagraph para : footer.getParagraphs()) { +// for (XWPFRun run : para.getRuns()) { +// String text = run.getText(0); +// if (text != null) { +// WordVO wordVO1 = new WordVO(); +// wordVO1.setWordText(text); +// List style_list = new ArrayList<>(); +// style_list.add("font: " + run.getFontFamily()); +// style_list.add("size: " + run.getFontSize()); +// style_list.add("color: " + run.getColor()); +// style_list.add("both: " + run.isBold()); +// style_list.add("italic: " + run.isItalic()); +// wordVO1.setExamKeynote(style_list); +// List style_lists = new ArrayList<>(); +// style_lists.add("字体: " + run.getFontFamily()); +// style_lists.add("字号: " + run.getFontSize()); +// style_lists.add("颜色: " + run.getColor()); +// style_lists.add("加粗: " + run.isBold()); +// style_lists.add("斜体: " + run.isItalic()); +// wordVO1.setKeynoteChinese(style_lists); +// wordVO1.setType("页脚"); +// wordVO.add(wordVO1); // } - - String textValue = cursors.getTextValue(); - if (!Objects.equals(textValue, "")) { - // 查找List里面是否已经存在相应文本的数据 - String finalText = text; - int listIndex = IntStream.range(0, wordVOs.size()) - .filter(i -> finalText.equals(wordVOs.get(i).getWordText())) - .findFirst() - .orElse(-1); - // 判断在段落内的样式,如果出现样式,向上兼容,直接再出现样式标签 -// System.out.println(xpath); - if (xpath.indexOf("w:sectPr") > 0 && xpath.indexOf("w:p[") > 0) { - // 说明出现了文本页面设置,需要进行向上绑定 - // 在获取当前的数组长度,获取上面的属性 遍历已经存在的数据 - int tindex = 0; - for (WordVO woVo : wordVOs) { - // 判断标识是否为false,,代表没有进行赋值 - if (!woVo.getIsTrue()) { - WordVO wordVO = wordVOs.get(tindex); - wordVO.setWordText(wordVO.getWordText()); - woVo.setIsTrue(true); - List kchinese = woVo.getKeynoteChinese(); - List examKeynote = woVo.getExamKeynote(); - examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); - kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); - wordVO.setKeynoteChinese(kchinese); - wordVO.setExamKeynote(examKeynote); - wordVO.setType(type); - wordVOs.set(tindex, woVo); - } - tindex += 1; - } - } else if (listIndex < 0) { // 如果没有查询到了 - if (xpath.indexOf("w:sectPr[") > 0) { - // 页面属性 - // 文本 - text = "页面属性"; - } - if (!Objects.equals(text, "")) { - if (!text.contains("MERGEFIELD")) { - // 给标志符 - WordVO wordVO = new WordVO(); - wordVO.setWordText(text); - // 创建list进行存放数据 - List kchinese = new ArrayList<>(); - List examKeynote = new ArrayList<>(); - examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); - kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); - // 组合完数据后进行存放数据 - wordVO.setKeynoteChinese(kchinese); - wordVO.setExamKeynote(examKeynote); - wordVO.setIsTrue(false); - wordVO.setType(type); - wordVOs.add(wordVO); - } - } - } else { // 如果找到了 - WordVO wordVO = wordVOs.get(listIndex); - List kchinese = wordVO.getKeynoteChinese(); - List examKeynote = wordVO.getExamKeynote(); - examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); - kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); - wordVO.setKeynoteChinese(kchinese); - wordVO.setExamKeynote(examKeynote); - wordVO.setIsTrue(false); - wordVO.setType(type); - wordVOs.remove(listIndex); - wordVOs.add(wordVO); - } -// System.out.println("文本:" + text + " 参数路径:" + String.join("@", pathChinese) + ",值:" + text_value); - } - cursors.dispose(); - } - } - } else { - for (WpsWordLinkDO child : node.getChildren()) { - traverseTreeAndQueryXml(type, wordVOs, firstTitle, text, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2); - } - } - pathSoFar.remove(pathSoFar.size() - 1); - pathChinese.remove(pathChinese.size() - 1); - } - - /** - * 使用邮件合并 - */ - public static List getMailMergeFields(XWPFDocument document) { - List fieldNames = new ArrayList<>(); - for (XWPFParagraph paragraph : document.getParagraphs()) { - for (XWPFRun run : paragraph.getRuns()) { - // 获取底层 CTR 对象 - CTR ctr = run.getCTR(); - for (CTText instrText : ctr.getInstrTextList()) { - String text = instrText.getStringValue(); - if (text != null && text.contains("MERGEFIELD")) { - // 正则提取字段名 - Pattern pattern = Pattern.compile("MERGEFIELD\\s+\"?([^\"\\s]+)\"?"); - Matcher matcher = pattern.matcher(text); - if (matcher.find()) { - String fieldName = matcher.group(1).trim(); - fieldNames.add(fieldName); - } - } - } - } - } - return fieldNames; - } - public static String shorten(String input) { - if (input == null) return null; - if (input.length() <= 14) { - return input; - } - String prefix = input.substring(0, 2); - String suffix = input.substring(input.length() - 2); - return prefix + "..." + suffix; - } -} +// } +// } +// } +// } +// +// /** +// * @param type String 用来存放类型 +// * @param wordVOs List 用来存放结果 +// * @param firstTitle String 用来存放一级标题 +// * @param text String 用来存放文本 +// * @param xpath String 用来存放xpath +// * @param node WpsWordLinkDO 用来存放节点 +// * @param currentXml XmlObject 用来存放当前xml +// * @param pathSoFar List 用来存放路径 +// * @param pathChinese List 用来存放中文路径 +// * @param index int 用来存放索引 +// * @param beginIndex int 用来存放开始索引 +// */ +// public static void traverseTreeAndQueryXml(String type, List wordVOs, String firstTitle, String text, String xpath, WpsWordLinkDO node, XmlObject currentXml, List pathSoFar, List pathChinese, int index, int beginIndex) { +// // 到达参数节点,构造 XPath 路径查询它的值 +// if (beginIndex == 1) { +// xpath += "./"; +// } +// pathSoFar.add(node.getName()); +// pathChinese.add(node.getToChinese()); +// +// if (node.getType() == 1) { +//// pathSoFar.remove(0); +// xpath += String.join("/", pathSoFar); +// try (XmlCursor cursors = currentXml.newCursor()) { +//// System.out.println(xpath); +//// System.out.println(cursors.xmlText()); +// cursors.selectPath(xpath); +// if (cursors.toNextSelection()) { +//// System.out.println(cursors.xmlText()); +//// cursors.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' //@w:firstLine"); +//// if (cursors.toNextSelection()) { +//// String texts = cursors.getTextValue(); +//// System.out.println("值:" + texts); +//// } +// +// String textValue = cursors.getTextValue(); +// if (!Objects.equals(textValue, "")) { +// // 查找List里面是否已经存在相应文本的数据 +// String finalText = text; +// int listIndex = IntStream.range(0, wordVOs.size()) +// .filter(i -> finalText.equals(wordVOs.get(i).getWordText())) +// .findFirst() +// .orElse(-1); +// // 判断在段落内的样式,如果出现样式,向上兼容,直接再出现样式标签 +//// System.out.println(xpath); +// if (xpath.indexOf("w:sectPr") > 0 && xpath.indexOf("w:p[") > 0) { +// // 说明出现了文本页面设置,需要进行向上绑定 +// // 在获取当前的数组长度,获取上面的属性 遍历已经存在的数据 +// int tindex = 0; +// for (WordVO woVo : wordVOs) { +// // 判断标识是否为false,,代表没有进行赋值 +// if (!woVo.getIsTrue()) { +// WordVO wordVO = wordVOs.get(tindex); +// wordVO.setWordText(wordVO.getWordText()); +// woVo.setIsTrue(true); +// List kchinese = woVo.getKeynoteChinese(); +// List examKeynote = woVo.getExamKeynote(); +// examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); +// kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); +// wordVO.setKeynoteChinese(kchinese); +// wordVO.setExamKeynote(examKeynote); +// wordVO.setType(type); +// wordVOs.set(tindex, woVo); +// } +// tindex += 1; +// } +// } else if (listIndex < 0) { // 如果没有查询到了 +// if (xpath.indexOf("w:sectPr[") > 0) { +// // 页面属性 +// // 文本 +// text = "页面属性"; +// } +// if (!Objects.equals(text, "")) { +// if (!text.contains("MERGEFIELD")) { +// // 给标志符 +// WordVO wordVO = new WordVO(); +// wordVO.setWordText(text); +// // 创建list进行存放数据 +// List kchinese = new ArrayList<>(); +// List examKeynote = new ArrayList<>(); +// examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); +// kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); +// // 组合完数据后进行存放数据 +// wordVO.setKeynoteChinese(kchinese); +// wordVO.setExamKeynote(examKeynote); +// wordVO.setIsTrue(false); +// wordVO.setType(type); +// wordVOs.add(wordVO); +// } +// } +// } else { // 如果找到了 +// WordVO wordVO = wordVOs.get(listIndex); +// List kchinese = wordVO.getKeynoteChinese(); +// List examKeynote = wordVO.getExamKeynote(); +// examKeynote.add(String.join("@", pathSoFar) + ",value:" + textValue); +// kchinese.add(String.join("@", pathChinese) + ",值:" + textValue); +// wordVO.setKeynoteChinese(kchinese); +// wordVO.setExamKeynote(examKeynote); +// wordVO.setIsTrue(false); +// wordVO.setType(type); +// wordVOs.remove(listIndex); +// wordVOs.add(wordVO); +// } +//// System.out.println("文本:" + text + " 参数路径:" + String.join("@", pathChinese) + ",值:" + text_value); +// } +// cursors.dispose(); +// } +// } +// } else { +// for (WpsWordLinkDO child : node.getChildren()) { +// traverseTreeAndQueryXml(type, wordVOs, firstTitle, text, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2); +// } +// } +// pathSoFar.remove(pathSoFar.size() - 1); +// pathChinese.remove(pathChinese.size() - 1); +// } +// +// /** +// * 使用邮件合并 +// */ +// public static List getMailMergeFields(XWPFDocument document) { +// List fieldNames = new ArrayList<>(); +// for (XWPFParagraph paragraph : document.getParagraphs()) { +// for (XWPFRun run : paragraph.getRuns()) { +// // 获取底层 CTR 对象 +// CTR ctr = run.getCTR(); +// for (CTText instrText : ctr.getInstrTextList()) { +// String text = instrText.getStringValue(); +// if (text != null && text.contains("MERGEFIELD")) { +// // 正则提取字段名 +// Pattern pattern = Pattern.compile("MERGEFIELD\\s+\"?([^\"\\s]+)\"?"); +// Matcher matcher = pattern.matcher(text); +// if (matcher.find()) { +// String fieldName = matcher.group(1).trim(); +// fieldNames.add(fieldName); +// } +// } +// } +// } +// } +// return fieldNames; +// } +// public static String shorten(String input) { +// if (input == null) return null; +// if (input.length() <= 14) { +// return input; +// } +// String prefix = input.substring(0, 6); +// String suffix = input.substring(input.length() - 2); +// return prefix + "..." + suffix; +// } +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/DocxConversion.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/DocxConversion.java new file mode 100644 index 00000000..db6c8547 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/DocxConversion.java @@ -0,0 +1,183 @@ +package pc.exam.pp.module.judgement.utils.wps_word.docx4j; + +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.springframework.web.multipart.MultipartFile; +import pc.exam.pp.module.judgement.utils.wps_word.WpsWordNameSpaces; +import pc.exam.pp.module.judgement.utils.wps_word.XmlUtil; +import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO; +import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; +import pc.exam.pp.module.judgement.utils.wps_word.vo.WordSecondInfoVo; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class DocxConversion { + public static List DocxDataInfos(MultipartFile file) throws Exception { + List dataInfoVOS = new ArrayList<>(); + try (InputStream inputStream = file.getInputStream()) { + // 1. 直接使用 InputStream 构造 XWPFDocument(无需本地文件) + XWPFDocument document = new XWPFDocument(inputStream); + + // 2. 读取文档内容(示例:提取所有段落文本) + StringBuilder content = new StringBuilder(); + document.getParagraphs().forEach(paragraph -> { + content.append(paragraph.getText()).append("\n"); + }); + + + String xmlString = XmlUtil.getDocumentXml(document); + String namespace = WpsWordNameSpaces.getNameSpace(xmlString); + XmlObject docXml = document.getDocument(); + // 1、获取文档段落W:P标签得数量,判断出一个有多少段 + XmlCursor wpCursor = docXml.newCursor(); + String wpPath = namespace + "/w:document/w:body/w:p"; + wpCursor.selectPath(wpPath); + int wpIndex = 0; + // 段落 + String firstIdWp = getStringRandom(); + setWordDataInfo(firstIdWp, "", "段落", "w:p", "", false, dataInfoVOS); + List wordSecondWp = new ArrayList<>(); + while (wpCursor.toNextSelection()) { + wpIndex ++; + // 段落属性 + if (!wpCursor.xmlText().contains("w:sectPr")) { + // 获取文本 + XmlCursor wpTextXml = wpCursor.newCursor(); + wpTextXml.selectPath(namespace + ".//w:r/w:t"); + if (wpTextXml.toNextSelection()) { + String secondIdWp = getStringRandom(); + String text = wpTextXml.getTextValue(); + text = shorten(text); + setWordDataInfo(secondIdWp, firstIdWp, "段落" + wpIndex + ":" + text, "w:p", String.valueOf(wpIndex), true, dataInfoVOS); + // 使用 。 判断句子 + String[] texts = text.split("。"); + int textsIndex = 0; + for (String s : texts) { + String thirdIdWp = getStringRandom(); + textsIndex ++; + s = shorten(s); + setWordDataInfo(thirdIdWp, secondIdWp, "句子" + textsIndex + ":" + s, "w:t", String.valueOf(wpIndex), true, dataInfoVOS); + } + } + } + } + // 2、页面 + XmlCursor wSectPrCursor = docXml.newCursor(); + String wSectPrPath = namespace + "//w:sectPr"; + wSectPrCursor.selectPath(wSectPrPath); + int wSectPrIndex = 0; + String firstIdSectPr = getStringRandom(); + setWordDataInfo(firstIdSectPr, "", "页面", "w:sectPr", "", false, dataInfoVOS); + List wordSecondWSectPr = new ArrayList<>(); + while (wSectPrCursor.toNextSelection()) { + wSectPrIndex ++; + String secondIdSectPr = getStringRandom(); + setWordDataInfo(secondIdSectPr, firstIdSectPr, "节" + wSectPrIndex, "w:sectPr", String.valueOf(wSectPrIndex), true, dataInfoVOS); + } +// // 3、图形 +// XmlCursor wDrawingCursor = docXml.newCursor(); +// String wDrawingPath = namespace + "//w:drawing"; +// wDrawingCursor.selectPath(wDrawingPath); +// int wDrawingIndex = 0; +// String firstIdDrawing = getStringRandom(); +// setWordDataInfo(firstIdDrawing, "", "图形", "w:drawing", "", false, dataInfoVOS); +// while (wDrawingCursor.toNextSelection()) { +// wDrawingIndex ++; +// String secondIdDrawing = getStringRandom(); +// XmlCursor wDrawingXml = wDrawingCursor.newCursor(); +// wDrawingXml.selectPath(namespace + ".//wp:anchor/wp:docPr/@name"); +// if (wDrawingXml.toNextSelection()) { +// setWordDataInfo(firstIdSectPr, firstIdDrawing, "图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "w:drawing", String.valueOf(wDrawingIndex), true, dataInfoVOS); +// setWordInfo("图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "(//w:drawing)[" + wDrawingIndex + "]", "w:drawing", filePath, secondIdDrawing, firstIdDrawing, wordInfoReqVos); +// } +// } +// // 4、尾注 +// XmlCursor endnoteReferenceCursor = docXml.newCursor(); +// String endnoteReferencePath = namespace + "//w:endnoteReference"; +// endnoteReferenceCursor.selectPath(endnoteReferencePath); +// int endnoteReferenceIndex = 0; +// String firstIdEndnoteReference = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (endnoteReferenceIndex == 0) { +// setWordInfo("引用", "w:endnoteReference", "w:endnoteReference", filePath, firstIdEndnoteReference, "", wordInfoReqVos); +// } +// endnoteReferenceIndex ++; +// String secondIdEndnoteReference = getStringRandom(); +// setWordInfo("尾注", "(//w:endnoteReference)[" + endnoteReferenceIndex + "]", "w:endnoteReference", filePath, secondIdEndnoteReference, firstIdEndnoteReference, wordInfoReqVos); +// } +// // 5、表格 +// XmlCursor tblCursor = docXml.newCursor(); +// String tblCursorPath = namespace + "//w:tbl"; +// endnoteReferenceCursor.selectPath(tblCursorPath); +// int tblIndex = 0; +// String firstIdTbl = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (tblIndex == 0) { +// setWordInfo("表格", "w:endnoteReference", "w:endnoteReference", filePath, firstIdTbl, "", wordInfoReqVos); +// } +// tblIndex ++; +// String secondIdTbl = getStringRandom(); +// setWordInfo("表格:"+tblIndex, "(//w:tbl)[" + tblIndex + "]", "w:tbl", filePath, secondIdTbl, firstIdTbl, wordInfoReqVos); +// } +// // 5、域 +// XmlCursor yuCursor = docXml.newCursor(); +// String yuCursorPath = namespace + "//w:instrText"; +// endnoteReferenceCursor.selectPath(yuCursorPath); +// int yuIndex = 0; +// String firstIdyu = getStringRandom(); +// while (endnoteReferenceCursor.toNextSelection()) { +// if (yuIndex == 0) { +// setWordInfo("域", "w:instrText", "w:instrText", filePath, firstIdyu, "", wordInfoReqVos); +// } +// yuIndex ++; +// String secondIdyu = getStringRandom(); +// setWordInfo("域:"+yuIndex, "(//w:instrText)[" + yuIndex + "]", "w:instrText", filePath, secondIdyu, firstIdyu, wordInfoReqVos); +// } + + // 3. 关闭资源(try-with-resources 自动关闭 InputStream) + document.close(); + + return dataInfoVOS; + } + } + public static String getStringRandom() { + String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + + // 生成指定长度的随机字符字符串 + for (int i = 0; i < 10; i++) { + int randomIndex = random.nextInt(characters.length()); + // 随机字符 + sb.append(characters.charAt(randomIndex)); + } + return sb.toString(); + } + + // 想数组中添加数据 + public static void setWordDataInfo(String id, String parentId, String text, + String type, String index, boolean isTrue, List dataInfoVOS) throws Exception { + DocxDataInfoVO dataInfo = new DocxDataInfoVO(); + dataInfo.setId(id); + dataInfo.setParentId(parentId); + dataInfo.setName(text); + dataInfo.setType(type); + dataInfo.setIndex(index); + dataInfo.setClick(isTrue); + dataInfoVOS.add(dataInfo); + } + public static String shorten(String input) { + if (input == null) return null; + if (input.length() <= 14) { + return input; + } + String prefix = input.substring(0, 6); + String suffix = input.substring(input.length() - 2); + return prefix + "..." + suffix; + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/vo/DocxDataInfoVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/vo/DocxDataInfoVO.java new file mode 100644 index 00000000..2c1cbd52 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/docx4j/vo/DocxDataInfoVO.java @@ -0,0 +1,19 @@ +package pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo; + +import lombok.Data; + +@Data +public class DocxDataInfoVO { + + private String name; + + private String type; + + private String id; + + private String parentId; + + private String index; + + private boolean isClick; +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/vo/WordInfoReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/vo/WordInfoReqVo.java index 5dffb457..bfe28c84 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/vo/WordInfoReqVo.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_word/vo/WordInfoReqVo.java @@ -2,7 +2,6 @@ package pc.exam.pp.module.judgement.utils.wps_word.vo; import lombok.Data; import org.apache.xmlbeans.XmlCursor; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; import java.util.ArrayList; import java.util.List; diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/resources/mapper/wpsword/WpsWordLinkMapper.xml b/exam-module-judgement/exam-module-judgement-biz/src/main/resources/mapper/wpsword/WpsWordLinkMapper.xml deleted file mode 100644 index 409a9c72..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/resources/mapper/wpsword/WpsWordLinkMapper.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java b/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java index c6a7bb5a..b951dbd8 100644 --- a/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java +++ b/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java @@ -176,13 +176,13 @@ public interface ErrorCodeConstants { // ========== WpsWOrd 1-002-030-000 ========== - ErrorCode WORD_NAME_DUPLICATE = new ErrorCode(1_002_030_000, "已经存在该名字的WORD节点"); - ErrorCode WORD_PARENT_NOT_EXITS = new ErrorCode(1_002_030_001,"父级WORD节点不存在"); - ErrorCode WORD_NOT_FOUND = new ErrorCode(1_002_030_002, "当前WORD节点不存在"); - ErrorCode WORD_EXITS_CHILDREN = new ErrorCode(1_002_030_003, "存在子WORD节点,无法删除"); - ErrorCode WORD_PARENT_ERROR = new ErrorCode(1_002_030_004, "不能设置自己为父WORD节点"); - ErrorCode WORD_NOT_ENABLE = new ErrorCode(1_002_030_006, "WORD节点({})不处于开启状态,不允许选择"); - ErrorCode WORD_PARENT_IS_CHILD = new ErrorCode(1_002_030_007, "不能设置自己的子WORD节点为父WORD节点"); + ErrorCode DOCX_NAME_DUPLICATE = new ErrorCode(1_002_030_000, "已经存在该名字的WORD节点"); + ErrorCode DOCX_PARENT_NOT_EXITS = new ErrorCode(1_002_030_001,"父级WORD节点不存在"); + ErrorCode DOCX_NOT_FOUND = new ErrorCode(1_002_030_002, "当前WORD节点不存在"); + ErrorCode DOCX_EXITS_CHILDREN = new ErrorCode(1_002_030_003, "存在子WORD节点,无法删除"); + ErrorCode DOCX_PARENT_ERROR = new ErrorCode(1_002_030_004, "不能设置自己为父WORD节点"); + ErrorCode DOCX_NOT_ENABLE = new ErrorCode(1_002_030_006, "WORD节点({})不处于开启状态,不允许选择"); + ErrorCode DOCX_PARENT_IS_CHILD = new ErrorCode(1_002_030_007, "不能设置自己的子WORD节点为父WORD节点"); // ========== WpsPptx 1-002-031-000 ========== ErrorCode PPTX_NAME_DUPLICATE = new ErrorCode(1_002_031_000, "已经存在该名字的PPTX节点");