package com.bonus.material.approval.strategy.impl;

import com.bonus.material.approval.domain.ApprovalInstance;
import com.bonus.material.approval.strategy.IApprovalCallback;
import com.bonus.material.project.mapper.ProjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 项目录入审批回调
 *
 * @author syruan
 */
@Component("PROJECT_ADD")
public class ProjectApprovalCallback implements IApprovalCallback {

    private static final Logger log = LoggerFactory.getLogger(ProjectApprovalCallback.class);

    @Resource
    private ProjectMapper projectMapper;

    @Override
    public void onApproved(ApprovalInstance instance) {
        try {
            // 审批通过：更新项目状态为已通过
            String businessId = instance.getBusinessId();
            // projectMapper.updateApprovalStatus(Long.valueOf(businessId), "2");
            
            log.info("项目录入审批通过，项目ID：{}", businessId);
        } catch (Exception e) {
            log.error("项目录入审批通过回调失败", e);
        }
    }

    @Override
    public void onRejected(ApprovalInstance instance) {
        try {
            // 审批驳回：更新项目状态为已驳回
            String businessId = instance.getBusinessId();
            // projectMapper.updateApprovalStatus(Long.valueOf(businessId), "3");
            
            log.info("项目录入审批驳回，项目ID：{}", businessId);
        } catch (Exception e) {
            log.error("项目录入审批驳回回调失败", e);
        }
    }
}

