Merge branch 'master' of http://git.yoho.cn/ops/monitor-service
Showing
11 changed files
with
471 additions
and
0 deletions
1 | +package com.monitor.mysql.mapper; | ||
2 | + | ||
3 | +import com.model.AuthModule; | ||
4 | +import com.model.User; | ||
5 | +import org.apache.ibatis.annotations.Param; | ||
6 | + | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +/** | ||
10 | + * Created by zhengyouwei on 2016/7/13. | ||
11 | + */ | ||
12 | +public interface AuthModuleMapper { | ||
13 | + | ||
14 | + int insert(AuthModule authModule); | ||
15 | + | ||
16 | + int updateLevel(AuthModule authModule); | ||
17 | + | ||
18 | + List<AuthModule> selectAll(); | ||
19 | + | ||
20 | + AuthModule selectByName(@Param("moduleName") String moduleName); | ||
21 | + | ||
22 | + AuthModule selectById(@Param("id") int id); | ||
23 | + | ||
24 | + | ||
25 | +} |
1 | +package com.monitor.mysql.mapper; | ||
2 | + | ||
3 | +import com.model.User; | ||
4 | +import org.apache.ibatis.annotations.Param; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +/** | ||
9 | + * Created by zhengyouwei on 2016/7/13. | ||
10 | + */ | ||
11 | +public interface UserMapper { | ||
12 | + | ||
13 | + int insert(User user); | ||
14 | + | ||
15 | + int updatePwd(User user); | ||
16 | + | ||
17 | + int updateLevel(User user); | ||
18 | + | ||
19 | + int deleteByName(@Param("name") String name); | ||
20 | + | ||
21 | + int deleteById(@Param("id") int id); | ||
22 | + | ||
23 | + List<User> selectAll(); | ||
24 | + | ||
25 | + User selectByName(@Param("name") String name); | ||
26 | + | ||
27 | + User selectById(@Param("id") int id); | ||
28 | + | ||
29 | + | ||
30 | +} |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | +<mapper namespace="com.monitor.mysql.mapper.AuthModuleMapper" > | ||
4 | + <resultMap id="BaseResultMap" type="com.model.AuthModule" > | ||
5 | + <id column="id" property="id" jdbcType="INTEGER" /> | ||
6 | + <result column="module_name" property="moduleName" jdbcType="VARCHAR" /> | ||
7 | + <result column="module_level" property="moduleLevel" jdbcType="INTEGER" /> | ||
8 | + </resultMap> | ||
9 | + <sql id="Base_Column_List" > | ||
10 | + id, module_name, module_level | ||
11 | + </sql> | ||
12 | + | ||
13 | + <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
14 | + select | ||
15 | + <include refid="Base_Column_List" /> | ||
16 | + from auth_module | ||
17 | + where id = #{id,jdbcType=INTEGER} | ||
18 | + </select> | ||
19 | + | ||
20 | + <select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" > | ||
21 | + select | ||
22 | + <include refid="Base_Column_List" /> | ||
23 | + from auth_module | ||
24 | + where module_name = #{moduleName,jdbcType=VARCHAR} | ||
25 | + </select> | ||
26 | + | ||
27 | + <select id="selectAll" resultMap="BaseResultMap"> | ||
28 | + select | ||
29 | + <include refid="Base_Column_List" /> | ||
30 | + from auth_module | ||
31 | + </select> | ||
32 | + | ||
33 | + <insert id="insert" parameterType="com.model.AuthModule" > | ||
34 | + insert into auth_module | ||
35 | + (module_name,module_level, create_time, update_time) | ||
36 | + values | ||
37 | + (#{moduleName,jdbcType=VARCHAR},#{moduleLevel,jdbcType=INTEGER}, now(),now()) | ||
38 | + </insert> | ||
39 | + | ||
40 | + <update id="updateLevel" parameterType="com.model.AuthModule" > | ||
41 | + update auth_module | ||
42 | + set module_level = #{moduleLevel,jdbcType=VARCHAR}, | ||
43 | + update_time = now() | ||
44 | + where id = #{id,jdbcType=INTEGER} | ||
45 | + </update> | ||
46 | + | ||
47 | +</mapper> |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | +<mapper namespace="com.monitor.mysql.mapper.UserMapper" > | ||
4 | + <resultMap id="BaseResultMap" type="com.model.User" > | ||
5 | + <id column="id" property="id" jdbcType="INTEGER" /> | ||
6 | + <result column="name" property="name" jdbcType="VARCHAR" /> | ||
7 | + <result column="pwd" property="pwd" jdbcType="VARCHAR" /> | ||
8 | + <result column="level" property="level" jdbcType="INTEGER" /> | ||
9 | + </resultMap> | ||
10 | + | ||
11 | + <sql id="Base_Column_List" > | ||
12 | + id, name, pwd, level | ||
13 | + </sql> | ||
14 | + | ||
15 | + <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
16 | + select | ||
17 | + <include refid="Base_Column_List" /> | ||
18 | + from user | ||
19 | + where id = #{id,jdbcType=INTEGER} | ||
20 | + </select> | ||
21 | + | ||
22 | + <select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" > | ||
23 | + select | ||
24 | + <include refid="Base_Column_List" /> | ||
25 | + from user | ||
26 | + where name = #{name,jdbcType=VARCHAR} | ||
27 | + </select> | ||
28 | + | ||
29 | + <select id="selectAll" resultMap="BaseResultMap"> | ||
30 | + select | ||
31 | + <include refid="Base_Column_List" /> | ||
32 | + from user | ||
33 | + </select> | ||
34 | + | ||
35 | + <delete id="deleteById" parameterType="java.lang.Integer" > | ||
36 | + delete from user | ||
37 | + where id = #{id,jdbcType=INTEGER} | ||
38 | + </delete> | ||
39 | + | ||
40 | + <delete id="deleteByName" parameterType="java.lang.String" > | ||
41 | + delete from user | ||
42 | + where name = #{name,jdbcType=VARCHAR} | ||
43 | + </delete> | ||
44 | + | ||
45 | + <insert id="insert" parameterType="com.model.User" > | ||
46 | + insert into user | ||
47 | + (name,pwd,level, create_time, update_time) | ||
48 | + values | ||
49 | + (#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER}, now(),now()) | ||
50 | + </insert> | ||
51 | + | ||
52 | + <update id="updatePwd" parameterType="com.model.User" > | ||
53 | + update user | ||
54 | + set pwd = #{pwd,jdbcType=VARCHAR}, | ||
55 | + update_time = now() | ||
56 | + where id = #{id,jdbcType=INTEGER} | ||
57 | + </update> | ||
58 | + | ||
59 | + <update id="updateLevel" parameterType="com.model.User" > | ||
60 | + update user | ||
61 | + set level = #{level,jdbcType=INTEGER}, | ||
62 | + update_time = now() | ||
63 | + where id = #{id,jdbcType=INTEGER} | ||
64 | + </update> | ||
65 | + | ||
66 | +</mapper> |
monitor-service-user/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
5 | + <parent> | ||
6 | + <artifactId>monitor-service-parent</artifactId> | ||
7 | + <groupId>monitor-service</groupId> | ||
8 | + <version>1.0-SNAPSHOT</version> | ||
9 | + </parent> | ||
10 | + <modelVersion>4.0.0</modelVersion> | ||
11 | + | ||
12 | + <artifactId>monitor-service-user</artifactId> | ||
13 | + <version>1.0-SNAPSHOT</version> | ||
14 | + | ||
15 | + <dependencies> | ||
16 | + | ||
17 | + <!--项目内部依赖--> | ||
18 | + <dependency> | ||
19 | + <groupId>monitor-service</groupId> | ||
20 | + <artifactId>monitor-service-common</artifactId> | ||
21 | + </dependency> | ||
22 | + <dependency> | ||
23 | + <groupId>monitor-service</groupId> | ||
24 | + <artifactId>monitor-service-mysql</artifactId> | ||
25 | + </dependency> | ||
26 | + <dependency> | ||
27 | + <groupId>monitor-service</groupId> | ||
28 | + <artifactId>monitor-service-influxdb</artifactId> | ||
29 | + </dependency> | ||
30 | + <dependency> | ||
31 | + <groupId>monitor-service</groupId> | ||
32 | + <artifactId>monitor-service-model</artifactId> | ||
33 | + </dependency> | ||
34 | +</dependencies> | ||
35 | +</project> |
1 | +package com.monitor.user.ctrl; | ||
2 | + | ||
3 | +import com.model.AuthModule; | ||
4 | +import com.model.User; | ||
5 | +import com.monitor.model.response.BaseResponse; | ||
6 | +import com.monitor.mysql.mapper.AuthModuleMapper; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Controller; | ||
11 | +import org.springframework.util.CollectionUtils; | ||
12 | +import org.springframework.web.bind.annotation.RequestBody; | ||
13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
15 | + | ||
16 | +import java.util.List; | ||
17 | + | ||
18 | +@Controller | ||
19 | +@RequestMapping("module") | ||
20 | +public class ModuleCtrl { | ||
21 | + | ||
22 | + Logger log = LoggerFactory.getLogger(ModuleCtrl.class); | ||
23 | + | ||
24 | + @Autowired | ||
25 | + AuthModuleMapper authModuleMapper; | ||
26 | + | ||
27 | + @RequestMapping("/getAll") | ||
28 | + @ResponseBody | ||
29 | + public BaseResponse getAll() { | ||
30 | + try{ | ||
31 | + List<AuthModule> list=authModuleMapper.selectAll(); | ||
32 | + | ||
33 | + if (list == null || CollectionUtils.isEmpty(list)) { | ||
34 | + return new BaseResponse<List<User>>(); | ||
35 | + } | ||
36 | + | ||
37 | + return new BaseResponse<List<AuthModule>>(list); | ||
38 | + }catch (Exception e){ | ||
39 | + log.error("getAll error",e); | ||
40 | + return null; | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + @RequestMapping("/getAuthModuleByName") | ||
45 | + @ResponseBody | ||
46 | + public BaseResponse getAuthModuleByName(String name) { | ||
47 | + try{ | ||
48 | + AuthModule authModule=authModuleMapper.selectByName(name); | ||
49 | + return new BaseResponse<AuthModule>(authModule); | ||
50 | + }catch (Exception e){ | ||
51 | + log.error("getAuthModuleByName error",e); | ||
52 | + return null; | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + @RequestMapping("/getAuthModuleById") | ||
57 | + @ResponseBody | ||
58 | + public BaseResponse getAuthModuleById(int id) { | ||
59 | + try{ | ||
60 | + AuthModule authModule=authModuleMapper.selectById(id); | ||
61 | + return new BaseResponse<AuthModule>(authModule); | ||
62 | + }catch (Exception e){ | ||
63 | + log.error("getAuthModuleById error",e); | ||
64 | + return null; | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + @RequestMapping("/insert") | ||
69 | + @ResponseBody | ||
70 | + public BaseResponse insert(@RequestBody AuthModule authModule) { | ||
71 | + try{ | ||
72 | + int result = authModuleMapper.insert(authModule); | ||
73 | + return new BaseResponse<Integer>(result); | ||
74 | + }catch (Exception e){ | ||
75 | + log.error("getUserById error",e); | ||
76 | + return null; | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | + @RequestMapping("/updateLevel") | ||
81 | + @ResponseBody | ||
82 | + public BaseResponse updateLevel(@RequestBody AuthModule authModule) { | ||
83 | + try{ | ||
84 | + int result = authModuleMapper.updateLevel( authModule); | ||
85 | + return new BaseResponse<Integer>(result); | ||
86 | + }catch (Exception e){ | ||
87 | + log.error("updateLevel error",e); | ||
88 | + return null; | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | +} | ||
93 | + |
1 | +package com.monitor.user.ctrl; | ||
2 | + | ||
3 | +import com.model.User; | ||
4 | +import com.monitor.model.response.BaseResponse; | ||
5 | +import com.monitor.mysql.mapper.UserMapper; | ||
6 | +import org.slf4j.Logger; | ||
7 | +import org.slf4j.LoggerFactory; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.stereotype.Controller; | ||
10 | +import org.springframework.util.CollectionUtils; | ||
11 | +import org.springframework.web.bind.annotation.RequestBody; | ||
12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
14 | + | ||
15 | +import java.util.List; | ||
16 | + | ||
17 | +@Controller | ||
18 | +@RequestMapping("user") | ||
19 | +public class UserCtrl { | ||
20 | + | ||
21 | + Logger log = LoggerFactory.getLogger(UserCtrl.class); | ||
22 | + | ||
23 | + @Autowired | ||
24 | + UserMapper userMapper; | ||
25 | + | ||
26 | + @RequestMapping("/getAllUser") | ||
27 | + @ResponseBody | ||
28 | + public BaseResponse getAllUser() { | ||
29 | + try{ | ||
30 | + List<User> list=userMapper.selectAll(); | ||
31 | + | ||
32 | + if (list == null || CollectionUtils.isEmpty(list)) { | ||
33 | + return new BaseResponse<List<User>>(); | ||
34 | + } | ||
35 | + | ||
36 | + return new BaseResponse<List<User>>(list); | ||
37 | + }catch (Exception e){ | ||
38 | + log.error("getAllUser error",e); | ||
39 | + return null; | ||
40 | + } | ||
41 | + } | ||
42 | + | ||
43 | + @RequestMapping("/getUserByName") | ||
44 | + @ResponseBody | ||
45 | + public BaseResponse getUserByName(String name) { | ||
46 | + try{ | ||
47 | + User user=userMapper.selectByName(name); | ||
48 | + return new BaseResponse<User>(user); | ||
49 | + }catch (Exception e){ | ||
50 | + log.error("getUserByName error",e); | ||
51 | + return null; | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + @RequestMapping("/getUserById") | ||
56 | + @ResponseBody | ||
57 | + public BaseResponse getUserById(int id) { | ||
58 | + try{ | ||
59 | + User user=userMapper.selectById(id); | ||
60 | + return new BaseResponse<User>(user); | ||
61 | + }catch (Exception e){ | ||
62 | + log.error("getUserById error",e); | ||
63 | + return null; | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + @RequestMapping("/insert") | ||
68 | + @ResponseBody | ||
69 | + public BaseResponse insert(@RequestBody User user) { | ||
70 | + try{ | ||
71 | + int result = userMapper.insert(user); | ||
72 | + return new BaseResponse<Integer>(result); | ||
73 | + }catch (Exception e){ | ||
74 | + log.error("getUserById error",e); | ||
75 | + return null; | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | + @RequestMapping("/updatePwd") | ||
80 | + @ResponseBody | ||
81 | + public BaseResponse updatePwd(@RequestBody User user) { | ||
82 | + try{ | ||
83 | + int result = userMapper.updatePwd(user); | ||
84 | + return new BaseResponse<Integer>(result); | ||
85 | + }catch (Exception e){ | ||
86 | + log.error("getUserById error",e); | ||
87 | + return null; | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + | ||
92 | + @RequestMapping("/updateLevel") | ||
93 | + @ResponseBody | ||
94 | + public BaseResponse updateAuth(@RequestBody User user) { | ||
95 | + try{ | ||
96 | + int result = userMapper.updateLevel(user); | ||
97 | + return new BaseResponse<Integer>(result); | ||
98 | + }catch (Exception e){ | ||
99 | + log.error("getUserById error",e); | ||
100 | + return null; | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + | ||
105 | + @RequestMapping("/deleteByName") | ||
106 | + @ResponseBody | ||
107 | + public BaseResponse deleteByName(String name) { | ||
108 | + try{ | ||
109 | + int result = userMapper.deleteByName(name); | ||
110 | + return new BaseResponse<Integer>(result); | ||
111 | + }catch (Exception e){ | ||
112 | + log.error("getUserById error",e); | ||
113 | + return null; | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + @RequestMapping("/deleteById") | ||
118 | + @ResponseBody | ||
119 | + public BaseResponse deleteById(int id) { | ||
120 | + try{ | ||
121 | + int result = userMapper.deleteById(id); | ||
122 | + return new BaseResponse<Integer>(result); | ||
123 | + }catch (Exception e){ | ||
124 | + log.error("getUserById error",e); | ||
125 | + return null; | ||
126 | + } | ||
127 | + } | ||
128 | +} | ||
129 | + |
@@ -43,6 +43,10 @@ | @@ -43,6 +43,10 @@ | ||
43 | <artifactId>monitor-service-switch</artifactId> | 43 | <artifactId>monitor-service-switch</artifactId> |
44 | </dependency> | 44 | </dependency> |
45 | <dependency> | 45 | <dependency> |
46 | + <groupId>monitor-service</groupId> | ||
47 | + <artifactId>monitor-service-user</artifactId> | ||
48 | + </dependency> | ||
49 | + <dependency> | ||
46 | <groupId>junit</groupId> | 50 | <groupId>junit</groupId> |
47 | <artifactId>junit</artifactId> | 51 | <artifactId>junit</artifactId> |
48 | <version>4.11</version> | 52 | <version>4.11</version> |
@@ -110,6 +110,11 @@ | @@ -110,6 +110,11 @@ | ||
110 | <version>${project-version}</version> | 110 | <version>${project-version}</version> |
111 | </dependency> | 111 | </dependency> |
112 | <dependency> | 112 | <dependency> |
113 | + <groupId>monitor-service</groupId> | ||
114 | + <artifactId>monitor-service-user</artifactId> | ||
115 | + <version>${project-version}</version> | ||
116 | + </dependency> | ||
117 | + <dependency> | ||
113 | <groupId>org.projectlombok</groupId> | 118 | <groupId>org.projectlombok</groupId> |
114 | <artifactId>lombok</artifactId> | 119 | <artifactId>lombok</artifactId> |
115 | <version>${lombok-version}</version> | 120 | <version>${lombok-version}</version> |
@@ -137,6 +142,7 @@ | @@ -137,6 +142,7 @@ | ||
137 | <module>monitor-service-cmdb</module> | 142 | <module>monitor-service-cmdb</module> |
138 | <module>monitor-service-model</module> | 143 | <module>monitor-service-model</module> |
139 | <module>monitor-service-middleware</module> | 144 | <module>monitor-service-middleware</module> |
145 | + <module>monitor-service-user</module> | ||
140 | </modules> | 146 | </modules> |
141 | 147 | ||
142 | 148 |
-
Please register or login to post a comment