package com.hz.pm.api.portrait.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.pm.api.portrait.mapper.ProjectTagMapper;
import com.hz.pm.api.portrait.model.entity.ProjectTag;
import com.hz.pm.api.portrait.model.entity.Tag;
import com.hz.pm.api.portrait.service.IProjectTagService;
import com.hz.pm.api.portrait.service.ITagService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * </p>
 *
 * @author ZPF
 * @since 2023-08-2
 */
@Service
@RequiredArgsConstructor
public class ProjectTagServiceImpl extends ServiceImpl<ProjectTagMapper,
        ProjectTag> implements IProjectTagService {

    private final ITagService tagService;

    /**
     * 获取项目标签
     * @param projectCode
     * @return
     */
    @Override
    public List<Tag> getProjectTas(String projectCode) {
        List<ProjectTag> proTags = this.list(Wrappers.lambdaQuery(ProjectTag.class)
                .eq(ProjectTag::getProjectCode, projectCode));
        if(CollUtil.isEmpty(proTags)){
            return Collections.emptyList();
        }
        List<Long> tagIds = proTags.stream().map(ProjectTag::getTagId).collect(Collectors.toList());
        return tagService.listByIds(tagIds);
    }
}
