xinyb
5 天以前 56d9f6a0b1ecfce70da391d406fcc92274cc1b03
提交 | 用户 | 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());
56d9f6 219                     List<Map<String,Object>> list = new ArrayList<>();
ad7c8d 220                     if (attachmentEntities.size() > 0) {
X 221                         for (AttachmentEntity a : attachmentEntities) {
56d9f6 222                             Map<String,Object> map=new HashMap<>();
X 223                             map.put("url",shoppingImageServer + "/uploads/email/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile());
224                             map.put("name",a.getOriginalFileName());
225                             map.put("size",a.getFileSize());
226                             map.put("fileType",a.getFileType());
227                             list.add(map);
7cf738 228                         }
X 229                         t482101HEntity.setAttachmentPath(list);
230                     }
231                 }
f5cc47 232                 msg.setSuccess("执行完成", t482101HEntity);
385e2d 233             }
X 234         } catch (Exception e) {
f5cc47 235             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 236         } finally {
X 237             SpObserver.setDBtoInstance();
238         }
239         return msg;
240     }
241
242     /**
f4c162 243      * 删除邮件
385e2d 244      *
X 245      * @return
246      */
5b1a4a 247     @PostMapping("/deleteEmail.do")
X 248     public AllBackMsg deleteEmail(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
385e2d 249         AllBackMsg msg = new AllBackMsg();
X 250         try {
f4c162 251             if (docCode == null && docCode.size() == 0) {//获取不到当前用户直接结束
X 252                 msg.setFail("请选中删除的邮件");
385e2d 253                 return msg;
X 254             }
f4c162 255             String arrayCode = StringUtils.join(docCode, ",");
f5cc47 256             HttpSession session = request.getSession();
X 257             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
258             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
259                 msg.setFail("获取不到用户信息");
260                 return msg;
261             }
385e2d 262             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 263             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
5b1a4a 264             Integer cont = emailIfc.deleteEmail(userCode, arrayCode);
385e2d 265             if (cont > 0) {
5b1a4a 266                 msg.setOk("已删除");
385e2d 267             }
X 268         } catch (Exception e) {
f5cc47 269             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 270         } finally {
X 271             SpObserver.setDBtoInstance();
272         }
273         return msg;
274     }
275
276     /**
57c8bf 277      * 快速回复
X 278      *
279      * @return
280      */
281     @PostMapping("/setQuickReply.do")
282     public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception {
283         AllBackMsg msg = new AllBackMsg();
284         try {
285             if (reply.get("docCode") == null) {
286                 msg.setFail("获取不到回复邮件的唯一docCode值");
287                 return msg;
288             }
289             if (reply.get("content") == null) {
290                 msg.setFail("请输入回复内容");
291                 return msg;
292             }
293             HttpSession session = request.getSession();
294             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
295             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
296                 msg.setFail("获取不到用户信息");
297                 return msg;
298             }
299             String docCode = (String) reply.get("docCode");//编号
300             String content = (String) reply.get("content");//内容
301             Integer count = mailServiceIfc.setQuickReply(docCode, content);
302             Map<String, Object> map = new HashMap<>();
303             if (count.equals(1)) {
304                 map.put("code", 0);
305                 map.put("docCode", docCode);
306                 map.put("msg", "邮件已回复");
307                 msg.setSuccess("执行成功", map);
308             } else {
309                 map.put("code", -1);
310                 map.put("docCode", docCode);
311                 map.put("msg", "邮件回复失败");
312                 msg.setSuccess("执行成功", map);
313             }
314         } catch (Exception e) {
315             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
316         } finally {
317             SpObserver.setDBtoInstance();
318         }
319         return msg;
320     }
321
322     /**
385e2d 323      * 保存草稿箱(保存或修改)
X 324      *
325      * @return
326      */
327     @PostMapping("/saveMailDrafts.do")
328     public AllBackMsg saveMailDrafts(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
329         AllBackMsg msg = new AllBackMsg();
330         try {
331             HttpSession session = request.getSession();
332             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
333             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
334                 msg.setFail("获取不到用户信息");
335                 return msg;
336             }
337             if (StringUtils.isNotBlank(t482101H.getSender())) {
338                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
339                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
340                     return msg;
341                 }
342             }
5b1a4a 343             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 344                 for (String mail : t482101H.getReceiver()) {
X 345                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
346                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
347                         return msg;
348                     }
385e2d 349                 }
f4c162 350
385e2d 351             }
X 352             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
353             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
354             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
355             t482101H.setCompanyId(companyId);
356             t482101H.setCompanyName(companyName);
357             t482101H.setUserCode(userCode);
358             t482101H.setUserName(userName);
359             t482101H.setMailType(0);//草稿
5b1a4a 360             t482101H.setReadFlag(1);//已读
7caeae 361             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 362             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 363             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
364             t482101H = emailIfc.saveReceivingMail(t482101H);
f5cc47 365             Map<String, Object> map = new HashMap<>();
X 366             map.put("docCode", t482101H.getDocCode());
367             msg.setSuccess("执行成功", map);
385e2d 368         } catch (Exception e) {
f5cc47 369             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 370         } finally {
X 371             SpObserver.setDBtoInstance();
372         }
373         return msg;
374     }
375
376
377     /**
7caeae 378      * 收邮件
X 379      *
380      * @param request
381      * @param response
382      * @return
383      */
384     @GetMapping("/receive.do")
385     public AllBackMsg getReceiveMail(String mail, HttpServletRequest request, HttpServletResponse response) throws Exception {
386         AllBackMsg msg = new AllBackMsg();
387         try {
388             HttpSession session = request.getSession();
389             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
390             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
391                 msg.setFail("获取不到用户信息");
392                 return msg;
393             }
394             if (StringUtils.isNotBlank(mail)) {
395                 if (!EMAIL_PATTERN.matcher(mail).matches()) {
396                     msg.setFail("请输入有效的邮箱");
397                     return msg;
398                 }
399             }
400             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
401             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
402             //根据当前用户查询绑定的邮箱信息
403             List<T482102Entity> emailEntities = new ArrayList<>();
404             if (StringUtils.isBlank(mail)) {
405                 emailEntities = emailAccountIfc.getAccount(userCode);//返回邮箱的账号信息
406             } else {
7cf738 407                 T482102Entity T482102 = emailAccountIfc.getAccountInfo(userCode, mail);
X 408                 if (T482102 != null) {
409                     emailEntities.add(T482102);
410                 }
7caeae 411             }
X 412             if (emailEntities.size() > 0) {
413                 List<t482101HEntity> mails = new ArrayList<>();
414                 Map<String, Object> map = new HashMap<>();
415                 for (T482102Entity e : emailEntities) {//遍历用户绑定邮箱
416                     //多线程收邮件
417                     threadPoolExecutor.execute(new ReceivingEmailsSave(mailServiceIfc, e, new FoundationEntity(request)));
418                 }
7cf738 419                 map.put("code", 0);
X 420                 map.put("msg", "请销等,邮件正在系统保存");
7caeae 421                 msg.setSuccess("执行成功", map);
X 422             } else {
423                 msg.setFail("没有找到绑定的邮箱信息");
424             }
425         } catch (Exception e) {
426             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
427         } finally {
428             SpObserver.setDBtoInstance();
429         }
430         return msg;
431     }
432
433
434     /**
435      * 发邮件
385e2d 436      *
X 437      * @param request
438      * @param response
439      * @return
440      */
441     @PostMapping("/sendingMail.do")
442     public AllBackMsg sendingMail(@RequestBody t482101HEntity t482101H, HttpServletRequest request, HttpServletResponse response) throws Exception {
443         AllBackMsg msg = new AllBackMsg();
444         try {
445             HttpSession session = request.getSession();
446             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
447             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
448                 msg.setFail("获取不到用户信息");
449                 return msg;
450             }
451             if (StringUtils.isNotBlank(t482101H.getSender())) {
452                 if (!EMAIL_PATTERN.matcher(t482101H.getSender()).matches()) {
453                     msg.setFail("发送人邮箱:" + t482101H.getSender() + "的格式不正确");
454                     return msg;
455                 }
456             }
5b1a4a 457             if (t482101H.getReceiver() != null && t482101H.getReceiver().size() > 0) {
f4c162 458                 for (String mail : t482101H.getReceiver()) {
X 459                     if (!EMAIL_PATTERN.matcher(mail).matches()) {
460                         msg.setFail("收件人邮箱:" + mail + "的格式不正确");
461                         return msg;
462                     }
385e2d 463                 }
f4c162 464
385e2d 465             }
X 466             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
467             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
468             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
469             t482101H.setCompanyId(companyId);
470             t482101H.setCompanyName(companyName);
471             t482101H.setUserCode(userCode);
472             t482101H.setUserName(userName);
473             t482101H.setMailType(2);//发件
7caeae 474             t482101H.setAttachmentList(t482101H.getAttachmentList());
385e2d 475             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
X 476             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
477             //发送
7caeae 478             mailServiceIfc.sendEmails(t482101H, request);
f5cc47 479             msg.setOk("发送成功");
f6ae0b 480         } catch (MessagingException e) {
f5cc47 481             String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
f6ae0b 482             if (StringUtils.isNotBlank(error)) {
X 483                 String[] arrayError = error.split("#");
484                 if (arrayError.length == 2) {
485                     Map<String, Object> map = new HashMap<>();
486                     map.put("docCode", arrayError[1]);
487                     msg.setError(arrayError[0], map);
488                 } else {
489                     msg.setFail(error);
490                 }
f5cc47 491             } else {
X 492                 msg.setFail(error);
493             }
f6ae0b 494         } catch (Exception e) {
X 495             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 496         } finally {
X 497             SpObserver.setDBtoInstance();
498         }
499         return msg;
500     }
f4c162 501
X 502     /**
503      * 标记已读
504      *
505      * @param request
506      * @param response
507      * @return
508      */
509     @PostMapping("/updateRead.do")
7cf738 510     public AllBackMsg updateRead(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
f4c162 511         AllBackMsg msg = new AllBackMsg();
X 512         try {
513             HttpSession session = request.getSession();
514             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
515             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
516                 msg.setFail("获取不到用户信息");
517                 return msg;
518             }
7cf738 519             List<String> docCode = (List<String>) map.get("list");
f4c162 520             if (docCode == null && docCode.size() == 0) {
X 521                 msg.setFail("请选择标记邮件");
522                 return msg;
523             }
7cf738 524             if (map.get("status") == null) {
X 525                 msg.setFail("请传入状态值");
526                 return msg;
527             }
528             boolean read = (Boolean) map.get("status");
f4c162 529             String arrayCode = StringUtils.join(docCode, ",");
X 530             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
531             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
7cf738 532             emailIfc.updateRead(arrayCode, read);
f4c162 533             msg.setOk("标记成功");
X 534         } catch (Exception e) {
535             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
536         } finally {
537             SpObserver.setDBtoInstance();
538         }
539         return msg;
540     }
541
7cf738 542     /**
aad276 543      * 移动邮件分类
X 544      *
545      * @param request
546      * @param response
547      * @return
548      */
549     @PostMapping("/updateMailType.do")
550     public AllBackMsg updateMailType(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
551         AllBackMsg msg = new AllBackMsg();
552         try {
553             HttpSession session = request.getSession();
554             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
555             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
556                 msg.setFail("获取不到用户信息");
557                 return msg;
558             }
559             if (map.get("docCode") == null) {
560                 msg.setFail("获取不到移动邮件编号docCode");
561                 return msg;
562             }
563             String docCode = (String) map.get("docCode");
564             Integer folderId = map.get("folderId") == null ? 0 : (Integer) map.get("folderId");
565             List<String> tagArray = (List<String>) map.get("tagId");
566             if (folderId.equals(0) && (tagArray == null || tagArray.size() == 0)) {
567                 msg.setFail("移动邮件分类不能为空");
568                 return msg;
569             }
570             String tagId = "";
571             if (tagArray != null && tagArray.size() > 0) {
572                 tagId = StringUtils.join(tagArray, ",");
573             }
574             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
575             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
576             emailIfc.updateMailType(docCode, folderId, tagId);
577             msg.setOk("移动成功");
578         } catch (Exception e) {
579             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
580         } finally {
581             SpObserver.setDBtoInstance();
582         }
583         return msg;
584     }
585
586     /**
587      * 加载不同目录里的邮件
588      *
589      * @param request
590      * @param response
591      * @return
592      */
593     @GetMapping("/classificationMail.do")
594     public AllBackMsg classificationMail(@RequestParam(defaultValue = "-1") Integer id, String type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,
595                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
596         AllBackMsg msg = new AllBackMsg();
597         try {
598             HttpSession session = request.getSession();
599             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
600             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
601                 msg.setFail("获取不到用户信息");
602                 return msg;
603             }
604             if (id == null || id.equals(-1)) {
605                 msg.setFail("获取不到文件Id");
606                 return msg;
607             }
608             if (StringUtils.isBlank(type)) {
609                 msg.setFail("获取不到文件类型");
610                 return msg;
611             }
612             type = type + "_" + id;//组装下
613             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
614             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
615             List<t482101HList> t482101 = emailIfc.getFolderMailList(type, userCode, page, limit);
616             Map<String, Object> map = new HashMap<>();
617             map.put("page", page);
618             map.put("limit", limit);
619             if (t482101.size() > 0) {
620                 map.put("total", emailIfc.getMailTotal(null, 6, false, type, userCode));
621                 map.put("list", t482101);
622             } else {
623                 map.put("list", new ArrayList<>());
624             }
625             msg.setSuccess("执行完成", map);
626         } catch (Exception e) {
627             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
628         } finally {
629             SpObserver.setDBtoInstance();
630         }
631         return msg;
632     }
633
634     /**
7cf738 635      * 待处理邮件
X 636      *
637      * @param request
638      * @param response
639      * @return
640      */
562e20 641     @PostMapping("/updateHandle.do")
X 642     public AllBackMsg updateHandle(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws Exception {
7cf738 643         AllBackMsg msg = new AllBackMsg();
X 644         try {
645             HttpSession session = request.getSession();
646             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
647             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
648                 msg.setFail("获取不到用户信息");
649                 return msg;
650             }
562e20 651             if (param.get("docCode") == null) {
7cf738 652                 msg.setFail("邮件唯一标识docCode不能空");
562e20 653                 return msg;
X 654             }
655             if (param.get("handleTime") == null) {
656                 msg.setFail("待处理时间不能空");
657                 return msg;
658             }
659             List<String> docCode = (List<String>) param.get("docCode");
660             String handleTime = (String) param.get("handleTime");
661             // 正则表达式,用于匹配日期格式
662             String regex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
663             Pattern pattern = Pattern.compile(regex);
664             Matcher matcher = pattern.matcher(handleTime);
665             if (!matcher.matches()) {
666                 msg.setFail("待处理日期格式为:yyyy-MM-dd HH:mm(如:1900-08-01 08:00)。请检查");
7cf738 667                 return msg;
X 668             }
669             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
670             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
562e20 671             emailIfc.updateMailHandle(handleTime, StringUtils.join(docCode, ","));
7cf738 672             msg.setOk("成功标记为待处理邮件");
X 673         } catch (Exception e) {
674             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
675         } finally {
676             SpObserver.setDBtoInstance();
677         }
678         return msg;
679     }
680
7caeae 681     private class ReceivingEmailsSave implements Runnable {
X 682         final MailServiceIfc mailServiceIfc;
683         final T482102Entity t482102;
684         final FoundationEntity foundation;
685
686         public ReceivingEmailsSave(MailServiceIfc mailServiceIfc, T482102Entity t482102, FoundationEntity foundation) {
687             this.mailServiceIfc = mailServiceIfc;
688             this.t482102 = t482102;
689             this.foundation = foundation;
690         }
691
692         @Override
693         public void run() {
694             try {
695                 SpObserver.setDBtoInstance("_" + foundation.getDbId());
696                 //收邮件
697                 mailServiceIfc.receivingEmails(t482102, foundation);
698             } catch (Exception e) {
699                 e.printStackTrace();
700             } finally {
701                 SpObserver.setDBtoInstance();
702             }
703         }
704     }
705
385e2d 706 }