根据csv文件批量更新AD域的用户
1、解析CSV文件并确定是新增还是更新用户
package com.lls.it.ldapapi.service;
import com.lls.it.ldapapi.entity.AdUser;
import com.lls.it.ldapapi.exception.UserExistException;
import com.lls.it.ldapapi.exception.UserNotFoundException;
import com.opencsv.CSVReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.FileReader;
@Service
public class CSVReaderService {
private static final String USER_ACCOUNT_CONTROL = "66048";
@Autowired
private UserService userService;
/**
* dealType: 1, create用户; 2, update用户
* 根据导入的CSV文件批量新增用户
*/
public boolean ParseCSVFile(String file, Integer dealType) {
try {
CSVReader reader = null;
reader = new CSVReader(new FileReader(file));
String[] line = null;
reader.readNext();
// 批量创建用户
if (dealType == 1) {
while ((line = reader.readNext()) != null) {
if (userService.findByAccountName(line[0]) == null) {
batchCreateADUser(line);
} else {
throw new UserExistException(String.format("user %s has existed&