下拉选

This commit is contained in:
cwchen 2023-12-20 18:09:46 +08:00
parent 5ecdc9261a
commit c6875f0f8b
9 changed files with 403 additions and 7 deletions

View File

@ -32,4 +32,47 @@ public class SelectController {
public AjaxResult getProData(SelectDto dto) {
return service.getProData(dto);
}
@ApiOperation(value = "机具类型下拉选")
@PostMapping("getMaTypeData")
public AjaxResult getMaTypeData(SelectDto dto){
return service.getMaTypeData(dto);
}
@ApiOperation(value = "机具类型下拉树")
@PostMapping("getMaTypeTreeData")
public AjaxResult getMaTypeTreeData(SelectDto dto){
// return service.getMaTypeTreeData(dto);
return null;
}
@ApiOperation(value = "数据字典下拉选")
@PostMapping("getDictByPidCbx")
public AjaxResult getDictByPidCbx(SelectDto dto){
return service.getDictByPidCbx(dto);
}
@ApiOperation(value = "单位树/归属部门/所属上级")
@PostMapping("getDeptTree")
public AjaxResult getDeptTree(SelectDto dto){
return service.getDeptTree(dto);
}
@ApiOperation(value = "岗位下拉选")
@PostMapping("getPostCbx")
public AjaxResult getPostCbx(SelectDto dto){
return service.getPostCbx(dto);
}
@ApiOperation(value = "角色下拉选")
@PostMapping("getRoleCbx")
public AjaxResult getRoleCbx(SelectDto dto){
return service.getRoleCbx(dto);
}
@ApiOperation(value = "单位类型下拉选")
@PostMapping("getUnitTypeCbx")
public AjaxResult getUnitTypeCbx(SelectDto dto){
return service.getUnitTypeCbx(dto);
}
}

View File

@ -10,4 +10,13 @@ public class SelectDto {
/** 参数id*/
private String id;
/** 2.物品种类 3.设备类型 4.规格型号*/
private String type;
/** 字典表 父类值*/
private String parentValue;
/** 层级*/
private String level;
}

View File

@ -12,5 +12,5 @@ public class SelectVo {
private long id;
/** 名称*/
private String titleName;
private String name;
}

View File

@ -0,0 +1,24 @@
package com.bonus.sgzb.system.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author 10488
* 下拉树-实体类
*/
@Data
public class TreeNode {
private long id;
private String label;
private long parentId;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeNode> children = new ArrayList<>();
}

View File

@ -2,6 +2,7 @@ package com.bonus.sgzb.system.mapper;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.system.domain.SelectVo;
import com.bonus.sgzb.system.domain.TreeNode;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -29,4 +30,58 @@ public interface SelectMapper {
* @date 2023/12/20 15:05
*/
List<SelectVo> getProData(SelectDto dto);
/**
* @param dto
* @return List<SelectVo>
* @description 机具类型
* @author cwchen
* @date 2023/12/20 16:02
*/
List<SelectVo> getMaTypeData(SelectDto dto);
/**
* @param dto
* @return List<SelectVo>
* @description 数据字典下拉选
* @author cwchen
* @date 2023/12/20 16:23
*/
List<SelectVo> getDictByPidCbx(SelectDto dto);
/**
* @param dto
* @return List<TreeVo>
* @description 单位树/归属部门/所属上级
* @author cwchen
* @date 2023/12/20 17:10
*/
List<TreeNode> getDeptTree(SelectDto dto);
/**
* @param dto
* @return List<SelectVo>
* @description 岗位下拉选
* @author cwchen
* @date 2023/12/20 17:50
*/
List<SelectVo> getPostCbx(SelectDto dto);
/**
* @param dto
* @return List<SelectVo>
* @description 角色下拉选
* @author cwchen
* @date 2023/12/20 17:56
*/
List<SelectVo> getRoleCbx(SelectDto dto);
/**
* @param dto
* @return List<SelectVo>
* @description 单位类型下拉选
* @author cwchen
* @date 2023/12/20 18:01
*/
List<SelectVo> getUnitTypeCbx(SelectDto dto);
}

