package weaver.formmode.recruit.modeexpand.process;

import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.hrm.User;
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;

/**
 * <p>聚才林招聘</p>
 *
 * <p>招聘流程新建时，生成流程阶段关联数据</p>
 *
 * @author:dxfeng
 * @createTime: 2023/09/19
 * @version: 1.0
 */
public class RelatedStageModeExpand 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());
                }
                // 开始阶段
                String ksjd = mainDataMap.get("ksjd");
                // 过程阶段
                String gcjd = mainDataMap.get("gcjd");
                // 结束阶段
                String jsjd = mainDataMap.get("jsjd");
                // 查询所有的操作阶段信息
                User user = (User) param.get("user");
                StageDataInsert.relatedStageData(user.getUID(), billId, "zplc", ksjd, gcjd, jsjd);
            }
        } catch (Exception e) {
            new BaseBean().writeLog(e);
            result.put("errmsg", e.getMessage());
            result.put("flag", "false");
        }
        return result;
    }
}
