package com.customization.shuzhi;

import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.hrm.cmd.jobset.GetJobTitleListCmd;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import weaver.general.Util;

import java.util.List;
import java.util.Map;

/**
 * 岗位列表表头信息调整
 *
 * @author:dxfeng
 * @createTime: 2023/04/26
 * @version: 1.0
 */
@CommandDynamicProxy(target = GetJobTitleListCmd.class, desc = "调整表头信息")
public class SzGetJobTitleListCmd extends AbstractCommandProxy<Map<String, Object>> {
    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
        Map<String, Object> result = (Map)this.nextExecute(targetCommand);
        String sessionKey = Util.null2String(result.get("sessionkey"));
        String tableString = Util_TableMap.getVal(sessionKey);
        tableString = tableString.replace("岗位简称", "岗位名称").replace("岗位全称", "职级名称").replace("所属职务", "职级代码").replace("职务类别", "序列");

        try {
            Document document = DocumentHelper.parseText(tableString);
            Element rootElement = document.getRootElement();
            Element head = rootElement.element("head");
            List colList = head.elements();
            Element col = DocumentHelper.createElement("col");
            col.addAttribute("width", "20%");
            col.addAttribute("text", "标识");
            col.addAttribute("column", "id");
            col.addAttribute("orderkey", "id");
            colList.add(0, col);
            tableString = document.asXML();
        } catch (Exception var10) {
            var10.getMessage();
        }

        Util_TableMap.setVal(sessionKey, tableString);
        return result;
    }
}
