<?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.younike.system.mapper.PublishMapper">

    <resultMap type="Publish" id="PublishResult">
        <result property="publishId"    column="publish_id"    />
        <result property="cateId"    column="cate_id"    />
        <result property="parentCateId"    column="parent_cate_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="name"    column="name"    />
        <result property="publishDesc"    column="publish_desc"    />
        <result property="publishState"    column="publish_state"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="bidMerchantId"    column="bid_merchant_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="bidServerUserId"    column="bid_server_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="memberId"    column="member_id"    />
    </resultMap>


    <resultMap type="PublishManageVo" id="PublishManageResult">
        <result property="publishId"    column="publish_id"    />
        <result property="cateId"    column="cate_id"    />
        <result property="parentCateId"    column="parent_cate_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="name"    column="name"    />
        <result property="publishDesc"    column="publish_desc"    />
        <result property="publishState"    column="publish_state"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="bidMerchantId"    column="bid_merchant_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="bidServerUserId"    column="bid_server_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="categoryName" column="category_name"/>
        <result property="parentCategoryName" column="parent_category_name"/>
        <association property="publishAddress" javaType="PublishAddress">
            <result property="addressId"    column="address_id"    />
            <result property="address"    column="address"    />
            <result property="detailed"    column="detailed"    />
            <result property="addressLongitude"    column="address_longitude"    />
            <result property="addressLatitude"    column="address_latitude"    />
            <result property="name"    column="address_name"    />
            <result property="sex"    column="sex"    />
            <result property="phone"    column="phone"    />
            <result property="privacyUser"    column="privacy_user"    />
            <result property="extensionNo"    column="extension_no"    />
            <result property="subsId"    column="subs_id"    />
        </association>
        <collection property="publishQuoteList" select="selectQuoteListByPublishId" column="publish_id"/>
    </resultMap>



    <resultMap type="com.younike.system.domain.vo.PublishManageVo" id="PublishInfoResult">
        <result property="publishId"    column="publish_id"    />
        <result property="cateId"    column="cate_id"    />
        <result property="parentCateId"    column="parent_cate_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="name"    column="name"    />
        <result property="publishDesc"    column="publish_desc"    />
        <result property="publishState"    column="publish_state"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="bidMerchantId"    column="bid_merchant_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="bidServerUserId"    column="bid_server_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="categoryName" column="category_name"/>
        <result property="parentCategoryName" column="parent_category_name"/>
        <result property="quoteCount" column="quote_count"/>
        <result property="serverQuoteCount" column="server_quote_count"/>
        <result property="bizType" column="biz_type"/>

        <association property="publishAddress" javaType="com.younike.system.domain.PublishAddress">
            <result property="addressId"    column="address_id"    />
            <result property="address"    column="address"    />
            <result property="detailed"    column="detailed"    />
            <result property="addressLongitude"    column="address_longitude"    />
            <result property="addressLatitude"    column="address_latitude"    />
            <result property="name"    column="address_name"    />
            <result property="sex"    column="sex"    />
            <result property="phone"    column="phone"    />
            <result property="privacyUser"    column="privacy_user"    />
            <result property="extensionNo"    column="extension_no"    />
            <result property="subsId"    column="subs_id"    />
        </association>
        <collection property="publishImageList" select="selectImageListByPublishId" column="publish_id"/>

    </resultMap>

    <sql id="selectPublishVo">
        select publish_id, cate_id, parent_cate_id, name, publish_desc, publish_state, del_flag, bid_merchant_id, create_by, bid_server_user_id, create_time, update_by, update_time, column1, column2, column3,member_id from publish
    </sql>

    <sql id="publishVoJoin">
        p.publish_id, p.cate_id, p.parent_cate_id, p.name, p.publish_desc, p.publish_state, p.del_flag, p.bid_merchant_id, p.create_by, p.bid_server_user_id, p.create_time, p.update_by, p.update_time,p.member_id
    </sql>

    <sql id="publishAddressJoin">
        pa.address_id, pa.address, pa.detailed, pa.address_longitude, pa.address_latitude, pa.name as address_name, pa.sex, pa.phone, pa.privacy_user, pa.extension_no, pa.subs_id
    </sql>

    <select id="publishManageList" resultMap="PublishManageResult">
        select <include refid="publishVoJoin" />,
               <include refid="publishAddressJoin" />,
               c.category_name as category_name, cp.category_name as parent_category_name
        from publish p
        left join category c on p.cate_id = c.category_id
        left join category cp on p.parent_cate_id = cp.category_id
        left join publish_address pa on p.publish_id = pa.publish_id and pa.del_flag = 0
        left join  merchant m on  m.merchant_id=#{merchantId}
        where p.del_flag = 0
        <if test="categoryId != null  and categoryId != ''">
            and p.cate_id = #{categoryId}
        </if>
        <if test="name != null and name != ''">
            and p.name like concat('%', #{name}, '%')
        </if>
        <if test="beginTime != null and beginTime != ''">
            and date_format(p.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''">
            and date_format(p.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        <if test="publishState != null and publishState != ''">
            and p.publish_state = #{publishState}
        </if>
        <if test="merchantId != null and merchantId != ''">
            <if test="status == 1">
                AND p.publish_state = '001'
                AND (
                    select count(0) from publish_quote pq
                    left join server_user su on pq.server_user_id = su.server_id
                    where su.merchant_id = #{merchantId} and pq.publish_id = p.publish_id
                ) > 0
            </if>
            <if test="status == 0">
                AND p.publish_state = '001'
                AND (
                    select count(0) from publish_quote pq
                    left join server_user su on pq.server_user_id = su.server_id
                    where su.merchant_id = #{merchantId} and pq.publish_id = p.publish_id
                ) = 0
            </if>
            <if test="status == 2">
                AND p.publish_state = '002' || p.publish_state = '003'
                AND p.bid_merchant_id = #{merchantId}
            </if>
            <if test="status == 3">
                AND p.publish_state = '002' || p.publish_state = '003'
                AND p.bid_merchant_id &lt;&gt; #{merchantId}
            </if>
            <if test="merchantLatitude!=null">
                AND ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - #{merchantLatitude} * pi() / 180
                ) / 2),2) +
                cos(pa.address_latitude * pi() / 180) * cos(#{merchantLatitude} * pi() / 180) *pow(sin((pa.address_longitude * pi() / 180 -#{merchantLongitude} * pi() / 180
                ) / 2),2))),2) &lt;=m.service_distance
            </if>
        </if>
        order by p.create_time desc
    </select>


    <select id="publishInfoList" resultMap="PublishManageResult">
        select <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(pq.quote_id) as quote_count, c.category_name as category_name, cp.category_name as parent_category_name
        from publish p
        left join category c on p.cate_id = c.category_id
        left join category cp on p.parent_cate_id = cp.category_id
        left join publish_address pa on p.publish_id = pa.publish_id and pa.del_flag = 0
        left join publish_quote pq on p.publish_id = pq.publish_id and pq.del_flag = 0
        where p.del_flag = 0
        group by p.publish_id

    </select>

    <select id="selectQuoteListByPublishId" resultMap="com.younike.system.mapper.PublishQuoteMapper.PublishQuoteResult">
        select * from publish_quote where del_flag = 0 and publish_id = #{publish_id}
    </select>
    <select id="selectImageListByPublishId" resultMap="com.younike.system.mapper.PublishImageMapper.PublishImageResult">
            select * from publish_image where del_flag = 0 and publish_id = #{publish_id}

    </select>
    <select id="selectPublishList" parameterType="Publish" resultMap="PublishResult">
        <include refid="selectPublishVo"/>
        <where>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="parentCateId != null "> and parent_cate_id = #{parentCateId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="publishDesc != null  and publishDesc != ''"> and publish_desc = #{publishDesc}</if>
            <if test="publishState != null  and publishState != ''"> and publish_state = #{publishState}</if>
            <if test="bidMerchantId != null "> and bid_merchant_id = #{bidMerchantId}</if>
            <if test="bidServerUserId != null "> and bid_server_user_id = #{bidServerUserId}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>

    <select id="selectPublishByPublishId" parameterType="Long" resultMap="PublishResult">
        <include refid="selectPublishVo"/>
        where publish_id = #{publishId}
        and del_flag=0
    </select>

    <update id="deleteByPublishId" parameterType="Long">
        update publish
        set del_flag = 2
        where publish_id = #{publishId}
    </update>

    <insert id="insertPublish" parameterType="Publish" useGeneratedKeys="true" keyProperty="publishId">
        insert into publish
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cateId != null">cate_id,</if>
            <if test="parentCateId != null">parent_cate_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="publishDesc != null">publish_desc,</if>
            <if test="publishState != null and publishState != ''">publish_state,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="bidMerchantId != null">bid_merchant_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="bidServerUserId != null">bid_server_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
            <if test="memberId != null">member_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cateId != null">#{cateId},</if>
            <if test="parentCateId != null">#{parentCateId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="publishDesc != null">#{publishDesc},</if>
            <if test="publishState != null and publishState != ''">#{publishState},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="bidMerchantId != null">#{bidMerchantId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="bidServerUserId != null">#{bidServerUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
            <if test="memberId != null">#{memberId},</if>
         </trim>
    </insert>

    <update id="updatePublish" parameterType="Publish">
        update publish
        <trim prefix="SET" suffixOverrides=",">
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="parentCateId != null">parent_cate_id = #{parentCateId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="publishDesc != null">publish_desc = #{publishDesc},</if>
            <if test="publishState != null and publishState != ''">publish_state = #{publishState},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="bidMerchantId != null">bid_merchant_id = #{bidMerchantId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="bidServerUserId != null">bid_server_user_id = #{bidServerUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
            <if test="memberId != null">member_id = #{memberId},</if>

        </trim>
        where publish_id = #{publishId}
    </update>

    <delete id="deletePublishByPublishId" parameterType="Long">
        delete from publish where publish_id = #{publishId}
    </delete>

    <delete id="deletePublishByPublishIds" parameterType="String">
        delete from publish where publish_id in
        <foreach item="publishId" collection="array" open="(" separator="," close=")">
            #{publishId}
        </foreach>
    </delete>


    <select id="mePublishList" parameterType="com.younike.system.param.PublishQueryParam" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        WHERE p.del_flag = 0
        <if test="memberId != null  and memberId != ''"> and p.member_id = #{memberId}</if>
        <if test="name != null  and name != ''"> and p.name like concat('%', #{name}, '%')</if>
        <if test="publishState != null  and publishState != ''"> and p.publish_state = #{publishState}</if>
        GROUP BY p.publish_id
        ORDER BY p.create_time DESC
    </select>
<!--需求详情（包含地址信息）-->
    <select id="getPublishByPublishId" parameterType="Long" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        b.category_name AS parent_category_name,
        c.category_name,
        c.biz_type
        FROM publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        WHERE p.del_flag = 0
        and p.publish_id = #{publishId}
    </select>
<!-- 查询我发布需求条数 -->
    <select id="mePublishCount" parameterType="Long" resultMap="PublishResult">
        <include refid="selectPublishVo"/>
        where del_flag=0
        and member_id =#{memberId}
        ORDER BY create_time DESC
    </select>
<!--   服务端查询任务广场列表 -->
    <select id="publishServerList" parameterType="com.younike.system.param.PublishQueryParam" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM server_user_follow suf
        LEFT JOIN publish p ON p.parent_cate_id = suf.category_id or p.cate_id=suf.category_id
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        LEFT JOIN server_user su ON su.server_id =#{serverId} and su.del_flag=0 and su.status = 0
        LEFT JOIN merchant m ON m.merchant_id =su.merchant_id and m.del_flag = 0 and m.shop_state = '002'
        WHERE p.del_flag = 0
        and  p.publish_state='001'
        <if test="memberId != null  and memberId != ''"> and p.member_id = #{memberId}</if>
        <if test="name != null  and name != ''"> and p.name like concat('%', #{name}, '%')</if>
        <if test="serverId != null  and serverId != ''">
        AND (
            ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - m.latitude * pi() / 180
            ) / 2),2) +
            cos(pa.address_latitude * pi() / 180) * cos(m.latitude * pi() / 180) *pow(sin((pa.address_longitude * pi() /
            180 -m.longitude * pi() / 180
            ) / 2),2))),2) &lt;=m.service_distance

            OR ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - m.latitude * pi() / 180
            ) / 2),2) +
            cos(pa.address_latitude * pi() / 180) * cos(m.latitude * pi() / 180) *pow(sin((pa.address_longitude * pi() /
            180 -m.longitude * pi() / 180
            ) / 2),2))),2) &lt;= (select config_value from sys_config where config_key = "home.server.distance" limit 1)
        )
        and suf.server_user_id = #{serverId}
        </if>
        GROUP BY p.publish_id
        ORDER BY p.create_time DESC
    </select>
