package com.goafanti.common.utils; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; import javax.mail.MessagingException; import com.goafanti.admin.bo.AdminListBo; import com.goafanti.common.dao.*; import com.goafanti.common.enums.NoticeStatus; import com.goafanti.common.model.Admin; import com.goafanti.common.model.TChangeTask; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.order.bo.NewOrderChangeBo; 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.enums.NoticeTypes; import com.goafanti.common.model.Notice; @Component @Async public class AsyncUtils { @Autowired private NoticeMapper noticeMapper; @Autowired private AdminMapper adminMapper; @Autowired private TOrderNewMapper tOrderNewMapper; @Autowired private NewOrderChangeMapper newOrderChangeMapper; @Autowired private TOrderInvoiceMapper tOrderInvoiceMapper; public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException { SendEmailUtil.getInstance().patentSend(bo); } public void sendList(List 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 addNotic(Integer type, String aid,String str) { Notice n =new Notice(); n.setId(UUID.randomUUID().toString()); n.setAid(aid); n.setNoticeType(type); n.setContent(str); n.setReaded(0);//未读 addNotice(n); } public void addNoticAndEmail(Notice n) { n.setType(NoticeTypes.getType(n.getNoticeType())); AdminListBo a = adminMapper.getDeptNameByAid(n.getAid()); EmailBo bo=new EmailBo(NoticeStatus.getStatus(n.getNoticeType()).getDesc(),a.getEmail(),n.getContent()) ; noticeMapper.insertSelective(n); send(bo); } public void addNoticeBatch(List ln) { List newList=new ArrayList(); 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 dl) { noticeMapper.batchUpdateUnreaded(dl); } /** * 切换审核人员 * @param type 1营销管理 2公司管理 3财务 * @param depId 部门编号 * @param aid 切换后审核人 * @return */ public void updateexamineName(Integer type, String depId, String aid) { if (type==1){ tOrderNewMapper.updateExamineName(1,depId,aid); newOrderChangeMapper.updateExamineName(1,depId,aid); tOrderInvoiceMapper.updateExamineName(1,depId,aid); }else if (type==2){ tOrderInvoiceMapper.updateListExamineName(2,depId); }else if (type==3){ tOrderNewMapper.updateExamineName(3,depId,aid); newOrderChangeMapper.updateExamineName(5,depId,aid); tOrderInvoiceMapper.updateExamineName(0,depId,aid); } } }