|
@@ -7,6 +7,7 @@ import com.jiayue.ssi.annotation.InterfaceLimit;
|
|
|
import com.jiayue.ssi.annotation.OperateLog;
|
|
|
import com.jiayue.ssi.backenum.AuditType;
|
|
|
import com.jiayue.ssi.backenum.BusinessType;
|
|
|
+import com.jiayue.ssi.entity.SysLogininfor;
|
|
|
import com.jiayue.ssi.entity.SysOperLog;
|
|
|
import com.jiayue.ssi.service.SysOperLogService;
|
|
|
import com.jiayue.ssi.util.DateUtils;
|
|
@@ -17,6 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 操作日志记录
|
|
|
*
|
|
@@ -142,4 +146,57 @@ public class SysOperlogController {
|
|
|
return ResponseVO.error(e);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 操作日志统计分析
|
|
|
+ *
|
|
|
+ * @return 列表信息
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/sysOperlogTotal")
|
|
|
+ @PreAuthorize("@ss.hasPermi('auditManager:sysOperlogTotal:list')")
|
|
|
+ public ResponseVO sysOperlogTotal(String startLoginTime,String endLoginTime) {
|
|
|
+ try {
|
|
|
+ QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotEmpty(startLoginTime)) {
|
|
|
+ wrapper.ge("oper_time", DateUtils.getDayStartTime(DateUtil.parseDate(startLoginTime)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(endLoginTime)) {
|
|
|
+ wrapper.le("oper_time", DateUtils.getDayLastTime(DateUtil.parseDate(endLoginTime)));
|
|
|
+ }
|
|
|
+ List<SysOperLog> sysOperLogList = sysOperLogService.list(wrapper);
|
|
|
+ Map<String,List<SysOperLog>> map = sysOperLogList.stream().collect(Collectors.groupingBy(item->DateUtil.format(item.getOperTime(),"yyyy-MM-dd")));
|
|
|
+ List<Map<String,String>> resultList = new ArrayList<>();
|
|
|
+ map.forEach((key,value)->{
|
|
|
+ List<SysOperLog> list = value;
|
|
|
+ Map<String,String> recordMap = new HashMap<>();
|
|
|
+ recordMap.put("day",key);
|
|
|
+ // 系统类型统计
|
|
|
+ List<SysOperLog> sysTypeList = list.stream().filter(sysOperLog->sysOperLog.getAuditType()==0).collect(Collectors.toList());
|
|
|
+ recordMap.put("syscount",sysTypeList.size()+"");
|
|
|
+ // 业务类型统计
|
|
|
+ List<SysOperLog> bizTypeList = list.stream().filter(sysOperLog->sysOperLog.getAuditType()==1).collect(Collectors.toList());
|
|
|
+ recordMap.put("bizcount",bizTypeList.size()+"");
|
|
|
+ // 操作成功统计
|
|
|
+ List<SysOperLog> successList = list.stream().filter(sysOperLog->sysOperLog.getStatus()==0).collect(Collectors.toList());
|
|
|
+ recordMap.put("success",successList.size()+"");
|
|
|
+ // 操作失败统计
|
|
|
+ List<SysOperLog> failList = list.stream().filter(sysOperLog->sysOperLog.getStatus()==1).collect(Collectors.toList());
|
|
|
+ recordMap.put("fail",failList.size()+"");
|
|
|
+ // 操作ip个数统计
|
|
|
+ int ips = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getOperIp()))), ArrayList::new)).size();
|
|
|
+ recordMap.put("ips",ips+"");
|
|
|
+ resultList.add(recordMap);
|
|
|
+ });
|
|
|
+ Collections.sort(resultList, new Comparator<Map<String, String>>() {
|
|
|
+ @Override
|
|
|
+ public int compare(Map<String, String> o1, Map<String, String> o2) {
|
|
|
+ return o1.get("day").compareTo(o2.get("day"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return ResponseVO.success(resultList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("获取操作日志统计列表异常");
|
|
|
+ return ResponseVO.error(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|