package org.fouram.core.plugin.weixin.cp.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.google.common.collect.Lists;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpDepart;

/**
 * 企业微信用户工具类
 * 
 * @author Liup
 */
public class DeleteAllDepartUtil {

	public static void main(String[] args) throws WxErrorException {
		List<Long> ids = Lists.newArrayList();
		List<WxCpDepart> departs = WXCpDepartUtil.getAllChildDeparts(1L);
		for(WxCpDepart depart : departs) {
			ids.add(depart.getId());
		}
		// 按照大小倒序
		Collections.sort(ids, new Comparator<Long>() {
			public int compare(Long o1, Long o2) {
				return o2.compareTo(o1);
			}
		});
		System.out.println(ids.size());
		System.out.println("===========================");
		for(Long id : ids) {
			if(id > 1) {
				if(WXCpUserUtil.listByDepartment(id).size() == 0) {
					System.out.println(id);
					WXCpDepartUtil.delete(id);
				}
			}
		}
	}
}
