<?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.ProductInfoMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.ProductInfo">
        <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="service_type" property="serviceType" jdbcType="VARCHAR"/>
        <result column="subclass" property="subclass" jdbcType="VARCHAR"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="image" property="image" jdbcType="VARCHAR"/>
        <result column="service_detail" property="serviceDetail" jdbcType="VARCHAR"/>
        <result column="inventory" property="inventory" jdbcType="INTEGER"/>
        <result column="on_shelf" property="onShelf" jdbcType="CHAR"/>
        <result column="use_flag" property="useFlag" jdbcType="CHAR"/>
        <result column="hot_flag" property="hotFlag" jdbcType="INTEGER"/>
        <result column="home_flag" property="homeFlag" jdbcType="INTEGER"/>
        <result column="rank" property="rank" jdbcType="INTEGER"/>
        <result column="store_id" property="storeId" jdbcType="INTEGER"/>
        <result column="type_flag" property="typeFlag" jdbcType="INTEGER"/>
        <result column="sales_volume" property="salesVolume" jdbcType="INTEGER"/>
        <result column="price" property="price" jdbcType="DECIMAL"/>
        <result column="product_detail" property="productDetail" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
            id,

            del_flag,

            update_time,

            update_user,

            create_time,

            create_user,

            service_type,

            subclass,

            title,

            image,

            service_detail,

            inventory,

            on_shelf,

            use_flag,

            hot_flag,

            home_flag,

            rank,

            store_id,

            type_flag,

            sales_volume,

            price,

            product_detail,

        </trim>
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from product_info
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from product_info
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.ProductInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into product_info
        <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="serviceType!= null">
                service_type,
            </if>
            <if test="subclass!= null">
                subclass,
            </if>
            <if test="title!= null">
                title,
            </if>
            <if test="image!= null">
                image,
            </if>
            <if test="serviceDetail!= null">
                service_detail,
            </if>
            <if test="inventory!= null">
                inventory,
            </if>
            <if test="onShelf!= null">
                on_shelf,
            </if>
            <if test="useFlag!= null">
                use_flag,
            </if>
            <if test="hotFlag!= null">
                hot_flag,
            </if>
            <if test="homeFlag!= null">
                home_flag,
            </if>
            <if test="rank!= null">
                rank,
            </if>
            <if test="storeId!= null">
                store_id,
            </if>
            <if test="typeFlag!= null">
                type_flag,
            </if>
            <if test="salesVolume!= null">
                sales_volume,
            </if>
            <if test="price!= null">
                price,
            </if>
            <if test="productDetail!= null">
                product_detail,
            </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="serviceType != null">
                #{serviceType,jdbcType=VARCHAR},
            </if>
            <if test="subclass != null">
                #{subclass,jdbcType=VARCHAR},
            </if>
            <if test="title != null">
                #{title,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                #{image,jdbcType=VARCHAR},
            </if>
            <if test="serviceDetail != null">
                #{serviceDetail,jdbcType=VARCHAR},
            </if>
            <if test="inventory != null">
                #{inventory,jdbcType=INTEGER},
            </if>
            <if test="onShelf != null">
                #{onShelf,jdbcType=CHAR},
            </if>
            <if test="useFlag != null">
                #{useFlag,jdbcType=CHAR},
            </if>
            <if test="hotFlag != null">
                #{hotFlag,jdbcType=INTEGER},
            </if>
            <if test="homeFlag != null">
                #{homeFlag,jdbcType=INTEGER},
            </if>
            <if test="rank != null">
                #{rank,jdbcType=INTEGER},
            </if>
            <if test="storeId != null">
                #{storeId,jdbcType=INTEGER},
            </if>
            <if test="typeFlag != null">
                #{typeFlag,jdbcType=INTEGER},
            </if>
            <if test="salesVolume != null">
                #{salesVolume,jdbcType=INTEGER},
            </if>
            <if test="price != null">
                #{price,jdbcType=DECIMAL},
            </if>
            <if test="productDetail != null">
                #{productDetail,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.ProductInfo">
        update product_info
        <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="serviceType != null">
                service_type= #{serviceType,jdbcType=VARCHAR},
            </if>
            <if test="subclass != null">
                subclass= #{subclass,jdbcType=VARCHAR},
            </if>
            <if test="title != null">
                title= #{title,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                image= #{image,jdbcType=VARCHAR},
            </if>
            <if test="serviceDetail != null">
                service_detail= #{serviceDetail,jdbcType=VARCHAR},
            </if>
            <if test="inventory != null">
                inventory= #{inventory,jdbcType=INTEGER},
            </if>
            <if test="onShelf != null">
                on_shelf= #{onShelf,jdbcType=CHAR},
            </if>
            <if test="useFlag != null">
                use_flag= #{useFlag,jdbcType=CHAR},
            </if>
            <if test="hotFlag != null">
                hot_flag= #{hotFlag,jdbcType=INTEGER},
            </if>
            <if test="homeFlag != null">
                home_flag= #{homeFlag,jdbcType=INTEGER},
            </if>
            <if test="rank != null">
                rank= #{rank,jdbcType=INTEGER},
            </if>
            <if test="storeId != null">
                store_id= #{storeId,jdbcType=INTEGER},
            </if>
            <if test="typeFlag != null">
                type_flag= #{typeFlag,jdbcType=INTEGER},
            </if>
            <if test="salesVolume != null">
                sales_volume= #{salesVolume,jdbcType=INTEGER},
            </if>
            <if test="price != null">
                price= #{price,jdbcType=DECIMAL},
            </if>
            <if test="productDetail != null">
                product_detail= #{productDetail,jdbcType=VARCHAR},
            </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="queryProductInfoByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.ProductInfo">
        select
        <include refid="Base_Column_List"/>
        from product_info
        <where>
            and del_flag = 'N'
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.idStr != null and !&quot;&quot;.equals(record.idStr)">
                and id in (${record.idStr})
            </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.serviceType != null and !&quot;&quot;.equals(record.serviceType)">
                and service_type = #{record.serviceType}
            </if>
            <if test="record.subclass != null and !&quot;&quot;.equals(record.subclass)">
                and subclass = #{record.subclass}
            </if>
            <if test="record.title != null and !&quot;&quot;.equals(record.title)">
                and title = #{record.title}
            </if>
            <if test="record.image != null and !&quot;&quot;.equals(record.image)">
                and image = #{record.image}
            </if>
            <if test="record.serviceDetail != null and !&quot;&quot;.equals(record.serviceDetail)">
                and service_detail = #{record.serviceDetail}
            </if>
            <if test="record.inventory != null and !&quot;&quot;.equals(record.inventory)">
                and inventory = #{record.inventory}
            </if>
            <if test="record.onShelf != null and !&quot;&quot;.equals(record.onShelf)">
                and on_shelf = #{record.onShelf}
            </if>
            <if test="record.useFlag != null and !&quot;&quot;.equals(record.useFlag)">
                and use_flag = #{record.useFlag}
            </if>
            <if test="record.hotFlag != null and !&quot;&quot;.equals(record.hotFlag)">
                and hot_flag = #{record.hotFlag}
            </if>
            <if test="record.homeFlag != null and !&quot;&quot;.equals(record.homeFlag)">
                and home_flag = #{record.homeFlag}
            </if>
            <if test="record.rank != null and !&quot;&quot;.equals(record.rank)">
                and rank = #{record.rank}
            </if>
            <if test="record.storeId != null and !&quot;&quot;.equals(record.storeId)">
                and store_id = #{record.storeId}
            </if>
            <if test="record.typeFlag != null and !&quot;&quot;.equals(record.typeFlag)">
                and type_flag = #{record.typeFlag}
            </if>
            <if test="record.salesVolume != null and !&quot;&quot;.equals(record.salesVolume)">
                and sales_volume = #{record.salesVolume}
            </if>
            <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR service_type LIKE concat('%',#{record.searchKey},'%')
                    OR subclass LIKE concat('%',#{record.searchKey},'%')
                    OR title LIKE concat('%',#{record.searchKey},'%')
                    OR service_detail LIKE concat('%',#{record.searchKey},'%')
                    OR inventory LIKE concat('%',#{record.searchKey},'%')
                    OR on_shelf LIKE concat('%',#{record.searchKey},'%')
                    OR use_flag LIKE concat('%',#{record.searchKey},'%')
                    OR hot_flag LIKE concat('%',#{record.searchKey},'%')
                    OR home_flag LIKE concat('%',#{record.searchKey},'%')
                    OR rank LIKE concat('%',#{record.searchKey},'%')
                    OR store_id LIKE concat('%',#{record.searchKey},'%')
                    OR type_flag LIKE concat('%',#{record.searchKey},'%')
                    OR sales_volume 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>
        rank desc, id desc
    </select>
    <select id="queryAllProductInfo" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.ProductInfo">
        select
        <include refid="Base_Column_List"/>
        from product_info
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="idStr != null and !&quot;&quot;.equals(idStr)">
                and id in (${idStr})
            </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="serviceType != null and !&quot;&quot;.equals(serviceType)">
                and service_type = #{serviceType}
            </if>
            <if test="subclass != null and !&quot;&quot;.equals(subclass)">
                and subclass = #{subclass}
            </if>
            <if test="title != null and !&quot;&quot;.equals(title)">
                and title = #{title}
            </if>
            <if test="image != null and !&quot;&quot;.equals(image)">
                and image = #{image}
            </if>
            <if test="serviceDetail != null and !&quot;&quot;.equals(serviceDetail)">
                and service_detail = #{serviceDetail}
            </if>
            <if test="inventory != null and !&quot;&quot;.equals(inventory)">
                and inventory = #{inventory}
            </if>
            <if test="onShelf != null and !&quot;&quot;.equals(onShelf)">
                and on_shelf = #{onShelf}
            </if>
            <if test="useFlag != null and !&quot;&quot;.equals(useFlag)">
                and use_flag = #{useFlag}
            </if>
            <if test="hotFlag != null and !&quot;&quot;.equals(hotFlag)">
                and hot_flag = #{hotFlag}
            </if>
            <if test="homeFlag != null and !&quot;&quot;.equals(homeFlag)">
                and home_flag = #{homeFlag}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="storeId != null and !&quot;&quot;.equals(storeId)">
                and store_id = #{storeId}
            </if>
            <if test="typeFlag != null and !&quot;&quot;.equals(typeFlag)">
                and type_flag = #{typeFlag}
            </if>
            <if test="salesVolume != null and !&quot;&quot;.equals(salesVolume)">
                and sales_volume = #{salesVolume}
            </if>
            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR service_type LIKE concat('%',#{searchKey},'%')
                    OR subclass LIKE concat('%',#{searchKey},'%')
                    OR title LIKE concat('%',#{searchKey},'%')
                    OR service_detail LIKE concat('%',#{searchKey},'%')
                    OR inventory LIKE concat('%',#{searchKey},'%')
                    OR on_shelf LIKE concat('%',#{searchKey},'%')
                    OR use_flag LIKE concat('%',#{searchKey},'%')
                    OR hot_flag LIKE concat('%',#{searchKey},'%')
                    OR home_flag LIKE concat('%',#{searchKey},'%')
                    OR rank LIKE concat('%',#{searchKey},'%')
                    OR store_id LIKE concat('%',#{searchKey},'%')
                    OR type_flag LIKE concat('%',#{searchKey},'%')
                    OR sales_volume 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>

        rank desc, id desc
    </select>
    <select id="queryProductInfo" parameterType="java.util.Map" resultMap="AllInfoForGetOne">
        select
        <include refid="Base_Column_List"/>
        from product_info
        <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="serviceType != null and !&quot;&quot;.equals(serviceType)">
                and service_type = #{serviceType}
            </if>
            <if test="subclass != null and !&quot;&quot;.equals(subclass)">
                and subclass = #{subclass}
            </if>
            <if test="title != null and !&quot;&quot;.equals(title)">
                and title = #{title}
            </if>
            <if test="image != null and !&quot;&quot;.equals(image)">
                and image = #{image}
            </if>
            <if test="serviceDetail != null and !&quot;&quot;.equals(serviceDetail)">
                and service_detail = #{serviceDetail}
            </if>
            <if test="inventory != null and !&quot;&quot;.equals(inventory)">
                and inventory = #{inventory}
            </if>
            <if test="onShelf != null and !&quot;&quot;.equals(onShelf)">
                and on_shelf = #{onShelf}
            </if>
            <if test="useFlag != null and !&quot;&quot;.equals(useFlag)">
                and use_flag = #{useFlag}
            </if>
            <if test="hotFlag != null and !&quot;&quot;.equals(hotFlag)">
                and hot_flag = #{hotFlag}
            </if>
            <if test="homeFlag != null and !&quot;&quot;.equals(homeFlag)">
                and home_flag = #{homeFlag}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="storeId != null and !&quot;&quot;.equals(storeId)">
                and store_id = #{storeId}
            </if>
            <if test="typeFlag != null and !&quot;&quot;.equals(typeFlag)">
                and type_flag = #{typeFlag}
            </if>
            <if test="salesVolume != null and !&quot;&quot;.equals(salesVolume)">
                and sales_volume = #{salesVolume}
            </if>

        </where>
        LIMIT 1
    </select>
    <update id="delete">
        UPDATE product_info SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>
    <select id="query" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ProductInfo">
        select
        <include refid="Base_Column_List"/>
        from product_info
        <where>
            and del_flag = 'N'
        </where>
        order by id desc
    </select>

    <resultMap id="AllInfoForGetOne" type="com.izouma.awesomeadmin.model.ProductInfo" extends="BaseResultMap">


        <association property="storeInfo"
                    javaType="com.izouma.awesomeadmin.model.StoreInfo"
                    select="com.izouma.awesomeadmin.dao.StoreInfoMapper.queryStoreInfo"
                    column="{ id = store_id }"/>

        <collection property="productPriceList"
                    ofType="com.izouma.awesomeadmin.model.ProductPrice"
                    select="com.izouma.awesomeadmin.dao.ProductPriceMapper.queryAllProductPrice"
                    column="{ productId = id }"/>

    </resultMap>

</mapper>

