public with sharing class DealerPersonnelController {
|
public DealerPersonnelController() {
|
|
}
|
@AuraEnabled
|
public static String processData(String fileData,String sobjectName,List<String> fields) {
|
system.debug('fileData===============>'+fileData);
|
String errorMage = '';
|
try {
|
if(fileData != null){
|
String[] fileLines = new String[]{};
|
fileLines = fileData.split('\n');
|
system.debug('fileLines===================>'+fileLines);
|
// 经销商管理编码
|
List<String> managementCodeList = new List<String>();
|
// 导入的数据
|
List<List<String>> inputList = new List<List<String>>();
|
for (Integer i = 1,j = fileLines.size(); i < j; i++) {
|
List<String> inputValues = new List<String>();
|
inputValues = fileLines[i].split(',');
|
System.debug('inputValues=============>'+inputValues);
|
if(inputValues != null){
|
if(inputValues[0] == '' || inputValues[0]== null){
|
errorMage += 'errorMage: 第' + i + '行,姓名不能为空!';
|
errorMage += '=';
|
}
|
if(inputValues[1] == '' || inputValues[1] ==null){
|
errorMage += 'errorMage: 第' + i + '行,手机不能为空!';
|
errorMage += '=';
|
}
|
boolean mobileNumberFlag = mobileNumberVerification(inputValues[1]);
|
if(mobileNumberFlag == false){
|
errorMage += 'errorMage: 你的手机号码不太正确,请检查您的手机是否正确!';
|
errorMage += '=';
|
}
|
if(inputValues[2] == '' || inputValues[2] == null){
|
errorMage += 'errorMage: 第' + i + '行,邮箱不能为空!';
|
errorMage += '=';
|
}
|
boolean mailboxFlag = mailboxVerification(inputValues[2]);
|
if(mailboxFlag == false){
|
errorMage += 'errorMage: 你的邮箱不太正确,请检查您的邮箱格式!';
|
errorMage += '=';
|
}
|
if(inputValues[3] == '' || inputValues[3] == null){
|
errorMage += 'errorMage: 第' + i + '行,经销商管理编码不能为空!';
|
errorMage += '=';
|
}
|
|
managementCodeList.add(inputValues[3]);
|
inputList.add(inputValues);
|
//导入的数据
|
System.debug('inputValues[0]===============>'+ inputValues[0]);
|
System.debug('inputValues[1]===============>'+ inputValues[1]);
|
System.debug('inputValues[2]===============>'+ inputValues[2]);
|
System.debug('inputValues[3]===============>'+ inputValues[3]);
|
}
|
}
|
Map<String,Account> accountIdMap = new Map<String,Account>();
|
List<Account> accountList = [select id, Name,Management_Code__c from Account where Management_Code__c in: managementCodeList];
|
for(Account ac : accountList){
|
accountIdMap.put(ac.Management_Code__c,ac);
|
}
|
List<Contact> cnList = new List<Contact>();
|
Integer lineNumber = 1;
|
for(List<String> lineList :inputList){
|
Contact con = new Contact();
|
//暂时导入的是经销商用户,所以记录类型只有经销商,暂时写死;后期如果有变动再更改
|
con.RecordTypeId = '01210000000QfWiAAK';
|
if(lineList[0] != null && lineList[0] != ''){
|
con.LastName = lineList[0];
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,姓氏'+lineList[0]+'不存在';
|
errorMage += '=';
|
}
|
if(lineList[1] != null && lineList[1] != ''){
|
if(mobileNumberVerification(lineList[1])){
|
con.MobilePhone = lineList[1];
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,手机'+lineList[1]+'不正确!';
|
errorMage += '=';
|
}
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,手机'+lineList[1]+'不存在';
|
errorMage += '=';
|
}
|
if(lineList[2] != null && lineList[2] != ''){
|
if(mailboxVerification(lineList[2])){
|
con.Email = lineList[2];
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,电子邮件'+lineList[2]+'不正确!';
|
errorMage += '=';
|
}
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,电子邮件'+lineList[2]+'不存在';
|
errorMage += '=';
|
}
|
if(accountIdMap.containsKey(lineList[3])){
|
con.AccountId = accountIdMap.get(lineList[3]).id;
|
}else{
|
errorMage += 'error: 第'+ lineNumber +'行数据,经销商编码'+lineList[3]+'不存在';
|
errorMage += '=';
|
}
|
//暂定创建直接为 true
|
con.Agency_User__c = true;
|
lineNumber++;
|
cnList.add(con);
|
}
|
if(errorMage != ''){
|
system.debug('errorMage==========>'+errorMage);
|
return errorMage;
|
}
|
// 新增周报明细
|
if(cnList.size() > 0 ){
|
insertContact(cnList);
|
}
|
}
|
return 'success';
|
} catch (Exception e) {
|
System.debug('exception'+e);
|
return 'exception'+e;
|
}
|
}
|
// 电子邮件的验证
|
public static boolean mailboxVerification(String mailbox){
|
String check = '^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$';
|
Pattern regex = Pattern.compile(check);
|
Matcher matcher = regex.matcher(mailbox);
|
if (matcher.matches()){
|
return true;
|
}
|
return false;
|
}
|
// 手机号的验证
|
public static boolean mobileNumberVerification(String phoneNumber){
|
String check = '^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$';
|
Pattern regex = Pattern.compile(check);
|
Matcher matcher = regex.matcher(phoneNumber);
|
if(matcher.matches()){
|
return true;
|
}
|
return false;
|
}
|
//新增客户人员;
|
public static void insertContact(List<Contact> data) {
|
insert data;
|
}
|
|
}
|