<?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.mapper.user.DeptsLineMapper'>
    <resultMap type="com.njcn.pojo.user.DeptsLine" id="DeptsLineMapperMap" autoMapping="true">
        <id property="deptsIndex" column="DEPTS_INDEX"/>
    </resultMap>

    <select id="getBind" resultMap="DeptsLineMapperMap">
	select * from pqs_deptsLine where depts_index = #{deptsIndex}
	</select>

    <update id="changeBindLine">
    update PQS_DEPTSLINE set depts_index = #{deptsIndex} where line_index = #{index} and systype=#{sysType}
	</update>



    <select id="selectIndexsByDept" resultType="IndexsCount">
        SELECT
            t2.LINE_INDEX lineIndex,
            t2.SUB_INDEX subIndex,
            t2.DEV_INDEX devIndex,
            t2.GD_INDEX gdIndex
        FROM
            PQS_DEPTSLINE t1,
            PQ_LINE t2,
            PQ_DEVICE t3
        WHERE
            t1.LINE_INDEX = t2.LINE_INDEX
            AND t2.DEV_INDEX = t3.DEV_INDEX
            AND t1.DEPTS_INDEX = #{deptsIndex}
        <if test="sysType != null">
            AND t1.systype=#{sysType}
        </if>
            AND t3.DEVMODEL = #{devModel}
            AND t3.DATATYPE in
            <foreach collection="dataType" item="item"  open="(" separator="," close=")">
                #{item}
            </foreach>
    </select>

    <select id="selectIndexsByDepts" resultType="IndexsCount">
        SELECT
        t2.LINE_INDEX lineIndex,
        t2.SUB_INDEX subIndex,
        t2.DEV_INDEX devIndex,
        t2.GD_INDEX gdIndex
        FROM
        PQS_DEPTSLINE t1,
        PQ_LINE t2,
        PQ_DEVICE t3
        WHERE
        t1.LINE_INDEX = t2.LINE_INDEX
        AND t2.DEV_INDEX = t3.DEV_INDEX
        AND t1.DEPTS_INDEX in
        <foreach collection="depts" item="item"  open="(" separator="," close=")">
            #{item.deptsIndex}
        </foreach>
        AND t1.systype=#{sysType}
        AND t3.DEVMODEL = #{devModel}
        AND t3.DATATYPE in
        <foreach collection="dataType" item="item"  open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectLine" resultType="int">
        SELECT COUNT( * )  FROM PQS_DEPTSLINE  WHERE DEPTS_INDEX = #{deptsIndex}
        AND SYSTYPE = #{sysType}
    </select>

    <select id="selectIndexsByDeptsRun" resultType="IndexsCount">
        SELECT
        t2.LINE_INDEX lineIndex,
        t2.SUB_INDEX subIndex,
        t2.DEV_INDEX devIndex,
        t2.GD_INDEX gdIndex
        FROM
        PQS_DEPTSLINE t1,
        PQ_LINE t2,
        PQ_DEVICE t3
        WHERE
        t1.LINE_INDEX = t2.LINE_INDEX
        AND t2.DEV_INDEX = t3.DEV_INDEX
        AND t1.DEPTS_INDEX in
        <foreach collection="depts" item="item"  open="(" separator="," close=")">
            #{item.deptsIndex}
        </foreach>
        AND t1.systype=#{sysType}
        AND t3.DEVMODEL = #{devModel}
        AND t3.DevFlag=#{devStatus}
        <if test="status!=null">
            AND t3.status = #{status}
        </if>
        AND t3.DATATYPE in
        <foreach collection="dataType" item="item"  open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectIndexsByDeptRun" resultType="IndexsCount">
        SELECT
        t2.LINE_INDEX lineIndex,
        t2.SUB_INDEX subIndex,
        t2.DEV_INDEX devIndex,
        t2.GD_INDEX gdIndex
        FROM
        PQS_DEPTSLINE t1,
        PQ_LINE t2,
        PQ_DEVICE t3
        WHERE
        t1.LINE_INDEX = t2.LINE_INDEX
        AND t2.DEV_INDEX = t3.DEV_INDEX
        AND t1.DEPTS_INDEX = #{deptsIndex}
        <if test="sysType != null">
            AND t1.systype=#{sysType}
        </if>
        AND t3.DEVMODEL = #{devModel}
        AND t3.DevFlag=#{devStatus}
        <if test="status!=null">
            AND t3.status = #{status}
        </if>
        AND t3.DATATYPE in
        <foreach collection="dataType" item="item"  open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>
