|
|
@ -1,23 +1,42 @@ |
|
|
package com.project.operation.domain.service.impl; |
|
|
package com.project.operation.domain.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.DesensitizedUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.base.domain.result.Result; |
|
|
|
|
|
import com.project.base.domain.utils.PageConverter; |
|
|
|
|
|
import com.project.ding.application.DepartmentApplicationService; |
|
|
|
|
|
import com.project.ding.application.UserApplicationService; |
|
|
|
|
|
import com.project.ding.domain.dto.DepartmentDTO; |
|
|
|
|
|
import com.project.ding.domain.dto.UserDTO; |
|
|
|
|
|
import com.project.ding.domain.service.DepartmentBaseService; |
|
|
import com.project.operation.domain.dto.OperationLogDTO; |
|
|
import com.project.operation.domain.dto.OperationLogDTO; |
|
|
import com.project.operation.domain.entity.OperationLogEntity; |
|
|
import com.project.operation.domain.entity.OperationLogEntity; |
|
|
import com.project.operation.domain.param.OperationLogParam; |
|
|
import com.project.operation.domain.param.OperationLogParam; |
|
|
import com.project.operation.domain.service.OperationLogBaseService; |
|
|
import com.project.operation.domain.service.OperationLogBaseService; |
|
|
import com.project.operation.domain.service.SearchOperationLogDomainService; |
|
|
import com.project.operation.domain.service.SearchOperationLogDomainService; |
|
|
|
|
|
import com.project.task.domain.entity.TaskEntity; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.Set; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class SearchOperationLogDomainServiceImpl implements SearchOperationLogDomainService { |
|
|
public class SearchOperationLogDomainServiceImpl implements SearchOperationLogDomainService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private OperationLogBaseService operationLogBaseService; |
|
|
private OperationLogBaseService operationLogBaseService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DepartmentApplicationService departmentApplicationService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private UserApplicationService userApplicationService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询日志 |
|
|
* 查询日志 |
|
|
@ -38,10 +57,72 @@ public class SearchOperationLogDomainServiceImpl implements SearchOperationLogDo |
|
|
if (param.getEndTime() != null) { |
|
|
if (param.getEndTime() != null) { |
|
|
logQueryWrapper.le("create_time",param.getEndTime()); |
|
|
logQueryWrapper.le("create_time",param.getEndTime()); |
|
|
} |
|
|
} |
|
|
|
|
|
//只查执行成功的日志
|
|
|
|
|
|
logQueryWrapper.eq("result",0); |
|
|
logQueryWrapper.orderByDesc("create_time"); |
|
|
logQueryWrapper.orderByDesc("create_time"); |
|
|
List<OperationLogEntity> entityList = operationLogBaseService.list(logQueryWrapper); |
|
|
Page<OperationLogEntity> page = new Page<>(param.getCurrent(), param.getSize()); |
|
|
|
|
|
List<OperationLogEntity> entityList = operationLogBaseService.page(page,logQueryWrapper).getRecords(); |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(entityList)){ |
|
|
|
|
|
return Result.success(Lists.newArrayList()); |
|
|
|
|
|
} |
|
|
|
|
|
//收集用户ID,冗余字段
|
|
|
|
|
|
Set<Long> idSet = entityList.stream().filter(entity -> entity.getId() != null) |
|
|
|
|
|
.map(OperationLogEntity::getCreatorId).collect(Collectors.toSet()); |
|
|
|
|
|
List<UserDTO> userDTOList = userApplicationService.searchByIds(idSet); |
|
|
|
|
|
Map<String, UserDTO> userDTOMap = userDTOList |
|
|
|
|
|
.stream().collect(Collectors.toMap(userDTO -> userDTO.getId(), userDTO -> userDTO)); |
|
|
|
|
|
|
|
|
|
|
|
//收集部门ID,冗余字段
|
|
|
|
|
|
Set<String> deptIdSet = userDTOList.stream() |
|
|
|
|
|
.filter(userDTO -> StringUtils.isNotBlank(userDTO.getDeptIdStr())) |
|
|
|
|
|
.flatMap(userDTO -> |
|
|
|
|
|
List.of(userDTO.getDeptIdStr().split(",")).stream().filter(StringUtils::isNoneBlank) |
|
|
|
|
|
).collect(Collectors.toSet()); |
|
|
|
|
|
Map<Long, DepartmentDTO> departmentDTOMap = departmentApplicationService.searchByIds(deptIdSet) |
|
|
|
|
|
.stream().collect(Collectors.toMap(departmentDTO -> departmentDTO.getId(), departmentDTO -> departmentDTO)); |
|
|
|
|
|
|
|
|
return Result.success(entityList.stream() |
|
|
return Result.success(entityList.stream() |
|
|
.map(entity -> entity.toDTO(OperationLogDTO::new)) |
|
|
.map(entity -> buildDTO(entity,userDTOMap,departmentDTOMap)) |
|
|
.collect(Collectors.toList())); |
|
|
.collect(Collectors.toList())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 构建日志DTO |
|
|
|
|
|
*/ |
|
|
|
|
|
private OperationLogDTO buildDTO(OperationLogEntity operationLogEntity,Map<String, UserDTO> userDTOMap,Map<Long, DepartmentDTO> departmentDTOMap){ |
|
|
|
|
|
OperationLogDTO operationLogDTO = operationLogEntity.toDTO(OperationLogDTO::new); |
|
|
|
|
|
if (!userDTOMap.containsKey(operationLogEntity.getCreatorId().toString())){ |
|
|
|
|
|
return operationLogDTO; |
|
|
|
|
|
} |
|
|
|
|
|
UserDTO userDTO = userDTOMap.get(operationLogEntity.getCreatorId().toString()); |
|
|
|
|
|
operationLogDTO.setUsername(DesensitizedUtil.chineseName(userDTO.getName())); |
|
|
|
|
|
operationLogDTO.setPosition(userDTO.getTitle()); |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(userDTO.getDeptIdStr())) { |
|
|
|
|
|
return operationLogDTO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拆分部门ID → 过滤有效ID → 转换为Long → 匹配部门名称 → 拼接
|
|
|
|
|
|
String deptName = List.of(userDTO.getDeptIdStr().split(",")) |
|
|
|
|
|
.stream() |
|
|
|
|
|
.filter(StringUtils::isNotBlank) |
|
|
|
|
|
.map(idStr -> { |
|
|
|
|
|
try { |
|
|
|
|
|
return Long.valueOf(idStr.trim()); |
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
|
.filter(departmentDTOMap::containsKey) |
|
|
|
|
|
.map(departmentDTOMap::get) |
|
|
|
|
|
.map(DepartmentDTO::getName) |
|
|
|
|
|
.collect(Collectors.joining(",")); |
|
|
|
|
|
|
|
|
|
|
|
operationLogDTO.setDepartment(deptName); |
|
|
|
|
|
|
|
|
|
|
|
return operationLogDTO; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|