<?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.dora.mapper.WechatQrCodeMapper">

    <resultMap id="WechatQrCodeResultMap" type="com.dora.entity.WechatQrCode">
        <id column="id" property="id"/>
        <result column="qr_code_url" property="qrCodeUrl"/>
        <result column="description" property="description"/>
        <result column="create_time" property="createTime"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>

    <select id="selectById" resultMap="WechatQrCodeResultMap">
        SELECT id, qr_code_url, description, create_time, is_deleted
        FROM wechat_qr_code 
        WHERE id = #{id} AND is_deleted = 0
        LIMIT 1
    </select>

    <select id="selectAll" resultMap="WechatQrCodeResultMap">
        SELECT id, qr_code_url, description, create_time, is_deleted
        FROM wechat_qr_code 
        WHERE is_deleted = 0
        ORDER BY create_time DESC
    </select>

    <insert id="insert" parameterType="com.dora.entity.WechatQrCode" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO wechat_qr_code (qr_code_url, description, create_time, is_deleted)
        VALUES (#{qrCodeUrl}, #{description}, NOW(), 0)
    </insert>

    <update id="updateById" parameterType="com.dora.entity.WechatQrCode">
        UPDATE wechat_qr_code 
        SET 
            <if test="qrCodeUrl != null">qr_code_url = #{qrCodeUrl},</if>
            <if test="description != null">description = #{description}</if>
        WHERE id = #{id} AND is_deleted = 0
    </update>

    <update id="softDelete">
        UPDATE wechat_qr_code 
        SET is_deleted = 1 
        WHERE id = #{id}
    </update>

</mapper>
