mirror of https://github.com/elunez/eladmin
1.新增日志清空接口
parent
720e8da0e7
commit
33cdb7fea1
|
@ -3,9 +3,12 @@ package me.zhengjie.repository;
|
||||||
import me.zhengjie.domain.Log;
|
import me.zhengjie.domain.Log;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-11-24
|
* @date 2018-11-24
|
||||||
|
@ -21,4 +24,13 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
|
||||||
*/
|
*/
|
||||||
@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)
|
@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);
|
Long findIp(String date1, String date2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据日志类型删除信息
|
||||||
|
* @param logType
|
||||||
|
*/
|
||||||
|
@Query(nativeQuery = true,value = "delete from log where log_type = ?1")
|
||||||
|
@Modifying
|
||||||
|
@Transactional
|
||||||
|
void deleteByLogType(String logType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -80,4 +77,21 @@ public class LogController {
|
||||||
public ResponseEntity getErrorLogs(@PathVariable Long id){
|
public ResponseEntity getErrorLogs(@PathVariable Long id){
|
||||||
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
|
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
@DeleteMapping(value = "/del/error")
|
||||||
|
@Log("删除所有ERROR日志")
|
||||||
|
@ApiOperation("删除所有ERROR日志")
|
||||||
|
@PreAuthorize("@el.check()")
|
||||||
|
public ResponseEntity delAllByError(){
|
||||||
|
logService.delAllByError();
|
||||||
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping(value = "/del/info")
|
||||||
|
@Log("删除所有INFO日志")
|
||||||
|
@ApiOperation("删除所有INFO日志")
|
||||||
|
@PreAuthorize("@el.check()")
|
||||||
|
public ResponseEntity delAllByInfo(){
|
||||||
|
logService.delAllByInfo();
|
||||||
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,4 +64,14 @@ public interface LogService {
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<Log> logs, HttpServletResponse response) throws IOException;
|
void download(List<Log> logs, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除所有错误日志
|
||||||
|
*/
|
||||||
|
void delAllByError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除所有INFO日志
|
||||||
|
*/
|
||||||
|
void delAllByInfo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,4 +137,16 @@ public class LogServiceImpl implements LogService {
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue