package com.engine.kq.cmd.leaverules;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

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

/**
 * @Auther: Administrator
 * @Date: 2019-03-13 17:21
 * @Description:
 */
public class GetUnitNameCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetUnitNameCmd(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{
            /*假期类型的ID(数据库表kq_leaveRules表的主键ID)*/
            String ruleId = Util.null2String(params.get("typeId"));

            KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo();

            /*最小请假单位：1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假*/
            int minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(ruleId));

            String unitName = "";//单位名称，天/小时
            if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
                unitName = SystemEnv.getHtmlLabelName(1925, user.getLanguage());//天
            } else {
                unitName = SystemEnv.getHtmlLabelName(391, user.getLanguage());//小时
            }

            resultMap.put("unitName",unitName);
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultMap;
    }
}
