Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 760f085d9c | |||
| 12cf45a106 |
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -2,6 +2,7 @@
|
||||
<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,12 +92,11 @@ export const size100MB = 104857600
|
||||
export const size500MB = 524288000
|
||||
export const size1GB = 1073741824
|
||||
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB, maxLength = undefined) {
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB) {
|
||||
return {
|
||||
useChunk: true,
|
||||
accept: accept,
|
||||
maxSize: maxSize,
|
||||
maxLength: maxLength,
|
||||
autoUpload: false,
|
||||
drag: true,
|
||||
startChunkApi: apiPost('${base}/upload/start'),
|
||||
@@ -262,19 +261,13 @@ export const permissionStateMapping = [
|
||||
export const checkTypeMapping = [
|
||||
mappingItem('确权审查', 'CONFIRMATION', 'bg-blue-500'),
|
||||
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
|
||||
mappingItem('上架审查', 'WARE', 'bg-green-500'),
|
||||
mappingItem('上架审查', 'MARKET', 'bg-green-500'),
|
||||
]
|
||||
|
||||
export const checkOverMapping = [
|
||||
mappingItem('进行中', 'RUNNING', 'bg-warning'),
|
||||
mappingItem('已撤销', 'TERMINAL', 'bg-primary'),
|
||||
mappingItem('已办结', 'COMPLETED', 'bg-success'),
|
||||
]
|
||||
|
||||
export const checkActionMapping = [
|
||||
mappingItem('同意', 'APPROVE', 'bg-green-500'),
|
||||
mappingItem('驳回', 'REJECT', 'bg-red-500'),
|
||||
mappingItem('撤回', 'TERMINAL', 'bg-blue-500'),
|
||||
mappingItem('进行中', 'CHECKING', 'bg-warning'),
|
||||
mappingItem('已撤销', 'RETRACT', 'bg-primary'),
|
||||
mappingItem('已办结', 'OVER', 'bg-success'),
|
||||
]
|
||||
|
||||
function api(method, url) {
|
||||
|
||||
@@ -101,7 +101,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB, 1),
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -156,7 +156,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
},
|
||||
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
||||
{
|
||||
@@ -167,7 +167,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml', undefined, 1),
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -297,7 +297,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
multiple: false,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB, 1),
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,70 +1,26 @@
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
checkActionMapping,
|
||||
checkOverMapping,
|
||||
checkTypeMapping,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
paginationTemplate,
|
||||
readOnlyDialogOptions,
|
||||
stringField,
|
||||
timeField,
|
||||
} from "../../components/constants.js";
|
||||
import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js";
|
||||
import {wareDetailDialog} from "../../components/ware/dialog-ware.js";
|
||||
|
||||
function detailDialog() {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '详情',
|
||||
size: 'md',
|
||||
...readOnlyDialogOptions(),
|
||||
body: [
|
||||
{
|
||||
type: 'amis',
|
||||
name: 'parameters.snapshot',
|
||||
},
|
||||
{type: 'divider'},
|
||||
{
|
||||
type: 'crud',
|
||||
api: apiGet('${base}/check_order/history/${instanceId}'),
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
],
|
||||
columns: [
|
||||
mappingField('action', '类型', checkActionMapping),
|
||||
stringField('comment', '描述'),
|
||||
timeField('createdTime', '操作时间'),
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function tabCheck() {
|
||||
return [
|
||||
{
|
||||
name: 'check_order_list',
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiPost('${base}/check_order/page'),
|
||||
data: {
|
||||
page: {
|
||||
page: '${page|default:1}',
|
||||
size: '${perPage|default:10}',
|
||||
}
|
||||
}
|
||||
},
|
||||
api: apiGet('${base}/check_order/list'),
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
],
|
||||
...paginationTemplate(10),
|
||||
columns: [
|
||||
stringField('description', '描述'),
|
||||
mappingField('type', '类型', checkTypeMapping),
|
||||
@@ -75,14 +31,7 @@ export function tabCheck() {
|
||||
stringField('modifiedUsername', '最后操作人', 100),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
visibleOn: "${state === 'COMPLETED'}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...detailDialog(),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'CONFIRMATION' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'CONFIRMATION' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -94,7 +43,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -102,14 +51,21 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'CONFIRMATION' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...confirmationDetailDialog('parameters.confirmationId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -121,7 +77,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -129,14 +85,21 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'WARE' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...authenticationDetailDialog('parameters.authenticationId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'MARKET' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -148,7 +111,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -156,12 +119,19 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'MARKET' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...wareDetailDialog('parameters.wareId'),
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<!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>
|
||||
@@ -1,133 +0,0 @@
|
||||
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"
|
||||
}
|
||||
})
|
||||
@@ -20,10 +20,6 @@
|
||||
<groupId>com.eshore</groupId>
|
||||
<artifactId>gringotts-forest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
@@ -32,6 +28,16 @@
|
||||
<groupId>com.blinkfox</groupId>
|
||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara.warm</groupId>
|
||||
<artifactId>warm-flow-jpa-sb-starter</artifactId>
|
||||
<version>1.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara.warm</groupId>
|
||||
<artifactId>warm-flow-plugin-ui-sb-web</artifactId>
|
||||
<version>1.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.blinkfox.fenix.EnableFenix;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.warm.flow.core.service.DefService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -22,13 +25,11 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-14
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {
|
||||
"com.eshore.gringotts",
|
||||
"com.lanyuanxiaoyao.flowable.jpa"
|
||||
})
|
||||
@Slf4j
|
||||
@SpringBootApplication(scanBasePackages = {"com.eshore.gringotts"})
|
||||
@EntityScan({
|
||||
"com.eshore.gringotts.web.domain.entity",
|
||||
"com.lanyuanxiaoyao.flowable.jpa.entity"
|
||||
"org.dromara.warm.flow.orm.entity"
|
||||
})
|
||||
@EnableFenix
|
||||
@EnableJpaAuditing
|
||||
@@ -47,10 +48,15 @@ public class WebApplication implements ApplicationRunner {
|
||||
SpringApplication.run(WebApplication.class, args);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private DefService defService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
// 初始化系统管理员
|
||||
userService.initial();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -30,6 +30,8 @@ public class SaTokenConfiguration implements WebMvcConfigurer {
|
||||
.notMatch("/pages/**")
|
||||
.notMatch("/user/**")
|
||||
.notMatch("/upload/download/**")
|
||||
.notMatch("/warm-flow-ui/**")
|
||||
.notMatch("/warm-flow/**")
|
||||
.check(r -> {
|
||||
try {
|
||||
StpUtil.checkLogin();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -13,8 +12,4 @@ 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,16 +1,13 @@
|
||||
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;
|
||||
@@ -24,7 +21,6 @@ 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}";
|
||||
|
||||
@@ -67,44 +63,6 @@ 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 {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -22,7 +26,9 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
private String flowableInstanceId;
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@ToString.Exclude
|
||||
private CheckOrder order;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 需要审查
|
||||
@@ -20,5 +22,7 @@ public abstract class CheckingService<ENTITY extends LogicDeleteEntity> extends
|
||||
|
||||
abstract public void retract(Long id) throws Exception;
|
||||
|
||||
abstract protected Object archive(ENTITY entity);
|
||||
abstract public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters);
|
||||
|
||||
abstract public ImmutableMap<String, Object> archive(ENTITY entity);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ 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
|
||||
@@ -22,10 +21,6 @@ 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,6 +2,7 @@ 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;
|
||||
@@ -11,10 +12,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;
|
||||
@@ -23,8 +24,6 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -100,6 +99,87 @@ 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)) {
|
||||
@@ -113,36 +193,13 @@ 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(QueryHelper.queryPredicates(listQuery.getQuery(), root, query, builder));
|
||||
predicates.addAllIterable(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,27 +1,20 @@
|
||||
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 com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.service.CheckOrderService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -39,112 +32,55 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("check_order")
|
||||
public class CheckOrderController implements ListController<CheckOrderController.ListItem> {
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public CheckOrderController(UserService userService, SpringFlowableManager flowableManager) {
|
||||
this.userService = userService;
|
||||
this.flowableManager = flowableManager;
|
||||
public CheckOrderController(CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<CheckOrderController.ListItem>> list() throws Exception {
|
||||
User user = userService.currentLoginUser();
|
||||
return AmisResponse.responseSuccess(
|
||||
Lists.immutable.ofAll(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())
|
||||
);
|
||||
}
|
||||
)).collect(this::toListItem)
|
||||
);
|
||||
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Override
|
||||
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);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/reject/{instanceId}")
|
||||
public AmisResponse<Object> reject(@PathVariable String instanceId) {
|
||||
flowableManager.reject(instanceId);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/history/{instanceId}")
|
||||
public AmisResponse<List<FlowableHistory>> history(@PathVariable String instanceId) {
|
||||
return AmisResponse.responseSuccess(flowableManager.listHistories(instanceId));
|
||||
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
|
||||
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private ListItem toListItem(FlowableInstance instance) {
|
||||
FlowableNode node = flowableManager.getNode(instance.getCurrentNodeId());
|
||||
private ListItem toListItem(CheckOrder order) {
|
||||
ListItem item = new ListItem();
|
||||
item.setInstanceId(instance.getInstanceId());
|
||||
item.setName(node.getName());
|
||||
item.setDescription(node.getDescription());
|
||||
item.setType(instance.getMetadata().getStringOrDefault("type", "unknown"));
|
||||
item.setParameters(Maps.immutable.ofAll(instance.getMetadata().getMetadata()));
|
||||
item.setState(instance.getStatus());
|
||||
item.setCreatedUsername(instance.getMetadata().getStringOrDefault("createdUsername", ""));
|
||||
item.setCreatedTime(instance.getCreatedTime());
|
||||
item.setModifiedUsername(instance.getMetadata().getStringOrDefault("modifiedUsername", ""));
|
||||
item.setModifiedTime(instance.getUpdatedTime());
|
||||
item.setCheckOrderId(order.getId());
|
||||
item.setDescription(order.getDescription());
|
||||
item.setType(order.getType());
|
||||
item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {}));
|
||||
item.setState(order.getState());
|
||||
item.setCreatedUsername(order.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(order.getCreatedTime());
|
||||
item.setModifiedUsername(order.getModifiedUser().getUsername());
|
||||
item.setModifiedTime(order.getModifiedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/operation/{id}/{operation}")
|
||||
public AmisResponse<Object> operation(@PathVariable Long id, @PathVariable CheckOrder.Operation operation) throws JsonProcessingException {
|
||||
log.info("id:{}, operation:{}", id, operation);
|
||||
checkOrderService.operation(id, operation);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class ListItem {
|
||||
private String instanceId;
|
||||
private String name;
|
||||
private Long checkOrderId;
|
||||
private String description;
|
||||
private String type;
|
||||
private CheckOrder.Type type;
|
||||
private ImmutableMap<String, Object> parameters;
|
||||
private FlowableInstance.Status state;
|
||||
private CheckOrder.State state;
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
@@ -87,7 +86,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={}", URLUtil.encodeAll(dataFile.getFilename())));
|
||||
response.setHeader("Content-Disposition", StrUtil.format("attachment; filename={}", dataFile.getFilename()));
|
||||
IoUtil.copy(new FileInputStream(targetFile), response.getOutputStream());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ 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;
|
||||
@@ -55,7 +54,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -83,7 +81,6 @@ 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());
|
||||
@@ -100,7 +97,6 @@ public class WareController extends CheckingController<Ware, WareController.Save
|
||||
private String description;
|
||||
private Long iconId;
|
||||
private String content;
|
||||
private ImmutableList<String> tags;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
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,13 +3,10 @@ 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;
|
||||
@@ -69,7 +66,4 @@ 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,28 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.flowable;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250106
|
||||
*/
|
||||
@Service
|
||||
public class CheckRoleAssessor implements FlowableAccessor {
|
||||
private final UserService userService;
|
||||
|
||||
public CheckRoleAssessor(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean access(FlowableInstance flowableInstance, FlowableNode flowableNode, FlowableAction flowableAction) {
|
||||
User.Role role = userService.currentLoginUser().getRole();
|
||||
return User.Role.ADMINISTRATOR.equals(role) || User.Role.CHECKER.equals(role);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.flowable;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250106
|
||||
*/
|
||||
@Service
|
||||
public class UserAssessor implements FlowableAccessor {
|
||||
public static final String KEY = "user_access_key";
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserAssessor(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean access(FlowableInstance flowableInstance, FlowableNode flowableNode, FlowableAction flowableAction) {
|
||||
FlowableMetadata metadata = flowableInstance.getMetadata();
|
||||
return NumberUtil.equals(userService.currentLoginUser().getId(), metadata.getLong(KEY));
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Authentication;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -30,14 +27,4 @@ public interface AuthenticationRepository extends SimpleRepository<Authenticatio
|
||||
@Override
|
||||
@EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Authentication> findOne(Specification<Authentication> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Authentication confirmation set confirmation.state = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateStateById(Long id, Authentication.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Authentication confirmation set confirmation.flowableInstanceId = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Confirmation;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -31,15 +28,5 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
|
||||
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Confirmation> findOne(Specification<Confirmation> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation set confirmation.state = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateStateById(Long id, Confirmation.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation set confirmation.flowableInstanceId = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
|
||||
Boolean existsByTarget_Id(Long targetId);
|
||||
Boolean existsByTarget_Id(Long id);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||
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;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@@ -26,14 +23,4 @@ public interface WareRepository extends SimpleRepository<Ware, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "ware.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Ware> findOne(Specification<Ware> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Ware ware set ware.state = ?2 where ware.id = ?1 and ware.deleted = false")
|
||||
void updateStateById(Long id, Ware.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Ware ware set ware.flowableInstanceId = ?2 where ware.id = ?1 and ware.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
}
|
||||
@@ -1,26 +1,29 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.entity.Authentication;
|
||||
import com.eshore.gringotts.web.domain.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.entity.Authentication_;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.flowable.CheckRoleAssessor;
|
||||
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
||||
import com.eshore.gringotts.web.domain.repository.AuthenticationRepository;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -28,38 +31,38 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2024-12-02
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("com.eshore.gringotts.web.domain.service.AuthenticationService")
|
||||
public class AuthenticationService extends CheckingService<Authentication> {
|
||||
private static final String AUTHENTICATION_FLOW_ID = "4ba86acd-1420-450b-98f9-0ed41772fe53";
|
||||
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, SpringFlowableManager flowableManager) {
|
||||
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(repository, userService, manager);
|
||||
this.authenticationRepository = repository;
|
||||
this.userService = userService;
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode userCheckNode = FlowableNode.builder()
|
||||
.nodeId(AUTHENTICATION_FLOW_ID)
|
||||
.name("用户审查")
|
||||
.description("用户审查")
|
||||
.listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowUserCheckListener.class.getName()))
|
||||
.accessor(UserAssessor.class.getName())
|
||||
.targets(Maps.mutable.of(
|
||||
FlowableAction.APPROVE, "f087b0e4-0efa-4b26-945f-642436aa4aef"
|
||||
))
|
||||
.build();
|
||||
FlowableNode roleCheckNode = FlowableNode.builder()
|
||||
.nodeId("f087b0e4-0efa-4b26-945f-642436aa4aef")
|
||||
.name("授权审查")
|
||||
.description("授权审查")
|
||||
.listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowRoleCheckListener.class.getName()))
|
||||
.accessor(CheckRoleAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(userCheckNode, roleCheckNode);
|
||||
@Override
|
||||
protected ImmutableList<Predicate> listPredicate(Root<Authentication> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
User loginUser = userService.currentLoginUser();
|
||||
if (User.isAdministrator(loginUser)) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
return Lists.immutable.of(builder.or(
|
||||
builder.equal(root.get(Authentication_.createdUser), loginUser),
|
||||
builder.and(
|
||||
builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.ROLE),
|
||||
builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetRole), loginUser.getRole())
|
||||
),
|
||||
builder.and(
|
||||
builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.USER),
|
||||
builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetUser), loginUser)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,34 +82,73 @@ public class AuthenticationService extends CheckingService<Authentication> {
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
User user = userService.currentLoginUser();
|
||||
public void submit(Long id) throws JsonProcessingException {
|
||||
Authentication authentication = detailOrThrow(id);
|
||||
String instanceId = flowableManager.start(
|
||||
AUTHENTICATION_FLOW_ID,
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("authenticationId", id)
|
||||
.put("type", "AUTHENTICATION")
|
||||
.put("createdUsername", user.getUsername())
|
||||
.put("modifiedUsername", user.getUsername())
|
||||
.put(UserAssessor.KEY, authentication.getTarget().getCreatedUser().getId())
|
||||
.build(),
|
||||
authentication.getTarget().getCreatedUser().getId().toString()
|
||||
);
|
||||
authenticationRepository.updateInstanceIdById(id, instanceId);
|
||||
authenticationRepository.updateStateById(id, Confirmation.State.CHECKING);
|
||||
authentication.setState(CheckingNeededEntity.State.OWNER_CHECKING);
|
||||
Long orderId = checkOrderService.save(new CheckOrder(
|
||||
"authentication_owner_check",
|
||||
StrUtil.format("数据资源「{}」的授权申请", authentication.getTarget().getName()),
|
||||
CheckOrder.Type.AUTHENTICATION,
|
||||
mapper.writeValueAsString(Maps.immutable.of("authenticationId", authentication.getId())),
|
||||
"com.eshore.gringotts.web.domain.service.AuthenticationService",
|
||||
authentication.getCreatedUser()
|
||||
));
|
||||
CheckOrder order = checkOrderService.detailOrThrow(orderId);
|
||||
authentication.setOrder(order);
|
||||
save(authentication);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void retract(Long id) {
|
||||
Authentication authentication = detailOrThrow(id);
|
||||
flowableManager.terminal(authentication.getFlowableInstanceId());
|
||||
authentication.setState(Authentication.State.DRAFT);
|
||||
save(authentication);
|
||||
|
||||
CheckOrder order = authentication.getOrder();
|
||||
order.setState(CheckOrder.State.RETRACT);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object archive(Authentication entity) {
|
||||
return "";
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
|
||||
Long id = (Long) parameters.get("authenticationId");
|
||||
Authentication authentication = detailOrThrow(id);
|
||||
if (StrUtil.equals(order.getKeyword(), "authentication_owner_check")) {
|
||||
switch (operation) {
|
||||
case APPLY:
|
||||
authentication.setState(Authentication.State.CHECKING);
|
||||
order.setKeyword("authentication_checker_check");
|
||||
order.setTarget(CheckOrder.Target.ROLE);
|
||||
order.setTargetRole(User.Role.CHECKER);
|
||||
break;
|
||||
case REJECT:
|
||||
authentication.setState(Authentication.State.DRAFT);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
}
|
||||
} else if (StrUtil.equals(order.getKeyword(), "authentication_checker_check")) {
|
||||
switch (operation) {
|
||||
case APPLY:
|
||||
authentication.setState(Authentication.State.NORMAL);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
case REJECT:
|
||||
authentication.setState(Authentication.State.DRAFT);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
save(authentication);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, Object> archive(Authentication authentication) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class AuthenticationDuplicatedException extends RuntimeException {
|
||||
@@ -114,44 +156,4 @@ public class AuthenticationService extends CheckingService<Authentication> {
|
||||
super("数据资源已绑定该账号的授权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class AuthenticationFlowUserCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
|
||||
public AuthenticationFlowUserCheckListener(AuthenticationRepository authenticationRepository) {
|
||||
this.authenticationRepository = authenticationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long authenticationId = metadata.getLong("authenticationId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
instance.setExtra(User.Role.CHECKER.name());
|
||||
} else {
|
||||
authenticationRepository.updateStateById(authenticationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class AuthenticationFlowRoleCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
|
||||
public AuthenticationFlowRoleCheckListener(AuthenticationRepository authenticationRepository) {
|
||||
this.authenticationRepository = authenticationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long authenticationId = metadata.getLong("authenticationId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
authenticationRepository.updateStateById(authenticationId, CheckingNeededEntity.State.NORMAL);
|
||||
} else {
|
||||
authenticationRepository.updateStateById(authenticationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.repository.CheckOrderRepository;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ObjectMapper mapper;
|
||||
private final CheckOrderRepository checkOrderRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public CheckOrderService(CheckOrderRepository repository, UserService userService, ApplicationContext applicationContext, Jackson2ObjectMapperBuilder builder) {
|
||||
super(repository, userService);
|
||||
this.applicationContext = applicationContext;
|
||||
this.mapper = builder.build();
|
||||
this.checkOrderRepository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableList<Predicate> listPredicate(Root<CheckOrder> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isAdministrator(user)) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
return Lists.immutable.of(builder.or(
|
||||
builder.equal(root.get(CheckOrder_.createdUser), user),
|
||||
builder.and(
|
||||
builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.USER),
|
||||
builder.equal(root.get(CheckOrder_.targetUser), user)
|
||||
),
|
||||
builder.and(
|
||||
builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.ROLE),
|
||||
builder.equal(root.get(CheckOrder_.targetRole), user.getRole())
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public void operation(Long id, CheckOrder.Operation operation) throws JsonProcessingException {
|
||||
CheckOrder order = detailOrThrow(id);
|
||||
CheckingService service = applicationContext.getBean(order.getTargetClass(), CheckingService.class);
|
||||
if (ObjectUtil.isNull(service)) {
|
||||
throw new RuntimeException(StrUtil.format("名为「{}」的服务未找到", order.getTargetClass()));
|
||||
}
|
||||
ImmutableMap<String, Object> parameters = mapper.readValue(order.getParameters(), new TypeReference<>() {});
|
||||
service.onChecked(order, operation, parameters);
|
||||
}
|
||||
|
||||
public void retract(Long id) {
|
||||
checkOrderRepository.overById(id, CheckOrder.State.RETRACT, userService.currentLoginUser());
|
||||
}
|
||||
|
||||
public void over(Long id) {
|
||||
checkOrderRepository.overById(id, CheckOrder.State.OVER, userService.currentLoginUser());
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,31 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
|
||||
import com.eshore.gringotts.web.domain.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.entity.Confirmation_;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.flowable.CheckRoleAssessor;
|
||||
import com.eshore.gringotts.web.domain.repository.ConfirmationRepository;
|
||||
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;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -26,69 +33,42 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("com.eshore.gringotts.web.domain.service.ConfirmationService")
|
||||
public class ConfirmationService extends CheckingService<Confirmation> {
|
||||
private static final String CONFIRMATION_FLOW_ID = "69d8ded5-35fd-4f03-b11a-be0ed91a4b8b";
|
||||
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
|
||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(confirmationRepository, userService, entityManager);
|
||||
this.confirmationRepository = confirmationRepository;
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode node = FlowableNode.builder()
|
||||
.nodeId(CONFIRMATION_FLOW_ID)
|
||||
.name("确权审查")
|
||||
.description("确权审查")
|
||||
.listeners(Lists.mutable.of(ConfirmationService.ConfirmationFlowRoleCheckListener.class.getName()))
|
||||
.accessor(CheckRoleAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(node);
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
User user = userService.currentLoginUser();
|
||||
String instanceId = flowableManager.start(
|
||||
CONFIRMATION_FLOW_ID,
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("confirmationId", id)
|
||||
.put("type", "CONFIRMATION")
|
||||
.put("snapshot", archive(confirmation))
|
||||
.put("createdUsername", user.getUsername())
|
||||
.put("modifiedUsername", user.getUsername())
|
||||
.build(),
|
||||
User.Role.CHECKER.name()
|
||||
);
|
||||
confirmationRepository.updateInstanceIdById(id, instanceId);
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.CHECKING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retract(Long id) {
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
flowableManager.terminal(confirmation.getFlowableInstanceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object archive(Confirmation entity) {
|
||||
DataResource resource = entity.getTarget();
|
||||
return AmisHelper.wrapper(
|
||||
AmisHelper.property(resource),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(entity),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(resource.getExample()),
|
||||
AmisHelper.divider(),
|
||||
AmisHelper.property(
|
||||
"确权申请信息",
|
||||
AmisHelper.propertyItem("描述", entity.getDescription()),
|
||||
AmisHelper.propertyItem(entity.getEvidences())
|
||||
protected ImmutableList<Predicate> listPredicate(Root<Confirmation> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
User loginUser = userService.currentLoginUser();
|
||||
if (User.isAdministrator(loginUser)) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
Join<Confirmation, CheckOrder> orderJoin = root.join(Confirmation_.order, JoinType.LEFT);
|
||||
return Lists.immutable.of(builder.or(
|
||||
builder.equal(root.get(Confirmation_.createdUser), loginUser),
|
||||
builder.and(
|
||||
builder.isNotNull(orderJoin),
|
||||
builder.or(
|
||||
builder.and(
|
||||
builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.ROLE),
|
||||
builder.equal(orderJoin.get(CheckOrder_.targetRole), loginUser.getRole())
|
||||
),
|
||||
builder.and(
|
||||
builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.USER),
|
||||
builder.equal(orderJoin.get(CheckOrder_.targetUser), loginUser)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,29 +79,65 @@ public class ConfirmationService extends CheckingService<Confirmation> {
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void submit(Long id) throws JsonProcessingException {
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
confirmation.setState(Confirmation.State.CHECKING);
|
||||
Long orderId = checkOrderService.save(new CheckOrder(
|
||||
"confirmation_check",
|
||||
StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()),
|
||||
CheckOrder.Type.CONFIRMATION,
|
||||
mapper.writeValueAsString(Maps.immutable.of("confirmationId", confirmation.getId())),
|
||||
"com.eshore.gringotts.web.domain.service.ConfirmationService",
|
||||
User.Role.CHECKER
|
||||
));
|
||||
CheckOrder order = checkOrderService.detailOrThrow(orderId);
|
||||
confirmation.setOrder(order);
|
||||
save(confirmation);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void retract(Long id) {
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
confirmation.setState(CheckingNeededEntity.State.DRAFT);
|
||||
save(confirmation);
|
||||
|
||||
CheckOrder order = confirmation.getOrder();
|
||||
order.setState(CheckOrder.State.RETRACT);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
|
||||
if (StrUtil.equals(order.getKeyword(), "confirmation_check")) {
|
||||
Long id = (Long) parameters.get("confirmationId");
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
switch (operation) {
|
||||
case APPLY:
|
||||
confirmation.setState(Confirmation.State.NORMAL);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
case REJECT:
|
||||
confirmation.setState(Confirmation.State.DRAFT);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
}
|
||||
save(confirmation);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, Object> archive(Confirmation confirmation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class ConfirmationDuplicatedException extends RuntimeException {
|
||||
public ConfirmationDuplicatedException() {
|
||||
super("数据资源已绑定确权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class ConfirmationFlowRoleCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
|
||||
public ConfirmationFlowRoleCheckListener(ConfirmationRepository confirmationRepository) {
|
||||
this.confirmationRepository = confirmationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long confirmationId = metadata.getLong("confirmationId");
|
||||
if (action == FlowableAction.APPROVE) {
|
||||
confirmationRepository.updateStateById(confirmationId, Confirmation.State.NORMAL);
|
||||
} else {
|
||||
confirmationRepository.updateStateById(confirmationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.eshore.gringotts.web.domain.entity.type.ResourceType;
|
||||
import com.eshore.gringotts.web.domain.repository.DataResourceRepository;
|
||||
import com.eshore.gringotts.web.domain.repository.ResourceFormatRepository;
|
||||
import com.eshore.gringotts.web.domain.repository.ResourceTypeRepository;
|
||||
import com.eshore.gringotts.web.helper.EntityHelper;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
@@ -55,8 +56,26 @@ public class DataResourceService extends LogicDeleteService<DataResource> {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
|
||||
Subquery<Confirmation> confirmationSubquery = query.subquery(Confirmation.class);
|
||||
Root<Confirmation> confirmationRoot = confirmationSubquery.from(Confirmation.class);
|
||||
confirmationSubquery.select(confirmationRoot)
|
||||
.where(
|
||||
builder.equal(confirmationRoot.get(Confirmation_.target), root),
|
||||
EntityHelper.checkNeededEntityPrediction(confirmationRoot, builder, loginUser)
|
||||
);
|
||||
|
||||
Subquery<Authentication> authenticationSubquery = query.subquery(Authentication.class);
|
||||
Root<Authentication> authenticationRoot = authenticationSubquery.from(Authentication.class);
|
||||
authenticationSubquery.select(authenticationRoot)
|
||||
.where(
|
||||
builder.equal(authenticationRoot.get(Authentication_.target), root),
|
||||
EntityHelper.checkNeededEntityPrediction(authenticationRoot, builder, loginUser)
|
||||
);
|
||||
|
||||
return Lists.immutable.of(builder.or(
|
||||
builder.equal(root.get(DataResource_.createdUser), loginUser)
|
||||
builder.equal(root.get(DataResource_.createdUser), loginUser),
|
||||
builder.exists(confirmationSubquery),
|
||||
builder.exists(authenticationSubquery)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
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;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.persistence.EntityManager;
|
||||
import lombok.SneakyThrows;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -27,28 +23,17 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2024-12-13
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("com.eshore.gringotts.web.domain.service.WareService")
|
||||
public class WareService extends CheckingService<Ware> {
|
||||
private static final String WARE_FLOW_ID = "870e7376-1713-48ed-9e60-e602981c6ecc";
|
||||
|
||||
private final WareRepository wareRepository;
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public WareService(WareRepository repository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
|
||||
public WareService(WareRepository repository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(repository, userService, entityManager);
|
||||
this.wareRepository = repository;
|
||||
this.userService = userService;
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode node = FlowableNode.builder()
|
||||
.nodeId(WARE_FLOW_ID)
|
||||
.name("上架审查")
|
||||
.description("上架审查")
|
||||
.listeners(Lists.mutable.of(WareService.WareFlowUserCheckListener.class.getName()))
|
||||
.accessor(UserAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(node);
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<Ware> listPublic() {
|
||||
@@ -57,71 +42,59 @@ public class WareService extends CheckingService<Ware> {
|
||||
);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
User user = userService.currentLoginUser();
|
||||
Ware ware = detailOrThrow(id);
|
||||
String instanceId = flowableManager.start(
|
||||
WARE_FLOW_ID,
|
||||
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())
|
||||
.build(),
|
||||
ware.getResource().getCreatedUser().getId().toString()
|
||||
);
|
||||
wareRepository.updateInstanceIdById(id, instanceId);
|
||||
wareRepository.updateStateById(id, Ware.State.CHECKING);
|
||||
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
|
||||
if (StrUtil.equals(order.getKeyword(), "ware_check")) {
|
||||
Long wareId = (Long) parameters.get("wareId");
|
||||
Ware ware = detailOrThrow(wareId);
|
||||
switch (operation) {
|
||||
case APPLY:
|
||||
ware.setState(Ware.State.NORMAL);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
case REJECT:
|
||||
ware.setState(Ware.State.DRAFT);
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
}
|
||||
save(ware);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, Object> archive(Ware ware) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void submit(Long id) throws JsonProcessingException {
|
||||
Ware ware = detailOrThrow(id);
|
||||
ware.setState(Ware.State.CHECKING);
|
||||
Long orderId = checkOrderService.save(new CheckOrder(
|
||||
"ware_check",
|
||||
StrUtil.format("数据资源「{}」的上架申请", ware.getName()),
|
||||
CheckOrder.Type.MARKET,
|
||||
mapper.writeValueAsString(Maps.immutable.of("wareId", ware.getId())),
|
||||
"com.eshore.gringotts.web.domain.service.WareService",
|
||||
User.Role.CHECKER
|
||||
));
|
||||
CheckOrder order = checkOrderService.detailOrThrow(orderId);
|
||||
ware.setOrder(order);
|
||||
save(ware);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void retract(Long id) {
|
||||
Ware ware = detailOrThrow(id);
|
||||
flowableManager.terminal(ware.getFlowableInstanceId());
|
||||
}
|
||||
ware.setState(Ware.State.DRAFT);
|
||||
save(ware);
|
||||
|
||||
@Override
|
||||
protected Object archive(Ware entity) {
|
||||
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
|
||||
public static final class WareFlowUserCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final WareRepository wareRepository;
|
||||
|
||||
public WareFlowUserCheckListener(WareRepository wareRepository) {
|
||||
this.wareRepository = wareRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long wareId = metadata.getLong("wareId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
wareRepository.updateStateById(wareId, Ware.State.NORMAL);
|
||||
} else {
|
||||
wareRepository.updateStateById(wareId, Ware.State.DRAFT);
|
||||
}
|
||||
}
|
||||
CheckOrder order = ware.getOrder();
|
||||
order.setState(CheckOrder.State.RETRACT);
|
||||
checkOrderService.save(order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,250 +0,0 @@
|
||||
package com.eshore.gringotts.web.helper;
|
||||
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.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 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.list.MutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250108
|
||||
*/
|
||||
public class AmisHelper {
|
||||
@SafeVarargs
|
||||
public static ImmutableMap<Object, Object> wrapper(ImmutableMap<Object, Object>... body) {
|
||||
MapBuilder<Object, Object> builder = MapUtil.builder();
|
||||
builder.put("type", "wrapper");
|
||||
builder.put("size", "none");
|
||||
builder.put("body", body);
|
||||
return Maps.immutable.ofMap(builder.build());
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> divider() {
|
||||
return Maps.immutable.of("type", "divider");
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ImmutableMap<Object, Object> property(ImmutableMap<Object, Object>... items) {
|
||||
return property(null, items);
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> property(ImmutableList<ImmutableMap<Object, Object>> items) {
|
||||
return property(null, items);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ImmutableMap<Object, Object> property(String title, ImmutableMap<Object, Object>... items) {
|
||||
return property(title, Lists.immutable.of(items));
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> property(String title, ImmutableList<ImmutableMap<Object, Object>> items) {
|
||||
MapBuilder<Object, Object> builder = MapUtil.builder();
|
||||
builder.put("type", "property");
|
||||
if (StrUtil.isNotBlank(title)) {
|
||||
builder.put("title", title);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(items)) {
|
||||
builder.put("items", items);
|
||||
}
|
||||
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) {
|
||||
type = Hibernate.unproxy(type, ResourceType.class);
|
||||
MutableList<ImmutableMap<Object, Object>> items = Lists.mutable.empty();
|
||||
switch (type.getResourceType()) {
|
||||
case API:
|
||||
ApiResourceType apiResourceType = (ApiResourceType) type;
|
||||
items.add(propertyItem("资源类型", "API", 3));
|
||||
items.add(propertyItem("用户名", apiResourceType.getUsername(), 1));
|
||||
items.add(propertyItem("密码", apiResourceType.getPassword(), 2));
|
||||
items.add(propertyItem("地址", apiResourceType.getUrl(), 3));
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileResourceType = (FileResourceType) type;
|
||||
items.add(propertyItem("资源类型", "文件", 3));
|
||||
items.add(propertyItem(fileResourceType.getFile()));
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseResourceType = (DatabaseResourceType) type;
|
||||
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;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsResourceType = (HDFSResourceType) type;
|
||||
items.add(propertyItem("资源类型", "HDFS"));
|
||||
items.add(propertyItem("core-site", hdfsResourceType.getCoreSite()));
|
||||
items.add(propertyItem("hdfs-site", hdfsResourceType.getHdfsSite()));
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpResourceType = (FtpResourceType) type;
|
||||
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;
|
||||
}
|
||||
return property("资源类型定义", items.toImmutable());
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> property(ResourceFormat format) {
|
||||
format = Hibernate.unproxy(format, ResourceFormat.class);
|
||||
MutableList<ImmutableMap<Object, Object>> items = Lists.mutable.empty();
|
||||
switch (format.getFormatType()) {
|
||||
case NONE:
|
||||
items.add(propertyItem("格式类型", "文件", 3));
|
||||
break;
|
||||
case LINE:
|
||||
items.add(propertyItem("格式类型", "文本行", 3));
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonResourceFormat = (JsonResourceFormat) format;
|
||||
items.add(propertyItem("格式类型", "Json", 3));
|
||||
items.add(propertyItem("格式详情", editor("json", jsonResourceFormat.getJsonSchema()), 3));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineResourceFormat = (JsonLineResourceFormat) format;
|
||||
items.add(propertyItem("格式类型", "Json Line", 3));
|
||||
items.add(propertyItem("格式详情", editor("json", jsonLineResourceFormat.getJsonSchema()), 3));
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvResourceFormat = (CsvResourceFormat) format;
|
||||
items.add(propertyItem("格式类型", "CSV文本", 3));
|
||||
items.add(propertyItem("格式详情", editor("json", csvResourceFormat.getCsvSchema()), 3));
|
||||
break;
|
||||
}
|
||||
return property("资源格式定义", items.toImmutable());
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> property(SimpleEntity entity) {
|
||||
return property(
|
||||
propertyItem("创建人", entity.getCreatedUser().getUsername(), 2),
|
||||
propertyItem("创建时间", entity.getCreatedTime()),
|
||||
propertyItem("修改人", entity.getModifiedUser().getUsername(), 2),
|
||||
propertyItem("修改时间", entity.getModifiedTime())
|
||||
);
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> property(DataFile dataFile) {
|
||||
return property(
|
||||
propertyItem("资源示例", dataFile)
|
||||
);
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> propertyItem(String label, Object content) {
|
||||
return propertyItem(label, content, null);
|
||||
}
|
||||
|
||||
public static ImmutableMap<Object, Object> propertyItem(String label, Object content, Integer span) {
|
||||
MapBuilder<Object, Object> builder = MapUtil.builder();
|
||||
builder.put("label", label);
|
||||
builder.put("content", content);
|
||||
if (ObjectUtil.isNotNull(span)) {
|
||||
builder.put("span", span);
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@ package com.eshore.gringotts.web.helper;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity_;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import java.util.function.Supplier;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
@@ -25,14 +28,14 @@ public class EntityHelper {
|
||||
|
||||
public static Predicate checkNeededEntityPrediction(Root<? extends CheckingNeededEntity> root, CriteriaBuilder builder, User loginUser) {
|
||||
return builder.or(
|
||||
/* builder.and(
|
||||
builder.and(
|
||||
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.ROLE),
|
||||
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetRole), loginUser.getRole())
|
||||
),
|
||||
builder.and(
|
||||
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.USER),
|
||||
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetUser), loginUser)
|
||||
) */
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,8 @@ logging:
|
||||
sdk:
|
||||
eventsub:
|
||||
EventSubscribeImp: error
|
||||
warm-flow:
|
||||
jpa_persistence_provider: org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider
|
||||
|
||||
---
|
||||
spring:
|
||||
|
||||
7
pom.xml
7
pom.xml
@@ -60,13 +60,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Private Dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user