<?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.ServiceTypeMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.ServiceType">
        <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="short_name" property="shortName" jdbcType="VARCHAR"/>
        <result column="image" property="image" jdbcType="VARCHAR"/>
        <result column="color" property="color" jdbcType="VARCHAR"/>
        <result column="rank" property="rank" jdbcType="INTEGER"/>
        <result column="show_flag" property="showFlag" jdbcType="CHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
            id,

            del_flag,

            update_time,

            update_user,

            create_time,

            create_user,

            service_type,

            short_name,

            image,

            color,

            rank,

            show_flag,

            description,

        </trim>
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from service_type
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from service_type
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.ServiceType" useGeneratedKeys="true"
            keyProperty="id">
        insert into service_type
        <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="shortName!= null">
                short_name,
            </if>
            <if test="image!= null">
                image,
            </if>
            <if test="color!= null">
                color,
            </if>
            <if test="rank!= null">
                rank,
            </if>
            <if test="showFlag!= null">
                show_flag,
            </if>
            <if test="description!= null">
                description,
            </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="shortName != null">
                #{shortName,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                #{image,jdbcType=VARCHAR},
            </if>
            <if test="color != null">
                #{color,jdbcType=VARCHAR},
            </if>
            <if test="rank != null">
                #{rank,jdbcType=INTEGER},
            </if>
            <if test="showFlag != null">
                #{showFlag,jdbcType=CHAR},
            </if>
            <if test="description != null">
                #{description,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.ServiceType">
        update service_type
        <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="shortName != null">
                short_name= #{shortName,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                image= #{image,jdbcType=VARCHAR},
            </if>
            <if test="color != null">
                color= #{color,jdbcType=VARCHAR},
            </if>
            <if test="rank != null">
                rank= #{rank,jdbcType=INTEGER},
            </if>
            <if test="showFlag != null">
                show_flag= #{showFlag,jdbcType=CHAR},
            </if>
            <if test="description != null">
                description= #{description,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="queryServiceTypeByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.ServiceType">
        select
        <include refid="Base_Column_List"/>
        from service_type
        <where>
            and del_flag = 'N'
            <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.serviceType != null and !&quot;&quot;.equals(record.serviceType)">
                and service_type = #{record.serviceType}
            </if>
            <if test="record.shortName != null and !&quot;&quot;.equals(record.shortName)">
                and short_name = #{record.shortName}
            </if>
            <if test="record.image != null and !&quot;&quot;.equals(record.image)">
                and image = #{record.image}
            </if>
            <if test="record.color != null and !&quot;&quot;.equals(record.color)">
                and color = #{record.color}
            </if>
            <if test="record.rank != null and !&quot;&quot;.equals(record.rank)">
                and rank = #{record.rank}
            </if>
            <if test="record.showFlag != null and !&quot;&quot;.equals(record.showFlag)">
                and show_flag = #{record.showFlag}
            </if>
            <if test="record.description != null and !&quot;&quot;.equals(record.description)">
                and description = #{record.description}
            </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 short_name LIKE concat('%',#{record.searchKey},'%')
                    OR image LIKE concat('%',#{record.searchKey},'%')
                    OR color LIKE concat('%',#{record.searchKey},'%')
                    OR rank LIKE concat('%',#{record.searchKey},'%')
                    OR show_flag LIKE concat('%',#{record.searchKey},'%')
                    OR description 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="queryAllServiceType" parameterType="java.util.Map"
            resultMap="InfoWithList">
        select
        <include refid="Base_Column_List"/>
        from service_type
        <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="shortName != null and !&quot;&quot;.equals(shortName)">
                and short_name = #{shortName}
            </if>
            <if test="image != null and !&quot;&quot;.equals(image)">
                and image = #{image}
            </if>
            <if test="color != null and !&quot;&quot;.equals(color)">
                and color = #{color}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="showFlag != null and !&quot;&quot;.equals(showFlag)">
                and show_flag = #{showFlag}
            </if>
            <if test="description != null and !&quot;&quot;.equals(description)">
                and description = #{description}
            </if>
            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR service_type LIKE concat('%',#{searchKey},'%')
                    OR short_name LIKE concat('%',#{searchKey},'%')
                    OR image LIKE concat('%',#{searchKey},'%')
                    OR color LIKE concat('%',#{searchKey},'%')
                    OR rank LIKE concat('%',#{searchKey},'%')
                    OR show_flag LIKE concat('%',#{searchKey},'%')
                    OR description 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="queryAllServiceTypeForHome" parameterType="java.util.Map"
            resultMap="InfoWithListForHome">
        select
        <include refid="Base_Column_List"/>,
        1 as homeFlag,
        'Y' as useFlag,
        6 as homeLimit,
        10 as hotLimit

        from service_type
        <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="shortName != null and !&quot;&quot;.equals(shortName)">
                and short_name = #{shortName}
            </if>
            <if test="image != null and !&quot;&quot;.equals(image)">
                and image = #{image}
            </if>
            <if test="color != null and !&quot;&quot;.equals(color)">
                and color = #{color}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="showFlag != null and !&quot;&quot;.equals(showFlag)">
                and show_flag = #{showFlag}
            </if>
            <if test="description != null and !&quot;&quot;.equals(description)">
                and description = #{description}
            </if>
            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR service_type LIKE concat('%',#{searchKey},'%')
                    OR short_name LIKE concat('%',#{searchKey},'%')
                    OR image LIKE concat('%',#{searchKey},'%')
                    OR color LIKE concat('%',#{searchKey},'%')
                    OR rank LIKE concat('%',#{searchKey},'%')
                    OR show_flag LIKE concat('%',#{searchKey},'%')
                    OR description 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="queryServiceType" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ServiceType">
        select
        <include refid="Base_Column_List"/>
        from service_type
        <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="shortName != null and !&quot;&quot;.equals(shortName)">
                and short_name = #{shortName}
            </if>
            <if test="image != null and !&quot;&quot;.equals(image)">
                and image = #{image}
            </if>
            <if test="color != null and !&quot;&quot;.equals(color)">
                and color = #{color}
            </if>
            <if test="rank != null and !&quot;&quot;.equals(rank)">
                and rank = #{rank}
            </if>
            <if test="showFlag != null and !&quot;&quot;.equals(showFlag)">
                and show_flag = #{showFlag}
            </if>
            <if test="description != null and !&quot;&quot;.equals(description)">
                and description = #{description}
            </if>

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


    <resultMap id="InfoWithList" type="com.izouma.awesomeadmin.model.ServiceType" extends="BaseResultMap">


        <collection property="serviceTypeDetailList"
                    ofType="com.izouma.awesomeadmin.model.ServiceTypeDetail"
                    select="com.izouma.awesomeadmin.dao.ServiceTypeDetailMapper.queryAllServiceTypeDetail"
                    column="{ parentId = id }"/>

    </resultMap>

    <resultMap id="InfoWithListForHome" type="com.izouma.awesomeadmin.model.ServiceType" extends="BaseResultMap">


        <collection property="serviceTypeDetailList"
                    ofType="com.izouma.awesomeadmin.model.ServiceTypeDetail"
                    select="com.izouma.awesomeadmin.dao.ServiceTypeDetailMapper.queryAllServiceTypeDetail"
                    column="{ parentId = id }"/>

        <collection property="homeStoreInfoList"
                    ofType="com.izouma.awesomeadmin.model.StoreInfo"
                    select="com.izouma.awesomeadmin.dao.StoreInfoMapper.queryAllStoreInfoForHome"
                    column="{ serviceType = id , homeFlag = homeFlag , useFlag = useFlag , limitNum = homeLimit }"/>

        <collection property="hotStoreInfoList"
                    ofType="com.izouma.awesomeadmin.model.StoreInfo"
                    select="com.izouma.awesomeadmin.dao.StoreInfoMapper.queryAllStoreInfoForHome"
                    column="{ serviceType = id , hotFlag = homeFlag , useFlag = useFlag , limitNum = hotLimit }"/>

    </resultMap>

</mapper>

