1
1 <input type="button" value="导出" onclick="window.location.href='${pageContext.request.contextPath}/operationLog/exportCSV.action';"/>
2.
1 package com.bjpowernode.egov.web.action; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 8 import javax.annotation.Resource; 9 10 import org.apache.struts2.convention.annotation.Action; 11 import org.apache.struts2.convention.annotation.Namespace; 12 import org.apache.struts2.convention.annotation.Result; 13 import org.springframework.context.annotation.Scope; 14 import org.springframework.stereotype.Controller; 15 16 import com.bjpowernode.egov.domain.OperationLog; 17 import com.bjpowernode.egov.service.OperationLogService; 18 import com.bjpowernode.egov.vo.PaginationVO; 19 20 @Controller 21 @Namespace("/operationLog") 22 @Scope("prototype") 23 public class OperationLogAction extends BaseAction { 24 25 @Resource(name="operationLogService") 26 private OperationLogService operationLogService; 27 28 private Integer pageNo; 29 private Integer pageSize; 30 private String operatorName; 31 private String operationType; 32 private String startTime; 33 private String endTime; 34 35 public void setPageNo(Integer pageNo) { 36 this.pageNo = pageNo; 37 } 38 39 public void setPageSize(Integer pageSize) { 40 this.pageSize = pageSize; 41 } 42 43 public void setOperatorName(String operatorName) { 44 this.operatorName = operatorName; 45 } 46 47 public void setOperationType(String operationType) { 48 this.operationType = operationType; 49 } 50 51 public void setStartTime(String startTime) { 52 this.startTime = startTime; 53 } 54 55 public void setEndTime(String endTime) { 56 this.endTime = endTime; 57 } 58 100 101 @Action("exportCSV") 102 public String exportCSV() throws Exception{ 103 String csv = operationLogService.getCsv(); 104 response.setContentType("application/vnd.ms-excel;charset=GBK"); 105 response.getWriter().write(csv); 106 //response.addHeader("Content-Disposition","attachment;filename=operation_log.csv"); 107 response.addHeader("Content-Disposition","attachment;filename="+new String("操作日志".getBytes("UTF-8"),"ISO8859-1")+".csv"); 108 return null; 109 } 110 111 112 }
2
1 package com.bjpowernode.egov.service.impl; 2 3 import java.io.ByteArrayOutputStream; 4 import java.io.IOException; 5 import java.util.List; 6 7 import javax.annotation.Resource; 8 9 import org.apache.poi.hssf.usermodel.HSSFRow; 10 import org.apache.poi.hssf.usermodel.HSSFSheet; 11 import org.apache.poi.hssf.usermodel.HSSFWorkbook; 12 import org.springframework.stereotype.Service; 13 14 import com.bjpowernode.egov.dao.OperationLogDao; 15 import com.bjpowernode.egov.domain.OperationLog; 16 import com.bjpowernode.egov.service.OperationLogService; 17 import com.bjpowernode.egov.vo.PaginationVO; 18 19 @Service("operationLogService") 20 public class OperationLogServiceImpl implements OperationLogService { 21 22 @Resource(name="operationLogDao") 23 private OperationLogDao operationLogDao; 24 25 @Override 26 public PaginationVO<OperationLog> getByPage(Integer pageNo, 27 Integer pageSize, String operatorName, String operationType, 28 String startTime, String endTime) { 29 return operationLogDao.getByPage(pageNo,pageSize,operatorName,operationType,startTime,endTime); 30 } 31 32 33 @Override 34 public String getCsv() { 35 StringBuilder csv = new StringBuilder(); 36 csv.append("标识"); 37 csv.append(","); 38 csv.append("操作时间"); 39 csv.append(","); 40 csv.append("操作员"); 41 csv.append(","); 42 csv.append("ip地址"); 43 csv.append(","); 44 csv.append("操作模块"); 45 csv.append(","); 46 csv.append("操作节点"); 47 csv.append(","); 48 csv.append("操作类型"); 49 csv.append("\n"); 50 51 List<OperationLog> operationLogs = operationLogDao.getAll(); 52 for (OperationLog ol : operationLogs) { 53 csv.append(ol.getId()); 54 csv.append(","); 55 csv.append(ol.getTime()); 56 csv.append(","); 57 csv.append(ol.getOperator().getName()); 58 csv.append(","); 59 csv.append(ol.getIp()); 60 csv.append(","); 61 csv.append(ol.getModule()); 62 csv.append(","); 63 csv.append(ol.getNode()); 64 csv.append(","); 65 csv.append(ol.getType()); 66 csv.append("\n"); 67 } 68 return csv.toString(); 69 } 70 71 }