<?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.ss.customerService.mapper.CustomerServiceMapper">

    <resultMap type="CustomerServiceVO" id="CustomerServiceResult" autoMapping="true"/>

    <sql id="selectCustomerServiceVo">
        select
            scs.id,
            scs.name,
            scs.mobile,
            scs.type,
            scs.wx,
            scs.create_time,
            scs.sort,
            scs.work_time_start,
            scs.work_time_end
        from ss_customer_service scs
    </sql>

    <sql id="searchCondition">
        <if test="query.id != null "> and scs.id = #{query.id}</if>
        <if test="query.name != null  and query.name != ''"> and scs.`name` like concat('%', #{query.name}, '%')</if>
        <if test="query.mobile != null  and query.mobile != ''"> and scs.mobile like concat('%', #{query.mobile}, '%')</if>
        <if test="query.type != null  and query.type != ''"> and scs.type = #{query.type}</if>
        <if test="query.wx != null  and query.wx != ''"> and scs.wx like concat('%', #{query.wx}, '%')</if>
    </sql>

    <select id="selectCustomerServiceList" parameterType="CustomerServiceQuery" resultMap="CustomerServiceResult">
        <include refid="selectCustomerServiceVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectCustomerServiceById" parameterType="Long" resultMap="CustomerServiceResult">
        <include refid="selectCustomerServiceVo"/>
        where scs.id = #{id}
    </select>

    <insert id="insertCustomerService" parameterType="CustomerService" useGeneratedKeys="true" keyProperty="id">
        insert into ss_customer_service
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="wx != null">wx,</if>
            <if test="createTime != null">create_time,</if>
            <if test="sort != null">sort,</if>
            <if test="workTimeStart != null">work_time_start,</if>
            <if test="workTimeEnd != null">work_time_end,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="wx != null">#{wx},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="sort != null">#{sort},</if>
            <if test="workTimeStart != null">#{workTimeStart},</if>
            <if test="workTimeEnd != null">#{workTimeEnd},</if>
         </trim>
    </insert>

    <update id="updateCustomerService" parameterType="CustomerService">
        update ss_customer_service
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where id = #{data.id}
    </update>

    <sql id="updateColumns">
        <if test="data.name != null and data.name != ''">`name` = #{data.name},</if>
        <if test="data.mobile != null">mobile = #{data.mobile},</if>
        <if test="data.type != null and data.type != ''">type = #{data.type},</if>
        <if test="data.wx != null">wx = #{data.wx},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
        <if test="data.sort != null">sort = #{data.sort},</if>
        <if test="data.workTimeStart != null">work_time_start = #{data.workTimeStart},</if>
        <if test="data.workTimeEnd != null">work_time_end = #{data.workTimeEnd},</if>
    </sql>

    <delete id="deleteCustomerServiceById" parameterType="Long">
        delete from ss_customer_service where id = #{id}
    </delete>

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