|
|
@@ -165,7 +165,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
165
|
165
|
}
|
|
166
|
166
|
|
|
167
|
167
|
/**
|
|
168
|
|
- * 校验部门名称是否唯一
|
|
|
168
|
+ * 校验部门名称是否唯一(全局未删除范围内唯一)
|
|
169
|
169
|
*
|
|
170
|
170
|
* @param dept 部门信息
|
|
171
|
171
|
* @return 结果
|
|
|
@@ -173,8 +173,14 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
173
|
173
|
@Override
|
|
174
|
174
|
public boolean checkDeptNameUnique(SysDept dept)
|
|
175
|
175
|
{
|
|
|
176
|
+ if (dept == null || StringUtils.isEmpty(dept.getDeptName()))
|
|
|
177
|
+ {
|
|
|
178
|
+ return UserConstants.UNIQUE;
|
|
|
179
|
+ }
|
|
|
180
|
+ String deptName = dept.getDeptName().trim();
|
|
|
181
|
+ dept.setDeptName(deptName);
|
|
176
|
182
|
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
|
177
|
|
- SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
|
|
|
183
|
+ SysDept info = deptMapper.checkDeptNameUnique(deptName, dept.getParentId());
|
|
178
|
184
|
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
|
|
179
|
185
|
{
|
|
180
|
186
|
return UserConstants.NOT_UNIQUE;
|
|
|
@@ -211,6 +217,10 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
211
|
217
|
@Override
|
|
212
|
218
|
public int insertDept(SysDept dept)
|
|
213
|
219
|
{
|
|
|
220
|
+ if (!checkDeptNameUnique(dept))
|
|
|
221
|
+ {
|
|
|
222
|
+ throw new ServiceException("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
|
223
|
+ }
|
|
214
|
224
|
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
|
215
|
225
|
// 如果父节点不为正常状态,则不允许新增子节点
|
|
216
|
226
|
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
|
|
|
@@ -230,6 +240,10 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
230
|
240
|
@Override
|
|
231
|
241
|
public int updateDept(SysDept dept)
|
|
232
|
242
|
{
|
|
|
243
|
+ if (!checkDeptNameUnique(dept))
|
|
|
244
|
+ {
|
|
|
245
|
+ throw new ServiceException("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
|
|
246
|
+ }
|
|
233
|
247
|
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
|
|
234
|
248
|
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
|
|
235
|
249
|
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
|