Browse Source

Merge remote-tracking branch 'origin/master' into test

Michael 8 years ago
parent
commit
2921352154

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

@@ -32,4 +32,6 @@ public interface RoleMapper {
 	List<Role> findRoles();
 	
 	List<RolePermissionBo> selectRolePList(String id);
+	
+	int selectCountByRoleId(List<String> records);
 }

+ 10 - 0
src/main/java/com/goafanti/common/mapper/RoleMapper.xml

@@ -135,4 +135,14 @@
     where
     tr.id=#{id,jdbcType=VARCHAR}
   </select>
+  <select id="selectCountByRoleId" parameterType="java.lang.String" resultType="java.lang.Integer">
+  	select 
+  	count(0) 
+  	from user_role 
+   	where 
+   	rid in 
+    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
+	  #{item,jdbcType=VARCHAR}  
+    </foreach>  
+  </select>  
 </mapper>

+ 10 - 1
src/main/java/com/goafanti/permission/controller/NewRoleApiController.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import javax.annotation.Resource;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -14,6 +15,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.dao.RoleMapper;
 import com.goafanti.common.model.Role;
 import com.goafanti.permission.bo.RoleBo;
 import com.goafanti.permission.service.NewRoleService;
@@ -23,7 +25,8 @@ import com.goafanti.permission.service.NewRoleService;
 public class NewRoleApiController extends BaseApiController{
 	@Resource
 	private NewRoleService newRoleService;
-	
+	@Autowired
+	RoleMapper				roleMapper;
 	
 	@RequestMapping(value = "/roles", method = RequestMethod.POST)
 	public Result roles(RoleBo role, Integer pageNo,
@@ -62,6 +65,7 @@ public class NewRoleApiController extends BaseApiController{
 	public Result deleteRole(String data) {
 		Result res = new Result();
 		JSONArray ja = (JSONArray) JSON.parse(data);
+		
 		if (ja != null && !ja.isEmpty()) {
 			List<String> records = new ArrayList<>();
 			for (int idx = 0; idx < ja.size(); idx++) {
@@ -70,6 +74,11 @@ public class NewRoleApiController extends BaseApiController{
 					records.add(rid);
 				}
 			}
+			int zz=roleMapper.selectCountByRoleId(records);
+			if(zz>0){
+				res.getError().add(buildError("","角色被分配不能删除"));
+				return res;
+			}
 			res.setData(newRoleService.deleteByPrimaryKeys(records));
 		} else {
 			res.getError().add(buildError("", "参数格式不正确"));