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

import java.util.List;

import org.apache.commons.lang3.StringUtils;

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

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

	public static void main(String[] args) throws WxErrorException {
		showEmail();
	}

	public static void updateEmail() throws WxErrorException {
		List<WxCpUser> users = WXCpUserUtil.listByDepartment(17L);
		for (WxCpUser user : users) { // @cmccap.com改成@cmcinc.cn
			System.out.println(user.getEmail());
			user.setEmail(user.getEmail().replace("@cmccap.com", "@cmcinc.cn"));
			WXCpUserUtil.updateUser(user);
		}
	}

	public static void showDiffEmail() throws WxErrorException {
		List<WxCpUser> users = WXCpUserUtil.listByDepartment(17L);
		for (WxCpUser user : users) {
			if (StringUtils.isNotBlank(user.getEmail()) && !user.getEmail().endsWith("@cmcinc.cn")) {
				System.out.println(user);
			}
		}
	}
	
	public static void showEmail() throws WxErrorException {
		List<WxCpUser> users = WXCpUserUtil.listByDepartment(17L);
		for (WxCpUser user : users) {
			System.out.println(user);
		}
	}
}
