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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jkcredit.invoice.mapper.calculateinfor.NoCarCalculateInforMapper;
import com.jkcredit.invoice.mapper.customer.CustomerMapper;
import com.jkcredit.invoice.model.entity.calculate.NoCarCalculateInfor;
import com.jkcredit.invoice.model.entity.customer.Customer;
import com.jkcredit.invoice.service.calculateinfor.NoCarCalculateInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
/**
 * @Description 无车计费服务
 * @Author mashengyi
 * @Date 2022/2/8 18:28
 * @Param
 * @Return
 * @Exception
 *
 */
public class NocarCalculateInfoServiceImpl extends ServiceImpl<NoCarCalculateInforMapper, NoCarCalculateInfor> implements NoCarCalculateInfoService {
    @Autowired
    NoCarCalculateInforMapper noCarCalculateInforMapper;

    @Autowired
    CustomerMapper customerMapper;

    @Override
    public IPage<List<NoCarCalculateInfor>> findByPageAndCalculateInfor(Page page, NoCarCalculateInfor calculateInfor) {
        return noCarCalculateInforMapper.selectAllByPage(page, calculateInfor);
    }

    @Override
    public List<Map<String, String>> findNocarCalculateInfoStatis(NoCarCalculateInfor calculateInfor) {
        List<Map<String, String>> list = noCarCalculateInforMapper.selectforStatis(calculateInfor);
        for (Map<String, String> map : list) {
            String customId = map.get("customId");
            Customer customer = customerMapper.selectByCustomerName(customId);
            if (customer != null) {
                map.put("customId", customer.getCompany());
            }
        }
        return list;
    }
}