<!--    服务端查询任务广场我报价的需求列表-->
    <select id="quoteList" parameterType="com.younike.system.param.PublishQueryParam" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        count(pq.publish_id) AS server_quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_quote pq ON pq.publish_id = p.publish_id and pq.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        WHERE p.del_flag = 0
        and pq.server_user_id =#{serverId}
        and  p.publish_state &lt;&gt; '004'
        <if test="memberId != null  and memberId != ''"> and p.member_id = #{memberId}</if>
        <if test="name != null  and name != ''"> and p.name like concat('%', #{name}, '%')</if>
        <if test="merchantLatitude!=null">
            AND ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - #{merchantLatitude} * pi() / 180
                ) / 2),2) +
                cos(pa.address_latitude * pi() / 180) * cos(#{merchantLatitude} * pi() / 180) *pow(sin((pa.address_longitude * pi() / 180 -#{merchantLongitude} * pi() / 180
                ) / 2),2))),2) &lt;=#{maxDeliverDistance}
        </if>
        <if test="parentCateIdS != null and parentCateIdS.size>0">
            and   p.parent_cate_id in
            <foreach item="parentCateId" collection="parentCateIdS" open="(" separator="," close=")">
                #{parentCateId}
            </foreach>
        </if>
        GROUP BY p.publish_id
        ORDER BY p.create_time DESC
    </select>

    <select id="selectPublishBy"  parameterType="com.younike.system.param.PublishQueryParam" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        count(pq.publish_id) AS server_quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_quote pq ON pq.publish_id = p.publish_id and pq.del_flag=0 and pq.server_user_id =#{serverId}
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        WHERE p.del_flag = 0
        and p.publish_id = #{publishId}
    </select>

