| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package com.goafanti.common.utils;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.List;
- import javax.mail.MessagingException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Component;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.dao.NoticeMapper;
- import com.goafanti.common.enums.NoticeTypes;
- import com.goafanti.common.model.Notice;
- @Component
- @Async
- public class AsyncUtils {
- @Autowired
- private NoticeMapper noticeMapper;
-
-
-
- public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
- SendEmailUtil.getInstance().patentSend(bo);
- }
-
- public void sendList(List<EmailBo> list) throws MessagingException, UnsupportedEncodingException {
- for (EmailBo emailBo : list) {
- SendEmailUtil.getInstance().patentSend(emailBo);
- }
-
- }
-
-
- public void send(EmailBo bo){
- try {
- SendEmailUtil.getInstance().send(bo);
- } catch (UnsupportedEncodingException | MessagingException e) {
- e.printStackTrace();
- }
- }
-
- public void addNotice(Notice n ) {
- n.setType(NoticeTypes.getType(n.getNoticeType()));
- noticeMapper.insertSelective(n);
- }
-
-
- public void addNoticeBatch(List<Notice> ln) {
- List<Notice> newList=new ArrayList<Notice>();
- if (ln != null && ln.size() > 0) {
- for (int i = 0; i < ln.size(); i++) {
- ln.get(i).setType(NoticeTypes.getType(ln.get(i).getNoticeType()));
- newList.add(ln.get(i));
- if (50 == newList.size() || i == ln.size() - 1) {
- if (newList.size() > 0) noticeMapper.insertBatch(newList);
- newList.clear();
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
-
- }
- public void batchUpdateUnreaded(List<String> dl) {
- noticeMapper.batchUpdateUnreaded(dl);
- }
- }
|