-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][admin] Task submit approval (#4070)
- Loading branch information
1 parent
c968389
commit bbc4db4
Showing
42 changed files
with
2,351 additions
and
56 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
dinky-admin/src/main/java/org/dinky/aop/TaskApprovalAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.dinky.aop; | ||
|
||
import org.dinky.data.annotations.CheckTaskApproval; | ||
import org.dinky.data.enums.Status; | ||
import org.dinky.data.exception.BusException; | ||
import org.dinky.data.model.SystemConfiguration; | ||
import org.dinky.utils.AspectUtil; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Objects; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Aspect | ||
@Slf4j | ||
@Component | ||
public class TaskApprovalAspect { | ||
@Resource | ||
private ApplicationContext applicationContext; | ||
|
||
/** | ||
* Check whether the user has the permission to perform the task. | ||
* | ||
* @param joinPoint task operation | ||
* @param checkTaskApproval check task approval aspect | ||
* @return join point execute result | ||
* @throws Throwable exception if task still need approval | ||
*/ | ||
@Around(value = "@annotation(checkTaskApproval)") | ||
public Object processAround(ProceedingJoinPoint joinPoint, CheckTaskApproval checkTaskApproval) throws Throwable { | ||
if (SystemConfiguration.getInstances().enableTaskSubmitApprove()) { | ||
Class checkParam = checkTaskApproval.checkParam(); | ||
Object param = AspectUtil.getParam(joinPoint, checkParam); | ||
if (Objects.nonNull(param)) { | ||
Object bean = applicationContext.getBean(checkTaskApproval.checkInterface()); | ||
Class<?> clazz = bean.getClass(); | ||
Method method = clazz.getMethod(checkTaskApproval.checkMethod(), param.getClass()); | ||
Object invoke = method.invoke(bean, param); | ||
if (invoke != null && (Boolean) invoke) { | ||
throw new BusException(Status.SYS_APPROVAL_TASK_NOT_APPROVED); | ||
} | ||
} | ||
} | ||
|
||
Object result; | ||
try { | ||
result = joinPoint.proceed(); | ||
} catch (Throwable e) { | ||
throw e; | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
dinky-admin/src/main/java/org/dinky/controller/ApprovalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.dinky.controller; | ||
|
||
import org.dinky.data.annotations.CheckTaskOwner; | ||
import org.dinky.data.annotations.ProcessId; | ||
import org.dinky.data.annotations.TaskId; | ||
import org.dinky.data.dto.ApprovalDTO; | ||
import org.dinky.data.enums.ApprovalEvent; | ||
import org.dinky.data.model.Approval; | ||
import org.dinky.data.model.rbac.User; | ||
import org.dinky.data.result.ProTableResult; | ||
import org.dinky.data.result.Result; | ||
import org.dinky.service.ApprovalService; | ||
import org.dinky.service.TaskService; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import cn.dev33.satoken.annotation.SaCheckLogin; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@RestController | ||
@Slf4j | ||
@Api(tags = "Approval Controller", hidden = true) | ||
@RequestMapping("/api/approval") | ||
@SaCheckLogin | ||
@RequiredArgsConstructor | ||
public class ApprovalController { | ||
|
||
private final ApprovalService approvalService; | ||
|
||
@PostMapping("/getSubmittedApproval") | ||
@ApiOperation("Get all approvals submitted by current user") | ||
ProTableResult<Approval> getSubmittedApproval(@RequestBody JsonNode para) { | ||
return approvalService.getSubmittedApproval(para); | ||
} | ||
|
||
@PostMapping("/getApprovalToBeReviewed") | ||
@ApiOperation("Get all approvals current user is required for review") | ||
ProTableResult<Approval> getApprovalToBeReviewed(@RequestBody JsonNode para) { | ||
return approvalService.getApprovalToBeReviewed(para); | ||
} | ||
|
||
@CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class) | ||
@PutMapping("/createTaskApproval") | ||
Result<Approval> createTaskApproval(@TaskId @ProcessId @RequestParam Integer taskId) { | ||
return Result.succeed(approvalService.createTaskApproval(taskId)); | ||
} | ||
|
||
@PostMapping("/submit") | ||
@ApiOperation("Submit approval") | ||
Result<Void> submit(@RequestBody ApprovalDTO approvalDTO) { | ||
approvalService.handleApproveEvent(ApprovalEvent.SUBMIT, approvalDTO); | ||
return Result.succeed(); | ||
} | ||
|
||
@PostMapping("/withdraw") | ||
@ApiOperation("Withdraw approval") | ||
Result<Void> withdraw(@RequestBody ApprovalDTO approvalDTO) { | ||
approvalService.handleApproveEvent(ApprovalEvent.WITHDRAW, approvalDTO); | ||
return Result.succeed(); | ||
} | ||
|
||
@PostMapping("/approve") | ||
@ApiOperation("Approve approval") | ||
Result<Void> approve(@RequestBody ApprovalDTO approvalDTO) { | ||
approvalService.handleApproveEvent(ApprovalEvent.APPROVE, approvalDTO); | ||
return Result.succeed(); | ||
} | ||
|
||
@PostMapping("/reject") | ||
@ApiOperation("Reject approval") | ||
Result<Void> reject(@RequestBody ApprovalDTO approvalDTO) { | ||
approvalService.handleApproveEvent(ApprovalEvent.REJECT, approvalDTO); | ||
return Result.succeed(); | ||
} | ||
|
||
@PostMapping("/cancel") | ||
@ApiOperation("Reject approval") | ||
Result<Void> cancel(@RequestBody ApprovalDTO approvalDTO) { | ||
approvalService.handleApproveEvent(ApprovalEvent.CANCEL, approvalDTO); | ||
return Result.succeed(); | ||
} | ||
|
||
@GetMapping("/getReviewers") | ||
@ApiOperation("Get reviewers that from current tenant") | ||
Result<List<User>> getReviewers(@RequestParam Integer tenantId) { | ||
return Result.succeed(approvalService.getTaskReviewerList(tenantId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
dinky-admin/src/main/java/org/dinky/data/dto/ApprovalDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.dinky.data.dto; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@ApiModel(value = "ApprovalDTO", description = "Approval Data Transfer Object") | ||
public class ApprovalDTO { | ||
@ApiModelProperty(value = "Approval ID", dataType = "Integer", example = "123", notes = "The ID of the approval") | ||
private Integer id; | ||
|
||
@ApiModelProperty(value = "Task ID", dataType = "Integer", example = "123", notes = "The ID of the task") | ||
private Integer taskId; | ||
|
||
@ApiModelProperty( | ||
value = "Reviewer id required for current approval", | ||
dataType = "Integer", | ||
example = "123", | ||
notes = "The ID of the reviewer") | ||
private Integer reviewer; | ||
|
||
@ApiModelProperty( | ||
value = "Comment", | ||
dataType = "String", | ||
example = "Looks good to me/Please take a look", | ||
notes = "Comment from reviewer or submitter") | ||
private String comment; | ||
} |
Oops, something went wrong.