<?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.moral.monitor.dao.UserDao">
|
|
<!--所有用户列表-->
|
<select id="allUsers" parameterType="com.moral.monitor.entity.QueryHelper" resultType="com.moral.monitor.entity.User">
|
select * from user
|
<where>
|
<if test="search!=''">
|
and name LIKE '%${search}%'
|
</if>
|
</where>
|
limit #{offset},#{limit}
|
</select>
|
|
<select id="userscount" parameterType="com.moral.monitor.entity.QueryHelper" resultType="int">
|
select COUNT(id) from user
|
<where>
|
<if test="search!=''">
|
and name LIKE '%${search}%'
|
</if>
|
</where>
|
</select>
|
|
|
|
<!-- 删除用户-->
|
<select id="deleteUser" parameterType="String" >
|
DELETE FROM `user` WHERE id=#{id}
|
</select>
|
|
|
<!--列出所有用户组-->
|
<select id="group" resultType="com.moral.monitor.entity.Group">
|
select * from `group`
|
</select>
|
|
<!--添加用户-->
|
<select id="adduser" parameterType="com.moral.monitor.entity.User">
|
insert into `user`(name,password,organization,sex,mobile,email,weixin,user_type,nickname,create_time) VALUES(#{name},#{password},#{organization},#{sex},#{mobile},#{email},#{weixin},#{user_type},#{nickname},NOW())
|
</select>
|
|
<!--根据用户名查找用户-->
|
<select id="finduserbymobile" parameterType="String" resultType="com.moral.monitor.entity.User">
|
select * from `user` WHERE mobile=#{mobile}
|
</select>
|
|
|
<!--插入groupuser表-->
|
<select id="intogroupuser">
|
INSERT INTO group_user(`group`,`user`) VALUES(#{0},#{1})
|
</select>
|
|
|
<!--根据用户id 查找 groupuser用于回显 -->
|
<select id="groupuser" parameterType="int" resultType="com.moral.monitor.entity.GroupUser">
|
select * from group_user WHERE user=#{id}
|
</select>
|
|
|
<!--修改用户信息-->
|
<select id="updateuser" parameterType="com.moral.monitor.entity.User">
|
update `user` set
|
name=#{name},
|
sex=#{sex},
|
mobile=#{mobile},
|
email=#{email},
|
weixin=#{weixin},
|
`password`=#{password},
|
organization=#{organization},
|
user_type=#{user_type},
|
nickname=#{nickname}
|
WHERE id=#{id}
|
</select>
|
|
<!-- 修改用户的用户组信息,先删除再插入 -->
|
<select id="deletegroupuser" parameterType="int">
|
DELETE FROM group_user WHERE `user`=#{userid}
|
</select>
|
|
|
|
|
<!-- <resultMap type="UserEntity" id="UserResult">
|
<result column="ID" jdbcType="INTEGER" property="id" />
|
<result column="NAME" jdbcType="VARCHAR" property="name" />
|
<result column="SEX" jdbcType="VARCHAR" property="sex" />
|
<result column="MOBILE" jdbcType="VARCHAR" property="mobile" />
|
<result column="EMAIL" jdbcType="VARCHAR" property="email" />
|
<result column="WEIXIN" jdbcType="VARCHAR" property="weixin" />
|
<result column="PASSWORD" jdbcType="VARCHAR" property="password" />
|
<result column="ORGANIZATION" jdbcType="VARCHAR" property="organization" />
|
<result column="USER_TYPE" jdbcType="VARCHAR" property="user_type" />
|
<result column="CREATE_TIME" property="create_time" />
|
<result column="NICKNAME" jdbcType="VARCHAR" property="nickname" />
|
</resultMap>
|
|
|
<select id="findAllUser" resultMap="UserResult">
|
select id,name,password,organization,sex,mobile,email,weixin,
|
case when (user_type)= 1 then '运维人员' when (user_type)=2 then '安装人员' end,
|
create_time,nickname
|
from user order by id desc
|
</select>
|
<insert id="insertUser" parameterType="UserEntity" useGeneratedKeys="true" keyProperty="id">
|
INSERT INTO user
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
NAME,
|
<if test="sex!=null">
|
SEX,
|
</if>
|
MOBILE,
|
EMAIL,
|
WEIXIN,
|
PASSWORD,
|
ORGANIZATION,
|
<if test="user_type!=null">
|
USER_TYPE,
|
</if>
|
CREATE_TIME,
|
NICKNAME
|
|
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
#{name,jdbcType=VARCHAR},
|
<if test="sex!=null ">
|
#{sex,jdbcType=VARCHAR},
|
</if>
|
#{mobile,jdbcType=VARCHAR},
|
#{email,jdbcType=VARCHAR},
|
#{weixin,jdbcType=VARCHAR},
|
#{password,jdbcType=VARCHAR},
|
#{organization,jdbcType=VARCHAR},
|
<if test="user_type!=null">
|
#{user_type,jdbcType=VARCHAR},
|
</if>
|
now(),
|
#{nickname,jdbcType=VARCHAR}
|
|
|
</trim>
|
</insert>
|
<update id="updataUser" parameterType="UserEntity">
|
update user set
|
NAME=#{name,jdbcType=VARCHAR},
|
SEX=#{sex,jdbcType=VARCHAR},
|
MOBILE=#{mobile,jdbcType=VARCHAR},
|
EMAIL=#{email,jdbcType=VARCHAR},
|
WEIXIN=#{weixin,jdbcType=VARCHAR},
|
PASSWORD=#{password,jdbcType=VARCHAR},
|
ORGANIZATION=#{organization,jdbcType=VARCHAR},
|
USER_TYPE=#{user_type,jdbcType=VARCHAR},
|
CREATE_TIME=now(),
|
NICKNAME=#{nickname,jdbcType=VARCHAR}
|
WHERE ID=#{id,jdbcType=INTEGER}
|
|
</update>
|
<delete id="deleUser" parameterType="int">
|
DELETE FROM user where ID=#{id,jdbcType=INTEGER}
|
|
</delete>
|
|
|
<select id="selectuserbyname" resultType="com.moral.monitor.entity.UserEntity" parameterType="String">
|
select * from user where name=#{username}
|
</select>
|
|
<select id="selectUserByid" resultType="com.moral.monitor.entity.UserEntity" parameterType="int">
|
select * from user where id=#{id}
|
</select>
|
<select id="selectCountUser" parameterType="String" resultType="int">
|
select count(*)from user where name=#{name}
|
</select>
|
<select id="findTotalUser" resultType="int">
|
select count(*) from user
|
|
</select>
|
<select id="PaginationUser" parameterType="int" resultMap="UserResult">
|
select id,name,password,organization,sex,mobile,email,weixin,
|
(case when (user_type)='1' then '安装运维人员' when (user_type)='2' then '安装人员' end)as user_type,
|
create_time,nickname from user order by create_time desc limit #{0},#{1}
|
</select>
|
|
|
-->
|
|
|
</mapper>
|