package com.gxwebsoft.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.house.mapper.InfoMapper;
import com.gxwebsoft.house.service.InfoService;
import com.gxwebsoft.house.entity.Info;
import com.gxwebsoft.house.param.InfoParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 房源信息表Service实现
 *
 * @author 科技小王子
 * @since 2023-08-03 18:23:43
 */
@Service
public class InfoServiceImpl extends ServiceImpl<InfoMapper, Info> implements InfoService {

    @Override
    public PageResult<Info> pageRel(InfoParam param) {
        PageParam<Info, InfoParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<Info> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<Info> listRel(InfoParam param) {
        List<Info> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<Info, InfoParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public Info getByIdRel(Integer houseId) {
        InfoParam param = new InfoParam();
        param.setHouseId(houseId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
