package com.gxwebsoft.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.house.entity.HouseMessage;
import com.gxwebsoft.house.mapper.HouseMessageMapper;
import com.gxwebsoft.house.param.HouseMessageParam;
import com.gxwebsoft.house.service.HouseMessageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AI找房留言Service实现
 */
@Service
public class HouseMessageServiceImpl extends ServiceImpl<HouseMessageMapper, HouseMessage> implements HouseMessageService {

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

    @Override
    public List<HouseMessage> listRel(HouseMessageParam param) {
        List<HouseMessage> list = baseMapper.selectListRel(param);
        PageParam<HouseMessage, HouseMessageParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc, message_id desc");
        return page.sortRecords(list);
    }

    @Override
    public HouseMessage getByIdRel(Integer messageId) {
        HouseMessageParam param = new HouseMessageParam();
        param.setMessageId(messageId);
        return param.getOne(baseMapper.selectListRel(param));
    }
}
