package com.hotent.project.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotent.project.manager.CostProjectTaskManager;
import com.hotent.project.model.CostProjectTask;
import com.hotent.project.model.CostProjectTaskEvidence;
import com.hotent.project.dao.CostProjectTaskEvidenceDao;
import com.hotent.project.manager.CostProjectTaskEvidenceManager;
import com.hotent.base.manager.impl.BaseManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 子任务资料登记表 服务实现类
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-01-27
 */
@Service
public class CostProjectTaskEvidenceManagerImpl extends BaseManagerImpl<CostProjectTaskEvidenceDao, CostProjectTaskEvidence> implements CostProjectTaskEvidenceManager {

    @Autowired
    private CostProjectTaskManager costProjectTaskManager;


    @Override
    @Transactional
    public void createOrUpdate(CostProjectTaskEvidence costProjectTaskEvidence) {
        //新建或更新
        this.saveOrUpdate(costProjectTaskEvidence);
    }

    @Override
    public List<CostProjectTaskEvidence> findEvidenceListByTaskIds(String projectId, String enterpriseId) {
         List<CostProjectTask> tasks= costProjectTaskManager.findTaskByProjectId(projectId,enterpriseId);
        QueryWrapper<CostProjectTaskEvidence> wrapper = new QueryWrapper<>();
        List<String> collect = tasks.stream().map(CostProjectTask::getId).collect(Collectors.toList());
        if (!collect.isEmpty()) {
            wrapper.in("task_id",collect);
            return this.list(wrapper);
        }
        return Collections.emptyList();
    }
}