View File

@ -26,4 +26,67 @@ public interface SelectService {
* @date 2023/12/20 15:04
*/
AjaxResult getProData(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 机具类型
* @author cwchen
* @date 2023/12/20 16:02
*/
AjaxResult getMaTypeData(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 机具类型-下拉树
* @author cwchen
* @date 2023/12/20 16:10
*/
// AjaxResult getMaTypeTreeData(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 数据字典下拉选
* @author cwchen
* @date 2023/12/20 16:22
*/
AjaxResult getDictByPidCbx(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 单位树/归属部门/所属上级
* @author cwchen
* @date 2023/12/20 16:36
*/
AjaxResult getDeptTree(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 岗位下拉树
* @author cwchen
* @date 2023/12/20 17:45
*/
AjaxResult getPostCbx(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 角色下拉选
* @author cwchen
* @date 2023/12/20 17:56
*/
AjaxResult getRoleCbx(SelectDto dto);
/**
* @param dto
* @return AjaxResult
* @description 单位类型下拉选
* @author cwchen
* @date 2023/12/20 18:00
*/
AjaxResult getUnitTypeCbx(SelectDto dto);
}

View File

@ -3,9 +3,12 @@ package com.bonus.sgzb.system.service.impl;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.system.domain.SelectVo;
import com.bonus.sgzb.system.domain.TreeNode;
import com.bonus.sgzb.system.mapper.SelectMapper;
import com.bonus.sgzb.system.service.SelectService;
import com.bonus.sgzb.system.util.TreeBuild;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -44,4 +47,77 @@ public class SelectServiceImpl implements SelectService {
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getMaTypeData(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getMaTypeData(dto);
} catch (Exception e) {
log.error("机具类型-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDictByPidCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getDictByPidCbx(dto);
} catch (Exception e) {
log.error("数据字典-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDeptTree(SelectDto dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getDeptTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("单位树/归属部门/所属上级-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getPostCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getPostCbx(dto);
} catch (Exception e) {
log.error("岗位下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getRoleCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getRoleCbx(dto);
} catch (Exception e) {
log.error("角色下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getUnitTypeCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getUnitTypeCbx(dto);
} catch (Exception e) {
log.error("单位类型下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
}

View File

@ -0,0 +1,79 @@
package com.bonus.sgzb.system.util;
import com.bonus.sgzb.system.domain.TreeNode;
import java.util.ArrayList;
import java.util.List;
/**
* BuildTree 构建树形结构
* @author 10488
*/
public class TreeBuild {
public List<TreeNode> nodeList = new ArrayList<>();
/**
* 构造方法
* @param nodeList 将数据集合赋值给nodeList即所有数据作为所有节点
*/
public TreeBuild(List<TreeNode> nodeList){
this.nodeList = nodeList;
}
/**
* 获取需构建的所有根节点顶级节点 "0"
* @return 所有根节点List集合
*/
public List<TreeNode> getRootNode(){
// 保存所有根节点所有根节点的数据
List<TreeNode> rootNodeList = new ArrayList<>();
// treeNode查询出的每一条数据节点
for (TreeNode treeNode : nodeList){
// 判断当前节点是否为根节点此处注意若parentId类型是String则要采用equals()方法判断
if (0 == treeNode.getParentId()) {
// 添加
rootNodeList.add(treeNode);
}
}
return rootNodeList;
}
/**
* 根据每一个顶级节点根节点进行构建树形结构
* @return 构建整棵树
*/
public List<TreeNode> buildTree(){
// treeNodes保存一个顶级节点所构建出来的完整树形
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
// getRootNode()获取所有的根节点
for (TreeNode treeRootNode : getRootNode()) {
// 将顶级节点进行构建子树
treeRootNode = buildChildTree(treeRootNode);
// 完成一个顶级节点所构建的树形增加进来
treeNodes.add(treeRootNode);
}
return treeNodes;
}
/**
* 递归-----构建子树形结构
* @param pNode 根节点顶级节点
* @return 整棵树
*/
public TreeNode buildChildTree(TreeNode pNode){
List<TreeNode> childTree = new ArrayList<TreeNode>();
// nodeList所有节点集合所有数据
for (TreeNode treeNode : nodeList) {
// 判断当前节点的父节点ID是否等于根节点的ID即当前节点为其下的子节点
if (treeNode.getParentId() == pNode.getId()) {
// 再递归进行判断当前节点的情况调用自身方法
childTree.add(buildChildTree(treeNode));
}
}
// for循环结束即节点下没有任何节点树形构建结束设置树结果
pNode.setChildren(childTree);
return pNode;
}
}

View File

@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
/*根据标段工程id关联协议查询往来单位*/
<if test="id != null and id != ''">
SELECT DISTINCT bui.unit_id AS id,
bui.unit_name AS titleName
bui.unit_name AS `name`
FROM bm_project_lot bpl
LEFT JOIN bm_agreement_info bai ON bpl.lot_id = bai.project_id AND bai.`status` = '1'
LEFT JOIN bm_unit_info bui ON bai.unit_id = bui.unit_id AND bui.del_flag = '0'
@ -17,7 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="id == null or id == ''">
SELECT unit_id AS id,
unit_name AS titleName
unit_name AS `name`
FROM bm_unit_info
WHERE del_flag = '0'
</if>
@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
/*根据往来单位id关联协议查询工程*/
<if test="id != null and id != ''">
SELECT DISTINCT bpl.lot_id AS id,
bpl.lot_name AS titleName
bpl.lot_name AS `name`
FROM bm_unit_info bui
LEFT JOIN bm_agreement_info bai ON bui.unit_id = bai.unit_id AND bai.`status` = '1'
LEFT JOIN bm_project_lot bpl ON bai.project_id = bpl.lot_id AND bpl.del_flag = '0'
@ -36,9 +36,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="id == null or id == ''">
SELECT lot_id AS id,
lot_name AS titleName
lot_name AS `name`
FROM bm_project_lot
WHERE del_flag = '0'
</if>
</select>
<!--机具类型-->
<select id="getMaTypeData" resultType="com.bonus.sgzb.system.domain.SelectVo">
SELECT type_id AS id,
type_name AS `name`
FROM ma_type
WHERE `level` = #{type} AND del_flag = '0'
</select>
<!--数据字典下拉选-->
<select id="getDictByPidCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
SELECT sd2.id,sd2.`name`
FROM sys_dic sd
LEFT JOIN sys_dic sd2 ON sd.id = sd2.p_id
WHERE sd.`value` = #{parentValue} AND sd.p_id = 0
</select>
<!--单位树/归属部门/所属上级-->
<select id="getDeptTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
SELECT dept_id AS id,
parent_id AS parentId,
dept_name AS label
FROM sys_dept
WHERE del_flag = '0'
ORDER BY order_num
</select>
<!--岗位下拉选-->
<select id="getPostCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
SELECT post_id AS id,
post_name AS `name`
FROM sys_post
WHERE status = '0'
ORDER BY post_sort
</select>
<!--角色下拉选-->
<select id="getRoleCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
SELECT role_id AS id,
role_name AS `name`
FROM sys_role
WHERE status = '0'
ORDER BY role_sort
</select>
<!--单位类型下拉选-->
<select id="getUnitTypeCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
SELECT sd2.id,sd2.`name`
FROM sys_dic sd
LEFT JOIN sys_dic sd2 ON sd.id = sd2.p_id
WHERE sd.`value` = #{parentValue} AND sd.p_id = 0
</select>
</mapper>