package org.fouram.service;

import java.util.List;

import org.fouram.core.base.service.BaseService;
import org.fouram.core.plugin.weixin.cp.util.WXCpUserUtil;
import org.fouram.core.util.LoggerUtil;
import org.fouram.entity.TestUser;
import org.springframework.stereotype.Service;

@Service
public class TestUserService extends BaseService {

	@SuppressWarnings("unchecked")
	public void createOrUpdateWXUsers() throws Exception {
		List<TestUser> testUsers = (List<TestUser>) findList("TestUserMapper.selectAllList", null);
		System.out.println(testUsers.size());
		for (int i = 0; i < testUsers.size(); i++) {
			TestUser testUser = testUsers.get(i);
			String wxUserResult = createOrUpdateWXUser(testUser);
			LoggerUtil.info(wxUserResult);
			System.out.println("=======================" + i);
			TestUser entity = TestUser.builder().personId(testUser.getPersonId()).wxUserResult(wxUserResult).build();
			update("TestUserMapper.updateWxUserResult", entity);
		}
	}

	private String createOrUpdateWXUser(TestUser testUser) throws Exception {
		String[] subCompanyList = new String[] { testUser.getSubCompany() };
		String[] departmentList = new String[] { testUser.getDepartment() };
		String position = "";
		String mobile = "";
		return WXCpUserUtil.createOrUpdateForTest(testUser.getPersonId(), testUser.getName(), subCompanyList,
				departmentList, position, mobile, testUser.getGender(), testUser.getEmail());
	}
}
