<?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.ruoyi.web.work.mapper.PositionMapper">

    <select id="selectList" resultType="com.ruoyi.web.work.domain.Position">
        SELECT
        p.*,
        e.name AS enterpriseName
        FROM
        tb_position p
        LEFT JOIN tb_enterprise e ON e.id = p.user_id
        <where>
            <if test="type != null "> AND p.type = #{type}</if>
            <if test="audit != null "> AND p.audit = #{audit}</if>
            <if test="recommend != null "> AND p.recommend = #{recommend}</if>
            <if test="title != null  and title != ''"> AND concat(p.title,e.name) LIKE concat('%', #{title}, '%')</if>
            <if test="dateBegin != null  and dateBegin != ''"> AND p.create_time BETWEEN #{dateBegin} AND #{dateEnd} + INTERVAL 1 DAY</if>
</where>
    </select>
    <select id="manageList" resultType="com.ruoyi.web.work.domain.Position">
        select * from tb_position
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="audit != null "> and audit = #{audit}</if>
            <if test="title != null  and title != ''"> and title like concat('%', #{name}, '%')</if>
        </where>
    </select>
    <select id="indexList" resultType="com.ruoyi.web.work.domain.vo.PositionListVo">
        SELECT
        id,
        type,
        title,
        pic,
        experience,
        salary,
        region_name,
        location,
        latitude,
        longitude,
        start_date,
        end_date
        <if test="longitude !=null and longitude != '' ">,ROUND( ST_Distance_Sphere ( POINT ( #{longitude}, #{latitude} ), POINT ( longitude, latitude ))/ 1000, 2 ) AS distance</if>
        FROM
        tb_position
        WHERE
        state = 0
        AND audit = 1
        AND complete = 0
        <if test="type != null "> AND type = #{type}</if>
        <if test="enterpriseId != null "> AND user_id = #{enterpriseId}</if>
        <if test="title != null and title != ''"> AND title LIKE concat('%', #{title}, '%')</if>
        <if test="regionId != null">AND FIND_IN_SET(#{regionId},ancestors)</if>
        <if test="positionId != null"> AND position_id=#{positionId}</if>
        <if test="experience != null  and experience.size() > 0">AND experience IN (<foreach collection="experience" item="name" separator=",">#{name}</foreach>)</if>
        <if test="min != null and max !=null">AND min <![CDATA[ >= ]]> #{min} AND max <![CDATA[ <= ]]> #{max}</if>
        <if test="recommend != null "> AND recommend = #{recommend}</if>
        <if test="orderBy=='distance' and longitude !=null">ORDER BY distance ASC</if>
        <if test="orderBy=='id'">ORDER BY id DESC</if>
    </select>
</mapper>