package com.hotwj.platform.securityManagement.violationInfo.callback;

import com.hotwj.platform.flow.callback.IFlowCallback;
import com.hotwj.platform.securityManagement.violationInfo.domain.HotViolationInfo;
import com.hotwj.platform.securityManagement.violationInfo.mapper.HotViolationInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ViolationHandleCallback implements IFlowCallback {

    private final HotViolationInfoMapper violationInfoMapper;

    public ViolationHandleCallback(HotViolationInfoMapper violationInfoMapper) {
        this.violationInfoMapper = violationInfoMapper;
    }

    @Override
    public String getFlowCode() {
        return "VIOLATION_HANDLE";
    }

    @Override
    public void onProcessEnd(String instanceId, String businessId, String flowCode, boolean success) {
        Long id = Long.parseLong(businessId);
        HotViolationInfo info = violationInfoMapper.selectById(id);
        if (info == null) {
            return;
        }
        if (success) {
            info.setProcessStatus(2L);
        } else {
            if (info.getProcessStatus() == null || info.getProcessStatus() == 2L) {
                info.setProcessStatus(1L);
            }
        }
        violationInfoMapper.updateById(info);
        log.info("违规处理流程结束回调: businessId={}, success={}, instanceId={}", businessId, success, instanceId);
    }
}