<!-- 取消订单（发布需求的订单）   cancelPublishOrder-->
    <update id="cancelPublishOrder" parameterType="Publish">
        update publish
        <trim prefix="SET" suffixOverrides=",">
            <if test="publishState != null and publishState != ''">publish_state = #{publishState},</if>
            <if test="bidMerchantId != null">bid_merchant_id = null,</if>
            <if test="bidServerUserId != null">bid_server_user_id = null,</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where publish_id = #{publishId}
    </update>

    <select id="taskList" parameterType="com.younike.system.param.PublishQueryParam" resultMap="PublishInfoResult">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM  publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id and d.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id and pa.del_flag=0
        LEFT JOIN server_user su ON su.server_id =#{serverId} and su.del_flag=0 and su.status = 0
        LEFT JOIN merchant m ON m.merchant_id =su.merchant_id and m.del_flag = 0 and m.shop_state = '002'
        WHERE p.del_flag = 0
        and  p.publish_state='001'
        <if test="memberId != null  and memberId != ''"> and p.member_id = #{memberId}</if>
        <if test="name != null  and name != ''"> and p.name like concat('%', #{name}, '%')</if>

        AND (
        ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - m.latitude * pi() / 180
        ) / 2),2) +
        cos(pa.address_latitude * pi() / 180) * cos(m.latitude * pi() / 180) *pow(sin((pa.address_longitude * pi() /
        180 -m.longitude * pi() / 180
        ) / 2),2))),2) &lt;=m.service_distance

        OR ROUND(6378.138 * 2 * asin(sqrt(pow(sin((pa.address_latitude * pi() / 180 - m.latitude * pi() / 180
        ) / 2),2) +
        cos(pa.address_latitude * pi() / 180) * cos(m.latitude * pi() / 180) *pow(sin((pa.address_longitude * pi() /
        180 -m.longitude * pi() / 180
        ) / 2),2))),2) &lt;= (select config_value from sys_config where config_key = "home.server.distance" limit 1)
        )

        GROUP BY p.publish_id
        ORDER BY p.create_time DESC
    </select>

    <!--查询发布需求详细信息-->
    <select id="getPublishDetail" resultType="com.younike.system.domain.vo.PublishManageVo">
        SELECT <include refid="publishVoJoin" />,
        <include refid="publishAddressJoin" />,
        count(d.publish_id) AS quote_count,
        b.category_name AS parent_category_name,
        c.category_name
        FROM publish p
        LEFT JOIN category b ON p.parent_cate_id = b.category_id AND b.del_flag = 0
        LEFT JOIN category c ON p.cate_id = c.category_id AND c.del_flag = 0
        LEFT JOIN publish_quote d ON d.publish_id = p.publish_id AND d.del_flag=0
        LEFT JOIN publish_address pa ON p.publish_id = pa.publish_id AND pa.del_flag=0
        WHERE p.del_flag = 0
        AND p.publish_id = #{publishId}
    </select>
</mapper>
