xinyb
6 天以前 aad276da26b3b44b7622343fa0bf15583e803585
提交 | 用户 | age
385e2d 1 package com.yc.crm.mail.action;
X 2
7caeae 3 import com.yc.crm.mail.entity.*;
385e2d 4 import com.yc.crm.mail.service.MailAccountIfc;
195685 5 import com.yc.crm.mail.service.MailFileIfc;
385e2d 6 import com.yc.crm.mail.service.MailIfc;
7caeae 7 import com.yc.crm.mail.service.MailServiceIfc;
385e2d 8 import com.yc.crm.mail.util.AllBackMsg;
7cf738 9 import com.yc.entity.AttachmentConfig;
385e2d 10 import com.yc.entity.DataSourceEntity;
ad7c8d 11 import com.yc.entity.attachment.AttachmentEntity;
7caeae 12 import com.yc.factory.FactoryBean;
385e2d 13 import com.yc.multiData.MultiDataSource;
X 14 import com.yc.multiData.SpObserver;
15 import com.yc.utils.SessionKey;
16 import org.apache.commons.lang3.StringUtils;
17 import org.springframework.beans.factory.annotation.Autowired;
7caeae 18 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
385e2d 19 import org.springframework.web.bind.annotation.*;
X 20
f6ae0b 21 import javax.mail.MessagingException;
385e2d 22 import javax.servlet.http.HttpServletRequest;
X 23 import javax.servlet.http.HttpServletResponse;
24 import javax.servlet.http.HttpSession;
f5cc47 25 import java.util.ArrayList;
X 26 import java.util.HashMap;
385e2d 27 import java.util.List;
f5cc47 28 import java.util.Map;
562e20 29 import java.util.regex.Matcher;
385e2d 30 import java.util.regex.Pattern;
X 31
32 /**
33  * @BelongsProject: eCoWorksV3
34  * @BelongsPackage: com.yc.crm.mail.action
35  * @author: xinyb
36  * @CreateTime: 2024-08-07  17:30
37  * @Description: 邮箱发送 收件
38  */
39 @CrossOrigin
40 @RestController
f5cc47 41 @RequestMapping("/crm/mail")
385e2d 42 public class MailController {
7caeae 43     ThreadPoolTaskExecutor threadPoolExecutor = (ThreadPoolTaskExecutor) FactoryBean.getBean("threadPoolExecutor");//线程池
7cf738 44
X 45     final static String shoppingImageServer = AttachmentConfig.get("attachment.server");
385e2d 46     @Autowired
X 47     MailAccountIfc emailAccountIfc;
48     @Autowired
49     MailIfc emailIfc;
7caeae 50     @Autowired
X 51     MailServiceIfc mailServiceIfc;
195685 52     @Autowired
X 53     MailFileIfc mailFileIfc;
385e2d 54
X 55     private static final Pattern EMAIL_PATTERN =
56             Pattern.compile("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$");
57
d8f4b9 58
X 59     /**
658898 60      * 左边结构上层
d8f4b9 61      *
X 62      * @return
63      */
64     @GetMapping("/getEmailModule.do")
65     public AllBackMsg getEmailModule(HttpServletRequest request, HttpServletResponse response) throws Exception {
66         AllBackMsg msg = new AllBackMsg();
67         try {
68             HttpSession session = request.getSession();
69             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
70             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
71                 msg.setFail("获取不到用户信息");
72                 return msg;
73             }
74             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
75             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
76             List<MailModuleEntity> list = emailIfc.getMailModuleList(userCode);
77             msg.setSuccess("执行成功", list);
78         } catch (Exception e) {
79             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
80         } finally {
81             SpObserver.setDBtoInstance();
82         }
83         return msg;
84     }
aad276 85
658898 86     /**
X 87      * 左边结构下层
88      *
89      * @return
90      */
91     @GetMapping("/getEmailModuleBelow.do")
92     public AllBackMsg getEmailModuleBelow(HttpServletRequest request, HttpServletResponse response) throws Exception {
93         AllBackMsg msg = new AllBackMsg();
94         try {
95             HttpSession session = request.getSession();
96             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
97             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
98                 msg.setFail("获取不到用户信息");
99                 return msg;
100             }
101             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
102             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
aad276 103             List<MailModuleBelowEntity> list = emailIfc.getMailModuleBelowList(userCode);
658898 104             msg.setSuccess("执行成功", list);
X 105         } catch (Exception e) {
106             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
107         } finally {
108             SpObserver.setDBtoInstance();
109         }
110         return msg;
111     }
385e2d 112
X 113     /**
114      * 获取邮件列表(包括草稿箱,收件箱)
115      *
116      * @return
117      */
118     @GetMapping("/getMailList.do")
195685 119     public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType,
562e20 120                                   @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 121         AllBackMsg msg = new AllBackMsg();
X 122         try {
123             if (StringUtils.isNotBlank(mail)) {
124                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
125                     msg.setFail("邮箱的各式不争取");
126                     return msg;
127                 }
128             }
5b1a4a 129             HttpSession session = request.getSession();
X 130             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
131             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
132                 msg.setFail("获取不到用户信息");
133                 return msg;
134             }
385e2d 135             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 136             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 137             List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode, page, limit);
aad276 138             Map<String, Object> map = new HashMap<>();
X 139             map.put("page", page);
140             map.put("limit", limit);
385e2d 141             if (t482101HEntityList.size() > 0) {
aad276 142                 map.put("total", emailIfc.getMailTotal(mail, mailType, isNoRead, null, userCode));
X 143                 map.put("list", t482101HEntityList);
144             } else {
145                 map.put("list", new ArrayList<>());
385e2d 146             }
aad276 147             msg.setSuccess("执行完成", map);
385e2d 148         } catch (Exception e) {
f5cc47 149             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 150         } finally {
X 151             SpObserver.setDBtoInstance();
152         }
153         return msg;
154     }
155
156     /**
57c8bf 157      * 获取待处理邮件列表
X 158      *
159      * @return
160      */
161     @GetMapping("/getHandleMailList.do")
562e20 162     public AllBackMsg getHandleMailList(String mail, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,
195685 163                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
57c8bf 164         AllBackMsg msg = new AllBackMsg();
X 165         try {
166             if (StringUtils.isNotBlank(mail)) {
167                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
168                     msg.setFail("邮箱的各式不争取");
169                     return msg;
170                 }
171             }
172             HttpSession session = request.getSession();
173             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
174             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
175                 msg.setFail("获取不到用户信息");
176                 return msg;
177             }
178             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
179             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 180             List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode, page, limit);
aad276 181             Map<String, Object> map = new HashMap<>();
X 182             map.put("page", page);
183             map.put("limit", limit);
57c8bf 184             if (t482101HEntityList.size() > 0) {
aad276 185                 map.put("total", emailIfc.getMailTotal(mail, 3, false, null, userCode));
X 186                 map.put("list", t482101HEntityList);
187             } else {
188                 map.put("list", new ArrayList<>());
57c8bf 189             }
aad276 190             msg.setSuccess("执行完成", map);
57c8bf 191         } catch (Exception e) {
X 192             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
193         } finally {
194             SpObserver.setDBtoInstance();
195         }
196         return msg;
197     }
198
199     /**
385e2d 200      * 获取邮件详情
X 201      *
202      * @return
203      */
204     @GetMapping("/getMailInfo.do")
f4c162 205     public AllBackMsg getMailInfo(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 206         AllBackMsg msg = new AllBackMsg();
X 207         try {
208             if (StringUtils.isBlank(docCode)) {//获取不到当前用户直接结束
209                 msg.setFail("缺少邮箱唯一码docCode,请检查");
210                 return msg;
211             }
212             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
213             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
f4c162 214             t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
385e2d 215             if (t482101HEntity != null) {
7cf738 216                 if (StringUtils.isNotBlank(t482101HEntity.getAttachmentList())) {//附件的处理
ad7c8d 217                     //获取到附件内容
195685 218                     List<AttachmentEntity> attachmentEntities = mailFileIfc.getAttachmentEntityList(t482101HEntity.getAttachmentList());
7cf738 219                     List<String> list = new ArrayList<>();
ad7c8d 220                     if (attachmentEntities.size() > 0) {
X 221                         for (AttachmentEntity a : attachmentEntities) {
195685 222                             list.add(shoppingImageServer + "/uploads/email/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile());
7cf738 223                         }
X 224                         t482101HEntity.setAttachmentPath(list);
225                     }
226                 }
f5cc47 227                 msg.setSuccess("执行完成", t482101HEntity);
385e2d 228             }
X 229         } catch (Exception e) {
f5cc47 230             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 231         } finally {
X 232             SpObserver.setDBtoInstance();
233         }
234         return msg;
235     }
236
237     /**
f4c162 238      * 删除邮件
385e2d 239      *
X 240      * @return
241      */
5b1a4a 242     @PostMapping("/deleteEmail.do")
X 243     public AllBackMsg deleteEmail(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 244         AllBackMsg msg = new AllBackMsg();
X 245         try {
f4c162 246             if (docCode == null && docCode.size() == 0) {//获取不到当前用户直接结束
X 247                 msg.setFail("请选中删除的邮件");
385e2d 248                 return msg;
X 249             }
f4c162 250             String arrayCode = StringUtils.join(docCode, ",");
f5cc47 251             HttpSession session = request.getSession();
X 252             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
253             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
254                 msg.setFail("获取不到用户信息");
255                 return msg;
256             }
385e2d 257             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 258             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
5b1a4a 259             Integer cont = emailIfc.deleteEmail(userCode, arrayCode);
385e2d 260             if (cont > 0) {
5b1a4a 261                 msg.setOk("已删除");
385e2d 262             }
X 263         } catch (Exception e) {
f5cc47 264             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 265         } finally {
X 266             SpObserver.setDBtoInstance();
267         }
268         return msg;
269     }
270
271     /**
57c8bf 272      * 快速回复
X 273      *
274      * @return
275      */
276     @PostMapping("/setQuickReply.do")
277     public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception {
278         AllBackMsg msg = new AllBackMsg();
279         try {
280             if (reply.get("docCode") == null) {
281                 msg.setFail("获取不到回复邮件的唯一docCode值");
282                 return msg;
283             }
284             if (reply.get("content") == null) {
285                 msg.setFail("请输入回复内容");
286                 return msg;
287             }
288             HttpSession session = request.getSession();
289             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
290             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
291                 msg.setFail("获取不到用户信息");
292                 return msg;
293             }
294             String docCode = (String) reply.get("docCode");//编号
295             String content = (String) reply.get("content");//内容
296             Integer count = mailServiceIfc.setQuickReply(docCode, content);
297             Map<String, Object> map = new HashMap<>();
298             if (count.equals(1)) {
299                 map.put("code", 0);
300                 map.put("docCode", docCode);
301                 map.put("msg", "邮件已回复");
302                 msg.setSuccess("执行成功", map);
303             } else {
304                 map.put("code", -1);
305                 map.put("docCode", docCode);
306                 map.put("msg", "邮件回复失败");
307                 msg.setSuccess("执行成功", map);
308             }
309         } catch (Exception e) {
310             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
311         } finally {
312             SpObserver.setDBtoInstance();
313         }
314         return msg;
315     }
316
317     /**
385e2d 318      * 保存草稿箱(保存或修改)
X 319      *
320      * @return
321      */
322     @PostMapping("/saveMailDrafts.do")
323     public AllBackMsg saveMailDrafts(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
324         AllBackMsg msg = new AllBackMsg();
325         try {
326             HttpSession session = request.getSession();
327             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
328             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
329                 msg.setFail("获取不到用户信息");
330                 return msg;
331             }
332             if (StringUtils.isNotBlank(t482101H.getSender())) {
333                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
334                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
335                     return msg;
336                 }
337             }
5b1a4a 338             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 339                 for (String mail : t482101H.getReceiver()) {
X 340                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
341                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
342                         return msg;
343                     }
385e2d 344                 }
f4c162 345
385e2d 346             }
X 347             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
348             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
349             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
350             t482101H.setCompanyId(companyId);
351             t482101H.setCompanyName(companyName);
352             t482101H.setUserCode(userCode);
353             t482101H.setUserName(userName);
354             t482101H.setMailType(0);//草稿
5b1a4a 355             t482101H.setReadFlag(1);//已读
7caeae 356             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 357             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 358             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
359             t482101H = emailIfc.saveReceivingMail(t482101H);
f5cc47 360             Map<String, Object> map = new HashMap<>();
X 361             map.put("docCode", t482101H.getDocCode());
362             msg.setSuccess("执行成功", map);
385e2d 363         } catch (Exception e) {
f5cc47 364             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 365         } finally {
X 366             SpObserver.setDBtoInstance();
367         }
368         return msg;
369     }
370
371
372     /**
7caeae 373      * 收邮件
X 374      *
375      * @param request
376      * @param response
377      * @return
378      */
379     @GetMapping("/receive.do")
380     public AllBackMsg getReceiveMail(String mail, HttpServletRequest request, HttpServletResponse response) throws Exception {
381         AllBackMsg msg = new AllBackMsg();
382         try {
383             HttpSession session = request.getSession();
384             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
385             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
386                 msg.setFail("获取不到用户信息");
387                 return msg;
388             }
389             if (StringUtils.isNotBlank(mail)) {
390                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
391                     msg.setFail("请输入有效的邮箱");
392                     return msg;
393                 }
394             }
395             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
396             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
397             //根据当前用户查询绑定的邮箱信息
398             List<T482102Entity> emailEntities = new ArrayList<>();
399             if (StringUtils.isBlank(mail)) {
400                 emailEntities = emailAccountIfc.getAccount(userCode);//返回邮箱的账号信息
401             } else {
7cf738 402                 T482102Entity T482102 = emailAccountIfc.getAccountInfo(userCode, mail);
X 403                 if (T482102 != null) {
404                     emailEntities.add(T482102);
405                 }
7caeae 406             }
X 407             if (emailEntities.size() > 0) {
408                 List<t482101HEntity> mails = new ArrayList<>();
409                 Map<String, Object> map = new HashMap<>();
410                 for (T482102Entity e : emailEntities) {//遍历用户绑定邮箱
411                     //多线程收邮件
412                     threadPoolExecutor.execute(new ReceivingEmailsSave(mailServiceIfc, e, new FoundationEntity(request)));
413                 }
7cf738 414                 map.put("code", 0);
X 415                 map.put("msg", "请销等,邮件正在系统保存");
7caeae 416                 msg.setSuccess("执行成功", map);
X 417             } else {
418                 msg.setFail("没有找到绑定的邮箱信息");
419             }
420         } catch (Exception e) {
421             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
422         } finally {
423             SpObserver.setDBtoInstance();
424         }
425         return msg;
426     }
427
428
429     /**
430      * 发邮件
385e2d 431      *
X 432      * @param request
433      * @param response
434      * @return
435      */
436     @PostMapping("/sendingMail.do")
437     public AllBackMsg sendingMail(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
438         AllBackMsg msg = new AllBackMsg();
439         try {
440             HttpSession session = request.getSession();
441             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
442             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
443                 msg.setFail("获取不到用户信息");
444                 return msg;
445             }
446             if (StringUtils.isNotBlank(t482101H.getSender())) {
447                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
448                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
449                     return msg;
450                 }
451             }
5b1a4a 452             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 453                 for (String mail : t482101H.getReceiver()) {
X 454                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
455                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
456                         return msg;
457                     }
385e2d 458                 }
f4c162 459
385e2d 460             }
X 461             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
462             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
463             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
464             t482101H.setCompanyId(companyId);
465             t482101H.setCompanyName(companyName);
466             t482101H.setUserCode(userCode);
467             t482101H.setUserName(userName);
468             t482101H.setMailType(2);//发件
7caeae 469             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 470             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 471             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
472             //发送
7caeae 473             mailServiceIfc.sendEmails(t482101H, request);
f5cc47 474             msg.setOk("发送成功");
f6ae0b 475         } catch (MessagingException e) {
f5cc47 476             String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
f6ae0b 477             if (StringUtils.isNotBlank(error)) {
X 478                 String[] arrayError = error.split("#");
479                 if (arrayError.length == 2) {
480                     Map<String, Object> map = new HashMap<>();
481                     map.put("docCode", arrayError[1]);
482                     msg.setError(arrayError[0], map);
483                 } else {
484                     msg.setFail(error);
485                 }
f5cc47 486             } else {
X 487                 msg.setFail(error);
488             }
f6ae0b 489         } catch (Exception e) {
X 490             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 491         } finally {
X 492             SpObserver.setDBtoInstance();
493         }
494         return msg;
495     }
f4c162 496
X 497     /**
498      * 标记已读
499      *
500      * @param request
501      * @param response
502      * @return
503      */
504     @PostMapping("/updateRead.do")
7cf738 505     public AllBackMsg updateRead(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
f4c162 506         AllBackMsg msg = new AllBackMsg();
X 507         try {
508             HttpSession session = request.getSession();
509             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
510             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
511                 msg.setFail("获取不到用户信息");
512                 return msg;
513             }
7cf738 514             List<String> docCode = (List<String>) map.get("list");
f4c162 515             if (docCode == null && docCode.size() == 0) {
X 516                 msg.setFail("请选择标记邮件");
517                 return msg;
518             }
7cf738 519             if (map.get("status") == null) {
X 520                 msg.setFail("请传入状态值");
521                 return msg;
522             }
523             boolean read = (Boolean) map.get("status");
f4c162 524             String arrayCode = StringUtils.join(docCode, ",");
X 525             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
526             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
7cf738 527             emailIfc.updateRead(arrayCode, read);
f4c162 528             msg.setOk("标记成功");
X 529         } catch (Exception e) {
530             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
531         } finally {
532             SpObserver.setDBtoInstance();
533         }
534         return msg;
535     }
536
7cf738 537     /**
aad276 538      * 移动邮件分类
X 539      *
540      * @param request
541      * @param response
542      * @return
543      */
544     @PostMapping("/updateMailType.do")
545     public AllBackMsg updateMailType(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
546         AllBackMsg msg = new AllBackMsg();
547         try {
548             HttpSession session = request.getSession();
549             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
550             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
551                 msg.setFail("获取不到用户信息");
552                 return msg;
553             }
554             if (map.get("docCode") == null) {
555                 msg.setFail("获取不到移动邮件编号docCode");
556                 return msg;
557             }
558             String docCode = (String) map.get("docCode");
559             Integer folderId = map.get("folderId") == null ? 0 : (Integer) map.get("folderId");
560             List<String> tagArray = (List<String>) map.get("tagId");
561             if (folderId.equals(0) && (tagArray == null || tagArray.size() == 0)) {
562                 msg.setFail("移动邮件分类不能为空");
563                 return msg;
564             }
565             String tagId = "";
566             if (tagArray != null && tagArray.size() > 0) {
567                 tagId = StringUtils.join(tagArray, ",");
568             }
569             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
570             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
571             emailIfc.updateMailType(docCode, folderId, tagId);
572             msg.setOk("移动成功");
573         } catch (Exception e) {
574             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
575         } finally {
576             SpObserver.setDBtoInstance();
577         }
578         return msg;
579     }
580
581     /**
582      * 加载不同目录里的邮件
583      *
584      * @param request
585      * @param response
586      * @return
587      */
588     @GetMapping("/classificationMail.do")
589     public AllBackMsg classificationMail(@RequestParam(defaultValue = "-1") Integer id, String type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,
590                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
591         AllBackMsg msg = new AllBackMsg();
592         try {
593             HttpSession session = request.getSession();
594             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
595             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
596                 msg.setFail("获取不到用户信息");
597                 return msg;
598             }
599             if (id == null || id.equals(-1)) {
600                 msg.setFail("获取不到文件Id");
601                 return msg;
602             }
603             if (StringUtils.isBlank(type)) {
604                 msg.setFail("获取不到文件类型");
605                 return msg;
606             }
607             type = type + "_" + id;//组装下
608             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
609             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
610             List<t482101HList> t482101 = emailIfc.getFolderMailList(type, userCode, page, limit);
611             Map<String, Object> map = new HashMap<>();
612             map.put("page", page);
613             map.put("limit", limit);
614             if (t482101.size() > 0) {
615                 map.put("total", emailIfc.getMailTotal(null, 6, false, type, userCode));
616                 map.put("list", t482101);
617             } else {
618                 map.put("list", new ArrayList<>());
619             }
620             msg.setSuccess("执行完成", map);
621         } catch (Exception e) {
622             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
623         } finally {
624             SpObserver.setDBtoInstance();
625         }
626         return msg;
627     }
628
629     /**
7cf738 630      * 待处理邮件
X 631      *
632      * @param request
633      * @param response
634      * @return
635      */
562e20 636     @PostMapping("/updateHandle.do")
X 637     public AllBackMsg updateHandle(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws Exception {
7cf738 638         AllBackMsg msg = new AllBackMsg();
X 639         try {
640             HttpSession session = request.getSession();
641             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
642             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
643                 msg.setFail("获取不到用户信息");
644                 return msg;
645             }
562e20 646             if (param.get("docCode") == null) {
7cf738 647                 msg.setFail("邮件唯一标识docCode不能空");
562e20 648                 return msg;
X 649             }
650             if (param.get("handleTime") == null) {
651                 msg.setFail("待处理时间不能空");
652                 return msg;
653             }
654             List<String> docCode = (List<String>) param.get("docCode");
655             String handleTime = (String) param.get("handleTime");
656             // 正则表达式,用于匹配日期格式
657             String regex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
658             Pattern pattern = Pattern.compile(regex);
659             Matcher matcher = pattern.matcher(handleTime);
660             if (!matcher.matches()) {
661                 msg.setFail("待处理日期格式为:yyyy-MM-dd HH:mm(如:1900-08-01 08:00)。请检查");
7cf738 662                 return msg;
X 663             }
664             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
665             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 666             emailIfc.updateMailHandle(handleTime, StringUtils.join(docCode, ","));
7cf738 667             msg.setOk("成功标记为待处理邮件");
X 668         } catch (Exception e) {
669             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
670         } finally {
671             SpObserver.setDBtoInstance();
672         }
673         return msg;
674     }
675
7caeae 676     private class ReceivingEmailsSave implements Runnable {
X 677         final MailServiceIfc mailServiceIfc;
678         final T482102Entity t482102;
679         final FoundationEntity foundation;
680
681         public ReceivingEmailsSave(MailServiceIfc mailServiceIfc, T482102Entity t482102, FoundationEntity foundation) {
682             this.mailServiceIfc = mailServiceIfc;
683             this.t482102 = t482102;
684             this.foundation = foundation;
685         }
686
687         @Override
688         public void run() {
689             try {
690                 SpObserver.setDBtoInstance("_" + foundation.getDbId());
691                 //收邮件
692                 mailServiceIfc.receivingEmails(t482102, foundation);
693             } catch (Exception e) {
694                 e.printStackTrace();
695             } finally {
696                 SpObserver.setDBtoInstance();
697             }
698         }
699     }
700
385e2d 701 }