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 weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;

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

/**
 * 假期余额--判断名称是否重复
 */
public class IsNameRepeatCmd extends AbstractCommonCommand<Map<String, Object>> {

    public IsNameRepeatCmd(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>();

        /*假期规则ID*/
        String ruleDetailId = Util.null2String(params.get("ruleId"));
        /*假期规则名称*/
        String ruleName = Util.null2String(params.get("ruleName"));

        boolean isRepeat = false;//名称是否重复了
        RecordSet recordSet = new RecordSet();
        String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete!=1) and ruleName='" + ruleName + "' ";
        if (!ruleDetailId.equals("")) {
            sql += " and id not in (" + ruleDetailId + ")";
        }
        recordSet.executeQuery(sql);
        if (recordSet.next()) {
            isRepeat = true;
        }
        resultMap.put("isRepeat", isRepeat);
        return resultMap;
    }
}
