f039e67454cc8e260f7b94babf914fcc6f0a95f7.svn-base 17.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
package com.espeed.action;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
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.YxyReadingCount;
import com.espeed.pojo.YxyReadingInfo;
import com.espeed.service.YxyReadingInfoService;
import com.espeed.vo.PageBean;
import com.opensymphony.xwork2.ActionContext;

/**
 * 程序名称:    	EspeedMail_时速邮箱
 * 程序版本:    	V1.0
 * 作    者:    	深圳市科飞时速网络技术有限公司(0755-88843776)
 * 版权所有:    	深圳市科飞时速网络技术有限公司
 * 技术支持:    	Tech@21gmail.com
 * 单元名称:     点击action(营销邮)
 * 开始时间:    	2013.12.09
 * 程 序 员:    	谢勇
 * 最后修改:    
 * 备    注:		统计邮件点读量 (营销邮)   
 */
public class YxyReadingAction extends BaseAction{
	private static final long serialVersionUID = 1L;

	/**用户条件查询点读信息(分页)*/
	public String findRedingByCondition(){
		try {
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			if(loginid==null||"".equals(loginid)){
				loginid=user.getLogin_id();//用户账号
			}
			domain=user.getDomain();//用户所属域名
			pagebean.setCurrentPage(currpage);
			pagebean.setPageSize(pagesize);
			readlist=yxyreadinginfoservice.findRedingByCondition(loginid, domain, pagebean, condition, 
					conditionvalue,user);
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "list";
	}
	
	/**用户点读导出生成excel文件*/
	public String importUserReadList(){
		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();//用户所属域名
			int importresult=yxyreadinginfoservice.importUserReadList(loginid,domain,isrepeat,condition,
					conditionvalue,user);
			if(importresult==1){//成功
				result="1";
			}else{//无记录
				result="0";
			}
		} catch (Exception e) {
			result="-1";
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return SUCCESS;
	}
	
	/**根据邮件唯一码查询点读信息*/
	public String findReadByMailUID(){
		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();//用户所属域名
			readlist=yxyreadinginfoservice.findReadByMailUID(loginid,domain,mailuid);
		} 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 downloadDD(){
		try{
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();
			YxyUserInfo user = (YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			if(loginid == null || loginid.equals("")){
				loginid = user.getLogin_id();//用户账号
			}
			domain = user.getDomain();//用户所属域名
			//查询点读信息
			readlist = yxyreadinginfoservice.exportReadMail(loginid,domain,mailuid);	
			if(readlist.size() > 0){
				//获取项目路径
				String pathew = this.getClass().getClassLoader().getResource("/").getPath();
				pathew = pathew.substring(1, pathew.length());
				pathew = pathew.replace("/WEB-INF/classes/","");
				String dir=pathew+"\\tempUserFile\\"+domain+"\\"+loginid;
				//生成文件
				File file=new File(dir);
				file.mkdirs();
				HSSFWorkbook workbook = new HSSFWorkbook();
				HSSFSheet sheet = workbook.createSheet("ExportEmail");//在Excel工作簿中建一工作表
				HSSFCellStyle style = workbook.createCellStyle();
				HSSFFont font = workbook.createFont();
				font.setColor(HSSFFont.COLOR_RED);
				font.setFontHeight(HSSFFont.BOLDWEIGHT_NORMAL);
				style.setFont(font);
				HSSFCell cell = null;//创建列
				HSSFRow row = null;//创建行
				row = sheet.createRow((short) 0);
				cell = row.createCell((short)0);
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				cell.setEncoding(HSSFCell.ENCODING_UTF_16);
//				cell.setCellValue("您所发的邮件主题:"+this.emailSubject+" ,"+"发送时间:"+this.emailTime);
//				cell.setCellStyle(style);
				row = sheet.createRow((short) 1);
				//加入文件头
				//String [] str={"E-mail","点读时间","点读总数","点读地区","点读IP"};
				String [] str={"E-mail","点读时间","点读设备","点读地区","点读IP"};
				for(int begin = 0; begin < str.length; begin++){
					cell = row.createCell((short) begin);
					cell.setEncoding(HSSFCell.ENCODING_UTF_16);//如果内容有中文件,则要设置这里
					cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 定义单元格为字符串类型
					cell.setCellValue(str[begin]);
				}
				
				//加入详细信息
				for(int i=0;i<readlist.size();i++){
					row = sheet.createRow((short) i+2);
					for(int j = 0; j < 5; j++) {
					  cell = row.createCell((short) j);//创建列
					  cell.setEncoding(HSSFCell.ENCODING_UTF_16);//如果内容有中文件,则要设置这里
					  cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 定义单元格为字符串类型
					  //在单元格中输入一些内容
					  if(j==0) {
					      cell.setCellValue(readlist.get(i).getYxy_reading_email());
					  }else if(j==1) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_date());
					  } else if(j==2) {
						  //cell.setCellValue(readlist.get(i).getYxy_reading_num());
						  if(readlist.get(i).getYxy_useragent()!=null&&!"".equals(readlist.get(i).getYxy_useragent())){
							  cell.setCellValue(readlist.get(i).getYxy_useragent());
						  }else{
							  cell.setCellValue("PC设备谷歌浏览器");
						  }
					  } else if(j==3) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_area());
					  } else if(j==4) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_ip());
					  }
					}  
				}
				// 新建一输出文件流
				FileOutputStream fOut = new FileOutputStream(dir+"\\readinfo.xls");		
				workbook.write(fOut);
				fOut.flush();
				
				fOut.close();
				
				result="1"; //导出成功
			}else //该邮件无点读数据
			{
				result = "0";
			}
		}catch(Exception e){
			result = "-1";//出现异常
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "diandu";
	}
	
	/**导出全部点读地址*/
	public String exportAllRead(){
		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();//用户所属域名
			//用户所有点读地址信息
			readlist = yxyreadinginfoservice.exportAllMail(loginid, domain);
			if (readlist.size() > 0) {
				//获取项目路径
				String pathew = this.getClass().getClassLoader().getResource("/").getPath();
				pathew = pathew.substring(1, pathew.length());
				pathew = pathew.replace("/WEB-INF/classes/","");
				String dir=pathew+"\\tempUserFile\\"+domain+"\\"+loginid;
				
				//生成文件
				File file=new File(dir);
				file.mkdirs();
				HSSFWorkbook workbook = new HSSFWorkbook();
				HSSFSheet sheet = workbook.createSheet("ExportEmail");//在Excel工作簿中建一工作表
				HSSFCellStyle style = workbook.createCellStyle();
				HSSFFont font = workbook.createFont();
				font.setColor(HSSFFont.COLOR_RED);
				font.setFontHeight(HSSFFont.BOLDWEIGHT_NORMAL);
				style.setFont(font);
				HSSFCell cell = null;//创建列
				HSSFRow row = null;//创建行
				row = sheet.createRow((short) 0);
				cell = row.createCell((short)0);
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				cell.setEncoding(HSSFCell.ENCODING_UTF_16);
				row = sheet.createRow((short) 1);
				//加入文件头
				//String [] str={"E-mail","点读时间","点读总数","点读地区","点读IP"};
				String [] str={"E-mail","点读时间","点读设备","点读地区","点读IP"};
				for(int begin = 0; begin < str.length; begin++){
					cell = row.createCell((short) begin);
					cell.setEncoding(HSSFCell.ENCODING_UTF_16);//如果内容有中文件,则要设置这里
					cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 定义单元格为字符串类型
					cell.setCellValue(str[begin]);
				}
				//加入详细信息
				for(int i=0;i<readlist.size();i++){
					row = sheet.createRow((short) i+2);
					for(int j = 0; j < 5; j++){
					  cell = row.createCell((short) j);//创建列
					  cell.setEncoding(HSSFCell.ENCODING_UTF_16);//如果内容有中文件,则要设置这里
					  cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 定义单元格为字符串类型
					  //在单元格中输入一些内容
					  if(j==0) {
					      cell.setCellValue(readlist.get(i).getYxy_reading_email());
					  } else if(j==1) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_date());
					  } else if(j==2) {
						  if(readlist.get(i).getYxy_useragent()!=null&&!"".equals(readlist.get(i).getYxy_useragent())){
							  cell.setCellValue(readlist.get(i).getYxy_useragent());
						  }else{
							  cell.setCellValue("PC设备谷歌浏览器");
						  }
						  //cell.setCellValue(readlist.get(i).getYxy_reading_num());
					  } else if(j==3) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_area());
					  } else if(j==4) {
						  cell.setCellValue(readlist.get(i).getYxy_reading_ip());
					  }
					}  
				}
				// 新建一输出文件流
				FileOutputStream fOut = new FileOutputStream(dir+"\\readinfo.xls");		
				workbook.write(fOut);
				fOut.flush();
				fOut.close();
				result="1"; //导出成功
			}else{
				result ="0"; //无地址
			}
		} catch (Exception e) {
			result ="-1"; //出现异常
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "exportAll";
	}
	
	/**根据该邮件地址查询点读过的邮件*/
	public String findMailAddress(){
		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();//用户所属域名
			readlist = yxyreadinginfoservice.findMailAddress(loginid, domain, mail);
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "mailAddress";
	}
	
