feat(dict): 添加字典明细分页查询功能
This commit is contained in:
+5
-1
@@ -16,8 +16,12 @@
|
|||||||
package cn.odboy.system.dal.mysql;
|
package cn.odboy.system.dal.mysql;
|
||||||
|
|
||||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
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.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.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典明细 Mapper
|
* 字典明细 Mapper
|
||||||
@@ -26,5 +30,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
|
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
|
@Service
|
||||||
public class SystemDictDetailService {
|
public class SystemDictDetailService {
|
||||||
@Autowired private SystemDictDetailMapper systemDictDetailMapper;
|
|
||||||
@Autowired private SystemDictMapper systemDictMapper;
|
|
||||||
|
|
||||||
/**
|
@Autowired
|
||||||
* 创建
|
private SystemDictDetailMapper systemDictDetailMapper;
|
||||||
*
|
@Autowired
|
||||||
* @param args /
|
private SystemDictMapper systemDictMapper;
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
/**
|
||||||
public void saveDictDetail(SystemCreateDictDetailArgs args) {
|
* 创建
|
||||||
SystemDictDetailTb dictDetail = BeanUtil.copyProperties(args, SystemDictDetailTb.class);
|
*
|
||||||
dictDetail.setDictId(args.getDict().getId());
|
* @param args /
|
||||||
systemDictDetailMapper.insert(dictDetail);
|
*/
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private List<SystemDictDetailTb> listDictDetailByDictId(Long dictId) {
|
||||||
* 编辑
|
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||||
*
|
wrapper.eq(SystemDictDetailTb::getDictId, dictId);
|
||||||
* @param args /
|
return systemDictDetailMapper.selectList(wrapper);
|
||||||
*/
|
}
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void updateDictDetailById(SystemDictDetailTb args) {
|
/**
|
||||||
SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(args.getId());
|
* 分页查询
|
||||||
args.setId(dictDetail.getId());
|
*
|
||||||
systemDictDetailMapper.insertOrUpdate(args);
|
* @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 /
|
* @param name 字典名称
|
||||||
*/
|
* @return /
|
||||||
@Transactional(rollbackFor = Exception.class)
|
*/
|
||||||
public void deleteDictDetailById(Long id) {
|
public List<SystemDictDetailVo> listDictDetailByName(String name) {
|
||||||
systemDictDetailMapper.deleteById(id);
|
if (StrUtil.isBlank(name)) {
|
||||||
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
SystemDictTb systemDictTb = systemDictMapper.getByName(name);
|
||||||
@Transactional(rollbackFor = Exception.class)
|
if (systemDictTb == null) {
|
||||||
public void deleteDictDetailByDictIds(Set<Long> ids) {
|
return new ArrayList<>();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
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>
|
||||||
+5
-1
@@ -16,8 +16,12 @@
|
|||||||
package cn.odboy.system.dal.mysql;
|
package cn.odboy.system.dal.mysql;
|
||||||
|
|
||||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
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.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.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典明细 Mapper
|
* 字典明细 Mapper
|
||||||
@@ -26,5 +30,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
|
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
|
||||||
|
IPage<SystemDictDetailTb> selectPageByArgs(Page<SystemDictDetailTb> page, @Param("args") SystemQueryDictDetailArgs args);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-30
@@ -41,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SystemDictDetailService {
|
public class SystemDictDetailService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemDictDetailMapper systemDictDetailMapper;
|
private SystemDictDetailMapper systemDictDetailMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -95,12 +96,6 @@ public class SystemDictDetailService {
|
|||||||
return systemDictDetailMapper.selectList(wrapper);
|
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,
|
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args,
|
||||||
Page<SystemDictDetailTb> page) {
|
Page<SystemDictDetailTb> page) {
|
||||||
IPage<SystemDictDetailVo> iPage = new Page<>();
|
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> BeanUtil.copyProperties(i, SystemDictDetailVo.class));
|
||||||
List<Long> dictIds = new ArrayList<>();
|
List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList());
|
||||||
List<SystemDictTb> dictTbs = new ArrayList<>();
|
Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
|
||||||
|
|
||||||
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()) {
|
for (SystemDictDetailVo record : iPage.getRecords()) {
|
||||||
record.setDict(id2ItemMap.get(record.getDictId()));
|
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>
|
||||||
Reference in New Issue
Block a user