Authored by zhengyouwei

host group删除校验

@@ -8,6 +8,7 @@ import com.monitor.model.page.PageRequest; @@ -8,6 +8,7 @@ import com.monitor.model.page.PageRequest;
8 import com.monitor.model.page.PageResponse; 8 import com.monitor.model.page.PageResponse;
9 import com.monitor.model.response.BaseResponse; 9 import com.monitor.model.response.BaseResponse;
10 import com.monitor.mysql.mapper.HostGroupMapper; 10 import com.monitor.mysql.mapper.HostGroupMapper;
  11 +import com.monitor.mysql.mapper.HostInfoMapper;
11 import org.slf4j.Logger; 12 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,9 @@ public class HostGroupServiceImpl implements IHostGroupService { @@ -27,6 +28,9 @@ public class HostGroupServiceImpl implements IHostGroupService {
27 @Autowired 28 @Autowired
28 HostGroupMapper hostGroupMapper; 29 HostGroupMapper hostGroupMapper;
29 30
  31 + @Autowired
  32 + HostInfoMapper hostInfoMapper;
  33 +
30 @Override 34 @Override
31 public PageResponse<HostGroup> getHostGroups(PageRequest req) { 35 public PageResponse<HostGroup> getHostGroups(PageRequest req) {
32 logger.debug("getHostGroups with param is {}", req); 36 logger.debug("getHostGroups with param is {}", req);
@@ -69,8 +73,13 @@ public class HostGroupServiceImpl implements IHostGroupService { @@ -69,8 +73,13 @@ public class HostGroupServiceImpl implements IHostGroupService {
69 73
70 @Override 74 @Override
71 public BaseResponse<Integer> delHostGroupById(int id) { 75 public BaseResponse<Integer> delHostGroupById(int id) {
72 - int result=hostGroupMapper.deleteByPrimaryKey(id);  
73 - return new BaseResponse<Integer>(result); 76 + List<HostInfo> list = hostInfoMapper.selectHostInfosByGroup(id);
  77 + if(list != null && list.size() > 0){
  78 + return new BaseResponse<Integer>("有主机绑定此机组,请先删除主机信息");
  79 + }else{
  80 + int result=hostGroupMapper.deleteByPrimaryKey(id);
  81 + return new BaseResponse<Integer>(result);
  82 + }
74 } 83 }
75 84
76 @Override 85 @Override
@@ -23,6 +23,8 @@ public interface HostInfoMapper { @@ -23,6 +23,8 @@ public interface HostInfoMapper {
23 23
24 List<HostInfo> selectHostInfosByCodition(PageBean page); 24 List<HostInfo> selectHostInfosByCodition(PageBean page);
25 25
  26 + List<HostInfo> selectHostInfosByGroup(Integer groupid);
  27 +
26 HostInfo selectByHostIp(@Param("hostIp") String hostIp); 28 HostInfo selectByHostIp(@Param("hostIp") String hostIp);
27 29
28 } 30 }
@@ -175,4 +175,11 @@ @@ -175,4 +175,11 @@
175 where host_ip = #{hostIp} 175 where host_ip = #{hostIp}
176 </select> 176 </select>
177 177
  178 + <select id="selectHostInfosByGroup" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  179 + select
  180 + <include refid="Base_Column_List" />
  181 + from host_info
  182 + where group_id = #{groupid,jdbcType=INTEGER}
  183 + </select>
  184 +
178 </mapper> 185 </mapper>