<?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.basic.mapper.HwTenantMapper">

    <resultMap type="HwTenant" id="HwTenantResult">
        <result property="tenantId"    column="tenant_id"    />
        <result property="tenantType"    column="tenant_type"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="tenantIndustry"    column="tenant_industry"    />
        <result property="contactName"    column="contact_name"    />
        <result property="contactPhone"    column="contact_phone"    />
        <result property="email"    column="email"    />
        <result property="areaId"    column="area_id"    />
        <result property="contactAddress"    column="contact_address"    />
        <result property="remark"    column="remark"    />
        <result property="tenantStatus"    column="tenant_status"    />
        <result property="isRegister"    column="is_register"    />
        <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="tenantGrade"    column="tenant_grade"    />
        <result property="tenantField"    column="tenant_field"    />
    </resultMap>

    <sql id="selectHwTenantVo">
        select tenant_id, tenant_type, tenant_name, tenant_industry, contact_name, contact_phone, email, area_id, contact_address, remark, tenant_status, is_register, create_by, create_time, update_by, update_time, tenant_grade, tenant_field from hw_tenant
    </sql>

    <select id="selectHwTenantList" parameterType="HwTenant" resultMap="HwTenantResult">
        <include refid="selectHwTenantVo"/>
        <where>
            <if test="tenantType != null  and tenantType != ''"> and tenant_type = #{tenantType}</if>
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="tenantIndustry != null "> and tenant_industry = #{tenantIndustry}</if>
            <if test="contactName != null  and contactName != ''"> and contact_name like concat('%', #{contactName}, '%')</if>
            <if test="contactPhone != null  and contactPhone != ''"> and contact_phone like concat ('%', #{contactPhone}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="contactAddress != null  and contactAddress != ''"> and contact_address = #{contactAddress}</if>
            <if test="tenantStatus != null  and tenantStatus != ''"> and tenant_status = #{tenantStatus}</if>
            <if test="isRegister != null  and isRegister != ''"> and is_register = #{isRegister}</if>
            <if test="tenantGrade != null "> and tenant_grade = #{tenantGrade}</if>
            <if test="tenantField != null  and tenantField != ''"> and tenant_field = #{tenantField}</if>
        </where>
    </select>

    <select id="selectHwTenantByTenantId" parameterType="Long" resultMap="HwTenantResult">
        <include refid="selectHwTenantVo"/>
        where tenant_id = #{tenantId}
    </select>

    <insert id="insertHwTenant" parameterType="HwTenant" useGeneratedKeys="true" keyProperty="tenantId">
        insert into hw_tenant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantType != null and tenantType != ''">tenant_type,</if>
            <if test="tenantName != null and tenantName != ''">tenant_name,</if>
            <if test="tenantIndustry != null">tenant_industry,</if>
            <if test="contactName != null and contactName != ''">contact_name,</if>
            <if test="contactPhone != null and contactPhone != ''">contact_phone,</if>
            <if test="email != null">email,</if>
            <if test="areaId != null">area_id,</if>
            <if test="contactAddress != null">contact_address,</if>
            <if test="remark != null">remark,</if>
            <if test="tenantStatus != null and tenantStatus != ''">tenant_status,</if>
            <if test="isRegister != null and isRegister != ''">is_register,</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="tenantGrade != null">tenant_grade,</if>
            <if test="tenantField != null">tenant_field,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantType != null and tenantType != ''">#{tenantType},</if>
            <if test="tenantName != null and tenantName != ''">#{tenantName},</if>
            <if test="tenantIndustry != null">#{tenantIndustry},</if>
            <if test="contactName != null and contactName != ''">#{contactName},</if>
            <if test="contactPhone != null and contactPhone != ''">#{contactPhone},</if>
            <if test="email != null">#{email},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="contactAddress != null">#{contactAddress},</if>
            <if test="remark != null">#{remark},</if>
            <if test="tenantStatus != null and tenantStatus != ''">#{tenantStatus},</if>
            <if test="isRegister != null and isRegister != ''">#{isRegister},</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="tenantGrade != null">#{tenantGrade},</if>
            <if test="tenantField != null">#{tenantField},</if>
         </trim>
    </insert>

    <update id="updateHwTenant" parameterType="HwTenant">
        update hw_tenant
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantType != null and tenantType != ''">tenant_type = #{tenantType},</if>
            <if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
            <if test="tenantIndustry != null">tenant_industry = #{tenantIndustry},</if>
            <if test="contactName != null and contactName != ''">contact_name = #{contactName},</if>
            <if test="contactPhone != null and contactPhone != ''">contact_phone = #{contactPhone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="contactAddress != null">contact_address = #{contactAddress},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="tenantStatus != null and tenantStatus != ''">tenant_status = #{tenantStatus},</if>
            <if test="isRegister != null and isRegister != ''">is_register = #{isRegister},</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="tenantGrade != null">tenant_grade = #{tenantGrade},</if>
            <if test="tenantField != null">tenant_field = #{tenantField},</if>
        </trim>
        where tenant_id = #{tenantId}
    </update>

    <delete id="deleteHwTenantByTenantId" parameterType="Long">
UPDATE hw_tenant t1,sys_user t2
 set t1.tenant_status = '9', t2.del_flag = '2'
 where t1.tenant_id = t2.tenant_id  and t1.tenant_id=#{tenantId}  </delete>

    <delete id="deleteHwTenantByTenantIds" parameterType="String">
        UPDATE hw_tenant t1,sys_user t2
        set t1.tenant_status = '9', t2.del_flag = '2'
        where t1.tenant_id = t2.tenant_id and t1.tenant_id in
        <foreach item="tenantId" collection="array" open="(" separator="," close=")">
            #{tenantId}
        </foreach>
    </delete>
</mapper>
