Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
8acf3cc2
Commit
8acf3cc2
authored
Mar 07, 2020
by
Elune
Browse files
代码生成器优化
parent
cf608b43
Changes
10
Hide whitespace changes
Inline
Side-by-side
eladmin-monitor/src/main/java/me/zhengjie/res/ServerMonitorController.java
View file @
8acf3cc2
package
me.zhengjie.res
;
package
me.zhengjie.res
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
@@ -13,8 +12,6 @@ import oshi.hardware.HardwareAbstractionLayer;
...
@@ -13,8 +12,6 @@ import oshi.hardware.HardwareAbstractionLayer;
import
oshi.hardware.VirtualMemory
;
import
oshi.hardware.VirtualMemory
;
import
oshi.software.os.OSFileStore
;
import
oshi.software.os.OSFileStore
;
import
oshi.software.os.OperatingSystem
;
import
oshi.software.os.OperatingSystem
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
...
eladmin-system/src/main/java/me/zhengjie/gen/domain/GenTest.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.domain
;
import
lombok.Data
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
javax.persistence.*
;
import
javax.validation.constraints.*
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Entity
@Data
@Table
(
name
=
"gen_test"
)
public
class
GenTest
implements
Serializable
{
/** ID */
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@Column
(
name
=
"id"
)
private
Integer
id
;
/** 名称 */
@Column
(
name
=
"name"
,
nullable
=
false
)
@NotBlank
private
String
name
;
/** 性别 */
@Column
(
name
=
"sex"
)
private
Integer
sex
;
@Column
(
name
=
"create_time"
)
private
Timestamp
createTime
;
public
void
copy
(
GenTest
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/repository/GenTestRepository.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.repository
;
import
me.zhengjie.gen.domain.GenTest
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
public
interface
GenTestRepository
extends
JpaRepository
<
GenTest
,
Integer
>,
JpaSpecificationExecutor
<
GenTest
>
{
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/rest/GenTestController.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.rest
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.GenTestService
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
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.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
io.swagger.annotations.*
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Api
(
tags
=
"测试生成管理"
)
@RestController
@RequestMapping
(
"/api/genTest"
)
public
class
GenTestController
{
private
final
GenTestService
genTestService
;
public
GenTestController
(
GenTestService
genTestService
)
{
this
.
genTestService
=
genTestService
;
}
@Log
(
"导出数据"
)
@ApiOperation
(
"导出数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('genTest:list')"
)
public
void
download
(
HttpServletResponse
response
,
GenTestQueryCriteria
criteria
)
throws
IOException
{
genTestService
.
download
(
genTestService
.
queryAll
(
criteria
),
response
);
}
@GetMapping
@Log
(
"查询测试生成"
)
@ApiOperation
(
"查询测试生成"
)
@PreAuthorize
(
"@el.check('genTest:list')"
)
public
ResponseEntity
<
Object
>
getGenTests
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
genTestService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@PostMapping
@Log
(
"新增测试生成"
)
@ApiOperation
(
"新增测试生成"
)
@PreAuthorize
(
"@el.check('genTest:add')"
)
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
GenTest
resources
){
return
new
ResponseEntity
<>(
genTestService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
@PutMapping
@Log
(
"修改测试生成"
)
@ApiOperation
(
"修改测试生成"
)
@PreAuthorize
(
"@el.check('genTest:edit')"
)
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
GenTest
resources
){
genTestService
.
update
(
resources
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除测试生成"
)
@ApiOperation
(
"删除测试生成"
)
@PreAuthorize
(
"@el.check('genTest:del')"
)
@DeleteMapping
public
ResponseEntity
<
Object
>
deleteAll
(
@RequestBody
Integer
[]
ids
)
{
genTestService
.
deleteAll
(
ids
);
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/GenTestService.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.service
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
java.util.Map
;
import
java.util.List
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
public
interface
GenTestService
{
/**
* 查询数据分页
* @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map
<
String
,
Object
>
queryAll
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<GenTestDto>
*/
List
<
GenTestDto
>
queryAll
(
GenTestQueryCriteria
criteria
);
/**
* 根据ID查询
* @param id ID
* @return GenTestDto
*/
GenTestDto
findById
(
Integer
id
);
/**
* 创建
* @param resources /
* @return GenTestDto
*/
GenTestDto
create
(
GenTest
resources
);
/**
* 编辑
* @param resources /
*/
void
update
(
GenTest
resources
);
/**
* 多选删除
* @param ids /
*/
void
deleteAll
(
Integer
[]
ids
);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
void
download
(
List
<
GenTestDto
>
all
,
HttpServletResponse
response
)
throws
IOException
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/dto/GenTestDto.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Data
public
class
GenTestDto
implements
Serializable
{
/** ID */
private
Integer
id
;
/** 名称 */
private
String
name
;
/** 性别 */
private
Integer
sex
;
private
Timestamp
createTime
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/dto/GenTestQueryCriteria.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.util.List
;
import
me.zhengjie.annotation.Query
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Data
public
class
GenTestQueryCriteria
{
/** 模糊 */
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
/** 不为空 */
@Query
(
type
=
Query
.
Type
.
NOT_NULL
)
private
Integer
sex
;
/** BETWEEN */
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/impl/GenTestServiceImpl.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.service.impl
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.gen.repository.GenTestRepository
;
import
me.zhengjie.gen.service.GenTestService
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
me.zhengjie.gen.service.dto.GenTestQueryCriteria
;
import
me.zhengjie.gen.service.mapper.GenTestMapper
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
java.util.List
;
import
java.util.Map
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Service
//@CacheConfig(cacheNames = "genTest")
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
GenTestServiceImpl
implements
GenTestService
{
private
final
GenTestRepository
genTestRepository
;
private
final
GenTestMapper
genTestMapper
;
public
GenTestServiceImpl
(
GenTestRepository
genTestRepository
,
GenTestMapper
genTestMapper
)
{
this
.
genTestRepository
=
genTestRepository
;
this
.
genTestMapper
=
genTestMapper
;
}
@Override
//@Cacheable
public
Map
<
String
,
Object
>
queryAll
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
){
Page
<
GenTest
>
page
=
genTestRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
genTestMapper:
:
toDto
));
}
@Override
//@Cacheable
public
List
<
GenTestDto
>
queryAll
(
GenTestQueryCriteria
criteria
){
return
genTestMapper
.
toDto
(
genTestRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
@Override
//@Cacheable(key = "#p0")
public
GenTestDto
findById
(
Integer
id
)
{
GenTest
genTest
=
genTestRepository
.
findById
(
id
).
orElseGet
(
GenTest:
:
new
);
ValidationUtil
.
isNull
(
genTest
.
getId
(),
"GenTest"
,
"id"
,
id
);
return
genTestMapper
.
toDto
(
genTest
);
}
@Override
//@CacheEvict(allEntries = true)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
GenTestDto
create
(
GenTest
resources
)
{
return
genTestMapper
.
toDto
(
genTestRepository
.
save
(
resources
));
}
@Override
//@CacheEvict(allEntries = true)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
GenTest
resources
)
{
GenTest
genTest
=
genTestRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
GenTest:
:
new
);
ValidationUtil
.
isNull
(
genTest
.
getId
(),
"GenTest"
,
"id"
,
resources
.
getId
());
genTest
.
copy
(
resources
);
genTestRepository
.
save
(
genTest
);
}
@Override
//@CacheEvict(allEntries = true)
public
void
deleteAll
(
Integer
[]
ids
)
{
for
(
Integer
id
:
ids
)
{
genTestRepository
.
deleteById
(
id
);
}
}
@Override
public
void
download
(
List
<
GenTestDto
>
all
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
GenTestDto
genTest
:
all
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"名称"
,
genTest
.
getName
());
map
.
put
(
"性别"
,
genTest
.
getSex
());
map
.
put
(
" createTime"
,
genTest
.
getCreateTime
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/mapper/GenTestMapper.java
0 → 100644
View file @
8acf3cc2
package
me.zhengjie.gen.service.mapper
;
import
me.zhengjie.base.BaseMapper
;
import
me.zhengjie.gen.domain.GenTest
;
import
me.zhengjie.gen.service.dto.GenTestDto
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author Zheng Jie
* @date 2020-03-07
*/
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
GenTestMapper
extends
BaseMapper
<
GenTestDto
,
GenTest
>
{
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/front/index.ftl
View file @
8acf3cc2
...
@@ -81,15 +81,15 @@
...
@@ -81,15 +81,15 @@
<#list columns as column>
<#list columns as column>
<#if column.columnShow>
<#if column.columnShow>
<#if column.dictName??>
<#if column.dictName??>
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<template slot-scope="scope">
<template slot-scope="scope">
{{
dict
.label
.$
{
column
.dictName
}
[
scope
.row
.$
{
column
.changeColumnName
}
]
}}
{{
dict
.label
.$
{
column
.dictName
}
[
scope
.row
.$
{
column
.changeColumnName
}
]
}}
</template>
</template>
</el-table-column>
</el-table-column>
<#elseif column.columnType != 'Timestamp'>
<#elseif column.columnType != 'Timestamp'>
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>" />
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>" />
<#else>
<#else>
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<template slot-scope="scope">
<template slot-scope="scope">
<span>
{{
parseTime
(
scope
.row
.$
{
column
.changeColumnName
})
}}
</span>
<span>
{{
parseTime
(
scope
.row
.$
{
column
.changeColumnName
})
}}
</span>
</template>
</template>
...
@@ -121,16 +121,17 @@ import crudOperation from '@crud/CRUD.operation'
...
@@ -121,16 +121,17 @@ import crudOperation from '@crud/CRUD.operation'
import
udOperation from '@crud/UD.operation'
import
udOperation from '@crud/UD.operation'
import
pagination from '@crud/Pagination'
import
pagination from '@crud/Pagination'
//
crud交由presenter持有
const
defaultCrud = CRUD(
{
title
:
'$
{
apiAlias
}
'
,
url
:
'
api
/$
{
changeClassName
}
'
,
sort
:
'$
{
pkChangeColName
},
desc
'
,
crudMethod
:
{
..
.crud
$
{
className
}
}}
)
const
defaultForm =
{
<#
if
columns
??><#
list
columns
as
column
>$
{
column
.changeColumnName
}:
null
<#
if
column_has_next
>
,
</#
if
></#
list
></#
if
>
}
const
defaultForm =
{
<#
if
columns
??><#
list
columns
as
column
>$
{
column
.changeColumnName
}:
null
<#
if
column_has_next
>
,
</#
if
></#
list
></#
if
>
}
export
default
{
export
default
{
name
:
'$
{
className
}
'
,
name
:
'$
{
className
}
'
,
components
:
{
pagination
,
crudOperation
,
rrOperation
,
udOperation
},
components
:
{
pagination
,
crudOperation
,
rrOperation
,
udOperation
},
mixins
:
[
presenter
(
defaultCrud
),
header
(),
form
(
defaultForm
),
crud
()
]
,
mixins
:
[
presenter
(),
header
(),
form
(
defaultForm
),
crud
()
]
,
<#
if
hasDict
>
<#
if
hasDict
>
dicts
:
[<#
if
hasDict
??><#
list
dicts
as
dict
>'$
{
dict
}
'<#
if
dict_has_next
>
,
</#
if
></#
list
></#
if
>]
,
dicts
:
[<#
if
hasDict
??><#
list
dicts
as
dict
>'$
{
dict
}
'<#
if
dict_has_next
>
,
</#
if
></#
list
></#
if
>]
,
</#
if
>
</#
if
>
cruds
()
{
return
CRUD
({
title
:
'$
{
apiAlias
}
'
,
url
:
'
api
/$
{
changeClassName
}
'
,
sort
:
'$
{
pkChangeColName
},
desc
'
,
crudMethod
:
{
..
.crud
$
{
className
}
}})
},
data
()
{
data
()
{
return
{
return
{
permission
:
{
permission
:
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment