package com.mortals.xhx.common.utils;

import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.util.AESUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Set;

@Slf4j
public class MenuEncodeUtil {

    public static String generateMenuUrlCode(Set<String> urls) {
        try {
            String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
            StringBuilder sb = new StringBuilder();
            if (urls != null && urls.size() > 0) {
                for (String url : urls) {
                    int index = url.hashCode() & (Integer.MAX_VALUE - 1);
                    sb.append(index).append(",");
                }
            }
            String menuUrl = sb.toString();
            return AESUtil.encrypt(menuUrl, securityKey);
        } catch (Throwable e) {
            log.error("编码异常",e);
            return null;
        }
    }
}
