<?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.fs.store.mapper.FsFollowMapper">

    <resultMap type="FsFollow" id="FsFollowResult">
        <result property="followId"    column="follow_id"    />
        <result property="tempId"    column="temp_id"    />
        <result property="patientId"    column="patient_id"    />
        <result property="patientName"    column="patient_name"    />
        <result property="patientPhone"    column="patient_phone"    />
        <result property="userId"    column="user_id"    />
        <result property="doctorId"    column="doctor_id"    />
        <result property="totalNum"    column="total_num"    />
        <result property="num"    column="num"    />
        <result property="pushStatus"    column="push_status"    />
        <result property="writeStatus"    column="write_status"    />
        <result property="planTime"    column="plan_time"    />
        <result property="formJson"    column="form_json"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="packageOrderId"    column="package_order_id"    />
        <result property="inquiryOrderId"    column="inquiry_order_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="writeUserName"    column="write_user_name"    />
        <result property="storeOrderId"    column="store_order_id"    />
    </resultMap>

    <sql id="selectFsFollowVo">
        select follow_id,temp_id,store_order_id,company_id,company_user_id,dept_id,write_user_name,patient_id,package_order_id,inquiry_order_id, patient_name, patient_phone, user_id, doctor_id, total_num, num, push_status, write_status, plan_time, form_json, create_time, update_time from fs_follow
    </sql>

    <select id="selectFsFollowList" parameterType="FsFollow" resultMap="FsFollowResult">
        <include refid="selectFsFollowVo"/>
        <where>
            <if test="patientName != null  and patientName != ''"> and patient_name like concat('%', #{patientName}, '%')</if>
            <if test="patientPhone != null  and patientPhone != ''"> and patient_phone like concat('%', #{patientPhone}, '%')</if>
            <if test="pushStatus != null "> and push_status = #{pushStatus}</if>
            <if test="writeStatus != null "> and write_status = #{writeStatus}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectFsFollowByFollowId" parameterType="Long" resultMap="FsFollowResult">
        <include refid="selectFsFollowVo"/>
        where follow_id = #{followId}
    </select>

    <insert id="insertFsFollow" parameterType="FsFollow" useGeneratedKeys="true" keyProperty="followId">
        insert into fs_follow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="followId != null">follow_id,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="patientId != null">patient_id,</if>
            <if test="patientName != null">patient_name,</if>
            <if test="patientPhone != null">patient_phone,</if>
            <if test="userId != null">user_id,</if>
            <if test="doctorId != null">doctor_id,</if>
            <if test="totalNum != null">total_num,</if>
            <if test="num != null">num,</if>
            <if test="pushStatus != null">push_status,</if>
            <if test="writeStatus != null">write_status,</if>
            <if test="planTime != null">plan_time,</if>
            <if test="formJson != null">form_json,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="packageOrderId != null">package_order_id,</if>
            <if test="inquiryOrderId != null">inquiry_order_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="writeUserName != null">write_user_name,</if>
            <if test="storeOrderId != null">store_order_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="followId != null">#{followId},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="patientId != null">#{patientId},</if>
            <if test="patientName != null">#{patientName},</if>
            <if test="patientPhone != null">#{patientPhone},</if>
            <if test="userId != null">#{userId},</if>
            <if test="doctorId != null">#{doctorId},</if>
            <if test="totalNum != null">#{totalNum},</if>
            <if test="num != null">#{num},</if>
            <if test="pushStatus != null">#{pushStatus},</if>
            <if test="writeStatus != null">#{writeStatus},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="formJson != null">#{formJson},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="packageOrderId != null">#{packageOrderId},</if>
            <if test="inquiryOrderId != null">#{inquiryOrderId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="writeUserName != null">#{writeUserName},</if>
            <if test="storeOrderId != null">#{storeOrderId},</if>
         </trim>
    </insert>

    <update id="updateFsFollow" parameterType="FsFollow">
        update fs_follow
        <trim prefix="SET" suffixOverrides=",">
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="patientId != null">patient_id = #{patientId},</if>
            <if test="patientName != null">patient_name = #{patientName},</if>
            <if test="patientPhone != null">patient_phone = #{patientPhone},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="doctorId != null">doctor_id = #{doctorId},</if>
            <if test="totalNum != null">total_num = #{totalNum},</if>
            <if test="num != null">num = #{num},</if>
            <if test="pushStatus != null">push_status = #{pushStatus},</if>
            <if test="writeStatus != null">write_status = #{writeStatus},</if>
            <if test="planTime != null">plan_time = #{planTime},</if>
            <if test="formJson != null">form_json = #{formJson},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="packageOrderId != null">package_order_id = #{packageOrderId},</if>
            <if test="inquiryOrderId != null">inquiry_order_id = #{inquiryOrderId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="writeUserName != null">write_user_name = #{writeUserName},</if>
            <if test="storeOrderId != null">store_order_id = #{storeOrderId},</if>
        </trim>
        where follow_id = #{followId}
    </update>

    <delete id="deleteFsFollowByFollowId" parameterType="Long">
        delete from fs_follow where follow_id = #{followId}
    </delete>

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

    <select id="selectFsFollowListVO_COUNT" parameterType="com.fs.store.param.FsFollowParam" resultType="Long">
    select count(1) from fs_follow ff
        <if test="doctorAccount != null "> LEFT JOIN fs_doctor fd ON fd.doctor_id=ff.doctor_id  </if>
        <if test="orderCode != null ">  LEFT JOIN fs_store_order fso ON fso.order_id=ff.store_order_id </if>
        <if test="companyUserName != null "> LEFT JOIN company_user cu ON cu.user_id =ff.company_user_id </if>
        where 1=1
        <if test="patientName != null  and patientName != ''"> and ff.patient_name like concat('%', #{patientName}, '%')</if>
        <if test="patientPhone != null  and patientPhone != ''"> and ff.patient_phone like concat('%', #{patientPhone}, '%')</if>
        <if test="orderCode != null "> and fso.order_code = #{orderCode}</if>
        <if test="userId != null "> and ff.user_id = #{userId}</if>
        <if test="companyUserName != null "> and cu.nick_name = #{companyUserName}</if>
        <if test="doctorAccount != null "> and fd.account = #{doctorAccount}</if>
        <if test="pushStatus != null "> and ff.push_status = #{pushStatus}</if>
        <if test="companyId != null "> and ff.company_id = #{companyId}</if>
        <if test="companyUserId != null "> and ff.company_user_id = #{companyUserId}</if>
        <if test="writeStatus != null "> and ff.write_status = #{writeStatus}</if>
        <if test="sTime != null ">  and DATE(ff.plan_time) &gt;= DATE(#{sTime})</if>
        <if test="eTime != null ">  and DATE(ff.plan_time) &lt;= DATE(#{eTime})</if>
    </select>

</mapper>
