package com.slcf.service.impl;
|
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
//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 org.apache.poi.ss.util.CellRangeAddress;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.slcf.bean.SysLogCondition;
|
import com.slcf.dao.SysLogDao;
|
import com.slcf.pojo.SysLogBean;
|
import com.slcf.service.SysLogService;
|
import com.slcf.util.DateTimeUtil;
|
|
/**
|
* 日志管理接口实现
|
* @author admin
|
* @date 2018年11月9日
|
*/
|
@Service
|
public class SysLogServiceImpl implements SysLogService {
|
|
@Autowired
|
SysLogDao sysLogDao;
|
|
/**
|
* 添加
|
*/
|
public int insertSysLog(SysLogBean sysLog) {
|
int result=0;
|
try {
|
result=sysLogDao.insertSysLog(sysLog);
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
/**
|
* 分页查询所有
|
*/
|
public Map<String,Object> querySysLogList(SysLogCondition sysLogCon) {
|
try {
|
Map<String,Object> map=new HashMap<String, Object>();
|
List<SysLogBean> list=sysLogDao.querySysLogList(sysLogCon);
|
int count =sysLogDao.getSysLogCount(sysLogCon);
|
map.put("rows", list);
|
map.put("total", count);
|
return map;
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
return null;
|
}
|
}
|
|
/**
|
* 根据id查找
|
*/
|
public SysLogBean querySysLogById(int id) {
|
try {
|
return sysLogDao.getSysLogById(id);
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
return null;
|
}
|
}
|
|
/**
|
* 根据id删除
|
*/
|
public int delSysLog(int did) {
|
int result=0;
|
try {
|
result=sysLogDao.delSysLogById(did);
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
/**
|
* 查询所有
|
* @return
|
*/
|
public List<SysLogBean> getSysLogList() {
|
try {
|
return sysLogDao.getSysLogList();
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
return null;
|
}
|
}
|
|
/**
|
* 删除所有数据
|
*/
|
public int resetSysLog() {
|
int result=0;
|
try {
|
result=sysLogDao.resetSysLog();
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
//导出excel
|
public void ExportSysLogList(SysLogCondition sysLogCon, HttpServletResponse response) {
|
//输出Excel文件
|
try {
|
//HSSFWorkbook对象(excel的文档对象)
|
HSSFWorkbook workBook=new HSSFWorkbook();
|
|
//sheet对象(excel的表单)
|
HSSFSheet sheet=workBook.createSheet("系统日志信息");
|
|
//行数,参数为行索引(excel的行)
|
// HSSFRow rowHead=sheet.createRow(0);//第一行 可以是0~65535之间的任何一个
|
|
// //创建excel的单元格,参数为列索引,可以是0~255之间的任何一个
|
// HSSFCell cellOne=rowHead.createCell(0);
|
// cellOne.setCellValue("用户信息");//表头
|
|
//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
|
// sheet.addMergedRegion(new CellRangeAddress(0,0,0,5));
|
|
sheet.setColumnWidth(0, (int)((15 + 0.72) * 256));
|
sheet.setColumnWidth(1, (int)((15 + 0.72) * 256));
|
sheet.setColumnWidth(2, (int)((35 + 0.72) * 256));
|
sheet.setColumnWidth(3, (int)((20 + 0.72) * 256));
|
sheet.setColumnWidth(4, (int)((30 + 0.72) * 256));
|
sheet.setColumnWidth(5, (int)((60 + 0.72) * 256));
|
|
HSSFRow rows=sheet.createRow(0);//第二行
|
//创建单元格并设置单元格内容
|
rows.createCell(0).setCellValue("用户账号");
|
rows.createCell(1).setCellValue("用户名称");
|
rows.createCell(2).setCellValue("日期");
|
rows.createCell(3).setCellValue("客户端IP");
|
rows.createCell(4).setCellValue("请求API");
|
rows.createCell(5).setCellValue("操作内容");
|
|
List<SysLogBean> sysLogList=sysLogDao.getSysLogAll(sysLogCon);
|
for(int i=0;i<sysLogList.size();i++){
|
HSSFRow row=sheet.createRow(i+1);//从第三行开始
|
//创建单元格并设置单元格内容
|
row.createCell(0).setCellValue(sysLogList.get(i).getLogin_no());
|
row.createCell(1).setCellValue(sysLogList.get(i).getLogin_name());
|
row.createCell(2).setCellValue(sysLogList.get(i).getLogin_date());
|
row.createCell(3).setCellValue(sysLogList.get(i).getMachine_ip());
|
row.createCell(4).setCellValue(sysLogList.get(i).getForm_no());
|
row.createCell(5).setCellValue(sysLogList.get(i).getTts_keyname());
|
}
|
// //输出Excel文件
|
// try {
|
OutputStream output=response.getOutputStream();
|
response.reset();
|
response.setHeader("Content-disposition", "attachment; filename=SysLog"+DateTimeUtil.getStringDateTime(14)+".xls");
|
response.setContentType("application/msexcel");
|
workBook.write(output);
|
output.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|