Authored by simba

update

... ... @@ -19,9 +19,9 @@ import java.util.List;
*/
@Controller
@RequestMapping("HostGroup")
public class HostGroupController {
public class HostGroupCtrl {
Logger log = LoggerFactory.getLogger(HostGroupController.class);
Logger log = LoggerFactory.getLogger(HostGroupCtrl.class);
@Autowired
IHostGroupService hostGroupService;
... ...
package com.monitor.cmdb.controller;
import com.model.MechineInfo;
import com.monitor.cmdb.service.IMechineInfoService;
import com.monitor.model.request.MechineInfoReq;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.monitor.model.request.HostInfoReq;
import com.monitor.model.response.PageResponse;
import com.monitor.model.response.Response;
import org.slf4j.Logger;
... ... @@ -20,36 +20,36 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
@Controller
@RequestMapping("mechineInfo")
public class MechineInfoController {
public class HostInfoCtrl {
Logger log = LoggerFactory.getLogger(MechineInfoController.class);
Logger log = LoggerFactory.getLogger(HostInfoCtrl.class);
@Autowired
IMechineInfoService mechineInfoService;
IHostInfoService hostInfoService;
@RequestMapping("/getMechineInfos")
@ResponseBody
public Response<PageResponse<MechineInfo>> getMechineInfos(MechineInfoReq req) throws Exception {
public Response<PageResponse<HostInfo>> getHostInfos(HostInfoReq req) throws Exception {
log.info("getMechineInfos with param is {}", req);
// 查询列表
PageResponse<MechineInfo> responseBO = mechineInfoService.getMechineInfos(req);
PageResponse<HostInfo> responseBO = hostInfoService.getHostInfos(req);
if (responseBO == null || CollectionUtils.isEmpty(responseBO.getRows())) {
return new Response<PageResponse<MechineInfo>>();
return new Response<PageResponse<HostInfo>>();
}
PageResponse<MechineInfo> response = new PageResponse<MechineInfo>();
PageResponse<HostInfo> response = new PageResponse<HostInfo>();
response.setCurrentPage(responseBO.getCurrentPage());
response.setRows(responseBO.getRows());
response.setPageSize(responseBO.getPageSize());
response.setTotal(responseBO.getTotal());
log.info("getMechineInfos success and total={}", response.getTotal());
return new Response<PageResponse<MechineInfo>>(response);
return new Response<PageResponse<HostInfo>>(response);
}
@RequestMapping("/saveMechineInfo")
@ResponseBody
public Response<Integer> saveMechineInfo(String req) throws Exception {
log.info("saveMechineInfo with param is {}", req);
return mechineInfoService.saveMechineInfo(req);
return hostInfoService.saveHostInfo(req);
}
... ... @@ -57,14 +57,14 @@ public class MechineInfoController {
@ResponseBody
public Response<Integer> delMechineInfo(int id) throws Exception {
log.info("delMechineInfo with param is {}", id);
return mechineInfoService.delMechineInfoById(id);
return hostInfoService.delHostInfoById(id);
}
@RequestMapping("/getMechineInfoById")
@ResponseBody
public Response<MechineInfo> getMechineInfoById(int id) throws Exception {
public Response<HostInfo> getMechineInfoById(int id) throws Exception {
log.info("getMechineInfoById with param is {}", id);
return mechineInfoService.getMechineInfoById(id);
return hostInfoService.getHostInfoById(id);
}
}
... ...
package com.monitor.cmdb.service;
import com.model.MechineInfo;
import com.monitor.model.request.MechineInfoReq;
import com.model.HostInfo;
import com.monitor.model.request.HostInfoReq;
import com.monitor.model.response.PageResponse;
import com.monitor.model.response.Response;
/**
* Created by yoho on 2016/6/14.
*/
public interface IMechineInfoService {
PageResponse<MechineInfo> getMechineInfos(MechineInfoReq req);
public interface IHostInfoService {
PageResponse<HostInfo> getHostInfos(HostInfoReq req);
Response<Integer> saveMechineInfo(String req);
Response<Integer> saveHostInfo(String req);
Response<Integer> delMechineInfoById(int id);
Response<Integer> delHostInfoById(int id);
Response<MechineInfo> getMechineInfoById(int id);
Response<HostInfo> getHostInfoById(int id);
}
... ...
package com.monitor.cmdb.service.impl;
import com.model.MechineInfo;
import com.monitor.cmdb.service.IMechineInfoService;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.MechineInfoReq;
import com.monitor.model.request.HostInfoReq;
import com.monitor.model.response.PageResponse;
import com.monitor.model.response.Response;
import com.monitor.mysql.mapper.MechineInfoMapper;
import com.monitor.mysql.mapper.HostInfoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,21 +19,21 @@ import java.util.List;
* Created by yoho on 2016/6/14.
*/
@Service
public class MechineInfoServiceImpl implements IMechineInfoService {
public class HostInfoServiceImpl implements IHostInfoService {
Logger logger = LoggerFactory.getLogger(MechineInfoServiceImpl.class);
Logger logger = LoggerFactory.getLogger(HostInfoServiceImpl.class);
@Autowired
MechineInfoMapper mechineInfoMapper;
HostInfoMapper hostInfoMapper;
@Override
public PageResponse<MechineInfo> getMechineInfos(MechineInfoReq req) {
logger.info("getMechineInfos with param is {}", req);
public PageResponse<HostInfo> getHostInfos(HostInfoReq req) {
logger.info("getHostInfos with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = mechineInfoMapper.selectCountByCodition(page.getParams());
int total = hostInfoMapper.selectCountByCodition(page.getParams());
logger.info("selectUserTotal num is {}, with param is {}", total,
req);
// 数量为0 直接返回
... ... @@ -42,44 +42,44 @@ public class MechineInfoServiceImpl implements IMechineInfoService {
return null;
}
// 获取列表
List<MechineInfo> mechineInfos = mechineInfoMapper.selectMechineInfosByCodition(page.getParams());
if (CollectionUtils.isEmpty(mechineInfos)) {
logger.debug("getMechineInfos is null with param is {}", req);
List<HostInfo> HostInfos = hostInfoMapper.selectHostInfosByCodition(page.getParams());
if (CollectionUtils.isEmpty(HostInfos)) {
logger.debug("getHostInfos is null with param is {}", req);
return null;
}
PageResponse<MechineInfo> response = new PageResponse<MechineInfo>();
PageResponse<HostInfo> response = new PageResponse<HostInfo>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(mechineInfos);
response.setRows(HostInfos);
return response;
}
@Override
public Response<Integer> saveMechineInfo(String req) {
MechineInfo mechineInfo=new MechineInfo();
// BeanUtils.copyProperties(mechineInfo, req);
if(mechineInfo.getId()>0){
mechineInfoMapper.updateByPrimaryKeySelective(mechineInfo);
public Response<Integer> saveHostInfo(String req) {
HostInfo HostInfo=new HostInfo();
// BeanUtils.copyProperties(HostInfo, req);
if(HostInfo.getId()>0){
hostInfoMapper.updateByPrimaryKeySelective(HostInfo);
}else{
mechineInfoMapper.insert(mechineInfo);
hostInfoMapper.insert(HostInfo);
}
return null;
}
@Override
public Response<Integer> delMechineInfoById(int id) {
int result=mechineInfoMapper.deleteByPrimaryKey(id);
public Response<Integer> delHostInfoById(int id) {
int result=hostInfoMapper.deleteByPrimaryKey(id);
return new Response<Integer>(result);
}
@Override
public Response<MechineInfo> getMechineInfoById(int id) {
MechineInfo mechineInfo=mechineInfoMapper.selectByPrimaryKey(id);
if(null==mechineInfo){
return new Response<MechineInfo>();
public Response<HostInfo> getHostInfoById(int id) {
HostInfo HostInfo=hostInfoMapper.selectByPrimaryKey(id);
if(null==HostInfo){
return new Response<HostInfo>();
}
return new Response<MechineInfo>(mechineInfo);
return new Response<HostInfo>(HostInfo);
}
}
... ...
... ... @@ -5,7 +5,7 @@ import com.monitor.model.page.PageRequest;
/**
* Created by yoho on 2016/6/14.
*/
public class MechineInfoReq extends PageRequest {
public class HostInfoReq extends PageRequest {
private String alias;
... ...
... ... @@ -5,7 +5,7 @@ import lombok.Data;
import java.io.Serializable;
@Data
public class MechineInfo implements Serializable {
public class HostInfo implements Serializable {
private int id;
private String alias;
... ...
package com.monitor.mysql.mapper;
import com.model.HostInfo;
import java.util.List;
import java.util.Map;
public interface HostInfoMapper {
int deleteByPrimaryKey(Integer id);
int insert(HostInfo record);
int insertSelective(HostInfo record);
HostInfo selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(HostInfo record);
int updateByPrimaryKey(HostInfo record);
int selectCountByCodition(Map<String, Object> param);
List<HostInfo> selectHostInfosByCodition(Map<String, Object> param);
}
\ No newline at end of file
... ...
package com.monitor.mysql.mapper;
import com.model.MechineInfo;
import java.util.List;
import java.util.Map;
public interface MechineInfoMapper {
int deleteByPrimaryKey(Integer id);
int insert(MechineInfo record);
int insertSelective(MechineInfo record);
MechineInfo selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(MechineInfo record);
int updateByPrimaryKey(MechineInfo record);
int selectCountByCodition(Map<String, Object> param);
List<MechineInfo> selectMechineInfosByCodition(Map<String, Object> param);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.MechineInfoMapper" >
<resultMap id="BaseResultMap" type="com.model.MechineInfo" >
<mapper namespace="com.monitor.mysql.mapper.HostInfoMapper" >
<resultMap id="BaseResultMap" type="com.model.HostInfo" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="alias" property="alias" jdbcType="VARCHAR" />
<result column="host_ip" property="hostIp" jdbcType="VARCHAR" />
... ... @@ -17,23 +17,23 @@
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from mechine_info
from host_info
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from mechine_info
delete from host_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.model.MechineInfo" >
insert into mechine_info (id, alias, host_ip,
<insert id="insert" parameterType="com.model.HostInfo" >
insert into host_info (id, alias, host_ip,
group_id, cloud_type, tags,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{alias,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER}, #{cloudType,jdbcType=BIT}, #{tags,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.model.MechineInfo" >
insert into mechine_info
<insert id="insertSelective" parameterType="com.model.HostInfo" >
insert into host_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
... ... @@ -87,8 +87,8 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.MechineInfo" >
update mechine_info
<update id="updateByPrimaryKeySelective" parameterType="com.model.HostInfo" >
update host_info
<set >
<if test="alias != null" >
alias = #{alias,jdbcType=VARCHAR},
... ... @@ -114,8 +114,8 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.model.MechineInfo" >
update mechine_info
<update id="updateByPrimaryKey" parameterType="com.model.HostInfo" >
update host_info
set alias = #{alias,jdbcType=VARCHAR},
host_ip = #{hostIp,jdbcType=VARCHAR},
group_id = #{groupId,jdbcType=INTEGER},
... ... @@ -129,7 +129,7 @@
<select id="selectCountByCodition" parameterType="java.util.Map" resultType="java.lang.Integer">
select
count(1)
from mechine_info
from host_info
where
1=1
<if test="alias != null" >
... ... @@ -137,10 +137,10 @@
</if>
</select>
<select id="selectMechineInfosByCodition" parameterType="java.util.Map" resultMap="BaseResultMap">
<select id="selectHostInfosByCodition" parameterType="java.util.Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from mechine_info
from host_info
where
1=1
<if test="alias != null" >
... ...