package weaver.formmode.recruit.modeexpand.process;

import cn.hutool.core.convert.Convert;
import org.apache.commons.lang3.StringUtils;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2024/07/15
 * @version: 1.0
 */
public class DeleteFlowStageModeExpand extends AbstractModeExpandJavaCodeNew {
    @Override
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<>();
        try {
            String billId;
            RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
            if (requestInfo != null) {
                billId = requestInfo.getRequestid();
                MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
                Property[] properties = mainTableInfo.getProperty();
                Map<String, String> mainDataMap = new HashMap<>();
                for (Property property : properties) {
                    mainDataMap.put(property.getName(), property.getValue());
                }

                int flowId = Convert.toInt(mainDataMap.get("zplc"), -1);
                int hjId = Convert.toInt(mainDataMap.get("hj"), -1);

                // 开始阶段
                if (-1 != flowId && StringUtils.isNotBlank(billId)) {
                    // 更新流程表单的阶段ID
                    StageDataInsert.deleteFlowStageId(flowId, Convert.toInt(billId, -1), hjId);
                }
            }
        } catch (Exception e) {
            new BaseBean().writeLog(e);
            result.put("errmsg", e.getMessage());
            result.put("flag", "false");
        }
        return result;
    }
}
