<?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.datas.dao.UnitDao">

    <select id="get" resultType="com.bootdo.datas.dto.GyDataImportDTO">
        select
            a.REPORTER_UNIT as reporterUnit,
            a.CREDIT_CODE as creditCode,
            a.UNIT_CHARACTER as unitCharacter,
            a.INDUSTRY_TYPE_ONE as industryTypeOne,
            a.INDUSTRY_TYPE_TWO as industryTypeTwo,
            a.UNIT_PROVINCE as unitProvince,
            a.UNIT_CITY as unitCity,
            a.SUPERVISORY_ORG as supervisoryOrg,
            a.UNIT_MAN as unitMan,
            a.UNIT_OFFICE as unitOffice,
            a.DATA_SECURITY_MAN as dataSecurityMan,
            a.DATA_SECURITY_OFFICE as dataSecurityOffice,
            a.DATA_SECURITY_WAY as dataSecurityWay
        from gy_unit a
        where a.ID = #{value}
    </select>

    <select id="getUnit" resultType="com.bootdo.datas.domain.UnitDO">
        select `ID`,
        `REPORTER_UNIT`,
        `UNIT_PROVINCE`,
        `UNIT_CITY`,
        `UNIT_OTHER`,
        `DATA_INDUSTRY`,
        `INDUSTRY_TYPE`,
        `DESC`,
        `STATUS`,
        `UPLOAD_USER`,
        `UPLOAD_USERID`,
        `CREATE_TIME`,
        `dept_id`,
        `UPDATE_TIME`
        from tf_unit
        <where>
            <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="industryType != null and industryType != ''">and INDUSTRY_TYPE = #{industryType}</if>
