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.tool.mapper.ToolMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 工具录入审批回调
 *
 * @author bonus
 * @date 2024-11-18
 */
@Component("TOOL_ADD")
public class ToolApprovalCallback implements IApprovalCallback {

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

    @Resource
    private ToolMapper toolMapper;

    @Override
    public void onApproved(ApprovalInstance instance) {
        try {
            // 审批通过：更新工具状态为已通过
            String businessId = instance.getBusinessId();
            // 这里假设工具表有approval_status字段
            // toolMapper.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();
            // toolMapper.updateApprovalStatus(Long.valueOf(businessId), "3");
            
            log.info("工具录入审批驳回，工具ID：{}", businessId);
        } catch (Exception e) {
            log.error("工具录入审批驳回回调失败", e);
        }
    }
}

