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