日期:2014-05-16 浏览次数:20496 次
// 对ztree进行重组
sb.append("[");
int flag = 0;
// 每个共享用户对应一个结点
for (Integer userId : userIds) {
User user = (User) us.findUserById(userId.intValue());
if (flag > 0) {
sb.append(Delimiters.COMMA);
}
List<ContactShareGroup> cg = cs.findShareContactGroup(
simpleUser.getEnterpriseId(), userId);
ContactShareGroup defaultShareGroup = cg.get(0);// 在共享通讯录中,点击用户名时显示第一组数据
sb.append(this.toUserTree(user, cg));
sb.append(Delimiters.COMMA);
flag++;
int min = -1;
int max = -1;
String minPath = cg.get(0).getContactGroup().getPath();
String maxPath = cg.get(0).getContactGroup().getPath();
int parentId = -(defaultShareGroup.getContactGroup().getId());
for (int i = 0; i < cg.size(); i++) {
if ((minPath.length()) > (cg.get(i).getContactGroup().getPath()
.length())) {
min = i;
minPath = cg.get(i).getContactGroup().getPath();
}
if ((maxPath.length()) < (cg.get(i).getContactGroup().getPath()
.length())) {
max = i;
maxPath = cg.get(i).getContactGroup().getPath();
}
}
if (min != -1) {
for(int i=0;i<cg.size();i++){
if(minPath.length()==cg.get(i).getContactGroup().getPath().length()){
cg.get(i).getContactGroup().setParentId(parentId);
}
}
} else if (max == min) {
for (int j = 0; j < cg.size(); j++) {
cg.get(j).getContactGroup().setParentId(parentId);
}
} else {
for (int k = 0; k < cg.size(); k++) {
if (cg.get(k).getContactGroup().getPath().length() == minPath
.length()) {
cg.get(k).getContactGroup().setParentId(parentId);
}
}
}
for (int m = 0; m < cg.size(); m++) {
if (m != 0)
sb.append(Delimiters.COMMA);
sb.append(cg.get(m).toZTreeJSON());
}
}
sb.append("]");