Authored by FengRuwei

获取服务状态

package com.monitor.javaserver.ctrl;
import com.monitor.javaserver.status.IJavaApiStatusService;
import com.monitor.model.request.JavaApiStatusListReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiStatusRep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by fruwei on 2016/6/21.
*/
@Controller
@RequestMapping("javaApiStatus")
public class JavaAppInfoCtrl {
@Autowired
IJavaApiStatusService javaApiStatusService;
@RequestMapping("/queryOne")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq req) {
BaseResponse rep = new BaseResponse();
try {
JavaApiStatusRep javaApiStatusRep = javaApiStatusService.getJavaApiStatus(req);
rep.setData(javaApiStatusRep);
} catch (Exception e) {
rep.setCode(400);
rep.setMessage(e.getMessage());
}
return rep;
}
@RequestMapping("/query")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq[] req) {
BaseResponse rep = new BaseResponse();
try {
List<JavaApiStatusReq> list= Arrays.asList(req);
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusList(list);
rep.setData(javaApiStatusRepList);
} catch (Exception e) {
rep.setCode(400);
rep.setMessage(e.getMessage());
}
return rep;
}
}
... ...
package com.monitor.javaserver.status;
import com.model.JavaApiInfo;
import com.monitor.model.request.JavaApiStatusListReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
import java.util.List;
/**
* Created by fruwei on 2016/6/21.
*/
public interface IJavaApiStatusService {
public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) ;
public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList) ;
}
... ...
package com.monitor.javaserver.status.impl;
import com.monitor.javaserver.status.IJavaApiStatusService;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Created by fruwei on 2016/6/21.
*/
@Component
public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
@Override
public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) {
JavaApiStatusRep rep = new JavaApiStatusRep();
if (req.getServiceId() == null || req.getMObjectId() == null)
return null;
rep.setServiceId(req.getServiceId());
rep.setMObjectId(req.getMObjectId());
Random rd = new Random();
//模拟
rep.setStatus((100 + rd.nextInt(100)) % 2);
return rep;
}
@Override
public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList) {
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
//模拟
for (JavaApiStatusReq req : reqList) {
JavaApiStatusRep rep = new JavaApiStatusRep();
rep.setServiceId(req.getServiceId());
rep.setMObjectId(req.getMObjectId());
Random rd = new Random();
rep.setStatus((100 + rd.nextInt(100)) % 2);
repList.add(rep);
}
return repList;
}
}
... ...
package com.monitor.model.request;
import lombok.Data;
import java.util.List;
/**
* Created by fruwei on 2016/6/21.
*/
@Data
public class JavaApiStatusListReq {
private List<JavaApiStatusReq> javaApiStatusReqList;
}
... ...
package com.monitor.model.request;
import lombok.Data;
/**
* Created by fruwei on 2016/6/21.
*/
@Data
public class JavaApiStatusReq {
private Integer serviceId;
private Integer serviceType;
private Integer mObjectId;
}
... ...
package com.monitor.model.response;
import lombok.Data;
/**
* Created by fruwei on 2016/6/21.
*/
@Data
public class JavaApiStatusRep {
private Integer serviceId;
private Integer serviceType;
private Integer mObjectId;
private Integer status;
}
... ...
package com.model;
import lombok.Data;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
@Data
public class JavaApiInfo {
private Integer serviceId;
... ... @@ -19,72 +21,11 @@ public class JavaApiInfo {
private Integer apiWarnTrigger;
public Integer getServiceId() {
return serviceId;
}
public void setServiceId(Integer serviceId) {
this.serviceId = serviceId;
}
public Integer getServiceType() {
return serviceType;
}
public void setServiceType(Integer serviceType) {
this.serviceType = serviceType;
}
public String getApiName() {
return apiName;
}
public void setApiName(String apiName) {
this.apiName = apiName == null ? null : apiName.trim();
}
public String getApiUrl() {
return apiUrl;
}
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl == null ? null : apiUrl.trim();
}
public String getApiData() {
return apiData;
}
public void setApiData(String apiData) {
this.apiData = apiData == null ? null : apiData.trim();
}
public Integer getApiToggle() {
return apiToggle;
}
public void setApiToggle(Integer apiToggle) {
this.apiToggle = apiToggle;
}
public Integer getApiReqMethod() {
return apiReqMethod;
}
public void setApiReqMethod(Integer apiReqMethod) {
this.apiReqMethod = apiReqMethod;
}
@Override
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
... ...
... ... @@ -9,9 +9,10 @@
<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"/>
<result column="api_warn_trigger" property="apiWarnTrigger" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
service_id, service_type, api_name, api_url, api_data, api_toggle, api_req_method
service_id, service_type, api_name, api_url, api_data, api_toggle, api_req_method,api_warn_trigger
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
... ... @@ -25,11 +26,11 @@
</delete>
<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)
api_url, api_data, api_toggle,
api_req_method,api_warn_trigger)
values (#{serviceId,jdbcType=INTEGER}, #{serviceType,jdbcType=INTEGER}, #{apiName,jdbcType=VARCHAR},
#{apiUrl,jdbcType=VARCHAR}, #{apiData,jdbcType=VARCHAR}, #{apiToggle,jdbcType=INTEGER},
#{apiReqMethod,jdbcType=INTEGER})
#{apiReqMethod,jdbcType=INTEGER},#{apiWarnTrigger,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.model.JavaApiInfo">
insert into java_api_info
... ... @@ -55,6 +56,9 @@
<if test="apiReqMethod != null">
api_req_method,
</if>
<if test="apiWarnTrigger != null">
api_warn_trigger,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="serviceId != null">
... ... @@ -78,6 +82,9 @@
<if test="apiReqMethod != null">
#{apiReqMethod,jdbcType=INTEGER},
</if>
<if test="apiWarnTrigger != null">
#{apiWarnTrigger,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.JavaApiInfo">
... ... @@ -101,6 +108,9 @@
<if test="apiReqMethod != null">
api_req_method = #{apiReqMethod,jdbcType=INTEGER},
</if>
<if test="apiWarnTrigger != null">
api_warn_trigger= #{apiWarnTrigger,jdbcType=INTEGER},
</if>
</set>
where service_id = #{serviceId,jdbcType=INTEGER}
</update>
... ... @@ -111,7 +121,8 @@
api_url = #{apiUrl,jdbcType=VARCHAR},
api_data = #{apiData,jdbcType=VARCHAR},
api_toggle = #{apiToggle,jdbcType=INTEGER},
api_req_method = #{apiReqMethod,jdbcType=INTEGER}
api_req_method = #{apiReqMethod,jdbcType=INTEGER},
api_warn_trigger= #{apiWarnTrigger,jdbcType=INTEGER}
where service_id = #{serviceId,jdbcType=INTEGER}
</update>
... ... @@ -146,6 +157,9 @@
<if test="params.apiReqMethod != null">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
<if test="params.apiWarnTrigger != null">
and api_warn_trigger = #{params.apiWarnTrigger,jdbcType=INTEGER}
</if>
</select>
<select id="selectJavaInfosByCodition" resultMap="BaseResultMap">
... ... @@ -172,6 +186,9 @@
<if test="params.apiReqMethod != null">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
<if test="params.apiWarnTrigger != null">
and api_warn_trigger = #{params.apiWarnTrigger,jdbcType=INTEGER}
</if>
limit #{startIndex},#{pageSize}
</select>
... ...
#---------jdbc config----------
local.jdbc.url=jdbc:mysql://localhost:3306/ops?characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
local.jdbc.url=jdbc:mysql://172.16.6.234:3306/yh_ops?characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
local.jdbc.user=root
local.jdbc.password=root
local.jdbc.password=123456
#---------jdbc config----------
\ No newline at end of file
... ...