Skip to content

Commit 766f841

Browse files
committed
add ui
1 parent fd33efd commit 766f841

24 files changed

Lines changed: 240 additions & 52 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.codingapi.example.security;
2+
3+
import com.codingapi.example.entity.User;
4+
import com.codingapi.example.repository.UserRepository;
5+
import com.codingapi.springboot.framework.user.UserContext;
6+
import com.codingapi.springboot.security.filter.AuthenticationTokenFilter;
7+
import com.codingapi.springboot.security.gateway.TokenContext;
8+
import jakarta.servlet.ServletException;
9+
import jakarta.servlet.http.HttpServletRequest;
10+
import jakarta.servlet.http.HttpServletResponse;
11+
import lombok.AllArgsConstructor;
12+
import org.springframework.stereotype.Component;
13+
import org.springframework.util.StringUtils;
14+
15+
import java.io.IOException;
16+
17+
@Component
18+
@AllArgsConstructor
19+
public class MyAuthenticationTokenFilter implements AuthenticationTokenFilter {
20+
21+
private final UserRepository userRepository;
22+
23+
@Override
24+
public void doFilter(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
25+
String userId = TokenContext.current().getExtra();
26+
if (StringUtils.hasText(userId)) {
27+
User user = userRepository.getUserById(Long.parseLong(userId));
28+
UserContext.getInstance().setCurrent(user);
29+
}
30+
}
31+
}

flow-engine-example/src/main/java/com/codingapi/example/security/UserDetailServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.example.entity.User;
44
import com.codingapi.example.repository.UserRepository;
5+
import com.codingapi.springboot.security.gateway.TokenContext;
56
import lombok.AllArgsConstructor;
67
import org.springframework.security.core.authority.SimpleGrantedAuthority;
78
import org.springframework.security.core.userdetails.UserDetails;
@@ -22,6 +23,8 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
2223
throw new UsernameNotFoundException("can't fond username " + username + " account");
2324
}
2425

26+
TokenContext.pushExtra(String.valueOf(user.getUserId()));
27+
2528
return org.springframework.security.core.userdetails.User.builder()
2629
.username(user.getAccount())
2730
.password(user.getPassword())

flow-engine-framework/src/main/java/com/codingapi/flow/operator/IFlowOperator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.codingapi.flow.operator;
22

