Skip to content

Dev #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 8, 2025
Merged

Dev #87

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions admin-ui/src/api/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {FormInstance} from "antd/es/form/hooks/useForm";
import {NamePath} from "rc-field-form/es/interface";

// 流程表单API 提供get post的能力
export interface FlowFormApi {
get: (url: string, params?: any) => Promise<any>;
post: (url: string, data: any) => Promise<any>;
}

// 流程表单验证内容
export class FlowFormValidateContent {
readonly value: any;
readonly form: FormInstance;
readonly api?: FlowFormApi

constructor(value: any, form: FormInstance, api?: FlowFormApi) {
this.value = value;
this.form = form;
this.api = api;
}
}

// 自定义验证
export interface FlowFormCustomValidate {
name: NamePath;
validate: (content: FlowFormValidateContent) => Promise<string[]>;
}

// 流程表单API上下文
export class FlowFormApiContext {

private static readonly instance: FlowFormApiContext = new FlowFormApiContext();

private api: FlowFormApi | undefined;

private constructor() {
this.api = undefined;
}

public static getInstance() {
return FlowFormApiContext.instance;
}

public setApi(api: FlowFormApi) {
this.api = api;
}

public getApi() {
return this.api;
}
}

// 自定义验证上下文
export class FlowFormCustomValidateContext {

private readonly map: Map<NamePath, FlowFormCustomValidate>;

constructor() {
this.map = new Map();
}

public addValidate(validate: FlowFormCustomValidate) {
this.map.set(validate.name, validate);
}

public addCustomFunctionCodeValidate(namePath:NamePath,validateFuncCode:string){
const validateFunc = new Function('content', validateFuncCode);
this.addValidate({
name: namePath,
validate: async (content) => {
return validateFunc(content);
}
});
}

public validate(form: FormInstance) {
this.map.values().forEach((validate) => {
const value = form.getFieldValue(validate.name);
const content = new FlowFormValidateContent(value, form, FlowFormApiContext.getInstance().getApi());
validate.validate(content).then((res) => {
form.setFields(
[
{
name: validate.name,
errors: res,
}
]
)
}).catch((error) => {
form.setFields(
[
{
name: validate.name,
errors: [error],
}
]
)
});
});
}
}


4 changes: 4 additions & 0 deletions admin-ui/src/components/Flow/flow/FlowButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const FlowButtons: React.FC<FlowButtonsProps> = (props) => {
return null;
}

if(flowData.hasData() && !flowData.canHandle()){
return null;
}

const buttons = flowData.getNodeButtons();

return (
Expand Down
68 changes: 47 additions & 21 deletions admin-ui/src/pages/welcome/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
import React from 'react';
import logo from '@/assets/logo.svg';
import './index.scss';
import {useSelector} from "react-redux";
import {RootState} from "@/store/Redux";
import RoleControl from "@/utils/RoleControl";
import Page from "@/components/Layout/Page";
import {Button, Form, Input} from "antd";
import {FlowFormApiContext, FlowFormCustomValidateContext} from "@/api/validate";
import * as api from "@/api"

FlowFormApiContext.getInstance().setApi({
get: (url: string, params?: any) => {
return api.get(url, params);
},
post: (url: string, data: any) => {
return api.post(url, data);
}
});

const Index = () => {

const counter = useSelector((state: RootState) => state.counter.value);
const username = localStorage.getItem('username');
const [form] = Form.useForm();

const context = new FlowFormCustomValidateContext();

const validateFuncCode = `
if (content.value) {
return [];
} else {
return ["姓名不存在"];
}
`;
context.addCustomFunctionCodeValidate(["user", "name"], validateFuncCode);

return (
<Page enablePageContainer={true}>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo"/>
<p>
hi {username} , Redux counter: {counter}, Roles: {RoleControl.roles().map(item => (
<label
key={item}
style={{
margin: '0 5px',
padding: '5px',
}}>{item}</label>
))}
</p>
</header>
</div>

<Form
form={form}
>

<Form.Item
name={["user", "name"]}
label={"姓名"}
>
<Input/>
</Form.Item>
</Form>

<Button onClick={() => {
form.validateFields().then(res => {
console.log(res);
})
}}>test1</Button>

<Button onClick={() => {
context.validate(form);
}}>test2</Button>

</Page>
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/example-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</parent>

<artifactId>springboot-example</artifactId>
<version>3.3.51</version>
<version>3.3.55</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.3.51</version>
<version>3.3.55</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>

<artifactId>springboot-starter-data-authorization</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public boolean beforeHandler(String sql) {

@Override
public void afterHandler(String sql, String newSql, SQLException exception) {
if(exception!=null){
log.error("sql:{}",sql);
log.error("newSql:{}",newSql);
log.error(exception.getMessage(),exception);
}
if (DataAuthorizationPropertyContext.getInstance().showSql()) {
log.info("newSql:{}", newSql);
}
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>

<name>springboot-starter-flow</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ public MessageResult rejectFlow() {
}

/**
* 是否为驳回状态
*
* @return 是否为驳回状态
* 上级节点的状态是驳回状态
* @return 上级节点的状态是驳回状态
*/
public boolean isRejectState() {
public boolean backStateIsReject() {
if (flowRecord == null) {
return false;
}
long preId = flowRecord.getPreId();
if (preId == 0) {
return false;
Expand All @@ -201,6 +203,26 @@ public boolean isRejectState() {
return false;
}

/**
* 上级节点的状态是驳回状态
*
* @see #backStateIsReject()
*/
@Deprecated
public boolean isRejectState() {
return this.backStateIsReject();
}

/**
* 当前节点的状态是驳回状态
*/
public boolean currentStateIsReject() {
if (flowRecord != null) {
return flowRecord.getFlowSourceDirection() == FlowSourceDirection.REJECT;
}
return false;
}


/**
* 预提交流程
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ private List<FlowRecord> createNextRecord() {
if (customOperatorIds != null && !customOperatorIds.isEmpty()) {
operators = operators.stream()
.filter(operator -> customOperatorIds.contains(operator.getUserId())).toList();
if (operators.size() != customOperatorIds.size()) {
throw new IllegalArgumentException("operator not match.");
}
}
List<FlowRecord> recordList;
if (operators.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private FlowResult submitCurrentFlow() {
this.saveFlowRecord(flowRecord);
this.updateFinishFlowRecord();

this.pushEvent(flowRecord, FlowApprovalEvent.STATE_CREATE);
this.pushEvent(flowRecord, FlowApprovalEvent.STATE_FINISH);

if (!nextRecords.isEmpty()) {
return new FlowResult(flowWork, nextRecords.get(0));
Expand Down Expand Up @@ -369,6 +369,11 @@ public FlowSubmitResult trySubmitFlow() {

this.loadNextNode(historyRecords);

while (nextNode.isCirculate()){
flowNodeService.skipCirculate();
this.nextNode = flowNodeService.getNextNode();
}

List<? extends IFlowOperator> operators = flowNodeService.loadNextNodeOperators();
return new FlowSubmitResult(flowWork, nextNode, operators);
}
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>

<artifactId>springboot-starter-security</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.3.51</version>
<version>3.3.55</version>
</parent>
<artifactId>springboot-starter</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
------------------------------------------------------
CodingApi SpringBoot-Starter 3.3.51
CodingApi SpringBoot-Starter 3.3.55
springboot version (${spring-boot.version})
------------------------------------------------------