<?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="net.lab1024.smartadmin.module.business.peony.dao.PeonyDao">

    <resultMap id="PeonyVO" type="net.lab1024.smartadmin.module.business.peony.domain.vo.PeonyVO"></resultMap>
    <resultMap id="PeonyExcelVO" type="net.lab1024.smartadmin.module.business.peony.domain.vo.PeonyExcelVO"></resultMap>


    <select id="queryByPage" resultMap="PeonyVO">
        select
          id,
          kind,
          name,
          color,
          image_url,
          create_time,
          update_time
        from t_peony
        <where>
            <if test="queryDTO.id != null">
                AND id = #{queryDTO.id}
            </if>
            <if test="queryDTO.kind != null and queryDTO.kind != ''">
                AND INSTR(kind,#{queryDTO.kind})
            </if>
            <if test="queryDTO.name != null and queryDTO.name != ''">
                AND INSTR(name,#{queryDTO.name})
            </if>
            <if test="queryDTO.color != null and queryDTO.color != ''">
                AND INSTR(color,#{queryDTO.color})
            </if>

            <if test="queryDTO.createTimeBegin != null ">
                AND create_time &gt;= #{queryDTO.createTimeBegin}
            </if>
            <if test="queryDTO.createTimeEnd != null ">
                AND create_time &lt;= #{queryDTO.createTimeEnd}
            </if>

            <if test="queryDTO.updateTimeBegin != null ">
                AND update_time &gt;= #{queryDTO.updateTimeBegin}
            </if>
            <if test="queryDTO.updateTimeEnd != null ">
                AND update_time &lt;= #{queryDTO.updateTimeEnd}
            </if>
        </where>
    </select>

    <select id="queryAllExportData" resultMap="PeonyExcelVO">
        select
           id,
           kind,
           name,
           color,
           image_url,
           create_time,
           update_time
        from t_peony
        <where>
            <if test="queryDTO.id != null">
                AND id = #{queryDTO.id}
            </if>
            <if test="queryDTO.kind != null and queryDTO.kind != ''">
                AND INSTR(kind,#{queryDTO.kind})
            </if>
            <if test="queryDTO.name != null and queryDTO.name != ''">
                AND INSTR(name,#{queryDTO.name})
            </if>
            <if test="queryDTO.color != null and queryDTO.color != ''">
                AND INSTR(color,#{queryDTO.color})
            </if>

            <if test="queryDTO.createTimeBegin != null ">
                AND create_time &gt;= #{queryDTO.createTimeBegin}
            </if>
            <if test="queryDTO.createTimeEnd != null ">
                AND create_time &lt;= #{queryDTO.createTimeEnd}
            </if>

            <if test="queryDTO.updateTimeBegin != null ">
                AND update_time &gt;= #{queryDTO.updateTimeBegin}
            </if>
            <if test="queryDTO.updateTimeEnd != null ">
                AND update_time &lt;= #{queryDTO.updateTimeEnd}
            </if>
        </where>
    </select>

    <select id="queryBatchExportData" resultMap="PeonyExcelVO">
        select
         id,
         kind,
         name,
         color,
         image_url,
         create_time,
         update_time
        from t_peony
        where id in
        <foreach collection="idList" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>

    <delete id="deleteById">
        delete from t_peony where id = #{id}
    </delete>

    <delete id="deleteByIdList">
        delete from t_peony where id in
        <foreach collection="idList" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </delete>

</mapper>