<?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.dgtly.companyext.mapper.CompanyReviewedMapper">
    
    <resultMap type="CompanyReviewed" id="CompanyReviewedResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyName"    column="company_name"    />
        <result property="companyType"    column="company_type"    />
        <result property="detailAddress"    column="detail_address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="legalPerson"    column="legal_person"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="establishDate"    column="establish_date"    />
        <result property="unifiedSocialCreditCode"    column="unified_social_credit_code"    />
        <result property="businessLicenseUrl"    column="business_license_url"    />
        <result property="defaultImgUrl"    column="default_img_url"    />
        <result property="propagandaImgUrl"    column="propaganda_img_url"    />
        <result property="companyIntroduce"    column="company_introduce"    />
        <result property="versionNum"    column="version_num"    />
        <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"    />
        <result property="loginName"    column="login_name"    />
        <result property="password"    column="password"    />
        <result property="reason"    column="reason"    />
        <result property="status"    column="status"    />
        <result property="primaryBusiness"    column="primary_business"    />
    </resultMap>

    <sql id="selectCompanyReviewedVo">
        select id, company_id, company_name, company_type, detail_address, longitude, latitude, legal_person, contact_number, establish_date,
         unified_social_credit_code, business_license_url, default_img_url, propaganda_img_url, company_introduce, version_num, create_by,
         create_time, update_by, update_time, remark ,login_name,password,reason,status,primary_business
         from company_reviewed
    </sql>

    <select id="selectCompanyReviewedList" parameterType="CompanyReviewed" resultMap="CompanyReviewedResult">
        <include refid="selectCompanyReviewedVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="companyType != null "> and company_type = #{companyType}</if>
            <if test="detailAddress != null  and detailAddress != ''"> and detail_address = #{detailAddress}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="legalPerson != null  and legalPerson != ''"> and legal_person = #{legalPerson}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="establishDate != null "> and establish_date = #{establishDate}</if>
            <if test="unifiedSocialCreditCode != null  and unifiedSocialCreditCode != ''"> and unified_social_credit_code = #{unifiedSocialCreditCode}</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''"> and business_license_url = #{businessLicenseUrl}</if>
            <if test="defaultImgUrl != null  and defaultImgUrl != ''"> and default_img_url = #{defaultImgUrl}</if>
            <if test="propagandaImgUrl != null  and propagandaImgUrl != ''"> and propaganda_img_url = #{propagandaImgUrl}</if>
            <if test="companyIntroduce != null  and companyIntroduce != ''"> and company_introduce = #{companyIntroduce}</if>
            <if test="versionNum != null "> and version_num = #{versionNum}</if>
            <if test="loginName != null  and loginName != ''"> and login_name = #{loginName}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectCompanyReviewedById" parameterType="Long" resultMap="CompanyReviewedResult">
        <include refid="selectCompanyReviewedVo"/>
        where id = #{id}
    </select>
    <select id="selectCompanyReviewedByCompanyId" parameterType="Long" resultMap="CompanyReviewedResult">
        <include refid="selectCompanyReviewedVo"/>
        where company_id = #{companyId}
    </select>
        
    <insert id="insertCompanyReviewed" parameterType="CompanyReviewed" useGeneratedKeys="true" keyProperty="id">
        insert into company_reviewed
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null ">company_id,</if>
            <if test="companyName != null  and companyName != ''">company_name,</if>
            <if test="companyType != null ">company_type,</if>
            <if test="detailAddress != null  and detailAddress != ''">detail_address,</if>
            <if test="longitude != null  and longitude != ''">longitude,</if>
            <if test="latitude != null  and latitude != ''">latitude,</if>
            <if test="legalPerson != null  and legalPerson != ''">legal_person,</if>
            <if test="contactNumber != null  and contactNumber != ''">contact_number,</if>
            <if test="establishDate != null ">establish_date,</if>
            <if test="unifiedSocialCreditCode != null  and unifiedSocialCreditCode != ''">unified_social_credit_code,</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''">business_license_url,</if>
            <if test="defaultImgUrl != null  and defaultImgUrl != ''">default_img_url,</if>
            <if test="propagandaImgUrl != null  and propagandaImgUrl != ''">propaganda_img_url,</if>
            <if test="companyIntroduce != null  and companyIntroduce != ''">company_introduce,</if>
            <if test="versionNum != null ">version_num,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
            <if test="loginName != null  and loginName != ''">  login_name ,</if>
            <if test="password != null  and password != ''"> password ,</if>
            <if test="reason != null  and reason != ''">  reason,</if>
            <if test="status != null ">status ,</if>
            <if test="primaryBusiness != null  and primaryBusiness != ''">primary_business,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null ">#{companyId},</if>
            <if test="companyName != null  and companyName != ''">#{companyName},</if>
            <if test="companyType != null ">#{companyType},</if>
            <if test="detailAddress != null  and detailAddress != ''">#{detailAddress},</if>
            <if test="longitude != null  and longitude != ''">#{longitude},</if>
            <if test="latitude != null  and latitude != ''">#{latitude},</if>
            <if test="legalPerson != null  and legalPerson != ''">#{legalPerson},</if>
            <if test="contactNumber != null  and contactNumber != ''">#{contactNumber},</if>
            <if test="establishDate != null ">#{establishDate},</if>
            <if test="unifiedSocialCreditCode != null  and unifiedSocialCreditCode != ''">#{unifiedSocialCreditCode},</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''">#{businessLicenseUrl},</if>
            <if test="defaultImgUrl != null  and defaultImgUrl != ''">#{defaultImgUrl},</if>
            <if test="propagandaImgUrl != null  and propagandaImgUrl != ''">#{propagandaImgUrl},</if>
            <if test="companyIntroduce != null  and companyIntroduce != ''">#{companyIntroduce},</if>
            <if test="versionNum != null ">#{versionNum},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
            <if test="loginName != null  and loginName != ''"> #{loginName},</if>
            <if test="password != null  and password != ''"> #{password},</if>
            <if test="reason != null  and reason != ''"> #{reason},</if>
            <if test="status != null "> #{status},</if>
            <if test="primaryBusiness != null  and primaryBusiness != ''">#{primaryBusiness},</if>
         </trim>
    </insert>

    <update id="updateCompanyReviewed" parameterType="CompanyReviewed">
        update company_reviewed
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null ">company_id = #{companyId},</if>
            <if test="companyName != null  and companyName != ''">company_name = #{companyName},</if>
            <if test="companyType != null ">company_type = #{companyType},</if>
            <if test="detailAddress != null  and detailAddress != ''">detail_address = #{detailAddress},</if>
            <if test="longitude != null  and longitude != ''">longitude = #{longitude},</if>
            <if test="latitude != null  and latitude != ''">latitude = #{latitude},</if>
            <if test="legalPerson != null  and legalPerson != ''">legal_person = #{legalPerson},</if>
            <if test="contactNumber != null  and contactNumber != ''">contact_number = #{contactNumber},</if>
            <if test="establishDate != null ">establish_date = #{establishDate},</if>
            <if test="unifiedSocialCreditCode != null  and unifiedSocialCreditCode != ''">unified_social_credit_code = #{unifiedSocialCreditCode},</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''">business_license_url = #{businessLicenseUrl},</if>
            <if test="defaultImgUrl != null  and defaultImgUrl != ''">default_img_url = #{defaultImgUrl},</if>
            <if test="propagandaImgUrl != null  and propagandaImgUrl != ''">propaganda_img_url = #{propagandaImgUrl},</if>
            <if test="companyIntroduce != null  and companyIntroduce != ''">company_introduce = #{companyIntroduce},</if>
            <if test="versionNum != null ">version_num = #{versionNum},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
            <if test="loginName != null  and loginName != ''">  login_name = #{loginName},</if>
            <if test="password != null  and password != ''">  password = #{password},</if>
            <if test="reason != null  and reason != ''">  reason = #{reason},</if>
            <if test="status != null ">  status = #{status},</if>
            <if test="primaryBusiness != null  and primaryBusiness != ''">primary_business=#{primaryBusiness},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyReviewedById" parameterType="Long">
        delete from company_reviewed where id = #{id}
    </delete>

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

    <select id="checkLoginNameUnique"  resultType="int">
		select count(1) from company_reviewed where login_name=#{loginName} and reason='0' and status="0"
	</select>

    <select id="selectCompanyReviewedListWiteAudit" parameterType="CompanyReviewed" resultMap="CompanyReviewedResult">
        <include refid="selectCompanyReviewedVo"/>
        <where>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="companyType != null "> and company_type = #{companyType}</if>
            <if test="detailAddress != null  and detailAddress != ''"> and detail_address = #{detailAddress}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="legalPerson != null  and legalPerson != ''"> and legal_person = #{legalPerson}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="establishDate != null "> and establish_date = #{establishDate}</if>
            <if test="unifiedSocialCreditCode != null  and unifiedSocialCreditCode != ''"> and unified_social_credit_code = #{unifiedSocialCreditCode}</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''"> and business_license_url = #{businessLicenseUrl}</if>
            <if test="defaultImgUrl != null  and defaultImgUrl != ''"> and default_img_url = #{defaultImgUrl}</if>
            <if test="propagandaImgUrl != null  and propagandaImgUrl != ''"> and propaganda_img_url = #{propagandaImgUrl}</if>
            <if test="companyIntroduce != null  and companyIntroduce != ''"> and company_introduce = #{companyIntroduce}</if>
            <if test="versionNum != null "> and version_num = #{versionNum}</if>
            <if test="loginName != null  and loginName != ''"> and login_name = #{loginName}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
        </where>
        order by status,create_time
    </select>
    
</mapper>