4d01645819e39bccba3884f7930d576c12f68a1b.svn-base
21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package com.espeed.action;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.espeed.centre.pojo.YxyUserInfo;
import com.espeed.log.LogClass;
import com.espeed.pojo.YxySendFilterAddress;
import com.espeed.service.YxySendFilterAddressService;
import com.espeed.tool.ConfigPath;
import com.espeed.tool.DomParseXml;
import com.espeed.vo.PageBean;
import com.opensymphony.xwork2.ActionContext;
/**
* 程序名称: EspeedMail_时速邮箱
* 程序版本: V1.0
* 作 者: 深圳市科飞时速网络技术有限公司(0755-88843776)
* 版权所有: 深圳市科飞时速网络技术有限公司
* 技术支持: Tech@21gmail.com
* 单元名称: 发送过滤地址action
* 开始时间: 2013.12.09
* 程 序 员: 谢勇
* 最后修改:
* 备 注: 如需修改请通知程序员
*/
public class YxyFilterAddressAction extends BaseAction{
private static final long serialVersionUID = 1L;
public static final String emailyz=ConfigPath.getEmailYZ();
public static final String domainyz=ConfigPath.getDomainYZ();
/**条件查询过滤地址*/
public String findByCondition(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
pagebean.setCurrentPage(currpage);
pagebean.setPageSize(pagesize);
filteraddresslist=filteraddressservice.findByCondition(loginid,domain,condition,conditionvalue,pagebean);
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "list";
}
/**添加过滤地址(可多个)*/
public String addFilterAddressPi(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
//返回值
resultmap.put("success", 0);//成功量
resultmap.put("nohefa", 0);//不合法量
resultmap.put("chongfu", 0);//文件重复量
resultmap.put("exits", 0);//已存在量
//查询已存在的地址
List<Object> exitsaddress=filteraddressservice.findIsExits(loginid,domain);
//过滤地址集合
List<YxySendFilterAddress> filteraddrlist=new ArrayList<YxySendFilterAddress>();
//地址对象
YxySendFilterAddress o=null;
//当前日期
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
String nowdate=df.format(new Date());
//以换行分割地址
String [] filterArry=addressarray.split("\n");
//去掉本身重复的
Set<String> setlist=new HashSet<String>();
for(int s=0;s<filterArry.length;s++){
setlist.add(filterArry[s]);
}
int chongfu=filterArry.length-setlist.size();
resultmap.put("chongfu",chongfu);//文件重复量
Pattern p=null;
Iterator<String> iterator =setlist.iterator();
String addressValue="";
our:while (iterator.hasNext()) {
addressValue=(String)iterator.next();
//判断地址的合法性
//1.email地址判断
p = Pattern.compile(emailyz);
Matcher m = p.matcher(addressValue);
if(!m.matches()){
//2.域名判断
p = Pattern.compile(domainyz);
Matcher m1 = p.matcher(addressValue);
if(!m1.matches()){
int nohefa=resultmap.get("nohefa")+1;
resultmap.put("nohefa",nohefa);//不合法量
continue our;
}
}
//是否重复判断
for(int j=0;j<exitsaddress.size();j++){
if(addressValue.equals(exitsaddress.get(j).toString())){
int nohefa=resultmap.get("exits")+1;
resultmap.put("exits",nohefa);//已存在量
continue our;
}
}
//建立对象
o=new YxySendFilterAddress();
o.setFilteraddrdate(nowdate);
o.setFilteraddrdomain(domain);
o.setFilteraddress(addressValue);
o.setFilteraddrloginid(loginid);
o.setFilteraddrreason(filterbody);
o.setFilterid(filterid);
filteraddrlist.add(o);
}
//循环插入
if(filteraddrlist.size()>0){
filteraddressservice.addFilterAddressPi(filteraddrlist);
}
resultmap.put("success",filteraddrlist.size());//成功量
resultmap.put("result",1);//结果
} catch (Exception e) {
resultmap.put("result",0);//结果
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "add";
}
/**批量外部文件导入*/
public String addFilterAddressFile(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
//返回值
resultmap.put("result",0);//返回值
resultmap.put("success",0);//成功量
resultmap.put("tolnum",0);//文件总量
resultmap.put("fcnum",0);//文件重复
resultmap.put("scnum",0);//系统重复
resultmap.put("nonum",0);//不合法量
int filelinenum=0;//文件行数
//地址对象
YxySendFilterAddress o=null;
//时间定义
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowdate=df.format(new Date());
//读取文件路径
String addressFilePath=file.getPath();
//判断文件格式是否正确
int i = filename.lastIndexOf(".");
String filetype =filename.substring(i + 1);
//如是不是txt与xls类型文件则无法导入
if(!"txt".equals(filetype)&&!"xls".equals(filetype)){
resultmap.put("result",-1);//"您导入的文件类型不对,请重新选择";
return "add";
}
//查询系统已存在的地址
List<Object> exitsaddress=filteraddressservice.findIsExits(loginid,domain);
//过滤地址集合
List<YxySendFilterAddress> filteraddrlist=new ArrayList<YxySendFilterAddress>();
//文件地址集合
List<String> filelist=new ArrayList<String>();
//判断导入的地址条数
if("txt".equals(filetype)){
filelinenum=DomParseXml.getTxtLineNum(addressFilePath);//txt文件条数
if(filelinenum<=1){
resultmap.put("result",-2);//您导入的文件无任何数据,请重新选择
return "add";
}
resultmap.put("tolnum",filelinenum);//文件总量
//解析文件
String tmpLineVal;
String encoding = "Unicode";
InputStreamReader in = new InputStreamReader(new FileInputStream(addressFilePath), encoding);
int p = (in.read() << 8) + in.read();
switch (p) {
case 0xefbb:
encoding = "UTF-8";
break;
case 0xfffe:
encoding = "Unicode";
break;
case 0xfeff:
encoding = "UTF-16BE";
break;
default:
encoding = "GBK";
}
InputStreamReader in1 = new InputStreamReader(new FileInputStream(addressFilePath), encoding);
BufferedReader bufread1 = new BufferedReader(in1);
String line_record ="";
our:while((tmpLineVal = bufread1.readLine())!=null){
// 解析每一条记录返回结果
line_record = tmpLineVal;
if(line_record!=null&&!line_record.equals("")){
//去掉空格
line_record=line_record.trim();
//1.email地址判断
Pattern yz = Pattern.compile(emailyz);
Matcher m = yz.matcher(line_record);
if(!m.matches()){//不是正确的
//2.域名判断
Pattern p1 = Pattern.compile(domainyz);
Matcher m1 = p1.matcher(line_record);
if(!m1.matches()){
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
continue;
}
}
//判断文件本身是否重复
for(int f=0;f<filelist.size();f++){
if(line_record.equals(filelist.get(f))){
int fcnum=resultmap.get("fcnum")+1;
resultmap.put("fcnum",fcnum);//文件重复
continue our;
}
}
/**-----------------txt文件导入-修改之前---------------------------------------*/
//判断系统文件是否重复
for(int j=0;j<exitsaddress.size();j++){
if(line_record.equals(exitsaddress.get(j).toString())){
int scnum=resultmap.get("scnum")+1;
resultmap.put("scnum",scnum);//已存在量
continue our;
}
}
/**-----------------txt文件导入-修改之后---------------------------------------*/
//加入地址结合
filelist.add(line_record);
//建立对象
o=new YxySendFilterAddress();
o.setFilteraddrdate(nowdate);
o.setFilteraddrdomain(domain);
o.setFilteraddress(line_record);
o.setFilteraddrloginid(loginid);
o.setFilteraddrreason(filterbody);
o.setFilterid(filterid);
//加入集合对象中
filteraddrlist.add(o);
}else{
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
}
}
}else if("xls".equals(filetype)){
//把一张xls的数据表读到wb里
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(new File(addressFilePath)));
//读取第一页
HSSFSheet sheet = wb.getSheetAt(0);
//获取一个表最后一条记录的记录号
filelinenum=sheet.getLastRowNum() + 1;//xls文件条数
if(filelinenum<=1){
resultmap.put("result",-2);//您导入的文件无任何数据,请重新选择
return "add";
}
resultmap.put("tolnum",filelinenum);//文件总量
//循环每一行的数据
for (int j = 1; j < sheet.getLastRowNum() + 1; j++) {
//创建一个对象
HSSFRow row = sheet.getRow(j);
String mailAddrAndName="";
if(row==null){
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
}else{
//一行对应的每一列的数据
our:for(int k = 0; k < row.getLastCellNum(); k++) {
//获取每一行中一个单元格中的值
HSSFCell cell = row.getCell((short) k);
/**-----------------xls文件导入-修改之前---------------------------------------*/
//判断单元格中是否为空
if(cell != null){
if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){
// 返回布尔类型的值
mailAddrAndName = String.valueOf(cell.getBooleanCellValue());
}else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
//返回数值类型的值
mailAddrAndName = "";
}else{
//返回字符串类型的值
mailAddrAndName = String.valueOf(cell.getStringCellValue());
}
//去掉空格
mailAddrAndName=mailAddrAndName.trim();
if(mailAddrAndName != null && !mailAddrAndName.equals("")){
//1.判断格式是否为邮件格式
Pattern yz = Pattern.compile(emailyz);
Matcher m = yz.matcher(mailAddrAndName);
if(!m.matches()){
//2.判断格式是否为域名格式
Pattern p1 = Pattern.compile(domainyz);
Matcher m1 = p1.matcher(mailAddrAndName);
if(!m1.matches()){
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
continue;
}
}
//3.判断与文件本身信息是否重复
for(int f=0;f<filelist.size();f++){
if(mailAddrAndName.equals(filelist.get(f))){
int fcnum=resultmap.get("fcnum")+1;
resultmap.put("fcnum",fcnum);//文件重复
continue our;
}
}
//4.判断与系统存在信息是否重复
for(int e=0;e<exitsaddress.size();e++){
if(mailAddrAndName.equals(exitsaddress.get(e).toString())){
int scnum=resultmap.get("scnum")+1;
resultmap.put("scnum",scnum);//已存在量
continue our;
}
}
//加入地址结合
filelist.add(mailAddrAndName);
//建立对象
o=new YxySendFilterAddress();
o.setFilteraddrdate(nowdate);
o.setFilteraddrdomain(domain);
o.setFilteraddress(mailAddrAndName);
o.setFilteraddrloginid(loginid);
o.setFilteraddrreason(filterbody);
o.setFilterid(filterid);
//加入集合对象中
filteraddrlist.add(o);
}else{
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
}
}else{
int nonum=resultmap.get("nonum")+1;
resultmap.put("nonum",nonum);//不合法量
}
/**-----------------xls文件导入-修改之后--------------------------------------*/
// if(cell!=null){
// if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){
// // 返回布尔类型的值
// mailAddrAndName += String.valueOf(cell.getBooleanCellValue()+",");
// }else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
// //返回数值类型的值
// mailAddrAndName +=""+",";
// }else{
// //返回字符串类型的值
// mailAddrAndName += String.valueOf(cell.getStringCellValue()+",");
// }
// if(mailAddrAndName==null||mailAddrAndName.equals("")){
// int nonum=resultmap.get("nonum")+1;
// resultmap.put("nonum",nonum);//不合法量
// }else{
// String lastAddress=mailAddrAndName.replaceAll(" ", "");//最后地址
// Pattern yz = Pattern.compile(emailyz);
// Matcher m = yz.matcher(lastAddress);
// if(!m.matches()){//不是正确的
// Pattern p1 = Pattern.compile(domainyz);
// Matcher m1 = p1.matcher(mailAddrAndName);
// if(!m1.matches()){
// int nonum=resultmap.get("nonum")+1;
// resultmap.put("nonum",nonum);//不合法量
// continue;
// }
// //判断文件本身是否重复
// for(int f=0;f<filelist.size();f++){
// if(mailAddrAndName.equals(filelist.get(f))){
// int fcnum=resultmap.get("fcnum")+1;
// resultmap.put("fcnum",fcnum);//文件重复
// continue our;
// }
// }
// //加入地址结合
// filelist.add(mailAddrAndName);
// //建立对象
// o=new YxySendFilterAddress();
// o.setFilteraddrdate(nowdate);
// o.setFilteraddrdomain(domain);
// o.setFilteraddress(mailAddrAndName);
// o.setFilteraddrloginid(loginid);
// o.setFilteraddrreason(filterbody);
// o.setFilterid(filterid);
//
// //加入集合对象中
// filteraddrlist.add(o);
// }else{
// int nonum=resultmap.get("nonum")+1;
// resultmap.put("nonum",nonum);//不合法量
// }
// }
// }else{
// int nonum=resultmap.get("nonum")+1;
// resultmap.put("nonum",nonum);//不合法量
// }
}
}
}
}
//循环插入
if(filteraddrlist.size()>0){
filteraddressservice.addFilterAddressPi(filteraddrlist);
}
resultmap.put("success",filteraddrlist.size());//成功量
resultmap.put("result",1);//结果
return "add";
} catch (Exception e) {
resultmap.put("result",0);//结果
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "addFilterAddress";
}
/**删除所选过滤地址*/
public String delFilterAddress(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
filteraddressservice.delFilterAddress(addressstr);
result=1;
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
/**过滤地址是否存在*/
public String findIsExits(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
result=filteraddressservice.findIsExits(loginid, domain, verifystr);
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
/**编辑过滤地址*/
public String updateFilterAddress(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
filteraddressservice.updateFilterAddress(filteraddress);
result=1;
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
private int condition;
private int pagesize;
private int currpage;
private int filterid;//过滤分类ID
private int result;
private String conditionvalue;
private String loginid="erro";
private String domain="erro";
private String addressarray;
private String filename;
private String addressstr;
private String verifystr;
private String filterbody;//过滤内容
private File file;
private PageBean pagebean;
private YxySendFilterAddress filteraddress;
private YxySendFilterAddressService filteraddressservice;
private List<YxySendFilterAddress> filteraddresslist;
private Map<String,Integer> resultmap=new HashMap<String, Integer>();
public YxySendFilterAddressService getFilteraddressservice() {
return filteraddressservice;
}
public void setFilteraddressservice(
YxySendFilterAddressService filteraddressservice) {
this.filteraddressservice = filteraddressservice;
}
public List<YxySendFilterAddress> getFilteraddresslist() {
return filteraddresslist;
}
public void setFilteraddresslist(List<YxySendFilterAddress> filteraddresslist) {
this.filteraddresslist = filteraddresslist;
}
public int getCondition() {
return condition;
}
public void setCondition(int condition) {
this.condition = condition;
}
public String getConditionvalue() {
return conditionvalue;
}
public void setConditionvalue(String conditionvalue) {
this.conditionvalue = conditionvalue;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getCurrpage() {
return currpage;
}
public void setCurrpage(int currpage) {
this.currpage = currpage;
}
public PageBean getPagebean() {
return pagebean;
}
public void setPagebean(PageBean pagebean) {
this.pagebean = pagebean;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public YxySendFilterAddress getFilteraddress() {
return filteraddress;
}
public void setFilteraddress(YxySendFilterAddress filteraddress) {
this.filteraddress = filteraddress;
}
public String getLoginid() {
return loginid;
}
public void setLoginid(String loginid) {
this.loginid = loginid;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getAddressarray() {
return addressarray;
}
public void setAddressarray(String addressarray) {
this.addressarray = addressarray;
}
public Map<String, Integer> getResultmap() {
return resultmap;
}
public void setResultmap(Map<String, Integer> resultmap) {
this.resultmap = resultmap;
}
public String getFilterbody() {
return filterbody;
}
public void setFilterbody(String filterbody) {
this.filterbody = filterbody;
}
public int getFilterid() {
return filterid;
}
public void setFilterid(int filterid) {
this.filterid = filterid;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getAddressstr() {
return addressstr;
}
public void setAddressstr(String addressstr) {
this.addressstr = addressstr;
}
public String getVerifystr() {
return verifystr;
}
public void setVerifystr(String verifystr) {
this.verifystr = verifystr;
}
}