package com.zkqy.execution.produce.dispersed.service.impl.runbpm.hangye1.testNode;

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.mapper.BpmExecuteProcessMapper;
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.stereotype.Service;

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

/**
 * @author hanzihang
 * <p>
 * 生产人员操作节点。
 * @date 2023/12/1
 */
@Service("11f4951b-682f-4185-acb7-f4b8db9d5940")
@Scope("prototype")
public class SandProductionImpl implements IRunBPMService {

    @Autowired // 下发Form
    private Sending sending;

    @Autowired // 执行流程
    private BpmExecuteProcessMapper runBpmExecuteProcessMapper;

    @Autowired
    private EchoNodeFormData echoNodeFormData;

    @Override
    public CommonEntity getNodeFormData(BpmRunNodeFromVo 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(bpmRunNodeFromVo);
    }








    @Override
    public AjaxResult preValidation(IRunBPMEntity iRunBPMEntity) {
        return AjaxResult.success();
    }

    @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 null;
    }

    @Override
    public AjaxResult afterValidation(IRunBPMEntity iRunBPMEntity) {
        return null;
    }

    @Override
    public boolean isVerificationMethod() {
        return true;
    }

    @Override
    @PreDestroy
    public boolean preDestroy() {
        System.err.println("清理成功！");
        return true;
    }
}
