AsyncUtils.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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.bo.OrderOperator;
  10. import com.goafanti.common.constant.AFTConstants;
  11. import com.goafanti.common.dao.*;
  12. import com.goafanti.common.enums.NoticeStatus;
  13. import com.goafanti.common.model.*;
  14. import com.goafanti.core.shiro.token.TokenManager;
  15. import com.goafanti.order.bo.NewOrderChangeBo;
  16. import com.goafanti.order.enums.OrderChangeProcess;
  17. import com.goafanti.order.enums.ProcessStatus;
  18. import org.apache.ibatis.annotations.Param;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.scheduling.annotation.Async;
  21. import org.springframework.stereotype.Component;
  22. import com.goafanti.common.bo.EmailBo;
  23. import com.goafanti.common.enums.NoticeTypes;
  24. @Component
  25. @Async
  26. public class AsyncUtils {
  27. @Autowired
  28. private NoticeMapper noticeMapper;
  29. @Autowired
  30. private AdminMapper adminMapper;
  31. @Autowired
  32. private TOrderNewMapper tOrderNewMapper;
  33. @Autowired
  34. private NewOrderChangeMapper newOrderChangeMapper;
  35. @Autowired
  36. private TOrderInvoiceMapper tOrderInvoiceMapper;
  37. @Autowired
  38. private TOrderTaskMapper tOrderTaskMapper;
  39. public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
  40. SendEmailUtil.getInstance().patentSend(bo);
  41. }
  42. public void sendList(List<EmailBo> list) throws MessagingException, UnsupportedEncodingException {
  43. for (EmailBo emailBo : list) {
  44. SendEmailUtil.getInstance().patentSend(emailBo);
  45. }
  46. }
  47. public void send(EmailBo bo){
  48. try {
  49. SendEmailUtil.getInstance().send(bo);
  50. } catch (UnsupportedEncodingException | MessagingException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. public void addNotice(Notice n ) {
  55. n.setType(NoticeTypes.getType(n.getNoticeType()));
  56. noticeMapper.insertSelective(n);
  57. }
  58. public void addNotic(Integer type, String aid,String str) {
  59. Notice n =new Notice();
  60. n.setId(UUID.randomUUID().toString());
  61. n.setAid(aid);
  62. n.setNoticeType(type);
  63. n.setContent(str);
  64. n.setReaded(0);//未读
  65. addNotice(n);
  66. }
  67. public void addNoticAndEmail(Notice n) {
  68. n.setType(NoticeTypes.getType(n.getNoticeType()));
  69. AdminListBo a = adminMapper.getDeptNameByAid(n.getAid());
  70. EmailBo bo=new EmailBo(NoticeStatus.getStatus(n.getNoticeType()).getDesc(),a.getEmail(),n.getContent()) ;
  71. noticeMapper.insertSelective(n);
  72. send(bo);
  73. }
  74. public void addNoticeBatch(List<Notice> ln) {
  75. List<Notice> newList=new ArrayList<Notice>();
  76. if (ln != null && ln.size() > 0) {
  77. for (int i = 0; i < ln.size(); i++) {
  78. ln.get(i).setType(NoticeTypes.getType(ln.get(i).getNoticeType()));
  79. newList.add(ln.get(i));
  80. if (50 == newList.size() || i == ln.size() - 1) {
  81. if (newList.size() > 0) noticeMapper.insertBatch(newList);
  82. newList.clear();
  83. try {
  84. Thread.sleep(2000);
  85. } catch (InterruptedException e) {
  86. e.printStackTrace();
  87. }
  88. }
  89. }
  90. }
  91. }
  92. public void batchUpdateUnreaded(List<String> dl) {
  93. noticeMapper.batchUpdateUnreaded(dl);
  94. }
  95. /**
  96. * 切换审核人员
  97. * @param depId 部门编号
  98. * @param aid 切换后审核人
  99. * @return
  100. */
  101. public void updateExamineName( String depId, String aid) {
  102. tOrderNewMapper.updateExamineName(3,depId,aid,null);
  103. newOrderChangeMapper.updateExamineName(5,depId,aid,null);
  104. tOrderInvoiceMapper.updateExamineName(0,depId,aid,null);
  105. }
  106. /**
  107. *
  108. * @param type 1营销管理 2公司管理 3财务管理 4咨询管理
  109. * @param id 管理员id
  110. * @param roleType
  111. */
  112. public void updateListExamineName(Integer type, String id, String roleType) {
  113. Admin admin = adminMapper.selectByPrimaryKey(id);
  114. String depId=admin.getDepartmentId();
  115. String names="";
  116. if (type==1){
  117. names=getNames(type,depId, roleType);
  118. tOrderNewMapper.updateExamineName(ProcessStatus.YPYXGLY.getCode(),depId,null,names);
  119. newOrderChangeMapper.updateExamineName(OrderChangeProcess.YXGLY.getCode(),depId,null,names);
  120. tOrderInvoiceMapper.updateExamineName(1,depId,null,names);
  121. }else if (type==2){
  122. tOrderInvoiceMapper.updateListExamineName(type,depId,roleType);
  123. }else if (type==3){
  124. names=getNames(type,depId, roleType);
  125. newOrderChangeMapper.updateExamineName(OrderChangeProcess.CWZJ.getCode(),depId,null,names);
  126. }else if (type==4){
  127. names=getNames(type,depId, roleType);
  128. tOrderNewMapper.updateExamineName(ProcessStatus.YPZXSGLY.getCode(),depId,null,names);
  129. newOrderChangeMapper.updateExamineName(OrderChangeProcess.JSZJ.getCode(),depId,null,names);
  130. }else if (type==5){
  131. newOrderChangeMapper.updateTaskExamineName(admin.getId(),admin.getId(),2);
  132. }else if (type==6){
  133. newOrderChangeMapper.updateTaskExamineName(admin.getId(),admin.getId(),3);
  134. }
  135. }
  136. private String getNames(Integer type,String depId, String roleType) {
  137. StringBuffer str=new StringBuffer();
  138. List<Admin> admins = adminMapper.selectAdminByRoleType(roleType);
  139. for (Admin admin : admins) {
  140. if (type==1&&admin.getDepartmentId().equals(depId)){
  141. str = str.append(admin.getName()).append(",");
  142. }else if(type!=1){
  143. str = str.append(admin.getName()).append(",");
  144. }
  145. }
  146. if (str.length()>1)return str.substring(0,str.length()-1);
  147. else return "暂无";
  148. }
  149. /**
  150. *
  151. * @param type 发送对象 0营销管理员 1 通知所有人
  152. * @param sotpType 发送对象 类型 0=项目暂停,1=项目重启
  153. *
  154. */
  155. public void addProjectSotpNotic(Integer type, Integer sotpType, String ids, TOrderTask task) {
  156. Integer noticeType=0;
  157. if (type==0){
  158. noticeType=sotpType==0?NoticeStatus.PROJECT_SOPT_START.getCode() :NoticeStatus.PROJECT_RENEW_START.getCode();
  159. String[] split = ids.split(",");
  160. task = tOrderTaskMapper.selectByPrimaryKey(Integer.valueOf(split[0]));
  161. String str=String.format("订单编号[%s]项目编号[%s],请及时审核",task.getOrderNo(),ids);
  162. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(task.getOrderNo());
  163. List<Admin> admins = adminMapper.listAdminBydepIdAndRoleType(tOrderNew.getOrderDep(),AFTConstants.SALESMAN_ADMIN);
  164. for (Admin admin : admins) {
  165. addNotic( noticeType,admin.getId(), str);
  166. }
  167. }else if(type==1){
  168. String str=String.format("订单编号[%s]项目编号[%s],已%s请悉知。",task.getOrderNo(),task.getId(),sotpType==1?"恢复":"暂停");
  169. noticeType=sotpType==0?NoticeStatus.PROJECT_SOPT_YES.getCode() :NoticeStatus.PROJECT_RENEW_YES.getCode();
  170. List<String> list = new ArrayList<>();
  171. if (task.getConsultantId()!=null)list.add(task.getConsultantId());
  172. if (task.getManagerId()!=null)list.add(task.getManagerId());
  173. OrderOperator orderOperator = tOrderTaskMapper.selectAidByParam(task.getId());
  174. if (orderOperator.getFinanceId()!=null)list.add(orderOperator.getFinanceId());
  175. if (orderOperator.getSalesmanId()!=null)list.add(orderOperator.getSalesmanId());
  176. List<Admin> cwgly = adminMapper.selectAdminByRoleType(AFTConstants.FINANCE_ADMIN);
  177. for (Admin admin : cwgly) {
  178. list.add(admin.getId());
  179. }
  180. List<Admin> zxsgly = adminMapper.selectAdminByRoleType(AFTConstants.TECH_ADMIN);
  181. for (Admin admin : zxsgly) {
  182. list.add(admin.getId());
  183. }
  184. List<Admin> zc = adminMapper.selectAdminByRoleType(AFTConstants.CED);
  185. for (Admin admin : zc) {
  186. list.add(admin.getId());
  187. }
  188. List<Admin> dsz = adminMapper.selectAdminByRoleType(AFTConstants.APPROVAL_DECISION);
  189. for (Admin admin : dsz) {
  190. list.add(admin.getId());
  191. }
  192. if (!list.isEmpty()){
  193. List<Notice> notes=new ArrayList<>();
  194. StringBuffer emails=new StringBuffer();
  195. for (String s : list) {
  196. notes.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, s,
  197. noticeType, str));
  198. emails=emails.append(s).append(",");
  199. }
  200. noticeMapper.insertBatch(notes);
  201. System.out.println(emails.substring(0,emails.length()-1));
  202. send(new EmailBo(NoticeStatus.getValueByCode(noticeType),emails.substring(0,emails.length()-1),str));
  203. }
  204. }
  205. }
  206. }