Compare commits
4 Commits
36c8959c01
...
e167a4467d
| Author | SHA1 | Date | |
|---|---|---|---|
| e167a4467d | |||
| 2ad3035f87 | |||
| 10b7451f28 | |||
| e2b6b50497 |
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="mavenCentral" />
|
||||
<option name="name" value="mavenCentral" />
|
||||
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -2,7 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/gringotts.iml" filepath="$PROJECT_DIR$/gringotts.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/gringotts-web/gringotts-web.iml" filepath="$PROJECT_DIR$/gringotts-web/gringotts-web.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
|
||||
@@ -92,11 +92,12 @@ export const size100MB = 104857600
|
||||
export const size500MB = 524288000
|
||||
export const size1GB = 1073741824
|
||||
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB) {
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB, maxLength = undefined) {
|
||||
return {
|
||||
useChunk: true,
|
||||
accept: accept,
|
||||
maxSize: maxSize,
|
||||
maxLength: maxLength,
|
||||
autoUpload: false,
|
||||
drag: true,
|
||||
startChunkApi: apiPost('${base}/upload/start'),
|
||||
|
||||
@@ -101,7 +101,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB, 1),
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -156,7 +156,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||
},
|
||||
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
||||
{
|
||||
@@ -167,7 +167,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -297,7 +297,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
multiple: false,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB, 1),
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
checkActionMapping,
|
||||
checkOverMapping,
|
||||
checkTypeMapping,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
paginationTemplate,
|
||||
readOnlyDialogOptions,
|
||||
stringField,
|
||||
timeField,
|
||||
@@ -49,11 +51,20 @@ export function tabCheck() {
|
||||
{
|
||||
name: 'check_order_list',
|
||||
type: 'crud',
|
||||
api: apiGet('${base}/check_order/list'),
|
||||
api: {
|
||||
...apiPost('${base}/check_order/page'),
|
||||
data: {
|
||||
page: {
|
||||
page: '${page|default:1}',
|
||||
size: '${perPage|default:10}',
|
||||
}
|
||||
}
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
],
|
||||
...paginationTemplate(10),
|
||||
columns: [
|
||||
stringField('description', '描述'),
|
||||
mappingField('type', '类型', checkTypeMapping),
|
||||
|
||||
@@ -3,88 +3,96 @@ import {useAmis} from "../../components/constants.js";
|
||||
useAmis((information) => {
|
||||
return {
|
||||
"type": "wrapper",
|
||||
"size": "none",
|
||||
"body": [
|
||||
{
|
||||
"type": "property",
|
||||
"items": [
|
||||
{
|
||||
"content": "API资源",
|
||||
"label": "名称"
|
||||
},
|
||||
{
|
||||
"label": "标签",
|
||||
"span": 2,
|
||||
"content": [
|
||||
{
|
||||
"type": "tag",
|
||||
"label": "API"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "简介",
|
||||
"span": 3,
|
||||
"content": "API 资源"
|
||||
},
|
||||
{
|
||||
"span": 3,
|
||||
"content": "<p>这是API<strong>资源</strong></p>",
|
||||
"label": "内容"
|
||||
},
|
||||
],
|
||||
"title": "商品信息"
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "wrapper",
|
||||
"body": [
|
||||
{
|
||||
"type": "property",
|
||||
"items": [
|
||||
{
|
||||
"label": "资源名称",
|
||||
"span": 3,
|
||||
"content": "文件资源"
|
||||
},
|
||||
{
|
||||
"content": "FIle",
|
||||
"span": 3,
|
||||
"label": "资源描述"
|
||||
}
|
||||
],
|
||||
"type": "property"
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"title": "资源类型定义",
|
||||
"type": "property",
|
||||
"items": [
|
||||
{
|
||||
"span": 3,
|
||||
"label": "资源类型",
|
||||
"content": "文件"
|
||||
"content": "API资源"
|
||||
},
|
||||
{
|
||||
"span": 3,
|
||||
"content": {
|
||||
"type": "flex",
|
||||
"alignItems": "start",
|
||||
"items": [
|
||||
{
|
||||
"label": "arthas-bin.zip",
|
||||
"api": {
|
||||
"method": "get",
|
||||
"url": "${base}/upload/download/3557040775256064",
|
||||
"headers": {
|
||||
"token": "${token|default:undefined}"
|
||||
},
|
||||
"responseType": "blob"
|
||||
},
|
||||
"actionType": "ajax",
|
||||
"type": "action",
|
||||
"level": "link"
|
||||
}
|
||||
],
|
||||
"direction": "column"
|
||||
},
|
||||
"label": "文件"
|
||||
},
|
||||
{
|
||||
label: '格式详情',
|
||||
content: {
|
||||
type: 'editor',
|
||||
language: 'json',
|
||||
value: {
|
||||
"name": "arthas-bin.zip",
|
||||
"size": 1024,
|
||||
"type": "application/zip",
|
||||
"lastModified": 1673920000000,
|
||||
"lastModifiedDate": "2023-01-14T14:40:00.000Z",
|
||||
"webkitRelativePath": ""
|
||||
}
|
||||
},
|
||||
"label": "资源描述",
|
||||
"content": "这是API资源"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"span": 3,
|
||||
"content": "API",
|
||||
"label": "资源类型"
|
||||
},
|
||||
{
|
||||
"span": 1,
|
||||
"content": "administrator@eshore.com",
|
||||
"label": "用户名"
|
||||
},
|
||||
{
|
||||
"label": "密码",
|
||||
"content": "bLiN+,qAss,uo'nxoH_:d@HEdD*WdZWAudq$J'a$5Z#aS>K-*dWN5L-i<m:w/U,R",
|
||||
"span": 2
|
||||
},
|
||||
{
|
||||
"span": 3,
|
||||
"content": "http://baidu.com",
|
||||
"label": "地址"
|
||||
}
|
||||
],
|
||||
"title": "资源类型定义",
|
||||
"type": "property"
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"label": "格式类型",
|
||||
"content": "Json"
|
||||
"span": 3,
|
||||
"content": "文件"
|
||||
}
|
||||
],
|
||||
"type": "property",
|
||||
@@ -97,6 +105,7 @@ useAmis((information) => {
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "property",
|
||||
"items": [
|
||||
{
|
||||
"label": "创建人",
|
||||
@@ -104,8 +113,8 @@ useAmis((information) => {
|
||||
"content": "administrator@eshore.com"
|
||||
},
|
||||
{
|
||||
"content": "2025-01-14 14:41:56",
|
||||
"label": "创建时间"
|
||||
"label": "创建时间",
|
||||
"content": "2025-01-23 14:24:15"
|
||||
},
|
||||
{
|
||||
"span": 2,
|
||||
@@ -113,12 +122,12 @@ useAmis((information) => {
|
||||
"label": "修改人"
|
||||
},
|
||||
{
|
||||
"content": "2025-01-14 14:41:56",
|
||||
"label": "修改时间"
|
||||
"label": "修改时间",
|
||||
"content": "2025-01-23 14:24:15"
|
||||
}
|
||||
],
|
||||
"type": "property"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"size": "none"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
@@ -12,4 +13,8 @@ public interface ListController<LIST_ITEM> {
|
||||
AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception;
|
||||
|
||||
AmisResponse<ImmutableList<LIST_ITEM>> list(Query query) throws Exception;
|
||||
|
||||
AmisListResponse page() throws Exception;
|
||||
|
||||
AmisListResponse page(Query query) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> implements SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
protected static final String SAVE = "/save";
|
||||
protected static final String LIST = "/list";
|
||||
protected static final String PAGE = "/page";
|
||||
protected static final String DETAIL = "/detail/{id}";
|
||||
protected static final String REMOVE = "/remove/{id}";
|
||||
|
||||
@@ -63,6 +67,44 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping(PAGE)
|
||||
@Override
|
||||
public AmisListResponse page() throws Exception {
|
||||
Page<ENTITY> page = service.page();
|
||||
return AmisResponse.responseListData(
|
||||
page.getContent()
|
||||
.stream()
|
||||
.map(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList()),
|
||||
page.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping(PAGE)
|
||||
@Override
|
||||
public AmisListResponse page(@RequestBody Query query) throws Exception {
|
||||
Page<ENTITY> page = service.page(query);
|
||||
return AmisResponse.responseListData(
|
||||
page.getContent()
|
||||
.stream()
|
||||
.map(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList()),
|
||||
page.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
@Override
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
@@ -21,6 +22,10 @@ public interface SimpleService<ENTITY extends SimpleEntity> {
|
||||
|
||||
ImmutableList<ENTITY> list(Query query) throws Exception;
|
||||
|
||||
Page<ENTITY> page() throws Exception;
|
||||
|
||||
Page<ENTITY> page(Query query) throws Exception;
|
||||
|
||||
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||
|
||||
ENTITY detail(Long id) throws Exception;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||
@@ -12,10 +11,10 @@ import com.eshore.gringotts.web.domain.base.entity.SimpleEntity_;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.eshore.gringotts.web.helper.QueryHelper;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
@@ -24,6 +23,8 @@ import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
@@ -99,87 +100,6 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
||||
));
|
||||
}
|
||||
|
||||
private <Y> Path<Y> column(Root<ENTITY> root, String column) {
|
||||
String[] columns = StrUtil.splitToArray(column, "/");
|
||||
Path<Y> path = root.get(columns[0]);
|
||||
for (int i = 1; i < columns.length; i++) {
|
||||
path = path.get(columns[i]);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private <Y> Object value(Path<Y> column, Object value) {
|
||||
Class<?> javaType = column.getJavaType();
|
||||
if (EnumUtil.isEnum(javaType)) {
|
||||
return EnumUtil.fromString((Class<Enum>) javaType, (String) value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ImmutableList<Predicate> queryPredicates(Query.Queryable queryable, Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
MutableList<Predicate> predicates = Lists.mutable.empty();
|
||||
if (ObjectUtil.isEmpty(queryable)) {
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNullEqual())) {
|
||||
queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotNullEqual())) {
|
||||
queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEmpty())) {
|
||||
queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEmpty())) {
|
||||
queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.equal(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.notEqual(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLike())) {
|
||||
queryable.getLike().forEachKeyValue((column, value) -> predicates.add(builder.like(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotLike())) {
|
||||
queryable.getNotLike().forEachKeyValue((column, value) -> predicates.add(builder.notLike(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreat())) {
|
||||
queryable.getGreat().forEachKeyValue((column, value) -> predicates.add(builder.greaterThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLess())) {
|
||||
queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreatEqual())) {
|
||||
queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLessEqual())) {
|
||||
queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getIn())) {
|
||||
queryable.getIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotIn())) {
|
||||
queryable.getNotIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value).not()));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getBetween())) {
|
||||
queryable.getBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotBetween())) {
|
||||
queryable.getNotBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
|
||||
protected ImmutableList<Predicate> listPredicate(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
@@ -193,13 +113,36 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
predicates.addAllIterable(queryPredicates(listQuery.getQuery(), root, query, builder));
|
||||
predicates.addAllIterable(QueryHelper.queryPredicates(listQuery.getQuery(), root, query, builder));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by(SimpleEntity_.CREATED_TIME).descending()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ENTITY> page() throws Exception {
|
||||
return repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
PageRequest.of(0, 10, Sort.by(SimpleEntity_.CREATED_TIME).descending())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ENTITY> page(Query listQuery) throws Exception {
|
||||
return repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
predicates.addAllIterable(QueryHelper.queryPredicates(listQuery.getQuery(), root, query, builder));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
PageRequest.of(listQuery.getPage().getPage(), listQuery.getPage().getSize(), Sort.by(SimpleEntity_.CREATED_TIME).descending())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.eshore.gringotts.web.domain.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.ListController;
|
||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.eshore.gringotts.web.helper.QueryHelper;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -18,6 +21,7 @@ import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -64,10 +68,41 @@ public class CheckOrderController implements ListController<CheckOrderController
|
||||
|
||||
@PostMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
|
||||
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query listQuery) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Override
|
||||
public AmisListResponse page() throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@Override
|
||||
public AmisListResponse page(@RequestBody Query listQuery) throws Exception {
|
||||
User user = userService.currentLoginUser();
|
||||
Page<FlowableInstance> page = flowableManager.listInstances(
|
||||
(root, query, builder) -> {
|
||||
if (User.isAdministrator(user)) {
|
||||
return null;
|
||||
}
|
||||
return builder.or(
|
||||
builder.like(root.get("extra"), user.getRole().name()),
|
||||
builder.like(root.get("extra"), user.getId().toString())
|
||||
);
|
||||
},
|
||||
QueryHelper.pageable(listQuery)
|
||||
);
|
||||
return AmisListResponse.responseListData(
|
||||
page.getContent()
|
||||
.stream()
|
||||
.map(this::toListItem)
|
||||
.collect(Collectors.toList()),
|
||||
page.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/approve/{instanceId}")
|
||||
public AmisResponse<Object> approve(@PathVariable String instanceId) {
|
||||
flowableManager.approve(instanceId);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.eshore.gringotts.web.domain.controller;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.eshore.gringotts.web.configuration.HostConfiguration;
|
||||
import com.eshore.gringotts.web.configuration.UploadConfiguration;
|
||||
@@ -86,7 +87,7 @@ public class DataFileController {
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Type");
|
||||
response.setHeader("Content-Type", dataFile.getType());
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setHeader("Content-Disposition", StrUtil.format("attachment; filename={}", dataFile.getFilename()));
|
||||
response.setHeader("Content-Disposition", StrUtil.format("attachment; filename={}", URLUtil.encodeAll(dataFile.getFilename())));
|
||||
IoUtil.copy(new FileInputStream(targetFile), response.getOutputStream());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -54,6 +55,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
||||
ware.setDescription(saveItem.getDescription());
|
||||
ware.setIcon(dataFileService.detailOrThrow(saveItem.getIconId()));
|
||||
ware.setContent(saveItem.getContent());
|
||||
ware.setTags(saveItem.getTags().toList());
|
||||
return ware;
|
||||
}
|
||||
|
||||
@@ -81,6 +83,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
||||
item.setDescription(entity.getDescription());
|
||||
item.setIconId(entity.getIcon().getId());
|
||||
item.setContent(entity.getContent());
|
||||
item.setTags(Lists.immutable.ofAll(entity.getTags()));
|
||||
item.setIcon(StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), entity.getIcon().getId()));
|
||||
item.setCreatedTime(entity.getCreatedTime());
|
||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||
@@ -97,6 +100,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
||||
private String description;
|
||||
private Long iconId;
|
||||
private String content;
|
||||
private ImmutableList<String> tags;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.TABLE_PREFIX + "check_order")
|
||||
@NamedEntityGraph(name = "check_order.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "check_order.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NoArgsConstructor
|
||||
public class CheckOrder extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String keyword;
|
||||
@Column(nullable = false)
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Type type;
|
||||
/**
|
||||
* JSON 结构 Map<String, Object>
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private String parameters;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Target target;
|
||||
@Column(nullable = false)
|
||||
private String targetClass;
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private User targetUser;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private User.Role targetRole;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.CHECKING;
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User targetUser
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.USER;
|
||||
this.targetClass = targetClass;
|
||||
this.targetUser = targetUser;
|
||||
}
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User.Role targetRole
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.ROLE;
|
||||
this.targetClass = targetClass;
|
||||
this.targetRole = targetRole;
|
||||
}
|
||||
|
||||
public enum Operation {
|
||||
APPLY,
|
||||
REJECT,
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
CONFIRMATION,
|
||||
AUTHENTICATION,
|
||||
MARKET,
|
||||
}
|
||||
|
||||
public enum Target {
|
||||
USER,
|
||||
ROLE,
|
||||
}
|
||||
|
||||
public enum State {
|
||||
CHECKING,
|
||||
RETRACT,
|
||||
OVER,
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package com.eshore.gringotts.web.domain.entity;
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import java.util.List;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
@@ -66,4 +69,7 @@ public class Ware extends CheckingNeededEntity {
|
||||
@ToString.Exclude
|
||||
@Column(nullable = false)
|
||||
private String content;
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = Constants.TABLE_PREFIX + "ware_tag", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private List<String> tags;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface CheckOrderRepository extends SimpleRepository<CheckOrder, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<CheckOrder> findAll(Specification<CheckOrder> specification);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<CheckOrder> findAll(Specification<CheckOrder> specification, Sort sort);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<CheckOrder> findOne(Specification<CheckOrder> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update CheckOrder check set check.state = ?2, check.modifiedUser = ?3, check.modifiedTime = current_timestamp where check.id = ?1")
|
||||
void overById(Long id, CheckOrder.State state, User modifiedUser);
|
||||
}
|
||||
@@ -81,7 +81,13 @@ public class ConfirmationService extends CheckingService<Confirmation> {
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(entity),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(resource.getExample())
|
||||
AmisHelper.property(resource.getExample()),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(
|
||||
"确权申请信息",
|
||||
AmisHelper.propertyItem("描述", entity.getDescription()),
|
||||
AmisHelper.propertyItem(entity.getEvidences())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
||||
import com.eshore.gringotts.web.domain.repository.WareRepository;
|
||||
import com.eshore.gringotts.web.helper.AmisHelper;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
|
||||
@@ -13,6 +15,7 @@ import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import javax.persistence.EntityManager;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
@@ -54,6 +57,7 @@ public class WareService extends CheckingService<Ware> {
|
||||
);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
User user = userService.currentLoginUser();
|
||||
@@ -63,6 +67,7 @@ public class WareService extends CheckingService<Ware> {
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("wareId", id)
|
||||
.put("type", "WARE")
|
||||
.put("snapshot", archive(ware))
|
||||
.put("createdUsername", user.getUsername())
|
||||
.put("modifiedUsername", user.getUsername())
|
||||
.put(UserAssessor.KEY, ware.getResource().getCreatedUser().getId())
|
||||
@@ -81,7 +86,23 @@ public class WareService extends CheckingService<Ware> {
|
||||
|
||||
@Override
|
||||
protected Object archive(Ware entity) {
|
||||
return "";
|
||||
DataResource resource = entity.getResource();
|
||||
return AmisHelper.wrapper(
|
||||
AmisHelper.property(
|
||||
"商品信息",
|
||||
AmisHelper.propertyItem("名称", entity.getName()),
|
||||
AmisHelper.propertyItem(
|
||||
"标签",
|
||||
Lists.immutable.ofAll(entity.getTags()).collect(AmisHelper::tag)
|
||||
),
|
||||
AmisHelper.propertyItem("简介", entity.getDescription(), 3),
|
||||
AmisHelper.propertyItem("内容", entity.getContent(), 3)
|
||||
),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(resource),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(entity)
|
||||
);
|
||||
}
|
||||
|
||||
@Component
|
||||
|
||||
@@ -190,8 +190,8 @@ public class AmisHelper {
|
||||
return propertyItem(Lists.immutable.of(dataFile));
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> propertyItem(ImmutableList<DataFile> dataFiles) {
|
||||
return propertyItem("文件", dataFiles);
|
||||
public static ImmutableMap<Object, Object> propertyItem(Iterable<DataFile> dataFiles) {
|
||||
return propertyItem("文件", Lists.immutable.ofAll(dataFiles));
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> propertyItem(String label, ImmutableList<DataFile> dataFiles) {
|
||||
@@ -202,6 +202,13 @@ public class AmisHelper {
|
||||
);
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> tag(String value) {
|
||||
return Maps.immutable.ofMap(MapUtil.builder()
|
||||
.put("type", "tag")
|
||||
.put("label", value)
|
||||
.build());
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> editor(String language, String value) {
|
||||
return Maps.immutable.ofMap(MapUtil.builder()
|
||||
.put("disabled", true)
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.eshore.gringotts.web.helper;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity_;
|
||||
import java.util.List;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250114
|
||||
*/
|
||||
public class QueryHelper {
|
||||
private static <ENTITY, Y> Path<Y> column(Root<ENTITY> root, String column) {
|
||||
String[] columns = StrUtil.splitToArray(column, "/");
|
||||
Path<Y> path = root.get(columns[0]);
|
||||
for (int i = 1; i < columns.length; i++) {
|
||||
path = path.get(columns[i]);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static <Y> Object value(Path<Y> column, Object value) {
|
||||
Class<?> javaType = column.getJavaType();
|
||||
if (EnumUtil.isEnum(javaType)) {
|
||||
return EnumUtil.fromString((Class<Enum>) javaType, (String) value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <ENTITY> ImmutableList<Predicate> queryPredicates(Query.Queryable queryable, Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
MutableList<Predicate> predicates = Lists.mutable.empty();
|
||||
if (ObjectUtil.isEmpty(queryable)) {
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNullEqual())) {
|
||||
queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotNullEqual())) {
|
||||
queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEmpty())) {
|
||||
queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEmpty())) {
|
||||
queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.equal(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.notEqual(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLike())) {
|
||||
queryable.getLike().forEachKeyValue((column, value) -> predicates.add(builder.like(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotLike())) {
|
||||
queryable.getNotLike().forEachKeyValue((column, value) -> predicates.add(builder.notLike(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreat())) {
|
||||
queryable.getGreat().forEachKeyValue((column, value) -> predicates.add(builder.greaterThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLess())) {
|
||||
queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreatEqual())) {
|
||||
queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLessEqual())) {
|
||||
queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getIn())) {
|
||||
queryable.getIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotIn())) {
|
||||
queryable.getNotIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value).not()));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getBetween())) {
|
||||
queryable.getBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotBetween())) {
|
||||
queryable.getNotBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
|
||||
public static Pageable pageable(Query query) {
|
||||
if (ObjectUtil.isNull(query)) {
|
||||
return PageRequest.of(0, 10);
|
||||
}
|
||||
int page = Math.max(query.getPage().getPage() - 1, 0);
|
||||
if (ObjectUtil.isEmpty(query.getSort())) {
|
||||
return org.springframework.data.domain.PageRequest.of(page, query.getPage().getSize(), Sort.by(Sort.Direction.DESC, SimpleEntity_.CREATED_TIME));
|
||||
} else {
|
||||
List<Sort.Order> orders = query.getSort()
|
||||
.collect(sortable -> new Sort.Order(Sort.Direction.fromString(sortable.getDirection().name()), sortable.getColumn()))
|
||||
.toList();
|
||||
return org.springframework.data.domain.PageRequest.of(page, query.getPage().getSize(), Sort.by(orders));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user