package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.ta.pdd.entity.AreaEntity;
import org.ta.pddserver.model.api.request.AreaListRequest;

import java.util.List;

@Mapper
public interface AreaMapper extends BaseMapper<AreaEntity> {

    @Select("SELECT count(`uid`) FROM `area` WHERE `state` > 0")
    Integer countUsable(AreaListRequest param);

    @Select("SELECT * FROM `area` WHERE  `state` > 0 ORDER BY uid DESC LIMIT #{offset}, #{size}; ")
    List<AreaEntity> getListByRequest(AreaListRequest param);

    @Select("SELECT * FROM `area` WHERE  `state` > 0 AND `code` = #{code};")
    AreaEntity getInfoByCode(@Param("code") String code);

    @Select("SELECT * FROM `area` WHERE `state` > 0 AND `uid` = #{uid}")
    AreaEntity getInfoByUid(@Param("uid") String uid);

    @Select("SELECT * FROM `area` WHERE `state` > 0 ORDER BY `uid` ASC")
    List<AreaEntity> getList();
}
