// Path: common/src/main/java/net/myscloud/open/yuna/common/kits/CollectionKits.java
// public class CollectionKits {
// 
//     public static boolean isEmpty(Collection<?> collection) {
//         return collection == null || collection.isEmpty();
//     }
// 
//     public static boolean isNotEmpty(Collection<?> collection) {
//         return !isEmpty(collection);
//     }
// 
//     public static boolean isEmpty(Map<?, ?> map) {
//         return map == null || map.isEmpty();
//     }
// 
//     public static boolean isNotEmpty(Map<?, ?> map) {
//         return !isEmpty(map);
//     }
// 
//     private CollectionKits() {
//     }
// }
// 
// Path: client/src/main/java/net/myscloud/open/yuna/consts/YunaConsts.java
// public interface YunaConsts {
//     //session attrs
//     String SESSION_USER = "session_user";
//     String SESSION_BUSINESS_SYSTEM_CODE_MAP = "session_business_system_code_map";
//     String SESSION_BUSINESS_SYSTEMS = "session_business_systems";
//     String SESSION_CURRENT_BUSINESS_SYSTEM = "session_current_business_system";
//     String CURRENT_PERMISSIONS = "current_permissions";
// }
// 
// Path: domain/src/main/java/net/myscloud/open/yuna/model/Permission.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// @EqualsAndHashCode(callSuper = true)
// public class Permission extends BaseModel {
// 
//     private Integer id;
// 
//     /**
//      * 系统
//      */
//     private Integer sid;
// 
//     /**
//      * Ext 系统名称
//      */
//     private String systemName;
// 
//     /**
//      * Ext 系统编码
//      */
//     private String systemCode;
// 
//     /**
//      * 上级权限ID
//      */
//     private Integer pid;
// 
//     /**
//      * 资源编码  定位中y坐标
//      */
//     private String code;
// 
//     /**
//      * {@link Type}
//      */
//     private Integer type;
// 
//     private String name;
// 
//     private String icon;
// 
//     private String value;
// 
//     private String regular;
// 
//     /**
//      * 等级分值 0为不显示，分值越高越靠前
//      */
//     private Integer rank;
// 
//     @AllArgsConstructor
//     public enum Type {
//         /**
//          * 页面
//          */
//         Page(1),
//         /**
//          * 链接,不直接显示在页面上
//          */
//         Url(2),
//         /**
//          * 按钮
//          */
//         Button(3),
//         /**
//          * 标签
//          */
//         Tag(4);
// 
//         @Getter
//         private int code;
//     }
// 
// }
// 
// Path: console/src/main/java/net/myscloud/open/yuna/service/BusinessSystemService.java
// public interface BusinessSystemService extends IGenericService<BusinessSystem, Integer> {
// }


import net.myscloud.open.yuna.common.kits.CollectionKits;
import net.myscloud.open.yuna.consts.YunaConsts;
import net.myscloud.open.yuna.model.Permission;
import net.myscloud.open.yuna.service.BusinessSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
package net.myscloud.open.yuna.controller;



/**
 * Created by genesis on 2016/12/30.
 */
@Controller
public class LocationController {

    @Autowired
    private BusinessSystemService businessSystemService;

