mirror of https://github.com/elunez/eladmin
v1.5 正式版发布 ,详情查看发行版说明
parent
40c2c880ca
commit
f63407fd81
|
@ -0,0 +1 @@
|
|||
package me.zhengjie.swagger2;
import com.fasterxml.classmate.TypeResolver;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.data.domain.Pageable;
import springfox.documentation.schema.AlternateTypeRule;
import springfox.documentation.schema.AlternateTypeRuleConvention;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static springfox.documentation.schema.AlternateTypeRules.newRule;
/**
* 将Pageable转换展示在swagger中
*/
@Configuration
public class SwaggerDataConfig {
@Bean
public AlternateTypeRuleConvention pageableConvention(final TypeResolver resolver) {
return new AlternateTypeRuleConvention() {
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
@Override
public List<AlternateTypeRule> rules() {
return newArrayList(newRule(resolver.resolve(Pageable.class), resolver.resolve(Page.class)));
}
};
}
@ApiModel
static class Page {
@ApiModelProperty("页码 (0..N)")
private Integer page;
@ApiModelProperty("每页显示的数目")
private Integer size;
@ApiModelProperty("以下列格式排序标准:property[,asc | desc]。 默认排序顺序为升序。 支持多种排序条件:如:id,asc")
private List<String> sort;
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
public List<String> getSort() {
return sort;
}
public void setSort(List<String> sort) {
this.sort = sort;
}
}
}
|
|
@ -79,7 +79,8 @@ public class GenUtil {
|
|||
map.put("hasBigDecimal",false);
|
||||
map.put("hasQuery",false);
|
||||
|
||||
List<Map<String,Object>> list = new ArrayList<>();
|
||||
List<Map<String,Object>> columns = new ArrayList<>();
|
||||
List<Map<String,Object>> queryColumns = new ArrayList<>();
|
||||
for (ColumnInfo column : columnInfos) {
|
||||
Map<String,Object> listMap = new HashMap();
|
||||
listMap.put("columnComment",column.getColumnComment());
|
||||
|
@ -98,17 +99,19 @@ public class GenUtil {
|
|||
listMap.put("columnType",colType);
|
||||
listMap.put("columnName",column.getColumnName());
|
||||
listMap.put("isNullable",column.getIsNullable());
|
||||
listMap.put("columnQuery",column.getColumnQuery());
|
||||
|
||||
if(!ObjectUtils.isEmpty(column.getColumnQuery())){
|
||||
map.put("hasQuery",true);
|
||||
}
|
||||
listMap.put("columnShow",column.getColumnShow());
|
||||
listMap.put("changeColumnName",StringUtils.toCamelCase(column.getColumnName().toString()));
|
||||
listMap.put("capitalColumnName",StringUtils.toCapitalizeCamelCase(column.getColumnName().toString()));
|
||||
list.add(listMap);
|
||||
|
||||
if(!StringUtils.isBlank(column.getColumnQuery())){
|
||||
listMap.put("columnQuery",column.getColumnQuery());
|
||||
map.put("hasQuery",true);
|
||||
queryColumns.add(listMap);
|
||||
}
|
||||
columns.add(listMap);
|
||||
}
|
||||
map.put("columns",list);
|
||||
map.put("columns",columns);
|
||||
map.put("queryColumns",queryColumns);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
|
||||
// 生成后端代码
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.security.authentication.AccountExpiredException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +45,7 @@ public class AuthenticationController {
|
|||
*/
|
||||
@Log("用户登录")
|
||||
@PostMapping(value = "${jwt.auth.path}")
|
||||
public ResponseEntity<?> login(@RequestBody AuthorizationUser authorizationUser){
|
||||
public ResponseEntity login(@Validated @RequestBody AuthorizationUser authorizationUser){
|
||||
|
||||
final UserDetails userDetails = userDetailsService.loadUserByUsername(authorizationUser.getUsername());
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public class RoleController {
|
|||
@Log("查询角色")
|
||||
@GetMapping(value = "/roles")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_SELECT')")
|
||||
public ResponseEntity getRoles(RoleDTO resources, Pageable pageable){
|
||||
return new ResponseEntity(roleQueryService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
public ResponseEntity getRoles(@RequestParam(required = false) String name, Pageable pageable){
|
||||
return new ResponseEntity(roleQueryService.queryAll(name,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增角色")
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Set;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
@ -15,6 +15,7 @@ import java.util.Set;
|
|||
@Data
|
||||
public class UserDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
|
@ -32,5 +33,6 @@ public class UserDTO implements Serializable {
|
|||
|
||||
private Date lastPasswordResetTime;
|
||||
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Set<RoleDTO> roles;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package me.zhengjie.modules.system.service.query;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -41,25 +40,17 @@ public class RoleQueryService {
|
|||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(RoleDTO role, Pageable pageable){
|
||||
Page<Role> page = roleRepository.findAll(new Spec(role),pageable);
|
||||
public Object queryAll(String name, Pageable pageable){
|
||||
Page<Role> page = roleRepository.findAll(new Spec(name),pageable);
|
||||
return PageUtil.toPage(page.map(roleMapper::toDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 不分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(RoleDTO role){
|
||||
return roleMapper.toDto(roleRepository.findAll(new Spec(role)));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Role> {
|
||||
|
||||
private RoleDTO role;
|
||||
private String name;
|
||||
|
||||
public Spec(RoleDTO role){
|
||||
this.role = role;
|
||||
public Spec(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,11 +58,11 @@ public class RoleQueryService {
|
|||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(role.getName())){
|
||||
if(!ObjectUtils.isEmpty(name)){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+role.getName()+"%"));
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
|
|
|
@ -67,9 +67,8 @@ public class ${className}QueryService {
|
|||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnQuery??>
|
||||
<#if queryColumns??>
|
||||
<#list queryColumns as column>
|
||||
if(!ObjectUtils.isEmpty(${changeClassName}.get${column.capitalColumnName}())){
|
||||
<#if column.columnQuery = '1'>
|
||||
/**
|
||||
|
@ -84,7 +83,6 @@ public class ${className}QueryService {
|
|||
list.add(cb.equal(root.get("${column.columnName}").as(${column.columnType}.class),${changeClassName}.get${column.capitalColumnName}()));
|
||||
</#if>
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
|
|
|
@ -35,13 +35,11 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
downloadLoading: false<#if hasQuery>,
|
||||
<#if hasQuery>
|
||||
queryTypeOptions: [
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.columnQuery??>
|
||||
<#if queryColumns??>
|
||||
<#list queryColumns as column>
|
||||
{ key: '${column.changeColumnName}', display_name: '<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
]
|
||||
|
|
20
pom.xml
20
pom.xml
|
@ -109,12 +109,32 @@
|
|||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
<version>1.5.21</version>
|
||||
</dependency>
|
||||
|
||||
<!--Mysql依赖包-->
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue