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.HouseAiConfig;
import com.gxwebsoft.house.mapper.HouseAiConfigMapper;
import com.gxwebsoft.house.param.HouseAiConfigParam;
import com.gxwebsoft.house.service.HouseAiConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AI找房配置Service实现
 */
@Service
public class HouseAiConfigServiceImpl extends ServiceImpl<HouseAiConfigMapper, HouseAiConfig> implements HouseAiConfigService {

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

    @Override
    public List<HouseAiConfig> listRel(HouseAiConfigParam param) {
        return baseMapper.selectListRel(param);
    }

    @Override
    public HouseAiConfig getByIdRel(Integer configId) {
        HouseAiConfigParam param = new HouseAiConfigParam();
        param.setConfigId(configId);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public HouseAiConfig getCurrentConfig(Integer tenantId) {
        HouseAiConfigParam param = new HouseAiConfigParam();
        param.setStatus(0);
        param.setTenantId(tenantId);
        HouseAiConfig config = param.getOne(baseMapper.selectListRel(param));
        if (config != null) {
            return config;
        }
        param.setTenantId(null);
        return param.getOne(baseMapper.selectListRel(param));
    }
}
