package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerRentRecordMapper;
import com.gxwebsoft.tower.service.TowerRentRecordService;
import com.gxwebsoft.tower.entity.TowerRentRecord;
import com.gxwebsoft.tower.param.TowerRentRecordParam;
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-06-13 00:42:42
 */
@Service
public class TowerRentRecordServiceImpl extends ServiceImpl<TowerRentRecordMapper, TowerRentRecord> implements TowerRentRecordService {

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

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

    @Override
    public TowerRentRecord getByIdRel(Integer rentRecordId) {
        TowerRentRecordParam param = new TowerRentRecordParam();
        param.setRentRecordId(rentRecordId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
