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.service.impl.ServiceImpl;
import com.gci.boot.modules.basedata.entity.TbInsuranceCompanyArchives;
import com.gci.boot.modules.basedata.entity.TbVehicleSupplierArchives;
import com.gci.boot.modules.basedata.mapper.TbInsuranceCompanyArchivesMapper;
import com.gci.boot.modules.basedata.service.ITbInsuranceCompanyArchivesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TbInsuranceCompanyArchivesServiceImpl extends ServiceImpl<TbInsuranceCompanyArchivesMapper, TbInsuranceCompanyArchives> implements ITbInsuranceCompanyArchivesService {

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