<?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.DataApplyDao">

    <select id="get" resultType="com.bootdo.data.domain.DataApplyDO">
        select `ID`,
               `UNIT_ID`,
               `DATA_ID`,
               `STATUS`,
               `UPLOAD_USER`,
               `UPLOAD_USERID`,
               `LIAISE_MAN`,
               `LIAISE_WAY`,
               `TOTAL`,
               `CREATE_TIME`,
               `UPDATE_TIME`
        from tf_data_apply
        where ID = #{value}
    </select>

    <select id="list" resultType="com.bootdo.data.domain.DataApplyDO">
        select
        `ID`,`UNIT_ID`,`DATA_ID`,`STATUS`,`UPLOAD_USER`,`UPLOAD_USERID`,`LIAISE_MAN`,`LIAISE_WAY`,`TOTAL`,`CREATE_TIME`,`UPDATE_TIME`
        from tf_data_apply
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="unitId != null and unitId != ''">and UNIT_ID = #{unitId}</if>
            <if test="dataId != null and dataId != ''">and DATA_ID = #{dataId}</if>
            <if test="status != null and status != ''">and STATUS = #{status}</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="liaiseMan != null and liaiseMan != ''">and LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and LIAISE_WAY = #{liaiseWay}</if>
            <if test="total != null and total != ''">and TOTAL = #{total}</if>
            <if test="createTime != null and createTime != ''">and CREATE_TIME = #{createTime}</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_apply
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="unitId != null and unitId != ''">and UNIT_ID = #{    }</if>
            <if test="dataId != null and dataId != ''">and DATA_ID = #{dataId}</if>
            <if test="status != null and status != ''">and STATUS = #{status}</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="liaiseMan != null and liaiseMan != ''">and LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and LIAISE_WAY = #{liaiseWay}</if>
            <if test="total != null and total != ''">and TOTAL = #{total}</if>
            <if test="createTime != null and createTime != ''">and CREATE_TIME = #{createTime}</if>
            <if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
        </where>
    </select>

    <insert id="save" parameterType="com.bootdo.data.domain.DataApplyDO" useGeneratedKeys="true" keyProperty="id">
        insert into tf_data_apply
        (`UNIT_ID`,
         `DATA_ID`,
         `STATUS`,
         `UPLOAD_USER`,
         `UPLOAD_USERID`,
         `LIAISE_MAN`,
         `LIAISE_WAY`,
         `TOTAL`,
         `CREATE_TIME`,
         `UPDATE_TIME`)
        values (#{unitId},
                #{dataId},
                #{status},
                #{uploadUser},
                #{uploadUserid},
                #{liaiseMan},
                #{liaiseWay},
                #{total},
                now(),
                #{updateTime})
    </insert>

    <update id="update" parameterType="com.bootdo.data.domain.DataApplyDO">
        update tf_data_apply
        <set>
<!--            <if test="unitId != null">`UNIT_ID` = #{unitId},</if>-->
            <if test="dataId != null">`DATA_ID` = #{dataId},</if>
            <if test="status != null">`STATUS` = #{status},</if>
            <if test="uploadUser != null">`UPLOAD_USER` = #{uploadUser},</if>
            <if test="uploadUserid != null">`UPLOAD_USERID` = #{uploadUserid},</if>
            <if test="liaiseMan != null">`LIAISE_MAN` = #{liaiseMan},</if>
            <if test="liaiseWay != null">`LIAISE_WAY` = #{liaiseWay},</if>
            <if test="total != null">`TOTAL` = #{total},</if>
            <if test="createTime != null">`CREATE_TIME` = #{createTime},</if>
            <if test="updateTime != null">`UPDATE_TIME` = #{updateTime}</if>
        </set>
        where ID = #{id}
        <!--ID等于   unitId或ID-->
    </update>

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

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

</mapper>