ars.module.educate.service.AbstractProfessionService Maven / Gradle / Ivy
package ars.module.educate.service;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.LinkedHashMap;
import ars.util.SimpleTree;
import ars.invoke.request.Requester;
import ars.module.people.model.Group;
import ars.module.educate.model.Profession;
import ars.module.educate.service.ProfessionService;
import ars.database.repository.Repositories;
import ars.database.service.StandardGeneralService;
/**
* 专业业务操作抽象实现
*
* @author yongqiangwu
*
* @param
* 数据模型
*/
public abstract class AbstractProfessionService extends StandardGeneralService
implements ProfessionService {
@Override
public List trees(Requester requester, Integer level) {
List objects = this.getQuery(requester).custom(requester.getParameters()).list();
if (objects.isEmpty()) {
return new ArrayList(0);
}
List departments = new LinkedList();
Map> leaves = new LinkedHashMap>();
for (int i = 0; i < objects.size(); i++) {
T profession = objects.get(i);
Group department = profession.getDepartment();
List professions = leaves.get(department);
if (professions == null) {
professions = new LinkedList();
leaves.put(department, professions);
}
professions.add(Repositories.getSimpleTree(profession));
while (department != null && (level == null || department.getLevel() >= level)
&& !departments.contains(department)) {
departments.add(department);
department = department.getParent();
}
}
Map mappings = new HashMap(departments.size());
List trunks = Repositories.getSimpleTrees(Repositories.mergeTrees(departments), mappings);
for (Entry> entry : leaves.entrySet()) {
SimpleTree leaf = mappings.get(entry.getKey());
List children = entry.getValue();
leaf.getChildren().addAll(0, children);
for (SimpleTree child : children) {
child.setParent(leaf);
}
}
return trunks;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy