package com.jeelowcode.module.biz.enhance;

import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.BeforeAdvicePlugin;
import com.jeelowcode.core.framework.config.btncommand.ButtonInvoker;
import com.jeelowcode.core.framework.config.btncommand.button.DetailsButtonCommand;
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamDetail;
import com.jeelowcode.core.framework.config.btncommand.receiver.ButtonReceiverDetail;
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.framework.exception.JeeLowCodeException;
import com.jeelowcode.framework.plus.core.toolkit.CollectionUtils;
import com.jeelowcode.framework.plus.core.toolkit.StringUtils;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.framework.utils.tool.NumberUtil;
import com.jeelowcode.module.biz.service.IPortalTodoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 删除前校验
 */
@Slf4j
@Component("afterRiskHazardDeleteEnhance")
public class AfterRiskHazardDeleteEnhance implements BeforeAdvicePlugin {

    @Autowired
    private IPortalTodoService portalTodoService;

    private static AfterRiskHazardDeleteEnhance ADTE;

    @PostConstruct
    public void init(){
        ADTE = this;
    }

    @Override
    public void execute(EnhanceContext enhanceContext) {
        Map<String, Object> params = enhanceContext.getParam().getParams();
        // 单条删除和批量删除的数据的id都是在dateIdList中
        Object dateIdList = params.get("dataIdList");
        if (Func.isEmpty(dateIdList)) {
            return;
        }
        List<Long> riskIdList = (List<Long>) dateIdList;
       for (Long riskId : riskIdList) {
           ADTE.portalTodoService.pushCancelRiskHazardWorkflow(riskId);
       }
    }
}
