package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerCustomerMapper;
import com.gxwebsoft.tower.service.TowerCustomerService;
import com.gxwebsoft.tower.entity.TowerCustomer;
import com.gxwebsoft.tower.param.TowerCustomerParam;
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-08 21:04:27
 */
@Service
public class TowerCustomerServiceImpl extends ServiceImpl<TowerCustomerMapper, TowerCustomer> implements TowerCustomerService {

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

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

    @Override
    public TowerCustomer getByIdRel(Integer customerId) {
        TowerCustomerParam param = new TowerCustomerParam();
        param.setCustomerId(customerId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
