package com.ics.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ics.admin.domain.Customer;
import com.ics.admin.mapper.CustomerMapper;
import com.ics.admin.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 客户管理Service业务层处理
 *
 * @author zzm
 * @date 2021-03-29
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 查询客户管理
     *
     * @param id 客户管理ID
     * @return 客户管理
     */
    @Override
    public Customer selectCustomerById(Long id) {
        return customerMapper.selectCustomerById(id);
    }

    /**
     * 查询客户管理列表
     *
     * @param customer 客户管理
     * @return 客户管理
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer) {
        return customerMapper.selectCustomerList(customer);
    }

    /**
     * 新增客户管理
     *
     * @param customer 客户管理
     * @return 结果
     */
    @Override
    public int insertCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    /**
     * 修改客户管理
     *
     * @param customer 客户管理
     * @return 结果
     */
    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateById(customer);
    }

    /**
     * 删除客户管理对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCustomerByIds(String ids) {
        String[] idsArray = StrUtil.split(ids,",");
        return customerMapper.deleteBatchIds(CollUtil.toList(idsArray));
    }

    /**
     * 删除客户管理信息
     *
     * @param id 客户管理ID
     * @return 结果
     */
    @Override
    public int deleteCustomerById(Long id) {
        return customerMapper.deleteById(id);
    }

    @Override
    public List<Customer> selectByRoomId(Long id, Long parkId) {

        QueryWrapper<Customer> queryWrapper =new QueryWrapper<>();
                queryWrapper.like("room_id",id);
                queryWrapper.eq("park_id",parkId);
        return customerMapper.selectList(queryWrapper);

    }

    @Override
    public Customer selectCustomerByIdAndParkId(Long icsCustomerId, Long parkId) {
        QueryWrapper<Customer> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("id",icsCustomerId).eq("park_id",parkId);
        return customerMapper.selectOne(queryWrapper);

    }

    @Override
    public List<Customer> selectCustomerByRoomId(Long id) {
        QueryWrapper<Customer> queryWrapper =new QueryWrapper<>();
        queryWrapper.like("room_id",id);
        return customerMapper.selectList(queryWrapper);
    }
}