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
aaeb67b2
"admin-console/vscode:/vscode.git/clone" did not exist on "075b388e2b64130b3929570f1fcb6ef4f0d352a3"
Commit
aaeb67b2
authored
Nov 19, 2019
by
dqjdda
Browse files
代码生成器新增多选删除功能
parent
3f80af66
Changes
14
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/gen/domain/GenTest.java
deleted
100644 → 0
View file @
3f80af66
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
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.hibernate.annotations.*
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author Zheng Jie
* @date 2019-11-19
*/
@Entity
@Data
@Table
(
name
=
"gen_test"
)
public
class
GenTest
implements
Serializable
{
// ID
@Id
@Column
(
name
=
"id"
)
private
Long
id
;
// 名称
@Column
(
name
=
"name"
,
nullable
=
false
)
@NotBlank
private
String
name
;
// 状态
@Column
(
name
=
"status"
,
nullable
=
false
)
@NotNull
private
Boolean
status
;
// 日期
@Column
(
name
=
"date"
,
nullable
=
false
)
@NotNull
private
Timestamp
date
;
// 创建日期
@Column
(
name
=
"create_time"
)
@CreationTimestamp
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
deleted
100644 → 0
View file @
3f80af66
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 2019-11-19
*/
public
interface
GenTestRepository
extends
JpaRepository
<
GenTest
,
Long
>,
JpaSpecificationExecutor
<
GenTest
>
{
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/rest/GenTestController.java
deleted
100644 → 0
View file @
3f80af66
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 2019-11-19
*/
@Api
(
tags
=
"GenTest管理"
)
@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
(
"查询GenTest"
)
@ApiOperation
(
"查询GenTest"
)
@PreAuthorize
(
"@el.check('genTest:list')"
)
public
ResponseEntity
getGenTests
(
GenTestQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
genTestService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@PostMapping
@Log
(
"新增GenTest"
)
@ApiOperation
(
"新增GenTest"
)
@PreAuthorize
(
"@el.check('genTest:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
GenTest
resources
){
return
new
ResponseEntity
<>(
genTestService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
@PutMapping
@Log
(
"修改GenTest"
)
@ApiOperation
(
"修改GenTest"
)
@PreAuthorize
(
"@el.check('genTest:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
GenTest
resources
){
genTestService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@DeleteMapping
(
value
=
"/{id}"
)
@Log
(
"删除GenTest"
)
@ApiOperation
(
"删除GenTest"
)
@PreAuthorize
(
"@el.check('genTest:del')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
genTestService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/GenTestService.java
deleted
100644 → 0
View file @
3f80af66
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 2019-11-19
*/
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
(
Long
id
);
GenTestDTO
create
(
GenTest
resources
);
void
update
(
GenTest
resources
);
void
delete
(
Long
id
);
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
deleted
100644 → 0
View file @
3f80af66
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer
;
/**
* @author Zheng Jie
* @date 2019-11-19
*/
@Data
public
class
GenTestDTO
implements
Serializable
{
// ID
// 处理精度丢失问题
@JsonSerialize
(
using
=
ToStringSerializer
.
class
)
private
Long
id
;
// 名称
private
String
name
;
// 状态
private
Boolean
status
;
// 日期
private
Timestamp
date
;
// 创建日期
private
Timestamp
createTime
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/dto/GenTestQueryCriteria.java
deleted
100644 → 0
View file @
3f80af66
package
me.zhengjie.gen.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
me.zhengjie.annotation.Query
;
/**
* @author Zheng Jie
* @date 2019-11-19
*/
@Data
public
class
GenTestQueryCriteria
{
// 模糊
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
// 精确
@Query
private
Boolean
status
;
// 时间段查询
@Query
(
type
=
Query
.
Type
.
GREATER_THAN
,
propName
=
"date"
)
private
Timestamp
dateStart
;
@Query
(
type
=
Query
.
Type
.
LESS_THAN
,
propName
=
"date"
)
private
Timestamp
dateEnd
;
// 时间段查询
@Query
(
type
=
Query
.
Type
.
GREATER_THAN
,
propName
=
"createTime"
)
private
Timestamp
createTimeStart
;
@Query
(
type
=
Query
.
Type
.
LESS_THAN
,
propName
=
"createTime"
)
private
Timestamp
createTimeEnd
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/gen/service/impl/GenTestServiceImpl.java
deleted
100644 → 0
View file @
3f80af66
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
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.util.IdUtil
;
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 2019-11-19
*/
@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
(
Long
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
)
{
Snowflake
snowflake
=
IdUtil
.
createSnowflake
(
1
,
1
);
resources
.
setId
(
snowflake
.
nextId
());
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
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
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
.
getStatus
());
map
.
put
(
"日期"
,
genTest
.
getDate
());
map
.
put
(
"创建日期"
,
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
deleted
100644 → 0
View file @
3f80af66
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 2019-11-19
*/
@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/admin/Controller.ftl
View file @
aaeb67b2
...
...
@@ -70,4 +70,13 @@ public class ${className}Controller {
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
return
new
R
esponseEntity
(
H
ttpStatus
.OK
)
;
}
@
L
og
(
"多选删除${className}"
)
@
A
piOperation
(
"多选删除${className}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
@
D
eleteMapping
public
R
esponseEntity
deleteAll
(
@
R
equestBody
$
{
pkColumnType
}
[]
ids
)
{
$
{
changeClassName
}
S
ervice
.deleteAll
(
ids
)
;
return
new
R
esponseEntity
(
H
ttpStatus
.OK
)
;
}
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/Service.ftl
View file @
aaeb67b2
...
...
@@ -43,5 +43,7 @@ public interface ${className}Service {
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
void
deleteAll
(
$
{
pkColumnType
}
[]
ids
)
;
void
download
(
L
ist
<$
{
className
}
DTO
>
all
,
H
ttpServletResponse
response
)
throws
IOE
xception
;
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/ServiceImpl.ftl
View file @
aaeb67b2
...
...
@@ -133,6 +133,13 @@ public class ${className}ServiceImpl implements ${className}Service {
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
}
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
public
void
deleteAll
(
$
{
pkColumnType
}
[]
ids
)
{
for
(
$
{
pkColumnType
}
id
:
ids
)
{
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
}
}
@
O
verride
public
void
download
(
L
ist
<$
{
className
}
DTO
>
all
,
H
ttpServletResponse
response
)
throws
IOE
xception
{
...
...
eladmin-system/src/main/resources/template/generator/front/api.ftl
View file @
aaeb67b2
...
...
@@ -14,6 +14,13 @@ export function del(${pkChangeColName}) {
method
:
'
delete
'
})
}
export
function delAll(ids)
{
return
request
({
url
:
'
api
/$
{
changeClassName
}
/'
,
method
:
'
delete
'
,
data
:
ids
})
}
export
function edit(data)
{
return
request
({
...
...
eladmin-system/src/main/resources/template/generator/front/eForm.ftl
View file @
aaeb67b2
...
...
@@ -51,7 +51,7 @@ export default {
required
:
true
}
<#
if
hasDict
>
,
dicts
:
{
type
:
A
rray
,
type
:
O
bject
,
required
:
true
}
</#
if
>
...
...
eladmin-system/src/main/resources/template/generator/front/index.ftl
View file @
aaeb67b2
...
...
@@ -47,11 +47,23 @@
icon="el-icon-download"
@click="download">导出</el-button>
</div>
<!-- 多选删除 -->
<div v-permission="['admin','$
{
changeClassName
}
:del']" style="display: inline-block;">
<el-button
:loading="delAllLoading"
:disabled="data.length === 0 || $refs.table.selection.length === 0"
class="filter-item"
size="mini"
type="danger"
icon="el-icon-delete"
@click="open">删除</el-button>
</div>
</div>
<!--表单组件-->
<eForm ref="form" :is-add="isAdd" <#if hasDict>:dicts="dict"</#if>/>
<!--表格渲染-->
<el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
<el-table v-loading="loading" ref="table" :data="data" size="small" style="width: 100%;">
<el-table-column type="selection" width="55"/>
<#if columns??>
<#list columns as column>
<#if column.columnShow>
...
...
@@ -105,7 +117,7 @@
<
script
>
import
checkPermission from '@/utils/permission'
import
initData from '@/mixins/initData'
import
{
del
,
download
$
{
className
}
}
from '@/api/$
{
changeClassName
}
'
import
{
del
,
download
$
{
className
}
,
delAll
}
from '@/api/$
{
changeClassName
}
'
<#
if
hasTimestamp>
import
{
parseTime
,
downloadFile
}
from '@/utils/index'
</#
if
>
...
...
@@ -118,7 +130,7 @@ export default {
</#
if
>
data
()
{
return
{
delLoading
:
false
,
delLoading
:
false
,
delAllLoading
:
false
,
<#
if
hasQuery
>
queryTypeOptions
:
[
<#
if
queryColumns
??>
...
...
@@ -208,6 +220,36 @@ export default {
})
.catch
(()
=>
{
this
.downloadLoading
=
false
})
},
doDelete
()
{
this
.delAllLoading
=
true
const
data
=
this
.
$refs
.table.selection
const
ids
=
[]
for
(
let
i
=
0
;
i
<
data
.length
;
i
++
)
{
ids
.push
(
data
[
i
]
.id
)
}
delAll
(
ids
)
.then
(
res
=>
{
this
.delAllLoading
=
false
this
.init
()
this
.dleChangePage
(
ids
.length
)
this
.
$notify
({
title
:
'删除成功'
,
type
:
'
success
'
,
duration
:
2500
})
})
.catch
(
err
=>
{
this
.delAllLoading
=
false
console
.log
(
err
.response.data.message
)
})
},
open
()
{
this
.
$confirm
(
'你确定删除选中的数据吗?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'
warning
'
})
.then
(()
=>
{
this
.doDelete
()
})
}
}
}
...
...
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