package com.fs.store.mapper;

import java.util.List;
import com.fs.store.domain.FsPrescribe;
import com.fs.store.param.FsPrescribeQueryParam;
import com.fs.store.param.FsPrescribeVOParam;
import com.fs.store.vo.FsPrescribeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 处方Mapper接口
 * 
 * @author fs
 * @date 2022-03-15
 */
public interface FsPrescribeMapper 
{
    /**
     * 查询处方
     * 
     * @param prescribeId 处方ID
     * @return 处方
     */
    public FsPrescribe selectFsPrescribeById(Long prescribeId);

    /**
     * 查询处方列表
     * 
     * @param fsPrescribe 处方
     * @return 处方集合
     */
    public List<FsPrescribe> selectFsPrescribeList(FsPrescribe fsPrescribe);

    /**
     * 新增处方
     * 
     * @param fsPrescribe 处方
     * @return 结果
     */
    public int insertFsPrescribe(FsPrescribe fsPrescribe);

    /**
     * 修改处方
     * 
     * @param fsPrescribe 处方
     * @return 结果
     */
    public int updateFsPrescribe(FsPrescribe fsPrescribe);

    /**
     * 删除处方
     * 
     * @param prescribeId 处方ID
     * @return 结果
     */
    public int deleteFsPrescribeById(Long prescribeId);

    /**
     * 批量删除处方
     * 
     * @param prescribeIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsPrescribeByIds(Long[] prescribeIds);
    @Select("select * from fs_prescribe where rp_id=#{rpId}")
    FsPrescribe selectFsPrescribeByRpId(String rpId);

    @Select({"<script> " +
            "select * from fs_prescribe  " +
            "where 1=1 " +
            "<if test = 'maps.userId != null    '> " +
            "and user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and status =#{maps.status} " +
            "</if>" +
            " order by create_time desc "+
            "</script>"})
    List<FsPrescribeVO> selectFsPrescribeListQuery(@Param("maps") FsPrescribeQueryParam param);
    @Select("select * from fs_prescribe where order_id=#{orderId} order by prescribe_id desc  limit 1 ")
    FsPrescribe selectFsPrescribeByOrderId(Long orderId);
    @Select({"<script> " +
            "select p.*,u.nickname as user_nickname,u.phone as user_phone,o.order_code from fs_prescribe p left join fs_store_order o on o.id=p.order_id left join fs_user u on u.user_id=p.user_id  " +
            "where 1=1 " +
            "<if test = 'maps.rpId != null and maps.rpId!=\"\"    '> " +
            "and p.rp_id =#{maps.rpId} " +
            "</if>" +
            "<if test = 'maps.orderCode != null and maps.orderCode!=\"\"    '> " +
            "and o.order_code =#{maps.orderCode} " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and p.status =#{maps.status} " +
            "</if>" +
            " order by p.create_time desc "+
            "</script>"})
    List<FsPrescribeVO> selectFsPrescribeListVO(@Param("maps") FsPrescribeVOParam fsPrescribe);
}
