<?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.bootdo.data.dao.DataInfoDao">

    <select id="get" resultType="com.bootdo.data.domain.DataInfoDO">
        select `ID`,
               `DATA_SOURCE`,
               `DATA_NAME`,
               `DATA_LEVEL`,
               `DATA_TYPE`,
               `OTHER_TYPE`,
               `DATA_SUB`,
               `DATA_ADJ_SUB`,
               `DATA_SCOPE`,
               `DATA_RESULT`,
               `DATA_LOCATION`,
               `DATA_RANGE`,
               `DATA_RULER`,
               `SHARE_RANGE`,
               `CROSS_RANGE`,
               `DATA_SAFETY`,
               `DATA_DESC`,
               `DATA_STATUS`,
               `UPLOAD_USER`,
               `UPLOAD_USERID`,
               `UPLOAD_TIME`,
               `UPDATE_TIME`
        from tf_data_info
        where ID = #{value}
    </select>

    <select id="list" resultType="com.bootdo.data.domain.DataInfoDO">
        select
        `ID`,`DATA_SOURCE`,`DATA_NAME`,`DATA_LEVEL`,`DATA_TYPE`,`OTHER_TYPE`,`DATA_SUB`,`DATA_ADJ_SUB`,`DATA_SCOPE`,`DATA_RESULT`,`DATA_LOCATION`,`DATA_RANGE`,`DATA_RULER`,`SHARE_RANGE`,`CROSS_RANGE`,`DATA_SAFETY`,`DATA_DESC`,`DATA_STATUS`,`UPLOAD_USER`,`UPLOAD_USERID`,`UPLOAD_TIME`,`UPDATE_TIME`
        from tf_data_info
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="dataSource != null and dataSource != ''">and DATA_SOURCE = #{dataSource}</if>
            <if test="dataName != null and dataName != ''">and DATA_NAME = #{dataName}</if>
            <if test="dataLevel != null and dataLevel != ''">and DATA_LEVEL = #{dataLevel}</if>
            <if test="dataType != null and dataType != ''">and DATA_TYPE = #{dataType}</if>
            <if test="dataSub != null and dataSub != ''">and DATA_SUB = #{dataSub}</if>
            <if test="dataAdjSub != null and dataAdjSub != ''">and DATA_ADJ_SUB = #{dataAdjSub}</if>
            <if test="dataScope != null and dataScope != ''">and DATA_SCOPE = #{dataScope}</if>
            <if test="dataResult != null and dataResult != ''">and DATA_RESULT = #{dataResult}</if>
            <if test="dataLocation != null and dataLocation != ''">and DATA_LOCATION = #{dataLocation}</if>
            <if test="dataRange != null and dataRange != ''">and DATA_RANGE = #{dataRange}</if>
            <if test="dataRuler != null and dataRuler != ''">and DATA_RULER = #{dataRuler}</if>
            <if test="shareRange != null and shareRange != ''">and SHARE_RANGE = #{shareRange}</if>
            <if test="crossRange != null and crossRange != ''">and CROSS_RANGE = #{crossRange}</if>
            <if test="dataSafety != null and dataSafety != ''">and DATA_SAFETY = #{dataSafety}</if>
            <if test="dataDesc != null and dataDesc != ''">and DATA_DESC = #{dataDesc}</if>
            <if test="dataStatus != null and dataStatus != ''">and DATA_STATUS = #{dataStatus}</if>
            <if test="uploadUser != null and uploadUser != ''">and UPLOAD_USER = #{uploadUser}</if>
            <if test="uploadUserid != null and uploadUserid != ''">and UPLOAD_USERID = #{uploadUserid}</if>
            <if test="uploadTime != null and uploadTime != ''">and UPLOAD_TIME = #{uploadTime}</if>
            <if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
        </where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
            <otherwise>
                order by ID desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="count" resultType="int">
        select count(*) from tf_data_info
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="dataSource != null and dataSource != ''">and DATA_SOURCE = #{dataSource}</if>
            <if test="dataName != null and dataName != ''">and DATA_NAME = #{dataName}</if>
            <if test="dataLevel != null and dataLevel != ''">and DATA_LEVEL = #{dataLevel}</if>
            <if test="dataType != null and dataType != ''">and DATA_TYPE = #{dataType}</if>
            <if test="dataSub != null and dataSub != ''">and DATA_SUB = #{dataSub}</if>
            <if test="dataAdjSub != null and dataAdjSub != ''">and DATA_ADJ_SUB = #{dataAdjSub}</if>
            <if test="dataScope != null and dataScope != ''">and DATA_SCOPE = #{dataScope}</if>
            <if test="dataResult != null and dataResult != ''">and DATA_RESULT = #{dataResult}</if>
            <if test="dataLocation != null and dataLocation != ''">and DATA_LOCATION = #{dataLocation}</if>
            <if test="dataRange != null and dataRange != ''">and DATA_RANGE = #{dataRange}</if>
            <if test="dataRuler != null and dataRuler != ''">and DATA_RULER = #{dataRuler}</if>
            <if test="shareRange != null and shareRange != ''">and SHARE_RANGE = #{shareRange}</if>
            <if test="crossRange != null and crossRange != ''">and CROSS_RANGE = #{crossRange}</if>
            <if test="dataSafety != null and dataSafety != ''">and DATA_SAFETY = #{dataSafety}</if>
            <if test="dataDesc != null and dataDesc != ''">and DATA_DESC = #{dataDesc}</if>
            <if test="dataStatus != null and dataStatus != ''">and DATA_STATUS = #{dataStatus}</if>
            <if test="uploadUser != null and uploadUser != ''">and UPLOAD_USER = #{uploadUser}</if>
            <if test="uploadUserid != null and uploadUserid != ''">and UPLOAD_USERID = #{uploadUserid}</if>
            <if test="uploadTime != null and uploadTime != ''">and UPLOAD_TIME = #{uploadTime}</if>
            <if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
        </where>
    </select>

    <insert id="save" parameterType="com.bootdo.data.domain.DataInfoDO" useGeneratedKeys="true" keyProperty="id">
        insert into tf_data_info
        (`DATA_SOURCE`,
         `DATA_NAME`,
         `DATA_LEVEL`,
         `DATA_TYPE`,
         `OTHER_TYPE`,
         `DATA_SUB`,
         `DATA_ADJ_SUB`,
         `DATA_SCOPE`,
         `DATA_RESULT`,
         `DATA_LOCATION`,
         `DATA_RANGE`,
         `DATA_RULER`,
         `SHARE_RANGE`,
         `CROSS_RANGE`,
         `DATA_SAFETY`,
         `DATA_DESC`,
         `DATA_STATUS`,
         `UPLOAD_USER`,
         `UPLOAD_USERID`,
         `UPLOAD_TIME`,
         `UPDATE_TIME`)
        values (#{dataSource},
                #{dataName},
                #{dataLevel},
                #{dataType},
                #{otherType},
                #{dataSub},
                #{dataAdjSub},
                #{dataScope},
                #{dataResult},
                #{dataLocation},
                #{dataRange},
                #{dataRuler},
                #{shareRange},
                #{crossRange},
                #{dataSafety},
                #{dataDesc},
                #{dataStatus},
                #{uploadUser},
                #{uploadUserid},
                now(),
                now())
    </insert>

    <update id="update" parameterType="com.bootdo.data.domain.DataInfoDO">
        update tf_data_info
        <set>
            <if test="dataSource != null">`DATA_SOURCE` = #{dataSource},</if>
            <if test="dataName != null">`DATA_NAME` = #{dataName},</if>
            <if test="dataLevel != null">`DATA_LEVEL` = #{dataLevel},</if>
            <if test="dataType != null">`DATA_TYPE` = #{dataType},</if>
            <if test="otherType != null">`OTHER_TYPE` = #{otherType},</if>
            <if test="dataSub != null">`DATA_SUB` = #{dataSub},</if>
            <if test="dataAdjSub != null">`DATA_ADJ_SUB` = #{dataAdjSub},</if>
            <if test="dataScope != null">`DATA_SCOPE` = #{dataScope},</if>
            <if test="dataResult != null">`DATA_RESULT` = #{dataResult},</if>
            <if test="dataLocation != null">`DATA_LOCATION` = #{dataLocation},</if>
            <if test="dataRange != null">`DATA_RANGE` = #{dataRange},</if>
            <if test="dataRuler != null">`DATA_RULER` = #{dataRuler},</if>
            <if test="shareRange != null">`SHARE_RANGE` = #{shareRange},</if>
            <if test="crossRange != null">`CROSS_RANGE` = #{crossRange},</if>
            <if test="dataSafety != null">`DATA_SAFETY` = #{dataSafety},</if>
            <if test="dataDesc != null">`DATA_DESC` = #{dataDesc},</if>
            <if test="dataStatus != null">`DATA_STATUS` = #{dataStatus},</if>
            <if test="uploadUser != null">`UPLOAD_USER` = #{uploadUser},</if>
            <if test="uploadUserid != null">`UPLOAD_USERID` = #{uploadUserid},</if>
            <if test="uploadTime != null">`UPLOAD_TIME` = #{uploadTime},</if>
            `UPDATE_TIME` = now()
        </set>
        where ID = #{id}
    </update>

    <delete id="remove">
        delete
        from tf_data_info
        where ID = #{value}
    </delete>

    <delete id="batchRemove">
        delete from tf_data_info where ID in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="querylistInfo" resultType="com.bootdo.data.domain.DataInfoDO">
        SELECT c.`ID`,c.`DATA_NAME` FROM `TF_DATA_APPLY` a ,`TF_DATA_RELATION` b,`TF_DATA_INFO` c
        WHERE a.`ID` = b.`APPLY_ID` AND b.`DATA_ID` = c.`ID`
        <if test="id != null and id != ''">and a.`ID` = #{id}</if>
        <if test="uploadUserid != null and uploadUserid != ''">and a.UPLOAD_USERID = #{uploadUserid}</if>
        ORDER BY a.`CREATE_TIME` DESC
    </select>

    <!--备案与数据关系表 状态修改-->
    <update id="updateRelation">
        UPDATE `TF_DATA_INFO`
        SET DATA_STATUS = '0'
        WHERE id = (SELECT a.`DATA_ID` FROM `TF_DATA_RELATION` a WHERE APPLY_ID = #{applyId})
    </update>

</mapper>