meegle/workflow/
api.rs

1use super::types::*;
2use crate::client::{AuthType, Client};
3use crate::error::ApiResult;
4use crate::structs::{ExPand, NodesConnections, WbsViewResponse};
5
6pub trait WorkflowApi {
7    /// 更新工作项实例的指定节点信息
8    ///
9    /// 该接口用于更新一个工作项实例的指定节点信息(节点流),包括节点负责人、排期和表单信息等。
10    ///
11    /// # Arguments
12    /// * `project_key` - 空间id或域名
13    /// * `work_item_type_key` - 工作项类型
14    /// * `work_item_id` - 工作项ID
15    /// * `node_id` - 目标节点ID
16    /// * `request` - 更新请求参数
17    /// * `auth` - 认证信息
18    fn update_node(
19        &self,
20        project_key: &str,
21        work_item_type_key: &str,
22        work_item_id: i64,
23        node_id: &str,
24        request: UpdateNodeRequest,
25        auth: AuthType,
26    ) -> impl std::future::Future<Output = ApiResult<serde_json::Value>> + Send;
27
28    /// 完成或回滚工作项实例的指定节点
29    ///
30    /// 该接口用于完成或者回滚一个工作项实例的指定节点(节点流),同时更新节点信息。
31    ///
32    /// # Arguments
33    /// * `project_key` - 空间id或域名
34    /// * `work_item_type_key` - 工作项类型
35    /// * `work_item_id` - 工作项ID
36    /// * `node_id` - 目标节点ID
37    /// * `request` - 操作请求参数
38    /// * `auth` - 认证信息
39    fn operate_node(
40        &self,
41        project_key: &str,
42        work_item_type_key: &str,
43        work_item_id: i64,
44        node_id: &str,
45        request: OperateNodeRequest,
46        auth: AuthType,
47    ) -> impl std::future::Future<Output = ApiResult<serde_json::Value>> + Send;
48
49    /// 状态流转
50    ///
51    /// 该接口用于流转一个工作项实例到指定状态(状态流),同时更新节点信息。
52    ///
53    /// # Arguments
54    /// * `project_key` - 空间id或域名
55    /// * `work_item_type_key` - 工作项类型
56    /// * `work_item_id` - 工作项ID
57    /// * `request` - 状态流转请求参数
58    /// * `auth` - 认证信息
59    fn change_state(
60        &self,
61        project_key: &str,
62        work_item_type_key: &str,
63        work_item_id: i64,
64        request: ChangeStateRequest,
65        auth: AuthType,
66    ) -> impl std::future::Future<Output = ApiResult<serde_json::Value>> + Send;
67
68    /// 获取工作流详情(WBS)
69    ///
70    /// 该接口用于获取行业专版中一个节点流工作项实例的WBS工作流信息。
71    ///
72    /// # Arguments
73    /// * `project_key` - 空间id或域名
74    /// * `work_item_type_key` - 工作项类型
75    /// * `work_item_id` - 工作项ID
76    /// * `expand` - 展开参数选项
77    /// * `auth` - 认证信息
78    fn get_workflow_wbs(
79        &self,
80        project_key: &str,
81        work_item_type_key: &str,
82        work_item_id: i64,
83        expand: Option<ExPand>,
84        auth: AuthType,
85    ) -> impl std::future::Future<Output = ApiResult<WbsViewResponse>> + Send;
86
87    /// 获取工作流详情
88    ///
89    /// 该接口用于获取指定空间和工作项类型下的一个工作项实例的工作流信息。
90    ///
91    /// # Arguments
92    /// * `project_key` - 空间id或域名
93    /// * `work_item_type_key` - 工作项类型
94    /// * `work_item_id` - 工作项ID
95    /// * `request` - 查询请求参数
96    /// * `auth` - 认证信息
97    fn get_workflow_detail(
98        &self,
99        project_key: &str,
100        work_item_type_key: &str,
101        work_item_id: i64,
102        request: GetWorkflowDetailRequest,
103        auth: AuthType,
104    ) -> impl std::future::Future<Output = ApiResult<NodesConnections>> + Send;
105}
106
107impl WorkflowApi for Client {
108    async fn update_node(
109        &self,
110        project_key: &str,
111        work_item_type_key: &str,
112        work_item_id: i64,
113        node_id: &str,
114        request: UpdateNodeRequest,
115        auth: AuthType,
116    ) -> ApiResult<serde_json::Value> {
117        let path = format!(
118            "{}/workflow/{}/{}/node/{}",
119            project_key, work_item_type_key, work_item_id, node_id
120        );
121        Ok(self.put(&path, request, auth).await?)
122    }
123
124    async fn operate_node(
125        &self,
126        project_key: &str,
127        work_item_type_key: &str,
128        work_item_id: i64,
129        node_id: &str,
130        request: OperateNodeRequest,
131        auth: AuthType,
132    ) -> ApiResult<serde_json::Value> {
133        let path = format!(
134            "{}/workflow/{}/{}/node/{}/operate",
135            project_key, work_item_type_key, work_item_id, node_id
136        );
137        Ok(self.post(&path, request, auth).await?)
138    }
139
140    async fn change_state(
141        &self,
142        project_key: &str,
143        work_item_type_key: &str,
144        work_item_id: i64,
145        request: ChangeStateRequest,
146        auth: AuthType,
147    ) -> ApiResult<serde_json::Value> {
148        let path = format!(
149            "{}/workflow/{}/{}/node/state_change",
150            project_key, work_item_type_key, work_item_id
151        );
152        Ok(self.post(&path, request, auth).await?)
153    }
154
155    async fn get_workflow_wbs(
156        &self,
157        project_key: &str,
158        work_item_type_key: &str,
159        work_item_id: i64,
160        expand: Option<ExPand>,
161        auth: AuthType,
162    ) -> ApiResult<WbsViewResponse> {
163        let path = format!(
164            "{}/work_item/{}/{}/wbs_view",
165            project_key, work_item_type_key, work_item_id
166        );
167        let mut query = Vec::new();
168        if let Some(e) = expand {
169            if let Some(true) = e.need_workflow {
170                query.push(("need_workflow", "true".to_string()));
171            }
172            if let Some(true) = e.need_multi_text {
173                query.push(("need_multi_text", "true".to_string()));
174            }
175            if let Some(true) = e.relation_fields_detail {
176                query.push(("relation_fields_detail", "true".to_string()));
177            }
178            if let Some(true) = e.need_union_deliverable {
179                query.push(("need_union_deliverable", "true".to_string()));
180            }
181            if let Some(true) = e.need_wbs_relation_chain_entity {
182                query.push(("need_wbs_relation_chain_entity", "true".to_string()));
183            }
184            if let Some(true) = e.need_wbs_relation_chain_path {
185                query.push(("need_wbs_relation_chain_path", "true".to_string()));
186            }
187        }
188        Ok(self.get_with_query(&path, &query, auth).await?)
189    }
190
191    async fn get_workflow_detail(
192        &self,
193        project_key: &str,
194        work_item_type_key: &str,
195        work_item_id: i64,
196        request: GetWorkflowDetailRequest,
197        auth: AuthType,
198    ) -> ApiResult<NodesConnections> {
199        let path = format!(
200            "{}/work_item/{}/{}/workflow/query",
201            project_key, work_item_type_key, work_item_id
202        );
203        Ok(self.post(&path, request, auth).await?)
204    }
205}