AsyncUtils.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 java.util.UUID;
  7. import javax.mail.MessagingException;
  8. import com.goafanti.admin.bo.AdminListBo;
  9. import com.goafanti.common.dao.*;
  10. import com.goafanti.common.enums.NoticeStatus;
  11. import com.goafanti.common.model.Admin;
  12. import com.goafanti.common.model.TChangeTask;
  13. import com.goafanti.core.shiro.token.TokenManager;
  14. import com.goafanti.order.bo.NewOrderChangeBo;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.scheduling.annotation.Async;
  17. import org.springframework.stereotype.Component;
  18. import com.goafanti.common.bo.EmailBo;
  19. import com.goafanti.common.enums.NoticeTypes;
  20. import com.goafanti.common.model.Notice;
  21. @Component
  22. @Async
  23. public class AsyncUtils {
  24. @Autowired
  25. private NoticeMapper noticeMapper;
  26. @Autowired
  27. private AdminMapper adminMapper;
  28. @Autowired
  29. private TOrderNewMapper tOrderNewMapper;
  30. @Autowired
  31. private NewOrderChangeMapper newOrderChangeMapper;
  32. @Autowired
  33. private TOrderInvoiceMapper tOrderInvoiceMapper;
  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 addNotic(Integer type, String aid,String str) {
  54. Notice n =new Notice();
  55. n.setId(UUID.randomUUID().toString());
  56. n.setAid(aid);
  57. n.setNoticeType(type);
  58. n.setContent(str);
  59. n.setReaded(0);//未读
  60. addNotice(n);
  61. }
  62. public void addNoticAndEmail(Notice n) {
  63. n.setType(NoticeTypes.getType(n.getNoticeType()));
  64. AdminListBo a = adminMapper.getDeptNameByAid(n.getAid());
  65. EmailBo bo=new EmailBo(NoticeStatus.getStatus(n.getNoticeType()).getDesc(),a.getEmail(),n.getContent()) ;
  66. noticeMapper.insertSelective(n);
  67. send(bo);
  68. }
  69. public void addNoticeBatch(List<Notice> ln) {
  70. List<Notice> newList=new ArrayList<Notice>();
  71. if (ln != null && ln.size() > 0) {
  72. for (int i = 0; i < ln.size(); i++) {
  73. ln.get(i).setType(NoticeTypes.getType(ln.get(i).getNoticeType()));
  74. newList.add(ln.get(i));
  75. if (50 == newList.size() || i == ln.size() - 1) {
  76. if (newList.size() > 0) noticeMapper.insertBatch(newList);
  77. newList.clear();
  78. try {
  79. Thread.sleep(2000);
  80. } catch (InterruptedException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. }
  85. }
  86. }
  87. public void batchUpdateUnreaded(List<String> dl) {
  88. noticeMapper.batchUpdateUnreaded(dl);
  89. }
  90. /**
  91. * 切换审核人员
  92. * @param type 1营销管理 2公司管理 3财务
  93. * @param depId 部门编号
  94. * @param aid 切换后审核人
  95. * @return
  96. */
  97. public void updateexamineName(Integer type, String depId, String aid) {
  98. if (type==1){
  99. tOrderNewMapper.updateExamineName(1,depId,aid);
  100. newOrderChangeMapper.updateExamineName(1,depId,aid);
  101. tOrderInvoiceMapper.updateExamineName(1,depId,aid);
  102. }else if (type==2){
  103. tOrderInvoiceMapper.updateListExamineName(2,depId);
  104. }else if (type==3){
  105. tOrderNewMapper.updateExamineName(3,depId,aid);
  106. newOrderChangeMapper.updateExamineName(5,depId,aid);
  107. tOrderInvoiceMapper.updateExamineName(0,depId,aid);
  108. }
  109. }
  110. }