123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?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.dayou.mapper.UserMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="userDepartmentPostMap" type="com.dayou.vo.UserVO">
- <result column="id" property="id" />
- <result column="deleted" property="deleted" />
- <result column="created" property="created" />
- <result column="modified" property="modified" />
- <result column="name" property="name" />
- <result column="id_no" property="idNo" />
- <result column="user_type" property="userType" />
- <result column="mobile" property="mobile" />
- <result column="sex" property="sex" />
- <result column="password" property="password" />
- <result column="salt" property="salt" />
- <result column="birthday" property="birthday" />
- <result column="enable" property="enable" />
- <result column="staff_no" property="staffNo"/>
- <result column="nation" property="nation"/>
- <result column="politics" property="politics"/>
- <result column="home_address" property="homeAddress"/>
- <result column="resign_state" property="resignState"/>
- <result column="hire_date" property="hireDate"/>
- <result column="resign_date" property="resignDate"/>
- <result column="remark" property="remark"/>
- <result column="native_place" property="nativePlace"/>
- <collection property="departmentPostVOList" ofType="com.dayou.vo.DepartmentPostVO" select="selectDepartmentPostVO" column="id"/>
- <collection property="userPosts" ofType="com.dayou.vo.IdNameVO" select="selectUserPosts" column="id"/>
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id,
- deleted,
- created,
- modified,
- name, id_no, user_type, mobile, sex, password, salt, birthday, enable,staff_no,nation,politics,home_address,resign_state,hire_date,resign_date,remark,native_place,settle_password
- </sql>
- <insert id="saveOrUpdateById" parameterType="com.dayou.entity.User">
- insert into user(`id`,`name`, `staff_no`,`password`,`user_type`,`sex`) values
- (#{user.id},#{user.name},#{user.staffNo},#{user.password},#{user.userType},#{user.sex})
- on duplicate key update
- id=id
- </insert>
- <select id="xPage" parameterType="com.dayou.vo.UserVO" resultMap="userDepartmentPostMap">
- select <include refid="Base_Column_List" /> from user
- <where>
- deleted = 0
- <if test="userVO!=null and userVO.sex!=null and userVO.sex!='' ">
- and sex = #{userVO.sex}
- </if>
- <if test="userVO!=null and userVO.resignState!=null">
- and resign_state = #{userVO.resignState}
- </if>
- <if test="userVO!=null and userVO.staffNo!=null and userVO.staffNo!='' ">
- and staff_no like concat('%',#{userVO.staffNo},'%')
- </if>
- <if test="userVO!=null and userVO.name!=null and userVO.name!='' ">
- and NAME like concat('%',#{userVO.name},'%')
- </if>
- <if test="userVO!=null and userVO.keyword!=null and userVO.keyword!='' ">
- and NAME like concat('%',#{userVO.keyword},'%') or staff_no like concat('%',#{userVO.keyword},'%')
- </if>
- </where>
- </select>
- <select id="selectDepartmentPostVO" parameterType="java.lang.Long" resultType="com.dayou.vo.DepartmentPostVO">
- SELECT
- d.NAME AS departmentName,
- p.name as postName
- FROM
- user_post up
- left join
- post p
- on up.post_id = p.id
- LEFT JOIN department d ON p.department_id = d.id
- where up.user_id = #{id} and up.deleted = 0 and d.deleted=0 and p.deleted=0
- </select>
- <select id="detail" parameterType="java.lang.Long" resultMap="userDepartmentPostMap">
- select <include refid="Base_Column_List" /> from user where deleted = 0 and id=#{id}
- </select>
- <select id="selectUserPosts" parameterType="java.lang.Long" resultType="com.dayou.vo.IdNameVO">
- SELECT
- p.id,
- CONCAT( p.NAME, '-', d.NAME ) AS NAME
- FROM
- user_post up
- LEFT JOIN post p ON up.post_id = p.id
- LEFT JOIN department d ON p.department_id = d.id
- WHERE
- up.user_id = #{id}
- AND p.deleted = 0
- AND d.deleted =0
- AND up.deleted = 0
- </select>
- <select id="getDepartmentIdByUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
- SELECT
- p.department_id
- FROM
- user_post up
- LEFT JOIN post p ON p.id = up.post_id
- left join user u on u.id = up.user_id
- WHERE
- u.id = #{userId}
- AND p.deleted = 0
- AND up.deleted = 0
- and u.deleted =0
- </select>
- <select id="simplePostName" parameterType="java.lang.String" resultType="com.dayou.entity.User">
- SELECT
- u.id,u.name
- FROM
- user_post up
- LEFT JOIN post p ON p.id = up.post_id
- left join user u on u.id = up.user_id
- WHERE
- p.NAME = #{postName}
- AND p.deleted = 0
- AND up.deleted = 0
- and u.deleted =0
- </select>
- <select id="listPostName" parameterType="com.dayou.vo.UserVO" resultMap="userDepartmentPostMap">
- select u.id,u.staff_no,u.name ,u.sex FROM
- user_post up
- LEFT JOIN post p ON p.id = up.post_id
- left join user u on u.id = up.user_id
- WHERE
- p.NAME = #{postName}
- AND p.deleted = 0
- AND up.deleted = 0
- and u.deleted =0
- and
- not exists (
- select 1 from team_member where team_member.deleted = 0 and team_member.member_id = u.id
- )
- </select>
- <select id="usersByDepartment" parameterType="java.lang.String" resultType="com.dayou.vo.IdNameVO">
- SELECT DISTINCT
- u.id,
- u.name
- FROM
- user_post up
- INNER JOIN ( SELECT id FROM post WHERE department_id =( SELECT id FROM department WHERE NAME = '市场部' AND deleted = 0 ) AND deleted = 0 ) p ON up.post_id = p.id
- LEFT JOIN user u ON u.id = up.user_id
- WHERE
- up.deleted = 0
- AND u.deleted = 0
- </select>
- </mapper>
|