package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerModelMapper;
import com.gxwebsoft.tower.service.TowerModelService;
import com.gxwebsoft.tower.entity.TowerModel;
import com.gxwebsoft.tower.param.TowerModelParam;
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-05-29 14:07:46
 */
@Service
public class TowerModelServiceImpl extends ServiceImpl<TowerModelMapper, TowerModel> implements TowerModelService {

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

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

    @Override
    public TowerModel getByIdRel(Integer modelId) {
        TowerModelParam param = new TowerModelParam();
        param.setModelId(modelId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