    /**
     * 定位页面渲染Iframe
     *
     * @param x x坐标(required)
     * @return ModelAndView
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "location/{x}", method = RequestMethod.GET)
    public ModelAndView businessSystem(HttpSession session, @PathVariable String x) {
        session.setAttribute(YunaConsts.SESSION_CURRENT_BUSINESS_SYSTEM, x);
        Map<String, List<Permission>> businessSystemCodeMap = (Map<String, List<Permission>>) session.getAttribute(YunaConsts.SESSION_BUSINESS_SYSTEM_CODE_MAP);
        Collection<Permission> permissions = businessSystemCodeMap.get(x);
        if (CollectionKits.isEmpty(permissions)) {
            return new ModelAndView("index");
        }

        ModelAndView modelAndView = new ModelAndView("index");

        modelAndView.addObject(YunaConsts.CURRENT_PERMISSIONS, permissions.parallelStream()
                .filter(permission -> permission.getType() != null
                        && permission.getType() == Permission.Type.Page.getCode())
                .map(permission -> {
                    StringBuilder value = new StringBuilder();
                    businessSystemService.get(permission.getSid()).ifPresent(businessSystem -> {
                        if (!permission.getValue().startsWith("http")) {
                            value.append(businessSystem.getDomain());
                        }
                    });
                    value.append(permission.getValue());
// Path: common/src/main/java/net/myscloud/open/yuna/common/kits/CollectionKits.java
// public class CollectionKits {
// 
//     public static boolean isEmpty(Collection<?> collection) {
//         return collection == null || collection.isEmpty();
//     }
// 
//     public static boolean isNotEmpty(Collection<?> collection) {
//         return !isEmpty(collection);
//     }
// 
//     public static boolean isEmpty(Map<?, ?> map) {
//         return map == null || map.isEmpty();
//     }
// 
//     public static boolean isNotEmpty(Map<?, ?> map) {
//         return !isEmpty(map);
//     }
// 
//     private CollectionKits() {
//     }
// }
// 
// Path: client/src/main/java/net/myscloud/open/yuna/consts/YunaConsts.java
// public interface YunaConsts {
//     //session attrs
//     String SESSION_USER = "session_user";
//     String SESSION_BUSINESS_SYSTEM_CODE_MAP = "session_business_system_code_map";
//     String SESSION_BUSINESS_SYSTEMS = "session_business_systems";
//     String SESSION_CURRENT_BUSINESS_SYSTEM = "session_current_business_system";
//     String CURRENT_PERMISSIONS = "current_permissions";
// }
// 
// Path: domain/src/main/java/net/myscloud/open/yuna/model/Permission.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// @EqualsAndHashCode(callSuper = true)
// public class Permission extends BaseModel {
// 
//     private Integer id;
// 
//     /**
//      * 系统
//      */
//     private Integer sid;
// 
//     /**
//      * Ext 系统名称
//      */
//     private String systemName;
// 
//     /**
//      * Ext 系统编码
//      */
//     private String systemCode;
// 
//     /**
//      * 上级权限ID
//      */
//     private Integer pid;
// 
//     /**
//      * 资源编码  定位中y坐标
//      */
//     private String code;
// 
//     /**
//      * {@link Type}
//      */
//     private Integer type;
// 
//     private String name;
// 
//     private String icon;
// 
//     private String value;
// 
//     private String regular;
// 
//     /**
//      * 等级分值 0为不显示，分值越高越靠前
//      */
//     private Integer rank;
// 
//     @AllArgsConstructor
//     public enum Type {
//         /**
//          * 页面
//          */
//         Page(1),
//         /**
//          * 链接,不直接显示在页面上
//          */
//         Url(2),
//         /**
//          * 按钮
//          */
//         Button(3),
//         /**
//          * 标签
//          */
//         Tag(4);
// 
//         @Getter
//         private int code;
//     }
// 
// }
// 
// Path: console/src/main/java/net/myscloud/open/yuna/service/BusinessSystemService.java
// public interface BusinessSystemService extends IGenericService<BusinessSystem, Integer> {
// }


// Path: console/src/main/java/net/myscloud/open/yuna/controller/LocationController.java
import net.myscloud.open.yuna.common.kits.CollectionKits;
import net.myscloud.open.yuna.consts.YunaConsts;
import net.myscloud.open.yuna.model.Permission;
import net.myscloud.open.yuna.service.BusinessSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

package net.myscloud.open.yuna.controller;



/**
 * Created by genesis on 2016/12/30.
 */
@Controller
public class LocationController {

    @Autowired
    private BusinessSystemService businessSystemService;

    /**
     * 定位页面渲染Iframe
     *
     * @param x x坐标(required)
     * @return ModelAndView
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "location/{x}", method = RequestMethod.GET)
    public ModelAndView businessSystem(HttpSession session, @PathVariable String x) {
        session.setAttribute(YunaConsts.SESSION_CURRENT_BUSINESS_SYSTEM, x);
        Map<String, List<Permission>> businessSystemCodeMap = (Map<String, List<Permission>>) session.getAttribute(YunaConsts.SESSION_BUSINESS_SYSTEM_CODE_MAP);
        Collection<Permission> permissions = businessSystemCodeMap.get(x);
        if (CollectionKits.isEmpty(permissions)) {
            return new ModelAndView("index");
        }

        ModelAndView modelAndView = new ModelAndView("index");

        modelAndView.addObject(YunaConsts.CURRENT_PERMISSIONS, permissions.parallelStream()
                .filter(permission -> permission.getType() != null
                        && permission.getType() == Permission.Type.Page.getCode())
                .map(permission -> {
                    StringBuilder value = new StringBuilder();
                    businessSystemService.get(permission.getSid()).ifPresent(businessSystem -> {
                        if (!permission.getValue().startsWith("http")) {
                            value.append(businessSystem.getDomain());
                        }
                    });
                    value.append(permission.getValue());
                    permission.setValue(value.toString());