Search in sources :

Example 1 with SysAccessLog

use of com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog in project Hidoc by yuzhengyang.

the class TestController method export.

@GetMapping({ "export" })
public ResponseData export() {
    String fileName = DirTool.combine(R.Paths.Temp, UUIDTool.get() + ".xlsx");
    // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
    // 如果这里想使用03 则 传入excelType参数即可
    ExcelWriter excelWriter = EasyExcel.write(fileName, SysAccessLog.class).build();
    WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").head(SysAccessLog.class).build();
    // region 分批处理
    for (int i = 0; i < 500; i++) {
        List<SysAccessLog> list = sysAccessLogMapper.selectList(null);
    // fillData(list);
    // excelWriter.write(list, writeSheet);
    }
    // endregion
    // //region 全量处理
    // List list = new ArrayList();
    // for (int i = 0; i < 500; i++) {
    // List<SysAccessLog> _l = sysAccessLogMapper.selectList(null);
    // list.addAll(_l);
    // }
    // fillData(list);
    // excelWriter.write(list, writeSheet);
    // //endregion
    excelWriter.finish();
    return ResponseData.ok();
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteSheet(com.alibaba.excel.write.metadata.WriteSheet) SysAccessLog(com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)

Example 2 with SysAccessLog

use of com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog in project Hidoc by yuzhengyang.

the class TestController method loadbig.

/**
 * 存储 indexeddb
 * 参考:
 * https://blog.csdn.net/xhom_w/article/details/103463460
 * http://www.ruanyifeng.com/blog/2018/07/indexeddb.html
 * @return
 */
@GetMapping({ "loadbig" })
public ResponseData loadbig() {
    long beg = System.currentTimeMillis();
    // //region 分批处理
    // for (int i = 0; i < 500; i++) {
    // List<SysAccessLog> list = sysAccessLogMapper.selectList(null);
    // fillData(list);
    // }
    // //endregion
    long size = 0;
    // List<String> jsons = new ArrayList<>();
    // region 全量处理
    List list = new ArrayList();
    for (int i = 0; i < 5; i++) {
        List<SysAccessLog> _l = sysAccessLogMapper.selectList(null);
        list.addAll(_l);
    // fillData(_l);
    // String s = JSONObject.toJSONString(_l);
    // jsons.add(s);
    // size = size + s.length();
    }
    // endregion
    long end = System.currentTimeMillis();
    log.info("共计花费:" + ((end - beg) / 1000) + " 秒");
    return ResponseData.okData(list);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SysAccessLog(com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)

Example 3 with SysAccessLog

use of com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog in project Hidoc by yuzhengyang.

the class LogInterceptor method createLog.

/**
 * 记录请求日志
 *
 * @param request 参数
 */
private void createLog(String step, HttpServletRequest request) {
    try {
        Thread currentThread = Thread.currentThread();
        SysAccessLog sysAccessLog = new SysAccessLog();
        sysAccessLog.setId(R.SnowFlake.nexts());
        sysAccessLog.setIp(ClientIPTool.getIp(request));
        sysAccessLog.setBeginTime(LocalDateTime.now());
        sysAccessLog.setEndTime(null);
        sysAccessLog.setUri(URLDecoder.decode(request.getRequestURI(), "utf-8"));
        sysAccessLog.setMethod(request.getMethod());
        sysAccessLog.setElapsedTime(0L);
        if (CurrentUserManager.isLogin()) {
            sysAccessLog.setUserId(CurrentUserManager.getUser().getId());
        }
        sysAccessLog.setStep(step);
        sysAccessLog.setThreadName(currentThread.getName());
        sysAccessLog.setException("");
        Runtime runtime = Runtime.getRuntime();
        sysAccessLog.setBeginMaxMemory(runtime.maxMemory());
        sysAccessLog.setBeginTotalMemory(runtime.totalMemory());
        sysAccessLog.setBeginFreeMemory(runtime.freeMemory());
        CurrentAccessManager.set(sysAccessLog);
        R.Queue.SysAccessLogQuene.add(sysAccessLog);
    } catch (Exception ex) {
    }
}
Also used : SysAccessLog(com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)

Example 4 with SysAccessLog

use of com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog in project Hidoc by yuzhengyang.

the class LogInterceptor method updateLog.

private void updateLog(String step, Exception exception) {
    try {
        if (CurrentAccessManager.isAccess()) {
            Thread currentThread = Thread.currentThread();
            SysAccessLog sysAccessLog = CurrentAccessManager.getWebAccessLog();
            sysAccessLog.setEndTime(LocalDateTime.now());
            if (sysAccessLog.getBeginTime() != null && sysAccessLog.getEndTime() != null) {
                Duration duration = Duration.between(sysAccessLog.getBeginTime(), sysAccessLog.getEndTime());
                sysAccessLog.setElapsedTime(duration.toMillis());
            }
            if (StringTool.ok(sysAccessLog.getThreadName()) && !sysAccessLog.getThreadName().equals(currentThread.getName())) {
                sysAccessLog.setThreadName(sysAccessLog.getThreadName() + " -> " + currentThread.getName());
            } else {
                sysAccessLog.setThreadName(currentThread.getName());
            }
            if (exception != null) {
                sysAccessLog.setException(ExceptionTool.getStackTrace(exception));
            }
            sysAccessLog.setStep(sysAccessLog.getStep() + " -> " + step);
            Runtime runtime = Runtime.getRuntime();
            sysAccessLog.setEndMaxMemory(runtime.maxMemory());
            sysAccessLog.setEndTotalMemory(runtime.totalMemory());
            sysAccessLog.setEndFreeMemory(runtime.freeMemory());
            if (sysAccessLog.getBeginFreeMemory() != null && sysAccessLog.getEndFreeMemory() != null) {
                sysAccessLog.setProbablyUseMemory(sysAccessLog.getBeginFreeMemory() - sysAccessLog.getEndFreeMemory());
            }
            R.Queue.SysAccessLogQuene.add(sysAccessLog);
            CurrentAccessManager.clear();
        }
    } catch (Exception ex) {
    }
}
Also used : Duration(java.time.Duration) SysAccessLog(com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)

Example 5 with SysAccessLog

use of com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog in project Hidoc by yuzhengyang.

the class CurrentAccessManager method isAccess.

public static boolean isAccess() {
    boolean ac = Access.get();
    SysAccessLog lg = webAccessLog.get();
    return ac && lg != null;
}
Also used : SysAccessLog(com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)

Aggregations

SysAccessLog (com.yuzhyn.hidoc.app.application.entity.sys.SysAccessLog)5 ExcelWriter (com.alibaba.excel.ExcelWriter)1 WriteSheet (com.alibaba.excel.write.metadata.WriteSheet)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1