mirror of
https://github.com/BgaSol/sol-cloud
synced 2026-04-21 17:17:16 +00:00
refactor: harden findOtherTable relation hydration across services
This commit is contained in:
parent
5f0816cdd5
commit
358c815b59
12 changed files with 170 additions and 93 deletions
|
|
@ -1,40 +0,0 @@
|
|||
package com.bgasol.common.core.base.service;
|
||||
|
||||
import com.bgasol.common.core.base.mapper.MyBaseMapper;
|
||||
import com.bgasol.common.core.base.mapper.PoiExportHistoryMapper;
|
||||
import com.bgasol.common.core.base.dto.PoiExportHistoryPageDto;
|
||||
import com.bgasol.common.core.base.entity.PoiExportHistoryEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class PoiExportHistoryService extends BaseService<PoiExportHistoryEntity, PoiExportHistoryPageDto> {
|
||||
|
||||
private final PoiExportHistoryMapper poiExportHistoryMapper;
|
||||
|
||||
@Override
|
||||
public MyBaseMapper<PoiExportHistoryEntity> commonBaseMapper() {
|
||||
return poiExportHistoryMapper;
|
||||
}
|
||||
|
||||
public void markFailed(String recordId, String errorMessage) {
|
||||
PoiExportHistoryEntity poiExportHistoryEntity = PoiExportHistoryEntity.builder()
|
||||
.id(recordId)
|
||||
.status(3)
|
||||
.errorMessage(errorMessage)
|
||||
.build();
|
||||
poiExportHistoryMapper.updateById(poiExportHistoryEntity);
|
||||
}
|
||||
|
||||
public void markSuccess(String recordId, String fileId) {
|
||||
PoiExportHistoryEntity poiExportHistoryEntity = PoiExportHistoryEntity.builder()
|
||||
.id(recordId)
|
||||
.status(2)
|
||||
.fileId(fileId)
|
||||
.build();
|
||||
poiExportHistoryMapper.updateById(poiExportHistoryEntity);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,15 +48,16 @@ public class MessageEnvelopeService extends BaseService<MessageEnvelopeEntity<?>
|
|||
.filter(ObjectUtils::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
if (ObjectUtils.isNotEmpty(userIds)) {
|
||||
Map<String, UserEntity> userEntityMap = userApi.findByIds(userIds, true)
|
||||
.getData()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserEntity::getId, Function.identity()));
|
||||
list.forEach(e -> {
|
||||
if (ObjectUtils.isNotEmpty(e.getUserId())) {
|
||||
e.setUser(userEntityMap.get(e.getUserId()));
|
||||
}
|
||||
});
|
||||
List<UserEntity> userEntityList = userApi.findByIds(userIds, true).getData();
|
||||
if (ObjectUtils.isNotEmpty(userEntityList)) {
|
||||
Map<String, UserEntity> userEntityMap = userEntityList.stream()
|
||||
.collect(Collectors.toMap(UserEntity::getId, Function.identity()));
|
||||
list.forEach(e -> {
|
||||
if (ObjectUtils.isNotEmpty(e.getUserId())) {
|
||||
e.setUser(userEntityMap.get(e.getUserId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
super.findOtherTable(list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.bgasol.common.poiHistory.service;
|
||||
|
||||
import com.bgasol.common.core.base.mapper.MyBaseMapper;
|
||||
import com.bgasol.common.core.base.service.BaseService;
|
||||
import com.bgasol.common.poiHistory.mapper.PoiExportHistoryMapper;
|
||||
import com.bgasol.model.system.department.api.DepartmentApi;
|
||||
import com.bgasol.model.system.department.entity.DepartmentEntity;
|
||||
import com.bgasol.model.system.poiHistory.dto.PoiExportHistoryPageDto;
|
||||
import com.bgasol.model.system.poiHistory.entity.PoiExportHistoryEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class PoiExportHistoryService extends BaseService<PoiExportHistoryEntity, PoiExportHistoryPageDto> {
|
||||
|
||||
private final PoiExportHistoryMapper poiExportHistoryMapper;
|
||||
private final DepartmentApi departmentApi;
|
||||
|
||||
@Override
|
||||
public MyBaseMapper<PoiExportHistoryEntity> commonBaseMapper() {
|
||||
return poiExportHistoryMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void findOtherTable(List<PoiExportHistoryEntity> list) {
|
||||
Set<String> departmentIds = list.stream()
|
||||
.map(PoiExportHistoryEntity::getDepartmentId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (ObjectUtils.isNotEmpty(departmentIds)) {
|
||||
List<DepartmentEntity> departmentEntityList = departmentApi.findByIds(departmentIds, true).getData();
|
||||
if (ObjectUtils.isNotEmpty(departmentEntityList)) {
|
||||
Map<String, DepartmentEntity> departmentEntityMap = departmentEntityList.stream()
|
||||
.collect(Collectors.toMap(DepartmentEntity::getId, Function.identity()));
|
||||
|
||||
list.forEach(entity -> {
|
||||
if (ObjectUtils.isNotEmpty(entity.getDepartmentId())) {
|
||||
entity.setDepartment(departmentEntityMap.get(entity.getDepartmentId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
super.findOtherTable(list);
|
||||
}
|
||||
|
||||
public void markFailed(String recordId, String errorMessage) {
|
||||
PoiExportHistoryEntity poiExportHistoryEntity = PoiExportHistoryEntity.builder()
|
||||
.id(recordId)
|
||||
.status(3)
|
||||
.errorMessage(errorMessage)
|
||||
.build();
|
||||
poiExportHistoryMapper.updateById(poiExportHistoryEntity);
|
||||
}
|
||||
|
||||
public void markSuccess(String recordId, String fileId) {
|
||||
PoiExportHistoryEntity poiExportHistoryEntity = PoiExportHistoryEntity.builder()
|
||||
.id(recordId)
|
||||
.status(2)
|
||||
.fileId(fileId)
|
||||
.build();
|
||||
poiExportHistoryMapper.updateById(poiExportHistoryEntity);
|
||||
}
|
||||
}
|
||||
|
|
@ -45,15 +45,19 @@ public class RequestLogService extends BaseTreeService<RequestLogEntity, Request
|
|||
.collect(Collectors.toSet());
|
||||
|
||||
if (ObjectUtils.isNotEmpty(userIds)) {
|
||||
Map<String, UserEntity> userEntityMap = userApi.findByIds(userIds, true).getData().stream().collect(Collectors.toMap(UserEntity::getId, Function.identity()));
|
||||
List<UserEntity> userEntityList = userApi.findByIds(userIds, true).getData();
|
||||
if (ObjectUtils.isNotEmpty(userEntityList)) {
|
||||
Map<String, UserEntity> userEntityMap = userEntityList.stream()
|
||||
.collect(Collectors.toMap(UserEntity::getId, Function.identity()));
|
||||
|
||||
list.forEach(requestLogEntity -> {
|
||||
if (ObjectUtils.isEmpty(requestLogEntity.getUserId())) {
|
||||
return;
|
||||
}
|
||||
UserEntity userEntity = userEntityMap.get(requestLogEntity.getUserId());
|
||||
requestLogEntity.setUser(userEntity);
|
||||
});
|
||||
list.forEach(requestLogEntity -> {
|
||||
if (ObjectUtils.isEmpty(requestLogEntity.getUserId())) {
|
||||
return;
|
||||
}
|
||||
UserEntity userEntity = userEntityMap.get(requestLogEntity.getUserId());
|
||||
requestLogEntity.setUser(userEntity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,14 +86,21 @@ public class ImageService extends BaseService<ImageEntity, ImagePageDto> {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void findOtherTable(List<ImageEntity> list) {
|
||||
if (ObjectUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> fileIds = list
|
||||
.stream()
|
||||
.map(ImageEntity::getFileId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Map<String, FileEntity> fileMap = fileService
|
||||
.findById(fileIds, true)
|
||||
if (ObjectUtils.isNotEmpty(fileIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, FileEntity> fileMap = fileService.findById(fileIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(FileEntity::getId, Function.identity()));
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,21 @@ public class VideoService extends BaseService<VideoEntity, VideoPageDto> {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void findOtherTable(List<VideoEntity> list) {
|
||||
if (ObjectUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> fileIds = list
|
||||
.stream()
|
||||
.map(VideoEntity::getFileId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Map<String, FileEntity> fileMap = fileService
|
||||
.findById(fileIds, true)
|
||||
if (ObjectUtils.isEmpty(fileIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, FileEntity> fileMap = fileService.findById(fileIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(FileEntity::getId, Function.identity()));
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,18 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
|
|||
import com.bgasol.common.core.base.controller.BaseController;
|
||||
import com.bgasol.common.core.base.dto.BaseCreateDto;
|
||||
import com.bgasol.common.core.base.dto.BaseUpdateDto;
|
||||
import com.bgasol.common.core.base.service.PoiExportHistoryService;
|
||||
import com.bgasol.common.core.base.vo.BaseVo;
|
||||
import com.bgasol.common.core.base.vo.PageVo;
|
||||
import com.bgasol.common.core.base.dto.PoiExportHistoryPageDto;
|
||||
import com.bgasol.common.core.base.entity.PoiExportHistoryEntity;
|
||||
import com.bgasol.web.file.file.service.FileService;
|
||||
import com.bgasol.common.poiHistory.service.PoiExportHistoryService;
|
||||
import com.bgasol.model.system.poiHistory.dto.PoiExportHistoryPageDto;
|
||||
import com.bgasol.model.system.poiHistory.entity.PoiExportHistoryEntity;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "POI导出记录管理")
|
||||
|
|
@ -38,11 +35,9 @@ public class PoiExportHistoryController extends BaseController<
|
|||
|
||||
@Override
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "分页查询POI导出记录", operationId = "findPagePoiExportHistory")
|
||||
@SaCheckPermission(value = "poiExportHistory:findByPage")
|
||||
public BaseVo<PageVo<PoiExportHistoryEntity>> findByPage(@RequestBody @Valid PoiExportHistoryPageDto pageDto) {
|
||||
return super.findByPage(pageDto);
|
||||
@Operation(summary = "分页查询POI导出记录", operationId = "findByPagePoiExportHistoryController")
|
||||
@SaCheckPermission(value = "PoiExportHistoryController:findByPage")
|
||||
public BaseVo<PageVo<PoiExportHistoryEntity>> findByPage(@RequestBody PoiExportHistoryPageDto pageDto, @PathVariable Boolean otherData) {
|
||||
return super.findByPage(pageDto, otherData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -11,10 +11,8 @@ import com.bgasol.model.system.role.entity.RolePermissionTable;
|
|||
import com.bgasol.web.system.menu.service.MenuService;
|
||||
import com.bgasol.web.system.permission.service.PermissionService;
|
||||
import com.bgasol.web.system.role.mapper.RoleMapper;
|
||||
import com.bgasol.web.system.user.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -44,11 +42,19 @@ public class RoleService extends BaseService<RoleEntity, BasePageDto<RoleEntity>
|
|||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public void findOtherTable(List<RoleEntity> list) {
|
||||
if (ObjectUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> roleIds = list.stream()
|
||||
.map(RoleEntity::getId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (ObjectUtils.isEmpty(roleIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, List<String>> menuIdGroup = this.findFromTableBatch(
|
||||
RoleMenuTable.NAME, RoleMenuTable.ROLE_ID, roleIds, RoleMenuTable.MENU_ID
|
||||
);
|
||||
|
|
@ -67,14 +73,17 @@ public class RoleService extends BaseService<RoleEntity, BasePageDto<RoleEntity>
|
|||
.flatMap(List::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Map<String, MenuEntity> menuMap = menuService
|
||||
.findById(allMenuIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(MenuEntity::getId, Function.identity()));
|
||||
Map<String, PermissionEntity> permissionMap = permissionService
|
||||
.findById(allPermissionIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(PermissionEntity::getId, Function.identity()));
|
||||
final Map<String, MenuEntity> menuMap = ObjectUtils.isNotEmpty(allMenuIds)
|
||||
? menuService.findById(allMenuIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(MenuEntity::getId, Function.identity()))
|
||||
: Map.of();
|
||||
|
||||
final Map<String, PermissionEntity> permissionMap = ObjectUtils.isNotEmpty(allPermissionIds)
|
||||
? permissionService.findById(allPermissionIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(PermissionEntity::getId, Function.identity()))
|
||||
: Map.of();
|
||||
|
||||
list.forEach(roleEntity -> {
|
||||
roleEntity.setMenus(menuIdGroup
|
||||
|
|
|
|||
|
|
@ -103,10 +103,19 @@ public class UserService extends BaseService<UserEntity, UserPageDto> {
|
|||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public void findOtherTable(List<UserEntity> list) {
|
||||
if (ObjectUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> userIds = list.stream()
|
||||
.map(UserEntity::getId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (ObjectUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, List<String>> roleIdGroup = this.findFromTableBatch(
|
||||
UserRoleTable.NAME, UserRoleTable.USER_ID, userIds, UserRoleTable.ROLE_ID);
|
||||
|
||||
|
|
@ -116,24 +125,32 @@ public class UserService extends BaseService<UserEntity, UserPageDto> {
|
|||
.flatMap(List::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Map<String, RoleEntity> roleMap = roleService
|
||||
.findById(roleIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(RoleEntity::getId, Function.identity()));
|
||||
final Map<String, RoleEntity> roleMap = ObjectUtils.isNotEmpty(roleIds)
|
||||
? roleService.findById(roleIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(RoleEntity::getId, Function.identity()))
|
||||
: Map.of();
|
||||
|
||||
Set<String> departmentIds = list.stream()
|
||||
.map(UserEntity::getDepartmentId)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final Map<String, DepartmentEntity> departmentMap = ObjectUtils.isNotEmpty(departmentIds)
|
||||
? departmentService.findById(departmentIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DepartmentEntity::getId, Function.identity()))
|
||||
: Map.of();
|
||||
|
||||
Set<String> departmentIds = list.stream().map(UserEntity::getDepartmentId).collect(Collectors.toSet());
|
||||
Map<String, DepartmentEntity> collect = departmentService
|
||||
.findById(departmentIds, true)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DepartmentEntity::getId, Function.identity()));
|
||||
for (UserEntity userEntity : list) {
|
||||
userEntity.setRoles(roleIdGroup
|
||||
.getOrDefault(userEntity.getId(), List.of())
|
||||
.stream()
|
||||
.map(roleMap::get)
|
||||
.filter(ObjectUtils::isNotEmpty)
|
||||
.toList());
|
||||
if (ObjectUtils.isNotEmpty(userEntity.getDepartmentId())) {
|
||||
userEntity.setDepartment(collect.get(userEntity.getDepartmentId()));
|
||||
userEntity.setDepartment(departmentMap.get(userEntity.getDepartmentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue