yshop1.7发布,后台升級eladmin2.4(前端,后台权限,代码生成器等重构),修复商品分类等一些问题
This commit is contained in:
@ -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