package digital.laboratory.platform.reagent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import digital.laboratory.platform.reagent.entity.CategoryTable;
import digital.laboratory.platform.reagent.mapper.CategoryTableMapper;
import digital.laboratory.platform.reagent.service.CategoryTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author Zhang Xiaolong created at  2023-03-29
 * @describe  服务实现类
 */
@Service
@SuppressWarnings("all")
public class CategoryTableServiceImpl extends ServiceImpl<CategoryTableMapper, CategoryTable> implements CategoryTableService {

    @Autowired
    private CategoryTableService categoryTableService;

    @Override
    public CategoryTable addSpecies(String category, String species){

        LambdaQueryWrapper<CategoryTable> categoryTableLambdaQueryWrapper = new LambdaQueryWrapper<>();

        categoryTableLambdaQueryWrapper.eq(CategoryTable::getSpecies,species);

        categoryTableLambdaQueryWrapper.eq(CategoryTable::getCategory,category);

        CategoryTable one = categoryTableService.getOne(categoryTableLambdaQueryWrapper);

        if (one==null){

        CategoryTable categoryTable = new CategoryTable();

        categoryTable.setId(IdWorker.get32UUID().toUpperCase());

        categoryTable.setSpecies(species);

        categoryTable.setCategory(category);

        categoryTableService.save(categoryTable);

        return categoryTable;
        }
        return one;
    }



    @Override
    public Boolean delSpeciesById(String categoryTableId){

        CategoryTable byId = categoryTableService.getById(categoryTableId);

        return categoryTableService.removeById(byId);
    }

    @Override
    public List<CategoryTable> getSpecies(String category){

        LambdaQueryWrapper<CategoryTable> typeTableLambdaQueryWrapper = new LambdaQueryWrapper<>();

        typeTableLambdaQueryWrapper.eq(CategoryTable::getCategory,category);

        List<CategoryTable> list = categoryTableService.list(typeTableLambdaQueryWrapper);

        return list;
    }

}
