From dfb700607f78db755cbe4f3d3e5b8cb0b4bccc74 Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Fri, 15 Jun 2018 11:47:52 +0800 Subject: [PATCH] init unsub mail --- .../notice/core/impls/MailServiceImp.java | 3 +- .../impls/CustomerImpressionImplTest.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java index 54d2f505e..cd436b203 100644 --- a/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/notice/core/impls/MailServiceImp.java @@ -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.notice.beans.NoticeBean; 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.ServerErrorException; 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")); if(existRecord!=null){ - throw new BadRequestException("address has been added"); + return; } JSONObject record= new JSONObject(); record.put("id", IdUtil.getId()); diff --git a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java index 1d4864e05..344ec333f 100644 --- a/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java +++ b/src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java @@ -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.OrgMapper; 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.SendMail; @@ -13,6 +14,12 @@ import com.alibaba.fastjson.JSONObject; import org.apache.commons.codec.binary.Base64; 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.runner.RunWith; 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.web.bind.annotation.RequestMethod; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -58,6 +68,8 @@ public class CustomerImpressionImplTest { @Resource private ClientManager clientManager; + @Resource + private MailService mailService; // @Test // public void redisQueue() { // BoundListOperations ops = stringRedisTemplate.boundListOps("customer_impression"); @@ -202,4 +214,47 @@ public class CustomerImpressionImplTest { 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 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(); + } + } } \ No newline at end of file