<?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.dbnt.kcgfilemanager.mapper.UserInfoMapper">
  <select id="selectUserInfoList" resultType="UserInfo" parameterType="UserInfo">
    SELECT A.USER_SEQ AS userSeq,
      A.USER_ID AS userId,
      A.NAME AS name,
      A.POSITION AS position,
      B.VALUE AS positionName,
      A.DEPARTMENT AS department,
      C.VALUE AS departmentName,
      A.USER_ROLE AS userRole,
      A.CREATE_DATE AS createDate,
      A.USER_STATUS AS userStatus
    FROM USER_INFO A
      INNER JOIN COMMON_CODE B
        ON A.POSITION = B.CODE_SQ
      INNER JOIN COMMON_CODE C
        on A.DEPARTMENT = C.CODE_SQ
    WHERE A.USER_STATUS != 'D'
      <if test="userId != null and userId != ''">
        AND A.USER_ID LIKE CONCAT ('%', #{userId},'%')
      </if>
      <if test="name != null and name != ''">
        AND A.NAME LIKE CONCAT ('%', #{name},'%')
      </if>
      <if test="position != null and position != 0">
        AND A.POSITION = #{position}
      </if>
      <if test="department != null and department != 0">
        AND A.DEPARTMENT = #{department}
      </if>
      <if test="startDate != null and startDate != ''">
        AND A.CREATE_DATE >= #{startDate}
      </if>
      <if test="endDate != null and endDate != ''">
        AND A.CREATE_DATE &lt;= #{endDate}
      </if>
    ORDER BY CREATE_DATE DESC
    LIMIT #{rowCnt} OFFSET #{firstIndex}
  </select>

  <select id="selectUserInfoListCnt" resultType="int" parameterType="UserInfo">
    SELECT COUNT(*)
    FROM USER_INFO A
    WHERE A.USER_STATUS != 'D'
      <if test="userId != null and userId != ''">
        AND A.USER_ID LIKE CONCAT ('%', #{userId},'%')
      </if>
      <if test="name != null and name != ''">
        AND A.NAME LIKE CONCAT ('%', #{name},'%')
      </if>
      <if test="position != null and position != 0">
        AND A.POSITION = #{position}
      </if>
      <if test="department != null and department != 0">
        AND A.DEPARTMENT = #{department}
      </if>
      <if test="startDate != null and startDate != ''">
        AND A.CREATE_DATE >= #{startDate}
      </if>
      <if test="endDate != null and endDate != ''">
        AND A.CREATE_DATE &lt;= #{endDate}
      </if>
  </select>
</mapper>