From ee2316e2cb7afde1c54f5e4216a1b0d1e055749e Mon Sep 17 00:00:00 2001 From: xinyb <574600396@qq.com> Date: 星期五, 27 九月 2024 17:33:14 +0800 Subject: [PATCH] CRM邮箱配置调整 --- src/com/yc/crm/mail/action/MailController.java | 648 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 518 insertions(+), 130 deletions(-) diff --git a/src/com/yc/crm/mail/action/MailController.java b/src/com/yc/crm/mail/action/MailController.java index 23c7349..fcfabb9 100644 --- a/src/com/yc/crm/mail/action/MailController.java +++ b/src/com/yc/crm/mail/action/MailController.java @@ -1,22 +1,32 @@ package com.yc.crm.mail.action; -import com.yc.crm.mail.entity.T482102Entity; -import com.yc.crm.mail.entity.t482101HEntity; +import com.yc.crm.mail.entity.*; import com.yc.crm.mail.service.MailAccountIfc; +import com.yc.crm.mail.service.MailFileIfc; import com.yc.crm.mail.service.MailIfc; +import com.yc.crm.mail.service.MailServiceIfc; import com.yc.crm.mail.util.AllBackMsg; +import com.yc.entity.AttachmentConfig; import com.yc.entity.DataSourceEntity; +import com.yc.entity.attachment.AttachmentEntity; +import com.yc.factory.FactoryBean; import com.yc.multiData.MultiDataSource; import com.yc.multiData.SpObserver; import com.yc.utils.SessionKey; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.web.bind.annotation.*; +import javax.mail.MessagingException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -28,16 +38,77 @@ */ @CrossOrigin @RestController -@RequestMapping("/crm/mail/") +@RequestMapping("/crm/mail") public class MailController { + ThreadPoolTaskExecutor threadPoolExecutor = (ThreadPoolTaskExecutor) FactoryBean.getBean("threadPoolExecutor");//绾跨▼姹� + + final static String shoppingImageServer = AttachmentConfig.get("attachment.server"); @Autowired MailAccountIfc emailAccountIfc; @Autowired MailIfc emailIfc; + @Autowired + MailServiceIfc mailServiceIfc; + @Autowired + MailFileIfc mailFileIfc; private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"); + + /** + * 宸﹁竟缁撴瀯涓婂眰 + * + * @return + */ + @GetMapping("/getEmailModule.do") + public AllBackMsg getEmailModule(HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + List<MailModuleEntity> list = emailIfc.getMailModuleList(userCode); + msg.setSuccess("鎵ц鎴愬姛", list); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 宸﹁竟缁撴瀯涓嬪眰 + * + * @return + */ + @GetMapping("/getEmailModuleBelow.do") + public AllBackMsg getEmailModuleBelow(HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + List<MailModuleBelowEntity> list = emailIfc.getMailModuleBelowList(userCode); + msg.setSuccess("鎵ц鎴愬姛", list); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } /** * 鑾峰彇閭欢鍒楄〃锛堝寘鎷崏绋跨锛屾敹浠剁锛� @@ -45,29 +116,80 @@ * @return */ @GetMapping("/getMailList.do") - public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception { + public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType, + @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception { AllBackMsg msg = new AllBackMsg(); try { -// HttpSession session = request.getSession(); -// String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 -// if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 -// msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); -// return msg; -// } if (StringUtils.isNotBlank(mail)) { if (!EMAIL_PATTERN.matcher(mail).matches()) { msg.setFail("閭鐨勫悇寮忎笉浜夊彇"); return msg; } } + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� - List<t482101HEntity> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead); + List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode, page, limit); + Map<String, Object> map = new HashMap<>(); + map.put("page", page); + map.put("limit", limit); if (t482101HEntityList.size() > 0) { - msg.setSuccess("鎿嶄綔瀹屾垚", t482101HEntityList); + map.put("total", emailIfc.getMailTotal(mail, mailType, isNoRead, null, userCode)); + map.put("list", t482101HEntityList); + } else { + map.put("list", new ArrayList<>()); } + msg.setSuccess("鎵ц瀹屾垚", map); } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 鑾峰彇寰呭鐞嗛偖浠跺垪琛� + * + * @return + */ + @GetMapping("/getHandleMailList.do") + public AllBackMsg getHandleMailList(String mail, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, + HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + if (StringUtils.isNotBlank(mail)) { + if (!EMAIL_PATTERN.matcher(mail).matches()) { + msg.setFail("閭鐨勫悇寮忎笉浜夊彇"); + return msg; + } + } + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode, page, limit); + Map<String, Object> map = new HashMap<>(); + map.put("page", page); + map.put("limit", limit); + if (t482101HEntityList.size() > 0) { + map.put("total", emailIfc.getMailTotal(mail, 3, false, null, userCode)); + map.put("list", t482101HEntityList); + } else { + map.put("list", new ArrayList<>()); + } + msg.setSuccess("鎵ц瀹屾垚", map); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } @@ -80,33 +202,32 @@ * @return */ @GetMapping("/getMailInfo.do") - public AllBackMsg getMailInfo(String mail, String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception { + public AllBackMsg getMailInfo(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception { AllBackMsg msg = new AllBackMsg(); try { -// HttpSession session = request.getSession(); -// String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 -// if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 -// msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); -// return msg; -// } if (StringUtils.isBlank(docCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 msg.setFail("缂哄皯閭鍞竴鐮乨ocCode,璇锋鏌�"); return msg; } - if (StringUtils.isNotBlank(mail)) { - if (!EMAIL_PATTERN.matcher(mail).matches()) { - msg.setFail("閭鐨勬牸寮忎笉姝g‘"); - return msg; - } - } DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� - t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(mail, docCode); + t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode); if (t482101HEntity != null) { - msg.setSuccess("鎿嶄綔瀹屾垚", t482101HEntity); + if (StringUtils.isNotBlank(t482101HEntity.getAttachmentList())) {//闄勪欢鐨勫鐞� + //鑾峰彇鍒伴檮浠跺唴瀹� + List<AttachmentEntity> attachmentEntities = mailFileIfc.getAttachmentEntityList(t482101HEntity.getAttachmentList()); + List<String> list = new ArrayList<>(); + if (attachmentEntities.size() > 0) { + for (AttachmentEntity a : attachmentEntities) { + list.add(shoppingImageServer + "/uploads/email/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile()); + } + t482101HEntity.setAttachmentPath(list); + } + } + msg.setSuccess("鎵ц瀹屾垚", t482101HEntity); } } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } @@ -114,26 +235,79 @@ } /** - * 鑾峰彇閭欢璇︽儏 + * 鍒犻櫎閭欢 * * @return */ - @GetMapping("/deleteReceivingMail.do") - public AllBackMsg deleteReceivingMail(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception { + @PostMapping("/deleteEmail.do") + public AllBackMsg deleteEmail(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception { AllBackMsg msg = new AllBackMsg(); try { - if (StringUtils.isBlank(docCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 - msg.setFail("缂哄皯閭鍞竴鐮乨ocCode,璇锋鏌�"); + if (docCode == null && docCode.size() == 0) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("璇烽�変腑鍒犻櫎鐨勯偖浠�"); + return msg; + } + String arrayCode = StringUtils.join(docCode, ","); + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); return msg; } DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� - Integer cont = emailIfc.deleteReceivingMail(docCode); + Integer cont = emailIfc.deleteEmail(userCode, arrayCode); if (cont > 0) { - msg.setSuccess("鎿嶄綔瀹屾垚", "閭欢宸插垹闄�"); + msg.setOk("宸插垹闄�"); } } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 蹇�熷洖澶� + * + * @return + */ + @PostMapping("/setQuickReply.do") + public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + if (reply.get("docCode") == null) { + msg.setFail("鑾峰彇涓嶅埌鍥炲閭欢鐨勫敮涓�docCode鍊�"); + return msg; + } + if (reply.get("content") == null) { + msg.setFail("璇疯緭鍏ュ洖澶嶅唴瀹�"); + return msg; + } + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + String docCode = (String) reply.get("docCode");//缂栧彿 + String content = (String) reply.get("content");//鍐呭 + Integer count = mailServiceIfc.setQuickReply(docCode, content); + Map<String, Object> map = new HashMap<>(); + if (count.equals(1)) { + map.put("code", 0); + map.put("docCode", docCode); + map.put("msg", "閭欢宸插洖澶�"); + msg.setSuccess("鎵ц鎴愬姛", map); + } else { + map.put("code", -1); + map.put("docCode", docCode); + map.put("msg", "閭欢鍥炲澶辫触"); + msg.setSuccess("鎵ц鎴愬姛", map); + } + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } @@ -161,11 +335,14 @@ return msg; } } - if (StringUtils.isNotBlank(t482101H.getReceiver())) { - if (!EMAIL_PATTERN.matcher(t482101H.getReceiver()).matches()) { - msg.setFail("鏀朵欢浜洪偖绠憋細" + t482101H.getReceiver() + "鐨勬牸寮忎笉姝g‘"); - return msg; + if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) { + for (String mail : t482101H.getReceiver()) { + if (!EMAIL_PATTERN.matcher(mail).matches()) { + msg.setFail("鏀朵欢浜洪偖绠憋細" + mail + "鐨勬牸寮忎笉姝g‘"); + return msg; + } } + } String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID); String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME); @@ -175,91 +352,16 @@ t482101H.setUserCode(userCode); t482101H.setUserName(userName); t482101H.setMailType(0);//鑽夌 + t482101H.setReadFlag(1);//宸茶 + t482101H.setAttachmentList(t482101H.getAttachmentList()); DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� t482101H = emailIfc.saveReceivingMail(t482101H); - msg.setSuccess("鎿嶄綔瀹屾垚", "鎵ц鎴愬姛"); + Map<String, Object> map = new HashMap<>(); + map.put("docCode", t482101H.getDocCode()); + msg.setSuccess("鎵ц鎴愬姛", map); } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); - } finally { - SpObserver.setDBtoInstance(); - } - return msg; - } - - /** - * 鍒犻櫎鑽夌绠� - * - * @return - */ - @GetMapping("/deleteMailDrafts.do") - public AllBackMsg deleteMailDrafts(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception { - AllBackMsg msg = new AllBackMsg(); - try { - if (StringUtils.isBlank(docCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 - msg.setFail("缂哄皯閭鍞竴鐮乨ocCode,璇锋鏌�"); - return msg; - } - DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� - SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� - int cont = emailIfc.deleteMailDrafts(docCode); - if (cont > 0) { - msg.setSuccess("鎿嶄綔瀹屾垚", "鍒犻櫎鎴愬姛"); - } - } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); - } finally { - SpObserver.setDBtoInstance(); - } - return msg; - } - - /** - * 鍙戦�侀偖浠� - * - * @param request - * @param response - * @return - */ - @PostMapping("/sendingMail.do") - public AllBackMsg sendingMail(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception { - AllBackMsg msg = new AllBackMsg(); - try { - HttpSession session = request.getSession(); - String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 - if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 - msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); - return msg; - } - if (StringUtils.isNotBlank(t482101H.getSender())) { - if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) { - msg.setFail("鍙戦�佷汉閭:" + t482101H.getSender() + "鐨勬牸寮忎笉姝g‘"); - return msg; - } - } - if (StringUtils.isNotBlank(t482101H.getReceiver())) { - if (!EMAIL_PATTERN.matcher(t482101H.getReceiver()).matches()) { - msg.setFail("鏀朵欢浜洪偖绠憋細" + t482101H.getReceiver() + "鐨勬牸寮忎笉姝g‘"); - return msg; - } - } - String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID); - String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME); - String userName = (String) session.getAttribute(SessionKey.USER_NAME); - t482101H.setCompanyId(companyId); - t482101H.setCompanyName(companyName); - t482101H.setUserCode(userCode); - t482101H.setUserName(userName); - t482101H.setMailType(2);//鍙戜欢 - DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� - SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� - //鏈夊彂閫佺殑閭欢淇濆瓨鍒板悗鍙版暟鎹簱 - t482101H = emailIfc.saveReceivingMail(t482101H); - //鍙戦�� - emailIfc.sendingMail(t482101H, request); - msg.setSuccess("鎵ц鎴愬姛", "鍙戦�佹垚鍔�"); - } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } @@ -268,7 +370,7 @@ /** - * 鎺ユ敹閭欢鍐呭 + * 鏀堕偖浠� * * @param request * @param response @@ -293,21 +395,307 @@ DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� //鏍规嵁褰撳墠鐢ㄦ埛鏌ヨ缁戝畾鐨勯偖绠变俊鎭� - List<T482102Entity> emailEntities = emailAccountIfc.getAccount(userCode, mail);//杩斿洖閭鐨勮处鍙蜂俊鎭� - if (emailEntities.size() > 0) { - for (T482102Entity e : emailEntities) {//閬嶅巻鐢ㄦ埛缁戝畾閭 - List<t482101HEntity> mails = emailIfc.getMailReceiving(e, request); - emailIfc.saveReceivingMailList(mails);//淇濆瓨 + List<T482102Entity> emailEntities = new ArrayList<>(); + if (StringUtils.isBlank(mail)) { + emailEntities = emailAccountIfc.getAccount(userCode);//杩斿洖閭鐨勮处鍙蜂俊鎭� + } else { + T482102Entity T482102 = emailAccountIfc.getAccountInfo(userCode, mail); + if (T482102 != null) { + emailEntities.add(T482102); } - msg.setSuccess("鎿嶄綔瀹屾垚", "淇濆瓨鎴愬姛"); + } + if (emailEntities.size() > 0) { + List<t482101HEntity> mails = new ArrayList<>(); + Map<String, Object> map = new HashMap<>(); + for (T482102Entity e : emailEntities) {//閬嶅巻鐢ㄦ埛缁戝畾閭 + //澶氱嚎绋嬫敹閭欢 + threadPoolExecutor.execute(new ReceivingEmailsSave(mailServiceIfc, e, new FoundationEntity(request))); + } + map.put("code", 0); + map.put("msg", "璇烽攢绛夛紝閭欢姝e湪绯荤粺淇濆瓨"); + msg.setSuccess("鎵ц鎴愬姛", map); } else { msg.setFail("娌℃湁鎵惧埌缁戝畾鐨勯偖绠变俊鎭�"); } } catch (Exception e) { - msg.setError("鎵ц鍑洪敊", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } + + + /** + * 鍙戦偖浠� + * + * @param request + * @param response + * @return + */ + @PostMapping("/sendingMail.do") + public AllBackMsg sendingMail(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + if (StringUtils.isNotBlank(t482101H.getSender())) { + if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) { + msg.setFail("鍙戦�佷汉閭:" + t482101H.getSender() + "鐨勬牸寮忎笉姝g‘"); + return msg; + } + } + if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) { + for (String mail : t482101H.getReceiver()) { + if (!EMAIL_PATTERN.matcher(mail).matches()) { + msg.setFail("鏀朵欢浜洪偖绠憋細" + mail + "鐨勬牸寮忎笉姝g‘"); + return msg; + } + } + + } + String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID); + String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME); + String userName = (String) session.getAttribute(SessionKey.USER_NAME); + t482101H.setCompanyId(companyId); + t482101H.setCompanyName(companyName); + t482101H.setUserCode(userCode); + t482101H.setUserName(userName); + t482101H.setMailType(2);//鍙戜欢 + t482101H.setAttachmentList(t482101H.getAttachmentList()); + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + //鍙戦�� + mailServiceIfc.sendEmails(t482101H, request); + msg.setOk("鍙戦�佹垚鍔�"); + } catch (MessagingException e) { + String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); + if (StringUtils.isNotBlank(error)) { + String[] arrayError = error.split("#"); + if (arrayError.length == 2) { + Map<String, Object> map = new HashMap<>(); + map.put("docCode", arrayError[1]); + msg.setError(arrayError[0], map); + } else { + msg.setFail(error); + } + } else { + msg.setFail(error); + } + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 鏍囪宸茶 + * + * @param request + * @param response + * @return + */ + @PostMapping("/updateRead.do") + public AllBackMsg updateRead(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + List<String> docCode = (List<String>) map.get("list"); + if (docCode == null && docCode.size() == 0) { + msg.setFail("璇烽�夋嫨鏍囪閭欢"); + return msg; + } + if (map.get("status") == null) { + msg.setFail("璇蜂紶鍏ョ姸鎬佸��"); + return msg; + } + boolean read = (Boolean) map.get("status"); + String arrayCode = StringUtils.join(docCode, ","); + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + emailIfc.updateRead(arrayCode, read); + msg.setOk("鏍囪鎴愬姛"); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 绉诲姩閭欢鍒嗙被 + * + * @param request + * @param response + * @return + */ + @PostMapping("/updateMailType.do") + public AllBackMsg updateMailType(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + if (map.get("docCode") == null) { + msg.setFail("鑾峰彇涓嶅埌绉诲姩閭欢缂栧彿docCode"); + return msg; + } + String docCode = (String) map.get("docCode"); + Integer folderId = map.get("folderId") == null ? 0 : (Integer) map.get("folderId"); + List<String> tagArray = (List<String>) map.get("tagId"); + if (folderId.equals(0) && (tagArray == null || tagArray.size() == 0)) { + msg.setFail("绉诲姩閭欢鍒嗙被涓嶈兘涓虹┖"); + return msg; + } + String tagId = ""; + if (tagArray != null && tagArray.size() > 0) { + tagId = StringUtils.join(tagArray, ","); + } + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + emailIfc.updateMailType(docCode, folderId, tagId); + msg.setOk("绉诲姩鎴愬姛"); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 鍔犺浇涓嶅悓鐩綍閲岀殑閭欢 + * + * @param request + * @param response + * @return + */ + @GetMapping("/classificationMail.do") + public AllBackMsg classificationMail(@RequestParam(defaultValue = "-1") Integer id, String type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, + HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + if (id == null || id.equals(-1)) { + msg.setFail("鑾峰彇涓嶅埌鏂囦欢Id"); + return msg; + } + if (StringUtils.isBlank(type)) { + msg.setFail("鑾峰彇涓嶅埌鏂囦欢绫诲瀷"); + return msg; + } + type = type + "_" + id;//缁勮涓� + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + List<t482101HList> t482101 = emailIfc.getFolderMailList(type, userCode, page, limit); + Map<String, Object> map = new HashMap<>(); + map.put("page", page); + map.put("limit", limit); + if (t482101.size() > 0) { + map.put("total", emailIfc.getMailTotal(null, 6, false, type, userCode)); + map.put("list", t482101); + } else { + map.put("list", new ArrayList<>()); + } + msg.setSuccess("鎵ц瀹屾垚", map); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 寰呭鐞嗛偖浠� + * + * @param request + * @param response + * @return + */ + @PostMapping("/updateHandle.do") + public AllBackMsg updateHandle(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws Exception { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛 + if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫 + msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅"); + return msg; + } + if (param.get("docCode") == null) { + msg.setFail("閭欢鍞竴鏍囪瘑docCode涓嶈兘绌�"); + return msg; + } + if (param.get("handleTime") == null) { + msg.setFail("寰呭鐞嗘椂闂翠笉鑳界┖"); + return msg; + } + List<String> docCode = (List<String>) param.get("docCode"); + String handleTime = (String) param.get("handleTime"); + // 姝e垯琛ㄨ揪寮忥紝鐢ㄤ簬鍖归厤鏃ユ湡鏍煎紡 + String regex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(handleTime); + if (!matcher.matches()) { + msg.setFail("寰呭鐞嗘棩鏈熸牸寮忎负锛歽yyy-MM-dd HH:mm锛堝锛�1900-08-01 08:00锛夈�傝妫�鏌�"); + return msg; + } + DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭� + SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧� + emailIfc.updateMailHandle(handleTime, StringUtils.join(docCode, ",")); + msg.setOk("鎴愬姛鏍囪涓哄緟澶勭悊閭欢"); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + private class ReceivingEmailsSave implements Runnable { + final MailServiceIfc mailServiceIfc; + final T482102Entity t482102; + final FoundationEntity foundation; + + public ReceivingEmailsSave(MailServiceIfc mailServiceIfc, T482102Entity t482102, FoundationEntity foundation) { + this.mailServiceIfc = mailServiceIfc; + this.t482102 = t482102; + this.foundation = foundation; + } + + @Override + public void run() { + try { + SpObserver.setDBtoInstance("_" + foundation.getDbId()); + //鏀堕偖浠� + mailServiceIfc.receivingEmails(t482102, foundation); + } catch (Exception e) { + e.printStackTrace(); + } finally { + SpObserver.setDBtoInstance(); + } + } + } + } -- Gitblit v1.8.0