package com.engine.kq.cmd.overtimerules;

import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.PageIdConst;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

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

/**
 * 加班规则--获取加班规则列表
 */
public class GetSearchListCmd extends AbstractCommonCommand<Map<String, Object>> {

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

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = new HashMap<String, Object>();

        boolean canEdit = HrmUserVarify.checkUserRight("KQOvertimeRulesEdit:Edit", user);//是否具有编辑的权限;
        boolean canDelete = HrmUserVarify.checkUserRight("KQOvertimeRulesDelete:Delete", user);//是否具有删除的权限;
        boolean canLog = HrmUserVarify.checkUserRight("KQOvertimeRules:Log", user);//是否具有查看日志的权限;

        String backFields = " id,name,shiftIds ";
        String sqlFrom = " from kq_OvertimeRules ";
        String sqlWhere = " where 1=1 and (isDelete is null or isDelete!=1) ";
        String orderBy = " id ";
        String pageUid = "1b3ad739-67fa-8b1e-1c19-6d37c1a33469";
        String operateString = "";
        operateString = "<operates width=\"20%\">";
        operateString += "<popedom transmethod=\"weaver.hrm.common.SplitPageTagOperate.getBasicOperate\" otherpara=\"" + canEdit + ":" + canDelete + ":" + canLog + "\"></popedom> ";
        operateString += "  <operate href=\"javascript:openDialog();\"  text=\"" + SystemEnv.getHtmlLabelName(93, user.getLanguage()) + "\" index=\"0\"/>";
        operateString += "  <operate href=\"javascript:doDel()\"    text=\"" + SystemEnv.getHtmlLabelName(91, user.getLanguage()) + "\"  index=\"1\"/>";
        operateString += "  <operate href=\"javascript:onLog()\"    text=\"" + SystemEnv.getHtmlLabelName(83, user.getLanguage()) + "\"  index=\"2\"/>";
        operateString += "</operates>";
        String tableString = "" +
                "<table pageId=\"Hrm:OvertimeRules\" pageUid=\"" + pageUid + "\" tabletype=\"checkbox\" pagesize=\"" + PageIdConst.getPageSize("Hrm:OvertimeRules", user.getUID(), PageIdConst.HRM) + "\" >" +
                "   <sql backfields=\"" + backFields + "\" sqlform=\"" + sqlFrom + "\" sqlwhere=\"" + Util.toHtmlForSplitPage(sqlWhere) + "\"  sqlorderby=\"" + orderBy + "\"  sqlprimarykey=\"id\" sqlsortway=\"asc\" sqlisdistinct=\"false\"/>"
                + operateString +
                "   <head>" +
                "       <col width=\"25%\" text=\"" + SystemEnv.getHtmlLabelName(388831, user.getLanguage()) + "\" column=\"name\" transmethod=\"weaver.general.Util.formatMultiLang\" otherpara=\"" + user.getLanguage() + "\"  orderkey=\"name\"/>" +
                "       <col width=\"40%\" text=\"" + SystemEnv.getHtmlLabelName(388832, user.getLanguage()) + "\" column=\"id\" transmethod=\"com.engine.kq.util.KQTransMethod.getRuleContent\" otherpara=\"" + user.getLanguage() + "\"/>" +
                "       <col width=\"25%\" text=\"" + SystemEnv.getHtmlLabelName(19374, user.getLanguage()) + "\" column=\"shiftIds\" transmethod=\"com.engine.kq.util.KQTransMethod.getShiftName\" otherpara=\"" + user.getLanguage() + "\" />" +
                "   </head>" +
                "</table>";
        String sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom());
        Util_TableMap.setVal(sessionKey, tableString);
        resultMap.put("sessionkey", sessionKey);
        return resultMap;
    }
}
