From 587eba5618e69a8f373d912b81d429d1568b1039 Mon Sep 17 00:00:00 2001 From: liushuai Date: Wed, 7 Jun 2023 08:37:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/scheduler/task/CommonLogTask.java | 101 +++++++++++---------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CommonLogTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CommonLogTask.java index 5035ecc..a03cdec 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CommonLogTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CommonLogTask.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.scheduler.task; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.file.FileReader; import cn.hutool.core.io.file.FileWriter; @@ -58,54 +58,57 @@ public class CommonLogTask { //查询日志 List logList = optLogMapper.selectList(query); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - if (CollUtil.isNotEmpty(logList)){ - logList.forEach(optLog -> { - CommonLog commonLog = new CommonLog(); - UserInfo userInfo = userInfoService.getById(optLog.getCreateBy()); - String employeeCode = userInfo.getEmployeeCode(); - if (StringUtils.isNotBlank(employeeCode)){ - DingEmployeeInfo dingEmployeeInfo = dingEmployeeInfoMapper.selectOne(new LambdaQueryWrapper() - .eq(DingEmployeeInfo::getEmployeeCode,employeeCode)); - if (dingEmployeeInfo != null){ - commonLog.setUserId(String.valueOf(dingEmployeeInfo.getAccountId())); - } - }else { - commonLog.setUserId(String.valueOf(userInfo.getId())); - } - commonLog.setUserRole("政府工作人员"); - commonLog.setAreaCode(userInfo.getRegionCode()); - String description = optLog.getDescription(); - if (description.equals("登录")){ - commonLog.setActionType(1); - }else if (description.equals("退出登录")){ - commonLog.setActionType(2); - }else { - commonLog.setActionType(3); - } - String actionId = UUID.randomUUID().toString(); - commonLog.setActionId(actionId); - commonLog.setActionTime(df.format(optLog.getStartTime())); - commonLog.setActionDuration(optLog.getConsumingTime()); - commonLog.setActionStatus(0); - commonLog.setAppCode(""); - //判断当天日志文件是否存在 - DateTimeFormatter dfNow = DateTimeFormatter.ofPattern("yyyyMMdd"); - String fileName = LOG_RECORD_ADDRESS + LOG_FILE + dfNow.format(LocalDateTime.now()) + ".log"; - boolean fileExist = FileUtil.exist(fileName); - if (!fileExist){ - //不存在则创建当天日志文件 - FileUtil.touch(fileName); - } - //写入通用规则 - FileWriter writer = new FileWriter(LOG_RECORD_ADDRESS + LOG_FILE); - writer.append(JSONUtil.toJsonStr(commonLog)); - if (commonLog.getActionType() == 3){ - CommonLog commonLogEnd = new CommonLog(); - BeanUtil.copyProperties(commonLog,commonLogEnd); - commonLogEnd.setActionType(4); - writer.append(JSONUtil.toJsonStr(commonLogEnd)); - } - }); + if (CollectionUtil.isNotEmpty(logList)){ + for (OptLog optLog : logList){ + CommonLog commonLog = new CommonLog(); + UserInfo userInfo = userInfoService.getById(optLog.getCreateBy()); + if (userInfo == null){ + continue; + } + String employeeCode = userInfo.getEmployeeCode(); + if (StringUtils.isNotBlank(employeeCode)){ + DingEmployeeInfo dingEmployeeInfo = dingEmployeeInfoMapper.selectOne(new LambdaQueryWrapper() + .eq(DingEmployeeInfo::getEmployeeCode,employeeCode)); + if (dingEmployeeInfo != null){ + commonLog.setUserId(String.valueOf(dingEmployeeInfo.getAccountId())); + } + }else { + commonLog.setUserId(String.valueOf(userInfo.getId())); + } + commonLog.setUserRole("政府工作人员"); + commonLog.setAreaCode(userInfo.getRegionCode()); + String description = optLog.getDescription(); + if (description.equals("登录")){ + commonLog.setActionType(1); + }else if (description.equals("退出登录")){ + commonLog.setActionType(2); + }else { + commonLog.setActionType(3); + } + String actionId = UUID.randomUUID().toString(); + commonLog.setActionId(actionId); + commonLog.setActionTime(df.format(optLog.getStartTime())); + commonLog.setActionDuration(optLog.getConsumingTime()); + commonLog.setActionStatus(0); + commonLog.setAppCode(""); + //判断当天日志文件是否存在 + DateTimeFormatter dfNow = DateTimeFormatter.ofPattern("yyyyMMdd"); + String fileName = LOG_RECORD_ADDRESS + LOG_FILE + dfNow.format(LocalDateTime.now()) + ".log"; + boolean fileExist = FileUtil.exist(fileName); + if (!fileExist){ + //不存在则创建当天日志文件 + FileUtil.touch(fileName); + } + //写入通用规则 + FileWriter writer = new FileWriter(LOG_RECORD_ADDRESS + LOG_FILE); + writer.append(JSONUtil.toJsonStr(commonLog)); + if (commonLog.getActionType() == 3){ + CommonLog commonLogEnd = new CommonLog(); + BeanUtil.copyProperties(commonLog,commonLogEnd); + commonLogEnd.setActionType(4); + writer.append(JSONUtil.toJsonStr(commonLogEnd)); + } + } //记录最后一个节点位置 FileWriter writer = new FileWriter(LOG_RECORD_ADDRESS + LOG_ID_FILE); writer.write(String.valueOf(logList.get(logList.size() - 1).getId()));