Skip to content

Commit

Permalink
更新代码生成器,更新sql脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Jun 5, 2019
1 parent 5c27bce commit c01435a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 131 deletions.
10 changes: 5 additions & 5 deletions eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static List<String> getAdminTemplateNames() {
templateNames.add("Repository");
templateNames.add("Service");
templateNames.add("ServiceImpl");
templateNames.add("QueryService");
templateNames.add("QueryCriteria");
templateNames.add("Controller");
return templateNames;
}
Expand Down Expand Up @@ -200,12 +200,12 @@ public static String getAdminFilePath(String templateName, GenConfig genConfig,
return packagePath + "service" + File.separator + "dto" + File.separator + className + "DTO.java";
}

if ("Mapper".equals(templateName)) {
return packagePath + "service" + File.separator + "mapper" + File.separator + className + "Mapper.java";
if ("QueryCriteria".equals(templateName)) {
return packagePath + "service" + File.separator + "dto" + File.separator + className + "QueryCriteria.java";
}

if ("QueryService".equals(templateName)) {
return packagePath + "service" + File.separator + "query" + File.separator + className + "QueryService.java";
if ("Mapper".equals(templateName)) {
return packagePath + "service" + File.separator + "mapper" + File.separator + className + "Mapper.java";
}

if ("Repository".equals(templateName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package ${package}.rest;
import me.zhengjie.aop.log.Log;
import ${package}.domain.${className};
import ${package}.service.${className}Service;
import ${package}.service.dto.${className}DTO;
import ${package}.service.query.${className}QueryService;
import ${package}.service.dto.${className}QueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
Expand All @@ -13,6 +12,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author ${author}
* @date ${date}
Expand All @@ -24,14 +24,11 @@ public class ${className}Controller {
@Autowired
private ${className}Service ${changeClassName}Service;

@Autowired
private ${className}QueryService ${changeClassName}QueryService;

@Log("查询${className}")
@GetMapping(value = "/${changeClassName}")
@PreAuthorize("hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_SELECT')")
public ResponseEntity get${className}s(${className}DTO resources, Pageable pageable){
return new ResponseEntity(${changeClassName}QueryService.queryAll(resources,pageable),HttpStatus.OK);
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable){
return new ResponseEntity(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
}

@Log("新增${className}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ${package}.service.dto;

import lombok.Data;
<#if hasTimestamp>
import java.sql.Timestamp;
</#if>
<#if hasBigDecimal>
import java.math.BigDecimal;
</#if>
<#if queryColumns??>
import me.zhengjie.annotation.Query;
</#if>

/**
* @author ${author}
* @date ${date}
*/
@Data
public class ${className}QueryCriteria{
<#if queryColumns??>
<#list queryColumns as column>

<#if column.columnQuery = '1'>
// 模糊
@Query(type = Query.Type.INNER_LIKE)
</#if>
<#if column.columnQuery = '2'>
// 精确
@Query
</#if>
private ${column.columnType} ${column.changeColumnName};
</#list>
</#if>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package ${package}.service;

import ${package}.domain.${className};
import ${package}.service.dto.${className}DTO;
import ${package}.service.dto.${className}QueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;

/**
* @author ${author}
Expand All @@ -13,6 +15,23 @@ import org.springframework.cache.annotation.Cacheable;
@CacheConfig(cacheNames = "${changeClassName}")
public interface ${className}Service {

/**
* queryAll 分页
* @param criteria
* @param pageable
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
Object queryAll(${className}QueryCriteria criteria, Pageable pageable);

/**
* queryAll 不分页
* @param criteria
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
public Object queryAll(${className}QueryCriteria criteria);

/**
* findById
* @param ${pkChangeColName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import me.zhengjie.utils.ValidationUtil;
import ${package}.repository.${className}Repository;
import ${package}.service.${className}Service;
import ${package}.service.dto.${className}DTO;
import ${package}.service.dto.${className}QueryCriteria;
import ${package}.service.mapper.${className}Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -27,6 +28,10 @@ import cn.hutool.core.util.IdUtil;
<#if !auto && pkColumnType = 'String'>
import cn.hutool.core.util.IdUtil;
</#if>
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;

/**
* @author ${author}
Expand All @@ -42,6 +47,17 @@ public class ${className}ServiceImpl implements ${className}Service {
@Autowired
private ${className}Mapper ${changeClassName}Mapper;

@Override
public Object queryAll(${className}QueryCriteria criteria, Pageable pageable){
Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
}

@Override
public Object queryAll(${className}QueryCriteria criteria){
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}

@Override
public ${className}DTO findById(${pkColumnType} ${pkChangeColName}) {
Optional<${className}> ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName});
Expand Down
Loading

0 comments on commit c01435a

Please sign in to comment.