package com.gci.boot.modules.basedata.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gci.boot.modules.basedata.entity.TbVehicleSupplierArchives;
import com.gci.boot.modules.basedata.mapper.TbVehicleSupplierArchivesMapper;
import com.gci.boot.modules.basedata.service.ITbVehicleSupplierArchivesService;
import com.gci.boot.modules.basedata.vo.SupplierPageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
@Slf4j
public class TbVehicleSupplierArchivesServiceImpl extends ServiceImpl<TbVehicleSupplierArchivesMapper, TbVehicleSupplierArchives> implements ITbVehicleSupplierArchivesService {

    @Autowired
    private TbVehicleSupplierArchivesMapper vehicleSupplierArchivesMapper;

    @Override
    public boolean check(TbVehicleSupplierArchives archives) {
        LambdaQueryWrapper<TbVehicleSupplierArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(wrapper -> wrapper.eq(TbVehicleSupplierArchives::getName,archives.getName())
                .or().eq(TbVehicleSupplierArchives::getShortened,archives.getShortened()))
                .ne(StrUtil.isNotBlank(archives.getId()), TbVehicleSupplierArchives::getId,archives.getId());

        int count = count(queryWrapper);
        return count <= 0;
    }

    @Override
    public Page getSupplierPage(Page page, SupplierPageVO vo) {
        List<SupplierPageVO> list = new ArrayList<>();
        list = vehicleSupplierArchivesMapper.findSupplierPage(page,vo);
        page.setRecords(list);
        return page;
    }
}
