package com.hotent.project.manager.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hotent.base.exception.BaseException;
import com.hotent.project.model.CostProjectTaskLog;
import com.hotent.project.dao.CostProjectTaskLogDao;
import com.hotent.project.manager.CostProjectTaskLogManager;
import com.hotent.base.manager.impl.BaseManagerImpl;
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;


/**
 * 项目任务日志表 服务实现类
 *
 * @author 超级管理员
 * @company 山西清众科技股份有限公司
 * @since 2025-10-03
 */
@Service
public class CostProjectTaskLogManagerImpl extends BaseManagerImpl<CostProjectTaskLogDao, CostProjectTaskLog> implements CostProjectTaskLogManager {

    @Override
    public CostProjectTaskLog getDetail(String id) {
        CostProjectTaskLog costProjectTaskLog = this.get(id);


        return costProjectTaskLog;
    }

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

    @Override
    public Map<String, List<CostProjectTaskLog>> getListByProjectId(String projectId) {
        LambdaQueryWrapper<CostProjectTaskLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CostProjectTaskLog::getProjectId, projectId);
        List<CostProjectTaskLog> list = this.list(queryWrapper);
        if (ObjectUtil.isEmpty(list)) {
            throw new BaseException("没有找到项目任务日志数据");
        }
        return list.stream().collect(Collectors.groupingBy(CostProjectTaskLog::getAuditedUnitId));
    }
}
