<?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.ruoyi.tcZz.mapper.TcDbdwMapper">
    
    <resultMap type="TcDbdw" id="TcDbdwResult">
        <result property="id"    column="id"    />
        <result property="areaId"    column="area_id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="postalCode"    column="postal_code"    />
        <result property="addressProvince"    column="address_province"    />
        <result property="addressCity"    column="address_city"    />
        <result property="addressCounty"    column="address_county"    />
        <result property="unitAddress"    column="unit_address"    />
        <result property="countyCode"    column="county_code"    />
        <result property="lsGx"    column="ls_gx"    />
        <result property="unitType"    column="unit_type"    />
        <result property="industryType"    column="industry_type"    />
        <result property="fzrName"    column="fzr_name"    />
        <result property="fzrDuty"    column="fzr_duty"    />
        <result property="fzrTel"    column="fzr_tel"    />
        <result property="fzrEmail"    column="fzr_email"    />
        <result property="isStatus"    column="isStatus"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTcDbdwVo">
        select id, area_id, unit_name, postal_code, address_province, address_city, address_county, unit_address, county_code, ls_gx, unit_type, industry_type, fzr_name, fzr_duty, fzr_tel, fzr_email, isStatus, create_by, create_time, update_by, update_time, remark from tc_dbdw
    </sql>

    <select id="selectTcDbdwList" parameterType="TcDbdw" resultMap="TcDbdwResult">
        <include refid="selectTcDbdwVo"/>
        <where>  
            <if test="id != null "> and id = #{id}</if>
            <if test="areaId != null  and areaId != ''"> and area_id = #{areaId}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="postalCode != null  and postalCode != ''"> and postal_code = #{postalCode}</if>
            <if test="addressProvince != null  and addressProvince != ''"> and address_province = #{addressProvince}</if>
            <if test="addressCity != null  and addressCity != ''"> and address_city = #{addressCity}</if>
            <if test="addressCounty != null  and addressCounty != ''"> and address_county = #{addressCounty}</if>
            <if test="unitAddress != null  and unitAddress != ''"> and unit_address = #{unitAddress}</if>
            <if test="countyCode != null  and countyCode != ''"> and county_code = #{countyCode}</if>
            <if test="lsGx != null  and lsGx != ''"> and ls_gx = #{lsGx}</if>
            <if test="unitType != null  and unitType != ''"> and unit_type = #{unitType}</if>
            <if test="industryType != null  and industryType != ''"> and industry_type = #{industryType}</if>
            <if test="fzrName != null  and fzrName != ''"> and fzr_name like concat('%', #{fzrName}, '%')</if>
            <if test="fzrDuty != null  and fzrDuty != ''"> and fzr_duty = #{fzrDuty}</if>
            <if test="fzrTel != null  and fzrTel != ''"> and fzr_tel = #{fzrTel}</if>
            <if test="fzrEmail != null  and fzrEmail != ''"> and fzr_email = #{fzrEmail}</if>
            <if test="isStatus != null "> and isStatus = #{isStatus}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
            <if test="updateBy != null  and updateBy != ''"> and update_by = #{updateBy}</if>
            <if test="params.beginUpdateTime != null and params.beginUpdateTime != '' and params.endUpdateTime != null and params.endUpdateTime != ''"> and update_time between #{params.beginUpdateTime} and #{params.endUpdateTime}</if>
            <if test="remark != null  and remark != ''"> and remark = #{remark}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTcDbdwById" parameterType="Long" resultMap="TcDbdwResult">
        <include refid="selectTcDbdwVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcDbdw" parameterType="TcDbdw" useGeneratedKeys="true" keyProperty="id">
        insert into tc_dbdw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="postalCode != null">postal_code,</if>
            <if test="addressProvince != null">address_province,</if>
            <if test="addressCity != null">address_city,</if>
            <if test="addressCounty != null">address_county,</if>
            <if test="unitAddress != null">unit_address,</if>
            <if test="countyCode != null">county_code,</if>
            <if test="lsGx != null">ls_gx,</if>
            <if test="unitType != null">unit_type,</if>
            <if test="industryType != null">industry_type,</if>
            <if test="fzrName != null">fzr_name,</if>
            <if test="fzrDuty != null">fzr_duty,</if>
            <if test="fzrTel != null">fzr_tel,</if>
            <if test="fzrEmail != null">fzr_email,</if>
            <if test="isStatus != null">isStatus,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId != null">#{areaId},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="postalCode != null">#{postalCode},</if>
            <if test="addressProvince != null">#{addressProvince},</if>
            <if test="addressCity != null">#{addressCity},</if>
            <if test="addressCounty != null">#{addressCounty},</if>
            <if test="unitAddress != null">#{unitAddress},</if>
            <if test="countyCode != null">#{countyCode},</if>
            <if test="lsGx != null">#{lsGx},</if>
            <if test="unitType != null">#{unitType},</if>
            <if test="industryType != null">#{industryType},</if>
            <if test="fzrName != null">#{fzrName},</if>
            <if test="fzrDuty != null">#{fzrDuty},</if>
            <if test="fzrTel != null">#{fzrTel},</if>
            <if test="fzrEmail != null">#{fzrEmail},</if>
            <if test="isStatus != null">#{isStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTcDbdw" parameterType="TcDbdw">
        update tc_dbdw
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="postalCode != null">postal_code = #{postalCode},</if>
            <if test="addressProvince != null">address_province = #{addressProvince},</if>
            <if test="addressCity != null">address_city = #{addressCity},</if>
            <if test="addressCounty != null">address_county = #{addressCounty},</if>
            <if test="unitAddress != null">unit_address = #{unitAddress},</if>
            <if test="countyCode != null">county_code = #{countyCode},</if>
            <if test="lsGx != null">ls_gx = #{lsGx},</if>
            <if test="unitType != null">unit_type = #{unitType},</if>
            <if test="industryType != null">industry_type = #{industryType},</if>
            <if test="fzrName != null">fzr_name = #{fzrName},</if>
            <if test="fzrDuty != null">fzr_duty = #{fzrDuty},</if>
            <if test="fzrTel != null">fzr_tel = #{fzrTel},</if>
            <if test="fzrEmail != null">fzr_email = #{fzrEmail},</if>
            <if test="isStatus != null">isStatus = #{isStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateByisStatus">
        UPDATE tc_dbdw
        SET isStatus = #{isStatus}
        WHERE id IN
        <foreach collection="ids" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <delete id="deleteTcDbdwById" parameterType="Long">
        delete from tc_dbdw where id = #{id}
    </delete>

    <delete id="deleteTcDbdwByIds" parameterType="String">
        delete from tc_dbdw where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>