package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.CustomerMapper;
import com.gxwebsoft.oa.service.CustomerService;
import com.gxwebsoft.oa.entity.Customer;
import com.gxwebsoft.oa.param.CustomerParam;
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 WebSoft
 * @since 2022-11-16 11:16:14
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

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

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

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

    @Override
    public Customer getByCustomerName(String customerName) {
        return query().eq("customer_name", customerName).one();
    }

}
