yshop1.6.1发布:新增移动端浏览记录,下单增加简单ReentrantLock锁
This commit is contained in:
@ -13,4 +13,5 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
int type() default 0;
|
||||
}
|
||||
|
@ -49,7 +49,9 @@ public class LogAspect {
|
||||
currentTime = System.currentTimeMillis();
|
||||
result = joinPoint.proceed();
|
||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
||||
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint, log);
|
||||
logService.save(getUsername(),
|
||||
StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint,
|
||||
log,getUid());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -63,7 +65,9 @@ public class LogAspect {
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
|
||||
logService.save(getUsername(),
|
||||
StringUtils.getIP(RequestHolder.getHttpServletRequest()),
|
||||
(ProceedingJoinPoint)joinPoint, log,getUid());
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@ -73,4 +77,12 @@ public class LogAspect {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public Long getUid(){
|
||||
try {
|
||||
return SecurityUtils.getUserId();
|
||||
}catch (Exception e){
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,10 @@ public class Log implements Serializable {
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
private Long uid;
|
||||
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 异常详细
|
||||
*/
|
||||
|
@ -1,11 +1,15 @@
|
||||
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.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
@ -13,6 +17,18 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor {
|
||||
|
||||
@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
|
||||
|
@ -28,9 +28,18 @@ public class LogController {
|
||||
@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);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/mlogs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
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){
|
||||
criteria.setLogType("INFO");
|
||||
|
@ -12,6 +12,8 @@ import org.springframework.scheduling.annotation.Async;
|
||||
*/
|
||||
public interface LogService {
|
||||
|
||||
Object findAllByPageable(String nickname, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
@ -36,7 +38,7 @@ public interface LogService {
|
||||
* @param log
|
||||
*/
|
||||
@Async
|
||||
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log);
|
||||
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log,Long uid);
|
||||
|
||||
/**
|
||||
* 查询异常详情
|
||||
|
@ -17,4 +17,8 @@ public class LogQueryCriteria {
|
||||
|
||||
@Query
|
||||
private String logType;
|
||||
|
||||
@Query
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -40,6 +42,15 @@ public class LogServiceImpl implements LogService {
|
||||
|
||||
private final String LOGINPATH = "login";
|
||||
|
||||
@Override
|
||||
public Object findAllByPageable(String nickname, Pageable pageable) {
|
||||
Page<Map> page = logRepository.findAllByPageable(nickname,pageable);
|
||||
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content",page.getContent());
|
||||
map.put("totalElements",page.getTotalElements());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(LogQueryCriteria criteria, Pageable pageable){
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
@ -57,7 +68,8 @@ public class LogServiceImpl implements LogService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log){
|
||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint,
|
||||
Log log,Long uid){
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
@ -67,6 +79,12 @@ public class LogServiceImpl implements LogService {
|
||||
if (log != null) {
|
||||
log.setDescription(aopLog.value());
|
||||
}
|
||||
//类型 0-后台 1-前台
|
||||
log.setType(aopLog.type());
|
||||
if(uid != null) {
|
||||
log.setUid(uid);
|
||||
}
|
||||
|
||||
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";
|
||||
|
Reference in New Issue
Block a user