package org.jeecg.module.custom.ocr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.module.custom.ocr.base.BaseServiceImpl;
import org.jeecg.module.custom.ocr.dataDao.OcrDictionaryDao;
import org.jeecg.module.custom.ocr.dataDao.OcrDictionaryGroupDao;
import org.jeecg.module.custom.ocr.dataobject.OcrDictionary;
import org.jeecg.module.custom.ocr.dataobject.OcrDictionaryGroup;
import org.jeecg.module.custom.ocr.service.OcrDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务向 数据字典 操作接口实现类
 *
 * @author hugh(shuli.yao) 1397940314@qq.com
 * @version 1.0
 * @date 2024/3/16 12:48
 */
@Service
@Slf4j
public class OcrDictionaryServiceImpl extends BaseServiceImpl<OcrDictionaryDao, OcrDictionary> implements OcrDictionaryService {

    @Autowired
    private OcrDictionaryGroupDao ocrDictionaryGroupDao;

    @Override
    public boolean isValueExists(Long groupId, String value, Long tenantId) {
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.eq("group_id",groupId);
        queryWrapper.eq("value",value);
        queryWrapper.eq("tenant_id",groupId);
        Long count = baseMapper.selectCount(queryWrapper);
        return count>0 ? false:true;
    }

    @Override
    public OcrDictionaryGroup queryGroupByField(String field) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("field",field);
        List<OcrDictionaryGroup> ocrDictionaryGroupList = ocrDictionaryGroupDao.selectList(queryWrapper);
        if(ocrDictionaryGroupList!=null && ocrDictionaryGroupList.size()>0){
            return ocrDictionaryGroupList.get(0);
        }
        return null;
    }
}
