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.TbRepairShopArchives;
import com.gci.boot.modules.basedata.mapper.TbRepairShopArchivesMapper;
import com.gci.boot.modules.basedata.service.ITbRepairShopArchivesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TbRepairShopArchivesServiceImpl extends ServiceImpl<TbRepairShopArchivesMapper, TbRepairShopArchives> implements ITbRepairShopArchivesService {

    @Autowired
    private TbRepairShopArchivesMapper tbRepairShopArchivesMapper;

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

    @Override
    public List<TbRepairShopArchives> getRepairShopByUserId(String userId) {
        return tbRepairShopArchivesMapper.getRepairShopByUserId(userId);
    }
}
