Authored by zhengyouwei

add user

... ... @@ -16,4 +16,8 @@ public class User {
private int level;
private String email;
private String mobile;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.mysql.mapper;
import com.model.AuthModule;
import com.model.User;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -21,5 +22,10 @@ public interface AuthModuleMapper {
AuthModule selectById(@Param("id") int id);
List<AuthModule> selectAuthModules(PageBean page);
int selectCount();
int deleteByName(@Param("name") String name);
}
... ...
package com.monitor.mysql.mapper;
import com.model.HostGroup;
import com.model.User;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -12,9 +14,9 @@ public interface UserMapper {
int insert(User user);
int updatePwd(User user);
int update(User user);
int updateLevel(User user);
int updatePwd(User user);
int deleteByName(@Param("name") String name);
... ... @@ -26,5 +28,8 @@ public interface UserMapper {
User selectById(@Param("id") int id);
List<User> selectUsers(PageBean page);
int selectCount();
}
... ...
... ... @@ -44,4 +44,22 @@
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from auth_module
</select>
<select id="selectAuthModules" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from auth_module
order by id desc
limit #{startIndex},#{pageSize}
</select>
<delete id="deleteByName" parameterType="java.lang.String" >
delete from auth_module
where module_name = #{name,jdbcType=VARCHAR}
</delete>
</mapper>
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@
<id property="moUrl" column="url"></id>
</resultMap>
<select id="getAllMosInfo" resultType="com.model.MObjectInfo" resultMap="mobjectInfoMapper" useCache="true">
<select id="getAllMosInfo" resultType="com.model.MObjectInfo" resultMap="mobjectInfoMapper">
SELECT * FROM mobject_info ORDER BY id asc
</select>
... ... @@ -38,7 +38,7 @@
</update>
<select id="selectMObjectsInfoByTypes" resultType="com.model.MObjectInfo" resultMap="mobjectInfoMapper" useCache="true">
<select id="selectMObjectsInfoByTypes" resultType="com.model.MObjectInfo" resultMap="mobjectInfoMapper">
SELECT * FROM mobject_info
where type_id in
... ...
... ... @@ -14,7 +14,7 @@
<sql id="Base_Column_List"> id, alias, isLeaf, parent_id </sql>
<select id="getAllTypesInfo" resultType="com.model.TypeInfo" resultMap="typeInfoMap" useCache="true">
<select id="getAllTypesInfo" resultType="com.model.TypeInfo" resultMap="typeInfoMap">
SELECT
<include refid="Base_Column_List"/>
FROM type_info ORDER BY id asc
... ...
... ... @@ -10,13 +10,11 @@
<id property="alertHigh" column="alert"></id>
</resultMap>
<select id="getAllAlertsInfo" resultType="com.model.RabbitAlertInfo" resultMap="rabbitAlertInfoMapper"
useCache="true">
<select id="getAllAlertsInfo" resultType="com.model.RabbitAlertInfo" resultMap="rabbitAlertInfoMapper">
SELECT * FROM rabbitalert_info ORDER BY id asc
</select>
<select id="queryAlertInfo" resultType="com.model.RabbitAlertInfo" resultMap="rabbitAlertInfoMapper"
useCache="true">
<select id="queryAlertInfo" resultType="com.model.RabbitAlertInfo" resultMap="rabbitAlertInfoMapper">
SELECT * FROM rabbitalert_info WHERE id = #{moId} AND alias= #{queueName}
</select>
... ...
... ... @@ -6,10 +6,12 @@
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="pwd" property="pwd" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="INTEGER" />
<result column="email" property="email" jdbcType="VARCHAR" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, name, pwd, level
id, name, pwd, level, email, mobile
</sql>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -32,6 +34,14 @@
from user
</select>
<select id="selectUsers" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
order by id desc
limit #{startIndex},#{pageSize}
</select>
<delete id="deleteById" parameterType="java.lang.Integer" >
delete from user
where id = #{id,jdbcType=INTEGER}
... ... @@ -44,23 +54,30 @@
<insert id="insert" parameterType="com.model.User" >
insert into user
(name,pwd,level, create_time, update_time)
(name,pwd,level,email,mobile, create_time, update_time)
values
(#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER}, now(),now())
(#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER},
#{email,jdbcType=INTEGER},#{mobile,jdbcType=INTEGER},now(),now())
</insert>
<update id="updatePwd" parameterType="com.model.User" >
<update id="update" parameterType="com.model.User" >
update user
set pwd = #{pwd,jdbcType=VARCHAR},
update_time = now()
set level = #{level,jdbcType=INTEGER},
email = #{email,jdbcType=VARCHAR},
mobile = #{mobile,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateLevel" parameterType="com.model.User" >
<update id="updatePwd" parameterType="com.model.User" >
update user
set level = #{level,jdbcType=INTEGER},
update_time = now()
set pwd = #{pwd,jdbcType=VARCHAR},
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from user
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -2,6 +2,9 @@ package com.monitor.user.ctrl;
import com.model.AuthModule;
import com.model.User;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import com.monitor.model.page.PageResponse;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.AuthModuleMapper;
import org.slf4j.Logger;
... ... @@ -89,5 +92,51 @@ public class ModuleCtrl {
}
}
@RequestMapping("/getAuthModules")
@ResponseBody
public BaseResponse<PageResponse<AuthModule>> getAuthModules(@RequestBody PageRequest req) {
try{
log.info("getAuthModules with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = authModuleMapper.selectCount();
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return null;
}
// 获取列表
List<AuthModule> authModules = authModuleMapper.selectAuthModules(page);
if (CollectionUtils.isEmpty(authModules)) {
log.debug("getAuthModules is null with param is {}", req);
return null;
}
PageResponse<AuthModule> response = new PageResponse<AuthModule>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(authModules);
return new BaseResponse<PageResponse<AuthModule>>(response);
}catch (Exception e){
log.error("getAuthModules error",e);
return new BaseResponse<>(e.getMessage());
}
}
@RequestMapping("/deleteByName")
@ResponseBody
public BaseResponse deleteByName(String name) {
try{
int result = authModuleMapper.deleteByName(name);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
return null;
}
}
}
... ...
package com.monitor.user.ctrl;
import com.model.HostGroup;
import com.model.User;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import com.monitor.model.page.PageResponse;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.UserMapper;
import org.slf4j.Logger;
... ... @@ -76,11 +80,11 @@ public class UserCtrl {
}
}
@RequestMapping("/updatePwd")
@RequestMapping("/update")
@ResponseBody
public BaseResponse updatePwd(@RequestBody User user) {
try{
int result = userMapper.updatePwd(user);
int result = userMapper.update(user);
return new BaseResponse<Integer>(result);
}catch (Exception e){
log.error("getUserById error",e);
... ... @@ -88,20 +92,6 @@ public class UserCtrl {
}
}
@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) {
... ... @@ -125,5 +115,40 @@ public class UserCtrl {
return null;
}
}
@RequestMapping("/getUsers")
@ResponseBody
public BaseResponse<PageResponse<User>> getUsers(@RequestBody PageRequest req) {
try{
log.info("getUsers with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = userMapper.selectCount();
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return null;
}
// 获取列表
List<User> users = userMapper.selectUsers(page);
if (CollectionUtils.isEmpty(users)) {
log.debug("getUsers is null with param is {}", req);
return null;
}
PageResponse<User> response = new PageResponse<User>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(users);
return new BaseResponse<PageResponse<User>>(response);
}catch (Exception e){
log.error("getUsers error",e);
return new BaseResponse<>(e.getMessage());
}
}
}
... ...