Skip to content

Commit

Permalink
2.0 抢先版,主要更新了elunez#71 | #IWYE2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjie committed May 24, 2019
1 parent 90c2bf9 commit 784d670
Show file tree
Hide file tree
Showing 49 changed files with 337 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### IntelliJ IDEA ###
### IDEA ###
.idea/*
*.iml
*/target/*
Expand Down
2 changes: 1 addition & 1 deletion eladmin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eladmin</artifactId>
<groupId>me.zhengjie</groupId>
<version>1.9</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Docket createRestApi() {

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("elune 接口文档")
.version("1.7")
.title("eladmin 接口文档")
.version("2.0")
.build();
}

Expand Down
4 changes: 2 additions & 2 deletions eladmin-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eladmin</artifactId>
<groupId>me.zhengjie</groupId>
<version>1.9</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.9</version>
<version>2.0</version>
</dependency>

<!--模板引擎-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class GenConfig {
/** 作者 **/
private String author;

/** 表前缀 **/
private String prefix;

/** 是否覆盖 **/
private Boolean cover;
}
10 changes: 9 additions & 1 deletion eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.zhengjie.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.template.*;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.domain.GenConfig;
Expand Down Expand Up @@ -75,9 +76,16 @@ public static void generatorCode(List<ColumnInfo> columnInfos, GenConfig genConf
map.put("date", LocalDate.now().toString());
map.put("tableName",tableName);
String className = StringUtils.toCapitalizeCamelCase(tableName);
String changeClassName = StringUtils.toCamelCase(tableName);

// 判断是否去除表前缀
if (StringUtils.isNotEmpty(genConfig.getPrefix())) {
className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(tableName,genConfig.getPrefix()));
changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(tableName,genConfig.getPrefix()));
}
map.put("className", className);
map.put("upperCaseClassName", className.toUpperCase());
map.put("changeClassName", StringUtils.toCamelCase(tableName));
map.put("changeClassName", changeClassName);
map.put("hasTimestamp",false);
map.put("hasBigDecimal",false);
map.put("hasQuery",false);
Expand Down
4 changes: 2 additions & 2 deletions eladmin-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eladmin</artifactId>
<groupId>me.zhengjie</groupId>
<version>1.9</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.9</version>
<version>2.0</version>
</dependency>
</dependencies>
</project>
3 changes: 2 additions & 1 deletion eladmin-logging/src/main/java/me/zhengjie/domain/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
Expand All @@ -14,7 +15,7 @@
@Data
@Table(name = "log")
@NoArgsConstructor
public class Log {
public class Log implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ 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);

@Query(value = "select exception_detail FROM log where id = ?1",nativeQuery = true)
String findExceptionById(Long id);
}
11 changes: 11 additions & 0 deletions eladmin-logging/src/main/java/me/zhengjie/rest/LogController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.zhengjie.rest;

import me.zhengjie.domain.Log;
import me.zhengjie.service.LogService;
import me.zhengjie.service.query.LogQueryService;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,6 +10,7 @@
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;

Expand All @@ -23,6 +25,9 @@ public class LogController {
@Autowired
private LogQueryService logQueryService;

@Autowired
private LogService logService;

@GetMapping(value = "/logs")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity getLogs(Log log, Pageable pageable){
Expand All @@ -43,4 +48,10 @@ public ResponseEntity getErrorLogs(Log log, Pageable pageable){
log.setLogType("ERROR");
return new ResponseEntity(logQueryService.queryAll(log,pageable), HttpStatus.OK);
}

@GetMapping(value = "/logs/error/{id}")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity getErrorLogs(@PathVariable Long id){
return new ResponseEntity(logService.findByErrDetail(id), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ public interface LogService {
*/
@Async
void save(ProceedingJoinPoint joinPoint, Log log);

/**
* 查询异常详情
* @param id
* @return
*/
Object findByErrDetail(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.zhengjie.service.dto;

import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;

/**
* @author jie
* @date 2019-5-22
*/
@Data
public class LogErrorDTO implements Serializable {

private Long id;

/**
* 操作用户
*/
private String username;

/**
* 描述
*/
private String description;

/**
* 方法名
*/
private String method;

/**
* 参数
*/
private String params;

/**
* 请求ip
*/
private String requestIp;


/**
* 创建日期
*/
private Timestamp createTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.zhengjie.service.dto;

import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;

/**
* @author jie
* @date 2019-5-22
*/
@Data
public class LogSmallDTO implements Serializable {

/**
* 描述
*/
private String description;

/**
* 请求ip
*/
private String requestIp;

/**
* 请求耗时
*/
private Long time;

/**
* 创建日期
*/
private Timestamp createTime;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.zhengjie.service.impl;

import cn.hutool.core.lang.Dict;
import cn.hutool.json.JSONObject;
import me.zhengjie.domain.Log;
import me.zhengjie.repository.LogRepository;
Expand Down Expand Up @@ -79,4 +80,9 @@ public void save(ProceedingJoinPoint joinPoint, Log log){
log.setParams(params + " }");
logRepository.save(log);
}

@Override
public Object findByErrDetail(Long id) {
return Dict.create().set("exception",logRepository.findExceptionById(id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.zhengjie.service.mapper;

import me.zhengjie.domain.Log;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.service.dto.LogErrorDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

/**
* @author jie
* @date 2019-5-22
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface LogErrorMapper extends EntityMapper<LogErrorDTO, Log> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.zhengjie.service.mapper;

import me.zhengjie.domain.Log;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.service.dto.LogSmallDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

/**
* @author jie
* @date 2019-5-22
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface LogSmallMapper extends EntityMapper<LogSmallDTO, Log> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import me.zhengjie.domain.Log;
import me.zhengjie.repository.LogRepository;
import me.zhengjie.service.mapper.LogErrorMapper;
import me.zhengjie.service.mapper.LogSmallMapper;
import me.zhengjie.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -16,6 +19,7 @@
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author jie
Expand All @@ -28,7 +32,20 @@ public class LogQueryService {
@Autowired
private LogRepository logRepository;

public Page queryAll(Log log, Pageable pageable){
@Autowired
private LogErrorMapper logErrorMapper;

@Autowired
private LogSmallMapper logSmallMapper;

public Object queryAll(Log log, Pageable pageable){
Page<Log> page = logRepository.findAll(new Spec(log),pageable);
if (!ObjectUtils.isEmpty(log.getUsername())) {
return PageUtil.toPage(page.map(logSmallMapper::toDto));
}
if (log.getLogType().equals("ERROR")) {
return PageUtil.toPage(page.map(logErrorMapper::toDto));
}
return logRepository.findAll(new Spec(log),pageable);
}

Expand Down
7 changes: 4 additions & 3 deletions eladmin-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eladmin</artifactId>
<groupId>me.zhengjie</groupId>
<version>1.9</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-generator</artifactId>
<version>1.9</version>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>me.zhengjie</groupId>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-tools</artifactId>
<version>1.9</version>
<version>2.0</version>
</dependency>

<!--jwt-->
Expand All @@ -53,6 +53,7 @@
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Loading

0 comments on commit 784d670

Please sign in to comment.