修复子库管理分页查询bug

修复子库管理新增重复bug
release_1.0.0
xueqingkun 8 months ago
parent 33b5d518a9
commit 7b9d194a5b

@ -33,8 +33,10 @@ public class ApplicationSubLibraryServiceImpl implements ApplicationSubLibrarySe
Assert.notEmpty(subLibraryReqVo.getBaseName(), "子库名称不能为空");
Assert.notEmpty(subLibraryReqVo.getDeptIds(), "关联部门不能为空");
Long count = systemBaseService.lambdaQuery().eq(SystemBase::getBaseCode, subLibraryReqVo.getBaseCode()).count();
Assert.isTrue(count == 0, "子库编码已存在");
Long count = systemBaseService.lambdaQuery().eq(SystemBase::getBaseCode, subLibraryReqVo.getBaseCode())
.or(query -> query.eq(SystemBase::getBaseName, subLibraryReqVo.getBaseName())).count();
Assert.isTrue(count == 0, "子库编码活子库名称已存在");
// 保存应用子库信息
SystemBase systemBase = new SystemBase();

@ -24,6 +24,10 @@
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>${mybatis-puls-spring-boot.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

@ -1,27 +1,67 @@
package com.supervision.knowsub.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.knowsub.model.SystemBase;
import com.supervision.knowsub.model.SystemBaseDeptRelation;
import com.supervision.knowsub.service.SystemBaseDeptRelationService;
import com.supervision.knowsub.service.SystemBaseService;
import com.supervision.knowsub.mapper.SystemBaseMapper;
import com.supervision.knowsub.vo.sublibrary.DeptInfo;
import com.supervision.knowsub.vo.sublibrary.SubLibraryReqVo;
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Administrator
* @description ks_system_base()Service
* @createDate 2024-06-24 11:35:15
*/
@Service
@RequiredArgsConstructor
public class SystemBaseServiceImpl extends ServiceImpl<SystemBaseMapper, SystemBase>
implements SystemBaseService{
private final SystemBaseDeptRelationService systemBaseDeptRelationService;
@Override
public IPage<SubLibraryResVo> listSubLibrary(SubLibraryReqVo subLibraryReqVo, Integer pageNum, Integer pageSize) {
return super.getBaseMapper().listSubLibrary(subLibraryReqVo,new Page<>(pageNum,pageSize));
Page<SystemBase> page = super.lambdaQuery().eq(StrUtil.isNotEmpty(subLibraryReqVo.getBaseCode()), SystemBase::getBaseCode, subLibraryReqVo.getBaseCode())
.like(StrUtil.isNotEmpty(subLibraryReqVo.getBaseName()), SystemBase::getBaseName, subLibraryReqVo.getBaseName())
.page(new Page<>(pageNum, pageSize));
if (CollUtil.isEmpty(page.getRecords())){
return page.convert(systemBase -> BeanUtil.toBean(systemBase, SubLibraryResVo.class));
}
// 关联部门信息
List<String> systemBaseIds = page.getRecords().stream().map(SystemBase::getId).toList();
List<SystemBaseDeptRelation> relationList = systemBaseDeptRelationService.lambdaQuery().in(SystemBaseDeptRelation::getBaseId, systemBaseIds).list();
// 聚合部门信息方便添加到SubLibraryResVo信息中
Map<String, List<DeptInfo>> deptIdMapDeptInfo = relationList.stream().collect(
Collectors.groupingBy(SystemBaseDeptRelation::getBaseId, Collectors.mapping(relation -> {
DeptInfo deptInfo = new DeptInfo();
deptInfo.setDeptId(relation.getDeptId());
return deptInfo;
}, Collectors.toList())));
// 封装返回
return page.convert(systemBase -> {
SubLibraryResVo subLibraryResVo = BeanUtil.toBean(systemBase, SubLibraryResVo.class);
subLibraryResVo.setDeptInfoList(deptIdMapDeptInfo.get(systemBase.getId()));
return subLibraryResVo;
});
}
}

Loading…
Cancel
Save