<?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.tofly.xrtymis.mapper.GdgltypebmMapper">

    <resultMap id="gdgltypebmMap" type="com.tofly.xrtymis.entity.Gdgltypebm">
        <id property="id" column="ID"/>
        <result property="gdlxMc" column="GDLX_MC"/>
        <result property="yxbz" column="YXBZ"/>
        <result property="gdlxId" column="GDLX_ID"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <result property="statusFlag" column="STATUS_FLAG"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="dataType" column="DATA_TYPE"/>
        <result property="viewType" column="VIEW_TYPE"/>
    </resultMap>
    <update id="updateViewType">
        UPDATE TF_YWPN_GDGLTYPEBM_W set VIEW_TYPE = #{viewType}
        WHERE ID IN
              (SELECT ID FROM (select * from TF_YWPN_GDGLTYPEBM_W
                                                 start with id = #{id}
                               connect by prior id = GDLX_ID order by GDLX_ID) WHERE ID != #{id})
    </update>

    <select id="getTypeName" resultType="String">
        SELECT replace( wm_concat(GDLX_MC),',','-') NAME FROM (SELECT GDLX_MC FROM TF_YWPN_GDGLTYPEBM_W START WITH id =#{id} CONNECT BY PRIOR GDLX_ID = ID ORDER BY id  )
    </select>

    <select id="getAuditInfo" resultType="com.tofly.pojo.comm.Audit">
        SELECT * FROM(
           SELECT * FROM TF_YMPN_AUDIT_W WHERE AUDIT_PLAN_ID = #{audit.auditPlanId} and AUDIT_TYPE = #{audit.auditType} ORDER BY AUDIT_LEVEL DESC
        ) WHERE ROWNUM = 1
    </select>


    <select id="getTypeTree" resultType="com.tofly.xrtymis.custom.vo.GdgltTypeTreeVO">
        SELECT distinct  t.*,DECODE(c.id,NULL,0,1) as ISLC FROM TF_YWPN_GDGLTYPEBM_W t
        LEFT JOIN TF_YWPN_GDYWCONFIG_W c ON (((t.ID = c.GDLX and c.GDXF1 is null)or(t.ID =  c.GDXF1 and c.GDXF2 is null) or t.ID =  c.GDXF2) and c.SF_DELETE !='0')
        <where>
            (t.STATUS_FLAG = '1' or t.STATUS_FLAG is null)
            <if test="datatype != null and datatype.trim() != ''" >
                AND t.DATA_TYPE = #{datatype}
            </if>
            <if test="statusFlag != null and statusFlag.trim() != ''" >
                AND t.STATUS_FLAG = #{statusFlag}
            </if>
            <if test="yxbz != null and yxbz.trim() != ''" >
                AND t.YXBZ = #{yxbz}
            </if>
            <if test="viewType != null and viewType.trim() != ''" >
                AND t.VIEW_TYPE like concat( concat('%',#{viewType}) ,'%')
            </if>
        </where>
        ORDER BY GDLX_ID
    </select>


</mapper>
