package com.engine.kq.cmd.reportfielddefine;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQReportFieldGroupComInfo;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetFieldDefineTabsCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetFieldDefineTabsCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        HashMap retmap = new HashMap();
        try {
            if (!HrmUserVarify.checkUserRight("KQReportFieldDefine:Add", user)) {
                retmap.put("status", "-1");
                retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
                return retmap;
            }

            List<Map<String, Object>> tabs = new ArrayList();
            Map<String, Object> tab = null;
            KQReportFieldGroupComInfo kqReportFieldGroupComInfo = new KQReportFieldGroupComInfo();
            while(kqReportFieldGroupComInfo.next()){
                if(!kqReportFieldGroupComInfo.getIsshow().equals("1"))continue;
                tab = new HashMap();
                tab.put("key", kqReportFieldGroupComInfo.getId());
                tab.put("title", kqReportFieldGroupComInfo.getGroupname());
                tab.put("editable", true);
                tabs.add(tab);
            }
            tab = new HashMap();
            tab.put("key", "other");
            tab.put("title", SystemEnv.getHtmlLabelName(81307, this.user.getLanguage()));
            tabs.add(tab);
            retmap.put("status", "1");
            retmap.put("tabs", tabs);
        } catch (Exception e) {
            this.writeLog(e);
            retmap.put("status", "-1");
            retmap.put("message", SystemEnv.getHtmlLabelName(382661, this.user.getLanguage()));
        }
        return retmap;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

}
