<?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="cn.ezhizao.project.business.standardCpmpany.mapper.BizStandardCompanyMapper">

    <resultMap type="cn.ezhizao.project.business.standardCpmpany.domain.BizStandardCompany" id="BizStandardCompanyResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizStandardCompany" resultMap="BizStandardCompanyResult">
        SELECT
        c.*
        FROM biz_company c
        LEFT JOIN sys_user s ON c.leader_id=s.user_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="category != null  and category != ''"> AND category = #{category}</if>
            <if test="code != null  and code != ''"> AND code = #{code}</if>
            <if test="name != null  and name != ''"> AND name like concat('%', #{name}, '%')</if>
            <if test="shortName != null  and shortName != ''"> AND short_name like concat('%', #{shortName}, '%')</if>
            <if test="oldName != null  and oldName != ''"> AND old_name like concat('%', #{oldName}, '%')</if>
            <if test="owner != null  and owner != ''"> AND owner = #{owner}</if>
            <if test="phone != null  and phone != ''"> AND phone = #{phone}</if>
            <if test="email != null  and email != ''"> AND email = #{email}</if>
            <if test="contactAddress != null  and contactAddress != ''"> AND contact_address = #{contactAddress}</if>
            <if test="source != null  and source != ''"> AND source = #{source}</if>
            <if test="type != null  and type != ''"> AND type = #{type}</if>
            <if test="socialCreditCode != null  and socialCreditCode != ''"> AND social_credit_code = #{socialCreditCode}</if>
            <if test="mainBusiness != null  and mainBusiness != ''"> AND main_business = #{mainBusiness}</if>
            <if test="legalRepresentative != null  and legalRepresentative != ''"> AND legal_representative = #{legalRepresentative}</if>
            <if test="foundationDate != null  and foundationDate != ''"> AND foundation_date = #{foundationDate}</if>
            <if test="licenceDate != null  and licenceDate != ''"> AND licence_date = #{licenceDate}</if>
            <if test="businessStartDate != null  and businessStartDate != ''"> AND business_start_date = #{businessStartDate}</if>
            <if test="businessEndDate != null  and businessEndDate != ''"> AND business_end_date = #{businessEndDate}</if>
            <if test="isPermanentlyEffective != null "> AND is_permanently_effective = #{isPermanentlyEffective}</if>
            <if test="registerMoney != null  and registerMoney != ''"> AND register_money = #{registerMoney}</if>
            <if test="registerMoneyUnit != null  and registerMoneyUnit != ''"> AND register_money_unit = #{registerMoneyUnit}</if>
            <if test="provinceCode != null  and provinceCode != ''"> AND province_code = #{provinceCode}</if>
            <if test="province != null  and province != ''"> AND province = #{province}</if>
            <if test="cityCode != null  and cityCode != ''"> AND city_code = #{cityCode}</if>
            <if test="city != null  and city != ''"> AND city = #{city}</if>
            <if test="districtCode != null  and districtCode != ''"> AND district_code = #{districtCode}</if>
            <if test="district != null  and district != ''"> AND district = #{district}</if>
            <if test="address != null  and address != ''"> AND address = #{address}</if>
            <if test="businessField != null  and businessField != ''"> AND business_field = #{businessField}</if>
            <if test="taxType != null  and taxType != ''"> AND tax_type = #{taxType}</if>
            <if test="isZero != null "> AND is_zero = #{isZero}</if>
            <if test="competentTaxAuthority != null  and competentTaxAuthority != ''"> AND competent_tax_authority = #{competentTaxAuthority}</if>
            <if test="taxCollectorName != null  and taxCollectorName != ''"> AND tax_collector_name like concat('%', #{taxCollectorName}, '%')</if>
            <if test="taxCollectorPhone != null  and taxCollectorPhone != ''"> AND tax_collector_phone = #{taxCollectorPhone}</if>
            <if test="taxMonth != null "> AND tax_month = #{taxMonth}</if>
            <if test="openingBank != null  and openingBank != ''"> AND opening_bank = #{openingBank}</if>
            <if test="bankAccount != null  and bankAccount != ''"> AND bank_account = #{bankAccount}</if>
            <if test="annualIncome != null  and annualIncome != ''"> AND annual_income = #{annualIncome}</if>
            <if test="governmentAccountNo != null  and governmentAccountNo != ''"> AND government_account_no = #{governmentAccountNo}</if>
            <if test="governmentPassword != null  and governmentPassword != ''"> AND government_password = #{governmentPassword}</if>
            <if test="socialSecurityAccountNo != null  and socialSecurityAccountNo != ''"> AND social_security_account_no = #{socialSecurityAccountNo}</if>
            <if test="socialSecurityPassword != null  and socialSecurityPassword != ''"> AND social_security_password = #{socialSecurityPassword}</if>
            <if test="employeePassword != null  and employeePassword != ''"> AND employee_password = #{employeePassword}</if>
            <if test="housingFundPassword != null  and housingFundPassword != ''"> AND housing_fund_password = #{housingFundPassword}</if>
            <if test="housingFundUnitAccount != null  and housingFundUnitAccount != ''"> AND housing_fund_unit_account = #{housingFundUnitAccount}</if>
            <if test="housingFundDeductionPassword != null  and housingFundDeductionPassword != ''"> AND housing_fund_deduction_password = #{housingFundDeductionPassword}</if>
            <if test="collectionMethod != null  and collectionMethod != ''"> AND collection_method = #{collectionMethod}</if>
            <if test="quotaAmount != null "> AND quota_amount = #{quotaAmount}</if>
            <if test="isPayOnWindow != null "> AND is_pay_on_window = #{isPayOnWindow}</if>
            <if test="isFirstSocialSecurity != null "> AND is_first_social_security = #{isFirstSocialSecurity}</if>
            <if test="isFirstHousingFund != null "> AND is_first_housing_fund = #{isFirstHousingFund}</if>
            <if test="leaderId != null and  leaderId != '' "> AND c.leader_id = #{leaderId}</if>
            <if test="adviserId != null  and  adviserId != ''"> AND c.adviser_id = #{adviserId}</if>
            <if test="leaderName != null and  leaderName != '' "> AND s.nick_name LIKE concat('%', #{leaderName}, '%')</if>
            <if test="tenantId != null ">AND c.tenant_id = #{tenantId}</if>
        </trim>
        order by c.create_time desc
    </select>

    <select id="getUserById" resultType="String">
        SELECT nick_name FROM sys_user  WHERE user_id = #{id}
    </select>

    <update id="updateLeaderId">
        UPDATE biz_company SET leader_id=#{userId}
        WHERE id=#{id}
    </update>

    <update id="updateAdviserId">
        UPDATE biz_company SET adviser_id=#{userId}
        WHERE id=#{id}
    </update>

    <delete id="physicalDelete">
        DELETE FROM biz_company
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
            <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
