<?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.njcn.product.event.transientes.mapper.PqsDeptsMapper">
  <resultMap id="BaseResultMap" type="com.njcn.product.event.transientes.pojo.po.PqsDepts">
    <!--@mbg.generated-->
    <!--@Table PQS_DEPTS-->
    <id column="DEPTS_INDEX" jdbcType="VARCHAR" property="deptsIndex" />
    <result column="DEPTSNAME" jdbcType="VARCHAR" property="deptsname" />
    <result column="DEPTS_DESC" jdbcType="DECIMAL" property="deptsDesc" />
    <result column="USER_INDEX" jdbcType="VARCHAR" property="userIndex" />
    <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
    <result column="DEPTS_DESCRIPTION" jdbcType="VARCHAR" property="deptsDescription" />
    <result column="STATE" jdbcType="DECIMAL" property="state" />
    <result column="AREA" jdbcType="VARCHAR" property="area" />
    <result column="CUSTOM_DEPT" jdbcType="DECIMAL" property="customDept" />
    <result column="PARENTNODEID" jdbcType="VARCHAR" property="parentnodeid" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    DEPTS_INDEX, DEPTSNAME, DEPTS_DESC, USER_INDEX, UPDATETIME, DEPTS_DESCRIPTION, "STATE", 
    AREA, CUSTOM_DEPT, PARENTNODEID
  </sql>

  <select id="findDeptAndChildren" resultType="java.lang.String">
    SELECT DEPTS_INDEX
    FROM PQS_DEPTS
    START WITH DEPTS_INDEX = #{deptId}
    CONNECT BY PRIOR DEPTS_INDEX = PARENTNODEID
    and state = 1
  </select>

  <select id="getDeptList" resultType="com.njcn.product.event.devcie.pojo.dto.PqsDeptDTO">
    SELECT
    a.DEPTS_INDEX ,
    a.DEPTSNAME ,
    a.DEPTS_DESC ,
    a.USER_INDEX ,
    a.UPDATETIME ,
    a.DEPTS_DESCRIPTION ,
    a."STATE",
    a.AREA,
    a.CUSTOM_DEPT,
    a.PARENTNODEID,
    b.dic_name areaName
    FROM
    PQS_DEPTS a
    LEFT JOIN PQS_DICDATA b ON a.AREA = b.DIC_INDEX
    where a.STATE= 1
    <if test="deptIds!= null and deptIds.size!=0">
    and a.DEPTS_INDEX in
    <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
       #{item}
    </foreach>
    </if >
  </select>
</mapper>