package com.engine.kq.cmd.shiftmanagement;

import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldUtil;
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.Util;
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 GetMessageRemindFormCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetMessageRemindFormCmd(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>();
        try {
            boolean canEdit = HrmUserVarify.checkUserRight("KQClass:Management", user);
            if (!canEdit) {
                resultMap.put("status", "-1");
                resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
                return resultMap;
            }

            String serialId = Util.null2String(params.get("serialId"));//班次ID

            List<Map<String, Object>> dataList = null;
            Map<String, Object> dataMap = null;

            String messageContent_signIn = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005295,weaver.general.ThreadVarLanguage.getLang())+"";
            String availableParams_signIn = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(18843,weaver.general.ThreadVarLanguage.getLang())+"";

            String messageContent_signOut = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005296,weaver.general.ThreadVarLanguage.getLang())+"";
            String availableParams_signOut = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005342,weaver.general.ThreadVarLanguage.getLang())+"";

            dataList = new ArrayList<Map<String, Object>>();
            dataMap = new HashMap<String, Object>();
            dataMap.put("id", "0");
            dataMap.put("radio", "1");
            dataMap.put("type", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(507835,weaver.general.ThreadVarLanguage.getLang())+"");
            dataMap.put("content", messageContent_signIn);
            dataMap.put("params", new String[]{availableParams_signIn});
            dataList.add(dataMap);

            dataMap = new HashMap<String, Object>();
            dataMap.put("id", "1");
            dataMap.put("radio", "0");
            dataMap.put("type", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(507837,weaver.general.ThreadVarLanguage.getLang())+"");
            dataMap.put("content", messageContent_signOut);
            dataMap.put("params", new String[]{availableParams_signOut});
            dataList.add(dataMap);

            resultMap.put("defaultDatas", dataList);
            resultMap.put("signInParams", new String[]{availableParams_signIn});
            resultMap.put("signOutParams", new String[]{availableParams_signOut});

            if (!"".equals(serialId)) {
                String sql = "select * from kq_messageRemindTemplate where serialId=?";
                RecordSet recordSet = new RecordSet();
                recordSet.executeQuery(sql, serialId);
                while (recordSet.next()) {
                    String signInOrSignOut = Util.null2String(recordSet.getString("signInOrSignOut"));
                    String messageContent = Util.null2String(recordSet.getString("messageContent"));

                    if (signInOrSignOut.equals("1")) {
                        messageContent_signIn = messageContent;
                    } else {
                        messageContent_signOut = messageContent;
                    }
                }
            }

            dataList = new ArrayList<Map<String, Object>>();
            dataMap = new HashMap<String, Object>();
            dataMap.put("id", "0");
            dataMap.put("radio", "1");
            dataMap.put("type", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(507835,weaver.general.ThreadVarLanguage.getLang())+"");
            dataMap.put("content", messageContent_signIn);
            dataMap.put("params", new String[]{availableParams_signIn});
            dataList.add(dataMap);

            dataMap = new HashMap<String, Object>();
            dataMap.put("id", "1");
            dataMap.put("radio", "0");
            dataMap.put("type", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(507837,weaver.general.ThreadVarLanguage.getLang())+"");
            dataMap.put("content", messageContent_signOut);
            dataMap.put("params", new String[]{availableParams_signOut});
            dataList.add(dataMap);

            resultMap.put("datas", dataList);
        } catch (Exception e) {
            resultMap.put("status", "-1");
            resultMap.put("message", e.getMessage());
        }
        return resultMap;
    }
}
