com.ajaxjs.website.section.TreeLikeService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-framework2 Show documentation
Show all versions of ajaxjs-framework2 Show documentation
AJAXJS aims to full-stack, not only the server-side framework,
but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated,
emphasizing the lightweight, and fast, very suitable for the Internet fast application.
The newest version!
package com.ajaxjs.website.section;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import com.ajaxjs.framework.BaseModel;
import com.ajaxjs.framework.BaseService;
import com.ajaxjs.sql.JdbcConnection;
import com.ajaxjs.sql.orm.Repository;
@Component
public class TreeLikeService extends BaseService {
public static TreeLikeoDao DAO = new Repository().bind(TreeLikeoDao.class);
{
setUiName("分类");
setShortName("catalog");
setDao(DAO);
}
/**
* 获取 pid 下面直接一级的子节点,
*
* @param pid
* @return
*/
public List getDirectChildren(int pid) {
return DAO.findList(by("pid", pid));
}
/**
* 获取全部的分类
*
* @return
*/
public List getAllChildren() {
return DAO.findList(sql -> sql + " ORDER BY pid");
}
/**
* 获取 pid 下面的所有子节点,无论下面有多少级
*
* @param pid
* @return
*/
public List getAllChildren(int pid) {
return DAO.getAllChildren(pid);
}
/**
* 转换为适合前端显示的 map
*
* @param pid
* @return
*/
public Map getAllChildrenAsMap(int pid) {
return idAskey(getAllChildren(pid));
}
/**
* 把列表(BaseModel 结构)转换为 map,以 id 作为键值。key 本来是 long,为照顾 el 转换为 int
*
* @param list 实体列表
* @return 以 id 作为键值的 map
*/
public static Map idAskey(List extends BaseModel> list) {
if (CollectionUtils.isEmpty(list))
return null;
Map map = new HashMap<>();
list.forEach(item -> map.put(item.getId(), item));
return map;
}
/**
* 把列表(Map结构)转换为 map,以 id 作为键值。key 本来是 long,为照顾 el 转换为 int
*
* @param list 实体列表
* @return 以 id 作为键值的 map
*/
public static Map idAsKey(List