package com.gxwebsoft.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.house.mapper.HouseUserMapper;
import com.gxwebsoft.house.service.HouseUserService;
import com.gxwebsoft.house.entity.HouseUser;
import com.gxwebsoft.house.param.HouseUserParam;
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 2025-03-05 15:13:05
 */
@Service
public class HouseUserServiceImpl extends ServiceImpl<HouseUserMapper, HouseUser> implements HouseUserService {

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

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

    @Override
    public HouseUser getByIdRel(Integer userId) {
        HouseUserParam param = new HouseUserParam();
        param.setUserId(userId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
