<?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.hzya.frame.basedao.dao.RequestDisposeEntityMapper">

    <!--    返回字段-->
    <sql id="Base_Column_List">
        <if test="returnValid">
            <trim suffixOverrides=",">
                <foreach collection="returnCriterions" item="returnCriterions">
                    ${returnCriterions.sqlFiled} as ${returnCriterions.returnField} ,
                </foreach>
            </trim>
        </if>
        <if test="!returnValid">
            *
        </if>
    </sql>
    <!--    拼接where条件-->
    <sql id="Example_Where_Clause">
        <if test="opinionWheres">
            <where>
            <trim suffixOverrides="AND">
                <trim suffixOverrides="OR">
                    <foreach collection="wheres" item="wheresCriterion">
                        <choose>
                            <when test="wheresCriterion.noValue">
                                ${wheresCriterion.leftBracket} ${wheresCriterion.filed} ${wheresCriterion.condition} ${wheresCriterion.rightBracket}
                                ${wheresCriterion.connect}
                            </when>
                            <when test="wheresCriterion.singleValue">
                                ${wheresCriterion.leftBracket} ${wheresCriterion.filed} ${wheresCriterion.condition}
                                <choose>
                                    <when test="wheresCriterion.condition == 'like'">
                                        <![CDATA['%${wheresCriterion.value}%' ]]>
                                    </when>
                                    <when test="wheresCriterion.condition == 'not like'">
                                        <![CDATA['%${wheresCriterion.value}%' ]]>
                                    </when>
                                    <when test="wheresCriterion.condition == 'like'">
                                        <![CDATA['${wheresCriterion.value}%' ]]>
                                    </when>
                                    <when test="wheresCriterion.condition == 'not like'">
                                        <![CDATA['${wheresCriterion.value}%' ]]>
                                    </when>
                                    <when test="wheresCriterion.condition == 'like'">
                                        <![CDATA['%${wheresCriterion.value}' ]]>
                                    </when>
                                    <when test="wheresCriterion.condition == 'not like'">
                                        <![CDATA[ '%${wheresCriterion.value}' ]]>
                                    </when>
                                    <otherwise>
                                        #{wheresCriterion.value}
                                    </otherwise>
                                </choose>
                                ${wheresCriterion.rightBracket} ${wheresCriterion.connect}
                            </when>
                            <when test="wheresCriterion.betweenValue">
                                ${wheresCriterion.leftBracket} ${wheresCriterion.filed} ${wheresCriterion.condition} #{wheresCriterion.value} and
                                #{wheresCriterion.secondValue} ${wheresCriterion.rightBracket} ${wheresCriterion.connect}
                            </when>
                            <when test="wheresCriterion.listValue">
                                ${wheresCriterion.leftBracket} ${wheresCriterion.filed} ${wheresCriterion.condition}
                                <foreach close=")" collection="wheresCriterion.value" item="listItem" open="("
                                         separator=",">
                                    #{listItem}
                                </foreach>
                                ${wheresCriterion.rightBracket} ${wheresCriterion.connect}
                            </when>
                        </choose>
                    </foreach>
                </trim>
            </trim>
            </where>
        </if>
    </sql>

    <!--    根据sql语句查询-->
    <select id="selectBySql" resultType="java.util.HashMap" parameterType="string">
        <if test="null != sql and sql != ''">
            ${sql}
        </if>
    </select>

    <!--    根据条件查询-->
    <select id="selectByExample" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity"
            resultType="java.util.HashMap">
        select
        <include refid="Base_Column_List"/>
        from ${tablename}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <!--    根据条件查询-->
    <select id="selectByExample_COUNT" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity"
            resultType="java.lang.Integer" >
        select
        count(*) from ${tablename}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>

<!--    根据条件查询数量-->
    <select id="countByExample" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity"
            resultType="java.lang.Integer">
        select count(*) from ${tablename}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>

<!--    单个添加-->
    <insert id="insert" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity">
        insert into ${tablename} (
        <trim suffixOverrides=",">
            <foreach collection="modifys" item="items">
                ${items.filedName} ,
            </foreach>
        </trim>
        )
        values (
        <trim suffixOverrides=",">
            <foreach collection="modifys" item="items">
                <choose>
                    <when test="items.intValue">
                        #{items.filedValue,jdbcType=INTEGER} ,
                    </when>
                    <when test="items.decimalValue">
                        #{items.filedValue,jdbcType=DECIMAL} ,
                    </when>
                    <when test="items.stringValue">
                        #{items.filedValue,jdbcType=VARCHAR} ,
                    </when>
                    <when test="items.dateValue">
                        #{items.filedValue,jdbcType=TIMESTAMP} ,
                    </when>
                </choose>
            </foreach>
        </trim>
        )
    </insert>


    <insert id="insertSelective" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity">
        insert into ${tablename}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <foreach collection="batchFileds" item="items">
                ${items} ,
            </foreach>
        </trim>
        <trim prefix=" VALUES " suffixOverrides=",">
            <foreach collection="batchModifys" item="items">
                <trim prefix="(" suffix=" ) ," suffixOverrides=",">
                    <foreach collection="items" item="filedValue">
                        <choose>
                            <when test="filedValue.intValue">
                                #{filedValue.filedValue,jdbcType=INTEGER} ,
                            </when>
                            <when test="filedValue.decimalValue">
                                #{filedValue.filedValue,jdbcType=DECIMAL} ,
                            </when>
                            <when test="filedValue.stringValue">
                                #{filedValue.filedValue,jdbcType=VARCHAR} ,
                            </when>
                            <when test="filedValue.dateValue">
                                #{filedValue.filedValue,jdbcType=TIMESTAMP} ,
                            </when>
                        </choose>
                    </foreach>
                </trim>
            </foreach>
        </trim>
    </insert>
    <update id="updateByExample" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity">
        update ${tablename}
        <set>
            <trim suffixOverrides=",">
                <foreach collection="modifys" item="items">
                    <choose>
                        <when test="items.intValue">
                            ${items.filedName} = #{items.filedValue,jdbcType=INTEGER} ,
                        </when>
                        <when test="items.decimalValue">
                            ${items.filedName} = #{items.filedValue,jdbcType=DECIMAL} ,
                        </when>
                        <when test="items.stringValue">
                            ${items.filedName} = #{items.filedValue,jdbcType=VARCHAR} ,
                        </when>
                        <when test="items.dateValue">
                            ${items.filedName} = #{items.filedValue,jdbcType=TIMESTAMP} ,
                        </when>
                    </choose>
                </foreach>
            </trim>
        </set>
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </update>

    <delete id="deleteByExample" parameterType="com.hzya.frame.basedao.entity.RequestDisposeEntity">
        delete from ${tablename}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
</mapper>
