/**
* Copyright © 2012-2014 JeeSite All rights reserved.
*/
package com.nis.supcan;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSessionFactory;
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.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.nis.util.CacheUtils;
import com.nis.util.Configurations;
import com.nis.util.StringUtils;
import com.nis.web.controller.BaseController;
import com.nis.web.service.SpringContextHolder;
/**
* 硕正Controller
* @author ThinkGem
* @version 2013-11-13
*/
@Controller
@RequestMapping(value = "${adminPath}/supcan")
public class SupcanController extends BaseController {
private static final String SUPCAN_CACHE = "supcanCache";
/**
* 获取硕正树列表描述(根据注解获取XML)
* @return
*/
@RequestMapping(value = "treeList/{typeAlias}.xml")
@ResponseBody
public TreeList treeList(@PathVariable("typeAlias") String typeAlias) {
// 如果使用Cache,并且在Cache里存在,则直接返回。
boolean useCache = Configurations.getBooleanProperty("supcan.useCache", false);
if (useCache){
Object object = CacheUtils.get(SUPCAN_CACHE, typeAlias);
if (object != null){
return (TreeList)object;
}
}
// 实体类型
Class> clazz;
try{
// 根据别名获取MyBaits注册类型。
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
clazz = sqlSessionFactory.getConfiguration().getTypeAliasRegistry().resolveAlias(typeAlias);
}catch (Exception e) {
// 取不到类型,返回空。
return null;
}
// 获取硕正注解配置
SupTreeList supTreeList = clazz.getAnnotation(SupTreeList.class);
// 没有硕正注解配置,则返回空
if (supTreeList == null){
return null;
}
// 实例化硕正树列表对象
TreeList treeList = new TreeList(supTreeList);
// 获取表头分组
Map groupMap = Maps.newHashMap();
if (supTreeList !=null && supTreeList.groups() != null){
for (SupGroup supGroup : supTreeList.groups()){
groupMap.put(supGroup.id(), new Group(supGroup));
}
}
// 获取表头列
List