DeptServiceImpl.java
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.huaheng.pc.system.dept.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huaheng.common.constant.UserConstants;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.mapper.DeptMapper;
/**
* 部门管理 服务实现
*
* @author huaheng
*/
@Service
public class DeptServiceImpl implements IDeptService
{
@Autowired
private DeptMapper deptMapper;
/**
* 查询部门管理数据
*
* @return 部门信息集合
*/
@Override
public List<Dept> selectDeptList(Dept dept)
{
return deptMapper.selectDeptList(dept);
}
/**
* 查询部门所有数据
*
* @return 部门信息集合
*/
@Override
public List<Dept> selectDeptAll()
{
return deptMapper.selectDeptAll();
}
/**
* 查询部门管理树
*
* @return 所有部门信息
*/
@Override
public List<Map<String, Object>> selectDeptTree()
{
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
List<Dept> deptList = deptMapper.selectDeptAll();
for (Dept dept : deptList)
{
if (dept.getEnable())
{
Map<String, Object> deptMap = new HashMap<String, Object>();
deptMap.put("id", dept.getId());
deptMap.put("pId", dept.getParentId());
deptMap.put("name", dept.getDeptName());
deptMap.put("title", dept.getDeptName());
trees.add(deptMap);
}
}
return trees;
}
/**
* 查询部门人数
*
* @param parentId 部门ID
* @return 结果
*/
@Override
public int selectDeptCount(Integer parentId)
{
Dept dept = new Dept();
dept.setParentId(parentId);
return deptMapper.selectDeptCount(dept);
}
/**
* 查询部门是否存在用户
*
* @param id 部门ID
* @return 结果 true 存在 false 不存在
*/
@Override
public boolean checkDeptExistUser(Integer id)
{
int result = deptMapper.checkDeptExistUser(id);
return result > 0 ? true : false;
}
/**
* 删除部门管理信息
*
* @param id 部门ID
* @return 结果
*/
@Override
public int deleteDeptById(Integer id)
{
return deptMapper.deleteDeptById(id);
}
/**
* 新增保存部门信息
*
* @param dept 部门信息
* @return 结果
*/
@Override
public int insertDept(Dept dept)
{
Dept info = deptMapper.selectDeptById(dept.getParentId());
dept.setCreateBy(ShiroUtils.getLoginName());
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
}
/**
* 修改保存部门信息
*
* @param dept 部门信息
* @return 结果
*/
@Override
public int updateDept(Dept dept)
{
Dept info = deptMapper.selectDeptById(dept.getParentId());
dept.setUpdateBy(ShiroUtils.getLoginName());
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.updateDept(dept);
}
/**
* 根据部门ID查询信息
*
* @param id 部门ID
* @return 部门信息
*/
@Override
public Dept selectDeptById(Integer id)
{
return deptMapper.selectDeptById(id);
}
/**
* 校验部门名称是否唯一
*
* @param dept 部门信息
* @return 结果
*/
@Override
public String checkDeptNameUnique(Dept dept)
{
Integer id = StringUtils.isNull(dept.getId()) ? -1 : dept.getId();
Dept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
if (StringUtils.isNotNull(info) && info.getId().intValue() != id.intValue())
{
return UserConstants.DEPT_NAME_NOT_UNIQUE;
}
return UserConstants.DEPT_NAME_UNIQUE;
}
}