Authored by simba

update

package com.monitor.cmdb.controller;
import com.model.MechineGroup;
import com.model.MechineInfo;
import com.monitor.cmdb.service.IMechineGroupService;
import com.monitor.model.request.MechineInfoReq;
import com.monitor.model.response.PageResponse;
import com.model.HostGroup;
import com.monitor.cmdb.service.IHostGroupService;
import com.monitor.model.response.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
... ... @@ -22,42 +18,42 @@ import java.util.List;
* 查询机器信息
*/
@Controller
@RequestMapping("mechineGroup")
public class MechineGroupController {
@RequestMapping("HostGroup")
public class HostGroupController {
Logger log = LoggerFactory.getLogger(MechineGroupController.class);
Logger log = LoggerFactory.getLogger(HostGroupController.class);
@Autowired
IMechineGroupService mechineGroupService;
IHostGroupService hostGroupService;
@RequestMapping("/getMechineGroups")
@RequestMapping("/getHostGroups")
@ResponseBody
public Response<List<MechineGroup>> getMechineGroups() throws Exception {
public Response<List<HostGroup>> getHostGroups() throws Exception {
// 查询列表
return mechineGroupService.getMechineGroups();
return hostGroupService.getHostGroups();
}
@RequestMapping("/saveMechineGroup")
@RequestMapping("/saveHostGroup")
@ResponseBody
public Response<Integer> saveMechineGroup(String req) throws Exception {
log.info("saveMechineInfo with param is {}", req);
return mechineGroupService.saveMechineGroup(req);
public Response<Integer> saveHostGroup(String req) throws Exception {
log.info("saveHostGroup with param is {}", req);
return hostGroupService.saveHostGroup(req);
}
@RequestMapping("/delMechineGroup")
@RequestMapping("/delHostGroup")
@ResponseBody
public Response<Integer> delMechineInfo(int id) throws Exception {
log.info("delMechineInfo with param is {}", id);
return mechineGroupService.delMechineGroupById(id);
public Response<Integer> delHostGroup(int id) throws Exception {
log.info("delHostGroup with param is {}", id);
return hostGroupService.delHostGroupById(id);
}
@RequestMapping("/getMechineGroupById")
@RequestMapping("/getHostGroupById")
@ResponseBody
public Response<MechineGroup> getMechineGroupById(int id) throws Exception {
log.info("getMechineInfoById with param is {}", id);
return mechineGroupService.getMechineGroupById(id);
public Response<HostGroup> getHostGroupById(int id) throws Exception {
log.info("getHostGroupById with param is {}", id);
return hostGroupService.getHostGroupById(id);
}
... ...
package com.monitor.cmdb.service;
import com.model.MechineGroup;
import com.model.HostGroup;
import com.monitor.model.response.Response;
import java.util.List;
... ... @@ -8,13 +8,13 @@ import java.util.List;
/**
* Created by yoho on 2016/6/14.
*/
public interface IMechineGroupService {
Response<List<MechineGroup>> getMechineGroups();
public interface IHostGroupService {
Response<List<HostGroup>> getHostGroups();
Response<Integer> saveMechineGroup(String req);
Response<Integer> saveHostGroup(String req);
Response<Integer> delMechineGroupById(int id);
Response<Integer> delHostGroupById(int id);
Response<MechineGroup> getMechineGroupById(int id);
Response<HostGroup> getHostGroupById(int id);
}
... ...
package com.monitor.cmdb.service.impl;
import com.model.MechineGroup;
import com.monitor.cmdb.service.IMechineGroupService;
import com.model.HostGroup;
import com.monitor.cmdb.service.IHostGroupService;
import com.monitor.model.response.Response;
import com.monitor.mysql.mapper.MechineGroupMapper;
import com.monitor.mysql.mapper.HostGroupMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,46 +16,46 @@ import java.util.List;
* Created by yoho on 2016/6/15.
*/
@Service
public class MechineGroupServiceImpl implements IMechineGroupService {
public class HostGroupServiceImpl implements IHostGroupService {
Logger logger = LoggerFactory.getLogger(MechineGroupServiceImpl.class);
Logger logger = LoggerFactory.getLogger(HostGroupServiceImpl.class);
@Autowired
MechineGroupMapper mechineGroupMapper;
HostGroupMapper hostGroupMapper;
@Override
public Response<List<MechineGroup>> getMechineGroups() {
List<MechineGroup> list= mechineGroupMapper.selectMechineGroups();
public Response<List<HostGroup>> getHostGroups() {
List<HostGroup> list= hostGroupMapper.selectHostGroups();
if(CollectionUtils.isEmpty(list)){
return new Response<List<MechineGroup>>();
return new Response<List<HostGroup>>();
}
return new Response<List<MechineGroup>>(list);
return new Response<List<HostGroup>>(list);
}
@Override
public Response<Integer> saveMechineGroup(String req) {
MechineGroup mechineGroup=new MechineGroup();
public Response<Integer> saveHostGroup(String req) {
HostGroup HostGroup=new HostGroup();
// BeanUtils.copyProperties(mechineInfo, req);
if(mechineGroup.getId()>0){
mechineGroupMapper.updateByPrimaryKeySelective(mechineGroup);
if(HostGroup.getId()>0){
hostGroupMapper.updateByPrimaryKeySelective(HostGroup);
}else{
mechineGroupMapper.insert(mechineGroup);
hostGroupMapper.insert(HostGroup);
}
return null;
}
@Override
public Response<Integer> delMechineGroupById(int id) {
int result=mechineGroupMapper.deleteByPrimaryKey(id);
public Response<Integer> delHostGroupById(int id) {
int result=hostGroupMapper.deleteByPrimaryKey(id);
return new Response<Integer>(result);
}
@Override
public Response<MechineGroup> getMechineGroupById(int id) {
MechineGroup mechineGroup=mechineGroupMapper.selectByPrimaryKey(id);
if(null == mechineGroup){
return new Response<MechineGroup>();
public Response<HostGroup> getHostGroupById(int id) {
HostGroup HostGroup=hostGroupMapper.selectByPrimaryKey(id);
if(null == HostGroup){
return new Response<HostGroup>();
}
return new Response<MechineGroup>(mechineGroup);
return new Response<HostGroup>(HostGroup);
}
}
... ...
package com.model;
import lombok.Data;
import java.io.Serializable;
/**
* Created by yoho on 2016/6/14.
*/
@Data
public class HostGroup implements Serializable {
private int id;
private String groupName;
private String createTime;
private String updateTime;
}
... ...
package com.model;
/**
* Created by yoho on 2016/6/14.
*/
public class MechineGroup {
private int id;
private String groupName;
private String createTime;
private String updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}
package com.model;
public class MechineInfo {
import lombok.Data;
import java.io.Serializable;
@Data
public class MechineInfo implements Serializable {
private int id;
private String alias;
... ... @@ -17,67 +22,4 @@ public class MechineInfo {
private String updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getHostIp() {
return hostIp;
}
public void setHostIp(String hostIp) {
this.hostIp = hostIp;
}
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
public int getCloudType() {
return cloudType;
}
public void setCloudType(int cloudType) {
this.cloudType = cloudType;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
package com.monitor.mysql.mapper;
import com.model.HostGroup;
import java.util.List;
public interface HostGroupMapper {
int deleteByPrimaryKey(Integer id);
int insert(HostGroup record);
int insertSelective(HostGroup record);
HostGroup selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(HostGroup record);
int updateByPrimaryKey(HostGroup record);
List<HostGroup> selectHostGroups();
}
\ No newline at end of file
... ...
package com.monitor.mysql.mapper;
import com.model.MechineGroup;
import java.util.List;
public interface MechineGroupMapper {
int deleteByPrimaryKey(Integer id);
int insert(MechineGroup record);
int insertSelective(MechineGroup record);
MechineGroup selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(MechineGroup record);
int updateByPrimaryKey(MechineGroup record);
List<MechineGroup> selectMechineGroups();
}
\ 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.MechineGroupMapper" >
<resultMap id="BaseResultMap" type="com.model.MechineGroup" >
<mapper namespace="com.monitor.mysql.mapper.HostGroupMapper" >
<resultMap id="BaseResultMap" type="com.model.HostGroup" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="group_name" property="groupName" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
... ... @@ -11,23 +11,23 @@
id, group_name, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
select
<include refid="Base_Column_List" />
from mechine_group
from host_group
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from mechine_group
delete from host_group
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.model.MechineGroup" >
insert into mechine_group (id, group_name, create_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{groupName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP})
<insert id="insert" parameterType="com.model.HostGroup" >
insert into host_group (id, group_name, create_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{groupName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.model.MechineGroup" >
insert into mechine_group
<insert id="insertSelective" parameterType="com.model.HostGroup" >
insert into host_group
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
... ... @@ -57,8 +57,8 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.MechineGroup" >
update mechine_group
<update id="updateByPrimaryKeySelective" parameterType="com.model.HostGroup" >
update host_group
<set >
<if test="groupName != null" >
group_name = #{groupName,jdbcType=VARCHAR},
... ... @@ -72,17 +72,17 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.model.MechineGroup" >
update mechine_group
<update id="updateByPrimaryKey" parameterType="com.model.HostGroup" >
update host_group
set group_name = #{groupName,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectMechineGroups" resultMap="BaseResultMap">
<select id="selectHostGroups" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from mechine_group
from host_group
</select>
</mapper>
\ No newline at end of file
... ...