package com.jkcredit.invoice.service.selfcar.impl;

import com.jkcredit.invoice.mapper.customer.CustomerCarRecMapper;
import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
import com.jkcredit.invoice.service.lowerservice.SelfCarCustService;
import com.jkcredit.invoice.service.selfcar.SelfCarBussService;
import com.jkcredit.invoice.util.RespR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 自有车业务层操作实现类
 * @author mumuxigua
 */
@Service
public class SelfCarBussServiceImpl implements SelfCarBussService {
    @Autowired
    SelfCarCustService selfCarService;
    @Autowired
    CustomerCarRecMapper customerCarRecMapper;

    @Override
    public RespR selfCarUnBind(String cardId) {
        CustomerCarRec customerCarRec = customerCarRecMapper.selectByEtc(cardId);
        if (customerCarRec.getRecStatus() != 1) {
            return new RespR(false, "无需解绑");
        }
        List<CustomerCarRec> customerCarRecs = new ArrayList<>();
        customerCarRecs.add(customerCarRec);
        return selfCarService.customerCarUnRec(customerCarRecs);
    }

    @Override
    public List<CustomerCarRec> getEtcsByCarNum(String carNum) {
        String [] carNumArr = carNum.split(",");
        return customerCarRecMapper.selectBySelfCarNum(carNumArr);
    }

    @Override
    public List<CustomerCarRec> getEtcsByCompany(String comapanyName) {
        return customerCarRecMapper.selectAllEtcByCompany(comapanyName);
    }
}
