package com.hotent.project.manager.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hotent.project.model.CostProjectProccessPersonnel;
import com.hotent.project.dao.CostProjectProccessPersonnelDao;
import com.hotent.project.manager.CostProjectProccessPersonnelManager;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.uc.exception.BaseException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.hotent.base.util.BeanUtils;


/**
 * 预置人员审核表 服务实现类
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-10-01
 */
@Service
public class CostProjectProccessPersonnelManagerImpl extends BaseManagerImpl<CostProjectProccessPersonnelDao, CostProjectProccessPersonnel> implements CostProjectProccessPersonnelManager {

	@Override
	public CostProjectProccessPersonnel getDetail(String id) {
    	CostProjectProccessPersonnel costProjectProccessPersonnel = this.get(id);
    	

		return costProjectProccessPersonnel;
	}
	@Override
	@Transactional
	public void createOrUpdate(CostProjectProccessPersonnel costProjectProccessPersonnel) {
		//新建或更新
		this.saveOrUpdate(costProjectProccessPersonnel);
	}

	@Override
	public Map<String, List<CostProjectProccessPersonnel>> getNodeListByProcessId(String processId) {
		List<CostProjectProccessPersonnel> nodeList = personnelList(processId);
		return nodeList.stream().collect(Collectors.groupingBy(CostProjectProccessPersonnel::getNodeId));
	}


	@Override
	public List<CostProjectProccessPersonnel> personnelList(String processId) {
		LambdaQueryWrapper<CostProjectProccessPersonnel> qw=new LambdaQueryWrapper<>();
		qw.eq(CostProjectProccessPersonnel::getProcessId,processId);
		List<CostProjectProccessPersonnel> nodeList = this.list(qw);
		if(ObjectUtil.isEmpty(nodeList)){
			throw new BaseException("流程节点不存在");
		}
		return nodeList;
	}
}
