package com.hotent.project.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hotent.constant.BaseConstant;
import com.hotent.project.dao.CostProjectTaskPreliminaryOpinionDao;
import com.hotent.project.manager.CostProjectTaskPreliminaryOpinionManager;
import com.hotent.project.model.CostProjectTaskPreliminaryOpinion;
import com.hotent.base.manager.impl.BaseManagerImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 成本审核意见表 服务实现类（包含初步意见、反馈意见、结论意见）
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-01-27
 */
@Service
public class CostProjectTaskPreliminaryOpinionManagerImpl extends BaseManagerImpl<CostProjectTaskPreliminaryOpinionDao, CostProjectTaskPreliminaryOpinion> implements CostProjectTaskPreliminaryOpinionManager {

    @Override
    public CostProjectTaskPreliminaryOpinion getDetail(String id) {
        CostProjectTaskPreliminaryOpinion opinion = this.get(id);
        return opinion;
    }

    @Override
    public CostProjectTaskPreliminaryOpinion getByTaskId(String taskId) {
        LambdaQueryWrapper<CostProjectTaskPreliminaryOpinion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CostProjectTaskPreliminaryOpinion::getTaskId, taskId)
                   .eq(CostProjectTaskPreliminaryOpinion::getIsDeleted, BaseConstant.NORMAL_STATUS)
                   .last("LIMIT 1");

        return this.getOne(queryWrapper);
    }

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

