<?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.izouma.awesomeadmin.dao.NavigationPackageMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.NavigationPackage">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="update_user" property="updateUser" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="create_user" property="createUser" jdbcType="VARCHAR"/>
        <result column="land_mark_id" property="landMarkId" jdbcType="INTEGER"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <result column="pay_flag" property="payFlag" jdbcType="CHAR"/>
        <result column="price" property="price" jdbcType="DECIMAL"/>
        <result column="aim_place" property="aimPlace" jdbcType="VARCHAR"/>
        <result column="rank" property="rank" jdbcType="INTEGER"/>
        <result column="shelf_flag" property="shelfFlag" jdbcType="CHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
            id,

            del_flag,

            update_time,

            update_user,

            create_time,

            create_user,

            land_mark_id,

            name,

            remark,

            pay_flag,

            price,

            aim_place,

            rank,

            shelf_flag,

        </trim>
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from navigation_package
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.NavigationPackage" useGeneratedKeys="true"
            keyProperty="id">
        insert into navigation_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id!= null">
                id,
            </if>
            <if test="delFlag!= null">
                del_flag,
            </if>
            <if test="updateTime!= null">
                update_time,
            </if>
            <if test="updateUser!= null">
                update_user,
            </if>
            <if test="createTime!= null">
                create_time,
            </if>
            <if test="createUser!= null">
                create_user,
            </if>
            <if test="landMarkId!= null">
                land_mark_id,
            </if>
            <if test="name!= null">
                name,
            </if>
            <if test="remark!= null">
                remark,
            </if>
            <if test="payFlag!= null">
                pay_flag,
            </if>
            <if test="price!= null">
                price,
            </if>
            <if test="aimPlace!= null">
                aim_place,
            </if>
            <if test="rank!= null">
                rank,
            </if>
            <if test="shelfFlag!= null">
                shelf_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=CHAR},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                #{updateUser,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="landMarkId != null">
                #{landMarkId,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="payFlag != null">
                #{payFlag,jdbcType=CHAR},
            </if>
            <if test="price != null">
                #{price,jdbcType=DECIMAL},
            </if>
            <if test="aimPlace != null">
                #{aimPlace,jdbcType=VARCHAR},
            </if>
            <if test="rank != null">
                #{rank,jdbcType=INTEGER},
            </if>
            <if test="shelfFlag != null">
                #{shelfFlag,jdbcType=CHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.NavigationPackage">
        update navigation_package
        <set>
            <if test="id != null">
                id= #{id,jdbcType=INTEGER},
            </if>
            <if test="delFlag != null">
                del_flag= #{delFlag,jdbcType=CHAR},
            </if>
            <if test="updateTime != null">
                update_time= #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                update_user= #{updateUser,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time= #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                create_user= #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="landMarkId != null">
                land_mark_id= #{landMarkId,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                name= #{name,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                remark= #{remark,jdbcType=VARCHAR},
            </if>
            <if test="payFlag != null">
                pay_flag= #{payFlag,jdbcType=CHAR},
            </if>
            <if test="price != null">
                price= #{price,jdbcType=DECIMAL},
            </if>
            <if test="aimPlace != null">
                aim_place= #{aimPlace,jdbcType=VARCHAR},
            </if>
            <if test="rank != null">
                rank= #{rank,jdbcType=INTEGER},
            </if>
            <if test="shelfFlag != null">
                shelf_flag= #{shelfFlag,jdbcType=CHAR},
            </if>
        </set>
        where
        <if test="id != null and !&quot;&quot;.equals(id)">
            id = #{id,jdbcType=INTEGER}
        </if>

        <if test="idStr != null and !&quot;&quot;.equals(idStr)">
            id in (${idStr})
        </if>

    </update>
    <select id="queryNavigationPackageByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        <where>
            and del_flag = 'N'
            <if test="record.idStr != null and !&quot;&quot;.equals(record.idStr)">
                and id in (${record.idStr})
            </if>
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                and del_flag = #{record.delFlag}
            </if>
            <if test="record.updateTime != null and !&quot;&quot;.equals(record.updateTime)">
                and update_time = #{record.updateTime}
            </if>
            <if test="record.updateUser != null and !&quot;&quot;.equals(record.updateUser)">
                and update_user = #{record.updateUser}
            </if>
            <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
                and create_time = #{record.createTime}
            </if>
            <if test="record.createUser != null and !&quot;&quot;.equals(record.createUser)">
                and create_user = #{record.createUser}
            </if>
            <if test="record.landMarkId != null and !&quot;&quot;.equals(record.landMarkId)">
                and land_mark_id = #{record.landMarkId}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and name = #{record.name}
            </if>
            <if test="record.remark != null and !&quot;&quot;.equals(record.remark)">
                and remark = #{record.remark}
            </if>
            <if test="record.payFlag != null and !&quot;&quot;.equals(record.payFlag)">
                and pay_flag = #{record.payFlag}
            </if>
            <if test="record.price != null and !&quot;&quot;.equals(record.price)">
                and price = #{record.price}
            </if>
            <if test="record.aimPlace != null and !&quot;&quot;.equals(record.aimPlace)">
                and aim_place = #{record.aimPlace}
            </if>
            <if test="record.rank != null and !&quot;&quot;.equals(record.rank)">
                and rank = #{record.rank}
            </if>
            <if test="record.shelfFlag != null and !&quot;&quot;.equals(record.shelfFlag)">
                and shelf_flag = #{record.shelfFlag}
            </if>
            <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR land_mark_id LIKE concat('%',#{record.searchKey},'%')
                    OR name LIKE concat('%',#{record.searchKey},'%')
                    OR remark LIKE concat('%',#{record.searchKey},'%')
                    OR pay_flag LIKE concat('%',#{record.searchKey},'%')
                    OR price LIKE concat('%',#{record.searchKey},'%')
                    OR rank LIKE concat('%',#{record.searchKey},'%')
                    OR shelf_flag LIKE concat('%',#{record.searchKey},'%')
                </trim>
            </if>

            <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
                <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
                    <choose>
                        <when test="item.indexOf('like') != -1">
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    concat('%',#{itemDetail},'%')
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </when>
                        <otherwise>
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    #{itemDetail}
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </otherwise>
                    </choose>


                </foreach>


            </if>

        </where>
        order by

        <if test="record.orderByStr != null and !&quot;&quot;.equals(record.orderByStr)">


            <trim suffixOverrides=",">
                <foreach item="item" index="index" separator="," collection="record.orderByStr.split('_;')">
                    <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                        ${itemDetail}
                    </foreach>
                </foreach>
            </trim>
            ,
        </if>
        id desc
    </select>
    <select id="queryAllNavigationPackage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        <where>
            and del_flag = 'N'
            <if test="idStr != null and !&quot;&quot;.equals(idStr)">
                and id in (${idStr})
            </if>
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="updateTime != null and !&quot;&quot;.equals(updateTime)">
                and update_time = #{updateTime}
            </if>
            <if test="updateUser != null and !&quot;&quot;.equals(updateUser)">
                and update_user = #{updateUser}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="createUser != null and !&quot;&quot;.equals(createUser)">
                and create_user = #{createUser}
            </if>
            <if test="landMarkId != null and !&quot;&quot;.equals(landMarkId)">
                and land_mark_id = #{landMarkId}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="remark != null and !&quot;&quot;.equals(remark)">
                and remark = #{remark}
            </if>
            <if test="payFlag != null and !&quot;&quot;.equals(payFlag)">
                and pay_flag = #{payFlag}
            </if>
            <if test="price != null and !&quot;&quot;.equals(price)">
                and price = #{price}
            </if>
            <if test="aimPlace != null and !&quot;&quot;.equals(aimPlace)">
                and aim_place = #{aimPlace}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="shelfFlag != null and !&quot;&quot;.equals(shelfFlag)">
                and shelf_flag = #{shelfFlag}
            </if>
            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR land_mark_id LIKE concat('%',#{searchKey},'%')
                    OR name LIKE concat('%',#{searchKey},'%')
                    OR remark LIKE concat('%',#{searchKey},'%')
                    OR pay_flag LIKE concat('%',#{searchKey},'%')
                    OR price LIKE concat('%',#{searchKey},'%')
                    OR rank LIKE concat('%',#{searchKey},'%')
                    OR shelf_flag LIKE concat('%',#{searchKey},'%')
                </trim>
            </if>
            <if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
                <foreach item="item" index="index" collection="advancedQuery.split('_;')">
                    <choose>
                        <when test="item.indexOf('like') != -1">
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    concat('%',#{itemDetail},'%')
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </when>
                        <otherwise>
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    #{itemDetail}
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </otherwise>
                    </choose>


                </foreach>


            </if>
        </where>
        order by

        <if test="orderByStr != null and !&quot;&quot;.equals(orderByStr)">


            <trim suffixOverrides=",">
                <foreach item="item" index="index" separator="," collection="orderByStr.split('_;')">
                    <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                        ${itemDetail}
                    </foreach>
                </foreach>
            </trim>
            ,
        </if>

        id desc
    </select>
    <select id="queryAllNavigationPackageForLankMark" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        <where>
            and del_flag = 'N'
            and shelf_flag = 'Y'
            <if test="idStr != null and !&quot;&quot;.equals(idStr)">
                and id in (${idStr})
            </if>
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="landMarkId != null and !&quot;&quot;.equals(landMarkId)">
                and land_mark_id = #{landMarkId}
            </if>

            <if test="buyFlag != null and !&quot;&quot;.equals(buyFlag)">
                <choose>
                    <when test="buyFlag == 'Y'.toString()">
                        AND id IN (
                        SELECT
                        DISTINCT package_id
                        FROM
                        user_order
                        WHERE
                        del_flag = 'N'
                        AND status_flag = 1
                        AND user_id = #{userId}
                        )
                    </when>
                    <otherwise>

                        AND id NOT IN (
                        SELECT
                        DISTINCT package_id
                        FROM
                        user_order
                        WHERE
                        del_flag = 'N'
                        AND status_flag = 1
                        AND user_id = #{userId}
                        )
                    </otherwise>
                </choose>
            </if>

        </where>
        order by

        <if test="orderByStr != null and !&quot;&quot;.equals(orderByStr)">


            <trim suffixOverrides=",">
                <foreach item="item" index="index" separator="," collection="orderByStr.split('_;')">
                    <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                        ${itemDetail}
                    </foreach>
                </foreach>
            </trim>
            ,
        </if>

        id desc
    </select>
    <select id="queryNavigationPackage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="updateTime != null and !&quot;&quot;.equals(updateTime)">
                and update_time = #{updateTime}
            </if>
            <if test="updateUser != null and !&quot;&quot;.equals(updateUser)">
                and update_user = #{updateUser}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="createUser != null and !&quot;&quot;.equals(createUser)">
                and create_user = #{createUser}
            </if>
            <if test="landMarkId != null and !&quot;&quot;.equals(landMarkId)">
                and land_mark_id = #{landMarkId}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="remark != null and !&quot;&quot;.equals(remark)">
                and remark = #{remark}
            </if>
            <if test="payFlag != null and !&quot;&quot;.equals(payFlag)">
                and pay_flag = #{payFlag}
            </if>
            <if test="price != null and !&quot;&quot;.equals(price)">
                and price = #{price}
            </if>
            <if test="aimPlace != null and !&quot;&quot;.equals(aimPlace)">
                and aim_place = #{aimPlace}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="shelfFlag != null and !&quot;&quot;.equals(shelfFlag)">
                and shelf_flag = #{shelfFlag}
            </if>

        </where>
        LIMIT 1
    </select>
    <select id="queryBoughtNavigationPackage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        SELECT
        GROUP_CONCAT(`name`) AS NAME,
        GROUP_CONCAT(aim_place) AS aim_place
        FROM
        navigation_package
        WHERE
        del_flag = 'N'
        AND id IN (
        SELECT
        package_id
        FROM
        user_order
        WHERE
        del_flag = 'N'
        AND user_id = #{userId}
        AND status_flag = 1
        )

        <if test="landMarkId != null and !&quot;&quot;.equals(landMarkId)">
            and land_mark_id = #{landMarkId}
        </if>
        <if test="payFlag != null and !&quot;&quot;.equals(payFlag)">
            and pay_flag = #{payFlag}
        </if>
        <if test="shelfFlag != null and !&quot;&quot;.equals(shelfFlag)">
            and shelf_flag = #{shelfFlag}
        </if>

    </select>
    <update id="delete">
        UPDATE navigation_package SET del_flag = 'Y'
        where
        <if test="id != null and !&quot;&quot;.equals(id)">
            id = #{id,jdbcType=INTEGER}
        </if>

        <if test="idStr != null and !&quot;&quot;.equals(idStr)">
            id in (${idStr})
        </if>
    </update>
    <select id="query" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.NavigationPackage">
        select
        <include refid="Base_Column_List"/>
        from navigation_package
        <where>
            and del_flag = 'N'
        </where>
        order by id desc
    </select>
</mapper>

