Browse Source

兽医人员库

wwh 2 weeks ago
parent
commit
ece43157cf

+ 10 - 0
baqing-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java

@@ -58,6 +58,16 @@ public class SysDeptController extends BaseController
58 58
         return success(depts);
59 59
     }
60 60
 
61
+    /**
62
+     * 校验部门名称是否唯一
63
+     */
64
+    @PreAuthorize("@ss.hasPermi('system:dept:list')")
65
+    @GetMapping("/checkDeptNameUnique")
66
+    public AjaxResult checkDeptNameUnique(SysDept dept)
67
+    {
68
+        return success(deptService.checkDeptNameUnique(dept));
69
+    }
70
+
61 71
     /**
62 72
      * 根据部门编号获取详细信息
63 73
      */

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -69,10 +69,10 @@ public interface SysDeptMapper
69 69
     public int checkDeptExistUser(Long deptId);
70 70
 
71 71
     /**
72
-     * 校验部门名称是否唯一
72
+     * 校验部门名称是否唯一(全局:未删除记录中部门名称不可重复)
73 73
      * 
74 74
      * @param deptName 部门名称
75
-     * @param parentId 父部门ID
75
+     * @param parentId 父部门ID(保留参数兼容调用方,校验时不按上级过滤)
76 76
      * @return 结果
77 77
      */
78 78
     public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java

@@ -84,10 +84,10 @@ public interface ISysDeptService
84 84
     public boolean checkDeptExistUser(Long deptId);
85 85
 
86 86
     /**
87
-     * 校验部门名称是否唯一
87
+     * 校验部门名称是否唯一(全局:未删除记录中部门名称不可重复)
88 88
      * 
89 89
      * @param dept 部门信息
90
-     * @return 结果
90
+     * @return 结果 true唯一 false不唯一
91 91
      */
92 92
     public boolean checkDeptNameUnique(SysDept dept);
93 93
 

+ 16 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -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))

+ 1 - 1
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
84 84
 	
85 85
 	<select id="checkDeptNameUnique" resultMap="SysDeptResult">
86 86
 	    <include refid="selectDeptVo"/>
87
-		where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
87
+		where dept_name = #{deptName} and del_flag = '0' limit 1
88 88
 	</select>
89 89
     
90 90
     <insert id="insertDept" parameterType="SysDept">