Commit e0c5d68f by fengshuonan

完善部门管理查询

parent 2dcaa929
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.stylefeng.guns.core.common.node;
import cn.stylefeng.roses.kernel.model.tree.Tree;
import lombok.Data;
import java.util.List;
/**
* jquery ztree 插件的节点
*
* @author fengshuonan
* @date 2017年2月17日 下午8:25:14
*/
@Data
public class TreeviewNode implements Tree {
/**
* 附加信息,一般用于存业务id
*/
private String tags;
/**
* 父级id
*/
private String parentId;
/**
* 节点名称
*/
private String text;
/**
* 子节点
*/
private List<TreeviewNode> nodes;
@Override
public String getNodeId() {
return tags;
}
@Override
public String getNodeParentId() {
return parentId;
}
@Override
public void setChildrenNodes(List childrenNodes) {
this.nodes = childrenNodes;
}
}
......@@ -21,13 +21,16 @@ import cn.stylefeng.guns.core.common.annotion.Permission;
import cn.stylefeng.guns.core.common.constant.dictmap.DeptDict;
import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.common.node.TreeviewNode;
import cn.stylefeng.guns.core.common.node.ZTreeNode;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.modular.system.entity.Dept;
import cn.stylefeng.guns.modular.system.model.DeptDto;
import cn.stylefeng.guns.modular.system.service.DeptService;
import cn.stylefeng.guns.modular.system.warpper.DeptTreeWarpper;
import cn.stylefeng.guns.modular.system.warpper.DeptWarpper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.treebuild.DefaultTreeBuildFactory;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -97,6 +100,24 @@ public class DeptController extends BaseController {
}
/**
* 获取部门的tree列表
*/
@RequestMapping(value = "/treeview")
@ResponseBody
public List<TreeviewNode> treeview() {
List<TreeviewNode> treeviewNodes = this.deptService.treeviewNodes();
//构建树
DefaultTreeBuildFactory<TreeviewNode> factory = new DefaultTreeBuildFactory<>();
factory.setRootParentId("0");
List<TreeviewNode> results = factory.doTreeBuild(treeviewNodes);
//把子节点为空的设为null
DeptTreeWarpper.clearNull(results);
return results;
}
/**
* 新增部门
*/
@BussinessLog(value = "添加部门", key = "simplename", dict = DeptDict.class)
......@@ -119,8 +140,9 @@ public class DeptController extends BaseController {
@RequestMapping(value = "/list")
@Permission
@ResponseBody
public Object list(String condition) {
List<Map<String, Object>> list = this.deptService.list(condition);
public Object list(@RequestParam(value = "condition", required = false) String condition,
@RequestParam(value = "deptId", required = false) String deptId) {
List<Map<String, Object>> list = this.deptService.list(condition, deptId);
return super.warpObject(new DeptWarpper(list));
}
......
package cn.stylefeng.guns.modular.system.mapper;
import cn.stylefeng.guns.core.common.node.TreeviewNode;
import cn.stylefeng.guns.core.common.node.ZTreeNode;
import cn.stylefeng.guns.modular.system.entity.Dept;
import com.baomidou.mybatisplus.mapper.BaseMapper;
......@@ -26,6 +27,10 @@ public interface DeptMapper extends BaseMapper<Dept> {
/**
* 获取所有部门列表
*/
List<Map<String, Object>> list(@Param("condition") String condition);
List<Map<String, Object>> list(@Param("condition") String condition, @Param("deptId") String deptId);
/**
* 获取所有部门树列表
*/
List<TreeviewNode> treeviewNodes();
}
......@@ -38,11 +38,18 @@
<select id="list" resultType="map">
select
<include refid="Base_Column_List"/>
from sys_dept
from sys_dept where 1 = 1
<if test="condition != null and condition != ''">
where SIMPLE_NAME like CONCAT('%',#{condition},'%') or FULL_NAME like CONCAT('%',#{condition},'%')
and SIMPLE_NAME like CONCAT('%',#{condition},'%') or FULL_NAME like CONCAT('%',#{condition},'%')
</if>
<if test="deptId != null and deptId != ''">
and (DEPT_ID = #{deptId} or DEPT_ID in ( select DEPT_ID from sys_dept where PIDS like CONCAT('%[', #{deptId}, ']%') ))
</if>
order by SORT ASC
</select>
<select id="treeviewNodes" resultType="cn.stylefeng.guns.core.common.node.TreeviewNode">
select DEPT_ID AS tags, PID as parentId, SIMPLE_NAME as text from sys_dept
</select>
</mapper>
package cn.stylefeng.guns.modular.system.service;
import cn.stylefeng.guns.core.common.node.TreeviewNode;
import cn.stylefeng.guns.core.common.node.ZTreeNode;
import cn.stylefeng.guns.modular.system.entity.Dept;
import cn.stylefeng.guns.modular.system.mapper.DeptMapper;
......@@ -52,10 +53,17 @@ public class DeptService extends ServiceImpl<DeptMapper, Dept> {
}
/**
* 获取ztree的节点列表
*/
public List<TreeviewNode> treeviewNodes() {
return this.baseMapper.treeviewNodes();
}
/**
* 获取所有部门列表
*/
public List<Map<String, Object>> list(String condition) {
return this.baseMapper.list(condition);
public List<Map<String, Object>> list(String condition, String deptId) {
return this.baseMapper.list(condition,deptId);
}
}
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.stylefeng.guns.modular.system.warpper;
import cn.stylefeng.guns.core.common.node.TreeviewNode;
import java.util.List;
/**
* 部门列表树的包装
*
* @author fengshuonan
* @date 2017年4月25日 18:10:31
*/
public class DeptTreeWarpper {
public static void clearNull(List<TreeviewNode> list) {
if (list == null) {
return;
} else {
if (list.size() == 0) {
return;
} else {
for (TreeviewNode node : list) {
if (node.getNodes() != null) {
if (node.getNodes().size() == 0) {
node.setNodes(null);
} else {
clearNull(node.getNodes());
}
}
}
}
}
}
}
......@@ -7,7 +7,8 @@ var Dept = {
table: null,
layerIndex: -1,
condition: {
name: ''
name: '',
deptId: ''
}
};
......@@ -95,59 +96,25 @@ Dept.delete = function () {
Dept.search = function () {
var queryData = {};
queryData['condition'] = Dept.condition.name;
queryData['deptId'] = Dept.condition.deptId;
Dept.table.refresh({query: queryData});
};
$(function () {
var defaultData = [
{
text: 'Parent 1',
href: '#parent1',
tags: ['4'],
nodes: [
{
text: 'Child 1',
href: '#child1',
tags: ['2'],
nodes: [
{
text: 'Grandchild 1',
href: '#grandchild1',
tags: ['0']
},
{
text: 'Grandchild 2',
href: '#grandchild2',
tags: ['0']
}
]
},
{
text: 'Child 2',
href: '#child2',
tags: ['0']
}
]
},
{
text: 'Parent 2'
},
{
text: 'Parent 3'
},
{
text: 'Parent 4'
}
];
//获取部门树
var ajax = new $ax(Feng.ctxPath + "/dept/treeview");
var result = ajax.start();
$('#deptTree').treeview({
selectedBackColor: "#03a9f3",
onhoverColor: "rgba(0, 0, 0, 0.05)",
expandIcon: 'ti-plus',
collapseIcon: 'ti-minus',
nodeIcon: 'fa fa-home',
data: defaultData
data: result,
onNodeSelected: function (event, data) {
Dept.condition.deptId = data.tags;
Dept.search();
}
});
Dept.app = new Vue({
......
......@@ -52,7 +52,7 @@ public class DeptTest extends BaseJunit {
@Test
public void listTest() {
List<Map<String, Object>> list = this.deptMapper.list("总公司");
List<Map<String, Object>> list = this.deptMapper.list("总公司", null);
assertTrue(list.size() > 0);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment