1.新增日志清空接口

pull/217/head
邹伟华 2019-12-05 10:16:09 +08:00
parent 720e8da0e7
commit 33cdb7fea1
4 changed files with 52 additions and 4 deletions

View File

@ -3,9 +3,12 @@ package me.zhengjie.repository;
import me.zhengjie.domain.Log;
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 javax.transaction.Transactional;
/**
* @author Zheng Jie
* @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)
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);
}

View File

@ -10,10 +10,7 @@ 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;
@ -80,4 +77,21 @@ public class LogController {
public ResponseEntity 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 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);
}
}

View File

@ -64,4 +64,14 @@ public interface LogService {
* @throws IOException /
*/
void download(List<Log> logs, HttpServletResponse response) throws IOException;
/**
*
*/
void delAllByError();
/**
* INFO
*/
void delAllByInfo();
}

View File

@ -137,4 +137,16 @@ public class LogServiceImpl implements LogService {
}
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");
}
}