15 changed files with 251 additions and 14 deletions
@ -0,0 +1,24 @@ |
|||||
|
package com.project.operation.domain.enums; |
||||
|
|
||||
|
import com.project.base.domain.enums.HasValueEnum; |
||||
|
import lombok.Getter; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
|
||||
|
@Getter |
||||
|
@RequiredArgsConstructor |
||||
|
public enum ModuleEnum implements HasValueEnum<String> { |
||||
|
EXAM_TASK("考试任务"), |
||||
|
DATA_MANAGEMENT("资料管理"), |
||||
|
APPEAL_APPROVAL("申诉审批"); |
||||
|
|
||||
|
private final String value; |
||||
|
|
||||
|
public static ModuleEnum findByValue(String value) { |
||||
|
for (ModuleEnum moduleEnum : ModuleEnum.values()) { |
||||
|
if (moduleEnum.getValue().equals(value)) { |
||||
|
return moduleEnum; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.project.operation.domain.service; |
||||
|
|
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
|
||||
|
/** |
||||
|
* 日志记录详细信息 |
||||
|
*/ |
||||
|
public interface DescriptionStrategy { |
||||
|
/** |
||||
|
* 获取并构建详细信息 |
||||
|
*/ |
||||
|
Boolean process(Object[] args, OperationLogDTO operationLogDTO,String methodName); |
||||
|
|
||||
|
/** |
||||
|
* 获取策略名称 |
||||
|
* @return 策略名称 |
||||
|
*/ |
||||
|
String getStrategyName(); |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
package com.project.operation.domain.service.impl.description; |
||||
|
|
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
import com.project.operation.domain.enums.ModuleEnum; |
||||
|
import com.project.operation.domain.service.DescriptionStrategy; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* 申诉审批 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class AppealDescriptionStrategy implements DescriptionStrategy { |
||||
|
@Override |
||||
|
public Boolean process(Object[] args, OperationLogDTO operationLogDTO,String methodName) { |
||||
|
|
||||
|
|
||||
|
if (methodName.equals("save")) { |
||||
|
|
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getStrategyName() { |
||||
|
return ModuleEnum.APPEAL_APPROVAL.name(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package com.project.operation.domain.service.impl.description; |
||||
|
|
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
import com.project.operation.domain.enums.ModuleEnum; |
||||
|
import com.project.operation.domain.service.DescriptionStrategy; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* 资料管理 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class DataDescriptionStrategy implements DescriptionStrategy { |
||||
|
@Override |
||||
|
public Boolean process(Object[] args, OperationLogDTO operationLogDTO,String methodName) { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getStrategyName() { |
||||
|
return ModuleEnum.DATA_MANAGEMENT.name(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
package com.project.operation.domain.service.impl.description; |
||||
|
|
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
import com.project.operation.domain.service.DescriptionStrategy; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||
|
import java.util.function.Function; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 日志记录详细信息策略管理器 |
||||
|
*/ |
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class DescriptionManager { |
||||
|
private Map<String, DescriptionStrategy> strategyMap = new ConcurrentHashMap<>(); |
||||
|
|
||||
|
@Autowired |
||||
|
public DescriptionManager(List<DescriptionStrategy> strategyList) { |
||||
|
this.strategyMap = strategyList.stream() |
||||
|
.collect(Collectors.toMap(DescriptionStrategy::getStrategyName, Function.identity())); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 指定使用的策略 |
||||
|
*/ |
||||
|
public Boolean process(String strategyName, Object[] args, OperationLogDTO operationLogDTO,String methodName) throws Exception { |
||||
|
DescriptionStrategy descriptionStrategy = strategyMap.get(strategyName); |
||||
|
if (descriptionStrategy == null) { |
||||
|
log.error("未找到构建日志详细信息的策略: {}", strategyName); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
log.info("使用构建日志详细信息策略: {}", strategyName); |
||||
|
return descriptionStrategy.process(args,operationLogDTO,methodName); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
package com.project.operation.domain.service.impl.description; |
||||
|
|
||||
|
import com.project.operation.domain.dto.OperationLogDTO; |
||||
|
import com.project.operation.domain.enums.ModuleEnum; |
||||
|
import com.project.operation.domain.service.DescriptionStrategy; |
||||
|
import com.project.task.application.TaskApplicationService; |
||||
|
import com.project.task.domain.dto.TaskDTO; |
||||
|
import org.apache.commons.lang3.ArrayUtils; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.lang.reflect.Array; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 考试任务 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class TaskDescriptionStrategy implements DescriptionStrategy { |
||||
|
@Autowired |
||||
|
private TaskApplicationService taskApplicationService; |
||||
|
|
||||
|
@Override |
||||
|
public Boolean process(Object[] args, OperationLogDTO operationLogDTO,String methodName) { |
||||
|
if (methodName.equals("save")) { |
||||
|
TaskDTO taskDTO = (TaskDTO) args[0]; |
||||
|
//设置操作
|
||||
|
if (taskDTO.getId() == null){ |
||||
|
operationLogDTO.setAction("创建"); |
||||
|
}else { |
||||
|
operationLogDTO.setAction("编辑"); |
||||
|
} |
||||
|
//构建操作详细信息
|
||||
|
if (StringUtils.isBlank(taskDTO.getName())){ |
||||
|
return false; |
||||
|
} |
||||
|
operationLogDTO.setDescription("【"+ taskDTO.getName() +"】"); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
if (methodName.equals("batchDelete")) { |
||||
|
String taskIds = (String) args[0]; |
||||
|
if (StringUtils.isBlank(taskIds)){ |
||||
|
return false; |
||||
|
} |
||||
|
List<Long> taskIdList = Arrays.asList(taskIds.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()); |
||||
|
List<TaskDTO> taskDTOList = taskApplicationService.selectBatchIds(taskIdList); |
||||
|
if (taskIdList.size() == 1){ |
||||
|
operationLogDTO.setAction("删除"); |
||||
|
}else{ |
||||
|
operationLogDTO.setAction("批量删除"); |
||||
|
} |
||||
|
operationLogDTO.setDescription(taskDTOList.stream().map(taskDTO -> "【"+ taskDTO.getName() +"】").collect(Collectors.joining(","))); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getStrategyName() { |
||||
|
return ModuleEnum.EXAM_TASK.name(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue