Skip to content

Commit 9197aa7

Browse files
committed
add query
1 parent 51f359d commit 9197aa7

File tree

13 files changed

+344
-146
lines changed

13 files changed

+344
-146
lines changed

example/example-app/example-app-query/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,24 @@
1717
</properties>
1818

1919

20+
<dependencies>
21+
<dependency>
22+
<groupId>com.codingapi.springboot</groupId>
23+
<artifactId>example-infra-jpa</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>com.codingapi.springboot</groupId>
29+
<artifactId>example-infra-flow</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>com.codingapi.springboot</groupId>
35+
<artifactId>example-infra-security</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
39+
</dependencies>
2040
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
import com.codingapi.example.domain.user.entity.User;
4+
import com.codingapi.example.domain.user.repository.UserRepository;
5+
import com.codingapi.example.infra.flow.entity.FlowRecordEntity;
6+
import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository;
7+
import com.codingapi.springboot.fast.jpa.SQLBuilder;
8+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
9+
import com.codingapi.springboot.security.gateway.TokenContext;
10+
import lombok.AllArgsConstructor;
11+
import org.springframework.data.domain.Page;
12+
import org.springframework.data.domain.PageRequest;
13+
import org.springframework.stereotype.Service;
14+
import org.springframework.util.StringUtils;
15+
16+
@Service
17+
@AllArgsConstructor
18+
public class FlowAppQueryService {
19+
20+
private final FlowRecordEntityRepository flowRecordQuery;
21+
private final UserRepository userRepository;
22+
23+
public Page<FlowRecordEntity> list(SearchRequest searchRequest) {
24+
String lastId = searchRequest.getParameter("lastId");
25+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) ");
26+
if(StringUtils.hasText(lastId)){
27+
sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId));
28+
}
29+
sqlBuilder.appendSql(" order by d.id desc ");
30+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
31+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
32+
}
33+
34+
35+
public Page<FlowRecordEntity> findAllByOperatorId(SearchRequest searchRequest) {
36+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
37+
String lastId = searchRequest.getParameter("lastId");
38+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) ");
39+
sqlBuilder.addParam(user.getId());
40+
if(StringUtils.hasText(lastId)){
41+
sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId));
42+
}
43+
sqlBuilder.appendSql(" order by d.id desc ");
44+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
45+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
46+
}
47+
48+
49+
public Page<FlowRecordEntity> findTodoByOperatorId(SearchRequest searchRequest) {
50+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
51+
String lastId = searchRequest.getParameter("lastId");
52+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' ");
53+
sqlBuilder.addParam(user.getId());
54+
if(StringUtils.hasText(lastId)){
55+
sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId));
56+
}
57+
sqlBuilder.appendSql(" order by r.id desc ");
58+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
59+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
60+
}
61+
62+
63+
public Page<FlowRecordEntity> findDoneByOperatorId(SearchRequest searchRequest) {
64+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
65+
String lastId = searchRequest.getParameter("lastId");
66+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) ");
67+
sqlBuilder.addParam(user.getId());
68+
if(StringUtils.hasText(lastId)){
69+
sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId));
70+
}
71+
sqlBuilder.appendSql(" order by d.id desc ");
72+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
73+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
74+
}
75+
76+
77+
public Page<FlowRecordEntity> findInitiatedByOperatorId(SearchRequest searchRequest) {
78+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
79+
String lastId = searchRequest.getParameter("lastId");
80+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) ");
81+
sqlBuilder.addParam(user.getId());
82+
if(StringUtils.hasText(lastId)){
83+
sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId));
84+
}
85+
sqlBuilder.appendSql(" order by d.id desc ");
86+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
87+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
88+
}
89+
90+
91+
public Page<FlowRecordEntity> findTimeoutTodoByOperatorId(SearchRequest searchRequest) {
92+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
93+
String lastId = searchRequest.getParameter("lastId");
94+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 ");
95+
sqlBuilder.addParam(user.getId());
96+
sqlBuilder.addParam(System.currentTimeMillis());
97+
if(StringUtils.hasText(lastId)){
98+
sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId));
99+
}
100+
sqlBuilder.appendSql(" order by r.id desc ");
101+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
102+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
103+
}
104+
105+
106+
public Page<FlowRecordEntity> findPostponedTodoByOperatorId(SearchRequest searchRequest) {
107+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
108+
String lastId = searchRequest.getParameter("lastId");
109+
SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 ");
110+
sqlBuilder.addParam(user.getId());
111+
if(StringUtils.hasText(lastId)){
112+
sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId));
113+
}
114+
sqlBuilder.appendSql(" order by r.id desc ");
115+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
116+
return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest);
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
import com.codingapi.example.domain.user.entity.User;
4+
import com.codingapi.example.domain.user.repository.UserRepository;
5+
import com.codingapi.example.infra.flow.entity.FlowRecordEntity;
6+
import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository;
7+
import com.codingapi.example.infra.flow.user.FlowUser;
8+
import com.codingapi.springboot.flow.pojo.FlowDetail;
9+
import com.codingapi.springboot.flow.service.FlowService;
10+
import com.codingapi.springboot.framework.dto.request.PageRequest;
11+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
12+
import com.codingapi.springboot.security.gateway.TokenContext;
13+
import lombok.AllArgsConstructor;
14+
import org.springframework.data.domain.Page;
15+
import org.springframework.data.domain.Sort;
16+
import org.springframework.stereotype.Service;
17+
18+
@Service
19+
@AllArgsConstructor
20+
public class FlowRecordQueryService {
21+
22+
private final FlowRecordEntityRepository flowRecordQuery;
23+
private final UserRepository userRepository;
24+
private final FlowService flowService;
25+
26+
public Page<FlowRecordEntity> list(SearchRequest searchRequest) {
27+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize(), Sort.by("id").descending());
28+
return flowRecordQuery.findAllFlowRecords(pageRequest);
29+
}
30+
31+
32+
public FlowDetail detail(SearchRequest searchRequest) {
33+
long id = 0;
34+
if (searchRequest.getParameter("id") != null) {
35+
id = Long.parseLong(searchRequest.getParameter("id"));
36+
}
37+
String workCode = searchRequest.getParameter("workCode");
38+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
39+
return flowService.detail(id, workCode, new FlowUser(user));
40+
}
41+
42+
43+
public Page<FlowRecordEntity> findAllByOperatorId(SearchRequest searchRequest) {
44+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
45+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
46+
return flowRecordQuery.findAllByOperatorId(user.getId(), pageRequest);
47+
}
48+
49+
50+
public Page<FlowRecordEntity> findTodoByOperatorId(SearchRequest searchRequest) {
51+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
52+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
53+
return flowRecordQuery.findTodoByOperatorId(user.getId(), pageRequest);
54+
}
55+
56+
57+
public Page<FlowRecordEntity> findDoneByOperatorId(SearchRequest searchRequest) {
58+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
59+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
60+
return flowRecordQuery.findDoneByOperatorId(user.getId(), pageRequest);
61+
}
62+
63+
64+
public Page<FlowRecordEntity> findInitiatedByOperatorId(SearchRequest searchRequest) {
65+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
66+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
67+
return flowRecordQuery.findInitiatedByOperatorId(user.getId(), pageRequest);
68+
}
69+
70+
71+
public Page<FlowRecordEntity> findTimeoutTodoByOperatorId(SearchRequest searchRequest) {
72+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
73+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
74+
return flowRecordQuery.findTimeoutTodoByOperatorId(user.getId(), System.currentTimeMillis(), pageRequest);
75+
}
76+
77+
78+
public Page<FlowRecordEntity> findPostponedTodoByOperatorId(SearchRequest searchRequest) {
79+
User user = userRepository.getUserByUsername(TokenContext.current().getUsername());
80+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
81+
return flowRecordQuery.findPostponedTodoByOperatorId(user.getId(), pageRequest);
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
import com.codingapi.example.infra.flow.entity.FlowWorkEntity;
4+
import com.codingapi.example.infra.flow.jpa.FlowWorkEntityRepository;
5+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
6+
import lombok.AllArgsConstructor;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.stereotype.Service;
9+
10+
@Service
11+
@AllArgsConstructor
12+
public class FlowWorkQueryService {
13+
14+
private final FlowWorkEntityRepository flowWorkEntityRepository;
15+
16+
public Page<FlowWorkEntity> list(SearchRequest searchRequest) {
17+
return flowWorkEntityRepository.searchRequest(searchRequest);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
import com.codingapi.example.infra.db.entity.LeaveEntity;
4+
import com.codingapi.example.infra.db.jpa.LeaveEntityRepository;
5+
import com.codingapi.springboot.fast.jpa.SQLBuilder;
6+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
7+
import com.codingapi.springboot.security.gateway.TokenContext;
8+
import lombok.AllArgsConstructor;
9+
import org.springframework.data.domain.Page;
10+
import org.springframework.data.domain.PageRequest;
11+
import org.springframework.stereotype.Service;
12+
import org.springframework.util.StringUtils;
13+
14+
@Service
15+
@AllArgsConstructor
16+
public class LeaveAppQueryService {
17+
18+
private final LeaveEntityRepository leaveEntityRepository;
19+
20+
public Page<LeaveEntity> list(SearchRequest searchRequest) {
21+
String username = TokenContext.current().getUsername();
22+
String lastId = searchRequest.getParameter("lastId");
23+
SQLBuilder sqlBuilder = new SQLBuilder("from LeaveEntity l where 1 =1 ");
24+
sqlBuilder.append(" and l.username = ? ", username);
25+
if (StringUtils.hasText(lastId)) {
26+
sqlBuilder.append(" and l.id < ? ", Long.parseLong(lastId));
27+
}
28+
sqlBuilder.appendSql(" order by l.id desc ");
29+
PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize());
30+
return leaveEntityRepository.dynamicPageQuery(sqlBuilder, pageRequest);
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
4+
import com.codingapi.example.infra.db.entity.LeaveEntity;
5+
import com.codingapi.example.infra.db.jpa.LeaveEntityRepository;
6+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
7+
import lombok.AllArgsConstructor;
8+
import org.springframework.data.domain.Page;
9+
import org.springframework.stereotype.Service;
10+
11+
@Service
12+
@AllArgsConstructor
13+
public class LeaveQueryService {
14+
15+
private final LeaveEntityRepository leaveEntityRepository;
16+
17+
public Page<LeaveEntity> list(SearchRequest searchRequest){
18+
return leaveEntityRepository.searchRequest(searchRequest);
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.codingapi.example.app.query.service;
2+
3+
import com.codingapi.example.infra.db.entity.UserEntity;
4+
import com.codingapi.example.infra.db.jpa.UserEntityRepository;
5+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
6+
import lombok.AllArgsConstructor;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.stereotype.Service;
9+
10+
@Service
11+
@AllArgsConstructor
12+
public class UserQueryService {
13+
14+
private final UserEntityRepository userEntityRepository;
15+
16+
public Page<UserEntity> list(SearchRequest searchRequest) {
17+
return userEntityRepository.searchRequest(searchRequest);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)