Jelajahi Sumber

统计做了一半 去写手册去了

于添 6 bulan lalu
induk
melakukan
93b69043ac

+ 144 - 26
src/api/statisticalAnalysis/statisticalAnalysisResourceLibrary.js

@@ -1,5 +1,6 @@
 import { moduleRequest } from '@/utils/request'
 import Mock from 'mockjs'
+import ForEach from "lodash-es/forEach";
 
 const request = moduleRequest(`/api/webapp/`)
 
@@ -116,6 +117,7 @@ const generateMockData = (filters = {}) => {
 	const formatCounts = generateFormatCounts()
 
 	return {
+		filterResponse : getFilterData(),
 		// 摘要数据
 		summaryData: {
 			code: 200,
@@ -233,44 +235,160 @@ const generateMockData = (filters = {}) => {
 }
 
 // API函数 - 每次调用都生成新的动态数据,传入筛选参数
-export const getSummaryData = (params = {}) => {
-	return new Promise((resolve) => {
-		setTimeout(() => {
-			const mockData = generateMockData(params)
-			resolve(mockData.summaryData)
-		}, Mock.mock('@integer(200, 500)')) // 随机延迟
-	})
+export const getSummaryData = async (params = {}) => {
+	// return new Promise((resolve) => {
+	// 	setTimeout(() => {
+	// 		const mockData = generateMockData(params)
+	// 		resolve(mockData.summaryData)
+	// 	}, Mock.mock('@integer(200, 500)')) // 随机延迟
+	// })
+
+	let res =  await request('/resourceStatistic/totalStatistic', params, 'get')
+	console.log('什么呢1233',res)
+	let json = {
+		code : 200,
+		data : {
+			totalResources : res.RESOURCE_TOTAL,
+			totalStorage : `${kbToTb(res.storageSize)}TB`,
+			totalCapacity : `${kbToTb(res.totalStorageSize)}TB`,
+			usageRate : `${((parseFloat(res.storageSize) / res.totalStorageSize) * 100).toFixed(0)}%`,
+			totalViews : res.WATCH_TOTAL,
+			totalFavorites : res.COLLECT_TOTAL
+		}
+	}
+	// {
+	// 	"RESOURCE_TOTAL": 34,  总资源数
+	// 	"TOTAL_STORAGE_SIZE": 20480, 总存储空间
+	// 	"COLLECT_TOTAL": 9, 总收藏数
+	// 	"WATCH_TOTAL": 471, 总观看数
+	// 	"storageSize": 1726487824,
+	// 	"totalStorageSize": 21474836480
+	// }
+		// totalResources: '0',
+		// totalStorage: '0 TB',
+		// totalCapacity: '10 TB',
+		// usageRate: '0%',
+		// totalViews: '0',
+		// totalFavorites: '0'
 	// 真实接口调用:
 	// return request('/resource-library/summary', params, 'get')
+	console.log('什么呢',json)
+	return json
+}
+function kbToTb(kb) {
+	const tb = kb / 1073741824;
+	return parseFloat(tb.toFixed(2));
 }
 
-export const getResourceTypeData = (params = {}) => {
-	return new Promise((resolve) => {
-		setTimeout(() => {
-			const mockData = generateMockData(params)
-			resolve(mockData.resourceTypeData)
-		}, Mock.mock('@integer(200, 500)'))
+export const getFilterData = async (params = {}) => {
+	let colleges = await request('resourceStatistic/selectOrgList', params, 'get')
+	colleges.unshift({
+		id : 'all',
+		name : '全部院系'
 	})
+	console.log("什么呢sss",colleges)
+	let json = {
+		code: 200,
+		data : colleges
+	}
+
+	return json
+}
+
+export const getResourceTypeData = async (params = {}) => {
+	let resourceTypeStatistic = await request('resourceStatistic/resourceTypeStatistic', params, 'get')
+	console.log('左面的',resourceTypeStatistic)
+	let types = []
+	let typeCounts = []
+	ForEach(resourceTypeStatistic, (item) => {
+		types.push(item.resourceTypeName)
+		typeCounts.push(item.num)
+	})
+
+	// types: types,
+	// 	typeCounts: typeCounts,
+	let json = {
+		code: 200,
+		data : {
+			types,
+			typeCounts,
+			typeStorage : []
+		}
+	}
+	return json
+
+	// return new Promise((resolve) => {
+	// 	setTimeout(() => {
+	// 		const mockData = generateMockData(params)
+	// 		resolve(mockData.resourceTypeData)
+	// 	}, Mock.mock('@integer(200, 500)'))
+	// })
 	// return request('/resource-library/type-distribution', params, 'get')
+
 }
 
-export const getDepartmentData = (params = {}) => {
-	return new Promise((resolve) => {
-		setTimeout(() => {
-			const mockData = generateMockData(params)
-			resolve(mockData.departmentData)
-		}, Mock.mock('@integer(200, 500)'))
+export const getDepartmentData = async(params = {}) => {
+	let collegeStatistic = await request('resourceStatistic/collegeStatistic', params, 'get')
+	let departments = []
+	let departmentCounts = []
+	ForEach(collegeStatistic, (item) => {
+		departments.push(item.collegeName)
+		departmentCounts.push(item.num)
 	})
+	let json = {
+		code: 200,
+		data : {
+			departments,
+			departmentCounts,
+			departmentStorage : []
+		}
+	}
+	return json
+
+	// return new Promise((resolve) => {
+	// 	setTimeout(() => {
+	// 		const mockData = generateMockData(params)
+	// 		resolve(mockData.departmentData)
+	// 	}, Mock.mock('@integer(200, 500)'))
+	// })
+	//
+	// departments: departments,
+	// 	departmentCounts: departmentCounts,
+	// 	departmentStorage: departmentCounts.map((count) =>
 	// return request('/resource-library/department-distribution', params, 'get')
 }
 
-export const getVisibilityData = (params = {}) => {
-	return new Promise((resolve) => {
-		setTimeout(() => {
-			const mockData = generateMockData(params)
-			resolve(mockData.visibilityData)
-		}, Mock.mock('@integer(200, 500)'))
-	})
+export const getVisibilityData = async(params = {}) => {
+	// return new Promise((resolve) => {
+	// 	setTimeout(() => {
+	// 		const mockData = generateMockData(params)
+	// 		resolve(mockData.visibilityData)
+	// 	}, Mock.mock('@integer(200, 500)'))
+	// })
+	let collegeStatistic = await request('resourceStatistic/collegeStatistic', params, 'get')
+
+
+	// data: {
+	// 	visibility: ['公开', '非公开'],
+	// 		visibilityCounts: [
+	// 		Math.floor(adjustedTotalResources * 0.75), // 75%公开
+	// 		Math.floor(adjustedTotalResources * 0.25) // 25%非公开
+	// 	],
+	// 		hotness: ['热门', '非热门'],
+	// 		hotnessCounts: [
+	// 		Math.floor(adjustedTotalResources * 0.2), // 20%热门
+	// 		Math.floor(adjustedTotalResources * 0.8) // 80%非热门
+	// 	],
+	// 		recommended: ['已推荐', '未推荐'],
+	// 		recommendedCounts: [
+	// 		Math.floor(adjustedTotalResources * 0.15), // 15%已推荐
+	// 		Math.floor(adjustedTotalResources * 0.85) // 85%未推荐
+	// 	]
+	// }
+
+
+
+
 	// return request('/resource-library/visibility-analysis', params, 'get')
 }
 

+ 24 - 15
src/views/statisticalAnalysis/statisticalAnalysisResourceLibrary/index.vue

@@ -41,21 +41,16 @@
 					style="width: 150px; margin-right: 20px"
 					@change="handleDepartmentChange"
 				>
-					<a-select-option value="all">全部院系</a-select-option>
-					<a-select-option value="aviation">航空学院</a-select-option>
-					<a-select-option value="military">军事管理系</a-select-option>
-					<a-select-option value="politics">政治工作部</a-select-option>
-					<a-select-option value="maintenance">地面维修中心</a-select-option>
-					<a-select-option value="other">其他部门</a-select-option>
+					<a-select-option :value="item.id" v-for="(item, index) in filterData">{{item.name}}</a-select-option>
 				</a-select>
 
 				<label>时间范围:</label>
 				<a-select v-model:value="filters.timeRange" style="width: 120px" @change="handleTimeChange">
 					<a-select-option value="all">全部时间</a-select-option>
-					<a-select-option value="30">最近30天</a-select-option>
-					<a-select-option value="90">最近90天</a-select-option>
-					<a-select-option value="180">最近180天</a-select-option>
-					<a-select-option value="365">最近1年</a-select-option>
+					<a-select-option value="1">最近30天</a-select-option>
+					<a-select-option value="2">最近90天</a-select-option>
+					<a-select-option value="3">最近180天</a-select-option>
+					<a-select-option value="4">最近1年</a-select-option>
 				</a-select>
 			</div>
 
@@ -134,7 +129,7 @@
 		getVisibilityData,
 		getFormatData,
 		getEngagementData,
-		getTrendData
+		getTrendData, getFilterData
 	} from '@/api/statisticalAnalysis/statisticalAnalysisResourceLibrary'
 
 	// 响应式数据
@@ -146,6 +141,7 @@
 		totalViews: '0',
 		totalFavorites: '0'
 	})
+	const filterData = ref([])
 
 	const filters = ref({
 		department: 'all',
@@ -209,6 +205,7 @@
 		try {
 			// 并行加载所有数据
 			const [
+				filterResponse,
 				summaryResponse,
 				typeResponse,
 				departmentResponse,
@@ -217,6 +214,7 @@
 				engagementResponse,
 				trendResponse
 			] = await Promise.all([
+				getFilterData(),
 				getSummaryData(getFilterParams()),
 				getResourceTypeData(getFilterParams()),
 				getDepartmentData(getFilterParams()),
@@ -225,7 +223,9 @@
 				getEngagementData(getFilterParams()),
 				getTrendData(getFilterParams())
 			])
-
+			if(filterResponse.code === 200){
+				filterData.value = filterResponse.data
+			}
 			// 更新摘要数据
 			if (summaryResponse.code === 200) {
 				summaryData.value = summaryResponse.data
@@ -237,6 +237,11 @@
 				chartData.value.types = types
 				chartData.value.typeCounts = typeCounts
 				chartData.value.typeStorage = typeStorage
+
+				console.log('现在获取到的 types',chartData.value.types)
+				console.log('现在获取到的 typeCounts',chartData.value.typeCounts)
+				console.log('现在获取到的 typeStorage',chartData.value.typeStorage)
+
 			}
 
 			if (departmentResponse.code === 200) {
@@ -285,10 +290,14 @@
 
 	// 获取筛选参数
 	const getFilterParams = () => {
-		return {
-			department: filters.value.department,
-			timeRange: filters.value.timeRange
+		let json = JSON.parse(JSON.stringify(filters.value))
+		if(filters.value.department == 'all'){
+			json.department = undefined
+		}
+		if(filters.value.timeRange == 'all'){
+			json.timeRange = undefined
 		}
+		return json
 	}
 
 	// 获取或创建图表实例