<?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="reviewPharmacistsMapper">

    <!-- 查询所有审核药师 -->
    <select id="selectAllReviewPharmacists" parameterType="pd" resultType="pd">
        SELECT * FROM s_dtp_review_pharmacists WHERE 1=1
        <if test="pharmacistName != null and pharmacistName != ''">
            AND pharmacistName = #{pharmacistName}
        </if>
        <if test="position != null and position != ''">
            AND position = #{position}
        </if>
        <if test="storeName != null and storeName != ''">
            AND storeName = #{storeName}
        </if>
        <if test="storeId != null and storeId != ''">
            AND storeId = #{storeId}
        </if>
        <if test="createdTime != null">
            AND createdTime = #{createdTime}
        </if>
        <if test="updatedTime != null">
            AND updatedTime = #{updatedTime}
        </if>
    </select>

    <!-- 根据 ID 查询单个审核药师 -->
    <select id="ReviewCheckInputPassword" parameterType="pd" resultType="pd">
        SELECT * FROM s_dtp_review_pharmacists WHERE id = #{id} and reviewPassword=#{reviewPassword}
    </select>
    <select id="selectReviewPharmacistById" parameterType="long" resultType="pd">
        SELECT * FROM s_dtp_review_pharmacists WHERE id = #{id}
    </select>
    <!-- 检查是否存在特定药师 -->
    <select id="checkPharmacistByNameAndStore" parameterType="pd" resultType="pd">
        SELECT * FROM s_dtp_review_pharmacists WHERE pharmacistName = #{pharmacistName} AND storeId = #{storeId}
    </select>

    <!-- 更新审核药师信息 -->
    <update id="updateReviewPharmacist" parameterType="pd">
        UPDATE s_dtp_review_pharmacists
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="pharmacistName != null and pharmacistName != ''">
                pharmacistName = #{pharmacistName},
            </if>
            <if test="position != null and position != ''">
                position = #{position},
            </if>
            <if test="storeName != null and storeName != ''">
                storeName = #{storeName},
            </if>
            <if test="storeId != null and storeId != ''">
                storeId = #{storeId},
            </if>
            <if test="reviewPassword != null and reviewPassword != ''">
                reviewPassword = #{reviewPassword},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
        </trim>
        <if test="id != null">
            WHERE id = #{id}
        </if>
    </update>

    <!-- 根据 d_value_code 更新审核药师信息 -->
    <update id="updateReviewPharmacistByStoreId" parameterType="pd">
        UPDATE s_dtp_review_pharmacists
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="pharmacistName != null and pharmacistName != ''">
                pharmacistName = #{pharmacistName},
            </if>
            <if test="position != null and position != ''">
                position = #{position},
            </if>
            <if test="storeName != null and storeName != ''">
                storeName = #{storeName},
            </if>
            <if test="reviewPassword != null and reviewPassword != ''">
                reviewPassword = #{reviewPassword},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
        </trim>
        <if test="storeId != null and storeId != ''">
            WHERE storeId = #{storeId}
        </if>
    </update>

    <!-- 删除审核药师（按ID列表） -->
    <delete id="deleteReviewPharmacistsByIds" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            DELETE FROM s_dtp_review_pharmacists
            WHERE id IN
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>

    <!-- 插入新的审核药师 -->
    <insert id="insertReviewPharmacist" parameterType="pd">
        INSERT INTO s_dtp_review_pharmacists
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="pharmacistName != null and pharmacistName != ''">
                pharmacistName,
            </if>
            <if test="position != null and position != ''">
                position,
            </if>
            <if test="storeName != null and storeName != ''">
                storeName,
            </if>
            <if test="storeId != null and storeId != ''">
                storeId,
            </if>
            <if test="reviewPassword != null and reviewPassword != ''">
                reviewPassword,
            </if>
            <if test="createdTime != null">
                createdTime,
            </if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="pharmacistName != null and pharmacistName != ''">
                #{pharmacistName},
            </if>
            <if test="position != null and position != ''">
                #{position},
            </if>
            <if test="storeName != null and storeName != ''">
                #{storeName},
            </if>
            <if test="storeId != null and storeId != ''">
                #{storeId},
            </if>
            <if test="reviewPassword != null and reviewPassword != ''">
                #{reviewPassword},
            </if>
            <if test="createdTime != null">
                #{createdTime},
            </if>
        </trim>
    </insert>

    <!-- 修改审核药师密码 -->
    <update id="changeStatus" parameterType="pd">
        UPDATE s_dtp_review_pharmacists SET updatedTime = #{updatedTime}, reviewPassword = #{reviewPassword} WHERE id = #{id}
    </update>
</mapper>
