Authored by zhengyouwei

host group删除校验

... ... @@ -8,6 +8,7 @@ import com.monitor.model.page.PageRequest;
import com.monitor.model.page.PageResponse;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.HostGroupMapper;
import com.monitor.mysql.mapper.HostInfoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -27,6 +28,9 @@ public class HostGroupServiceImpl implements IHostGroupService {
@Autowired
HostGroupMapper hostGroupMapper;
@Autowired
HostInfoMapper hostInfoMapper;
@Override
public PageResponse<HostGroup> getHostGroups(PageRequest req) {
logger.debug("getHostGroups with param is {}", req);
... ... @@ -69,8 +73,13 @@ public class HostGroupServiceImpl implements IHostGroupService {
@Override
public BaseResponse<Integer> delHostGroupById(int id) {
int result=hostGroupMapper.deleteByPrimaryKey(id);
return new BaseResponse<Integer>(result);
List<HostInfo> list = hostInfoMapper.selectHostInfosByGroup(id);
if(list != null && list.size() > 0){
return new BaseResponse<Integer>("有主机绑定此机组,请先删除主机信息");
}else{
int result=hostGroupMapper.deleteByPrimaryKey(id);
return new BaseResponse<Integer>(result);
}
}
@Override
... ...
... ... @@ -23,6 +23,8 @@ public interface HostInfoMapper {
List<HostInfo> selectHostInfosByCodition(PageBean page);
List<HostInfo> selectHostInfosByGroup(Integer groupid);
HostInfo selectByHostIp(@Param("hostIp") String hostIp);
}
\ No newline at end of file
... ...
... ... @@ -175,4 +175,11 @@
where host_ip = #{hostIp}
</select>
<select id="selectHostInfosByGroup" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from host_info
where group_id = #{groupid,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...