feat(dict): 添加字典明细分页查询功能
This commit is contained in:
+5
-1
@@ -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);
|
||||
}
|
||||
|
||||
+86
-110
@@ -41,121 +41,97 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class SystemDictDetailService {
|
||||
@Autowired private SystemDictDetailMapper systemDictDetailMapper;
|
||||
@Autowired private SystemDictMapper systemDictMapper;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param args /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDictDetail(SystemCreateDictDetailArgs args) {
|
||||
SystemDictDetailTb dictDetail = BeanUtil.copyProperties(args, SystemDictDetailTb.class);
|
||||
dictDetail.setDictId(args.getDict().getId());
|
||||
systemDictDetailMapper.insert(dictDetail);
|
||||
@Autowired
|
||||
private SystemDictDetailMapper systemDictDetailMapper;
|
||||
@Autowired
|
||||
private SystemDictMapper systemDictMapper;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param args /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDictDetail(SystemCreateDictDetailArgs args) {
|
||||
SystemDictDetailTb dictDetail = BeanUtil.copyProperties(args, SystemDictDetailTb.class);
|
||||
dictDetail.setDictId(args.getDict().getId());
|
||||
systemDictDetailMapper.insert(dictDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param args /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDictDetailById(SystemDictDetailTb args) {
|
||||
SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(args.getId());
|
||||
args.setId(dictDetail.getId());
|
||||
systemDictDetailMapper.insertOrUpdate(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailById(Long id) {
|
||||
systemDictDetailMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailByDictIds(Set<Long> ids) {
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(SystemDictDetailTb::getDictId, ids);
|
||||
systemDictDetailMapper.delete(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param args /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDictDetailById(SystemDictDetailTb args) {
|
||||
SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(args.getId());
|
||||
args.setId(dictDetail.getId());
|
||||
systemDictDetailMapper.insertOrUpdate(args);
|
||||
private List<SystemDictDetailTb> listDictDetailByDictId(Long dictId) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDictDetailTb::getDictId, dictId);
|
||||
return systemDictDetailMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param args 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args,
|
||||
Page<SystemDictDetailTb> page) {
|
||||
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()));
|
||||
}
|
||||
return KitPageUtil.toPage(iPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailById(Long id) {
|
||||
systemDictDetailMapper.deleteById(id);
|
||||
/**
|
||||
* 根据字典名称获取字典详情
|
||||
*
|
||||
* @param name 字典名称
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDictDetailVo> listDictDetailByName(String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailByDictIds(Set<Long> ids) {
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(SystemDictDetailTb::getDictId, ids);
|
||||
systemDictDetailMapper.delete(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private List<SystemDictDetailTb> listDictDetailByDictId(Long dictId) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDictDetailTb::getDictId, dictId);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param args 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
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));
|
||||
for (SystemDictDetailVo record : iPage.getRecords()) {
|
||||
record.setDict(id2ItemMap.get(record.getDictId()));
|
||||
}
|
||||
return KitPageUtil.toPage(iPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典名称获取字典详情
|
||||
*
|
||||
* @param name 字典名称
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDictDetailVo> listDictDetailByName(String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
SystemDictTb systemDictTb = systemDictMapper.getByName(name);
|
||||
if (systemDictTb == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return this.listDictDetailByDictId(systemDictTb.getId()).stream().map(m -> {
|
||||
SystemDictDetailVo detailVo = BeanUtil.copyProperties(m, SystemDictDetailVo.class);
|
||||
detailVo.setDict(systemDictTb);
|
||||
return detailVo;
|
||||
}).collect(Collectors.toList());
|
||||
SystemDictTb systemDictTb = systemDictMapper.getByName(name);
|
||||
if (systemDictTb == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return this.listDictDetailByDictId(systemDictTb.getId()).stream().map(m -> {
|
||||
SystemDictDetailVo detailVo = BeanUtil.copyProperties(m, SystemDictDetailVo.class);
|
||||
detailVo.setDict(systemDictTb);
|
||||
return detailVo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -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>
|
||||
Reference in New Issue
Block a user