statisticalAnalysisResourceLibrary.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. import { moduleRequest } from '@/utils/request'
  2. import Mock from 'mockjs'
  3. import ForEach from "lodash-es/forEach";
  4. const request = moduleRequest(`/api/webapp/`)
  5. // 使用 Mock.js 生成动态数据
  6. const generateMockData = (filters = {}) => {
  7. const Random = Mock.Random
  8. // 基础数据模板
  9. const types = ['航空教学', '部队管理', '政治工作', '地面维修', '其他']
  10. const departments = ['航空学院', '军事管理系', '政治工作部', '地面维修中心', '其他部门']
  11. const formats = ['mp4', 'pdf', 'docx', 'pptx', 'xlsx', 'jpg', 'avi', 'wmv', 'mkv', 'other']
  12. const months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月']
  13. // 根据筛选条件调整数据规模
  14. const getScaleFactor = () => {
  15. if (filters.department === 'all') return 1.0
  16. return 0.15 + Math.random() * 0.25 // 单个院系占总数的15%-40%
  17. }
  18. const scaleFactor = getScaleFactor()
  19. // 固定总容量为10TB,已使用空间根据筛选条件调整
  20. const TOTAL_CAPACITY = 10.0 // 固定总容量10TB
  21. // 生成合理的基础总数
  22. const baseTotalResources = Mock.mock('@integer(1500, 2500)')
  23. const baseUsedStorage = Mock.mock('@float(4.0, 8.0, 1, 1)') // 已使用4-8TB
  24. const baseViews = Mock.mock('@integer(80000, 200000)')
  25. const baseFavorites = Mock.mock('@integer(15000, 40000)')
  26. // 根据筛选条件调整摘要数据
  27. const adjustedTotalResources = Math.floor(baseTotalResources * scaleFactor)
  28. const adjustedUsedStorage = (baseUsedStorage * scaleFactor).toFixed(1)
  29. const adjustedViews = Math.floor(baseViews * scaleFactor)
  30. const adjustedFavorites = Math.floor(baseFavorites * scaleFactor)
  31. // 生成资源类型分布 - 确保航空教学占主导地位
  32. const generateTypeCounts = () => {
  33. const total = adjustedTotalResources
  34. const counts = []
  35. // 航空教学占40-50%
  36. counts[0] = Math.floor(total * (0.4 + Math.random() * 0.1))
  37. // 其他类型按比例分配剩余资源
  38. const remaining = total - counts[0]
  39. const ratios = [0.25, 0.2, 0.15, 0.1] // 部队管理、政治工作、地面维修、其他
  40. for (let i = 1; i < types.length - 1; i++) {
  41. counts[i] = Math.floor(remaining * ratios[i - 1] * (0.8 + Math.random() * 0.4))
  42. }
  43. // 最后一项为剩余数量
  44. counts[types.length - 1] = total - counts.slice(0, -1).reduce((sum, count) => sum + count, 0)
  45. return counts
  46. }
  47. // 生成院系分布 - 确保航空学院占主导地位
  48. const generateDepartmentCounts = () => {
  49. const total = adjustedTotalResources
  50. const counts = []
  51. // 航空学院占45-55%
  52. counts[0] = Math.floor(total * (0.45 + Math.random() * 0.1))
  53. // 其他院系按比例分配
  54. const remaining = total - counts[0]
  55. const ratios = [0.2, 0.18, 0.15, 0.12] // 军事管理系、政治工作部、地面维修中心、其他部门
  56. for (let i = 1; i < departments.length - 1; i++) {
  57. counts[i] = Math.floor(remaining * ratios[i - 1] * (0.8 + Math.random() * 0.4))
  58. }
  59. counts[departments.length - 1] = total - counts.slice(0, -1).reduce((sum, count) => sum + count, 0)
  60. return counts
  61. }
  62. // 生成文件格式分布 - 视频和文档类型占主导
  63. const generateFormatCounts = () => {
  64. const total = adjustedTotalResources
  65. const counts = new Array(formats.length).fill(0)
  66. // 主要格式占比
  67. const mainFormats = {
  68. mp4: 0.25, // 视频最多
  69. pdf: 0.2, // PDF文档
  70. docx: 0.15, // Word文档
  71. pptx: 0.12, // PPT
  72. jpg: 0.08, // 图片
  73. avi: 0.06, // 其他视频格式
  74. xlsx: 0.05, // Excel
  75. wmv: 0.04, // 视频格式
  76. mkv: 0.03, // 视频格式
  77. other: 0.02 // 其他格式
  78. }
  79. formats.forEach((format, index) => {
  80. const ratio = mainFormats[format] || 0.01
  81. counts[index] = Math.floor(total * ratio * (0.8 + Math.random() * 0.4))
  82. })
  83. // 确保总数匹配
  84. const currentTotal = counts.reduce((sum, count) => sum + count, 0)
  85. const diff = total - currentTotal
  86. counts[0] += diff // 将差值加到mp4上
  87. return counts
  88. }
  89. const typeCounts = generateTypeCounts()
  90. const departmentCounts = generateDepartmentCounts()
  91. const formatCounts = generateFormatCounts()
  92. return {
  93. filterResponse : getFilterData(),
  94. // 摘要数据
  95. summaryData: {
  96. code: 200,
  97. data: {
  98. totalResources: adjustedTotalResources.toLocaleString(),
  99. totalStorage: `${adjustedUsedStorage} TB`,
  100. totalCapacity: `${TOTAL_CAPACITY} TB`,
  101. usageRate: `${((parseFloat(adjustedUsedStorage) / TOTAL_CAPACITY) * 100).toFixed(0)}%`,
  102. totalViews: adjustedViews.toLocaleString(),
  103. totalFavorites: adjustedFavorites.toLocaleString()
  104. }
  105. },
  106. // 资源类型分布数据
  107. resourceTypeData: {
  108. code: 200,
  109. data: {
  110. types: types,
  111. typeCounts: typeCounts,
  112. typeStorage: typeCounts.map((count) =>
  113. ((count / adjustedTotalResources) * parseFloat(adjustedUsedStorage)).toFixed(1)
  114. )
  115. }
  116. },
  117. // 院系分布数据
  118. departmentData: {
  119. code: 200,
  120. data: {
  121. departments: departments,
  122. departmentCounts: departmentCounts,
  123. departmentStorage: departmentCounts.map((count) =>
  124. ((count / adjustedTotalResources) * parseFloat(adjustedUsedStorage)).toFixed(1)
  125. )
  126. }
  127. },
  128. // 可见性和热度数据
  129. visibilityData: {
  130. code: 200,
  131. data: {
  132. visibility: ['公开', '非公开'],
  133. visibilityCounts: [
  134. Math.floor(adjustedTotalResources * 0.75), // 75%公开
  135. Math.floor(adjustedTotalResources * 0.25) // 25%非公开
  136. ],
  137. hotness: ['热门', '非热门'],
  138. hotnessCounts: [
  139. Math.floor(adjustedTotalResources * 0.2), // 20%热门
  140. Math.floor(adjustedTotalResources * 0.8) // 80%非热门
  141. ],
  142. recommended: ['已推荐', '未推荐'],
  143. recommendedCounts: [
  144. Math.floor(adjustedTotalResources * 0.15), // 15%已推荐
  145. Math.floor(adjustedTotalResources * 0.85) // 85%未推荐
  146. ]
  147. }
  148. },
  149. // 文件格式数据
  150. formatData: {
  151. code: 200,
  152. data: {
  153. formats: formats,
  154. formatCounts: formatCounts,
  155. formatStorage: formatCounts.map((count) =>
  156. ((count / adjustedTotalResources) * parseFloat(adjustedUsedStorage)).toFixed(2)
  157. ),
  158. formatAvgSize: formats.map((format, index) => {
  159. // 根据文件类型设置合理的平均大小
  160. const sizeMap = {
  161. mp4: Mock.mock('@integer(200, 800)'),
  162. avi: Mock.mock('@integer(300, 1000)'),
  163. wmv: Mock.mock('@integer(150, 600)'),
  164. mkv: Mock.mock('@integer(400, 1200)'),
  165. pdf: Mock.mock('@integer(5, 50)'),
  166. docx: Mock.mock('@integer(2, 20)'),
  167. pptx: Mock.mock('@integer(10, 100)'),
  168. xlsx: Mock.mock('@integer(1, 15)'),
  169. jpg: Mock.mock('@integer(1, 10)'),
  170. other: Mock.mock('@integer(5, 200)')
  171. }
  172. const size = sizeMap[format] || Mock.mock('@integer(1, 100)')
  173. if (size > 1000) return `${(size / 1000).toFixed(1)}GB`
  174. return `${size}MB`
  175. })
  176. }
  177. },
  178. // 用户参与度数据
  179. engagementData: {
  180. code: 200,
  181. data: {
  182. engagement: ['观看', '收藏', '分享'],
  183. engagementCounts: [
  184. adjustedViews,
  185. adjustedFavorites,
  186. Math.floor(adjustedFavorites * 0.3) // 分享数约为收藏数的30%
  187. ],
  188. typeViewCounts: typeCounts.map((count) => Math.floor(count * (2 + Math.random() * 3))) // 每个资源平均2-5次观看
  189. }
  190. },
  191. // 时间趋势数据
  192. trendData: {
  193. code: 200,
  194. data: {
  195. trendLabels: months,
  196. uploadTrend: months.map(() => Math.floor((adjustedTotalResources / 12) * (0.6 + Math.random() * 0.8))), // 月均上传量有波动
  197. viewTrend: months.map(() => Math.floor((adjustedViews / 12) * (0.7 + Math.random() * 0.6))) // 月均观看量有波动
  198. }
  199. }
  200. }
  201. }
  202. // API函数 - 每次调用都生成新的动态数据,传入筛选参数
  203. export const getSummaryData = async (params = {}) => {
  204. // return new Promise((resolve) => {
  205. // setTimeout(() => {
  206. // const mockData = generateMockData(params)
  207. // resolve(mockData.summaryData)
  208. // }, Mock.mock('@integer(200, 500)')) // 随机延迟
  209. // })
  210. let res = await request('/resourceStatistic/totalStatistic', params, 'get')
  211. console.log('什么呢1233',res)
  212. let json = {
  213. code : 200,
  214. data : {
  215. totalResources : res.RESOURCE_TOTAL,
  216. totalStorage : `${kbToTb(res.storageSize)}TB`,
  217. totalCapacity : `${kbToTb(res.totalStorageSize)}TB`,
  218. usageRate : `${((parseFloat(res.storageSize) / res.totalStorageSize) * 100).toFixed(0)}%`,
  219. totalViews : res.WATCH_TOTAL,
  220. totalFavorites : res.COLLECT_TOTAL
  221. }
  222. }
  223. // {
  224. // "RESOURCE_TOTAL": 34, 总资源数
  225. // "TOTAL_STORAGE_SIZE": 20480, 总存储空间
  226. // "COLLECT_TOTAL": 9, 总收藏数
  227. // "WATCH_TOTAL": 471, 总观看数
  228. // "storageSize": 1726487824,
  229. // "totalStorageSize": 21474836480
  230. // }
  231. // totalResources: '0',
  232. // totalStorage: '0 TB',
  233. // totalCapacity: '10 TB',
  234. // usageRate: '0%',
  235. // totalViews: '0',
  236. // totalFavorites: '0'
  237. // 真实接口调用:
  238. // return request('/resource-library/summary', params, 'get')
  239. console.log('什么呢',json)
  240. return json
  241. }
  242. function kbToTb(kb) {
  243. const tb = kb / 1073741824;
  244. return parseFloat(tb.toFixed(2));
  245. }
  246. export const getFilterData = async (params = {}) => {
  247. let colleges = await request('resourceStatistic/selectOrgList', params, 'get')
  248. colleges.unshift({
  249. id : 'all',
  250. name : '全部院系'
  251. })
  252. console.log("什么呢sss",colleges)
  253. let json = {
  254. code: 200,
  255. data : colleges
  256. }
  257. return json
  258. }
  259. export const getResourceTypeData = async (params = {}) => {
  260. let resourceTypeStatistic = await request('resourceStatistic/resourceTypeStatistic', params, 'get')
  261. console.log('左面的',resourceTypeStatistic)
  262. let types = []
  263. let typeCounts = []
  264. ForEach(resourceTypeStatistic, (item) => {
  265. types.push(item.resourceTypeName)
  266. typeCounts.push(item.num)
  267. })
  268. // types: types,
  269. // typeCounts: typeCounts,
  270. let json = {
  271. code: 200,
  272. data : {
  273. types,
  274. typeCounts,
  275. typeStorage : []
  276. }
  277. }
  278. return json
  279. // return new Promise((resolve) => {
  280. // setTimeout(() => {
  281. // const mockData = generateMockData(params)
  282. // resolve(mockData.resourceTypeData)
  283. // }, Mock.mock('@integer(200, 500)'))
  284. // })
  285. // return request('/resource-library/type-distribution', params, 'get')
  286. }
  287. export const getDepartmentData = async(params = {}) => {
  288. let collegeStatistic = await request('resourceStatistic/collegeStatistic', params, 'get')
  289. let departments = []
  290. let departmentCounts = []
  291. ForEach(collegeStatistic, (item) => {
  292. departments.push(item.collegeName)
  293. departmentCounts.push(item.num)
  294. })
  295. let json = {
  296. code: 200,
  297. data : {
  298. departments,
  299. departmentCounts,
  300. departmentStorage : []
  301. }
  302. }
  303. return json
  304. // return new Promise((resolve) => {
  305. // setTimeout(() => {
  306. // const mockData = generateMockData(params)
  307. // resolve(mockData.departmentData)
  308. // }, Mock.mock('@integer(200, 500)'))
  309. // })
  310. //
  311. // departments: departments,
  312. // departmentCounts: departmentCounts,
  313. // departmentStorage: departmentCounts.map((count) =>
  314. // return request('/resource-library/department-distribution', params, 'get')
  315. }
  316. export const getVisibilityData = async(params = {}) => {
  317. // return new Promise((resolve) => {
  318. // setTimeout(() => {
  319. // const mockData = generateMockData(params)
  320. // resolve(mockData.visibilityData)
  321. // }, Mock.mock('@integer(200, 500)'))
  322. // })
  323. let resourcePublicStatistic = await request('resourceStatistic/resourcePublicStatistic', params, 'get')
  324. let visibility = ['非公开','公开']
  325. let visibilityCounts = []
  326. ForEach(resourcePublicStatistic, (item) => {
  327. visibilityCounts.push(item.num)
  328. })
  329. let hotness = []
  330. let hotnessCounts = []
  331. let recommended = ['已推荐', '未推荐']
  332. let hotStatistic = await request('resourceStatistic/hotStatistic', params, 'get')
  333. ForEach(hotStatistic, (item) => {
  334. //1推荐 2热门 3推荐和热门
  335. if(item.type == 1){
  336. hotness.push('推荐')
  337. }
  338. if(item.type == 2){
  339. hotness.push('热门')
  340. }
  341. if(item.type == 3){
  342. hotness.push('推荐和热门')
  343. }
  344. hotnessCounts.push(item.num)
  345. })
  346. console.log('接口看看',hotStatistic)
  347. let recommendedCounts = [12,13]
  348. let json = {
  349. code: 200,
  350. data : {
  351. visibility,
  352. visibilityCounts,
  353. hotness,
  354. hotnessCounts,
  355. recommended,
  356. recommendedCounts
  357. }
  358. }
  359. return json
  360. // data: {
  361. // visibility: ['公开', '非公开'],
  362. // visibilityCounts: [
  363. // Math.floor(adjustedTotalResources * 0.75), // 75%公开
  364. // Math.floor(adjustedTotalResources * 0.25) // 25%非公开
  365. // ],
  366. // hotness: ['热门', '非热门'],
  367. // hotnessCounts: [
  368. // Math.floor(adjustedTotalResources * 0.2), // 20%热门
  369. // Math.floor(adjustedTotalResources * 0.8) // 80%非热门
  370. // ],
  371. // recommended: ['已推荐', '未推荐'],
  372. // recommendedCounts: [
  373. // Math.floor(adjustedTotalResources * 0.15), // 15%已推荐
  374. // Math.floor(adjustedTotalResources * 0.85) // 85%未推荐
  375. // ]
  376. // }
  377. // return request('/resource-library/visibility-analysis', params, 'get')
  378. }
  379. export const getFormatData = async(params = {}) => {
  380. // return new Promise((resolve) => {
  381. // setTimeout(() => {
  382. // const mockData = generateMockData(params)
  383. // resolve(mockData.formatData)
  384. // }, Mock.mock('@integer(200, 500)'))
  385. // })
  386. let formatStatistic = await request('resourceStatistic/formatStatistic', params, 'get')
  387. let formats = []
  388. let formatCounts = []
  389. ForEach(formatStatistic, (item) => {
  390. formats.push(item.extendName)
  391. formatCounts.push(item.num)
  392. })
  393. let storageStatistic = await request('resourceStatistic/storageStatistic', params, 'get')
  394. console.log('内存',storageStatistic)
  395. let formatAvgSize = []
  396. ForEach(storageStatistic, (item) => {
  397. formatAvgSize.push(item.extendName)
  398. })
  399. let json = {
  400. code: 200,
  401. data : {
  402. formats,
  403. formatCounts,
  404. formatStorage: storageStatistic.map((item) => {
  405. let size = (item.FILESIZE) * parseFloat(1).toFixed(2)
  406. console.log("asdasd",item.FILESIZE)
  407. return `${(item.FILESIZE/1000/1000).toFixed(2)}`
  408. }
  409. ),
  410. formatAvgSize: storageStatistic.map((format, index) => {
  411. // 根据文件类型设置合理的平均大小
  412. const size = format.avgSize
  413. // if (size > 1000) return `${(size / 1000).toFixed(1)}MB`
  414. return `${(size/1000/1000).toFixed(2)}MB`
  415. })
  416. }
  417. }
  418. return json
  419. // formatData: {
  420. // code: 200,
  421. // data: {
  422. // formats: formats,
  423. // formatCounts: formatCounts,
  424. // formatStorage: formatCounts.map((count) =>
  425. // ((count / adjustedTotalResources) * parseFloat(adjustedUsedStorage)).toFixed(2)
  426. // ),
  427. // formatAvgSize: formats.map((format, index) => {
  428. // // 根据文件类型设置合理的平均大小
  429. // const sizeMap = {
  430. // mp4: Mock.mock('@integer(200, 800)'),
  431. // avi: Mock.mock('@integer(300, 1000)'),
  432. // wmv: Mock.mock('@integer(150, 600)'),
  433. // mkv: Mock.mock('@integer(400, 1200)'),
  434. // pdf: Mock.mock('@integer(5, 50)'),
  435. // docx: Mock.mock('@integer(2, 20)'),
  436. // pptx: Mock.mock('@integer(10, 100)'),
  437. // xlsx: Mock.mock('@integer(1, 15)'),
  438. // jpg: Mock.mock('@integer(1, 10)'),
  439. // other: Mock.mock('@integer(5, 200)')
  440. // }
  441. //
  442. // const size = sizeMap[format] || Mock.mock('@integer(1, 100)')
  443. // if (size > 1000) return `${(size / 1000).toFixed(1)}GB`
  444. // return `${size}MB`
  445. // })
  446. // }
  447. // },
  448. // return request('/resource-library/format-distribution', params, 'get')
  449. }
  450. export const getEngagementData = async(params = {}) => {
  451. // return new Promise((resolve) => {
  452. // setTimeout(() => {
  453. // const mockData = generateMockData(params)
  454. // resolve(mockData.engagementData)
  455. // }, Mock.mock('@integer(200, 500)'))
  456. // })
  457. let totalStatistic = await request('resourceStatistic/totalStatistic', params, 'get')
  458. console.log('001 ',totalStatistic)
  459. let json = {
  460. code: 200,
  461. data : {
  462. engagement: ['观看', '收藏', '分享'],
  463. engagementCounts: [
  464. //船锚
  465. ],
  466. }
  467. }
  468. return json
  469. // return request('/resource-library/engagement-analysis', params, 'get')
  470. // 用户参与度数据
  471. // engagementData: {
  472. // code: 200,
  473. // data: {
  474. // engagement: ['观看', '收藏', '分享'],
  475. // engagementCounts: [
  476. // adjustedViews,
  477. // adjustedFavorites,
  478. // Math.floor(adjustedFavorites * 0.3) // 分享数约为收藏数的30%
  479. // ],
  480. // typeViewCounts: typeCounts.map((count) => Math.floor(count * (2 + Math.random() * 3))) // 每个资源平均2-5次观看
  481. // }
  482. // },
  483. }
  484. export const getTrendData = (params = {}) => {
  485. return new Promise((resolve) => {
  486. setTimeout(() => {
  487. const mockData = generateMockData(params)
  488. resolve(mockData.trendData)
  489. }, Mock.mock('@integer(200, 500)'))
  490. })
  491. // return request('/resource-library/trend-analysis', params, 'get')
  492. }