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

    <select id="get" resultType="com.bootdo.data.domain.UnitInfoDO">
        select `ID`,
               `REPORTER_UNIT`,
               `UNIT_PROVINCE`,
               `UNIT_CITY`,
               `UNIT_OTHER`,
               `DATA_INDUSTRY`,
               `OTHER_INDUSTRY`,
               `DESC`,
               `STATUS`,
               `UPLOAD_USER`,
               `UPLOAD_USERID`,
               `CREATE_TIME`,
               `LIAISE_MAN`,
               `LIAISE_WAY`,
               `UPDATE_TIME`
        from tf_unit_info
        where ID = #{value}
    </select>

    <select id="list" resultType="com.bootdo.data.domain.UnitInfoDO">
        select
        `ID`,`REPORTER_UNIT`,`UNIT_PROVINCE`,`UNIT_CITY`,`UNIT_OTHER`,`DATA_INDUSTRY`,`OTHER_INDUSTRY`,`DESC`,`STATUS`,`UPLOAD_USER`,`UPLOAD_USERID`,`CREATE_TIME`,`LIAISE_MAN`,
        `LIAISE_WAY`,`UPDATE_TIME`
        from tf_unit_info
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="reporterUnit != null and reporterUnit != ''">and REPORTER_UNIT = #{reporterUnit}</if>
            <if test="unitProvince != null and unitProvince != ''">and UNIT_PROVINCE = #{unitProvince}</if>
            <if test="unitCity != null and unitCity != ''">and UNIT_CITY = #{unitCity}</if>
            <if test="unitOther != null and unitOther != ''">and UNIT_OTHER = #{unitOther}</if>
            <if test="dataIndustry != null and dataIndustry != ''">and DATA_INDUSTRY = #{dataIndustry}</if>
            <if test="otherIndustry != null and otherIndustry != ''">and OTHER_INDUSTRY = #{otherIndustry}</if>
            <if test="desc != null and desc != ''">and DESC = #{desc}</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="createTime != null and createTime != ''">and CREATE_TIME = #{createTime}</if>
            <if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
            <if test="liaiseMan != null and liaiseMan != ''">and LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and LIAISE_WAY = #{liaiseWay}</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_unit_info
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="reporterUnit != null and reporterUnit != ''">and REPORTER_UNIT = #{reporterUnit}</if>
            <if test="unitProvince != null and unitProvince != ''">and UNIT_PROVINCE = #{unitProvince}</if>
            <if test="unitCity != null and unitCity != ''">and UNIT_CITY = #{unitCity}</if>
            <if test="unitOther != null and unitOther != ''">and UNIT_OTHER = #{unitOther}</if>
            <if test="dataIndustry != null and dataIndustry != ''">and DATA_INDUSTRY = #{dataIndustry}</if>
            <if test="otherIndustry != null and otherIndustry != ''">and OTHER_INDUSTRY = #{otherIndustry}</if>
            <if test="desc != null and desc != ''">and DESC = #{desc}</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="createTime != null and createTime != ''">and CREATE_TIME = #{createTime}</if>
            <if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
            <if test="liaiseMan != null and liaiseMan != ''">and LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and LIAISE_WAY = #{liaiseWay}</if>
        </where>
    </select>


    <select id="listQuery" resultType="com.bootdo.data.domain.UnitApplyInfoDO">
        SELECT b.ID as id,b.UNIT_ID AS unitId,a.REPORTER_UNIT AS reporterUnit,a.`UNIT_CITY` AS unitCity,a.`UNIT_PROVINCE` AS unitProvince,a.`UNIT_OTHER` AS unitOther,a.`DATA_INDUSTRY` AS dataIndustry,
        a.`OTHER_INDUSTRY` AS otherIndustry,a.`LIAISE_MAN` AS liaiseMan,a.`LIAISE_WAY` AS liaiseWay,a.`STATUS` AS STATUS,
        b.`CREATE_TIME` AS upLoadTime,b.`LIAISE_MAN` AS liaiseMans,b.`LIAISE_WAY` AS liaiseWays,b.`TOTAL` AS total
        FROM tf_unit_info a,TF_DATA_APPLY b
        WHERE a.id=b.UNIT_ID
        <where>
            <if test="id != null and id != ''">and a.ID = #{id}</if>
            <if test="reporterUnit != null and reporterUnit != ''">and a.REPORTER_UNIT = #{reporterUnit}</if>
            <if test="unitProvince != null and unitProvince != ''">and a.UNIT_PROVINCE = #{unitProvince}</if>
            <if test="unitCity != null and unitCity != ''">and a.UNIT_CITY = #{unitCity}</if>
            <if test="unitOther != null and unitOther != ''">and a.UNIT_OTHER = #{unitOther}</if>
            <if test="dataIndustry != null and dataIndustry != ''">and a.DATA_INDUSTRY = #{dataIndustry}</if>
            <if test="otherIndustry != null and otherIndustry != ''">and a.OTHER_INDUSTRY = #{otherIndustry}</if>
            <if test="desc != null and desc != ''">and a.DESC = #{desc}</if>
            <if test="status != null and status != ''">and a.STATUS = #{status}</if>
            <if test="uploadUser != null and uploadUser != ''">and a.UPLOAD_USER = #{uploadUser}</if>
            <if test="uploadUserid != null and uploadUserid != ''">and a.UPLOAD_USERID = #{uploadUserid}</if>
            <if test="createTime != null and createTime != ''">and a.CREATE_TIME = #{createTime}</if>
            <if test="updateTime != null and updateTime != ''">and a.UPDATE_TIME = #{updateTime}</if>
            <if test="liaiseMan != null and liaiseMan != ''">and a.LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and a.LIAISE_WAY = #{liaiseWay}</if>
        </where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
            <otherwise>
                order by a.ID desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="countQuery" resultType="int">
        select count(*) FROM tf_unit_info a,TF_DATA_APPLY b
        WHERE a.id=b.UNIT_ID
        <where>
            <if test="id != null and id != ''">and a.ID = #{id}</if>
            <if test="reporterUnit != null and reporterUnit != ''">and a.REPORTER_UNIT = #{reporterUnit}</if>
            <if test="unitProvince != null and unitProvince != ''">and a.UNIT_PROVINCE = #{unitProvince}</if>
            <if test="unitCity != null and unitCity != ''">and a.UNIT_CITY = #{unitCity}</if>
            <if test="unitOther != null and unitOther != ''">and a.UNIT_OTHER = #{unitOther}</if>
            <if test="dataIndustry != null and dataIndustry != ''">and a.DATA_INDUSTRY = #{dataIndustry}</if>
            <if test="otherIndustry != null and otherIndustry != ''">and a.OTHER_INDUSTRY = #{otherIndustry}</if>
            <if test="desc != null and desc != ''">and a.DESC = #{desc}</if>
            <if test="status != null and status != ''">and a.STATUS = #{status}</if>
            <if test="uploadUser != null and uploadUser != ''">and a.UPLOAD_USER = #{uploadUser}</if>
            <if test="uploadUserid != null and uploadUserid != ''">and a.UPLOAD_USERID = #{uploadUserid}</if>
            <if test="createTime != null and createTime != ''">and a.CREATE_TIME = #{createTime}</if>
            <if test="updateTime != null and updateTime != ''">and a.UPDATE_TIME = #{updateTime}</if>
            <if test="liaiseMan != null and liaiseMan != ''">and a.LIAISE_MAN = #{liaiseMan}</if>
            <if test="liaiseWay != null and liaiseWay != ''">and a.LIAISE_WAY = #{liaiseWay}</if>
        </where>
    </select>


    <insert id="save" parameterType="com.bootdo.data.domain.UnitInfoDO" useGeneratedKeys="true" keyProperty="id">
        insert into tf_unit_info
        (`REPORTER_UNIT`,
         `UNIT_PROVINCE`,
         `UNIT_CITY`,
         `UNIT_OTHER`,
         `DATA_INDUSTRY`,
         `OTHER_INDUSTRY`,
         `DESC`,
         `STATUS`,
         `UPLOAD_USER`,
         `UPLOAD_USERID`,
         `CREATE_TIME`,
         `LIAISE_MAN`,
         `LIAISE_WAY`,
         `UPDATE_TIME`)
        values (#{reporterUnit},
                #{unitProvince},
                #{unitCity},
                #{unitOther},
                #{dataIndustry},
                #{otherIndustry},
                #{desc},
                #{status},
                #{uploadUser},
                #{uploadUserid},
                now(),
                #{liaiseMan},
                #{liaiseWay},
                #{updateTime})
    </insert>

    <update id="update" parameterType="com.bootdo.data.domain.UnitInfoDO">
        update tf_unit_info
        <set>
            <if test="reporterUnit != null">`REPORTER_UNIT` = #{reporterUnit},</if>
            <if test="unitProvince != null">`UNIT_PROVINCE` = #{unitProvince},</if>
            <if test="unitCity != null">`UNIT_CITY` = #{unitCity},</if>
            <if test="unitOther != null">`UNIT_OTHER` = #{unitOther},</if>
            <if test="dataIndustry != null">`DATA_INDUSTRY` = #{dataIndustry},</if>
            <if test="otherIndustry != null">`OTHER_INDUSTRY` = #{otherIndustry},</if>
            <if test="desc != null">`DESC` = #{desc},</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="createTime != null">`CREATE_TIME` = #{createTime},</if>
            <if test="liaiseMan != null">`LIAISE_MAN` = #{liaiseMan},</if>
            <if test="liaiseWay != null">`LIAISE_WAY` = #{liaiseWay},</if>
            `UPDATE_TIME` = now()
        </set>
        where ID = #{id}
    </update>

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

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


    <select id="listEditInfo" resultType="com.bootdo.data.domain.UnitApplyInfoDO">
        SELECT b.ID AS id,b.UNIT_ID AS unitId,a.REPORTER_UNIT AS reporterUnit,a.`UNIT_CITY` AS unitCity,a.`UNIT_PROVINCE` AS unitProvince,a.`UNIT_OTHER` AS unitOther,a.`DATA_INDUSTRY` AS dataIndustry,
        a.`OTHER_INDUSTRY` AS otherIndustry,a.`LIAISE_MAN` AS liaiseMan,a.`LIAISE_WAY` AS liaiseWay,a.`STATUS` AS STATUS,
        b.`CREATE_TIME` AS upLoadTime,b.`LIAISE_MAN` AS liaiseMans,b.`LIAISE_WAY` AS liaiseWays,b.`TOTAL` AS total
        FROM tf_unit_info a,TF_DATA_APPLY b
        WHERE a.id=b.UNIT_ID
        <if test="liaiseWay != null and liaiseWay != ''">and b.ID = #{id}</if>
        <if test="uploadUserid != null and uploadUserid != ''">and b.UPLOAD_USERID = #{uploadUserid}</if>
    </select>

</mapper>