package com.zkqy.execution.produce.dispersed.service.templateimpl;


import com.zkqy.common.core.domain.AjaxResult;
import com.zkqy.execution.produce.dispersed.entity.runbpm.BpmRunNodeFormFilterConditionsVo;
import com.zkqy.execution.produce.dispersed.entity.runbpm.BpmRunNodeFromVo;
import com.zkqy.execution.produce.dispersed.entity.runbpm.IRunBPMEntity;
import com.zkqy.execution.produce.dispersed.service.IRunBPMService;
import com.zkqy.execution.produce.dispersed.service.IBpmExecuteNodeService;
import com.zkqy.execution.produce.utils.EchoNodeFormData;
import com.zkqy.system.entity.CommonEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hanzihang
 * @date 2023/11/3
 * <p>
 * 当前bean名称必填项！
 * {
 * @AliasFor(annotation = Component.class)
 * String value() default "";
 * }
 * <p>
 * 使用 @Scope("prototype") 注解指定了 bean 的作用域为 prototype。
 * 这样，在每次通过 applicationContext.getBean()
 * 获取该 bean 的实例时，都会返回一个新的实例。从而避免并发的的操作
 * spring不会清理prototype作用域的bean。
 */
@Service("RunBPMImpl")
@Scope("prototype")
public class RunBPMImpl implements IRunBPMService {

    @Autowired
    private IBpmExecuteNodeService bpmExecuteNodeService;

    @Autowired
    private EchoNodeFormData echoNodeFormData;

    /**
     * 当前节点表单的回显数据
     *
     * @param bpmRunNodeFromVo
     * @return
     */
    @Override
    public CommonEntity getNodeFormData(BpmRunNodeFromVo bpmRunNodeFromVo) {
        BpmRunNodeFromVo bpmRunNodeFromVo1 = new BpmRunNodeFromVo();
        // 选择货品 list，当前表单中有个选择货品的下拉框
        Map<String, Object> map = new HashMap<>();
        map.put("isdelete", 0);
        map.put("type", 2);
        bpmRunNodeFromVo.getFormDataVoList().add(new BpmRunNodeFormFilterConditionsVo("goods", map, false, "goodsList"));
        return echoNodeFormData.getEchoNodeFormData(bpmRunNodeFromVo1);
    }

    /**
     * 前置验证节点
     *
     * @param iRunBPMEntity 节点执行参数
     * @return
     */
    @Override
    public AjaxResult preValidation(IRunBPMEntity iRunBPMEntity) {
        return AjaxResult.success();
    }

    /**
     * 节点执行流程
     *
     * @param iRunBPMEntity 节点执行参数
     * @return
     */
    @Override
    public AjaxResult executeNode(IRunBPMEntity iRunBPMEntity) {
        return null;
    }

    /**
     * 后置验证节点
     *
     * @param iRunBPMEntity 节点执行参数
     */
    @Override
    public AjaxResult afterValidation(IRunBPMEntity iRunBPMEntity) {
        return null;
    }

    /**
     * 需要手动修改返回为true！当前实现类中不得写逻辑代码！
     * 此操作只为验证当前实现类是否存在！
     *
     * @return
     */
    @Override
    public boolean isVerificationMethod() {
        return true;
    }

    /**
     * * @PreDestroy 注解用来清理当前bean。
     * spring不会清理prototype作用域的bean。
     *
     * @return
     */
    @Override
    @PreDestroy
    public boolean preDestroy() {
        // 执行清理操作
        System.err.print("清理成功！");
        return true;
    }
}
