package cn.com.ty.lift.ud.chat.mapper;

import cn.com.ty.lift.ud.chat.controller.model.ChatSessionReq;
import cn.com.ty.lift.ud.chat.controller.query.ChatSessionQuery;
import cn.com.ty.lift.ud.chat.mapper.entity.ChatSessionEntity;
import cn.com.xwy.boot.web.dto.RestResponse;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * 会话 -Repository
 * 
 * @author Xson
 * @date 2020-04-22
 */
public interface ChatSessionMapper extends BaseMapper<ChatSessionEntity> {
    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table chat_session
     *
     * @mbggenerated Tue Apr 28 14:25:10 CST 2020
     */
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table chat_session
     *
     * @mbggenerated Tue Apr 28 14:25:10 CST 2020
     */
    int insertSelective(ChatSessionEntity record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table chat_session
     *
     * @mbggenerated Tue Apr 28 14:25:10 CST 2020
     */
    ChatSessionEntity selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table chat_session
     *
     * @mbggenerated Tue Apr 28 14:25:10 CST 2020
     */
    int updateByPrimaryKeySelective(ChatSessionEntity record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table chat_session
     *
     * @mbggenerated Tue Apr 28 14:25:10 CST 2020
     */
    int updateByPrimaryKey(ChatSessionEntity record);

    ChatSessionEntity findOneBySessionIdAndPwd(@Param("sessionId") String sessionId, @Param("pwd") String pwd);

    int batchUpdate(@Param("req") ChatSessionReq req);

    /**
     * 置顶操作，取消置顶炒操作，根据sessionid修改top_flag字段
     * @param req
     * @return
     */
    int setTop(@Param("req") ChatSessionReq req);

    List<ChatSessionEntity> selectByQuery(@Param("ew") Wrapper wrapper, @Param("page") ChatSessionQuery query);

//    List<ChatSessionEntity> findDBListByUserId(@Param("userId") String userId);
    List<ChatSessionEntity> findDBListByUserId(ChatSessionQuery query);

    int countByQuery(@Param("ew") Wrapper wrapper);

    @Select("select sessionid from chat_session where user_id = #{userId} and statuz = 1 ")
    List<String> findListByUserId(@Param("userId") String userId);

    int batchUpdateEntrance(@Param("sessionId") String sessionId, @Param("entrance") Integer entrance);

    @Select("select sessionid from chat_session where (user_id = #{userId}  and create_user_id  = #{createUserId}) or (user_id = #{createUserId}  and create_user_id  = #{userId})   and data_table = #{dataTable}")
    String findOneByUserIdAndCreateUserIdAndDateTable(@Param("userId") String userId,
        @Param("createUserId") String createUserId, @Param("dataTable") Integer dataTable);


    List<ChatSessionEntity> findAllSession();
}
