xinyb
10 天以前 658898d28cded745ca15ee0a89e3025358356259
提交 | 用户 | 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     }
658898 85     /**
X 86      * 左边结构下层
87      *
88      * @return
89      */
90     @GetMapping("/getEmailModuleBelow.do")
91     public AllBackMsg getEmailModuleBelow(HttpServletRequest request, HttpServletResponse response) throws Exception {
92         AllBackMsg msg = new AllBackMsg();
93         try {
94             HttpSession session = request.getSession();
95             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
96             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
97                 msg.setFail("获取不到用户信息");
98                 return msg;
99             }
100             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
101             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
102             List<MailModuleBelowEntity> list =emailIfc.getMailModuleBelowList(userCode);
103             msg.setSuccess("执行成功", list);
104         } catch (Exception e) {
105             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
106         } finally {
107             SpObserver.setDBtoInstance();
108         }
109         return msg;
110     }
385e2d 111
X 112     /**
113      * 获取邮件列表(包括草稿箱,收件箱)
114      *
115      * @return
116      */
117     @GetMapping("/getMailList.do")
195685 118     public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType,
562e20 119                                   @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 120         AllBackMsg msg = new AllBackMsg();
X 121         try {
122             if (StringUtils.isNotBlank(mail)) {
123                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
124                     msg.setFail("邮箱的各式不争取");
125                     return msg;
126                 }
127             }
5b1a4a 128             HttpSession session = request.getSession();
X 129             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
130             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
131                 msg.setFail("获取不到用户信息");
132                 return msg;
133             }
385e2d 134             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 135             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 136             List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode, page, limit);
385e2d 137             if (t482101HEntityList.size() > 0) {
0c7568 138                 Map<String,Object> map=new HashMap<>();
X 139                 map.put("page",page);
140                 map.put("limit",limit);
141                 map.put("total",emailIfc.getMailTotal(mail,mailType,isNoRead,userCode));
142                 map.put("list",t482101HEntityList);
143                 msg.setSuccess("执行完成", map);
385e2d 144             }
X 145         } catch (Exception e) {
f5cc47 146             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 147         } finally {
X 148             SpObserver.setDBtoInstance();
149         }
150         return msg;
151     }
152
153     /**
57c8bf 154      * 获取待处理邮件列表
X 155      *
156      * @return
157      */
158     @GetMapping("/getHandleMailList.do")
562e20 159     public AllBackMsg getHandleMailList(String mail, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,
195685 160                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
57c8bf 161         AllBackMsg msg = new AllBackMsg();
X 162         try {
163             if (StringUtils.isNotBlank(mail)) {
164                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
165                     msg.setFail("邮箱的各式不争取");
166                     return msg;
167                 }
168             }
169             HttpSession session = request.getSession();
170             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
171             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
172                 msg.setFail("获取不到用户信息");
173                 return msg;
174             }
175             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
176             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 177             List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode, page, limit);
57c8bf 178             if (t482101HEntityList.size() > 0) {
0c7568 179                 Map<String,Object> map=new HashMap<>();
X 180                 map.put("page",page);
181                 map.put("limit",limit);
182                 map.put("total",emailIfc.getMailTotal(mail,3,false,userCode));
183                 map.put("list",t482101HEntityList);
184                 msg.setSuccess("执行完成", map);
57c8bf 185             }
X 186         } catch (Exception e) {
187             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
188         } finally {
189             SpObserver.setDBtoInstance();
190         }
191         return msg;
192     }
193
194     /**
385e2d 195      * 获取邮件详情
X 196      *
197      * @return
198      */
199     @GetMapping("/getMailInfo.do")
f4c162 200     public AllBackMsg getMailInfo(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 201         AllBackMsg msg = new AllBackMsg();
X 202         try {
203             if (StringUtils.isBlank(docCode)) {//获取不到当前用户直接结束
204                 msg.setFail("缺少邮箱唯一码docCode,请检查");
205                 return msg;
206             }
207             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
208             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
f4c162 209             t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
385e2d 210             if (t482101HEntity != null) {
7cf738 211                 if (StringUtils.isNotBlank(t482101HEntity.getAttachmentList())) {//附件的处理
ad7c8d 212                     //获取到附件内容
195685 213                     List<AttachmentEntity> attachmentEntities = mailFileIfc.getAttachmentEntityList(t482101HEntity.getAttachmentList());
7cf738 214                     List<String> list = new ArrayList<>();
ad7c8d 215                     if (attachmentEntities.size() > 0) {
X 216                         for (AttachmentEntity a : attachmentEntities) {
195685 217                             list.add(shoppingImageServer + "/uploads/email/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile());
7cf738 218                         }
X 219                         t482101HEntity.setAttachmentPath(list);
220                     }
221                 }
f5cc47 222                 msg.setSuccess("执行完成", t482101HEntity);
385e2d 223             }
X 224         } catch (Exception e) {
f5cc47 225             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 226         } finally {
X 227             SpObserver.setDBtoInstance();
228         }
229         return msg;
230     }
231
232     /**
f4c162 233      * 删除邮件
385e2d 234      *
X 235      * @return
236      */
5b1a4a 237     @PostMapping("/deleteEmail.do")
X 238     public AllBackMsg deleteEmail(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 239         AllBackMsg msg = new AllBackMsg();
X 240         try {
f4c162 241             if (docCode == null && docCode.size() == 0) {//获取不到当前用户直接结束
X 242                 msg.setFail("请选中删除的邮件");
385e2d 243                 return msg;
X 244             }
f4c162 245             String arrayCode = StringUtils.join(docCode, ",");
f5cc47 246             HttpSession session = request.getSession();
X 247             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
248             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
249                 msg.setFail("获取不到用户信息");
250                 return msg;
251             }
385e2d 252             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 253             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
5b1a4a 254             Integer cont = emailIfc.deleteEmail(userCode, arrayCode);
385e2d 255             if (cont > 0) {
5b1a4a 256                 msg.setOk("已删除");
385e2d 257             }
X 258         } catch (Exception e) {
f5cc47 259             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 260         } finally {
X 261             SpObserver.setDBtoInstance();
262         }
263         return msg;
264     }
265
266     /**
57c8bf 267      * 快速回复
X 268      *
269      * @return
270      */
271     @PostMapping("/setQuickReply.do")
272     public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception {
273         AllBackMsg msg = new AllBackMsg();
274         try {
275             if (reply.get("docCode") == null) {
276                 msg.setFail("获取不到回复邮件的唯一docCode值");
277                 return msg;
278             }
279             if (reply.get("content") == null) {
280                 msg.setFail("请输入回复内容");
281                 return msg;
282             }
283             HttpSession session = request.getSession();
284             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
285             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
286                 msg.setFail("获取不到用户信息");
287                 return msg;
288             }
289             String docCode = (String) reply.get("docCode");//编号
290             String content = (String) reply.get("content");//内容
291             Integer count = mailServiceIfc.setQuickReply(docCode, content);
292             Map<String, Object> map = new HashMap<>();
293             if (count.equals(1)) {
294                 map.put("code", 0);
295                 map.put("docCode", docCode);
296                 map.put("msg", "邮件已回复");
297                 msg.setSuccess("执行成功", map);
298             } else {
299                 map.put("code", -1);
300                 map.put("docCode", docCode);
301                 map.put("msg", "邮件回复失败");
302                 msg.setSuccess("执行成功", map);
303             }
304         } catch (Exception e) {
305             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
306         } finally {
307             SpObserver.setDBtoInstance();
308         }
309         return msg;
310     }
311
312     /**
385e2d 313      * 保存草稿箱(保存或修改)
X 314      *
315      * @return
316      */
317     @PostMapping("/saveMailDrafts.do")
318     public AllBackMsg saveMailDrafts(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
319         AllBackMsg msg = new AllBackMsg();
320         try {
321             HttpSession session = request.getSession();
322             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
323             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
324                 msg.setFail("获取不到用户信息");
325                 return msg;
326             }
327             if (StringUtils.isNotBlank(t482101H.getSender())) {
328                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
329                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
330                     return msg;
331                 }
332             }
5b1a4a 333             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 334                 for (String mail : t482101H.getReceiver()) {
X 335                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
336                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
337                         return msg;
338                     }
385e2d 339                 }
f4c162 340
385e2d 341             }
X 342             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
343             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
344             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
345             t482101H.setCompanyId(companyId);
346             t482101H.setCompanyName(companyName);
347             t482101H.setUserCode(userCode);
348             t482101H.setUserName(userName);
349             t482101H.setMailType(0);//草稿
5b1a4a 350             t482101H.setReadFlag(1);//已读
7caeae 351             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 352             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 353             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
354             t482101H = emailIfc.saveReceivingMail(t482101H);
f5cc47 355             Map<String, Object> map = new HashMap<>();
X 356             map.put("docCode", t482101H.getDocCode());
357             msg.setSuccess("执行成功", map);
385e2d 358         } catch (Exception e) {
f5cc47 359             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 360         } finally {
X 361             SpObserver.setDBtoInstance();
362         }
363         return msg;
364     }
365
366
367     /**
7caeae 368      * 收邮件
X 369      *
370      * @param request
371      * @param response
372      * @return
373      */
374     @GetMapping("/receive.do")
375     public AllBackMsg getReceiveMail(String mail, HttpServletRequest request, HttpServletResponse response) throws Exception {
376         AllBackMsg msg = new AllBackMsg();
377         try {
378             HttpSession session = request.getSession();
379             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
380             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
381                 msg.setFail("获取不到用户信息");
382                 return msg;
383             }
384             if (StringUtils.isNotBlank(mail)) {
385                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
386                     msg.setFail("请输入有效的邮箱");
387                     return msg;
388                 }
389             }
390             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
391             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
392             //根据当前用户查询绑定的邮箱信息
393             List<T482102Entity> emailEntities = new ArrayList<>();
394             if (StringUtils.isBlank(mail)) {
395                 emailEntities = emailAccountIfc.getAccount(userCode);//返回邮箱的账号信息
396             } else {
7cf738 397                 T482102Entity T482102 = emailAccountIfc.getAccountInfo(userCode, mail);
X 398                 if (T482102 != null) {
399                     emailEntities.add(T482102);
400                 }
7caeae 401             }
X 402             if (emailEntities.size() > 0) {
403                 List<t482101HEntity> mails = new ArrayList<>();
404                 Map<String, Object> map = new HashMap<>();
405                 for (T482102Entity e : emailEntities) {//遍历用户绑定邮箱
406                     //多线程收邮件
407                     threadPoolExecutor.execute(new ReceivingEmailsSave(mailServiceIfc, e, new FoundationEntity(request)));
408                 }
7cf738 409                 map.put("code", 0);
X 410                 map.put("msg", "请销等,邮件正在系统保存");
7caeae 411                 msg.setSuccess("执行成功", map);
X 412             } else {
413                 msg.setFail("没有找到绑定的邮箱信息");
414             }
415         } catch (Exception e) {
416             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
417         } finally {
418             SpObserver.setDBtoInstance();
419         }
420         return msg;
421     }
422
423
424     /**
425      * 发邮件
385e2d 426      *
X 427      * @param request
428      * @param response
429      * @return
430      */
431     @PostMapping("/sendingMail.do")
432     public AllBackMsg sendingMail(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
433         AllBackMsg msg = new AllBackMsg();
434         try {
435             HttpSession session = request.getSession();
436             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
437             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
438                 msg.setFail("获取不到用户信息");
439                 return msg;
440             }
441             if (StringUtils.isNotBlank(t482101H.getSender())) {
442                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
443                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
444                     return msg;
445                 }
446             }
5b1a4a 447             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 448                 for (String mail : t482101H.getReceiver()) {
X 449                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
450                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
451                         return msg;
452                     }
385e2d 453                 }
f4c162 454
385e2d 455             }
X 456             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
457             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
458             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
459             t482101H.setCompanyId(companyId);
460             t482101H.setCompanyName(companyName);
461             t482101H.setUserCode(userCode);
462             t482101H.setUserName(userName);
463             t482101H.setMailType(2);//发件
7caeae 464             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 465             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 466             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
467             //发送
7caeae 468             mailServiceIfc.sendEmails(t482101H, request);
f5cc47 469             msg.setOk("发送成功");
f6ae0b 470         } catch (MessagingException e) {
f5cc47 471             String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
f6ae0b 472             if (StringUtils.isNotBlank(error)) {
X 473                 String[] arrayError = error.split("#");
474                 if (arrayError.length == 2) {
475                     Map<String, Object> map = new HashMap<>();
476                     map.put("docCode", arrayError[1]);
477                     msg.setError(arrayError[0], map);
478                 } else {
479                     msg.setFail(error);
480                 }
f5cc47 481             } else {
X 482                 msg.setFail(error);
483             }
f6ae0b 484         } catch (Exception e) {
X 485             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 486         } finally {
X 487             SpObserver.setDBtoInstance();
488         }
489         return msg;
490     }
f4c162 491
X 492     /**
493      * 标记已读
494      *
495      * @param request
496      * @param response
497      * @return
498      */
499     @PostMapping("/updateRead.do")
7cf738 500     public AllBackMsg updateRead(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
f4c162 501         AllBackMsg msg = new AllBackMsg();
X 502         try {
503             HttpSession session = request.getSession();
504             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
505             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
506                 msg.setFail("获取不到用户信息");
507                 return msg;
508             }
7cf738 509             List<String> docCode = (List<String>) map.get("list");
f4c162 510             if (docCode == null && docCode.size() == 0) {
X 511                 msg.setFail("请选择标记邮件");
512                 return msg;
513             }
7cf738 514             if (map.get("status") == null) {
X 515                 msg.setFail("请传入状态值");
516                 return msg;
517             }
518             boolean read = (Boolean) map.get("status");
f4c162 519             String arrayCode = StringUtils.join(docCode, ",");
X 520             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
521             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
7cf738 522             emailIfc.updateRead(arrayCode, read);
f4c162 523             msg.setOk("标记成功");
X 524         } catch (Exception e) {
525             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
526         } finally {
527             SpObserver.setDBtoInstance();
528         }
529         return msg;
530     }
531
7cf738 532     /**
X 533      * 待处理邮件
534      *
535      * @param request
536      * @param response
537      * @return
538      */
562e20 539     @PostMapping("/updateHandle.do")
X 540     public AllBackMsg updateHandle(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws Exception {
7cf738 541         AllBackMsg msg = new AllBackMsg();
X 542         try {
543             HttpSession session = request.getSession();
544             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
545             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
546                 msg.setFail("获取不到用户信息");
547                 return msg;
548             }
562e20 549             if (param.get("docCode") == null) {
7cf738 550                 msg.setFail("邮件唯一标识docCode不能空");
562e20 551                 return msg;
X 552             }
553             if (param.get("handleTime") == null) {
554                 msg.setFail("待处理时间不能空");
555                 return msg;
556             }
557             List<String> docCode = (List<String>) param.get("docCode");
558             String handleTime = (String) param.get("handleTime");
559             // 正则表达式,用于匹配日期格式
560             String regex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
561             Pattern pattern = Pattern.compile(regex);
562             Matcher matcher = pattern.matcher(handleTime);
563             if (!matcher.matches()) {
564                 msg.setFail("待处理日期格式为:yyyy-MM-dd HH:mm(如:1900-08-01 08:00)。请检查");
7cf738 565                 return msg;
X 566             }
567             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
568             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 569             emailIfc.updateMailHandle(handleTime, StringUtils.join(docCode, ","));
7cf738 570             msg.setOk("成功标记为待处理邮件");
X 571         } catch (Exception e) {
572             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
573         } finally {
574             SpObserver.setDBtoInstance();
575         }
576         return msg;
577     }
578
7caeae 579     private class ReceivingEmailsSave implements Runnable {
X 580         final MailServiceIfc mailServiceIfc;
581         final T482102Entity t482102;
582         final FoundationEntity foundation;
583
584         public ReceivingEmailsSave(MailServiceIfc mailServiceIfc, T482102Entity t482102, FoundationEntity foundation) {
585             this.mailServiceIfc = mailServiceIfc;
586             this.t482102 = t482102;
587             this.foundation = foundation;
588         }
589
590         @Override
591         public void run() {
592             try {
593                 SpObserver.setDBtoInstance("_" + foundation.getDbId());
594                 //收邮件
595                 mailServiceIfc.receivingEmails(t482102, foundation);
596             } catch (Exception e) {
597                 e.printStackTrace();
598             } finally {
599                 SpObserver.setDBtoInstance();
600             }
601         }
602     }
603
385e2d 604 }