|
|
|
@ -1,8 +1,12 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISysLogService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.FileContentTypeTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
@ -12,20 +16,24 @@ import cn.estsh.i3plus.pojo.platform.platbean.*;
|
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description :
|
|
|
|
@ -42,6 +50,13 @@ public class ImppLogController extends CoreBaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysLogService logService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
@Resource(name= CommonConstWords.IMPP_REDIS_RES)
|
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 系统日志分页复杂查询
|
|
|
|
|
*
|
|
|
|
@ -206,11 +221,11 @@ public class ImppLogController extends CoreBaseController {
|
|
|
|
|
@ApiOperation(value = "添加操作日志", notes = "添加操作日志,可用于国际化")
|
|
|
|
|
public ResultBean logClean(String time) {
|
|
|
|
|
try {
|
|
|
|
|
Date thisTime = TimeTool.parseDate(time);
|
|
|
|
|
String startTime = TimeTool.getToday(TimeTool.getDateBefore(thisTime, 0)) + " 00:00:00";
|
|
|
|
|
String endTime = TimeTool.getToday(TimeTool.getDateBefore(thisTime, 0)) + " 23:59:59";
|
|
|
|
|
|
|
|
|
|
logService.actionCleanLog(startTime, endTime);
|
|
|
|
|
int to = RedisCacheTool.getSysConfigIntVal(CommonConstWords.LOG_STORAGE_DAYS, CommonConstWords.LOG_STORAGE_DAYS_DEFAULT);
|
|
|
|
|
Date thisTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -2 - to);
|
|
|
|
|
String startTime = TimeTool.getToday(thisTime) + " 00:00:00";
|
|
|
|
|
String endTime = TimeTool.getToday(TimeTool.timeCalc(thisTime, Calendar.DAY_OF_MONTH, to)) + " 23:59:59";
|
|
|
|
|
logService.actionCleanLog(startTime,endTime);
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep).build();
|
|
|
|
@ -219,4 +234,62 @@ public class ImppLogController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 操作日志导出
|
|
|
|
|
* @param logOperate 查询条件
|
|
|
|
|
* @param response
|
|
|
|
|
* @throws Exception 异常
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/operate/export")
|
|
|
|
|
@ApiOperation(value = "操作日志导出", notes = "操作日志导出")
|
|
|
|
|
public void exportSysLogUserLogin(SysLogOperate logOperate, HttpServletResponse response) throws Exception {
|
|
|
|
|
File file = null;
|
|
|
|
|
try {
|
|
|
|
|
Pager pager = Pager.defaultPager();
|
|
|
|
|
pager.setCurrentPage(0);
|
|
|
|
|
pager.setTotalPages(1);
|
|
|
|
|
List<SysLogOperate> list = new ArrayList();
|
|
|
|
|
do {
|
|
|
|
|
pager.next();
|
|
|
|
|
ListPager listPager = logService.queryLogOperatePager(logOperate, pager);
|
|
|
|
|
if (listPager.getObjectPager().getTotalRows() >= 10000) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("数据过大,导出数据建议在10000以内")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.addAll(listPager.getObjectList());
|
|
|
|
|
pager= listPager.getObjectPager();
|
|
|
|
|
} while (pager.hasNext());
|
|
|
|
|
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
Class logOperateClass =SysLogOperate.class;
|
|
|
|
|
String fileName = "log-operate-" + System.currentTimeMillis() + ".xls";
|
|
|
|
|
file = new File(fileName);
|
|
|
|
|
file.createNewFile();
|
|
|
|
|
File excle = excelTool.exportData(file, list, logOperateClass, (LinkedHashMap<String, String>) ExcelTool.getColName(logOperateClass));
|
|
|
|
|
|
|
|
|
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名
|
|
|
|
|
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName,true)));
|
|
|
|
|
|
|
|
|
|
// 设置文件名
|
|
|
|
|
try (BufferedInputStream bis = new BufferedInputStream(new DataInputStream(new FileInputStream(excle)))) {
|
|
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int i = bis.read(buffer);
|
|
|
|
|
while (i != -1) {
|
|
|
|
|
os.write(buffer, 0, i);
|
|
|
|
|
i = bis.read(buffer);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
FileUtils.deleteQuietly(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|