From 89d1c9c571ae2faea9457569747fa42ec01b5271 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Sun, 6 Nov 2022 22:08:45 +0800 Subject: [PATCH] core: Add data source radar map within 7 days --- .../user/PluginAuditAdminController.java | 7 ++ .../server/itransient/ContributionRadar.java | 17 ++++ .../repository/PluginAuditRepository.java | 7 ++ .../server/service/PluginAuditService.java | 3 + .../service/impl/PluginAuditServiceImpl.java | 21 +++++ web/console-fe/package.json | 1 + .../src/charts/calendar/CalendarChart.vue | 30 +------ web/console-fe/src/charts/radar/Radar.ts | 6 ++ .../src/charts/radar/RadarChart.vue | 80 +++++++++++++++++++ web/console-fe/src/i18n/langs/en/index.ts | 4 +- web/console-fe/src/i18n/langs/en/profile.ts | 3 + web/console-fe/src/i18n/langs/zhCn/index.ts | 4 +- web/console-fe/src/i18n/langs/zhCn/profile.ts | 3 + web/console-fe/src/services/AdminService.ts | 5 ++ .../src/views/pages/profile/ProfileIndex.vue | 48 ++++++++--- .../pages/profile/layout/ProfileLayout.vue | 2 +- 16 files changed, 198 insertions(+), 43 deletions(-) create mode 100644 server/src/main/java/io/edurt/datacap/server/itransient/ContributionRadar.java create mode 100644 web/console-fe/src/charts/radar/Radar.ts create mode 100644 web/console-fe/src/charts/radar/RadarChart.vue create mode 100644 web/console-fe/src/i18n/langs/en/profile.ts create mode 100644 web/console-fe/src/i18n/langs/zhCn/profile.ts diff --git a/server/src/main/java/io/edurt/datacap/server/controller/user/PluginAuditAdminController.java b/server/src/main/java/io/edurt/datacap/server/controller/user/PluginAuditAdminController.java index 5273f98e..6dd1d382 100644 --- a/server/src/main/java/io/edurt/datacap/server/controller/user/PluginAuditAdminController.java +++ b/server/src/main/java/io/edurt/datacap/server/controller/user/PluginAuditAdminController.java @@ -2,6 +2,7 @@ package io.edurt.datacap.server.controller.user; import io.edurt.datacap.server.common.Response; import io.edurt.datacap.server.itransient.ContributionHistory; +import io.edurt.datacap.server.itransient.ContributionRadar; import io.edurt.datacap.server.service.PluginAuditService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,4 +32,10 @@ public class PluginAuditAdminController { return this.pluginAuditService.getAllContribution(); } + + @GetMapping(value = "radar") + public Response> radar() + { + return this.pluginAuditService.getContributionRadar(); + } } diff --git a/server/src/main/java/io/edurt/datacap/server/itransient/ContributionRadar.java b/server/src/main/java/io/edurt/datacap/server/itransient/ContributionRadar.java new file mode 100644 index 00000000..f358f4fe --- /dev/null +++ b/server/src/main/java/io/edurt/datacap/server/itransient/ContributionRadar.java @@ -0,0 +1,17 @@ +package io.edurt.datacap.server.itransient; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Data +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ContributionRadar +{ + private Long count; + private String label; + private Double percentage; +} diff --git a/server/src/main/java/io/edurt/datacap/server/repository/PluginAuditRepository.java b/server/src/main/java/io/edurt/datacap/server/repository/PluginAuditRepository.java index e32c8083..e74d46f2 100644 --- a/server/src/main/java/io/edurt/datacap/server/repository/PluginAuditRepository.java +++ b/server/src/main/java/io/edurt/datacap/server/repository/PluginAuditRepository.java @@ -49,4 +49,11 @@ public interface PluginAuditRepository " ) AS tbr ON tbl._date = tbr.create_time\n" + "GROUP BY tbl._date", nativeQuery = true) List> selectContributionByUserId(Long id); + + @Query(value = "SELECT count(1) AS dataOfCount, s.name AS dataOfLabel\n" + + "FROM audit_plugin AS ap\n" + + "LEFT JOIN source AS s ON ap.plugin_id = s.id\n" + + "WHERE date_sub(curdate(), interval 7 day) <= date(ap.create_time)\n" + + "GROUP BY s._type", nativeQuery = true) + List> selectRadarByUserId(Long id); } diff --git a/server/src/main/java/io/edurt/datacap/server/service/PluginAuditService.java b/server/src/main/java/io/edurt/datacap/server/service/PluginAuditService.java index 5a2379ab..47e378f6 100644 --- a/server/src/main/java/io/edurt/datacap/server/service/PluginAuditService.java +++ b/server/src/main/java/io/edurt/datacap/server/service/PluginAuditService.java @@ -4,6 +4,7 @@ import io.edurt.datacap.server.common.Response; import io.edurt.datacap.server.entity.PageEntity; import io.edurt.datacap.server.entity.PluginAuditEntity; import io.edurt.datacap.server.itransient.ContributionHistory; +import io.edurt.datacap.server.itransient.ContributionRadar; import java.util.List; @@ -14,4 +15,6 @@ public interface PluginAuditService Response count(); Response> getAllContribution(); + + Response> getContributionRadar(); } diff --git a/server/src/main/java/io/edurt/datacap/server/service/impl/PluginAuditServiceImpl.java b/server/src/main/java/io/edurt/datacap/server/service/impl/PluginAuditServiceImpl.java index 67589699..f8a3d83f 100644 --- a/server/src/main/java/io/edurt/datacap/server/service/impl/PluginAuditServiceImpl.java +++ b/server/src/main/java/io/edurt/datacap/server/service/impl/PluginAuditServiceImpl.java @@ -6,14 +6,17 @@ import io.edurt.datacap.server.entity.PageEntity; import io.edurt.datacap.server.entity.PluginAuditEntity; import io.edurt.datacap.server.entity.UserEntity; import io.edurt.datacap.server.itransient.ContributionHistory; +import io.edurt.datacap.server.itransient.ContributionRadar; import io.edurt.datacap.server.repository.PluginAuditRepository; import io.edurt.datacap.server.security.UserDetailsService; import io.edurt.datacap.server.service.PluginAuditService; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Service public class PluginAuditServiceImpl @@ -57,4 +60,22 @@ public class PluginAuditServiceImpl }); return Response.success(contributions); } + + @Override + public Response> getContributionRadar() + { + UserEntity user = UserDetailsService.getUser(); + List contributionRadars = new ArrayList<>(); + List> list = this.pluginAuditRepository.selectRadarByUserId(user.getId()); + Long count = list.stream().mapToLong(v -> Long.valueOf(String.valueOf(v.get("dataOfCount")))).sum(); + list.forEach(v -> { + ContributionRadar radar = new ContributionRadar(); + radar.setLabel(String.valueOf(v.get("dataOfLabel"))); + radar.setCount(Long.valueOf(String.valueOf(v.get("dataOfCount")))); + BigDecimal bigDecimal = new BigDecimal(Double.valueOf(radar.getCount()) / Double.valueOf(count)); + radar.setPercentage(bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100.0); + contributionRadars.add(radar); + }); + return Response.success(contributionRadars); + } } diff --git a/web/console-fe/package.json b/web/console-fe/package.json index c8cf07bd..7692641d 100644 --- a/web/console-fe/package.json +++ b/web/console-fe/package.json @@ -10,6 +10,7 @@ "lint": "vue-cli-service lint" }, "dependencies": { + "@antv/data-set": "^0.11.8", "@antv/g2": "^4.2.8", "@antv/s2": "^1.30.0", "@antv/s2-vue": "^1.3.0", diff --git a/web/console-fe/src/charts/calendar/CalendarChart.vue b/web/console-fe/src/charts/calendar/CalendarChart.vue index d1e20993..ec6ba0cb 100644 --- a/web/console-fe/src/charts/calendar/CalendarChart.vue +++ b/web/console-fe/src/charts/calendar/CalendarChart.vue @@ -6,7 +6,6 @@ import {defineComponent, PropType} from "vue"; import {Chart, IGroup, registerShape} from "@antv/g2"; import {RangePoint, ShapeInfo} from "@antv/g2/lib/interface"; import {ShapeCfg} from "@antv/g-base/src/types"; -import {Data} from "@antv/s2"; import {Calendar} from "@/charts/calendar/Calendar"; export default defineComponent({ @@ -46,33 +45,6 @@ export default defineComponent({ group.addShape('path', { attrs }); - const dat = cfg.data as Data; - if (dat.lastWeek) { - const linePath = [ - ['M', points[2].x, points[2].y], - ['L', points[3].x, points[3].y] - ]; - // Add the right border for the last week's polygon - group.addShape('path', { - attrs: { - path: this.parsePath(linePath), - lineWidth: 4, - stroke: '#404040' - } - }); - if (dat.lastDay) { - group.addShape('path', { - attrs: { - path: this.parsePath([ - ['M', points[1].x, points[1].y], - ['L', points[2].x, points[2].y] - ]), - lineWidth: 2, - stroke: '#404040' - } - }); - } - } return group; } }); @@ -109,7 +81,7 @@ export default defineComponent({ }); chart.coordinate().reflect('y'); chart.polygon().position('week*day*date') - .color('count', '#BAE7FF-#1890FF-#0050B3') + .color('count', '#F0F0F2-#6bd08d-#023915') .shape('boundary-polygon'); chart.interaction('element-active'); chart.render(); diff --git a/web/console-fe/src/charts/radar/Radar.ts b/web/console-fe/src/charts/radar/Radar.ts new file mode 100644 index 00000000..266b196d --- /dev/null +++ b/web/console-fe/src/charts/radar/Radar.ts @@ -0,0 +1,6 @@ +export interface Radar +{ + label: string; + percentage: number; + value: number; +} diff --git a/web/console-fe/src/charts/radar/RadarChart.vue b/web/console-fe/src/charts/radar/RadarChart.vue new file mode 100644 index 00000000..04a69057 --- /dev/null +++ b/web/console-fe/src/charts/radar/RadarChart.vue @@ -0,0 +1,80 @@ + + diff --git a/web/console-fe/src/i18n/langs/en/index.ts b/web/console-fe/src/i18n/langs/en/index.ts index d40d95c3..03eb020c 100644 --- a/web/console-fe/src/i18n/langs/en/index.ts +++ b/web/console-fe/src/i18n/langs/en/index.ts @@ -3,11 +3,13 @@ import common from "@/i18n/langs/en/common"; import required from "@/i18n/langs/en/required"; import tooltip from "@/i18n/langs/en/tooltip"; import settings from "@/i18n/langs/en/settings"; +import profile from "@/i18n/langs/en/profile"; export default { ...enGB, common: common, required: required, tooltip: tooltip, - setting: settings + setting: settings, + profile: profile } diff --git a/web/console-fe/src/i18n/langs/en/profile.ts b/web/console-fe/src/i18n/langs/en/profile.ts new file mode 100644 index 00000000..41493615 --- /dev/null +++ b/web/console-fe/src/i18n/langs/en/profile.ts @@ -0,0 +1,3 @@ +export default { + radar7Days: 'Data source radar map within 7 days' +} diff --git a/web/console-fe/src/i18n/langs/zhCn/index.ts b/web/console-fe/src/i18n/langs/zhCn/index.ts index b317253e..c7a4cb4c 100644 --- a/web/console-fe/src/i18n/langs/zhCn/index.ts +++ b/web/console-fe/src/i18n/langs/zhCn/index.ts @@ -3,11 +3,13 @@ import common from "@/i18n/langs/zhCn/common"; import required from "@/i18n/langs/zhCn/required"; import tooltip from "@/i18n/langs/zhCn/tooltip"; import settings from "@/i18n/langs/zhCn/settings"; +import profile from "@/i18n/langs/zhCn/profile"; export default { ...zhCN, common: common, required: required, tooltip: tooltip, - setting: settings + setting: settings, + profile: profile } diff --git a/web/console-fe/src/i18n/langs/zhCn/profile.ts b/web/console-fe/src/i18n/langs/zhCn/profile.ts new file mode 100644 index 00000000..c3465449 --- /dev/null +++ b/web/console-fe/src/i18n/langs/zhCn/profile.ts @@ -0,0 +1,3 @@ +export default { + radar7Days: '7天内数据源雷达图' +} diff --git a/web/console-fe/src/services/AdminService.ts b/web/console-fe/src/services/AdminService.ts index 48889dba..b5a1663a 100644 --- a/web/console-fe/src/services/AdminService.ts +++ b/web/console-fe/src/services/AdminService.ts @@ -20,4 +20,9 @@ export class AdminService { return new HttpCommon().get(pluginHistoryAdmin + '/contribution'); } + + getUserContributionRadar() + { + return new HttpCommon().get(pluginHistoryAdmin + '/radar'); + } } diff --git a/web/console-fe/src/views/pages/profile/ProfileIndex.vue b/web/console-fe/src/views/pages/profile/ProfileIndex.vue index 8a39bc10..b3e9961b 100644 --- a/web/console-fe/src/views/pages/profile/ProfileIndex.vue +++ b/web/console-fe/src/views/pages/profile/ProfileIndex.vue @@ -1,26 +1,44 @@