Browse Source

角色管理 新增名字重复问题修改

Michael 8 years ago
parent
commit
99fe36f032

+ 4 - 0
src/main/java/com/goafanti/common/dao/RoleMapper.java

@@ -34,4 +34,8 @@ public interface RoleMapper {
 	List<RolePermissionBo> selectRolePList(String id);
 	
 	int selectCountByRoleId(List<String> records);
+	
+	String selectIdByName(String roleName);
+	
+	String selectNameById(String id);
 }

+ 15 - 1
src/main/java/com/goafanti/common/mapper/RoleMapper.xml

@@ -144,5 +144,19 @@
     <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
 	  #{item,jdbcType=VARCHAR}  
     </foreach>  
-  </select>  
+  </select>
+  <select id="selectIdByName" parameterType="java.lang.String" resultType="java.lang.String">
+  	select
+  	id
+  	from role
+  	where
+  	role_name=#{roleName,jdbcType=VARCHAR}
+  </select>
+  <select id="selectNameById" parameterType="java.lang.String" resultType="java.lang.String">
+  	select
+  	role_name as roleName
+  	from role
+  	where
+  	id=#{id,jdbcType=VARCHAR}
+  </select>   
 </mapper>

+ 8 - 0
src/main/java/com/goafanti/permission/controller/NewRoleApiController.java

@@ -54,6 +54,14 @@ public class NewRoleApiController extends BaseApiController{
 					permisionIds.add(pid);
 			}
 			Role records = jo.toJavaObject(Role.class);
+			String newName=roleMapper.selectNameById(records.getId());
+			if(newName==null){
+				String newid=roleMapper.selectIdByName(records.getRoleName());
+				if(newid!=null){
+					res.getError().add(buildError("","角色已存在"));
+					return res;
+				}
+			}			
 			res.setData(newRoleService.insert(records, permisionIds));
 		} else {
 			res.getError().add(buildError("", "参数格式不正确"));