<?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.ruoyi.system.mapper.EpsBusinessMapper">
    
    <resultMap type="EpsBusiness" id="EpsBusinessResult">
        <result property="id"    column="id"    />
        <result property="businessName"    column="business_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="description"    column="description"    />
    </resultMap>

    <sql id="selectEpsBusinessVo">
        select id, business_name, create_time, update_time, create_by, update_by, description from eps_business
    </sql>

    <select id="selectEpsBusinessList" parameterType="EpsBusiness" resultMap="EpsBusinessResult">
        <include refid="selectEpsBusinessVo"/>
        <where>  
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
        </where>
    </select>
    
    <select id="selectEpsBusinessById" parameterType="String" resultMap="EpsBusinessResult">
        <include refid="selectEpsBusinessVo"/>
        where id = #{id}
    </select>

    <select id="selectEpsBusinessByName" parameterType="String" resultMap="EpsBusinessResult">
        <include refid="selectEpsBusinessVo"/>
        where business_name = #{businessName}
        limit 1
    </select>

    <insert id="insertEpsBusiness" parameterType="EpsBusiness">
        insert into eps_business
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="businessName != null and businessName != ''">business_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="description != null">description,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="businessName != null and businessName != ''">#{businessName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="description != null">#{description},</if>
         </trim>
    </insert>

    <update id="updateEpsBusiness" parameterType="EpsBusiness">
        update eps_business
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="description != null">description = #{description},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEpsBusinessById" parameterType="String">
        delete from eps_business where id = #{id}
    </delete>

    <delete id="deleteEpsBusinessByIds" parameterType="String">
        delete from eps_business where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="countByBusinessName" parameterType="EpsBusiness" resultType="java.lang.Integer">
        select count(1) from eps_business
        <where>
            <if test="businessName != '' and businessName != null">
                and business_name = #{businessName}
            </if>
        </where>
    </select>
</mapper>