<!--            <if test="uploadUserid != null and uploadUserid != ''">and UPLOAD_USERID = #{uploadUserid}</if>-->
<!--            <if test="deptId != null and deptId != ''">and dept_id = #{deptId}</if>-->
        </where>
    </select>

    <select id="getUnitById" resultType="com.bootdo.datas.domain.GyUnitDO">
        select
            a.ID as id,
            a.REPORTER_UNIT as reporterUnit,
            a.CREDIT_CODE as creditCode,
            a.UNIT_CHARACTER as unitCharacter,
            a.INDUSTRY_TYPE_ONE as industryTypeOne,
            a.INDUSTRY_TYPE_TWO as industryTypeTwo,
            a.UNIT_PROVINCE as unitProvince,
            a.UNIT_CITY as unitCity,
            a.SUPERVISORY_ORG as supervisoryOrg,
            a.UNIT_MAN as unitMan,
            a.UNIT_OFFICE as unitOffice,
            a.DATA_SECURITY_MAN as dataSecurityMan,
            a.DATA_SECURITY_OFFICE as dataSecurityOffice,
            a.DATA_SECURITY_WAY as dataSecurityWay,
            a.CREATE_TIME as createTime,
            a.UPDATE_TIME as updateTime
        from gy_unit a
        where a.ID = #{value}
    </select>

    <select id="query" resultType="com.bootdo.datas.domain.UnitDO">
        select `ID`,
               `REPORTER_UNIT`,
               `UNIT_PROVINCE`,
               `UNIT_CITY`,
               `UNIT_OTHER`,
               `DATA_INDUSTRY`,
               `INDUSTRY_TYPE`,
               `DESC`,
               `STATUS`,
               `UPLOAD_USER`,
               `UPLOAD_USERID`,
               `CREATE_TIME`,
               `dept_id`,
               `UPDATE_TIME`
        from tf_unit
        where REPORTER_UNIT = #{value}
    </select>

    <select id="list" resultType="com.bootdo.datas.domain.GyUnitDO">
        select
            a.ID as id,
            a.REPORTER_UNIT as reporterUnit,
            a.CREDIT_CODE as creditCode,
            a.UNIT_CHARACTER as unitCharacter,
            a.INDUSTRY_TYPE_ONE as industryTypeOne,
            a.INDUSTRY_TYPE_TWO as industryTypeTwo,
            a.UNIT_PROVINCE as unitProvince,
            a.UNIT_CITY as unitCity,
            a.SUPERVISORY_ORG as supervisoryOrg,
            a.UNIT_MAN as unitMan,
            a.UNIT_OFFICE as unitOffice,
            a.DATA_SECURITY_MAN as dataSecurityMan,
            a.DATA_SECURITY_OFFICE as dataSecurityOffice,
            a.DATA_SECURITY_WAY as dataSecurityWay,
            a.CREATE_TIME as createTime,
            a.UPDATE_TIME as updateTime
        from gy_unit a
        <where>
            a.STATUS = '0'
            <if test="reporterUnit != null and reporterUnit != ''">and REPORTER_UNIT like
                CONCAT('%',#{reporterUnit},'%')
            </if>
            <if test="industryTypeOne != null and industryTypeOne != ''">and UNIT_CHARACTER = #{industryTypeOne}</if>
            <if test="unitCity != null and unitCity != ''">and (UNIT_CITY = #{unitCity})</if>
            <if test="unitProvince != null and unitProvince != ''">and (UNIT_PROVINCE = #{unitProvince})</if>
            <if test="creditCode != null and creditCode != ''">and (CREDIT_CODE = #{creditCode})</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 gy_unit
        <where>
            STATUS = "0"
            <if test="reporterUnit != null and reporterUnit != ''">and REPORTER_UNIT like
                CONCAT('%',#{reporterUnit},'%')
            </if>
            <if test="industryTypeOne != null and industryTypeOne != ''">and UNIT_CHARACTER = #{industryTypeOne}</if>
            <if test="unitCity != null and unitCity != ''">and (UNIT_CITY = #{unitCity})</if>
            <if test="unitProvince != null and unitProvince != ''">and (UNIT_PROVINCE = #{unitProvince})</if>
            <if test="creditCode != null and creditCode != ''">and (CREDIT_CODE = #{creditCode})</if>
        </where>
    </select>

    <insert id="save" parameterType="com.bootdo.datas.domain.GyUnitDO" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        insert into gy_unit
        (
            REPORTER_UNIT,
            CREDIT_CODE,
            SUPERVISORY_ORG,
            UNIT_CHARACTER,
            INDUSTRY_TYPE_ONE,
            INDUSTRY_TYPE_TWO,
            UNIT_PROVINCE,
            UNIT_CITY,
            UNIT_MAN,
            UNIT_OFFICE,
            DATA_SECURITY_MAN,
            DATA_SECURITY_OFFICE,
            DATA_SECURITY_WAY,
            STATUS,
            CREATE_TIME,
            UPDATE_TIME,
            NOTE)
        values (
            #{reporterUnit},
            #{creditCode},
            #{supervisoryOrg},
            #{unitCharacter},
            #{industryTypeOne},
            #{industryTypeTwo},
            #{unitProvince},
            #{unitCity},
            #{unitMan},
            #{unitOffice},
            #{dataSecurityMan},
            #{dataSecurityOffice},
            #{dataSecurityWay},
            #{status},
            #{createTime},
            #{updateTime},
            #{note}
               )
    </insert>

    <update id="update" parameterType="com.bootdo.datas.domain.UnitDO">
        update tf_unit
        <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="industryType != null">`INDUSTRY_TYPE` = #{industryType}</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="deptId != null">`dept_id` = #{deptId},</if>
            <if test="updateTime != null">`UPDATE_TIME` = #{updateTime}</if>
        </set>
        where ID = #{id}
    </update>

    <update id="remove">
        update gy_unit
        set status = '1'
        where ID = #{value}
    </update>

    <delete id="batchRemove">
        update gy_unit set status = '1' where ID in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateUnitByCreditCode">
        update gy_unit
        set status = '0'
        where CREDIT_CODE = #{value}
    </update>

</mapper>