From f63407fd8190837f6b816f168f59da91568ea6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=9D=B0?= Date: Mon, 21 Jan 2019 17:15:52 +0800 Subject: [PATCH] =?UTF-8?q?v1.5=20=E6=AD=A3=E5=BC=8F=E7=89=88=E5=8F=91?= =?UTF-8?q?=E5=B8=83=20=EF=BC=8C=E8=AF=A6=E6=83=85=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=8F=91=E8=A1=8C=E7=89=88=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhengjie/swagger2/SwaggerDataConfig.java | 1 + .../main/java/me/zhengjie/utils/GenUtil.java | 19 ++++++++------- .../rest/AuthenticationController.java | 3 ++- .../modules/system/rest/RoleController.java | 4 ++-- .../modules/system/service/dto/RoleDTO.java | 1 - .../modules/system/service/dto/UserDTO.java | 4 +++- .../service/query/RoleQueryService.java | 23 ++++++------------- .../template/generator/admin/QueryService.ftl | 6 ++--- .../template/generator/front/header.ftl | 8 +++---- pom.xml | 20 ++++++++++++++++ 10 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerDataConfig.java diff --git a/eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerDataConfig.java b/eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerDataConfig.java new file mode 100644 index 00000000..35f0edf1 --- /dev/null +++ b/eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerDataConfig.java @@ -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 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 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 getSort() { return sort; } public void setSort(List sort) { this.sort = sort; } } } \ No newline at end of file diff --git a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java index 4374190a..3917d348 100644 --- a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java +++ b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java @@ -79,7 +79,8 @@ public class GenUtil { map.put("hasBigDecimal",false); map.put("hasQuery",false); - List> list = new ArrayList<>(); + List> columns = new ArrayList<>(); + List> queryColumns = new ArrayList<>(); for (ColumnInfo column : columnInfos) { Map 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)); // 生成后端代码 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java index d60c1cf9..a5ec229d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java @@ -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()); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java index 165858d5..1dfb2090 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java @@ -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("新增角色") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java index f67e72ec..d21afadc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java @@ -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; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDTO.java index 857e977d..606563f2 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDTO.java @@ -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 roles; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/query/RoleQueryService.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/query/RoleQueryService.java index 62b8c7fa..12a88318 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/query/RoleQueryService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/query/RoleQueryService.java @@ -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 page = roleRepository.findAll(new Spec(role),pageable); + public Object queryAll(String name, Pageable pageable){ + Page 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 { - 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 list = new ArrayList(); - 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()]; diff --git a/eladmin-system/src/main/resources/template/generator/admin/QueryService.ftl b/eladmin-system/src/main/resources/template/generator/admin/QueryService.ftl index 12cce620..fba6c2d6 100644 --- a/eladmin-system/src/main/resources/template/generator/admin/QueryService.ftl +++ b/eladmin-system/src/main/resources/template/generator/admin/QueryService.ftl @@ -67,9 +67,8 @@ public class ${className}QueryService { List list = new ArrayList(); - <#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}())); } - Predicate[] p = new Predicate[list.size()]; diff --git a/eladmin-system/src/main/resources/template/generator/front/header.ftl b/eladmin-system/src/main/resources/template/generator/front/header.ftl index 51a244e3..ba4d334b 100644 --- a/eladmin-system/src/main/resources/template/generator/front/header.ftl +++ b/eladmin-system/src/main/resources/template/generator/front/header.ftl @@ -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 column_has_next>, - ] diff --git a/pom.xml b/pom.xml index e0123131..40811eba 100644 --- a/pom.xml +++ b/pom.xml @@ -109,12 +109,32 @@ io.springfox springfox-swagger2 ${swagger.version} + + + io.swagger + swagger-annotations + + + io.swagger + swagger-models + + io.springfox springfox-swagger-ui ${swagger.version} + + io.swagger + swagger-annotations + 1.5.21 + + + io.swagger + swagger-models + 1.5.21 +