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

    <resultMap type="PosReview" id="PosReviewResult">
        <result property="id" column="id"/>
        <result property="ddId" column="dd_id"/>
        <result property="score" column="score"/>
        <result property="cretim" column="cretim"/>
        <result property="content" column="content"/>
        <result property="userId" column="user_id"/>
        <result property="anonymous" column="anonymous"/>
        <result property="images" column="images"/>
    </resultMap>

    <sql id="selectPosReviewVo">
        select id,
               dd_id,
               score,
               cretim,
               content,
               user_id,
               anonymous,
               images
        from pos_review
    </sql>

    <select id="selectPosReviewList" parameterType="PosReview" resultMap="PosReviewResult">
        <include refid="selectPosReviewVo"/>
        <where>
            <if test="ddId != null ">and dd_id = #{ddId}</if>
            <if test="score != null ">and score = #{score}</if>
            <if test="cretim != null ">
                AND DATE(cretim) = DATE(#{cretim})
            </if>
            <if test="content != null  and content != ''">and content = #{content}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="anonymous != null ">and anonymous = #{anonymous}</if>
            <if test="images != null ">and images = #{images}</if>
        </where>
    </select>

    <select id="selectPosReviewById" parameterType="Long" resultMap="PosReviewResult">
        <include refid="selectPosReviewVo"/>
        where id = #{id}
    </select>

    <insert id="insertPosReview" parameterType="PosReview" useGeneratedKeys="true" keyProperty="id">
        insert into pos_review
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ddId != null">dd_id,</if>
            <if test="score != null">score,</if>
            <if test="cretim != null">cretim,</if>
            <if test="content != null">content,</if>
            <if test="userId != null">user_id,</if>
            <if test="anonymous != null">anonymous,</if>
            <if test="images != null">images,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ddId != null">#{ddId},</if>
            <if test="score != null">#{score},</if>
            <if test="cretim != null">#{cretim},</if>
            <if test="content != null">#{content},</if>
            <if test="userId != null">#{userId},</if>
            <if test="anonymous != null">#{anonymous},</if>
            <if test="images != null">#{images},</if>
        </trim>
    </insert>

    <update id="updatePosReview" parameterType="PosReview">
        update pos_review
        <trim prefix="SET" suffixOverrides=",">
            <if test="ddId != null">dd_id = #{ddId},</if>
            <if test="score != null">score = #{score},</if>
            <if test="cretim != null">cretim = #{cretim},</if>
            <if test="content != null">content = #{content},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="anonymous != null">anonymous = #{anonymous},</if>
            <if test="images != null">images = #{images},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePosReviewById" parameterType="Long">
        delete
        from pos_review
        where id = #{id}
    </delete>

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