<?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.CompanySaleMapper">

    <resultMap type="CompanySale" id="CompanySaleResult">
        <result property="id"    column="id"    />
        <result property="saleName"    column="sale_name"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="wxAccount"    column="wx_account"    />
        <result property="wxQrcode"    column="wx_qrcode"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanySaleVo">
        select id, sale_name, is_enable, wx_account, wx_qrcode, create_by, create_time, update_by, update_time, remark from company_sale
    </sql>

    <select id="selectCompanySaleList" parameterType="CompanySale" resultMap="CompanySaleResult">
        <include refid="selectCompanySaleVo"/>
        <where>
            <if test="saleName != null  and saleName != ''"> and sale_name like concat('%', #{saleName}, '%')</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
            <if test="wxAccount != null  and wxAccount != ''"> and wx_account = #{wxAccount}</if>
            <if test="wxQrcode != null  and wxQrcode != ''"> and wx_qrcode = #{wxQrcode}</if>
        </where>
    </select>

    <select id="selectCompanySaleById" parameterType="Long" resultMap="CompanySaleResult">
        <include refid="selectCompanySaleVo"/>
        where id = #{id}
    </select>

    <insert id="insertCompanySale" parameterType="CompanySale" useGeneratedKeys="true" keyProperty="id">
        insert into company_sale
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="saleName != null">sale_name,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="wxAccount != null">wx_account,</if>
            <if test="wxQrcode != null">wx_qrcode,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="saleName != null">#{saleName},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="wxAccount != null">#{wxAccount},</if>
            <if test="wxQrcode != null">#{wxQrcode},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateCompanySale" parameterType="CompanySale">
        update company_sale
        <trim prefix="SET" suffixOverrides=",">
            <if test="saleName != null">sale_name = #{saleName},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="wxAccount != null">wx_account = #{wxAccount},</if>
            <if test="wxQrcode != null">wx_qrcode = #{wxQrcode},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanySaleById" parameterType="Long">
        delete from company_sale where id = #{id}
    </delete>

    <delete id="deleteCompanySaleByIds" parameterType="String">
        delete from company_sale where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>