From 9f05383de08ab054aa1755a7189d6b833654f2d3 Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Mon, 25 Oct 2021 00:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=BB=9F=E8=AE=A1=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnifiedMessagingController.java | 72 ++++ .../UnifiedMessagingRouteController.java | 27 ++ .../IUnifiedMessagingService.java | 37 ++ .../service/UnifiedMessagingServiceImpl.java | 184 ++++++++++ .../templates/visual-report/report.html | 323 ++++++++++++++++++ 5 files changed, 643 insertions(+) create mode 100644 src/main/java/cn/com/tenlion/usercenter/controller/api/versualreport/UnifiedMessagingController.java create mode 100644 src/main/java/cn/com/tenlion/usercenter/controller/route/visualreport/UnifiedMessagingRouteController.java create mode 100644 src/main/java/cn/com/tenlion/usercenter/service/visualreport/IUnifiedMessagingService.java create mode 100644 src/main/java/cn/com/tenlion/usercenter/service/visualreport/service/UnifiedMessagingServiceImpl.java create mode 100644 src/main/resources/templates/visual-report/report.html diff --git a/src/main/java/cn/com/tenlion/usercenter/controller/api/versualreport/UnifiedMessagingController.java b/src/main/java/cn/com/tenlion/usercenter/controller/api/versualreport/UnifiedMessagingController.java new file mode 100644 index 0000000..fc7dc16 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/controller/api/versualreport/UnifiedMessagingController.java @@ -0,0 +1,72 @@ +package cn.com.tenlion.usercenter.controller.api.versualreport; + +import cn.com.tenlion.usercenter.service.visualreport.IUnifiedMessagingService; +import ink.wgink.exceptions.ParamsException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.pojo.result.ErrorResult; +import ink.wgink.pojo.result.SuccessResultData; +import ink.wgink.util.RegexUtil; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * @ClassName: UnifiedMessagingCountroller + * @Description: 统一消息统计可视化 + * @Author: wanggeng + * @Date: 2021/10/24 4:04 下午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "统一消息统计可视化接口") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/visual-report/unified-messaging") +public class UnifiedMessagingController { + + @Autowired + private IUnifiedMessagingService unifiedMessagingService; + + @ApiOperation(value = "日发送统计", notes = "日发送统计接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "date", value = "当天", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("day-send-count/{date}") + public SuccessResultData> daySendCount(@PathVariable("date") String date) { + if (!RegexUtil.isDate(date)) { + throw new ParamsException("日期格式错误"); + } + return new SuccessResultData<>(unifiedMessagingService.daySendCount(date)); + } + + @ApiOperation(value = "周发送统计", notes = "周发送统计接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "day", value = "当天", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("week-send-count/{day}") + public SuccessResultData> weekSendCount(@PathVariable("day") String day) { + if (!RegexUtil.isDate(day)) { + throw new ParamsException("日期格式错误"); + } + return new SuccessResultData<>(unifiedMessagingService.weekSendCount(day)); + } + + @ApiOperation(value = "月发送统计", notes = "月发送统计接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "day", value = "当天", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("month-send-count/{day}") + public SuccessResultData> monthSendCount(@PathVariable("day") String day) { + if (!RegexUtil.isDate(day)) { + throw new ParamsException("日期格式错误"); + } + return new SuccessResultData<>(unifiedMessagingService.monthSendCount(day)); + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/controller/route/visualreport/UnifiedMessagingRouteController.java b/src/main/java/cn/com/tenlion/usercenter/controller/route/visualreport/UnifiedMessagingRouteController.java new file mode 100644 index 0000000..d46dea1 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/controller/route/visualreport/UnifiedMessagingRouteController.java @@ -0,0 +1,27 @@ +package cn.com.tenlion.usercenter.controller.route.visualreport; + +import ink.wgink.interfaces.consts.ISystemConstant; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +/** + * @ClassName: UnifiedMessagingRouteController + * @Description: 统一消息统计可视化路由 + * @Author: wanggeng + * @Date: 2021/10/24 3:30 下午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.ROUTE_TAGS_PREFIX + "统一消息统计可视化路由") +@RestController +@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/visual-report/unified-messaging") +public class UnifiedMessagingRouteController { + + @GetMapping("report") + public ModelAndView report() { + return new ModelAndView("visual-report/report"); + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/visualreport/IUnifiedMessagingService.java b/src/main/java/cn/com/tenlion/usercenter/service/visualreport/IUnifiedMessagingService.java new file mode 100644 index 0000000..6fdbbca --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/visualreport/IUnifiedMessagingService.java @@ -0,0 +1,37 @@ +package cn.com.tenlion.usercenter.service.visualreport; + +import java.util.Map; + +/** + * @ClassName: IUnifiedMessagingService + * @Description: 统一消息可视化统计 + * @Author: wanggeng + * @Date: 2021/10/24 4:05 下午 + * @Version: 1.0 + */ +public interface IUnifiedMessagingService { + + /** + * 日发送统计 + * + * @param date + * @return + */ + Map daySendCount(String date); + + /** + * 周发送统计 + * + * @param date + * @return + */ + Map weekSendCount(String date); + + /** + * 月发送统计 + * + * @param date + * @return + */ + Map monthSendCount(String date); +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/visualreport/service/UnifiedMessagingServiceImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/visualreport/service/UnifiedMessagingServiceImpl.java new file mode 100644 index 0000000..081f2e2 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/visualreport/service/UnifiedMessagingServiceImpl.java @@ -0,0 +1,184 @@ +package cn.com.tenlion.usercenter.service.visualreport.service; + +import cn.com.tenlion.usercenter.service.visualreport.IUnifiedMessagingService; +import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.module.instantmessage.pojo.pos.NoticePO; +import ink.wgink.module.instantmessage.service.INoticeService; +import ink.wgink.module.sms.pojo.pos.sms.SmsPO; +import ink.wgink.module.sms.service.sms.ISmsService; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: UnifiedMessagingServiceImpl + * @Description: 统一消息统计 + * @Author: wanggeng + * @Date: 2021/10/24 4:06 下午 + * @Version: 1.0 + */ +@Service +public class UnifiedMessagingServiceImpl extends DefaultBaseService implements IUnifiedMessagingService { + + @Autowired + private ISmsService smsService; + @Autowired + private INoticeService noticeService; + + @Override + public Map daySendCount(String date) { + List smsPOs = smsService.listPOByDate(date); + List noticePOs = noticeService.listPOByDate(date); + + int smsSendCount = smsPOs.size(); + int smsSendSuccessCount = 0; + + int noticeSendCount = noticePOs.size(); + int noticeSendSuccessCount = 0; + + for (SmsPO smsPO : smsPOs) { + if (smsPO.getSendStatus() == 1) { + smsSendSuccessCount++; + } + } + for (NoticePO noticePO : noticePOs) { + if (noticePO.getIsSend() == 1) { + noticeSendSuccessCount++; + } + } + Map resultJsonMap = getHashMap(12); + resultJsonMap.put("smsSendCount", smsSendCount); + resultJsonMap.put("smsSendSuccessCount", smsSendSuccessCount); + resultJsonMap.put("smsSendSuccessPercent", smsSendCount > 0 ? String.format("%.2f", (smsSendSuccessCount / (double) smsSendCount * 100)) : "0.00"); + resultJsonMap.put("noticeSendCount", noticeSendCount); + resultJsonMap.put("noticeSendSuccessCount", noticeSendSuccessCount); + resultJsonMap.put("noticeSendSuccessPercent", noticeSendCount > 0 ? String.format("%.2f", (noticeSendSuccessCount / (double) noticeSendCount * 100)) : "0.00"); + + return resultJsonMap; + } + + @Override + public Map weekSendCount(String date) { + DateTime dateDateTime = DateTime.parse(date, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DateTime firstDateTime = dateDateTime.dayOfWeek().withMinimumValue(); + String startTime = firstDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DateTime endDateTime = dateDateTime.dayOfWeek().withMaximumValue(); + String endTime = endDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + + List smsPOs = smsService.listPOByStartTimeAndEndTime(startTime, endTime); + List noticePOs = noticeService.listPOByStartTimeAndEndTime(startTime, endTime); + + List xDatas = new ArrayList<>(); + List ySmsSendDatas = new ArrayList<>(); + List ySmsSendSuccessDatas = new ArrayList<>(); + List yNoticeSendDatas = new ArrayList<>(); + List yNoticeSendSuccessDatas = new ArrayList<>(); + for (int i = 0; i < 7; i++) { + int smsSendCount = 0; + int smsSendSuccessCount = 0; + int noticeSendCount = 0; + int noticeSendSuccessCount = 0; + DateTime dayOfWeek = dateDateTime.withDayOfWeek(i + 1); + String dayOfWeekDate = dayOfWeek.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + + xDatas.add(dayOfWeekDate); + for (SmsPO smsPO : smsPOs) { + if (!smsPO.getGmtCreate().startsWith(dayOfWeekDate)) { + continue; + } + smsSendCount++; + if (smsPO.getSendStatus() == 1) { + smsSendSuccessCount++; + } + } + for (NoticePO noticePO : noticePOs) { + if (!noticePO.getGmtCreate().startsWith(dayOfWeekDate)) { + continue; + } + noticeSendCount++; + if (noticePO.getIsSend() == 1) { + noticeSendSuccessCount++; + } + } + ySmsSendDatas.add(smsSendCount); + ySmsSendSuccessDatas.add(smsSendSuccessCount); + yNoticeSendDatas.add(noticeSendCount); + yNoticeSendSuccessDatas.add(noticeSendSuccessCount); + } + + Map result = new HashMap<>(); + result.put("xDatas", xDatas); + result.put("ySmsSendDatas", ySmsSendDatas); + result.put("ySmsSendSuccessDatas", ySmsSendSuccessDatas); + result.put("yNoticeSendDatas", yNoticeSendDatas); + result.put("yNoticeSendSuccessDatas", yNoticeSendSuccessDatas); + return result; + } + + @Override + public Map monthSendCount(String date) { + DateTime dateDateTime = DateTime.parse(date, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DateTime firstDateTime = dateDateTime.dayOfMonth().withMinimumValue(); + String startTime = firstDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DateTime endDateTime = dateDateTime.dayOfMonth().withMaximumValue(); + String endTime = endDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + + List smsPOs = smsService.listPOByStartTimeAndEndTime(startTime, endTime); + List noticePOs = noticeService.listPOByStartTimeAndEndTime(startTime, endTime); + + List xDatas = new ArrayList<>(); + List ySmsSendDatas = new ArrayList<>(); + List ySmsSendSuccessDatas = new ArrayList<>(); + List yNoticeSendDatas = new ArrayList<>(); + List yNoticeSendSuccessDatas = new ArrayList<>(); + int totalDay = dateDateTime.dayOfMonth().getMaximumValue(); + for (int i = 0; i < totalDay; i++) { + int smsSendCount = 0; + int smsSendSuccessCount = 0; + int noticeSendCount = 0; + int noticeSendSuccessCount = 0; + DateTime dayOfWeek = dateDateTime.withDayOfMonth(i + 1); + String dayOfWeekDate = dayOfWeek.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + + xDatas.add(dayOfWeekDate); + for (SmsPO smsPO : smsPOs) { + if (!smsPO.getGmtCreate().startsWith(dayOfWeekDate)) { + continue; + } + smsSendCount++; + if (smsPO.getSendStatus() == 1) { + smsSendSuccessCount++; + } + } + for (NoticePO noticePO : noticePOs) { + if (!noticePO.getGmtCreate().startsWith(dayOfWeekDate)) { + continue; + } + noticeSendCount++; + if (noticePO.getIsSend() == 1) { + noticeSendSuccessCount++; + } + } + ySmsSendDatas.add(smsSendCount); + ySmsSendSuccessDatas.add(smsSendSuccessCount); + yNoticeSendDatas.add(noticeSendCount); + yNoticeSendSuccessDatas.add(noticeSendSuccessCount); + } + + Map result = new HashMap<>(); + result.put("xDatas", xDatas); + result.put("ySmsSendDatas", ySmsSendDatas); + result.put("ySmsSendSuccessDatas", ySmsSendSuccessDatas); + result.put("yNoticeSendDatas", yNoticeSendDatas); + result.put("yNoticeSendSuccessDatas", yNoticeSendSuccessDatas); + return result; + } + +} diff --git a/src/main/resources/templates/visual-report/report.html b/src/main/resources/templates/visual-report/report.html new file mode 100644 index 0000000..7306dcc --- /dev/null +++ b/src/main/resources/templates/visual-report/report.html @@ -0,0 +1,323 @@ + + + + + + + + + + + + + +
+
+ +
+
+
+ 短信发送量 + +
+
+

0

+

+ 成功率 + + 0% + +

+
+
+
+
+
+
+ 通知发送量 + +
+
+

0

+

+ 成功率 + + 0% + +

+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file