Authored by jack.xue

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -12,7 +12,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.model.ZkConfig;
import com.model.ZkConfigAll;
import com.monitor.cmdb.service.IZkMoitorService;
import com.monitor.model.request.ZkTreeAllReq;
import com.monitor.model.request.ZkTreeReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
... ... @@ -44,7 +46,12 @@ public class ZkMonitorCtrl {
return new BaseResponse<Object>(response);
}
/**
* 查询选中Ip下的根节点
* @param req
* @return
* @throws Exception
*/
@RequestMapping("/getZkMonitorTree")
@ResponseBody
public BaseResponse<PageResponse<ZkConfig>> getZkMonitorTree(@RequestBody ZkTreeReq req) throws Exception {
... ... @@ -60,6 +67,58 @@ public class ZkMonitorCtrl {
response.setTotal(list.getTotal());
return new BaseResponse<PageResponse<ZkConfig>>(response);
}
/**
* 查询跟节点下的所有子节点的路径和值
* @param req
* @return
* @throws Exception
*/
@RequestMapping("/getZkMonitorDetail")
@ResponseBody
public BaseResponse<PageResponse<ZkConfigAll>> getZkMonitorDetail(@RequestBody ZkTreeAllReq req) throws Exception {
log.debug("getZkMonitorTree with req is {}",req);
PageResponse<ZkConfigAll> list = zkMoitorService.getZkMonitorDetail(req);
if(list==null){
return new BaseResponse<PageResponse<ZkConfigAll>>();
}
PageResponse<ZkConfigAll> response = new PageResponse<ZkConfigAll>();
response.setCurrentPage(list.getCurrentPage());
response.setRows(list.getRows());
response.setPageSize(list.getPageSize());
response.setTotal(list.getTotal());
return new BaseResponse<PageResponse<ZkConfigAll>>(response);
}
/**
* 修改某个子节点的值
* @param req
* @return
* @throws Exception
*/
@RequestMapping("/editZkMonitorDetail")
@ResponseBody
public BaseResponse<Object> editZkMonitorDetail(@RequestBody ZkTreeAllReq req) throws Exception {
log.debug("editZkMonitorDetail with req is {}",req);
int result = zkMoitorService.editZkMonitorDetail(req);
return new BaseResponse<Object>(result);
}
/**
* 修改根节点的路径
* @param req
* @return
* @throws Exception
*/
@RequestMapping("/editZkMonitorRoot")
@ResponseBody
public BaseResponse<Object> editZkMonitorRoot(@RequestBody ZkTreeReq req) throws Exception {
log.debug("editZkMonitorRoot with req is {}",req);
int result = zkMoitorService.editZkMonitorRoot(req);
return new BaseResponse<Object>(result);
}
}
... ...
... ... @@ -3,6 +3,8 @@ package com.monitor.cmdb.service;
import java.util.Map;
import com.model.ZkConfig;
import com.model.ZkConfigAll;
import com.monitor.model.request.ZkTreeAllReq;
import com.monitor.model.request.ZkTreeReq;
import com.monitor.model.response.PageResponse;
... ... @@ -14,4 +16,10 @@ public interface IZkMoitorService {
Map<String,Object> getZkMonitorRecords();
PageResponse<ZkConfig> getZkMonitorTree(ZkTreeReq req);
PageResponse<ZkConfigAll> getZkMonitorDetail(ZkTreeAllReq req);
int editZkMonitorDetail(ZkTreeAllReq req);
int editZkMonitorRoot(ZkTreeReq req);
}
... ...
... ... @@ -18,9 +18,11 @@ import org.springframework.util.CollectionUtils;
import com.model.MObjectInfo;
import com.model.ZkConfig;
import com.model.ZkConfigAll;
import com.monitor.cmdb.service.IZkMoitorService;
import com.monitor.influxdb.mapper.IZkMapper;
import com.monitor.influxdb.model.ZkInfo;
import com.monitor.model.request.ZkTreeAllReq;
import com.monitor.model.request.ZkTreeReq;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.MObjectInfoMapper;
... ... @@ -83,7 +85,7 @@ public class ZkMoitorServiceImpl implements IZkMoitorService {
String rootString = "";
int page=0;
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.102.205"+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
CuratorFramework client = CuratorFrameworkFactory.newClient(req.getIp()+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
client.start();
try {
List<String> children = client.getChildren().forPath(root);
... ... @@ -93,6 +95,7 @@ public class ZkMoitorServiceImpl implements IZkMoitorService {
rootString = root+"/"+chi;
zkConfig.setName(chi);
zkConfig.setRoot(rootString);
zkConfig.setIp(req.getIp());
list.add(zkConfig);
page++;
}
... ... @@ -103,11 +106,160 @@ public class ZkMoitorServiceImpl implements IZkMoitorService {
response.setRows(list);
} catch (Exception e) {
logger.error("getZkMonitorTree fail with ip is {}",req.getIp());
e.printStackTrace();
} finally {
client.close();
}
return response;
}
@Override
public PageResponse<ZkConfigAll> getZkMonitorDetail(ZkTreeAllReq req) {
PageResponse<ZkConfigAll> response = new PageResponse<ZkConfigAll>();
List<ZkConfigAll> list = new ArrayList<ZkConfigAll>();
int page=0;
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client = CuratorFrameworkFactory.newClient(req.getIp()+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
client.start();
try {
list=getAllChildren(req.getZkPath(),client,req.getIp());
for(ZkConfigAll zk:list){
zk.getCurrentPage();
page++;
}
if (list.size()>10&&req.getCurrentPage()*10<list.size()) {
list=list.subList(req.getCurrentPage()*10-10, req.getCurrentPage()*10);
}else if (req.getCurrentPage()*10>list.size()) {
list=list.subList(req.getCurrentPage()*10-10, list.size());
}
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(page);
response.setRows(list);
} catch (Exception e) {
logger.error("getZkMonitorDetail fail with ip is {} and path is {}",req.getIp(),req.getZkPath());
e.printStackTrace();
}finally {
client.close();
}
return response;
}
public List<ZkConfigAll> getAllChildren(String parentPath,CuratorFramework client,String ip) {
List<ZkConfigAll> childList=new ArrayList<ZkConfigAll>();
try {
//取该路径下的所有子节点
List<String> childNodeNames=client.getChildren().forPath(parentPath);
for(String nodeName: childNodeNames){
//拼接路径
String nodePath=parentPath.concat("/").concat(nodeName);
ZkConfigAll zkNode=new ZkConfigAll();
zkNode.setZkPath(nodePath);
zkNode.setIp(ip);
String data =new String(client.getData().forPath(nodePath),"UTF-8");
zkNode.setZkValue(data);
List<String> liString = client.getChildren().forPath(nodePath);
if(CollectionUtils.isEmpty(liString)){
childList.add(zkNode);
}else {
//递归
childList.addAll(getAllChildren(nodePath, client,ip));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return childList;
}
@Override
public int editZkMonitorDetail(ZkTreeAllReq req) {
int result = 0;
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client = CuratorFrameworkFactory.newClient(req.getIp()+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
client.start();
try {
byte[] data = req.getZkValue().getBytes();
client.setData().forPath(req.getZkPath(), data);
String newData = new String(client.getData().forPath(req.getZkPath()));
if(newData.equals(req.getZkValue())){
result=1;
}
} catch (Exception e) {
logger.error("editZkMonitorDetail fail with data is {}",req.getZkValue());
e.printStackTrace();
}finally {
client.close();
}
return result;
}
@Override
public int editZkMonitorRoot(ZkTreeReq req) {
int result = 0;
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client = CuratorFrameworkFactory.newClient(req.getIp()+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
client.start();
try {
List<ZkConfigAll> childList=getAllChildren(req,client);
//将原来节点的值重新创建到新的节点上
client.create().creatingParentContainersIfNeeded().forPath(req.getRoot(),client.getData().forPath(req.getOldRoot()));
for(ZkConfigAll zkNode:childList)
{
String path=zkNode.getZkPath().replaceFirst(req.getOldRoot(), req.getRoot());
client.create().forPath(path,zkNode.getZkValue().getBytes());
}
client.delete().deletingChildrenIfNeeded().forPath(req.getOldRoot());
result =1;
} catch (Exception e) {
logger.error("editZkMonitorRoot fail with oldRoot is {}",req.getOldRoot());
} finally {
client.close();
}
return result;
}
public List<ZkConfigAll> getAllChildren(ZkTreeReq req,CuratorFramework client) {
List<ZkConfigAll> childList=new ArrayList<ZkConfigAll>();
try {
//取该路径下的所有子节点
List<String> childNodeNames=client.getChildren().forPath(req.getOldRoot());
for(String nodeName: childNodeNames)
{
//拼接路径
String nodePath=req.getOldRoot().concat("/").concat(nodeName);
ZkConfigAll zkNode=new ZkConfigAll();
zkNode.setZkPath(nodePath);
String data =new String(client.getData().forPath(nodePath),"UTF-8");
zkNode.setZkValue(data);
childList.add(zkNode);
//递归
childList.addAll(getAllChildren(req,client));
}
} catch (Exception e) {
logger.error("getAllChildren fail");
e.printStackTrace();
}
return childList;
}
}
... ...
... ... @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.model.MObjectInfo;
import com.model.RedisMonitor;
import com.model.TypeInfo;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.common.util.HttpRestClient;
import com.monitor.common.util.RedisCommonUtil;
import com.monitor.common.util.TelnetUtils;
... ... @@ -43,13 +45,19 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
@Autowired
RedisMonitorMapper redisMonitorMapper;
@Autowired
public AlarmMsgService alarmMsgService;
@Autowired
private SnsMobileConfig snsMobileConfig;
@Override
public void redisMonitor() {
List<RedisMonitor> redisInfoList=new ArrayList<RedisMonitor>();
int twemproxyAlarmCount=0;
int redisAlarmCount=0;
int slaveAramCount=0;
List<String> twemproxyAlarmList=new ArrayList<String>();
List<String> redisAlarmList=new ArrayList<String>();
List<String> slaveAlarmList=new ArrayList<String>();
TypeInfo typeInfo=mTypeInfoMapper.selectTypeInfoByName("redis");
if(typeInfo==null){
... ... @@ -101,7 +109,6 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
String result= TelnetUtils.getResult(obj.getMoHostIp(),Integer.valueOf(ports[0]));
redisMonitor = new RedisMonitor();
if(StringUtils.isNotBlank(result)){
paramMonitor.append("1,");
boolean proxyFlag=RedisCommonUtil.getRedisIsSlave(obj.getMoHostIp(),Integer.valueOf(ports[1]));
if(proxyFlag){
paramMonitor.append("探测成功;");
... ... @@ -134,9 +141,9 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
redisMonitor.setParamMonitor(paramMonitor.toString());
}
}else{
twemproxyAlarmCount++;
twemproxyAlarmList.add("失败:"+obj.getMoHostIp()+":"+ports[0]);
redisMonitor.setIsFailed(0);
redisMonitor.setParamMonitor("0,");
redisMonitor.setParamMonitor(obj.getMoHostIp()+":"+obj.getMoTags());
}
redisMonitor.setNodeFrom(redisTweproxyMap.get(obj.getMoTypeId()));
redisMonitor.setNodeTo(obj.getMoHostIp()+":"+ports[1]);
... ... @@ -166,7 +173,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
result= RedisCommonUtil.getRedisInfo(ipConfig[0], Integer.valueOf(ipConfig[1]));
paramMonitor=new StringBuffer();
if(null==result){
redisAlarmCount++;
redisAlarmList.add(ipConfig[0]+":"+ipConfig[1]+",");
paramMonitor.append("0,");
}else{
isFailed=1;
... ... @@ -200,6 +207,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
if(flag){
msg="OK";
}else{
slaveAlarmList.add("主"+result.get("master_host").toString()+":"+result.get("master_port").toString()+",从"+ ipConfig[0]+":"+ipConfig[1]+",");
msg="ERROR";
}
redisInfoList.add(new RedisMonitor(ipConfig[0]+":"+ipConfig[1],result.get("master_host").toString()+":"+result.get("master_port").toString(),2,isFailed,1,Integer.valueOf(ipConfig[2]),msg));
... ... @@ -219,5 +227,39 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
redisMonitorMapper.deleteAllRedisMonitor();
redisMonitorMapper.bachInsertRedisMonitor(redisInfoList);
}
/**********************************************************************
*4、告警
***********************************************************************/
StringBuffer alrarmMsg=new StringBuffer("");
if(!CollectionUtils.isEmpty(twemproxyAlarmList)){
alrarmMsg.append("twemproxy:");
for(String str:twemproxyAlarmList){
alrarmMsg.append(str);
}
alrarmMsg.append("失败;");
}
if(!CollectionUtils.isEmpty(redisAlarmList)){
alrarmMsg.append("redis:");
for(String str:redisAlarmList){
alrarmMsg.append(str);
}
alrarmMsg.append("失败;");
}
if(!CollectionUtils.isEmpty(slaveAlarmList)){
alrarmMsg.append("主从:");
for(String str:slaveAlarmList){
alrarmMsg.append(str);
}
alrarmMsg.append("失败;");
}
log.info("sms redis start info {}",alrarmMsg.toString());
if(StringUtils.isNotBlank(alrarmMsg.toString())) {
alrarmMsg.append("请您及时查看!");
alarmMsgService.sendSms("redis", alrarmMsg.toString(), snsMobileConfig.getBaseMobile());
}
}
}
... ...
package com.monitor.model.request;
import lombok.Data;
import com.monitor.model.page.PageRequest;
@Data
public class ZkTreeAllReq extends PageRequest{
private String ip;
private String zkPath;
private String zkValue;
}
... ...
... ... @@ -12,4 +12,6 @@ public class ZkTreeReq extends PageRequest{
private String name;
private String root;
private String oldRoot;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/7/14.
*/
@Data
public class AuthModule {
private int id;
private String moduleName;
private int moduleLevel;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/7/13.
*/
@Data
public class User {
private int id;
private String name;
private String pwd;
private int level;
}
... ...
... ... @@ -7,7 +7,8 @@ import com.monitor.model.page.PageRequest;
import lombok.Data;
@Data
public class ZkConfig extends PageRequest implements Serializable{
private String ip;
private String name;
... ...
package com.model;
import java.io.Serializable;
import lombok.Data;
import com.monitor.model.page.PageRequest;
@Data
public class ZkConfigAll extends PageRequest implements Serializable {
private String ip;
private String zkValue;
private String zkPath;
}
... ...
package com.monitor.mysql.mapper;
import com.model.AuthModule;
import com.model.User;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by zhengyouwei on 2016/7/13.
*/
public interface AuthModuleMapper {
int insert(AuthModule authModule);
int updateLevel(AuthModule authModule);
List<AuthModule> selectAll();
AuthModule selectByName(@Param("moduleName") String moduleName);
AuthModule selectById(@Param("id") int id);
}
... ...
package com.monitor.mysql.mapper;
import com.model.User;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by zhengyouwei on 2016/7/13.
*/
public interface UserMapper {
int insert(User user);
int updatePwd(User user);
int updateLevel(User user);
int deleteByName(@Param("name") String name);
int deleteById(@Param("id") int id);
List<User> selectAll();
User selectByName(@Param("name") String name);
User selectById(@Param("id") int id);
}
... ...
<?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.AuthModuleMapper" >
<resultMap id="BaseResultMap" type="com.model.AuthModule" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="module_name" property="moduleName" jdbcType="VARCHAR" />
<result column="module_level" property="moduleLevel" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, module_name, module_level
</sql>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from auth_module
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from auth_module
where module_name = #{moduleName,jdbcType=VARCHAR}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from auth_module
</select>
<insert id="insert" parameterType="com.model.AuthModule" >
insert into auth_module
(module_name,module_level, create_time, update_time)
values
(#{moduleName,jdbcType=VARCHAR},#{moduleLevel,jdbcType=INTEGER}, now(),now())
</insert>
<update id="updateLevel" parameterType="com.model.AuthModule" >
update auth_module
set module_level = #{moduleLevel,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ 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.UserMapper" >
<resultMap id="BaseResultMap" type="com.model.User" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="pwd" property="pwd" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, name, pwd, level
</sql>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from user
where name = #{name,jdbcType=VARCHAR}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
</select>
<delete id="deleteById" parameterType="java.lang.Integer" >
delete from user
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByName" parameterType="java.lang.String" >
delete from user
where name = #{name,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.model.User" >
insert into user
(name,pwd,level, create_time, update_time)
values
(#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER}, now(),now())
</insert>
<update id="updatePwd" parameterType="com.model.User" >
update user
set pwd = #{pwd,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateLevel" parameterType="com.model.User" >
update user
set level = #{level,jdbcType=INTEGER},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>monitor-service-parent</artifactId>
<groupId>monitor-service</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>monitor-service-user</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--项目内部依赖-->
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-common</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-mysql</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-influxdb</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-model</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.user.ctrl;
import com.model.AuthModule;
import com.model.User;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.AuthModuleMapper;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("module")
public class ModuleCtrl {
Logger log = LoggerFactory.getLogger(ModuleCtrl.class);
@Autowired
AuthModuleMapper authModuleMapper;
@RequestMapping("/getAll")
@ResponseBody
public BaseResponse getAll() {
try{
List<AuthModule> list=authModuleMapper.selectAll();
if (list == null || CollectionUtils.isEmpty(list)) {
return new BaseResponse<List<User>>();
}
return new BaseResponse<List<AuthModule>>(list);
}catch (Exception e){
log.error("getAll error",e);
return null;
}
}
@RequestMapping("/getAuthModuleByName")
@ResponseBody
public BaseResponse getAuthModuleByName(String name) {
try{
AuthModule authModule=authModuleMapper.selectByName(name);
return new BaseResponse<AuthModule>(authModule);
}catch (Exception e){
log.error("getAuthModuleByName error",e);
return null;
}
}
@RequestMapping("/getAuthModuleById")
@ResponseBody
public BaseResponse getAuthModuleById(int id) {
try{
AuthModule authModule=authModuleMapper.selectById(id);
return new BaseResponse<AuthModule>(authModule);
}catch (Exception e){
log.error("getAuthModuleById error",e);
return null;
}
}
@RequestMapping("/insert")
@ResponseBody
public BaseResponse insert(@RequestBody AuthModule authModule) {
try{
int result = authModuleMapper.insert(authModule);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/updateLevel")
@ResponseBody
public BaseResponse updateLevel(@RequestBody AuthModule authModule) {
try{
int result = authModuleMapper.updateLevel( authModule);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("updateLevel error",e);
return null;
}
}
}
... ...
package com.monitor.user.ctrl;
import com.model.User;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.UserMapper;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("user")
public class UserCtrl {
Logger log = LoggerFactory.getLogger(UserCtrl.class);
@Autowired
UserMapper userMapper;
@RequestMapping("/getAllUser")
@ResponseBody
public BaseResponse getAllUser() {
try{
List<User> list=userMapper.selectAll();
if (list == null || CollectionUtils.isEmpty(list)) {
return new BaseResponse<List<User>>();
}
return new BaseResponse<List<User>>(list);
}catch (Exception e){
log.error("getAllUser error",e);
return null;
}
}
@RequestMapping("/getUserByName")
@ResponseBody
public BaseResponse getUserByName(String name) {
try{
User user=userMapper.selectByName(name);
return new BaseResponse<User>(user);
}catch (Exception e){
log.error("getUserByName error",e);
return null;
}
}
@RequestMapping("/getUserById")
@ResponseBody
public BaseResponse getUserById(int id) {
try{
User user=userMapper.selectById(id);
return new BaseResponse<User>(user);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/insert")
@ResponseBody
public BaseResponse insert(@RequestBody User user) {
try{
int result = userMapper.insert(user);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/updatePwd")
@ResponseBody
public BaseResponse updatePwd(@RequestBody User user) {
try{
int result = userMapper.updatePwd(user);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/updateLevel")
@ResponseBody
public BaseResponse updateAuth(@RequestBody User user) {
try{
int result = userMapper.updateLevel(user);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/deleteByName")
@ResponseBody
public BaseResponse deleteByName(String name) {
try{
int result = userMapper.deleteByName(name);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
@RequestMapping("/deleteById")
@ResponseBody
public BaseResponse deleteById(int id) {
try{
int result = userMapper.deleteById(id);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
}
... ...
... ... @@ -43,6 +43,10 @@
<artifactId>monitor-service-switch</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-user</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
... ...
... ... @@ -110,6 +110,11 @@
<version>${project-version}</version>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-user</artifactId>
<version>${project-version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok-version}</version>
... ... @@ -137,6 +142,7 @@
<module>monitor-service-cmdb</module>
<module>monitor-service-model</module>
<module>monitor-service-middleware</module>
<module>monitor-service-user</module>
</modules>
... ...