package com.jeelowcode.module.biz.enhance;

import cn.hutool.json.JSONUtil;
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
import com.jeelowcode.core.framework.controller.BaseController;
import com.jeelowcode.core.framework.service.IFormService;
import com.jeelowcode.framework.utils.tool.NumberUtil;
import com.jeelowcode.module.biz.service.IDrillPlanService;
import com.jeelowcode.module.biz.service.IPortalTodoService;
import com.jeelowcode.tool.framework.common.pojo.CommonResult;
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("afterRiskHazardEditEnhance")
public class AfterRiskHazardEditEnhance extends BaseController implements AfterAdvicePlugin {

    @Autowired
    private IPortalTodoService portalTodoService;

    private static AfterRiskHazardEditEnhance ADTE;

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

    @Override
    public void execute(EnhanceContext enhanceContext) {

        Map<String, Object> params = enhanceContext.getParam().getParams();
        if(!params.containsKey("id")){
            return;
        }

        if(!params.containsKey("RiskNotifyEnum")){
            return;
        }

        Long id = NumberUtil.toLong(params.get("id").toString());
        String todoType=params.get("RiskNotifyEnum").toString();

        if(todoType.equals("CONFIRM_DONE"))
        {
            ADTE.portalTodoService.pushDoneRiskHazardWorkflow(id, todoType);
        }else if(todoType.equals("CONFIRM_TODO"))
        {
            ADTE.portalTodoService.pushDoneRiskHazardWorkflow(id, "CHARGE_DONE");
            ADTE.portalTodoService.pushDoneRiskHazardWorkflow(id, todoType);
        }
    }
}
