package com.zkqy.execution.produce.dispersed.service.impl.runbpm.nuts;

import com.alibaba.fastjson2.JSONObject;
import com.zkqy.common.config.bpm.BpmProperties;
import com.zkqy.common.core.domain.AjaxResult;
import com.zkqy.common.utils.http.Sending;
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.utils.EchoNodeFormData;
import com.zkqy.system.entity.CommonEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

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

/**
 * @author hmc
 * @date 2023-12-06 18:23
 * @Description:
 */

@Service("69d7ed88-5790-4c04-a556-18f46d0f2b60")
@Scope("prototype")
public class GodownEntryImpl implements IRunBPMService {

    @Autowired
    private Sending sending;

    @Autowired
    private BpmProperties bpmProperties;

    @Autowired
    private EchoNodeFormData echoNodeFormData;

    @Override
    public CommonEntity getNodeFormData(BpmRunNodeFromVo bpmRunNodeFromVo) {
        //1、查询计划表信息
        //选择货品 list，当前表单中有个选择货品的下拉框
        Map<String, Object> map = new HashMap<>();
        map.put("del_flag", 0);
        // 查询材料信息(下拉框)
        BpmRunNodeFormFilterConditionsVo bpmRunNodeFormFilterConditionsVo2 = new BpmRunNodeFormFilterConditionsVo();
        bpmRunNodeFormFilterConditionsVo2.setNodeOnlyData(false);
        bpmRunNodeFormFilterConditionsVo2.setCondition(map);
        bpmRunNodeFormFilterConditionsVo2.setListKey("caiLiao");
        bpmRunNodeFormFilterConditionsVo2.setTableName("materials");
        bpmRunNodeFromVo.getFormDataVoList().add(bpmRunNodeFormFilterConditionsVo2);
        // 查询工艺信息（下拉框）
        BpmRunNodeFormFilterConditionsVo bpmRunNodeFormFilterConditionsVo3 = new BpmRunNodeFormFilterConditionsVo();
        bpmRunNodeFormFilterConditionsVo3.setNodeOnlyData(false);
        bpmRunNodeFormFilterConditionsVo3.setCondition(map);
        bpmRunNodeFormFilterConditionsVo3.setListKey("gongyi");
        bpmRunNodeFormFilterConditionsVo3.setTableName("production_process");
        bpmRunNodeFromVo.getFormDataVoList().add(bpmRunNodeFormFilterConditionsVo3);
        return echoNodeFormData.getEchoNodeFormData(bpmRunNodeFromVo);
    }

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

    /**
     * 节点执行流程
     *
     * @param iRunBPMEntity 节点执行参数
     * @return
     */
    @Override
    public AjaxResult executeNode(IRunBPMEntity iRunBPMEntity) {
        CommonEntity commonEntity = new CommonEntity();
        //commonEntity.getConditionMap().put("id", iRunBPMEntity.getExecutionMap().get("taskPlanKey"));
        //commonEntity.getBasicMap().put("tableName", iRunBPMEntity.getTableName());
        //iRunBPMEntity.getExecutionMap().remove("taskPlanKey");
        //commonEntity.getCommMap().putAll(iRunBPMEntity.getExecutionMap());
        //// 发送修改请求
        //sending.sendCommonUpdate(commonEntity);
        return AjaxResult.success();
    }

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

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

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