1 changed files with 91 additions and 0 deletions
@ -0,0 +1,91 @@ |
|||||
|
package com.project.operation.domain.service.impl.description; |
||||
|
|
||||
|
import com.project.classicpaper.domain.dto.ClassicCategoryDTO; |
||||
|
import com.project.classicpaper.domain.dto.ClassicPaperSetDTO; |
||||
|
import com.project.classicpaper.domain.entity.ClassicCategoryEntity; |
||||
|
import com.project.classicpaper.domain.entity.ClassicPaperSetEntity; |
||||
|
import com.project.classicpaper.mapper.ClassicCategoryMapper; |
||||
|
import com.project.classicpaper.mapper.ClassicPaperSetMapper; |
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
import com.project.operation.domain.enums.ModuleEnum; |
||||
|
import com.project.operation.domain.service.DescriptionStrategy; |
||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.Optional; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 套题管理 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class ClassicPaperDescriptionStrategy implements DescriptionStrategy { |
||||
|
|
||||
|
@Autowired |
||||
|
private ClassicCategoryMapper classicCategoryMapper; |
||||
|
@Autowired |
||||
|
private ClassicPaperSetMapper classicPaperSetMapper; |
||||
|
|
||||
|
@Override |
||||
|
public Boolean process(Object[] args, OperationLogDTO operationLogDTO, String methodName) { |
||||
|
// ClassicCategoryController.save — 添加套题分类
|
||||
|
if (methodName.equals("save") && ObjectUtils.isNotEmpty(args) && args[0] instanceof ClassicCategoryDTO dto) { |
||||
|
if (StringUtils.isBlank(dto.getName())) { |
||||
|
return false; |
||||
|
} |
||||
|
operationLogDTO.setDescription("【套题分类】【" + dto.getName() + "】"); |
||||
|
} |
||||
|
|
||||
|
// ClassicCategoryController.delete — 删除套题分类
|
||||
|
if (methodName.equals("delete") && ObjectUtils.isNotEmpty(args) && args[0] instanceof Long id) { |
||||
|
ClassicCategoryEntity entity = classicCategoryMapper.selectByIdIncludeDeleted(id); |
||||
|
if (entity == null || StringUtils.isBlank(entity.getName())) { |
||||
|
return false; |
||||
|
} |
||||
|
operationLogDTO.setDescription("【套题分类】【" + entity.getName() + "】"); |
||||
|
} |
||||
|
|
||||
|
// ClassicPaperSetController.generate — 添加套题
|
||||
|
if (methodName.equals("generate") && ObjectUtils.isNotEmpty(args) && args[0] instanceof ClassicPaperSetDTO dto) { |
||||
|
if (StringUtils.isBlank(dto.getName())) { |
||||
|
return false; |
||||
|
} |
||||
|
operationLogDTO.setDescription("【" + dto.getName() + "】"); |
||||
|
} |
||||
|
|
||||
|
// ClassicPaperSetController.delete — 删除套题
|
||||
|
if (methodName.equals("delete") && ObjectUtils.isNotEmpty(args) && args[0] instanceof String ids) { |
||||
|
if (StringUtils.isBlank(ids)) { |
||||
|
return false; |
||||
|
} |
||||
|
List<Long> idList = Arrays.stream(ids.split(",")) |
||||
|
.filter(StringUtils::isNotBlank) |
||||
|
.map(Long::valueOf) |
||||
|
.collect(Collectors.toList()); |
||||
|
if (idList.isEmpty()) { |
||||
|
return false; |
||||
|
} |
||||
|
List<ClassicPaperSetEntity> entities = classicPaperSetMapper.selectBatchIdsIncludeDeleted(idList); |
||||
|
if (CollectionUtils.isEmpty(entities)) { |
||||
|
return false; |
||||
|
} |
||||
|
operationLogDTO.setAction(idList.size() == 1 ? "删除" : "批量删除"); |
||||
|
String description = entities.stream() |
||||
|
.map(e -> "【" + Optional.ofNullable(e.getName()).orElse("未知文件") + "】") |
||||
|
.collect(Collectors.joining(",")); |
||||
|
operationLogDTO.setDescription(description); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getStrategyName() { |
||||
|
return ModuleEnum.CLASSIC_PAPER.name(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue