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.AfterAdvicePlugin;
import com.jeelowcode.core.framework.controller.BaseController;
import com.jeelowcode.framework.utils.tool.NumberUtil;
import com.jeelowcode.module.biz.service.IPortalTodoService;
import com.jeelowcode.module.biz.service.IWorkItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * 删除前校验
 */
@Slf4j
@Component("afterItemResultCreateEnhance")
public class AfterItemResultCreateEnhance extends BaseController implements AfterAdvicePlugin {

    @Autowired
    private IWorkItemService workItemService;

    private static AfterItemResultCreateEnhance 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("workItemId")){
            return;
        }

        Long id = NumberUtil.toLong(params.get("id").toString());
        Long workItemId = NumberUtil.toLong(params.get("workItemId").toString());

        // 发送代办消息
        ADTE.workItemService.pushTodoWorkItemWorkflow(workItemId,id,"WORK_ITEM_TODO");
    }
}
