Compare commits
6 Commits
b16dba4ef1
...
flowable
| Author | SHA1 | Date | |
|---|---|---|---|
| e167a4467d | |||
| 2ad3035f87 | |||
| 10b7451f28 | |||
| e2b6b50497 | |||
| 36c8959c01 | |||
| 4242940e6b |
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
<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>
|
<remote-repository>
|
||||||
<option name="id" value="mavenCentral" />
|
<option name="id" value="mavenCentral" />
|
||||||
<option name="name" value="mavenCentral" />
|
<option name="name" value="mavenCentral" />
|
||||||
|
|||||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -2,7 +2,6 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<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" />
|
<module fileurl="file://$PROJECT_DIR$/gringotts-web/gringotts-web.iml" filepath="$PROJECT_DIR$/gringotts-web/gringotts-web.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -92,11 +92,12 @@ export const size100MB = 104857600
|
|||||||
export const size500MB = 524288000
|
export const size500MB = 524288000
|
||||||
export const size1GB = 1073741824
|
export const size1GB = 1073741824
|
||||||
|
|
||||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB) {
|
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB, maxLength = undefined) {
|
||||||
return {
|
return {
|
||||||
useChunk: true,
|
useChunk: true,
|
||||||
accept: accept,
|
accept: accept,
|
||||||
maxSize: maxSize,
|
maxSize: maxSize,
|
||||||
|
maxLength: maxLength,
|
||||||
autoUpload: false,
|
autoUpload: false,
|
||||||
drag: true,
|
drag: true,
|
||||||
startChunkApi: apiPost('${base}/upload/start'),
|
startChunkApi: apiPost('${base}/upload/start'),
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
required: true,
|
required: true,
|
||||||
joinValues: false,
|
joinValues: false,
|
||||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
...inputFileFormItemCommonOptions('.zip', size1GB, 1),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -156,7 +156,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
required: true,
|
required: true,
|
||||||
joinValues: false,
|
joinValues: false,
|
||||||
...inputFileFormItemCommonOptions('.xml'),
|
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||||
},
|
},
|
||||||
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
||||||
{
|
{
|
||||||
@@ -167,7 +167,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
required: true,
|
required: true,
|
||||||
joinValues: false,
|
joinValues: false,
|
||||||
...inputFileFormItemCommonOptions('.xml'),
|
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -297,7 +297,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
|||||||
description: '可以上传用于作为格式示范的样例数据',
|
description: '可以上传用于作为格式示范的样例数据',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
joinValues: false,
|
joinValues: false,
|
||||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
...inputFileFormItemCommonOptions(undefined, size500MB, 1),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
apiGet,
|
apiGet,
|
||||||
|
apiPost,
|
||||||
checkActionMapping,
|
checkActionMapping,
|
||||||
checkOverMapping,
|
checkOverMapping,
|
||||||
checkTypeMapping,
|
checkTypeMapping,
|
||||||
crudCommonOptions,
|
crudCommonOptions,
|
||||||
mappingField,
|
mappingField,
|
||||||
operationField,
|
operationField,
|
||||||
|
paginationTemplate,
|
||||||
readOnlyDialogOptions,
|
readOnlyDialogOptions,
|
||||||
stringField,
|
stringField,
|
||||||
timeField,
|
timeField,
|
||||||
@@ -49,11 +51,20 @@ export function tabCheck() {
|
|||||||
{
|
{
|
||||||
name: 'check_order_list',
|
name: 'check_order_list',
|
||||||
type: 'crud',
|
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(),
|
...crudCommonOptions(),
|
||||||
headerToolbar: [
|
headerToolbar: [
|
||||||
'reload',
|
'reload',
|
||||||
],
|
],
|
||||||
|
...paginationTemplate(10),
|
||||||
columns: [
|
columns: [
|
||||||
stringField('description', '描述'),
|
stringField('description', '描述'),
|
||||||
mappingField('type', '类型', checkTypeMapping),
|
mappingField('type', '类型', checkTypeMapping),
|
||||||
|
|||||||
25
gringotts-frontend/pages/test/index.html
Normal file
25
gringotts-frontend/pages/test/index.html
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||||
|
<title></title>
|
||||||
|
<link href="/assets/sdk/antd.css" rel="stylesheet"/>
|
||||||
|
<link href="/assets/sdk/helper.css" rel="stylesheet"/>
|
||||||
|
<link href="/assets/sdk/iconfont.css" rel="stylesheet"/>
|
||||||
|
<style>
|
||||||
|
html, body, #app {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="/assets/sdk/sdk.js"></script>
|
||||||
|
<script src="./main.js" type="module"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
133
gringotts-frontend/pages/test/main.js
Normal file
133
gringotts-frontend/pages/test/main.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import {useAmis} from "../../components/constants.js";
|
||||||
|
|
||||||
|
useAmis((information) => {
|
||||||
|
return {
|
||||||
|
"type": "wrapper",
|
||||||
|
"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": "API资源"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"span": 3,
|
||||||
|
"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": "格式类型",
|
||||||
|
"span": 3,
|
||||||
|
"content": "文件"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "property",
|
||||||
|
"title": "资源格式定义"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"size": "none"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "divider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "property",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"label": "创建人",
|
||||||
|
"span": 2,
|
||||||
|
"content": "administrator@eshore.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "创建时间",
|
||||||
|
"content": "2025-01-23 14:24:15"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"span": 2,
|
||||||
|
"content": "administrator@eshore.com",
|
||||||
|
"label": "修改人"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "修改时间",
|
||||||
|
"content": "2025-01-23 14:24:15"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"size": "none"
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.controller;
|
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.configuration.amis.AmisResponse;
|
||||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
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() throws Exception;
|
||||||
|
|
||||||
AmisResponse<ImmutableList<LIST_ITEM>> list(Query query) 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;
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
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.configuration.amis.AmisResponse;
|
||||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
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.entity.SimpleEntity;
|
||||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.collections.api.factory.Lists;
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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> {
|
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 SAVE = "/save";
|
||||||
protected static final String LIST = "/list";
|
protected static final String LIST = "/list";
|
||||||
|
protected static final String PAGE = "/page";
|
||||||
protected static final String DETAIL = "/detail/{id}";
|
protected static final String DETAIL = "/detail/{id}";
|
||||||
protected static final String REMOVE = "/remove/{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)
|
@GetMapping(DETAIL)
|
||||||
@Override
|
@Override
|
||||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
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 java.util.Optional;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
@@ -21,6 +22,10 @@ public interface SimpleService<ENTITY extends SimpleEntity> {
|
|||||||
|
|
||||||
ImmutableList<ENTITY> list(Query query) throws Exception;
|
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;
|
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||||
|
|
||||||
ENTITY detail(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.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.util.EnumUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.controller.query.Query;
|
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.base.repository.SimpleRepository;
|
||||||
import com.eshore.gringotts.web.domain.entity.User;
|
import com.eshore.gringotts.web.domain.entity.User;
|
||||||
import com.eshore.gringotts.web.domain.service.UserService;
|
import com.eshore.gringotts.web.domain.service.UserService;
|
||||||
|
import com.eshore.gringotts.web.helper.QueryHelper;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Path;
|
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.transaction.Transactional;
|
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.ImmutableList;
|
||||||
import org.eclipse.collections.api.list.MutableList;
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
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;
|
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) {
|
protected ImmutableList<Predicate> listPredicate(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||||
User user = userService.currentLoginUser();
|
User user = userService.currentLoginUser();
|
||||||
if (User.isNotAdministrator(user)) {
|
if (User.isNotAdministrator(user)) {
|
||||||
@@ -193,13 +113,36 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
return Lists.immutable.ofAll(repository.findAll(
|
return Lists.immutable.ofAll(repository.findAll(
|
||||||
(root, query, builder) -> {
|
(root, query, builder) -> {
|
||||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(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()]));
|
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||||
},
|
},
|
||||||
Sort.by(SimpleEntity_.CREATED_TIME).descending()
|
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
|
@Override
|
||||||
public Optional<ENTITY> detailOptional(Long id) {
|
public Optional<ENTITY> detailOptional(Long id) {
|
||||||
if (ObjectUtil.isNull(id)) {
|
if (ObjectUtil.isNull(id)) {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package com.eshore.gringotts.web.domain.controller;
|
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.configuration.amis.AmisResponse;
|
||||||
import com.eshore.gringotts.web.domain.base.controller.ListController;
|
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.base.controller.query.Query;
|
||||||
import com.eshore.gringotts.web.domain.entity.User;
|
import com.eshore.gringotts.web.domain.entity.User;
|
||||||
import com.eshore.gringotts.web.domain.service.UserService;
|
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.FlowableHistory;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.factory.Maps;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.eclipse.collections.api.map.ImmutableMap;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -64,10 +68,41 @@ public class CheckOrderController implements ListController<CheckOrderController
|
|||||||
|
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@Override
|
@Override
|
||||||
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
|
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query listQuery) throws Exception {
|
||||||
throw new UnsupportedOperationException();
|
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}")
|
@GetMapping("/approve/{instanceId}")
|
||||||
public AmisResponse<Object> approve(@PathVariable String instanceId) {
|
public AmisResponse<Object> approve(@PathVariable String instanceId) {
|
||||||
flowableManager.approve(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.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import com.eshore.gringotts.web.configuration.HostConfiguration;
|
import com.eshore.gringotts.web.configuration.HostConfiguration;
|
||||||
import com.eshore.gringotts.web.configuration.UploadConfiguration;
|
import com.eshore.gringotts.web.configuration.UploadConfiguration;
|
||||||
@@ -86,7 +87,7 @@ public class DataFileController {
|
|||||||
response.setHeader("Access-Control-Expose-Headers", "Content-Type");
|
response.setHeader("Access-Control-Expose-Headers", "Content-Type");
|
||||||
response.setHeader("Content-Type", dataFile.getType());
|
response.setHeader("Content-Type", dataFile.getType());
|
||||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
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());
|
IoUtil.copy(new FileInputStream(targetFile), response.getOutputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.time.LocalDateTime;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -54,6 +55,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
|||||||
ware.setDescription(saveItem.getDescription());
|
ware.setDescription(saveItem.getDescription());
|
||||||
ware.setIcon(dataFileService.detailOrThrow(saveItem.getIconId()));
|
ware.setIcon(dataFileService.detailOrThrow(saveItem.getIconId()));
|
||||||
ware.setContent(saveItem.getContent());
|
ware.setContent(saveItem.getContent());
|
||||||
|
ware.setTags(saveItem.getTags().toList());
|
||||||
return ware;
|
return ware;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +83,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
|||||||
item.setDescription(entity.getDescription());
|
item.setDescription(entity.getDescription());
|
||||||
item.setIconId(entity.getIcon().getId());
|
item.setIconId(entity.getIcon().getId());
|
||||||
item.setContent(entity.getContent());
|
item.setContent(entity.getContent());
|
||||||
|
item.setTags(Lists.immutable.ofAll(entity.getTags()));
|
||||||
item.setIcon(StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), entity.getIcon().getId()));
|
item.setIcon(StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), entity.getIcon().getId()));
|
||||||
item.setCreatedTime(entity.getCreatedTime());
|
item.setCreatedTime(entity.getCreatedTime());
|
||||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||||
@@ -97,6 +100,7 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
|||||||
private String description;
|
private String description;
|
||||||
private Long iconId;
|
private Long iconId;
|
||||||
private String content;
|
private String content;
|
||||||
|
private ImmutableList<String> tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@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.core.Constants;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||||
|
import java.util.List;
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.ConstraintMode;
|
import javax.persistence.ConstraintMode;
|
||||||
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityListeners;
|
import javax.persistence.EntityListeners;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
@@ -66,4 +69,7 @@ public class Ware extends CheckingNeededEntity {
|
|||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String content;
|
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);
|
|
||||||
}
|
|
||||||
@@ -77,16 +77,17 @@ public class ConfirmationService extends CheckingService<Confirmation> {
|
|||||||
protected Object archive(Confirmation entity) {
|
protected Object archive(Confirmation entity) {
|
||||||
DataResource resource = entity.getTarget();
|
DataResource resource = entity.getTarget();
|
||||||
return AmisHelper.wrapper(
|
return AmisHelper.wrapper(
|
||||||
|
AmisHelper.property(resource),
|
||||||
|
AmisHelper.divider(),
|
||||||
|
AmisHelper.property(entity),
|
||||||
|
AmisHelper.divider(),
|
||||||
|
AmisHelper.property(resource.getExample()),
|
||||||
|
AmisHelper.divider(),
|
||||||
AmisHelper.property(
|
AmisHelper.property(
|
||||||
AmisHelper.propertyItem("资源名称", resource.getName(), 3),
|
"确权申请信息",
|
||||||
AmisHelper.propertyItem("资源描述", resource.getDescription(), 3)
|
AmisHelper.propertyItem("描述", entity.getDescription()),
|
||||||
),
|
AmisHelper.propertyItem(entity.getEvidences())
|
||||||
AmisHelper.divider(),
|
)
|
||||||
AmisHelper.property(resource.getType()),
|
|
||||||
AmisHelper.divider(),
|
|
||||||
AmisHelper.property(resource.getFormat()),
|
|
||||||
AmisHelper.divider(),
|
|
||||||
AmisHelper.property(entity)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package com.eshore.gringotts.web.domain.service;
|
|||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
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.User;
|
||||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||||
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
||||||
import com.eshore.gringotts.web.domain.repository.WareRepository;
|
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.FlowableAction;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
|
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.core.model.FlowableNode;
|
||||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.collections.api.factory.Lists;
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
@@ -54,6 +57,7 @@ public class WareService extends CheckingService<Ware> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void submit(Long id) {
|
public void submit(Long id) {
|
||||||
User user = userService.currentLoginUser();
|
User user = userService.currentLoginUser();
|
||||||
@@ -63,6 +67,7 @@ public class WareService extends CheckingService<Ware> {
|
|||||||
MapUtil.<String, Object>builder()
|
MapUtil.<String, Object>builder()
|
||||||
.put("wareId", id)
|
.put("wareId", id)
|
||||||
.put("type", "WARE")
|
.put("type", "WARE")
|
||||||
|
.put("snapshot", archive(ware))
|
||||||
.put("createdUsername", user.getUsername())
|
.put("createdUsername", user.getUsername())
|
||||||
.put("modifiedUsername", user.getUsername())
|
.put("modifiedUsername", user.getUsername())
|
||||||
.put(UserAssessor.KEY, ware.getResource().getCreatedUser().getId())
|
.put(UserAssessor.KEY, ware.getResource().getCreatedUser().getId())
|
||||||
@@ -81,7 +86,23 @@ public class WareService extends CheckingService<Ware> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object archive(Ware entity) {
|
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
|
@Component
|
||||||
|
|||||||
@@ -5,8 +5,17 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.DataFile;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.DataResource;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.format.CsvResourceFormat;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.format.JsonLineResourceFormat;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.format.JsonResourceFormat;
|
||||||
import com.eshore.gringotts.web.domain.entity.format.ResourceFormat;
|
import com.eshore.gringotts.web.domain.entity.format.ResourceFormat;
|
||||||
import com.eshore.gringotts.web.domain.entity.type.ApiResourceType;
|
import com.eshore.gringotts.web.domain.entity.type.ApiResourceType;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.type.DatabaseResourceType;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.type.FileResourceType;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.type.FtpResourceType;
|
||||||
|
import com.eshore.gringotts.web.domain.entity.type.HDFSResourceType;
|
||||||
import com.eshore.gringotts.web.domain.entity.type.ResourceType;
|
import com.eshore.gringotts.web.domain.entity.type.ResourceType;
|
||||||
import org.eclipse.collections.api.factory.Lists;
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
import org.eclipse.collections.api.factory.Maps;
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
@@ -59,6 +68,19 @@ public class AmisHelper {
|
|||||||
return Maps.immutable.ofMap(builder.build());
|
return Maps.immutable.ofMap(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> property(DataResource resource) {
|
||||||
|
return AmisHelper.wrapper(
|
||||||
|
AmisHelper.property(
|
||||||
|
AmisHelper.propertyItem("资源名称", resource.getName(), 3),
|
||||||
|
AmisHelper.propertyItem("资源描述", resource.getDescription(), 3)
|
||||||
|
),
|
||||||
|
AmisHelper.divider(),
|
||||||
|
AmisHelper.property(resource.getType()),
|
||||||
|
AmisHelper.divider(),
|
||||||
|
AmisHelper.property(resource.getFormat())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static ImmutableMap<Object, Object> property(ResourceType type) {
|
public static ImmutableMap<Object, Object> property(ResourceType type) {
|
||||||
type = Hibernate.unproxy(type, ResourceType.class);
|
type = Hibernate.unproxy(type, ResourceType.class);
|
||||||
MutableList<ImmutableMap<Object, Object>> items = Lists.mutable.empty();
|
MutableList<ImmutableMap<Object, Object>> items = Lists.mutable.empty();
|
||||||
@@ -71,16 +93,32 @@ public class AmisHelper {
|
|||||||
items.add(propertyItem("地址", apiResourceType.getUrl(), 3));
|
items.add(propertyItem("地址", apiResourceType.getUrl(), 3));
|
||||||
break;
|
break;
|
||||||
case FILE:
|
case FILE:
|
||||||
items.add(propertyItem("资源类型", "文件"));
|
FileResourceType fileResourceType = (FileResourceType) type;
|
||||||
|
items.add(propertyItem("资源类型", "文件", 3));
|
||||||
|
items.add(propertyItem(fileResourceType.getFile()));
|
||||||
break;
|
break;
|
||||||
case DATABASE:
|
case DATABASE:
|
||||||
|
DatabaseResourceType databaseResourceType = (DatabaseResourceType) type;
|
||||||
items.add(propertyItem("资源类型", "数据库"));
|
items.add(propertyItem("资源类型", "数据库"));
|
||||||
|
items.add(propertyItem("数据库", databaseResourceType.getDatabaseType().name(), 3));
|
||||||
|
items.add(propertyItem("地址", databaseResourceType.getJdbc(), 3));
|
||||||
|
items.add(propertyItem("用户名", databaseResourceType.getUsername(), 1));
|
||||||
|
items.add(propertyItem("密码", databaseResourceType.getPassword(), 2));
|
||||||
break;
|
break;
|
||||||
case HDFS:
|
case HDFS:
|
||||||
|
HDFSResourceType hdfsResourceType = (HDFSResourceType) type;
|
||||||
items.add(propertyItem("资源类型", "HDFS"));
|
items.add(propertyItem("资源类型", "HDFS"));
|
||||||
|
items.add(propertyItem("core-site", hdfsResourceType.getCoreSite()));
|
||||||
|
items.add(propertyItem("hdfs-site", hdfsResourceType.getHdfsSite()));
|
||||||
break;
|
break;
|
||||||
case FTP:
|
case FTP:
|
||||||
|
FtpResourceType ftpResourceType = (FtpResourceType) type;
|
||||||
items.add(propertyItem("资源类型", "FTP"));
|
items.add(propertyItem("资源类型", "FTP"));
|
||||||
|
items.add(propertyItem("地址", ftpResourceType.getUrl(), 3));
|
||||||
|
items.add(propertyItem("用户名", ftpResourceType.getUsername(), 1));
|
||||||
|
items.add(propertyItem("密码", ftpResourceType.getPassword(), 2));
|
||||||
|
items.add(propertyItem("根路径", ftpResourceType.getPath(), 3));
|
||||||
|
items.add(propertyItem("正则匹配过滤", ftpResourceType.getRegexFilter(), 3));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return property("资源类型定义", items.toImmutable());
|
return property("资源类型定义", items.toImmutable());
|
||||||
@@ -97,13 +135,19 @@ public class AmisHelper {
|
|||||||
items.add(propertyItem("格式类型", "文本行", 3));
|
items.add(propertyItem("格式类型", "文本行", 3));
|
||||||
break;
|
break;
|
||||||
case JSON:
|
case JSON:
|
||||||
items.add(propertyItem("格式类型", "Json"));
|
JsonResourceFormat jsonResourceFormat = (JsonResourceFormat) format;
|
||||||
|
items.add(propertyItem("格式类型", "Json", 3));
|
||||||
|
items.add(propertyItem("格式详情", editor("json", jsonResourceFormat.getJsonSchema()), 3));
|
||||||
break;
|
break;
|
||||||
case JSON_LINE:
|
case JSON_LINE:
|
||||||
items.add(propertyItem("格式类型", "Json Line"));
|
JsonLineResourceFormat jsonLineResourceFormat = (JsonLineResourceFormat) format;
|
||||||
|
items.add(propertyItem("格式类型", "Json Line", 3));
|
||||||
|
items.add(propertyItem("格式详情", editor("json", jsonLineResourceFormat.getJsonSchema()), 3));
|
||||||
break;
|
break;
|
||||||
case CSV:
|
case CSV:
|
||||||
items.add(propertyItem("格式类型", "CSV文本"));
|
CsvResourceFormat csvResourceFormat = (CsvResourceFormat) format;
|
||||||
|
items.add(propertyItem("格式类型", "CSV文本", 3));
|
||||||
|
items.add(propertyItem("格式详情", editor("json", csvResourceFormat.getCsvSchema()), 3));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return property("资源格式定义", items.toImmutable());
|
return property("资源格式定义", items.toImmutable());
|
||||||
@@ -118,6 +162,12 @@ public class AmisHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> property(DataFile dataFile) {
|
||||||
|
return property(
|
||||||
|
propertyItem("资源示例", dataFile)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static ImmutableMap<Object, Object> propertyItem(String label, Object content) {
|
public static ImmutableMap<Object, Object> propertyItem(String label, Object content) {
|
||||||
return propertyItem(label, content, null);
|
return propertyItem(label, content, null);
|
||||||
}
|
}
|
||||||
@@ -131,4 +181,70 @@ public class AmisHelper {
|
|||||||
}
|
}
|
||||||
return Maps.immutable.ofMap(builder.build());
|
return Maps.immutable.ofMap(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> propertyItem(String label, DataFile dataFile) {
|
||||||
|
return propertyItem(label, Lists.immutable.of(dataFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> propertyItem(DataFile dataFile) {
|
||||||
|
return propertyItem(Lists.immutable.of(dataFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
return propertyItem(
|
||||||
|
label,
|
||||||
|
flex(dataFiles.collect(file -> ajaxAction(file.getFilename(), "${base}/upload/download/" + file.getId()))),
|
||||||
|
3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
.put("type", "editor")
|
||||||
|
.put("language", language)
|
||||||
|
.put("value", value)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> flex(ImmutableList<ImmutableMap<Object, Object>> items) {
|
||||||
|
return Maps.immutable.ofMap(MapUtil.builder()
|
||||||
|
.put("type", "flex")
|
||||||
|
.put("direction", "column")
|
||||||
|
.put("alignItems", "start")
|
||||||
|
.put("items", items)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> ajaxAction(String label, String url) {
|
||||||
|
return Maps.immutable.ofMap(MapUtil.builder()
|
||||||
|
.put("type", "action")
|
||||||
|
.put("actionType", "ajax")
|
||||||
|
.put("label", label)
|
||||||
|
.put("level", "link")
|
||||||
|
.put("api", apiDownload(url))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImmutableMap<Object, Object> apiDownload(String url) {
|
||||||
|
return Maps.immutable.ofMap(MapUtil.builder()
|
||||||
|
.put("method", "get")
|
||||||
|
.put("url", url)
|
||||||
|
.put("responseType", "blob")
|
||||||
|
.put("headers", MapUtil.builder()
|
||||||
|
.put("token", "${token|default:undefined}")
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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