3+
import com.codingapi.springboot.framework.user.IUser;
4+
35
/**
46
* 流程参与用户
57
*/
6-
public interface IFlowOperator {
8+
public interface IFlowOperator extends IUser {
79

810
/**
911
* 获取用户ID

flow-engine-framework/src/main/java/com/codingapi/flow/workflow/Workflow.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ public String toJson(boolean hasSchema) {
162162
map.put("id", id);
163163
map.put("code", code);
164164
map.put("title", title);
165-
map.put("createdOperator", String.valueOf(createdOperator.getUserId()));
166-
map.put("form", form.toMap());
165+
if(createdOperator!=null) {
166+
map.put("createdOperator", String.valueOf(createdOperator.getUserId()));
167+
}
168+
if(form!=null) {
169+
map.put("form", form.toMap());
170+
}
167171
map.put("operatorCreateScript", operatorCreateScript.getScript());
168172
map.put("nodes", nodes.stream().map(IFlowNode::toMap).toList());
169173
map.put("edges", edges);

flow-engine-framework/src/main/java/com/codingapi/flow/workflow/WorkflowBuilder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ public WorkflowBuilder edges(List<FlowEdge> edges) {
8787
return this;
8888
}
8989

90-
public Workflow build() {
91-
workflow.verify();
90+
public Workflow build(boolean verify) {
91+
if(verify) {
92+
workflow.verify();
93+
}
9294
return workflow;
9395
}
9496

97+
public Workflow build() {
98+
return this.build(true);
99+
}
100+
95101
}
Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.codingapi.flow.api.controller;
22

3+
import com.alibaba.fastjson.JSONObject;
4+
import com.codingapi.flow.operator.IFlowOperator;
35
import com.codingapi.flow.repository.WorkflowRepository;
46
import com.codingapi.flow.workflow.Workflow;
57
import com.codingapi.flow.workflow.WorkflowBuilder;
8+
import com.codingapi.springboot.framework.dto.request.IdRequest;
9+
import com.codingapi.springboot.framework.dto.response.Response;
610
import com.codingapi.springboot.framework.dto.response.SingleResponse;
11+
import com.codingapi.springboot.framework.user.UserContext;
712
import lombok.AllArgsConstructor;
8-
import org.springframework.web.bind.annotation.GetMapping;
9-
import org.springframework.web.bind.annotation.RequestMapping;
10-
import org.springframework.web.bind.annotation.RestController;
13+
import org.springframework.web.bind.annotation.*;
1114

1215

1316
@RestController
@@ -17,12 +20,37 @@ public class WorkflowController {
1720

1821
private final WorkflowRepository workflowRepository;
1922

20-
@GetMapping("/create")
21-
public SingleResponse<Workflow> create() {
23+
@PostMapping("/remove")
24+
public Response remove(@RequestBody IdRequest request) {
25+
Workflow workflow = workflowRepository.get(request.getStringId());
26+
workflowRepository.delete(workflow);
27+
return Response.buildSuccess();
28+
}
29+
30+
@PostMapping("/create")
31+
public SingleResponse<JSONObject> create() {
2232
Workflow workflow = WorkflowBuilder.builder()
23-
.build();
24-
workflowRepository.save(workflow);
25-
return SingleResponse.of(workflow);
33+
.build(false);
34+
JSONObject jsonObject = JSONObject.parseObject(workflow.toJson(true));
35+
return SingleResponse.of(jsonObject);
36+
}
37+
38+
@PostMapping("/save")
39+
public Response save(@RequestBody JSONObject request) {
40+
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
41+
if(current!=null){
42+
request.put("createdOperator",String.valueOf(current.getUserId()));
43+
}
44+
Workflow workflow = Workflow.formJson(request.toJSONString());
45+
System.out.println(workflow);
46+
return Response.buildSuccess();
47+
}
48+
49+
@GetMapping("/load")
50+
public SingleResponse<JSONObject> load(String id) {
51+
Workflow workflow = workflowRepository.get(id);
52+
JSONObject jsonObject = JSONObject.parseObject(workflow.toJson(true));
53+
return SingleResponse.of(jsonObject);
2654
}
2755

2856
}

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public Long convertToDatabaseColumn(IFlowOperator operator) {
1616

1717
@Override
1818
public IFlowOperator convertToEntityAttribute(Long dbData) {
19-
if(dbData<=0){
19+
if(dbData==null || dbData<=0){
2020
return null;
2121
}
2222
return GatewayContext.getInstance().getFlowOperator(dbData);

frontend/packages/flow-design/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@flow-engine/flow-types": "workspace:*",
2727
"@reduxjs/toolkit": "^2.11.2",
2828
"antd": "^6.2.1",
29+
"dayjs": "^1.11.19",
2930
"react-redux": "^9.2.0"
3031
},
3132
"devDependencies": {

frontend/packages/flow-design/src/api/workflow.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@ import { httpClient } from ".";
22

33
export const list = (request: any) => {
44
return httpClient.page('/api/query/workflow/list', request, {}, {}, []);
5+
}
6+
7+
export const remove = (id:string) => {
8+
return httpClient.post('/api/cmd/workflow/remove',{id});
9+
}
10+
11+
export const create = () => {
12+
return httpClient.post('/api/cmd/workflow/create',{});
13+
}
14+
15+
export const save = (body:any) => {
16+
return httpClient.post('/api/cmd/workflow/save',body);
17+
}
18+
19+
export const load = (id:string) => {
20+
return httpClient.get('/api/cmd/workflow/load',{id});
521
}

frontend/packages/flow-design/src/components/table/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { Table as AntdTable, TableProps as AntdTableProps,Flex,Space,Card } from
33

44

55
export interface Result<T> {
6-
data:{
7-
total: number;
8-
list: T[];
9-
}
6+
data:T[]
7+
total: number;
108
success: boolean
119
}
1210

@@ -57,8 +55,8 @@ export function Table<RecordType extends object = any>(props: TableProps<RecordT
5755
if (res.success) {
5856
setCurrent(request.current);
5957
setPageSize(request.pageSize);
60-
setTotal(res.data.total);
61-
setDataSource(res.data.list);
58+
setTotal(res.total);
59+
setDataSource(res.data);
6260
}
6361
})
6462
};
@@ -88,6 +86,8 @@ export function Table<RecordType extends object = any>(props: TableProps<RecordT
8886
pageSize: pageSize,
8987
current: current,
9088
total: total,
89+
showSizeChanger: true,
90+
showQuickJumper: true,
9191
defaultCurrent: defaultCurrent,
9292
defaultPageSize: defaultPageSize,
9393
onChange: (pageSize, current) => {

0 commit comments

Comments
 (0)