<?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.ycwl.basic.mapper.ScenicAccountMapper">
    <insert id="add">
        insert into scenic_account(id, scenic_id, is_super, name, phone, account, password, create_time, update_time)
        values (#{id}, #{scenicId}, #{isSuper}, #{name}, #{phone}, #{account}, #{password}, now(), now())
    </insert>
    <update id="update">
        update scenic_account
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="phone != null and phone != ''">
                phone = #{phone},
            </if>
            <if test="account != null and account != ''">
                account = #{account},
            </if>
            <if test="password != null and password != ''">
                password = #{password},
            </if>
            update_time = now()
        </set>
        where id = #{id}
    </update>
    <update id="updateStatus">
        update scenic_account
        set status = (CASE
                          WHEN status = 1 THEN
                              0
                          WHEN status = 0 THEN
                              1
                          ELSE null
                      END)
        where id = #{id}
    </update>
    <delete id="deleteById">
        delete from scenic_account where id = #{id}
    </delete>
    <delete id="deleteByScenicId">
        delete from scenic_account where scenic_id = #{scenicId}
    </delete>
    <select id="getSuperAccountOfScenic"
            resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
        select id, scenic_id, is_super, name, phone, account, password, create_time, update_time
        from scenic_account
        where scenic_id = #{scenicId} and is_super = 1
    </select>
    <select id="getByAccount" resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
        select id, scenic_id, is_super, name, phone, account, password, status,create_time, update_time
        from scenic_account
        where account = #{account}
    </select>
    <select id="findAccountById" resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
        select *
        from scenic_account
        where id = #{id}
    </select>
    <select id="pageQuery" resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
        SELECT * FROM scenic_account
        <where>
            <if test="scenicId != null">
                AND scenic_id = #{scenicId}
            </if>
            <if test="account != null and account != ''">
                AND account LIKE CONCAT('%', #{account}, '%')
            </if>
            <if test="phone != null and phone != ''">
                AND phone LIKE CONCAT('%', #{phone}, '%')
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="isSuper != null">
                AND is_super = #{isSuper}
            </if>
            <if test="startTime != null">
                AND create_time >= #{startTime}
            </if>
            <if test="endTime != null">
                AND create_time &lt;= #{endTime}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
</mapper>