package com.lantone.daqe.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lantone.common.enums.IsDeleteEnum;
import com.lantone.common.util.BeanUtil;
import com.lantone.common.util.StringUtil;
import com.lantone.daqe.dto.GetConceptLibraryPageDTO;
import com.lantone.daqe.entity.ConceptLibrary;
import com.lantone.daqe.enums.ConceptLibraryTypeEnum;
import com.lantone.daqe.facade.base.ConceptLibraryFacade;
import com.lantone.daqe.vo.GetConceptLibraryPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 通用处理API-业务处理类
 * @author： rengb
 * @time: 2022/3/1 10:14
 */
@Component
public class CurrencyManagementFacade {

    @Autowired
    private ConceptLibraryFacade conceptLibraryFacade;

    public IPage<GetConceptLibraryPageDTO> getConceptLibraryPage(GetConceptLibraryPageVO getConceptLibraryPageVO) {
        IPage<GetConceptLibraryPageDTO> getConceptLibraryPageDTOIPage = new Page<>();

        QueryWrapper<ConceptLibrary> conceptLibraryQueryWrapper = new QueryWrapper<>();
        conceptLibraryQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        conceptLibraryQueryWrapper.eq("type", getConceptLibraryPageVO.getType());
        conceptLibraryQueryWrapper.like(StringUtil.isNotBlank(getConceptLibraryPageVO.getWord()), "synonym", getConceptLibraryPageVO.getWord());

        Page<ConceptLibrary> conceptLibraryIPage = new Page<>(getConceptLibraryPageVO.getCurrent(), getConceptLibraryPageVO.getSize());
        conceptLibraryFacade.page(conceptLibraryIPage, conceptLibraryQueryWrapper);
        BeanUtil.copyProperties(conceptLibraryIPage, getConceptLibraryPageDTOIPage);

        List<GetConceptLibraryPageDTO> getConceptLibraryPageDTOList = BeanUtil.listCopyTo(conceptLibraryIPage.getRecords(), GetConceptLibraryPageDTO.class);
        getConceptLibraryPageDTOList.forEach(i -> {
            i.setType(ConceptLibraryTypeEnum.getName(i.getType()));
        });
        getConceptLibraryPageDTOIPage.setRecords(getConceptLibraryPageDTOList);
        return getConceptLibraryPageDTOIPage;
    }

}