【新增】 Xlsx相关页面方法
This commit is contained in:
@@ -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.xlsx.XlsxListReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxRespVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSimpleRespVO;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx;
|
||||
import pc.exam.pp.module.exam.service.wps.xlsx.ExamWpsXlsxService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static pc.exam.pp.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "考试系统 - XLSX考点")
|
||||
@RestController
|
||||
@RequestMapping("/exam/xlsx")
|
||||
@Validated
|
||||
public class ExamWpsXlsxController {
|
||||
|
||||
@Resource
|
||||
private ExamWpsXlsxService examWpsXlsxService;
|
||||
|
||||
@PostMapping("create")
|
||||
@Operation(summary = "创建XLSX考点")
|
||||
public CommonResult<Long> createXlsx(@Valid @RequestBody XlsxSaveReqVO createReqVO) {
|
||||
Long XlsxId = examWpsXlsxService.createXlsx(createReqVO);
|
||||
return success(XlsxId);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@Operation(summary = "更新XLSX考点")
|
||||
public CommonResult<Boolean> updateXlsx(@Valid @RequestBody XlsxSaveReqVO updateReqVO) {
|
||||
examWpsXlsxService.updateXlsx(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("delete")
|
||||
@Operation(summary = "删除XLSX考点")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<Boolean> deleteXlsx(@RequestParam("id") Long id) {
|
||||
examWpsXlsxService.deleteXlsx(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取XLSX考点列表")
|
||||
public CommonResult<List<XlsxRespVO>> getXlsxList(XlsxListReqVO reqVO) {
|
||||
List<ExamWpsXlsx> list = examWpsXlsxService.getXlsxList(reqVO);
|
||||
return success(BeanUtils.toBean(list, XlsxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/list-all-simple", "/simple-list"})
|
||||
@Operation(summary = "获取XLSX考点精简信息列表", description = "只包含被开启的XLSX考点,主要用于前端的下拉选项")
|
||||
public CommonResult<List<XlsxSimpleRespVO>> getSimpleXlsxList() {
|
||||
List<ExamWpsXlsx> list = examWpsXlsxService.getXlsxList(
|
||||
new XlsxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
return success(BeanUtils.toBean(list, XlsxSimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得XLSX考点信息")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<XlsxRespVO> getXlsx(@RequestParam("id") Long id) {
|
||||
ExamWpsXlsx xlsx = examWpsXlsxService.getXlsx(id);
|
||||
return success(BeanUtils.toBean(xlsx, XlsxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/getByNameList")
|
||||
public CommonResult<List<XlsxRespVO>> getXlsxByNameList(@RequestParam("title") String title) {
|
||||
ExamWpsXlsx xlsx = examWpsXlsxService.getXlsxByTitle(title);
|
||||
return success(BeanUtils.toBean(examWpsXlsxService.getChildXlsxList(xlsx.getId()), XlsxRespVO.class));
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "考试模块 - XLSX考点列表 Request VO")
|
||||
@Data
|
||||
public class XlsxListReqVO {
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer status;
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "考试模块 - XLSX考点信息 Response VO")
|
||||
@Data
|
||||
public class XlsxRespVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String title;
|
||||
|
||||
private String chineseName;
|
||||
|
||||
private String functions;
|
||||
|
||||
private String parameter;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "考试模块 - XLSX考点创建/修改 Request VO")
|
||||
@Data
|
||||
public class XlsxSaveReqVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String title;
|
||||
|
||||
private String chineseName;
|
||||
|
||||
private String parameter;
|
||||
|
||||
private String functions;
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx;
|
||||
|
||||
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 XlsxSimpleRespVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
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 xlsx关系对应表
|
||||
*
|
||||
* @author REN
|
||||
*/
|
||||
@TableName("exam_wps_xlsx")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ExamWpsXlsx 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 functions;
|
||||
private String parameter;
|
||||
private Integer status;
|
||||
@TableField(exist = false)
|
||||
private List<ExamWpsXlsx> children = new ArrayList<>();
|
||||
}
|
@@ -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.xlsx.XlsxListReqVO;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ExamWpsXlsxMapper extends BaseMapperX<ExamWpsXlsx> {
|
||||
|
||||
default List<ExamWpsXlsx> selectList(XlsxListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<ExamWpsXlsx>()
|
||||
.likeIfPresent(ExamWpsXlsx::getName, reqVO.getName())
|
||||
.eqIfPresent(ExamWpsXlsx::getStatus, reqVO.getStatus()));
|
||||
}
|
||||
|
||||
default ExamWpsXlsx selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(ExamWpsXlsx::getParentId, parentId, ExamWpsXlsx::getName, name);
|
||||
}
|
||||
|
||||
default ExamWpsXlsx selectByTitle(String title) {
|
||||
return selectOne(ExamWpsXlsx::getTitle, title);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
return selectCount(ExamWpsXlsx::getParentId, parentId);
|
||||
}
|
||||
|
||||
default List<ExamWpsXlsx> selectListByParentId(Collection<Long> parentIds) {
|
||||
return selectList(ExamWpsXlsx::getParentId, parentIds);
|
||||
}
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
package pc.exam.pp.module.exam.service.wps.xlsx;
|
||||
|
||||
import pc.exam.pp.framework.common.util.collection.CollectionUtils;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxListReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Xlsx考点 Service 接口
|
||||
*
|
||||
* @author 朋辰
|
||||
*/
|
||||
public interface ExamWpsXlsxService {
|
||||
|
||||
/**
|
||||
* 创建Xlsx考点
|
||||
*
|
||||
* @param createReqVO Xlsx考点信息
|
||||
* @return Xlsx考点编号
|
||||
*/
|
||||
Long createXlsx(XlsxSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新Xlsx考点
|
||||
*
|
||||
* @param updateReqVO Xlsx考点信息
|
||||
*/
|
||||
void updateXlsx(XlsxSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除Xlsx考点
|
||||
*
|
||||
* @param id Xlsx考点编号
|
||||
*/
|
||||
void deleteXlsx(Long id);
|
||||
|
||||
/**
|
||||
* 获得Xlsx考点信息
|
||||
*
|
||||
* @param id Xlsx考点编号
|
||||
* @return Xlsx考点信息
|
||||
*/
|
||||
ExamWpsXlsx getXlsx(Long id);
|
||||
|
||||
/**
|
||||
* 获得Xlsx考点信息
|
||||
*
|
||||
* @param title Xlsx考点标签
|
||||
* @return Xlsx考点信息
|
||||
*/
|
||||
ExamWpsXlsx getXlsxByTitle(String title);
|
||||
|
||||
/**
|
||||
* 获得Xlsx考点信息数组
|
||||
*
|
||||
* @param ids Xlsx考点编号数组
|
||||
* @return Xlsx考点信息数组
|
||||
*/
|
||||
List<ExamWpsXlsx> getXlsxList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 筛选Xlsx考点列表
|
||||
*
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return Xlsx考点列表
|
||||
*/
|
||||
List<ExamWpsXlsx> getXlsxList(XlsxListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得指定编号的Xlsx考点 Map
|
||||
*
|
||||
* @param ids Xlsx考点编号数组
|
||||
* @return Xlsx考点 Map
|
||||
*/
|
||||
default Map<Long, ExamWpsXlsx> getXlsxMap(Collection<Long> ids) {
|
||||
List<ExamWpsXlsx> list = getXlsxList(ids);
|
||||
return CollectionUtils.convertMap(list, ExamWpsXlsx::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定Xlsx考点的所有子Xlsx考点
|
||||
*
|
||||
* @param id Xlsx考点编号
|
||||
* @return 子Xlsx考点列表
|
||||
*/
|
||||
default List<ExamWpsXlsx> getChildXlsxList(Long id) {
|
||||
return getChildXlsxList(Collections.singleton(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定Xlsx考点的所有子Xlsx考点
|
||||
*
|
||||
* @param ids Xlsx考点编号数组
|
||||
* @return 子Xlsx考点列表
|
||||
*/
|
||||
List<ExamWpsXlsx> getChildXlsxList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得所有子Xlsx考点,从缓存中
|
||||
*
|
||||
* @param id 父Xlsx考点编号
|
||||
* @return 子Xlsx考点列表
|
||||
*/
|
||||
Set<Long> getChildXlsxIdListFromCache(Long id);
|
||||
|
||||
/**
|
||||
* 校验Xlsx考点们是否有效。如下情况,视为无效:
|
||||
* 1. Xlsx考点编号不存在
|
||||
* 2. Xlsx考点被禁用
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
*/
|
||||
void validateXlsxList(Collection<Long> ids);
|
||||
|
||||
}
|
@@ -0,0 +1,221 @@
|
||||
package pc.exam.pp.module.exam.service.wps.xlsx;
|
||||
|
||||
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.xlsx.XlsxListReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx;
|
||||
import pc.exam.pp.module.exam.dal.mysql.wps.ExamWpsXlsxMapper;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* Xlsx考点 Service 实现类
|
||||
*
|
||||
* @author 朋辰
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class ExamWpsXlsxServiceImpl implements ExamWpsXlsxService {
|
||||
|
||||
@Resource
|
||||
private ExamWpsXlsxMapper XlsxMapper;
|
||||
|
||||
@Override
|
||||
public Long createXlsx(XlsxSaveReqVO createReqVO) {
|
||||
if (createReqVO.getParentId() == null) {
|
||||
createReqVO.setParentId(ExamWpsXlsx.PARENT_ID_ROOT);
|
||||
}
|
||||
// 校验父Xlsx考点的有效性
|
||||
validateParentXlsx(null, createReqVO.getParentId());
|
||||
// 校验Xlsx考点名的唯一性
|
||||
validateXlsxNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
||||
|
||||
// 插入Xlsx考点
|
||||
ExamWpsXlsx Xlsx = BeanUtils.toBean(createReqVO, ExamWpsXlsx.class);
|
||||
XlsxMapper.insert(Xlsx);
|
||||
return Xlsx.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateXlsx(XlsxSaveReqVO updateReqVO) {
|
||||
if (updateReqVO.getParentId() == null) {
|
||||
updateReqVO.setParentId(ExamWpsXlsx.PARENT_ID_ROOT);
|
||||
}
|
||||
// 校验自己存在
|
||||
validateXlsxExists(updateReqVO.getId());
|
||||
// 校验父Xlsx考点的有效性
|
||||
validateParentXlsx(updateReqVO.getId(), updateReqVO.getParentId());
|
||||
// 校验Xlsx考点名的唯一性
|
||||
validateXlsxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
||||
|
||||
// 更新Xlsx考点
|
||||
ExamWpsXlsx updateObj = BeanUtils.toBean(updateReqVO, ExamWpsXlsx.class);
|
||||
XlsxMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteXlsx(Long id) {
|
||||
// 校验是否存在
|
||||
validateXlsxExists(id);
|
||||
// 校验是否有子Xlsx考点
|
||||
if (XlsxMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(XLSX_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除Xlsx考点
|
||||
XlsxMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateXlsxExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
ExamWpsXlsx Xlsx = XlsxMapper.selectById(id);
|
||||
if (Xlsx == null) {
|
||||
throw exception(XLSX_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateParentXlsx(Long id, Long parentId) {
|
||||
if (parentId == null || ExamWpsXlsx.PARENT_ID_ROOT.equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 1. 不能设置自己为父Xlsx考点
|
||||
if (Objects.equals(id, parentId)) {
|
||||
throw exception(XLSX_PARENT_ERROR);
|
||||
}
|
||||
// 2. 父Xlsx考点不存在
|
||||
ExamWpsXlsx parent = XlsxMapper.selectById(parentId);
|
||||
if (parent == null) {
|
||||
throw exception(XLSX_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 3. 递归校验父Xlsx考点,如果父Xlsx考点是自己的子Xlsx考点,则报错,避免形成环路
|
||||
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(XLSX_PARENT_IS_CHILD);
|
||||
}
|
||||
// 3.2 继续递归下一级父Xlsx考点
|
||||
if (parentId == null || ExamWpsXlsx.PARENT_ID_ROOT.equals(parentId)) {
|
||||
break;
|
||||
}
|
||||
parent = XlsxMapper.selectById(parentId);
|
||||
if (parent == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateXlsxNameUnique(Long id, Long parentId, String name) {
|
||||
ExamWpsXlsx dept = XlsxMapper.selectByParentIdAndName(parentId, name);
|
||||
if (dept == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的Xlsx考点
|
||||
if (id == null) {
|
||||
throw exception(XLSX_NAME_DUPLICATE);
|
||||
}
|
||||
if (ObjectUtil.notEqual(dept.getId(), id)) {
|
||||
throw exception(XLSX_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExamWpsXlsx getXlsx(Long id) {
|
||||
return XlsxMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExamWpsXlsx getXlsxByTitle(String title) {
|
||||
return XlsxMapper.selectByTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamWpsXlsx> getXlsxList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return XlsxMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamWpsXlsx> getXlsxList(XlsxListReqVO reqVO) {
|
||||
List<ExamWpsXlsx> list = XlsxMapper.selectList(reqVO);
|
||||
list.sort(Comparator.comparing(ExamWpsXlsx::getSort));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, ExamWpsXlsx> getXlsxMap(Collection<Long> ids) {
|
||||
return ExamWpsXlsxService.super.getXlsxMap(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamWpsXlsx> getChildXlsxList(Long id) {
|
||||
return ExamWpsXlsxService.super.getChildXlsxList(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamWpsXlsx> getChildXlsxList(Collection<Long> ids) {
|
||||
List<ExamWpsXlsx> children = new LinkedList<>();
|
||||
// 遍历每一层
|
||||
Collection<Long> parentIds = ids;
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
|
||||
// 查询当前层,所有的子Xlsx考点
|
||||
List<ExamWpsXlsx> Xlsxs = XlsxMapper.selectListByParentId(parentIds);
|
||||
// 1. 如果没有子Xlsx考点,则结束遍历
|
||||
if (CollUtil.isEmpty(Xlsxs)) {
|
||||
break;
|
||||
}
|
||||
// 2. 如果有子Xlsx考点,继续遍历
|
||||
children.addAll(Xlsxs);
|
||||
parentIds = convertSet(Xlsxs, ExamWpsXlsx::getId);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getChildXlsxIdListFromCache(Long id) {
|
||||
List<ExamWpsXlsx> children = getChildXlsxList(id);
|
||||
return convertSet(children, ExamWpsXlsx::getId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateXlsxList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得科室信息
|
||||
Map<Long, ExamWpsXlsx> XlsxMap = getXlsxMap(ids);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
ExamWpsXlsx Xlsx = XlsxMap.get(id);
|
||||
if (Xlsx == null) {
|
||||
throw exception(XLSX_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(Xlsx.getStatus())) {
|
||||
throw exception(XLSX_NOT_ENABLE, Xlsx.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user