<?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.post.mapper.PostMapper">


    <select id="selectPostWithUserAndCompanyByPostId" resultType="com.sqx.modules.post.dto.SelectAllDto">
        SELECT
        p.post_id AS postId,
        p.rule_classify_name AS ruleClassifyName,
        p.post_im_tag AS postImTag,
        p.wage AS wage,
        p.address AS address,
        p.if_due AS ifDue,
        p.wage_time AS wageTime,
        c.company_id AS companyId,
        c.company_name AS companyName,
        c.company_people as companyPeople,
        h.hr_img AS hrImg,
        h.hr_name AS hrName
        FROM
        post p
        LEFT JOIN
        company c ON p.company_id = c.company_id
        LEFT JOIN
        hr h  ON  p.user_id = h.user_id
        WHERE
         p.status = 1

    </select>
    <select id="selectPostOne" resultType="com.sqx.modules.post.dto.SelectOneDto">
        SELECT
            p.post_id AS postId,
            p.post_type AS postType,
            p.rule_classify_name AS ruleClassifyName,
            p.post_im_tag AS postImTag,
            p.post_describe AS postDescribe,
            p.wage_time AS wageTime,
        p.exp AS exp,
        p.edu AS edu,
        p.wage AS wage,
        p.welfare_tag AS welfareTag,
        p.welfare_details AS welfareDetails,
        p.comment_tag AS commentTag,
        p.address AS address,
        p.status AS status,
        p.if_due AS ifDue,
        c.company_id AS companyId,
        c.company_name AS companyName,
        c.company_people AS companyPeople,
        h.hr_img AS hrImg,
        h.hr_name AS hrName
        FROM
            post p
            LEFT JOIN
            company c ON p.company_id = c.company_id
            LEFT JOIN
            hr h  ON  p.user_id = h.user_id
        WHERE post_id = #{postId}
    </select>
    <select id="findPost" resultType="com.sqx.modules.post.dto.SelectAllDto" >
        SELECT
            p.post_id AS postId,
            p.rule_classify_name AS ruleClassifyName,
            p.post_im_tag AS postImTag,
            p.wage AS wage,
            p.address AS address,
            p.if_due AS ifDue,
            p.wage_time AS wageTime,
            c.company_id AS companyId,
            c.company_name AS companyName,
            c.company_people as companyPeople,
            h.hr_img AS hrImg,
            h.hr_name AS hrName
        FROM
            post p
                LEFT JOIN
            company c ON p.company_id = c.company_id
            LEFT JOIN
             hr h  ON  p.user_id = h.user_id
        WHERE
            p.status = 1
        <if test="key != null and key != ''">
            AND (
            c.company_name LIKE CONCAT('%', #{key}, '%')
            OR
            p.rule_classify_name LIKE CONCAT('%', #{key}, '%')
            )
        </if>
        <if test="address!=null and address!=0">
            and p.address=#{address}
        </if>
        <if test="wage!=null and wage!=0">
            and p.wage=#{wage}
        </if>
        <if test="edu!=null and edu!=0">
            and p.edu &lt;= #{edu}
        </if>
        <if test="companyPeople!=null and companyPeople!=0">
            and c.company_people=#{companyPeople}
        </if>
    </select>
    <select id="getViewPostList" resultType="com.sqx.modules.post.dto.SelectAllDto">
        SELECT
            p.post_id AS postId,
            p.rule_classify_name AS ruleClassifyName,
            p.post_im_tag AS postImTag,
            p.wage AS wage,
            p.address AS address,
            p.if_due AS ifDue,
            p.wage_time AS wageTime,
            c.company_id AS companyId,
            c.company_name AS companyName,
            c.company_people as companyPeople,
            h.hr_img AS hrImg,
            h.hr_name AS hrName
        FROM
            view_post v
                LEFT JOIN
            post p on v.post_id = p.post_id
                LEFT JOIN
            company c ON p.company_id = c.company_id
                LEFT JOIN
            hr h  ON  p.user_id = h.user_id
        WHERE
            p.status = 1
        and v.user_id = #{userId}
        ORDER BY v.creat_time desc;


    </select>
    <select id="getCollectPostList" resultType="com.sqx.modules.post.dto.SelectAllDto">
        SELECT
            p.post_id AS postId,
            p.rule_classify_name AS ruleClassifyName,
             p.post_im_tag AS postImTag,
             p.wage AS wage,
             p.address AS address,
            p.if_due AS ifDue,
            p.wage_time AS wageTime,
             c.company_id AS companyId,
            c.company_people as companyPeople,
             h.hr_img AS hrImg,
             h.hr_name AS hrName
         FROM
            view_post v
                LEFT JOIN
            post p on v.post_id = p.post_id
                LEFT JOIN
                company c ON p.company_id = c.company_id
                LEFT JOIN
            hr h  ON  p.user_id = h.user_id
         WHERE
            p.status = 1
          and v.is_collect = 1
           and v.user_id = #{userId}
            ORDER BY v.creat_time desc;


    </select>

<select id="getPushPost" resultType="com.sqx.modules.post.dto.SelectAllDto">
SELECT
    p.post_id AS postId,
    p.rule_classify_name AS ruleClassifyName,
    p.post_im_tag AS postImTag,
    p.wage AS wage,
    p.address AS address,
    p.if_due AS ifDue,
    p.wage_time AS wageTime,
    c.company_id AS companyId,
    c.company_name AS companyName,
    c.company_people as companyPeople,
    h.hr_img AS hrImg,
    h.hr_name AS hrName
FROM
    view_post v
        LEFT JOIN
    post p on v.post_id = p.post_id
        LEFT JOIN
    company c ON p.company_id = c.company_id
        LEFT JOIN
    hr h  ON  p.user_id = h.user_id
WHERE
    p.status = 1
  and v.is_push = 1
  and v.user_id = #{userId}
ORDER BY v.creat_time desc;

</select>
</mapper>
