<?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.companyFollow.mapper.BizCompanyFollowDetailMapper">

    <resultMap type="cn.ezhizao.project.business.companyFollow.domain.BizCompanyFollowDetail" id="BizCompanyFollowDetailResult">
        <id column="id" property="id"/>
        <collection property="files" column="id" select="getFiles" />
    </resultMap>

    <resultMap id="FileResultMap" type="cn.ezhizao.project.system.domain.SysFileStorage">
        <id column="id" jdbcType="INTEGER" property="id"/>
    </resultMap>

    <select id="getFiles" resultMap="FileResultMap">
        select *
        from sys_file_storage
        where master_id = #{id} and master_table_name = 'biz_company_follow_detail'
    </select>

    <select id="getList" parameterType="BizCompanyFollowDetail" resultMap="BizCompanyFollowDetailResult">
        SELECT a.*, b.dict_label as follow_mode, f.dict_label as follow_category FROM biz_company_follow_detail a
        left join sys_dict_data b on b.dict_code = a.follow_type_id
        left join sys_dict_data f on f.dict_code = a.follow_category_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            a.deleted = 0
            <if test="id != null "> AND a.id = #{id}</if>
            <if test="companyId != null "> AND a.company_id = #{companyId}</if>
            <if test="tenantId != null "> AND a.tenant_id = #{tenantId}</if>
            <if test="followDate != null "> AND a.follow_date = #{followDate}</if>
            <if test="nextFollowDate != null "> AND a.next_follow_date = #{nextFollowDate}</if>
            <if test="content != null  and content != ''"> AND a.content = #{content}</if>
        </trim>
        <if test="asc == true">
            order by follow_date asc
        </if>
        <if test="asc == false">
            order by follow_date desc
        </if>
    </select>

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