package com.engine.kq.cmd.holidaySet;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType4Hrm;
import com.engine.common.constant.BizLogType;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.biz.KQHolidaySetBiz;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

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

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

    private SimpleBizLogger logger;

    public InitHolidaySetCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
        this.logger = new SimpleBizLogger();

        String groupId = Util.null2String(params.get("groupId"));//考勤组的ID
        BizLogContext bizLogContext = new BizLogContext();
        bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型
        bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_HOLIDAYSET);//所属大类型
        bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQ_HOLIDAYSET);//当前小类型
        bizLogContext.setParams(params);//当前request请求参数
        logger.setUser(user);//当前操作人
        String mainSql = "select * from kq_HolidaySet where groupId=" + groupId;
        logger.setMainSql(mainSql, "id");//主表sql
        logger.setMainPrimarykey("id");//主日志表唯一key
        logger.setMainTargetNameMethod("com.engine.kq.util.KQTransMethod.getTargetName4HolidaySet","column:groupId+column:holidayDate+"+user.getLanguage());//当前targetName对应的列（对应日志中的对象名）
        logger.before(bizLogContext);
    }

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

    @Override
    public List<BizLogContext> getLogContexts() {
        return logger.getBizLogContexts();
    }

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

        String groupId = Util.null2String(params.get("groupId"));//考勤组的ID
        String currentYear = Util.null2String(params.get("currentYear"));//年份
        try {
            /**
             * 调用初始化考勤组节假日的接口(只初始化公众假日，调配休息日和调配工作日需要单个维护)
             * 返回的数据格式：
             * status： 0-初始化失败、1-初始化成功
             * sketch： '简述'
             * description[
             * 	'详细说明1',
             * 	'详细说明2', ……
             * 	'详细说明N'
             * ]
             */
            Map<String, Object> tempMap = KQHolidaySetBiz.initHolidaySet(groupId, currentYear,user);
            if ("0".equals((String) tempMap.get("status"))) {
                resultMap.put("status", "-1");
                resultMap.put("message", tempMap.get("sketch"));
            } else {
                resultMap.put("status", "1");
                resultMap.put("message", SystemEnv.getHtmlLabelName(20196, user.getLanguage()));
            }
        } catch (Exception e) {
            writeLog(e);
            resultMap.put("status", "-1");
            resultMap.put("message", SystemEnv.getHtmlLabelName(125960, user.getLanguage()));
        }
        return resultMap;
    }
}
