feat(dict): 添加字典明细分页查询功能

This commit is contained in:
2025-12-29 17:18:02 +08:00
parent 4097e1801f
commit 866e689ad3
6 changed files with 136 additions and 142 deletions
@@ -16,8 +16,12 @@
package cn.odboy.system.dal.mysql;
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
import cn.odboy.system.dal.model.SystemQueryDictDetailArgs;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 字典明细 Mapper
@@ -26,5 +30,5 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
IPage<SystemDictDetailTb> selectPageByArgs(Page<SystemDictDetailTb> page, @Param("args") SystemQueryDictDetailArgs args);
}
@@ -41,8 +41,11 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemDictDetailService {
@Autowired private SystemDictDetailMapper systemDictDetailMapper;
@Autowired private SystemDictMapper systemDictMapper;
@Autowired
private SystemDictDetailMapper systemDictDetailMapper;
@Autowired
private SystemDictMapper systemDictMapper;
/**
* 创建
@@ -93,12 +96,6 @@ public class SystemDictDetailService {
return systemDictDetailMapper.selectList(wrapper);
}
private IPage<SystemDictDetailTb> searchDictDetailByArgs(List<Long> dictIds, Page<SystemDictDetailTb> page) {
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CollUtil.isNotEmpty(dictIds), SystemDictDetailTb::getDictId, dictIds);
return systemDictDetailMapper.selectPage(page, wrapper);
}
/**
* 分页查询
*
@@ -108,30 +105,9 @@ public class SystemDictDetailService {
*/
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args,
Page<SystemDictDetailTb> page) {
IPage<SystemDictDetailVo> iPage = new Page<>();
List<Long> dictIds = new ArrayList<>();
List<SystemDictTb> dictTbs = new ArrayList<>();
if (args == null) {
dictTbs.addAll(systemDictMapper.listAll());
dictIds = dictTbs.stream().map(SystemDictTb::getId).collect(Collectors.toList());
} else {
String dictName = args.getDictName();
if (StrUtil.isBlank(dictName)) {
return KitPageUtil.toPage(iPage);
}
SystemDictTb dictTb = systemDictMapper.getByName(dictName);
if (dictTb == null) {
return KitPageUtil.toPage(iPage);
} else {
dictIds.add(dictTb.getId());
dictTbs.add(dictTb);
}
}
Map<Long, SystemDictTb> id2ItemMap = dictTbs.stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
iPage = this.searchDictDetailByArgs(dictIds, page)
.convert(i -> BeanUtil.copyProperties(i, SystemDictDetailVo.class));
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> BeanUtil.copyProperties(i, SystemDictDetailVo.class));
List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList());
Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
for (SystemDictDetailVo record : iPage.getRecords()) {
record.setDict(id2ItemMap.get(record.getDictId()));
}
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.odboy.system.dal.mysql.SystemDictDetailMapper">
<select id="selectPageByArgs" resultType="cn.odboy.system.dal.dataobject.SystemDictDetailTb">
SELECT
t1.*
FROM system_dict_detail t1 LEFT JOIN system_dict t2 ON t1.dict_id = t2.id
<where>
<if test="args.dictName != null and args.dictName != ''">
AND t2.name = #{args.dictName}
</if>
<if test="args.label != null and args.label != ''">
AND t1.label = #{args.label}
</if>
</where>
ORDER BY t1.dict_sort
</select>
</mapper>
@@ -16,8 +16,12 @@
package cn.odboy.system.dal.mysql;
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
import cn.odboy.system.dal.model.SystemQueryDictDetailArgs;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 字典明细 Mapper
@@ -26,5 +30,5 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
IPage<SystemDictDetailTb> selectPageByArgs(Page<SystemDictDetailTb> page, @Param("args") SystemQueryDictDetailArgs args);
}
@@ -41,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemDictDetailService {
@Autowired
private SystemDictDetailMapper systemDictDetailMapper;
@Autowired
@@ -95,12 +96,6 @@ public class SystemDictDetailService {
return systemDictDetailMapper.selectList(wrapper);
}
private IPage<SystemDictDetailTb> searchDictDetailByArgs(List<Long> dictIds, Page<SystemDictDetailTb> page) {
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CollUtil.isNotEmpty(dictIds), SystemDictDetailTb::getDictId, dictIds);
return systemDictDetailMapper.selectPage(page, wrapper);
}
/**
* 分页查询
*
@@ -110,30 +105,9 @@ public class SystemDictDetailService {
*/
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args,
Page<SystemDictDetailTb> page) {
IPage<SystemDictDetailVo> iPage = new Page<>();
List<Long> dictIds = new ArrayList<>();
List<SystemDictTb> dictTbs = new ArrayList<>();
if (args == null) {
dictTbs.addAll(systemDictMapper.listAll());
dictIds = dictTbs.stream().map(SystemDictTb::getId).collect(Collectors.toList());
} else {
String dictName = args.getDictName();
if (StrUtil.isBlank(dictName)) {
return KitPageUtil.toPage(iPage);
}
SystemDictTb dictTb = systemDictMapper.getByName(dictName);
if (dictTb == null) {
return KitPageUtil.toPage(iPage);
} else {
dictIds.add(dictTb.getId());
dictTbs.add(dictTb);
}
}
Map<Long, SystemDictTb> id2ItemMap = dictTbs.stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
iPage = this.searchDictDetailByArgs(dictIds, page)
.convert(i -> BeanUtil.copyProperties(i, SystemDictDetailVo.class));
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> BeanUtil.copyProperties(i, SystemDictDetailVo.class));
List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList());
Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
for (SystemDictDetailVo record : iPage.getRecords()) {
record.setDict(id2ItemMap.get(record.getDictId()));
}
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.odboy.system.dal.mysql.SystemDictDetailMapper">
<select id="selectPageByArgs" resultType="cn.odboy.system.dal.dataobject.SystemDictDetailTb">
SELECT
t1.*
FROM system_dict_detail t1 LEFT JOIN system_dict t2 ON t1.dict_id = t2.id
<where>
<if test="args.dictName != null and args.dictName != ''">
AND t2.name = #{args.dictName}
</if>
<if test="args.label != null and args.label != ''">
AND t1.label = #{args.label}
</if>
</where>
ORDER BY t1.dict_sort
</select>
</mapper>