Authored by fanzelei

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

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;
}
... ...
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>
... ...