package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerLendingMapper;
import com.gxwebsoft.tower.service.TowerLendingService;
import com.gxwebsoft.tower.entity.TowerLending;
import com.gxwebsoft.tower.param.TowerLendingParam;
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-15 10:29:54
 */
@Service
public class TowerLendingServiceImpl extends ServiceImpl<TowerLendingMapper, TowerLending> implements TowerLendingService {

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

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

    @Override
    public TowerLending getByIdRel(Integer lendingId) {
        TowerLendingParam param = new TowerLendingParam();
        param.setLendingId(lendingId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
