<?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.doumee.dao.system.SystemPositionMapper"> 
 | 
  
 | 
  <!-- 查询岗位列表 --> 
 | 
  <resultMap id="SystemPositionListVO" type="com.doumee.dao.system.vo.SystemPositionListVO" autoMapping="true"> 
 | 
    <id column="ID" property="id"/> 
 | 
    <association property="createUserInfo" javaType="com.doumee.dao.system.model.SystemUser"> 
 | 
      <result column="CREATE_USER_ID" property="id"/> 
 | 
      <result column="CREATE_USER_NAME" property="username"/> 
 | 
    </association> 
 | 
    <association property="updateUserInfo" javaType="com.doumee.dao.system.model.SystemUser"> 
 | 
      <result column="UPDATE_USER_ID" property="id"/> 
 | 
      <result column="UPDATE_USER_NAME" property="username"/> 
 | 
    </association> 
 | 
  </resultMap> 
 | 
  <select id="selectManageList" resultMap="SystemPositionListVO"> 
 | 
    SELECT 
 | 
      posi.`ID`, posi.`PARENT_ID`, posi.`CODE`, posi.`NAME`, posi.`CREATE_TIME`, posi.`UPDATE_TIME`, posi.`CREATE_USER`, posi.`UPDATE_USER`, 
 | 
      create_user.ID CREATE_USER_ID, create_user.`USERNAME` CREATE_USER_NAME, 
 | 
      update_user.ID UPDETE_USER_ID, update_user.`USERNAME` UPDATE_USER_NAME, 
 | 
      COUNT(usr.ID) USER_COUNT 
 | 
    FROM SYSTEM_POSITION posi 
 | 
    LEFT JOIN `SYSTEM_POSITION_USER` spu ON spu.POSITION_ID = posi.ID AND spu.DELETED = 0 
 | 
    LEFT JOIN `SYSTEM_USER` usr ON usr.ID = spu.USER_ID AND usr.DELETED = 0 
 | 
    LEFT JOIN `SYSTEM_USER` create_user ON create_user.ID = posi.CREATE_USER 
 | 
    LEFT JOIN `SYSTEM_USER` update_user ON update_user.ID = posi.UPDATE_USER 
 | 
    <where> 
 | 
      posi.DELETED = 0 
 | 
      <if test="name != null and name != ''"> 
 | 
        AND posi.`NAME` LIKE concat('%', #{name}, '%') 
 | 
      </if> 
 | 
    </where> 
 | 
    GROUP BY posi.`ID` 
 | 
  </select> 
 | 
  
 | 
  <!-- 查询用户岗位列表 --> 
 | 
  <select id="selectByUserId" parameterType="java.lang.Integer" resultType="com.doumee.dao.system.model.SystemPosition"> 
 | 
    SELECT 
 | 
      sp.`ID`, sp.`PARENT_ID`, sp.`CODE`, sp.`NAME` 
 | 
    FROM `SYSTEM_POSITION` sp 
 | 
    INNER JOIN `SYSTEM_POSITION_USER` spu ON spu.`POSITION_ID` = sp.`ID` AND spu.`DELETED` = 0 
 | 
    INNER JOIN `SYSTEM_USER` su ON su.`ID` = spu.`USER_ID` 
 | 
    <where> 
 | 
      sp.DELETED = 0 
 | 
      AND spu.USER_ID = #{userId} 
 | 
    </where> 
 | 
  </select> 
 | 
</mapper> 
 |