package com.lantone.facade.med;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.util.StringUtil;
import com.google.common.collect.Lists;
import com.lantone.dto.med.TermConceptDTO;
import com.lantone.entity.med.KlLibraryInfo;
import com.lantone.vo.med.TermMatchingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wangfeng
 * @Description:
 * @date 2021-06-10 19:48
 */
@Component
public class TermMatchingFacade {

    @Autowired
    private KlLibraryInfoFacade klLibraryInfoFacade;

    public List<TermConceptDTO> getTermMatchingAll(TermMatchingVO termMatchingVO) {
        List<TermConceptDTO> ret = Lists.newArrayList();
        QueryWrapper<KlLibraryInfo> klLibraryInfoQueryWrapper = new QueryWrapper<>();
        klLibraryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        klLibraryInfoQueryWrapper.eq(termMatchingVO.getType() != null, "type_id", termMatchingVO.getType());
        klLibraryInfoQueryWrapper.like(StringUtil.isNotBlank(termMatchingVO.getInputStr()), "name", termMatchingVO.getInputStr());
        List<KlLibraryInfo> klLibraryInfoList = klLibraryInfoFacade.list(klLibraryInfoQueryWrapper);
        klLibraryInfoList.forEach(i -> {
            TermConceptDTO termConceptDTO = new TermConceptDTO();
            termConceptDTO.setId(i.getConceptId());
            termConceptDTO.setName(i.getName());
            termConceptDTO.setSource(i.getIsConcept() == 1 ? 1 : 2);
            ret.add(termConceptDTO);
        });
        return ret;
    }

}
