<?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.system.mapper.house.BusinessEntityInfoMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.house.BusinessEntityInfo">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="nature" property="nature" jdbcType="VARCHAR"/>
        <result column="social_credit_code" property="socialCreditCode" jdbcType="VARCHAR"/>
        <result column="principal" property="principal" jdbcType="VARCHAR"/>
        <result column="principal_tel" property="principalTel" jdbcType="VARCHAR"/>
        <result column="business" property="business" jdbcType="VARCHAR"/>
        <result column="worker_number" property="workerNumber" jdbcType="INTEGER"/>
        <result column="registered_address" property="registeredAddress" jdbcType="VARCHAR"/>
        <result column="industry_classification" property="industryClassification" jdbcType="VARCHAR"/>
        <result property="gs" column="gs" jdbcType="INTEGER"/>
        <result property="registrationPlaceFlag" column="registration_place_flag" jdbcType="INTEGER"/>
        <result property="associationBusinessEntityFlag" column="association_business_entity_flag" jdbcType="INTEGER"/>
        <result property="backPayFlag" column="back_pay_flag" jdbcType="INTEGER"/>
        <result property="stabilityRelated" column="stability_related" jdbcType="VARCHAR"/>
        <result property="investigationDate" column="investigation_date" jdbcType="DATE"/>
        <result property="note" column="note" jdbcType="LONGVARCHAR"/>
    </resultMap>

    <insert id="insertBusinessEntityInfo" parameterType="com.ruoyi.system.domain.house.BusinessEntityInfo">
        INSERT INTO business_entity_info (
            id, name, nature, social_credit_code,
            principal, principal_tel, business, worker_number, registered_address, industry_classification, gs, registration_place_flag, association_business_entity_flag, back_pay_flag, stability_related, investigation_date, note
        ) VALUES (
                     #{id}, #{name}, #{nature}, #{socialCreditCode},
                     #{principal}, #{principalTel}, #{business}, #{workerNumber}, #{registeredAddress}, #{industryClassification}, #{gs}, #{registrationPlaceFlag}, #{associationBusinessEntityFlag}, #{backPayFlag}, #{stabilityRelated}, #{investigationDate}, #{note}
                 )
    </insert>

    <select id="selectBusinessEntityInfoById" resultMap="BaseResultMap">
        SELECT * FROM business_entity_info WHERE id = #{id}
    </select>

    <update id="updateBusinessEntityInfo" parameterType="com.ruoyi.system.domain.house.BusinessEntityInfo">
        UPDATE business_entity_info
        <set>
            <if test="name != null">name=#{name},</if>
            <if test="nature != null">nature=#{nature},</if>
            <if test="socialCreditCode != null">social_credit_code=#{socialCreditCode},</if>
            <if test="principal != null">principal=#{principal},</if>
            <if test="principalTel != null">principal_tel=#{principalTel},</if>
            <if test="business != null">business=#{business},</if>
            <if test="workerNumber != null">worker_number=#{workerNumber},</if>
            <if test="registeredAddress != null">registered_address=#{registeredAddress},</if>
            <if test="industryClassification != null">industry_classification=#{industryClassification},</if>
            <if test="gs != null">gs=#{gs},</if>
            <if test="registrationPlaceFlag != null">registration_place_flag=#{registrationPlaceFlag},</if>
            <if test="associationBusinessEntityFlag != null">association_business_entity_flag=#{associationBusinessEntityFlag},</if>
            <if test="backPayFlag != null">back_pay_flag=#{backPayFlag},</if>
            <if test="stabilityRelated != null">stability_related=#{stabilityRelated},</if>
            <if test="investigationDate != null">investigation_date=#{investigationDate},</if>
            <if test="note != null">note=#{note},</if>
        </set>
        WHERE id=#{id}
    </update>

    <delete id="deleteBusinessEntityInfoById">
        DELETE FROM business_entity_info WHERE id = #{id}
    </delete>

    <select id="selectAllBusinessEntityInfos" resultMap="BaseResultMap">
        SELECT * FROM business_entity_info
    </select>
    <select id="selectByName" resultType="com.ruoyi.system.domain.house.BusinessEntityInfo">
        SELECT
            t3.*
        FROM
            house_resource t1
                LEFT JOIN house_resource_business_entity_info_mapping t2 ON t1.id = t2.house_resource_id
                LEFT JOIN business_entity_info t3 ON t2.business_entity_info_id = t3.id
        WHERE t3.name like concat('%', #{name}, '%')
    </select>
    <select id="selectByIdList" resultType="com.ruoyi.system.domain.house.BusinessEntityInfo">
        SELECT * FROM business_entity_info WHERE id IN
        <foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>
