package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.ta.pdd.entity.UserEntity;
import org.ta.pddserver.model.api.request.UserRequest;
import org.ta.pddserver.model.api.response.UserListResponse;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {

    @Select("SELECT * FROM `user` WHERE  `account` = #{account}")
    UserEntity getInfoByAccount(String account);

    @Select("SELECT `uid` , `name` ,`status`, `account`, `created` FROM `user` WHERE `state` > 0 AND `account` LIKE '%${account}%' ORDER BY uid DESC LIMIT #{offset}, #{size};")
    List<UserListResponse> getListByRequest(UserRequest param);

    @Select("SELECT COUNT(`uid`) FROM `user` WHERE `state` > 0 AND `account` LIKE '%${account}%' ; ")
    Integer countUsable(UserRequest param);
}
