Authored by FengRuwei

java服务 增删改

package com.monitor.cmdb.ctrl;
import com.model.HostInfo;
import com.model.JavaApiInfo;
import com.monitor.cmdb.service.IJavaApiInfoService;
import com.monitor.cmdb.service.impl.JavaApiInfoService;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Created by fruwei on 2016/6/20.
*/
@RestController
@RequestMapping(value = "/javaApi")
public class JavaApiInfoCtrl {
Logger log = LoggerFactory.getLogger(JavaApiInfoCtrl.class);
@Autowired
private IJavaApiInfoService javaApiInfoService;
@RequestMapping("/query")
@ResponseBody
public BaseResponse<PageResponse<JavaApiInfo>> getJavaApiInfos(@RequestBody JavaApiInfoReq req) throws Exception {
log.info("getJavaApiInfos with param is {}", req);
// 查询列表
PageResponse<JavaApiInfo> responseBO = javaApiInfoService.getJavaApiInfos(req);
if (responseBO == null || CollectionUtils.isEmpty(responseBO.getRows())) {
return new BaseResponse<PageResponse<JavaApiInfo>>();
}
PageResponse<JavaApiInfo> response = new PageResponse<JavaApiInfo>();
response.setCurrentPage(responseBO.getCurrentPage());
response.setRows(responseBO.getRows());
response.setPageSize(responseBO.getPageSize());
response.setTotal(responseBO.getTotal());
log.info("getJavaApiInfos success and total={}", response.getTotal());
return new BaseResponse<PageResponse<JavaApiInfo>>(response);
}
@RequestMapping("/save")
@ResponseBody
public BaseResponse<Integer> saveJavaApiInfo(@RequestBody JavaApiInfo req) throws Exception {
log.info("saveMechineInfo with param is {}", req);
return javaApiInfoService.saveJavaApiInfo(req);
}
@RequestMapping("/del")
@ResponseBody
public BaseResponse<Integer> delJavaApiInfo(@RequestParam(value = "id", required = true) Integer id) throws Exception {
log.info("delMechineInfo with param is {}", id);
return javaApiInfoService.delJavaApiInfo(id);
}
}
... ...
package com.monitor.cmdb.service;
import com.model.JavaApiInfo;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import java.util.List;
... ... @@ -19,5 +21,5 @@ public interface IJavaApiInfoService {
public BaseResponse<Integer> delJavaApiInfo(int id);
PageResponse<JavaApiInfo> getJavaApiInfos(JavaApiInfoReq req);
}
... ...
... ... @@ -2,11 +2,17 @@ package com.monitor.cmdb.service.impl;
import com.model.JavaApiInfo;
import com.monitor.cmdb.service.IJavaApiInfoService;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.JavaApiInfoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
... ... @@ -15,6 +21,7 @@ import java.util.List;
*/
@Service
public class JavaApiInfoService implements IJavaApiInfoService {
Logger log= LoggerFactory.getLogger(JavaApiInfoService.class);
@Autowired
private JavaApiInfoMapper javaApiInfoMapper;
@Override
... ... @@ -44,4 +51,33 @@ public class JavaApiInfoService implements IJavaApiInfoService {
return new BaseResponse<Integer>(result);
}
@Override
public PageResponse<JavaApiInfo> getJavaApiInfos(JavaApiInfoReq req) {
log.info("get api infos with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = javaApiInfoMapper.selectCountByCodition(page);
log.info("get api infos num is {}, with param is {}", total,
req);
// 数量为0 直接返回
if (total == 0) {
return null;
}
// 获取列表
List<JavaApiInfo> JavaApiInfo = javaApiInfoMapper.selectJavaInfosByCodition(page);
if (CollectionUtils.isEmpty(JavaApiInfo)) {
log.debug("get api infos is null with param is {}", req);
return null;
}
PageResponse<JavaApiInfo> response = new PageResponse<JavaApiInfo>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(JavaApiInfo);
return response;
}
}
... ...
... ... @@ -19,7 +19,7 @@ public class ScheduledPlan {
JavaApiClient javaApiClient;
@Scheduled(fixedRate=10000)
@Scheduled(fixedRate=60000*3)
public void run() {
log.info("task start...");
... ...
... ... @@ -147,17 +147,32 @@ public class JavaApiClient {
//
// mObjInfoMap.add(1, mObj2);
MObjectInfo mObj2 = new MObjectInfo();
mObj2.setMoId(0);
mObj2.setMoHostIp("localhost");
mObj2.setMoTags("10080");
mObj2.setMoName("gay");
mObj2.setMoTypeId(0);
mObjInfoMap.add(0, mObj2);
int uid = 8041886;
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 1; i++) {
JavaApiInfo javaApiInfo = new JavaApiInfo();
javaApiInfo.setApiName("order.get_" + i);
javaApiInfo.setApiReqMethod(0);
javaApiInfo.setApiToggle(0);
javaApiInfo.setApiUrl("/gateway/?debug=XYZ&method=app.Shopping.listCoupon&uid=" + (uid++));
javaApiInfo.setServiceType(1);
javaApimap.put("order.get_" + i, javaApiInfo);
javaApimap.put(javaApiInfo.getApiName(), javaApiInfo);
}
JavaApiInfo javaApiInfo = new JavaApiInfo();
javaApiInfo.setApiName("frw.test");
javaApiInfo.setApiReqMethod(0);
javaApiInfo.setApiToggle(0);
javaApiInfo.setApiUrl("/gay/time/get?second=40");
javaApiInfo.setServiceType(0);
javaApimap.put(javaApiInfo.getApiName(), javaApiInfo);
}
... ...
package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
import lombok.Data;
/**
* Created by fruwei on 2016/6/20.
*/
@Data
public class JavaApiInfoReq extends PageRequest {
private Integer serviceId;
private Integer serviceType;
private String apiName;
private String apiUrl;
private String apiData;
private Integer apiToggle;
private Integer apiReqMethod;
private Integer apiWarnTrigger;
}
... ...
... ... @@ -17,6 +17,8 @@ public class JavaApiInfo {
private Integer apiReqMethod;
private Integer apiWarnTrigger;
public Integer getServiceId() {
return serviceId;
}
... ... @@ -77,4 +79,12 @@ public class JavaApiInfo {
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
public Integer getApiWarnTrigger() {
return apiWarnTrigger;
}
public void setApiWarnTrigger(Integer apiWarnTrigger) {
this.apiWarnTrigger = apiWarnTrigger;
}
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.mysql.mapper;
import com.model.JavaApiInfo;
import com.monitor.model.domain.PageBean;
import java.util.List;
... ... @@ -19,4 +20,8 @@ public interface JavaApiInfoMapper {
int updateByPrimaryKey(JavaApiInfo record);
List<JavaApiInfo> selectAllApi();
int selectCountByCodition(PageBean page);
List<JavaApiInfo> selectJavaInfosByCodition(PageBean page);
}
\ 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.JavaApiInfoMapper" >
<resultMap id="BaseResultMap" type="com.model.JavaApiInfo" >
<id column="service_id" property="serviceId" jdbcType="INTEGER" />
<result column="service_type" property="serviceType" jdbcType="INTEGER" />
<result column="api_name" property="apiName" jdbcType="VARCHAR" />
<result column="api_url" property="apiUrl" jdbcType="VARCHAR" />
<result column="api_data" property="apiData" jdbcType="VARCHAR" />
<result column="api_toggle" property="apiToggle" jdbcType="INTEGER" />
<result column="api_req_method" property="apiReqMethod" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
<mapper namespace="com.monitor.mysql.mapper.JavaApiInfoMapper">
<resultMap id="BaseResultMap" type="com.model.JavaApiInfo">
<id column="service_id" property="serviceId" jdbcType="INTEGER"/>
<result column="service_type" property="serviceType" jdbcType="INTEGER"/>
<result column="api_name" property="apiName" jdbcType="VARCHAR"/>
<result column="api_url" property="apiUrl" jdbcType="VARCHAR"/>
<result column="api_data" property="apiData" jdbcType="VARCHAR"/>
<result column="api_toggle" property="apiToggle" jdbcType="INTEGER"/>
<result column="api_req_method" property="apiReqMethod" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
service_id, service_type, api_name, api_url, api_data, api_toggle, api_req_method
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from java_api_info
where service_id = #{serviceId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from java_api_info
where service_id = #{serviceId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from java_api_info
where service_id = #{serviceId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.model.JavaApiInfo" >
<insert id="insert" parameterType="com.model.JavaApiInfo">
insert into java_api_info (service_id, service_type, api_name,
api_url, api_data, api_toggle,
api_req_method)
... ... @@ -31,80 +31,80 @@
#{apiUrl,jdbcType=VARCHAR}, #{apiData,jdbcType=VARCHAR}, #{apiToggle,jdbcType=INTEGER},
#{apiReqMethod,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.model.JavaApiInfo" >
insert into java_api_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="serviceId != null" >
service_id,
</if>
<if test="serviceType != null" >
service_type,
</if>
<if test="apiName != null" >
api_name,
</if>
<if test="apiUrl != null" >
api_url,
</if>
<if test="apiData != null" >
api_data,
</if>
<if test="apiToggle != null" >
api_toggle,
</if>
<if test="apiReqMethod != null" >
api_req_method,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="serviceId != null" >
#{serviceId,jdbcType=INTEGER},
</if>
<if test="serviceType != null" >
#{serviceType,jdbcType=INTEGER},
</if>
<if test="apiName != null" >
#{apiName,jdbcType=VARCHAR},
</if>
<if test="apiUrl != null" >
#{apiUrl,jdbcType=VARCHAR},
</if>
<if test="apiData != null" >
#{apiData,jdbcType=VARCHAR},
</if>
<if test="apiToggle != null" >
#{apiToggle,jdbcType=INTEGER},
</if>
<if test="apiReqMethod != null" >
#{apiReqMethod,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.JavaApiInfo" >
update java_api_info
<set >
<if test="serviceType != null" >
service_type = #{serviceType,jdbcType=INTEGER},
</if>
<if test="apiName != null" >
api_name = #{apiName,jdbcType=VARCHAR},
</if>
<if test="apiUrl != null" >
api_url = #{apiUrl,jdbcType=VARCHAR},
</if>
<if test="apiData != null" >
api_data = #{apiData,jdbcType=VARCHAR},
</if>
<if test="apiToggle != null" >
api_toggle = #{apiToggle,jdbcType=INTEGER},
</if>
<if test="apiReqMethod != null" >
api_req_method = #{apiReqMethod,jdbcType=INTEGER},
</if>
</set>
where service_id = #{serviceId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.model.JavaApiInfo" >
<insert id="insertSelective" parameterType="com.model.JavaApiInfo">
insert into java_api_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="serviceId != null">
service_id,
</if>
<if test="serviceType != null">
service_type,
</if>
<if test="apiName != null">
api_name,
</if>
<if test="apiUrl != null">
api_url,
</if>
<if test="apiData != null">
api_data,
</if>
<if test="apiToggle != null">
api_toggle,
</if>
<if test="apiReqMethod != null">
api_req_method,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="serviceId != null">
#{serviceId,jdbcType=INTEGER},
</if>
<if test="serviceType != null">
#{serviceType,jdbcType=INTEGER},
</if>
<if test="apiName != null">
#{apiName,jdbcType=VARCHAR},
</if>
<if test="apiUrl != null">
#{apiUrl,jdbcType=VARCHAR},
</if>
<if test="apiData != null">
#{apiData,jdbcType=VARCHAR},
</if>
<if test="apiToggle != null">
#{apiToggle,jdbcType=INTEGER},
</if>
<if test="apiReqMethod != null">
#{apiReqMethod,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.JavaApiInfo">
update java_api_info
<set>
<if test="serviceType != null">
service_type = #{serviceType,jdbcType=INTEGER},
</if>
<if test="apiName != null">
api_name = #{apiName,jdbcType=VARCHAR},
</if>
<if test="apiUrl != null">
api_url = #{apiUrl,jdbcType=VARCHAR},
</if>
<if test="apiData != null">
api_data = #{apiData,jdbcType=VARCHAR},
</if>
<if test="apiToggle != null">
api_toggle = #{apiToggle,jdbcType=INTEGER},
</if>
<if test="apiReqMethod != null">
api_req_method = #{apiReqMethod,jdbcType=INTEGER},
</if>
</set>
where service_id = #{serviceId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.model.JavaApiInfo">
update java_api_info
set service_type = #{serviceType,jdbcType=INTEGER},
api_name = #{apiName,jdbcType=VARCHAR},
... ... @@ -115,11 +115,64 @@
where service_id = #{serviceId,jdbcType=INTEGER}
</update>
<select id="selectAllApi" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from java_api_info
</select>
<select id="selectAllApi" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from java_api_info
</select>
<select id="selectCountByCodition" resultType="java.lang.Integer">
select
count(1)
from java_api_info
where
1=1
<if test="params.serviceType != null">
and service_type = #{params.serviceType,jdbcType=INTEGER}
</if>
<if test="params.apiName != null">
and api_name = #{params.apiName,jdbcType=VARCHAR}
</if>
<if test="params.apiUrl != null">
and api_url = #{params.apiUrl,jdbcType=VARCHAR}
</if>
<if test="params.apiData != null">
and api_data = #{params.apiData,jdbcType=VARCHAR}
</if>
<if test="params.apiToggle != null">
and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
</if>
<if test="params.apiReqMethod != null">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
</select>
<select id="selectJavaInfosByCodition" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from java_api_info
where
1=1
<if test="params.serviceType != null">
and service_type = #{params.serviceType,jdbcType=INTEGER}
</if>
<if test="params.apiName != null">
and api_name = #{params.apiName,jdbcType=VARCHAR}
</if>
<if test="params.apiUrl != null">
and api_url = #{params.apiUrl,jdbcType=VARCHAR}
</if>
<if test="params.apiData != null">
and api_data = #{params.apiData,jdbcType=VARCHAR}
</if>
<if test="params.apiToggle != null">
and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
</if>
<if test="params.apiReqMethod != null">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
limit #{startIndex},#{pageSize}
</select>
</mapper>
\ No newline at end of file
... ...