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

import cn.com.taiji.sdk.model.comm.protocol.tts.card.server.*;
import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleRegisterRequest;
import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleRegisterResponse;
import com.jkcredit.invoice.common.CommonConstants;
import com.jkcredit.invoice.mapper.customer.CustomerCarRecMapper;
import com.jkcredit.invoice.mapper.customer.CustomerMapper;
import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
import com.jkcredit.invoice.model.entity.customer.Customer;
import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
import com.jkcredit.invoice.model.entity.customer.CustomerRec;
import com.jkcredit.invoice.service.lowerService.CustomeLowerService;
import com.jkcredit.invoice.service.lowerService.vo.EtcBindVo;
import com.jkcredit.invoice.service.lowerService.vo.EtcValidVo;
import com.jkcredit.invoice.service.upService.NoCarInterface;
import com.jkcredit.invoice.service.upService.SelfCarInterface;
import com.jkcredit.invoice.util.DateUtil;
import com.jkcredit.invoice.util.RespR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

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

@Service("lowerService")
public class CustomerLowerServiceImpl implements CustomeLowerService {
    @Autowired
    CustomerMapper customerMapper;

    @Autowired
    CustomerRecMapper customerRecMapper;

    @Autowired
    CustomerCarRecMapper customerCarRecMapper;

    @Autowired
    NoCarInterface noCarInterface;

    @Autowired
    SelfCarInterface selfCarInterface;
    @Override
    public RespR customeRec(List<CustomerRec> customerRecs) {

        if(customerRecs==null || customerRecs.size()<=0){return new RespR(false,"备案信息为空");};
        StringBuffer res = new StringBuffer();
        customerRecs.stream().forEach(customerRec -> {
            Customer customer = customerMapper.selectByCustomerName(customerRec.getCustomerName());
            if(customer == null || customer.getAccstatus()!=0){
                res.append(customerRec.getCustomerName()+"不存在或已经停用;");
                return;
            }
            //默认备案状态为备案中 0 -备案中 1.备案失败 2.备案完成
            customerRec.setRecStatus(0);
            //客户备案信息入表
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompany(customerRec);
            customerRec.setCreatetime(DateUtil.getCurrentDateStr());
            customerRec.setCompanyBelongName(customerRec.getCompanyName());
            if(customerRec1 == null){
                customerRecMapper.insert(customerRec);
            }else{
                customerRec.setId(customerRec1.getId());
                customerRecMapper.updateByPrimaryKey(customerRec);
            }
        });
        if(StringUtils.isEmpty(res.toString())){
            return new RespR(true,"成功");
        }else{
            return new RespR(false,res.toString());
        }

    }

    @Override
    public RespR customeRecQueryList(CustomerRec customerRec) {

        return new RespR(customerRecMapper.selectByCustomerName(customerRec.getCustomerName()));
    }
    @Override
    public RespR customeRecQuery(CustomerRec customerRec) {

        return new RespR(customerRecMapper.selectByCustomerNameAndCompany(customerRec));
    }

}
