public void classifyTree(HttpServletRequest request,HttpServletResponse response,String planId) throws Exception {
List<TreeDataString> list=new ArrayList<TreeDataString>();
SessionInfo session=getCurrentSessionInfo(request);
List<TrainplanClassifyInfo> data=trainplanClassifyService.getTrainplanClassifyListByPlatFormId(session.getPlatFormId());
Map<Long, Long> map = new HashMap<Long, Long>();
for(TrainplanClassifyInfo tt:data){
if(Objects.equals("0", tt.getParentId())) {
TreeDataString node=new TreeDataString();
node.setText(tt.getName());
node.setId(tt.getId());
node.setChildren(new ArrayList<TreeDataString>());
node.setLevel(Integer.valueOf(tt.getParentId()));
TrainplanLmsInfo t=new TrainplanLmsInfo();
t.setId(planId);
map = MapUtils.list2TreeMap1(trainplanLmsService.findByParam(t,null), "classifyId", "id");
if(map.containsKey(tt.getId())){
node.setChecked(true);
}
getTreeDataClassify(data,node,map);
list.add(node);
}
}
writeJson(response, list);
}
//
private void getTreeDataClassify(List<TrainplanClassifyInfo> list, TreeDataString tree, Map<Long, Long> map) {
List<TrainplanClassifyInfo> tmpList = findChildrenClassify(list, tree);
if(tmpList.size()>0){
for (TrainplanClassifyInfo item : tmpList) {
TreeDataString td = null;
td = new TreeDataString(item.getId(), item.getName(), "open", new Attributes(item.getName(), null, false), new ArrayList<TreeDataString>(),map.containsKey(item.getId()));
getTreeDataClassify(list, td, map);
tree.setAttributes(new Attributes(tree.getText(), null, true));
tree.getChildren().add(td);
}
}
}
//
private List<TrainplanClassifyInfo> findChildrenClassify(List<TrainplanClassifyInfo> mList, TreeDataString tree) {
List<TrainplanClassifyInfo> childInfoList = new ArrayList<TrainplanClassifyInfo>();
for (TrainplanClassifyInfo t : mList) {
if (tree.getId().equals(t.getParentId())) {
childInfoList.add(t);
}
}
return childInfoList;
}
//
public String id;
public String text;
// 状态:open 或者 closed
public String state;
public boolean checked;
private Integer level;
public Attributes attributes;
public TreeDataString(){}
public TreeDataString(String id, String name, String state, Attributes attributes, ArrayList<TreeDataString> arrayList, boolean flag) {
this.id=id;
this.text=name;
this.state=state;
this.attributes=attributes;
this.children=arrayList;
this.checked=flag;
}