package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerAccessoryMapper;
import com.gxwebsoft.tower.service.TowerAccessoryService;
import com.gxwebsoft.tower.entity.TowerAccessory;
import com.gxwebsoft.tower.param.TowerAccessoryParam;
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-22 11:53:48
 */
@Service
public class TowerAccessoryServiceImpl extends ServiceImpl<TowerAccessoryMapper, TowerAccessory> implements TowerAccessoryService {

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

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

    @Override
    public TowerAccessory getByIdRel(Integer accessoryId) {
        TowerAccessoryParam param = new TowerAccessoryParam();
        param.setAccessoryId(accessoryId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
