You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/12/01 03:10:25 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #13031: [Feature][API] New restful API for workflow state

zhongjiajie commented on code in PR #13031:
URL: https://github.com/apache/dolphinscheduler/pull/13031#discussion_r1036634931


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count

Review Comment:
   ```suggestion
        * query one workflow states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count

Review Comment:
   ```suggestion
        * query all workflow states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count

Review Comment:
   ```suggestion
        * @return tasks states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person

Review Comment:
   ```suggestion
        * statistics the workflow quantities of certain user
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person
+     *
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUserId", description = "COUNT_PROCESS_DEFINITION_V2_BY_USERID_NOTES")
+    @GetMapping(value = "/workflows/users/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        String projectName = statisticsStateRequest.getProjectName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        if (null == projectCode && !StringUtils.isBlank(projectName)) {
+            projectCode = dataAnalysisService.getProjectCodeByName(projectName);
+        }
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain userId
+     *
+     * @param loginUser login user
+     * @param userId userId
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
+    @GetMapping(value = "/workflows/users/{userId}/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                          @PathVariable("userId") Integer userId) {
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
+        return returnDataList(result);
+    }
+    /**
+    * statistics the process definition quantities of certain userId filter releaseState
+    *
+    * @param loginUser login user
+    * @param userId userId
+    * @param releaseState releaseState
+    * @return definition count in project code

Review Comment:
   ```suggestion
       * @return workflow count in project code
   ```



##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java:
##########
@@ -287,4 +288,25 @@ IPage<ProcessInstance> queryProcessInstanceListV2Paging(Page<ProcessInstance> pa
                                                             @Param("state") Integer state,
                                                             @Param("host") String host);
 
+    /**
+     * Statistics process instance state v2
+     * <p>
+     * We only need project codes to determine whether the process instance belongs to the user or not.
+     *
+     * @param startTime    startTime
+     * @param endTime      endTime
+     * @param projectCode  projectCode
+     * @param workflowCode workflowCode
+     * @param model model

Review Comment:
   can we list the model value, make users know the meaning here? same as other interface using model



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java:
##########
@@ -353,4 +359,250 @@ public List<ExecuteStatusCount> countTaskInstanceAllStatesByProjectCodes(Date st
 
         return startTimeStates.orElse(null);
     }
+    /**
+     * query all workflow count
+     *
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Override
+    public Map<String, Object> queryAllWorkflowCounts(User loginUser) {
+        Map<String, Object> result = new HashMap<>();
+        int count = 0;
+        Set<Integer> projectIds = resourcePermissionCheckService
+                .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
+        if (!projectIds.isEmpty()) {
+            List<Project> projects = projectMapper.selectBatchIds(projectIds);
+            List<Long> projectCodes = projects.stream().map(project -> project.getCode()).collect(Collectors.toList());
+            count = projectMapper.queryAllWorkflowCounts(projectCodes);
+        }
+        result.put("data", "AllWorkflowCounts = " + count);
+        putMsg(result, Status.SUCCESS);
+        return result;
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Override
+    public Map<String, Object> countWorkflowStates(User loginUser,
+                                                   StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result = new HashMap<>();
+        Set<Integer> projectIds = resourcePermissionCheckService
+                .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
+        if (projectIds.isEmpty()) {
+            putMsg(result, Status.SUCCESS);
+            return result;
+        }
+
+        String projectName = statisticsStateRequest.getProjectName();
+        String workflowName = statisticsStateRequest.getWorkflowName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        Long workflowCode = statisticsStateRequest.getWorkflowCode();
+        Integer model = Constants.QUERY_ALL_ON_SYSTEM;
+
+        if (!StringUtils.isBlank(projectName) || null != projectCode) {
+            model = Constants.QUERY_ALL_ON_PROJECT;
+        }
+        if (!StringUtils.isBlank(workflowName) || null != workflowCode) {
+            model = Constants.QUERY_ALL_ON_WORKFLOW;
+        }
+        try {
+            if (null == workflowCode || null == projectCode) {
+                projectCode = projectMapper.queryByName(projectName).getCode();
+                workflowCode = processDefinitionMapper.queryByDefineName(projectCode, workflowName).getCode();
+            }
+        } catch (Exception e) {
+
+        }
+
+        Date date = new Date();
+        Date startTime = statisticsStateRequest.getStartTime() == null ? DateUtils.addMonths(date, -1)
+                : statisticsStateRequest.getStartTime();
+        Date endTime = statisticsStateRequest.getEndTime() == null ? date : statisticsStateRequest.getEndTime();
+
+        List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
+                startTime, endTime, projectCode, workflowCode, model, projectIds);
+        TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
+        result.put(Constants.DATA_LIST, taskCountResult);
+        putMsg(result, Status.SUCCESS);
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> countOneWorkflowStates(User loginUser, Long workflowCode) {
+        Map<String, Object> result = new HashMap<>();
+        Project project = projectMapper.queryByCode(workflowCode);
+        boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
+        if (!hasProjectAndWritePerm) {
+            return result;
+        }
+        List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
+                null, null, null, workflowCode, Constants.QUERY_ALL_ON_WORKFLOW, null);
+        if (executeStatusCounts != null) {
+            TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
+            result.put(Constants.DATA_LIST, taskCountResult);
+            putMsg(result, Status.SUCCESS);
+        }
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result = new HashMap<>();
+        Set<Integer> projectIds = resourcePermissionCheckService
+                .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
+        if (projectIds.isEmpty()) {
+            putMsg(result, Status.SUCCESS);
+            return result;
+        }
+        String projectName = statisticsStateRequest.getProjectName();
+        String workflowName = statisticsStateRequest.getWorkflowName();
+        String taskName = statisticsStateRequest.getTaskName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        Long workflowCode = statisticsStateRequest.getWorkflowCode();
+        Long taskCode = statisticsStateRequest.getTaskCode();
+        Integer model = Constants.QUERY_ALL_ON_SYSTEM;
+
+        if (!StringUtils.isBlank(projectName) || null != projectCode) {
+            model = Constants.QUERY_ALL_ON_PROJECT;
+        }
+        if (!StringUtils.isBlank(workflowName) || null != workflowCode) {
+            model = Constants.QUERY_ALL_ON_WORKFLOW;
+        }
+        if (!StringUtils.isBlank(taskName) || null != taskCode) {
+            model = Constants.QUERY_ALL_ON_TASK;
+        }
+
+        try {
+            if (null == taskCode || null == workflowCode || null == projectCode) {
+                projectCode = projectMapper.queryByName(projectName).getCode();
+                workflowCode = processDefinitionMapper.queryByDefineName(projectCode, workflowName).getCode();
+                taskCode = relationMapper.queryTaskCodeByTaskName(workflowCode, taskName);
+            }
+        } catch (Exception e) {
+
+        }

Review Comment:
   if we do not handle the exception, we should not catch them



##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml:
##########
@@ -308,6 +308,30 @@
         </if>
         order by instance.start_time desc,instance.id desc
     </select>
+    <select id="countInstanceStateV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">

Review Comment:
   resolve



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count

Review Comment:
   ```suggestion
        * @return workflow states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count

Review Comment:
   ```suggestion
        * @return workflow states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count

Review Comment:
   ```suggestion
        * query one task states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/StatisticsStateRequest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.apache.dolphinscheduler.api.dto.project;
+
+import java.util.Date;
+
+import lombok.Data;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.v3.oas.annotations.media.Schema;
+
+@Data
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class StatisticsStateRequest {
+
+    @Schema(name = "isAll", example = "true")
+    boolean isAll;
+
+    @Schema(name = "projectName", example = "PROJECT-NAME")
+    String projectName;
+
+    @Schema(name = "projectCode", example = "PROJECT-CODE")

Review Comment:
   we should use the code as code related parameter, same as workflow code
   ```suggestion
       @Schema(name = "projectCode", example = "1234567890")
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count

Review Comment:
   ```suggestion
        * @return tasks states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count

Review Comment:
   ```suggestion
        * query all task states count
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person
+     *
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return definition count in project code

Review Comment:
   ```suggestion
        * @return workflow count in project code
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person
+     *
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUserId", description = "COUNT_PROCESS_DEFINITION_V2_BY_USERID_NOTES")
+    @GetMapping(value = "/workflows/users/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        String projectName = statisticsStateRequest.getProjectName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        if (null == projectCode && !StringUtils.isBlank(projectName)) {
+            projectCode = dataAnalysisService.getProjectCodeByName(projectName);
+        }
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain userId
+     *
+     * @param loginUser login user
+     * @param userId userId
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
+    @GetMapping(value = "/workflows/users/{userId}/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                          @PathVariable("userId") Integer userId) {
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
+        return returnDataList(result);
+    }
+    /**
+    * statistics the process definition quantities of certain userId filter releaseState

Review Comment:
   ```suggestion
       * statistics the workflow quantities of certain userId filter releaseState
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person
+     *
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUserId", description = "COUNT_PROCESS_DEFINITION_V2_BY_USERID_NOTES")
+    @GetMapping(value = "/workflows/users/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        String projectName = statisticsStateRequest.getProjectName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        if (null == projectCode && !StringUtils.isBlank(projectName)) {
+            projectCode = dataAnalysisService.getProjectCodeByName(projectName);
+        }
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain userId
+     *
+     * @param loginUser login user
+     * @param userId userId
+     * @return definition count in project code

Review Comment:
   ```suggestion
        * @return workflow count in project code
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java:
##########
@@ -353,4 +359,250 @@ public List<ExecuteStatusCount> countTaskInstanceAllStatesByProjectCodes(Date st
 
         return startTimeStates.orElse(null);
     }
+    /**
+     * query all workflow count
+     *
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Override
+    public Map<String, Object> queryAllWorkflowCounts(User loginUser) {
+        Map<String, Object> result = new HashMap<>();
+        int count = 0;
+        Set<Integer> projectIds = resourcePermissionCheckService
+                .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
+        if (!projectIds.isEmpty()) {
+            List<Project> projects = projectMapper.selectBatchIds(projectIds);
+            List<Long> projectCodes = projects.stream().map(project -> project.getCode()).collect(Collectors.toList());
+            count = projectMapper.queryAllWorkflowCounts(projectCodes);
+        }
+        result.put("data", "AllWorkflowCounts = " + count);
+        putMsg(result, Status.SUCCESS);
+        return result;
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Override
+    public Map<String, Object> countWorkflowStates(User loginUser,
+                                                   StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result = new HashMap<>();
+        Set<Integer> projectIds = resourcePermissionCheckService
+                .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
+        if (projectIds.isEmpty()) {
+            putMsg(result, Status.SUCCESS);
+            return result;
+        }
+
+        String projectName = statisticsStateRequest.getProjectName();
+        String workflowName = statisticsStateRequest.getWorkflowName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        Long workflowCode = statisticsStateRequest.getWorkflowCode();
+        Integer model = Constants.QUERY_ALL_ON_SYSTEM;
+
+        if (!StringUtils.isBlank(projectName) || null != projectCode) {
+            model = Constants.QUERY_ALL_ON_PROJECT;
+        }
+        if (!StringUtils.isBlank(workflowName) || null != workflowCode) {
+            model = Constants.QUERY_ALL_ON_WORKFLOW;
+        }
+        try {
+            if (null == workflowCode || null == projectCode) {
+                projectCode = projectMapper.queryByName(projectName).getCode();
+                workflowCode = processDefinitionMapper.queryByDefineName(projectCode, workflowName).getCode();
+            }
+        } catch (Exception e) {
+
+        }

Review Comment:
   same as this exception



##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml:
##########
@@ -221,6 +221,13 @@
         </where>
         order by update_time desc, id asc
     </select>
+    <select id="queryTaskCodeByTaskName" resultType="java.lang.Long">

Review Comment:
   It is seem we support  same task name in one single workflow currently



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.apache.dolphinscheduler.api.controller;
+
+import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.DataAnalysisService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+/**
+ * StatisticsV2 controller
+ */
+@Tag(name = "STATISTICS_V2")
+@RestController
+@RequestMapping("/v2/statistics")
+public class StatisticsV2Controller extends BaseController {
+
+    @Autowired
+    private DataAnalysisService dataAnalysisService;
+
+    /**
+     * query all workflow count
+     * @param loginUser login user
+     * @return workflow count
+     */
+    @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
+    @GetMapping(value = "/workflows/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
+        Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all workflow States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return workflow States count
+     */
+    @Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/workflows/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                            @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one workflow States count
+     * @param loginUser login user
+     * @param workflowCode workflowCode
+     * @return workflow States count
+     */
+    @Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
+    @GetMapping(value = "/{workflowCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                         @PathVariable("workflowCode") Long workflowCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * query all task States count
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return tasks States count
+     */
+    @Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        Map<String, Object> result =
+                dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
+        return returnDataList(result);
+    }
+
+    /**
+     * query one task States count
+     * @param loginUser login user
+     * @param taskCode taskCode
+     * @return tasks States count
+     */
+    @Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
+    @GetMapping(value = "/tasks/{taskCode}/states/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                           @PathVariable("taskCode") Long taskCode) {
+        Map<String, Object> result =
+                dataAnalysisService.countOneTaskStates(loginUser, taskCode);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain person
+     *
+     * @param loginUser login user
+     * @param statisticsStateRequest statisticsStateRequest
+     * @return definition count in project code
+     */
+    @Operation(summary = "countDefinitionV2ByUserId", description = "COUNT_PROCESS_DEFINITION_V2_BY_USERID_NOTES")
+    @GetMapping(value = "/workflows/users/count")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                        @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
+        String projectName = statisticsStateRequest.getProjectName();
+        Long projectCode = statisticsStateRequest.getProjectCode();
+        if (null == projectCode && !StringUtils.isBlank(projectName)) {
+            projectCode = dataAnalysisService.getProjectCodeByName(projectName);
+        }
+        Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
+        return returnDataList(result);
+    }
+
+    /**
+     * statistics the process definition quantities of certain userId

Review Comment:
   ```suggestion
        * statistics the workflow quantities of certain userId
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org