yshop1.7发布,后台升級eladmin2.4(前端,后台权限,代码生成器等重构),修复商品分类等一些问题
This commit is contained in:
@ -1,21 +1,22 @@
|
||||
package co.yixiang.aspect;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.service.LogService;
|
||||
import co.yixiang.utils.RequestHolder;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import co.yixiang.utils.ThrowableUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.service.LogService;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
@ -25,10 +26,13 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class LogAspect {
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
private final LogService logService;
|
||||
|
||||
private long currentTime = 0L;
|
||||
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
||||
|
||||
public LogAspect(LogService logService) {
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置切入点
|
||||
@ -45,12 +49,14 @@ public class LogAspect {
|
||||
*/
|
||||
@Around("logPointcut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Object result = null;
|
||||
currentTime = System.currentTimeMillis();
|
||||
Object result;
|
||||
currentTime.set(System.currentTimeMillis());
|
||||
result = joinPoint.proceed();
|
||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(),
|
||||
StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint,
|
||||
StringUtils.getIp(RequestHolder.getHttpServletRequest()),joinPoint,
|
||||
log,getUid());
|
||||
return result;
|
||||
}
|
||||
@ -63,10 +69,12 @@ public class LogAspect {
|
||||
*/
|
||||
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
|
||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(),
|
||||
StringUtils.getIP(RequestHolder.getHttpServletRequest()),
|
||||
StringUtils.getIp(RequestHolder.getHttpServletRequest()),
|
||||
(ProceedingJoinPoint)joinPoint, log,getUid());
|
||||
}
|
||||
|
||||
|
@ -21,60 +21,46 @@ public class Log implements Serializable {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 操作用户
|
||||
*/
|
||||
/** 操作用户 */
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
/** 描述 */
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 方法名
|
||||
*/
|
||||
/** 方法名 */
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
@Column(columnDefinition = "text")
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
@Column(name = "log_type")
|
||||
private String logType;
|
||||
|
||||
/**
|
||||
* 请求ip
|
||||
*/
|
||||
@Column(name = "request_ip")
|
||||
private String requestIp;
|
||||
|
||||
@Column(name = "address")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 请求耗时
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
private Long uid;
|
||||
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 异常详细
|
||||
*/
|
||||
/** 参数 */
|
||||
@Column(columnDefinition = "text")
|
||||
private String params;
|
||||
|
||||
/** 日志类型 */
|
||||
@Column(name = "log_type")
|
||||
private String logType;
|
||||
|
||||
/** 请求ip */
|
||||
@Column(name = "request_ip")
|
||||
private String requestIp;
|
||||
|
||||
/** 地址 */
|
||||
@Column(name = "address")
|
||||
private String address;
|
||||
|
||||
/** 浏览器 */
|
||||
private String browser;
|
||||
|
||||
/** 请求耗时 */
|
||||
private Long time;
|
||||
|
||||
/** 异常详细 */
|
||||
@Column(name = "exception_detail", columnDefinition = "text")
|
||||
private byte[] exceptionDetail;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
/** 创建日期 */
|
||||
@CreationTimestamp
|
||||
@Column(name = "create_time")
|
||||
private Timestamp createTime;
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@ -15,7 +16,9 @@ import java.util.Map;
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Repository
|
||||
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor {
|
||||
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor<Log> {
|
||||
|
||||
|
||||
|
||||
@Query(nativeQuery = true,
|
||||
value = "select l.id,l.create_time as createTime,l.description," +
|
||||
@ -28,21 +31,20 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
|
||||
"and if(?1 !='',u.nickname LIKE CONCAT('%',?1,'%'),1=1)")
|
||||
Page<Map> findAllByPageable(String nickname,
|
||||
Pageable pageable);
|
||||
|
||||
/**
|
||||
* 获取一个时间段的IP记录
|
||||
* @param date1
|
||||
* @param date2
|
||||
* @return
|
||||
* @param date1 startTime
|
||||
* @param date2 entTime
|
||||
* @return IP数目
|
||||
*/
|
||||
@Query(value = "select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s",nativeQuery = true)
|
||||
Long findIp(String date1, String date2);
|
||||
|
||||
/**
|
||||
* findExceptionById
|
||||
* @param id
|
||||
* @return
|
||||
* 根据日志类型删除信息
|
||||
* @param logType 日志类型
|
||||
*/
|
||||
@Query(value = "select exception_detail FROM log where id = ?1",nativeQuery = true)
|
||||
String findExceptionById(Long id);
|
||||
@Query(nativeQuery = true,value = "delete from log where log_type = ?1")
|
||||
@Modifying
|
||||
void deleteByLogType(String logType);
|
||||
}
|
||||
|
@ -1,62 +1,103 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import co.yixiang.service.LogService;
|
||||
import co.yixiang.service.dto.LogQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@RequestMapping("/api/logs")
|
||||
@Api(tags = "监控:日志管理")
|
||||
public class LogController {
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
private final LogService logService;
|
||||
|
||||
@GetMapping(value = "/logs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setType(0);
|
||||
return new ResponseEntity(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
public LogController(LogService logService) {
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check()")
|
||||
public void download(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
|
||||
criteria.setLogType("INFO");
|
||||
logService.download(logService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("导出错误数据")
|
||||
@ApiOperation("导出错误数据")
|
||||
@GetMapping(value = "/error/download")
|
||||
@PreAuthorize("@el.check()")
|
||||
public void errorDownload(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
|
||||
criteria.setLogType("ERROR");
|
||||
logService.download(logService.queryAll(criteria), response);
|
||||
}
|
||||
@GetMapping
|
||||
@ApiOperation("日志查询")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> getLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setType(0);
|
||||
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
@GetMapping(value = "/mlogs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity getApiLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setType(1);
|
||||
return new ResponseEntity(logService.findAllByPageable(criteria.getBlurry(),pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/user")
|
||||
public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
@GetMapping(value = "/user")
|
||||
@ApiOperation("用户日志查询")
|
||||
public ResponseEntity<Object> getUserLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setBlurry(SecurityUtils.getUsername());
|
||||
return new ResponseEntity(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
|
||||
return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/error")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
@GetMapping(value = "/error")
|
||||
@ApiOperation("错误日志查询")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("ERROR");
|
||||
return new ResponseEntity(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/error/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getErrorLogs(@PathVariable Long id){
|
||||
return new ResponseEntity(logService.findByErrDetail(id), HttpStatus.OK);
|
||||
@GetMapping(value = "/error/{id}")
|
||||
@ApiOperation("日志异常详情查询")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> getErrorLogs(@PathVariable Long id){
|
||||
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping(value = "/del/error")
|
||||
@Log("删除所有ERROR日志")
|
||||
@ApiOperation("删除所有ERROR日志")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> delAllByError(){
|
||||
logService.delAllByError();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/del/info")
|
||||
@Log("删除所有INFO日志")
|
||||
@ApiOperation("删除所有INFO日志")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> delAllByInfo(){
|
||||
logService.delAllByInfo();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -6,44 +6,75 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
public interface LogService {
|
||||
|
||||
Object findAllByPageable(String nickname, Pageable pageable);
|
||||
|
||||
|
||||
Object findAllByPageable(String nickname, Pageable pageable);
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
* 分页查询
|
||||
* @param criteria 查询条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAllByUser
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
* 查询全部数据
|
||||
* @param criteria 查询条件
|
||||
* @return /
|
||||
*/
|
||||
List<Log> queryAll(LogQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询用户日志
|
||||
* @param criteria 查询条件
|
||||
* @param pageable 分页参数
|
||||
* @return -
|
||||
*/
|
||||
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 新增日志
|
||||
* @param username
|
||||
* @param ip
|
||||
* @param joinPoint
|
||||
* @param log
|
||||
* 保存日志数据
|
||||
* @param username 用户
|
||||
* @param browser 浏览器
|
||||
* @param ip 请求IP
|
||||
* @param joinPoint /
|
||||
* @param log 日志实体
|
||||
*/
|
||||
@Async
|
||||
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log,Long uid);
|
||||
|
||||
/**
|
||||
* 查询异常详情
|
||||
* @param id
|
||||
* @return
|
||||
* @param id 日志ID
|
||||
* @return Object
|
||||
*/
|
||||
Object findByErrDetail(Long id);
|
||||
|
||||
/**
|
||||
* 导出日志
|
||||
* @param logs 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<Log> logs, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除所有错误日志
|
||||
*/
|
||||
void delAllByError();
|
||||
|
||||
/**
|
||||
* 删除所有INFO日志
|
||||
*/
|
||||
void delAllByInfo();
|
||||
}
|
||||
|
@ -13,36 +13,19 @@ public class LogErrorDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 操作用户
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 方法名
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 请求ip
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
private String requestIp;
|
||||
|
||||
private String address;
|
||||
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private Timestamp createTime;
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import co.yixiang.annotation.Query;
|
||||
import lombok.Data;
|
||||
import co.yixiang.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 日志查询类
|
||||
@ -11,14 +13,16 @@ import lombok.Data;
|
||||
@Data
|
||||
public class LogQueryCriteria {
|
||||
|
||||
// 多字段模糊
|
||||
@Query(blurry = "username,description,address,requestIp,method,params")
|
||||
private String blurry;
|
||||
|
||||
@Query
|
||||
private String logType;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
|
||||
@Query
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@ -12,25 +11,15 @@ import java.sql.Timestamp;
|
||||
@Data
|
||||
public class LogSmallDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 请求ip
|
||||
*/
|
||||
private String requestIp;
|
||||
|
||||
/**
|
||||
* 请求耗时
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
||||
|
@ -1,26 +1,29 @@
|
||||
package co.yixiang.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.service.LogService;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.QueryHelp;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import co.yixiang.repository.LogRepository;
|
||||
import co.yixiang.service.LogService;
|
||||
import co.yixiang.service.dto.LogQueryCriteria;
|
||||
import co.yixiang.service.mapper.LogErrorMapper;
|
||||
import co.yixiang.service.mapper.LogSmallMapper;
|
||||
import co.yixiang.utils.*;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -31,16 +34,12 @@ import java.util.Map;
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
@Autowired
|
||||
private LogRepository logRepository;
|
||||
private final LogRepository logRepository;
|
||||
|
||||
@Autowired
|
||||
private LogErrorMapper logErrorMapper;
|
||||
private final LogErrorMapper logErrorMapper;
|
||||
|
||||
@Autowired
|
||||
private LogSmallMapper logSmallMapper;
|
||||
private final LogSmallMapper logSmallMapper;
|
||||
|
||||
private final String LOGINPATH = "login";
|
||||
|
||||
@Override
|
||||
public Object findAllByPageable(String nickname, Pageable pageable) {
|
||||
@ -51,15 +50,27 @@ public class LogServiceImpl implements LogService {
|
||||
return map;
|
||||
}
|
||||
|
||||
public LogServiceImpl(LogRepository logRepository, LogErrorMapper logErrorMapper, LogSmallMapper logSmallMapper) {
|
||||
this.logRepository = logRepository;
|
||||
this.logErrorMapper = logErrorMapper;
|
||||
this.logSmallMapper = logSmallMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(LogQueryCriteria criteria, Pageable pageable){
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
if ("ERROR".equals(criteria.getLogType())) {
|
||||
String status = "ERROR";
|
||||
if (status.equals(criteria.getLogType())) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Log> queryAll(LogQueryCriteria criteria) {
|
||||
return logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
@ -69,12 +80,25 @@ public class LogServiceImpl implements LogService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint,
|
||||
Log log,Long uid){
|
||||
Log log,Long uid){
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
co.yixiang.aop.log.Log aopLog = method.getAnnotation(co.yixiang.aop.log.Log.class);
|
||||
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";
|
||||
|
||||
StringBuilder params = new StringBuilder("{");
|
||||
//参数值
|
||||
Object[] argValues = joinPoint.getArgs();
|
||||
//参数名称
|
||||
String[] argNames = ((MethodSignature)joinPoint.getSignature()).getParameterNames();
|
||||
if(argValues != null){
|
||||
for (int i = 0; i < argValues.length; i++) {
|
||||
params.append(" ").append(argNames[i]).append(": ").append(argValues[i]);
|
||||
}
|
||||
}
|
||||
// 描述
|
||||
if (log != null) {
|
||||
log.setDescription(aopLog.value());
|
||||
@ -84,29 +108,14 @@ public class LogServiceImpl implements LogService {
|
||||
if(uid != null) {
|
||||
log.setUid(uid);
|
||||
}
|
||||
|
||||
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";
|
||||
|
||||
String params = "{";
|
||||
//参数值
|
||||
Object[] argValues = joinPoint.getArgs();
|
||||
//参数名称
|
||||
String[] argNames = ((MethodSignature)joinPoint.getSignature()).getParameterNames();
|
||||
if(argValues != null){
|
||||
for (int i = 0; i < argValues.length; i++) {
|
||||
params += " " + argNames[i] + ": " + argValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取IP地址
|
||||
assert log != null;
|
||||
log.setRequestIp(ip);
|
||||
|
||||
if(LOGINPATH.equals(signature.getName())){
|
||||
String loginPath = "login";
|
||||
if(loginPath.equals(signature.getName())){
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(argValues[0]);
|
||||
username = jsonObject.get("username").toString();
|
||||
assert argValues != null;
|
||||
username = new JSONObject(argValues[0]).get("username").toString();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -114,12 +123,45 @@ public class LogServiceImpl implements LogService {
|
||||
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
|
||||
log.setMethod(methodName);
|
||||
log.setUsername(username);
|
||||
log.setParams(params + " }");
|
||||
log.setParams(params.toString() + " }");
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findByErrDetail(Long id) {
|
||||
return Dict.create().set("exception",logRepository.findExceptionById(id));
|
||||
Log log = logRepository.findById(id).orElseGet(Log::new);
|
||||
ValidationUtil.isNull( log.getId(),"Log","id", id);
|
||||
byte[] details = log.getExceptionDetail();
|
||||
return Dict.create().set("exception",new String(ObjectUtil.isNotNull(details) ? details : "".getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<Log> logs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Log log : logs) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", log.getUsername());
|
||||
map.put("IP", log.getRequestIp());
|
||||
map.put("IP来源", log.getAddress());
|
||||
map.put("描述", log.getDescription());
|
||||
map.put("浏览器", log.getBrowser());
|
||||
map.put("请求耗时/毫秒", log.getTime());
|
||||
map.put("异常详情", new String(ObjectUtil.isNotNull(log.getExceptionDetail()) ? log.getExceptionDetail() : "".getBytes()));
|
||||
map.put("创建日期", log.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByError() {
|
||||
logRepository.deleteByLogType("ERROR");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByInfo() {
|
||||
logRepository.deleteByLogType("INFO");
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package co.yixiang.service.mapper;
|
||||
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
import co.yixiang.service.dto.LogErrorDTO;
|
||||
import co.yixiang.base.BaseMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogErrorMapper extends EntityMapper<LogErrorDTO, Log> {
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogErrorMapper extends BaseMapper<LogErrorDTO, Log> {
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package co.yixiang.service.mapper;
|
||||
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
import co.yixiang.base.BaseMapper;
|
||||
import co.yixiang.service.dto.LogSmallDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogSmallMapper extends EntityMapper<LogSmallDTO, Log> {
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogSmallMapper extends BaseMapper<LogSmallDTO, Log> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user