Detailed explanation of the approval process: key steps to improve work efficiency
About 802 wordsAbout 3 minDecember 2, 2024
1. Design the Data Structure for CC (Carbon Copy) Functionality
CC Configuration Table (CC_Config)
Stores the CC configurations for each process or task.
CREATE TABLE CC_Config (
CC_Config_ID INT PRIMARY KEY AUTO_INCREMENT,
Process_Definition_ID INT,
Task_ID INT,
CC_User VARCHAR(255),
Created_At TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (Process_Definition_ID) REFERENCES Process_Definitions(Process_Definition_ID),
FOREIGN KEY (Task_ID) REFERENCES Approval_Tasks(Task_ID)
);
CC Logs Table (CC_Logs)
Stores the actual execution records of CC actions.
CREATE TABLE CC_Logs (
CC_Log_ID INT PRIMARY KEY AUTO_INCREMENT,
Process_Instance_ID INT,
Task_ID INT,
CC_User VARCHAR(255),
CC_Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Message TEXT,
FOREIGN KEY (Process_Instance_ID) REFERENCES Process_Instances(Process_Instance_ID),
FOREIGN KEY (Task_ID) REFERENCES Approval_Tasks(Task_ID)
);
2. Implement the CC Functionality
Based on the CC configuration, write logic to trigger CC actions during process execution.
Trigger Points
- Process Start: Trigger a CC notification when a new process instance starts to inform relevant personnel that the process has begun.
- Task Creation: Trigger a CC notification when a new approval task is created to inform relevant personnel about the task's existence.
- Task Completion: Trigger a CC notification when an approval task is completed to inform relevant personnel about the task's result.
- Process End: Trigger a CC notification when the entire process instance completes to inform relevant personnel about the final result of the process.
The following steps demonstrate the implementation, using Activiti as an example:
1. Create an Event Listener
First, create an event listener to capture various events in the process:
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.context.Context;
public class CcEventListener implements ActivitiEventListener {
@Override
public void onEvent(ActivitiEvent event) {
switch (event.getType()) {
case PROCESS_STARTED:
handleCc(event, "Process Started");
break;
case TASK_CREATED:
handleCc(event, "Task Created");
break;
case TASK_COMPLETED:
handleCc(event, "Task Completed");
break;
case PROCESS_COMPLETED:
handleCc(event, "Process Completed");
break;
default:
break;
}
}
private void handleCc(ActivitiEvent event, String message) {
// Get relevant information
String processInstanceId = event.getProcessInstanceId();
String taskId = event.getExecutionId();
List<String> ccUsers = getCcUsers(taskId);
// Send CC notification
for (String ccUser : ccUsers) {
sendCcNotification(ccUser, message);
recordCcLog(processInstanceId, taskId, ccUser, message);
}
}
}
2. Register the Event Listener
Register the event listener to the process engine when the process engine starts:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
processEngine.getRuntimeService().addEventListener(new CcEventListener());
3. Get the List of CC Users
Implement logic to get the list of CC users by querying the CC configuration table (CC_Config):
public List<String> getCcUsers(String taskId) {
// Query the CC configuration table to get the list of configured CC users
String sql = "SELECT CC_User FROM CC_Config WHERE Task_ID = ?";
// Execute the query logic and return the list of CC users
List<String> ccUsers = new ArrayList<>();
// Assuming JDBC query
try (Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, taskId);
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
ccUsers.add(rs.getString("CC_User"));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return ccUsers;
}
4. Send CC Notifications and Log CC Actions
Implement logic to send CC notifications and log CC actions:
public void sendCcNotification(String ccUser, String message) {
// Logic to send notification, e.g., via email or messaging system
System.out.println("Notify user " + ccUser + ": " + message);
}
public void recordCcLog(String processInstanceId, String taskId, String ccUser, String message) {
// Insert CC record into the CC logs table
String sql = "INSERT INTO CC_Logs (Process_Instance_ID, Task_ID, CC_User, Message) VALUES (?, ?, ?, ?)";
// Execute the insert logic
try (Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, processInstanceId);
pstmt.setString(2, taskId);
pstmt.setString(3, ccUser);
pstmt.setString(4, message);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
3. Update Database Tables
In practical application, ensure each CC action has a new record for audit and tracking purposes. Here are SQL operations to update the database tables:
Insert CC Configuration
INSERT INTO CC_Config (Process_Definition_ID, Task_ID, CC_User)
VALUES (?, ?, ?);
Insert CC Log
INSERT INTO CC_Logs (Process_Instance_ID, Task_ID, CC_User, Message)
VALUES (?, ?, ?, ?);