refactor(system): 重构字典明细查询功能
- 创建 SystemDictDetailVo 视图对象用于数据传输 - 修改控制器返回类型为 SystemDictDetailVo - 重构查询方法使用 LambdaQueryWrapper 替代 XML 配置 - 移除 SystemDictDetailTb 中的 dict 关联字段 - 添加字典名称查询的辅助方法 - 更新前端组件移除搜索功能并简化工具栏
This commit is contained in:
-1
@@ -32,7 +32,6 @@ public class SystemDictDetailTb extends KitBaseUserTimeTb {
|
||||
@NotNull(groups = Update.class) @ApiModelProperty(value = "ID", hidden = true)
|
||||
@TableId(value = "id", type = IdType.AUTO) private Long id;
|
||||
@TableField(value = "dict_id") @ApiModelProperty(hidden = true) private Long dictId;
|
||||
@TableField(exist = false) @ApiModelProperty(value = "字典") private SystemDictTb dict;
|
||||
@ApiModelProperty(value = "字典标签") private String label;
|
||||
@ApiModelProperty(value = "字典值") private String value;
|
||||
@ApiModelProperty(value = "排序") private Integer dictSort = 999;
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.dal.model;
|
||||
|
||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictTb;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SystemDictDetailVo extends SystemDictDetailTb {
|
||||
@ApiModelProperty(value = "字典") private SystemDictTb dict;
|
||||
}
|
||||
+12
-4
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package cn.odboy.system.dal.mysql;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
||||
import cn.odboy.system.dal.model.SystemQueryDictDetailArgs;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 字典明细 Mapper
|
||||
@@ -31,6 +31,14 @@ import org.apache.ibatis.annotations.Param;
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemDictDetailMapper extends BaseMapper<SystemDictDetailTb> {
|
||||
IPage<SystemDictDetailTb> selectDictDetailByArgs(@Param("criteria") SystemQueryDictDetailArgs criteria, Page<SystemDictDetailTb> page);
|
||||
List<SystemDictDetailTb> selectDictDetailByArgs(@Param("criteria") SystemQueryDictDetailArgs criteria);
|
||||
default List<SystemDictDetailTb> selectByDictId(Long dictId) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDictDetailTb::getDictId, dictId);
|
||||
return selectList(wrapper);
|
||||
}
|
||||
default IPage<SystemDictDetailTb> selectDictDetailByArgs(List<Long> dictIds, Page<SystemDictDetailTb> page) {
|
||||
LambdaQueryWrapper<SystemDictDetailTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(CollUtil.isNotEmpty(dictIds), SystemDictDetailTb::getDictId, dictIds);
|
||||
return selectPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -47,4 +47,9 @@ public interface SystemDictMapper extends BaseMapper<SystemDictTb> {
|
||||
injectQueryParams(args, wrapper);
|
||||
return selectList(page, wrapper);
|
||||
}
|
||||
default SystemDictTb getByName(String name) {
|
||||
LambdaQueryWrapper<SystemDictTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDictTb::getName, name);
|
||||
return selectOne(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
+70
-23
@@ -17,16 +17,24 @@ package cn.odboy.system.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictTb;
|
||||
import cn.odboy.system.dal.model.SystemCreateDictDetailArgs;
|
||||
import cn.odboy.system.dal.model.SystemDictDetailVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryDictDetailArgs;
|
||||
import cn.odboy.system.dal.mysql.SystemDictDetailMapper;
|
||||
import cn.odboy.system.dal.mysql.SystemDictMapper;
|
||||
import cn.odboy.util.KitPageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -34,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class SystemDictDetailService {
|
||||
@Autowired private SystemDictDetailMapper systemDictDetailMapper;
|
||||
@Autowired private SystemDictMapper systemDictMapper;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
@@ -69,29 +78,6 @@ public class SystemDictDetailService {
|
||||
systemDictDetailMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param args 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemDictDetailTb> queryDictDetailByArgs(SystemQueryDictDetailArgs args, Page<SystemDictDetailTb> page) {
|
||||
return KitPageUtil.toPage(systemDictDetailMapper.selectDictDetailByArgs(args, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典名称获取字典详情
|
||||
*
|
||||
* @param name 字典名称
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDictDetailTb> queryDictDetailByName(String name) {
|
||||
SystemQueryDictDetailArgs args = new SystemQueryDictDetailArgs();
|
||||
args.setDictName(name);
|
||||
return systemDictDetailMapper.selectDictDetailByArgs(args);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailByDictIds(Set<Long> ids) {
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
@@ -100,4 +86,65 @@ public class SystemDictDetailService {
|
||||
systemDictDetailMapper.delete(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param args 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemDictDetailVo> queryDictDetailByArgs(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.selectList(null));
|
||||
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 = systemDictDetailMapper.selectDictDetailByArgs(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> queryDictDetailByName(String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
SystemDictTb systemDictTb = systemDictMapper.getByName(name);
|
||||
if (systemDictTb == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return systemDictDetailMapper.selectByDictId(systemDictTb.getId()).stream().map(m -> {
|
||||
SystemDictDetailVo detailVo = BeanUtil.copyProperties(m, SystemDictDetailVo.class);
|
||||
detailVo.setDict(systemDictTb);
|
||||
return detailVo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-6
@@ -21,9 +21,8 @@ import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictDetailTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemDictTb;
|
||||
import cn.odboy.system.dal.model.SystemCreateDictArgs;
|
||||
import cn.odboy.system.dal.model.SystemDictDetailVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryDictArgs;
|
||||
import cn.odboy.system.dal.model.SystemQueryDictDetailArgs;
|
||||
import cn.odboy.system.dal.mysql.SystemDictDetailMapper;
|
||||
import cn.odboy.system.dal.mysql.SystemDictMapper;
|
||||
import cn.odboy.util.KitFileUtil;
|
||||
import cn.odboy.util.KitPageUtil;
|
||||
@@ -42,7 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class SystemDictService {
|
||||
@Autowired private SystemDictMapper systemDictMapper;
|
||||
@Autowired private SystemDictDetailMapper systemDictDetailMapper;
|
||||
// @Autowired private SystemDictDetailMapper systemDictDetailMapper;
|
||||
@Autowired private SystemDictDetailService systemDictDetailService;
|
||||
|
||||
/**
|
||||
@@ -91,9 +90,7 @@ public class SystemDictService {
|
||||
public void exportDictExcel(List<SystemDictTb> dicts, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemDictTb dict : dicts) {
|
||||
SystemQueryDictDetailArgs args = new SystemQueryDictDetailArgs();
|
||||
args.setDictName(dict.getName());
|
||||
List<SystemDictDetailTb> dictDetails = systemDictDetailMapper.selectDictDetailByArgs(args);
|
||||
List<SystemDictDetailVo> dictDetails = systemDictDetailService.queryDictDetailByName(dict.getName());
|
||||
if (CollectionUtil.isNotEmpty(dictDetails)) {
|
||||
for (SystemDictDetailTb dictDetail : dictDetails) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
<?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">
|
||||
<resultMap id="BaseResultMap" type="cn.odboy.system.dal.dataobject.SystemDictDetailTb">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="label" property="label" jdbcType="VARCHAR"/>
|
||||
<result column="value" property="value" jdbcType="VARCHAR"/>
|
||||
<result column="dict_sort" property="dictSort" jdbcType="INTEGER"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<!-- 一对一关联 -->
|
||||
<association property="dict" javaType="cn.odboy.system.dal.dataobject.SystemDictTb">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
<select id="selectDictDetailByArgs" resultMap="BaseResultMap">
|
||||
select
|
||||
dd.id, dd.label, dd.`value`, dd.`dict_sort`, dd.create_by, dd.update_by, dd.create_time, dd.update_time,
|
||||
d.id as dict_id, d.name
|
||||
from system_dict_detail dd, system_dict d
|
||||
where dd.dict_id = d.id
|
||||
<if test="criteria.dictName != null and criteria.dictName != ''">
|
||||
and d.name = #{criteria.dictName}
|
||||
</if>
|
||||
<if test="criteria.label != null and criteria.label != ''">
|
||||
and dd.label = #{criteria.label}
|
||||
</if>
|
||||
order by dd.dict_sort
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user