diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java index 076f9c03ae..0ea664ae62 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java @@ -118,21 +118,21 @@ public class DataAnalysisController extends BaseController { * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id - * @return definition count in project id + * @param projectCode project code + * @return definition count in project code */ @ApiOperation(value = "countDefinitionByUser", notes = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") + @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100") }) @GetMapping(value = "/define-user-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result countDefinitionByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectId); + Map result = dataAnalysisService.countDefinitionByUser(loginUser, projectCode); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java index f189358edd..680c8962f2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java @@ -52,10 +52,10 @@ public interface DataAnalysisService { * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return definition count data */ - Map countDefinitionByUser(User loginUser, int projectId); + Map countDefinitionByUser(User loginUser, long projectCode); /** * statistical command status data diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index 25bc3f80f4..3e3d6ea751 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -132,10 +132,14 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal private Map countStateByProject(User loginUser, long projectCode, String startDate, String endDate , TriFunction> instanceStateCounter) { - Project project = projectMapper.queryByCode(projectCode); - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; + Map result = new HashMap<>(); + + if (projectCode != 0) { + Project project = projectMapper.queryByCode(projectCode); + result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } } Date start = null; @@ -167,18 +171,23 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistics the process definition quantities of certain person * * @param loginUser login user - * @param projectId project id + * @param projectCode project code * @return definition count data */ @Override - public Map countDefinitionByUser(User loginUser, int projectId) { + public Map countDefinitionByUser(User loginUser, long projectCode) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; + + if (projectCode != 0) { + Project project = projectMapper.queryByCode(projectCode); + result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } } - Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectMapper.selectById(projectId).getCode() }; + + Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectCode }; List defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser( loginUser.getId(), projectCodeArray, isAdmin(loginUser)); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java index 08187534a7..39cf9bd8bb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java @@ -92,7 +92,7 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { @Test public void testCountDefinitionByUser() throws Exception { - PowerMockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); + PowerMockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("projectId","16"); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index d838b15b7a..f098ee40e8 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -237,10 +237,15 @@ public class DataAnalysisServiceTest { @Test public void testCountDefinitionByUser() { - Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); + Mockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, null); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(processDefinitionMapper.countDefinitionGroupByUser(Mockito.anyInt(), Mockito.any(Long[].class), Mockito.anyBoolean())).thenReturn(new ArrayList()); - Map result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); + result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/defineUserCount.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/defineUserCount.vue index 07e734987c..be4304f934 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/defineUserCount.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/defineUserCount.vue @@ -38,11 +38,11 @@ return { isSpin: true, msg: true, - parameter: { projectId: 0 } + parameter: { projectCode: 0 } } }, props: { - projectId: Number + projectCode: Number }, methods: { ...mapActions('projects', ['getDefineUserCount']), @@ -57,7 +57,7 @@ const myChart = Chart.bar('#process-definition-bar', this.defineUserList, {}) myChart.echart.setOption(bar) // Jump not allowed on home page - if (this.projectId) { + if (this.projectCode) { myChart.echart.on('click', e => { this.$router.push({ name: 'projects-definition-list', @@ -71,7 +71,7 @@ }, created () { this.isSpin = true - this.parameter.projectId = this.projectId + this.parameter.projectCode = this.projectCode this.getDefineUserCount(this.parameter).then(res => { this.msg = res.data.count > 0 this.defineUserList = [] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/index.vue index 5175ba5e20..e482ed6b0a 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/index.vue @@ -56,7 +56,7 @@ {{$t('Process Definition Statistics')}}
- +
@@ -71,7 +71,6 @@ import mDefineUserCount from './_source/defineUserCount' import mTaskStatusCount from './_source/taskStatusCount' import mProcessStateCount from './_source/processStateCount' - import localStore from '@/module/util/localStorage' import mListConstruction from '@/module/components/listConstruction/listConstruction' export default { @@ -79,7 +78,6 @@ data () { return { searchParams: { - projectId: null, projectCode: null, startDate: '', endDate: '' @@ -87,9 +85,6 @@ dataTime: [] } }, - props: { - id: Number - }, methods: { _datepicker (val) { this.searchParams.startDate = val[0] @@ -97,8 +92,7 @@ } }, created () { - this.searchParams.projectId = this.id === 0 ? 0 : localStore.getItem('projectId') - this.searchParams.projectCode = this.id === 0 ? 0 : localStore.getItem('projectCode') + this.searchParams.projectCode = this.$route.params.projectCode == null ? 0 : this.$route.params.projectCode this.dataTime[0] = dayjs().format('YYYY-MM-DD 00:00:00') this.dataTime[1] = dayjs().format('YYYY-MM-DD HH:mm:ss') this.searchParams.startDate = this.dataTime[0] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue index fe5086f984..9ce93e506d 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue @@ -97,7 +97,7 @@ localStore.setItem('projectId', item.id) localStore.setItem('projectCode', item.code) localStore.setItem('projectName', item.name) - this.$router.push({ path: `/projects/${item.id}/index` }) + this.$router.push({ path: `/projects/${item.code}/index` }) }, /** * Delete Project diff --git a/dolphinscheduler-ui/src/js/conf/home/router/index.js b/dolphinscheduler-ui/src/js/conf/home/router/index.js index 1ebe4a3a34..f73dba2abb 100644 --- a/dolphinscheduler-ui/src/js/conf/home/router/index.js +++ b/dolphinscheduler-ui/src/js/conf/home/router/index.js @@ -83,7 +83,7 @@ const router = new Router({ } }, { - path: '/projects/:projectId/index', + path: '/projects/:projectCode/index', name: 'projects-index', component: resolve => require(['../pages/projects/pages/index/index'], resolve), meta: {