init unsub mail

master
wangning 7 years ago
parent 3395120f3c
commit dfb700607f

@ -4,7 +4,6 @@ import au.com.royalpay.payment.manage.mappers.system.MailUnsubMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.beans.NoticeBean; import au.com.royalpay.payment.manage.notice.beans.NoticeBean;
import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException; import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.PageListUtils;
@ -212,7 +211,7 @@ public class MailServiceImp implements MailService {
} }
JSONObject existRecord = mailUnsubMapper.getOne(null,client.getString("contact_email")); JSONObject existRecord = mailUnsubMapper.getOne(null,client.getString("contact_email"));
if(existRecord!=null){ if(existRecord!=null){
throw new BadRequestException("address has been added"); return;
} }
JSONObject record= new JSONObject(); JSONObject record= new JSONObject();
record.put("id", IdUtil.getId()); record.put("id", IdUtil.getId());

@ -5,6 +5,7 @@ import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.system.OrgMapper; import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.tools.mail.MailGunClient; import au.com.royalpay.payment.tools.mail.MailGunClient;
import au.com.royalpay.payment.tools.mail.SendMail; import au.com.royalpay.payment.tools.mail.SendMail;
@ -13,6 +14,12 @@ import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -21,12 +28,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -58,6 +68,8 @@ public class CustomerImpressionImplTest {
@Resource @Resource
private ClientManager clientManager; private ClientManager clientManager;
@Resource
private MailService mailService;
// @Test // @Test
// public void redisQueue() { // public void redisQueue() {
// BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression"); // BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
@ -202,4 +214,47 @@ public class CustomerImpressionImplTest {
System.out.println(asd); System.out.println(asd);
System.out.println(asd); System.out.println(asd);
} }
@Test
public void addMailUnsub() {
try {
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.rowIterator();
Row row = null;
Cell cell = null;
while (rowIterator.hasNext()) {
row = rowIterator.next();
cell = row.getCell(1);
if(cell==null){
continue;
}
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
CellStyle cellStyle = cell.getCellStyle();
if(cellStyle.getFillForegroundColor()==0){
continue;
}
String clientMonikers = cell.getStringCellValue().trim();
if(clientMonikers.contains("/")){
String [] clientMonikerArr = clientMonikers.split("/");
for (String s : clientMonikerArr) {
String tmp = s.trim().toUpperCase();
if(tmp.length()>4 || tmp.length()==0){
continue;
}
mailService.addUnsub(s.trim().toUpperCase());
}
}else {
String tmp = clientMonikers.trim().toUpperCase();
if(tmp.length()>4 || tmp.length()==0){
continue;
}
mailService.addUnsub(clientMonikers.trim().toUpperCase());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} }
Loading…
Cancel
Save