//	/**查询域下点读信息*/
//	public String findEmployRedingByUser(){
//		//String loginid="erro";
//		String domain="erro";
//		try {
//			//获取用户session
//			ActionContext ac = ActionContext.getContext();
//			Map<String,Object> sess = ac.getSession();			
//			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
//			domain=user.getCompanydomain().toString();//用户所属域名
//			
//			pageBean.setCurrentPage(currpage);
//			pageBean.setPageSize(pageSize);
//			yxyreadinfo=yxyreadinginfoservice.findEmployRedingByUser(loginid, domain, pageBean,year,month);
//		} catch (Exception e) {
//			StringWriter sw = new StringWriter();
//			e.printStackTrace(new PrintWriter(sw, true));
//	        String str = sw.toString();
//	        LogClass.saveLog(domain,loginid, "查询该用户的所有点读信息--ERRO--"+str);
//		}
//		return "allinfo";
//	}

	
//	/**根据年月查询*/
//	public String findByTimer(){
//		String loginid="";
//		String domain="";
//		try {
//			//获取用户session
//			ActionContext ac = ActionContext.getContext();
//			Map<String,Object> sess = ac.getSession();			
//			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
//			loginid=user.getLoginid().toString();//用户账号
//			domain=user.getCompanydomain().toString();//用户所属域名
//			System.out.println(conditionvalue +"  ----    " +  condition);
//			
//			if(conditionvalue.trim().length() != 0){
//				String[] strs = conditionvalue.split("#");
//				pagebean.setCurrentPage(currpage);
//				pagebean.setPageSize(pagesize);
//				year = Integer.parseInt(strs[0]);
//				month = Integer.parseInt(strs[1]);
//				readlist=yxyreadinginfoservice.findByTimer(loginid, domain, year, month, pagebean);
//				System.out.println(year+"------年");
//				System.out.println(month+"------月");
//			}
//			pagebean.setCurrentPage(currpage);
//			pagebean.setPageSize(pagesize);
//			readlist=yxyreadinginfoservice.findByTimer(loginid, domain, year, month, pagebean);
//			
//		} catch (Exception e) {
//			StringWriter sw = new StringWriter();
//			e.printStackTrace(new PrintWriter(sw, true));
//	        String str = sw.toString();
//	        LogClass.errolog(str, uid);
//	        e.printStackTrace();
//		}
//		return "list";
//	}
	
	private YxyReadingInfoService yxyreadinginfoservice;//点击service
	private YxyReadingCount yxyreadingcount;//点读统计信息
	private List<YxyReadingInfo> readlist;//点读集合
	private PageBean pagebean;
	private int currpage;
	private int pagesize=5;//每页显示量
	private String readidstr;//点读信息id
	private String result;//
	private int readTol;//点读总数
	private int readperson;//点读人数
	private String mailuid;//邮件唯一码
	private String loginid="";//用户账号
	private String domain="";//用户域名
	private int isrepeat;//是不是导出已导出过的
	private int month;//月
	private int year;//年
	private String emailSubject;//某一封邮件的主题
	private String emailTime;//邮件的发送时间
	private int condition;//条件
	private String conditionvalue;//条件值
	private String mail;//点读邮件地址
	private int isExport;
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public int getIsExport() {
		return isExport;
	}
	public void setIsExport(int isExport) {
		this.isExport = isExport;
	}
	public void setYxyreadinginfoservice(YxyReadingInfoService yxyreadinginfoservice) {
		this.yxyreadinginfoservice = yxyreadinginfoservice;
	}
	public YxyReadingCount getYxyreadingcount() {
		return yxyreadingcount;
	}
	public void setYxyreadingcount(YxyReadingCount yxyreadingcount) {
		this.yxyreadingcount = yxyreadingcount;
	}
	public int getReadTol() {
		return readTol;
	}
	public void setReadTol(int readTol) {
		this.readTol = readTol;
	}
	public int getReadperson() {
		return readperson;
	}
	public void setReadperson(int readperson) {
		this.readperson = readperson;
	}
	public String getMailuid() {
		return mailuid;
	}
	public void setMailuid(String mailuid) {
		this.mailuid = mailuid;
	}
	public int getCurrpage() {
		return currpage;
	}
	public void setCurrpage(int currpage) {
		this.currpage = currpage;
	}
	public int getPagesize() {
		return pagesize;
	}
	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String getLoginid() {
		return loginid;
	}
	public void setLoginid(String loginid) {
		this.loginid = loginid;
	}
	public int getIsrepeat() {
		return isrepeat;
	}
	public void setIsrepeat(int isrepeat) {
		this.isrepeat = isrepeat;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public String getEmailSubject() {
		return emailSubject;
	}
	public void setEmailSubject(String emailSubject) {
		this.emailSubject = emailSubject;
	}
	public String getEmailTime() {
		return emailTime;
	}
	public void setEmailTime(String emailTime) {
		this.emailTime = emailTime;
	}
	public List<YxyReadingInfo> getReadlist() {
		return readlist;
	}
	public void setReadlist(List<YxyReadingInfo> readlist) {
		this.readlist = readlist;
	}
	public String getDomain() {
		return domain;
	}
	public void setDomain(String domain) {
		this.domain = domain;
	}
	public int getCondition() {
		return condition;
	}
	public void setCondition(int condition) {
		this.condition = condition;
	}
	public PageBean getPagebean() {
		return pagebean;
	}
	public void setPagebean(PageBean pagebean) {
		this.pagebean = pagebean;
	}
	public String getConditionvalue() {
		return conditionvalue;
	}
	public void setConditionvalue(String conditionvalue) {
		this.conditionvalue = conditionvalue;
	}
	public String getReadidstr() {
		return readidstr;
	}
	public void setReadidstr(String readidstr) {
		this.readidstr = readidstr;
	}
}