AsyncUtils.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.goafanti.common.utils;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import javax.mail.MessagingException;
  7. import com.goafanti.admin.bo.AdminListBo;
  8. import com.goafanti.common.dao.AdminMapper;
  9. import com.goafanti.common.dao.NewOrderChangeMapper;
  10. import com.goafanti.common.dao.TChangeTaskMapper;
  11. import com.goafanti.common.enums.NoticeStatus;
  12. import com.goafanti.common.model.Admin;
  13. import com.goafanti.common.model.TChangeTask;
  14. import com.goafanti.core.shiro.token.TokenManager;
  15. import com.goafanti.order.bo.NewOrderChangeBo;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.scheduling.annotation.Async;
  18. import org.springframework.stereotype.Component;
  19. import com.goafanti.common.bo.EmailBo;
  20. import com.goafanti.common.dao.NoticeMapper;
  21. import com.goafanti.common.enums.NoticeTypes;
  22. import com.goafanti.common.model.Notice;
  23. @Component
  24. @Async
  25. public class AsyncUtils {
  26. @Autowired
  27. private NoticeMapper noticeMapper;
  28. @Autowired
  29. private AdminMapper adminMapper;
  30. @Autowired
  31. private TChangeTaskMapper tChangeTaskMapper;
  32. @Autowired
  33. private NewOrderChangeMapper newOrderChangeMapper;
  34. public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
  35. SendEmailUtil.getInstance().patentSend(bo);
  36. }
  37. public void sendList(List<EmailBo> list) throws MessagingException, UnsupportedEncodingException {
  38. for (EmailBo emailBo : list) {
  39. SendEmailUtil.getInstance().patentSend(emailBo);
  40. }
  41. }
  42. public void send(EmailBo bo){
  43. try {
  44. SendEmailUtil.getInstance().send(bo);
  45. } catch (UnsupportedEncodingException | MessagingException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. public void addNotice(Notice n ) {
  50. n.setType(NoticeTypes.getType(n.getNoticeType()));
  51. noticeMapper.insertSelective(n);
  52. }
  53. public void addNoticAndEmail(Notice n) {
  54. n.setType(NoticeTypes.getType(n.getNoticeType()));
  55. AdminListBo a = adminMapper.getDeptNameByAid(n.getAid());
  56. EmailBo bo=new EmailBo(NoticeStatus.getStatus(n.getNoticeType()).getDesc(),a.getEmail(),n.getContent()) ;
  57. noticeMapper.insertSelective(n);
  58. send(bo);
  59. }
  60. public void addNoticeBatch(List<Notice> ln) {
  61. List<Notice> newList=new ArrayList<Notice>();
  62. if (ln != null && ln.size() > 0) {
  63. for (int i = 0; i < ln.size(); i++) {
  64. ln.get(i).setType(NoticeTypes.getType(ln.get(i).getNoticeType()));
  65. newList.add(ln.get(i));
  66. if (50 == newList.size() || i == ln.size() - 1) {
  67. if (newList.size() > 0) noticeMapper.insertBatch(newList);
  68. newList.clear();
  69. try {
  70. Thread.sleep(2000);
  71. } catch (InterruptedException e) {
  72. e.printStackTrace();
  73. }
  74. }
  75. }
  76. }
  77. }
  78. public void batchUpdateUnreaded(List<String> dl) {
  79. noticeMapper.batchUpdateUnreaded(dl);
  80. }
  81. }