@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>yshop</artifactId>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<version>2.2</version>
|
||||
<version>2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -16,13 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<artifactId>yshop-common</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<artifactId>yshop-mproot</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>compile</scope>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
17
yshop-logging/src/main/java/co/yixiang/aop/log/Log.java
Normal file
17
yshop-logging/src/main/java/co/yixiang/aop/log/Log.java
Normal file
@ -0,0 +1,17 @@
|
||||
package co.yixiang.aop.log;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
int type() default 0;
|
||||
}
|
@ -1,16 +1,8 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.aspect;
|
||||
package co.yixiang.aspect;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.logging.domain.Log;
|
||||
import co.yixiang.logging.service.LogService;
|
||||
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;
|
||||
@ -26,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Component
|
||||
@ -45,7 +37,7 @@ public class LogAspect {
|
||||
/**
|
||||
* 配置切入点
|
||||
*/
|
||||
@Pointcut("@annotation(co.yixiang.logging.aop.log.Log)")
|
||||
@Pointcut("@annotation(co.yixiang.aop.log.Log)")
|
||||
public void logPointcut() {
|
||||
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
||||
}
|
@ -1,17 +1,5 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.domain;
|
||||
package co.yixiang.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
@ -20,15 +8,17 @@ import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@TableName("log")
|
||||
@Table(name = "log")
|
||||
@NoArgsConstructor
|
||||
public class Log implements Serializable {
|
||||
|
||||
@TableId
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/** 操作用户 */
|
||||
@ -45,15 +35,19 @@ public class Log implements Serializable {
|
||||
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;
|
||||
|
||||
/** 浏览器 */
|
||||
@ -63,10 +57,12 @@ public class Log implements Serializable {
|
||||
private Long time;
|
||||
|
||||
/** 异常详细 */
|
||||
@Column(name = "exception_detail", columnDefinition = "text")
|
||||
private byte[] exceptionDetail;
|
||||
|
||||
/** 创建日期 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@CreationTimestamp
|
||||
@Column(name = "create_time")
|
||||
private Timestamp createTime;
|
||||
|
||||
public Log(String logType, Long time) {
|
@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.aop.log;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
int type() default 0;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogSmallDTO implements Serializable {
|
||||
|
||||
private String description;
|
||||
|
||||
private String requestIp;
|
||||
|
||||
private Long time;
|
||||
|
||||
private String address;
|
||||
|
||||
private String browser;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service.mapper;
|
||||
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.logging.domain.Log;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface LogMapper extends CoreMapper<Log> {
|
||||
|
||||
@Delete("delete from log where log_type = #{logType}")
|
||||
void deleteByLogType(@Param("logType") String logType);
|
||||
@Select("<script>select l.id,l.create_time as createTime,l.description, l.request_ip as requestIp,l.address,u.nickname from log l " +
|
||||
" left join yx_user u on u.uid=l.uid where l.type=1 " +
|
||||
" <if test = \"nickname !=null\"> and u.nickname LIKE CONCAT('%',#{nickname},'%')</if> order by l.id desc</script>")
|
||||
List<Log> findAllByPageable(@Param("nickname") String nickname);
|
||||
@Select( "select count(*) FROM (select request_ip FROM log where create_time between #{date1} and #{date2} GROUP BY request_ip) as s")
|
||||
long findIp(@Param("date1") String date1, @Param("date2")String date2);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package co.yixiang.repository;
|
||||
|
||||
import co.yixiang.domain.Log;
|
||||
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;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Repository
|
||||
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor<Log> {
|
||||
|
||||
|
||||
|
||||
@Query(nativeQuery = true,
|
||||
value = "select l.id,l.create_time as createTime,l.description," +
|
||||
"l.request_ip as requestIp,l.address," +
|
||||
"u.nickname from log l left join yx_user u on u.uid=l.uid " +
|
||||
" where l.type=1" +
|
||||
" and if(?1 !='',u.nickname LIKE CONCAT('%',?1,'%'),1=1) order by l.id desc",
|
||||
countQuery = "select count(*) from log l left join yx_user u on u.uid=l.uid" +
|
||||
" where l.type=1 " +
|
||||
"and if(?1 !='',u.nickname LIKE CONCAT('%',?1,'%'),1=1)")
|
||||
Page<Map> findAllByPageable(String nickname,
|
||||
Pageable pageable);
|
||||
/**
|
||||
* 获取一个时间段的IP记录
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 根据日志类型删除信息
|
||||
* @param logType 日志类型
|
||||
*/
|
||||
@Query(nativeQuery = true,value = "delete from log where log_type = ?1")
|
||||
@Modifying
|
||||
void deleteByLogType(String logType);
|
||||
}
|
@ -1,18 +1,10 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.rest;
|
||||
package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import co.yixiang.logging.service.LogService;
|
||||
import co.yixiang.logging.service.dto.LogQueryCriteria;
|
||||
import co.yixiang.service.LogService;
|
||||
import co.yixiang.service.dto.LogQueryCriteria;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -23,7 +15,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@RestController
|
||||
@ -41,7 +33,7 @@ public class LogController {
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','log:list')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public void download(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
|
||||
criteria.setLogType("INFO");
|
||||
logService.download(logService.queryAll(criteria), response);
|
||||
@ -50,21 +42,21 @@ public class LogController {
|
||||
@Log("导出错误数据")
|
||||
@ApiOperation("导出错误数据")
|
||||
@GetMapping(value = "/error/download")
|
||||
@PreAuthorize("@el.check('admin','log:list')")
|
||||
@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('admin','log:list')")
|
||||
@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("@el.check('admin','log:list')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity getApiLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setType(1);
|
||||
@ -80,7 +72,7 @@ public class LogController {
|
||||
|
||||
@GetMapping(value = "/error")
|
||||
@ApiOperation("错误日志查询")
|
||||
@PreAuthorize("@el.check('admin','logError:list')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("ERROR");
|
||||
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
@ -88,14 +80,14 @@ public class LogController {
|
||||
|
||||
@GetMapping(value = "/error/{id}")
|
||||
@ApiOperation("日志异常详情查询")
|
||||
@PreAuthorize("@el.check('admin','logError:detail')")
|
||||
@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('admin','logError:remove')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> delAllByError(){
|
||||
logService.delAllByError();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
@ -104,7 +96,7 @@ public class LogController {
|
||||
@DeleteMapping(value = "/del/info")
|
||||
@Log("删除所有INFO日志")
|
||||
@ApiOperation("删除所有INFO日志")
|
||||
@PreAuthorize("@el.check('admin','logInfo:remove')")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> delAllByInfo(){
|
||||
logService.delAllByInfo();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
@ -1,16 +1,7 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service;
|
||||
package co.yixiang.service;
|
||||
|
||||
import co.yixiang.logging.domain.Log;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.logging.service.dto.LogQueryCriteria;
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.service.dto.LogQueryCriteria;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -20,10 +11,10 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
public interface LogService extends BaseService<Log> {
|
||||
public interface LogService {
|
||||
|
||||
|
||||
|
@ -1,19 +1,11 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service.dto;
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
@ -36,4 +28,4 @@ public class LogErrorDTO implements Serializable {
|
||||
private String address;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
||||
}
|
@ -1,21 +1,13 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service.dto;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 日志查询类
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2019-6-4 09:23:07
|
||||
*/
|
||||
@Data
|
@ -0,0 +1,25 @@
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogSmallDTO implements Serializable {
|
||||
|
||||
private String description;
|
||||
|
||||
private String requestIp;
|
||||
|
||||
private Long time;
|
||||
|
||||
private String address;
|
||||
|
||||
private String browser;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
@ -1,29 +1,18 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.logging.service.impl;
|
||||
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.logging.aop.log.Log;
|
||||
import co.yixiang.logging.service.mapper.LogMapper;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.logging.service.LogService;
|
||||
import co.yixiang.logging.service.dto.LogErrorDTO;
|
||||
import co.yixiang.logging.service.dto.LogQueryCriteria;
|
||||
import co.yixiang.logging.service.dto.LogSmallDTO;
|
||||
import co.yixiang.domain.Log;
|
||||
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 com.github.pagehelper.PageInfo;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
@ -38,74 +27,64 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class LogServiceImpl extends BaseServiceImpl<LogMapper, co.yixiang.logging.domain.Log> implements LogService {
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
private final LogRepository logRepository;
|
||||
|
||||
private final LogMapper logMapper;
|
||||
private final LogErrorMapper logErrorMapper;
|
||||
|
||||
private final IGenerator generator;
|
||||
private final LogSmallMapper logSmallMapper;
|
||||
|
||||
public LogServiceImpl(LogMapper logMapper, IGenerator generator) {
|
||||
this.logMapper = logMapper;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findAllByPageable(String nickname, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<co.yixiang.logging.domain.Log> page = new PageInfo<>(logMapper.findAllByPageable(nickname));
|
||||
Page<Map> page = logRepository.findAllByPageable(nickname,pageable);
|
||||
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content",page.getList());
|
||||
map.put("totalElements",page.getTotal());
|
||||
map.put("content",page.getContent());
|
||||
map.put("totalElements",page.getTotalElements());
|
||||
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){
|
||||
|
||||
getPage(pageable);
|
||||
PageInfo<co.yixiang.logging.domain.Log> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
String status = "ERROR";
|
||||
if(status.equals(criteria.getLogType())){
|
||||
map.put("content", generator.convert(page.getList(), LogErrorDTO.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
if (status.equals(criteria.getLogType())) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
map.put("content", page.getList());
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<co.yixiang.logging.domain.Log> queryAll(LogQueryCriteria criteria) {
|
||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(co.yixiang.logging.domain.Log.class, criteria));
|
||||
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) {
|
||||
getPage(pageable);
|
||||
PageInfo<co.yixiang.logging.domain.Log> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", generator.convert(page.getList(), LogSmallDTO.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
return PageUtil.toPage(page.map(logSmallMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint,
|
||||
co.yixiang.logging.domain.Log log, Long uid){
|
||||
Log log,Long uid){
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
Log aopLog = method.getAnnotation(Log.class);
|
||||
co.yixiang.aop.log.Log aopLog = method.getAnnotation(co.yixiang.aop.log.Log.class);
|
||||
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";
|
||||
@ -145,21 +124,21 @@ public class LogServiceImpl extends BaseServiceImpl<LogMapper, co.yixiang.loggin
|
||||
log.setMethod(methodName);
|
||||
log.setUsername(username);
|
||||
log.setParams(params.toString() + " }");
|
||||
this.save(log);
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findByErrDetail(Long id) {
|
||||
co.yixiang.logging.domain.Log log = this.getById(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<co.yixiang.logging.domain.Log> logs, HttpServletResponse response) throws IOException {
|
||||
public void download(List<Log> logs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (co.yixiang.logging.domain.Log log : logs) {
|
||||
for (Log log : logs) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", log.getUsername());
|
||||
map.put("IP", log.getRequestIp());
|
||||
@ -177,12 +156,12 @@ public class LogServiceImpl extends BaseServiceImpl<LogMapper, co.yixiang.loggin
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByError() {
|
||||
logMapper.deleteByLogType("ERROR");
|
||||
logRepository.deleteByLogType("ERROR");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByInfo() {
|
||||
logMapper.deleteByLogType("INFO");
|
||||
logRepository.deleteByLogType("INFO");
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package co.yixiang.service.mapper;
|
||||
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.service.dto.LogErrorDTO;
|
||||
import co.yixiang.base.BaseMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogErrorMapper extends BaseMapper<LogErrorDTO, Log> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package co.yixiang.service.mapper;
|
||||
|
||||
import co.yixiang.domain.Log;
|
||||
import co.yixiang.base.BaseMapper;
|
||||
import co.yixiang.service.dto.LogSmallDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogSmallMapper extends BaseMapper<LogSmallDTO, Log> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user