<?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.sqx.modules.app.dao.UserBrowseDao">
    <select id="selectMyBrowse" resultType="com.sqx.modules.app.response.UserFollowResponse">
        SELECT b.id,
               t.user_id,
               t.user_name,
               t.avatar,
               t.sex,
               t.age,
               b.update_time,
               b.taking_id
        FROM user_browse b
                 left join order_taking o on o.id = b.taking_id
                 LEFT JOIN tb_user t ON b.by_browse_id = t.user_id
        WHERE b.user_id = #{userId}
          and o.id is not null
        order by b.update_time desc
    </select>
    <select id="selectMyVisitor1" resultType="com.sqx.modules.app.response.UserFollowResponse">
        SELECT t.user_id,
               t.user_name,
               t.avatar
        FROM user_browse b
                 LEFT JOIN tb_user t ON b.user_id = t.user_id
        WHERE b.by_browse_id = #{userId}
          and t.user_id is not null
        order by b.update_time desc
    </select>
    <select id="selectMyBrowse1" resultType="com.sqx.modules.app.response.UserFollowResponse">
        SELECT t.user_id,
               t.user_name,
               t.avatar
        FROM user_browse b
                 LEFT JOIN tb_user t ON b.by_browse_id = t.user_id
        WHERE b.user_id = #{userId}
          and t.user_id is not null
        order by b.update_time desc
    </select>


    <select id="selectUserBrowseCountByUserId" resultType="Integer">
        select count(*) from user_browse where user_id=#{userId}
        <if test="startTime!=null and startTime!=''">
            and date_format(update_time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime!=null and endTime!=''">
            and date_format(update_time,'%Y-%m-%d')&lt;=date_format(#{endTime},'%Y-%m-%d')
        </if>
    </select>
    <select id="getUserByBrowse" resultType="com.sqx.modules.app.entity.UserEntity">
        select u.*
        from tb_user u,
             user_browse b
        where b.user_id = u.user_id
          and b.post_push_id = #{postPushId}
        order by b.update_time desc
    </select>
    <select id="selectBrowseList" resultType="com.sqx.modules.app.vo.UserPostPushBrowseVo">
        SELECT
        p.*,
        c.company_name,
        c.company_logo,
        c.company_address,
        c.company_lng,
        c.company_lat,
        c.company_people,
        c.company_legal_person,
        c.company_scope
        FROM
        user_browse b,
        post_push p,
        company c
        WHERE p.company_id = c.company_id
        AND b.post_push_id = p.post_push_id
        <if test="experience!=null and experience.length!=0">
            and
            <foreach collection="experience" item="item" open="(" separator="or" close=")">
                p.experience like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="industry!=null and industry.length!=0">
            and
            <foreach collection="industry" item="item" open="(" separator="or" close=")">
                p.industry like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="salaryRange!=null and salaryRange.length!=0">
            and
            <foreach collection="salaryRange" item="item" open="(" separator="or" close=")">
                p.salary_range like concat("%",#{item},"%")
            </foreach>
        </if>

        <if test="companyPeople!=null and companyPeople.length!=0">
            and
            <foreach collection="companyPeople" item="item" open="(" separator="or" close=")">
                c.company_people like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="education!=null and education.length!=0">
            and
            <foreach collection="education" item="item" open="(" separator="or" close=")">
                p.education like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="userBrowse.userId!=null">
            and b.user_id = #{userBrowse.userId}
        </if>
        and b.browse_type = 1

        order by b.update_time desc
    </select>
    <select id="selectCompanyBrowse" resultType="com.sqx.modules.app.vo.ResumesBrowseVo">
        select s.*,
        u.avatar,
        b.update_time as b_update_time
        from resumes s,
        tb_user u,
        user_browse b
        where s.user_id = u.user_id
        and b.resumes_user_id = u.user_id
        and b.browse_type = 2
        and b.user_id = #{userBrowse.userId}
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            and date_format(b.update_time,'%Y-%m-%d') BETWEEN #{startTime} and #{endTime}
        </if>
        <if test="startTime!=null and startTime!='' and  (endTime==null or endTime=='')">
            and date_format(b.update_time,'%Y-%m-%d') &gt;= #{startTime}
        </if>
        <if test="endTime!=null and endTime!='' and  (startTime==null or startTime=='')">
            and date_format(b.update_time,'%Y-%m-%d') &lt;= #{endTime}
        </if>
        <if test="resumes.resumesPost!=null and resumes.resumesPost!=''">
            and s.resumes_post like concat("%",#{resumes.resumesPost},"%")
        </if>
        <if test="resumesCompensation!=null and resumesCompensation.length!=0">
            and
            <foreach collection="resumesCompensation" item="item" open="(" separator="or" close=")">
                s.resumes_compensation like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="resumesEducation!=null and resumesEducation.length!=0">
            and
            <foreach collection="resumesEducation" item="item" open="(" separator="or" close=")">
                s.resumes_education like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="resumesWorkExperience!=null and resumesWorkExperience.length!=0">
            and
            <foreach collection="resumesWorkExperience" item="item" open="(" separator="or" close=")">
                s.resumes_work_experience like concat("%",#{item},"%")
            </foreach>
        </if>
        <if test="industryName!=null and industryName.length!=0">
            and
            <foreach collection="industryName" item="item" open="(" separator="or" close=")">
                s.industry_name like concat("%",#{item},"%")
            </foreach>
        </if>
        order by b.update_time desc
    </select>

</mapper>