diff --git a/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java b/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java index b7ebc2a..c8a1697 100644 --- a/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java +++ b/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java @@ -27,6 +27,7 @@ import com.greenorange.promotion.service.userInfo.UserPerformanceSummaryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.scheduling.annotation.Scheduled; @@ -84,89 +85,7 @@ public class UserPerformanceSummaryController { @Operation(summary = "Web端仪表盘", description = "参数:无,权限:管理员,方法名:webQueryDashboard") @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse webQueryDashboard() { - BigDecimal totalAmount = BigDecimal.ZERO; - BigDecimal netAmount = BigDecimal.ZERO; - Integer promoCount = 0; - Integer superCount; - Integer empCount = 0; - Integer orderCount = 0; - BigDecimal toRelease = BigDecimal.ZERO; - BigDecimal toSettle = BigDecimal.ZERO; - BigDecimal settled = BigDecimal.ZERO; - BigDecimal refunded = BigDecimal.ZERO; - - Integer todayOrderCount; - BigDecimal todayOrderAmount; - Integer todayRefundCount; - BigDecimal todayRefundAmount; - Integer todayPromotionCount; - - Integer monthOrderCount; - BigDecimal monthOrderAmount; - Integer monthRefundCount; - BigDecimal monthRefundAmount; - Integer monthPromotionCount; - - List userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE, userInfoService); - List userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId); - superCount = userPerformanceSummaryList.size(); - for (UserPerformanceSummary userPerformanceSummary : userPerformanceSummaryList) { - totalAmount = totalAmount.add(userPerformanceSummary.getTotalAmount()); - netAmount = netAmount.add(userPerformanceSummary.getNetAmount()); - promoCount += userPerformanceSummary.getPromoCount(); - empCount += userPerformanceSummary.getEmpCount(); - orderCount += userPerformanceSummary.getOrderCount(); - toRelease = toRelease.add(userPerformanceSummary.getToRelease()); - toSettle = toSettle.add(userPerformanceSummary.getToSettle()); - settled = settled.add(userPerformanceSummary.getSettled()); - refunded = refunded.add(userPerformanceSummary.getRefunded()); - } - - - DateTime now = DateUtil.date(); - - // 查看今天的绩效 - DateTime beginOfDay = DateUtil.beginOfDay(now); - DateTime endOfDay = DateUtil.endOfDay(now); - Map todayPerformanceSummary = userPerformanceSummaryService.getPerformanceSummaryByStartAndEndTime(beginOfDay, endOfDay); - todayOrderCount = (Integer) todayPerformanceSummary.get("orderCount"); - todayOrderAmount = (BigDecimal) todayPerformanceSummary.get("orderAmount"); - todayRefundCount = (Integer) todayPerformanceSummary.get("refundCount"); - todayRefundAmount = (BigDecimal) todayPerformanceSummary.get("refundAmount"); - todayPromotionCount = (Integer) todayPerformanceSummary.get("promotionCount"); - - // 查看本月的绩效 - DateTime beginOfMonth = DateUtil.beginOfMonth(now); - DateTime endOfMonth = DateUtil.beginOfMonth(now); - Map monthPerformanceSummary = userPerformanceSummaryService.getPerformanceSummaryByStartAndEndTime(beginOfMonth, endOfMonth); - monthOrderCount = (Integer) monthPerformanceSummary.get("orderCount"); - monthOrderAmount = (BigDecimal) monthPerformanceSummary.get("orderAmount"); - monthRefundCount = (Integer) monthPerformanceSummary.get("refundCount"); - monthRefundAmount = (BigDecimal) monthPerformanceSummary.get("refundAmount"); - monthPromotionCount = (Integer) monthPerformanceSummary.get("promotionCount"); - - WebQueryDashboardVO webQueryDashboardVO = WebQueryDashboardVO.builder() - .totalAmount(totalAmount) - .netAmount(netAmount) - .promoCount(promoCount) - .superCount(superCount) - .empCount(empCount) - .orderCount(orderCount) - .toRelease(toRelease) - .toSettle(toSettle) - .settled(settled) - .refunded(refunded) - .todayOrderCount(todayOrderCount) - .todayOrderAmount(todayOrderAmount) - .todayRefundCount(todayRefundCount) - .todayRefundAmount(todayRefundAmount) - .todayPromotionCount(todayPromotionCount) - .monthOrderCount(monthOrderCount) - .monthOrderAmount(monthOrderAmount) - .monthRefundCount(monthRefundCount) - .monthRefundAmount(monthRefundAmount) - .monthPromotionCount(monthPromotionCount) - .build(); + WebQueryDashboardVO webQueryDashboardVO = userPerformanceSummaryService.queryManagerDashboard(); return ResultUtils.success(webQueryDashboardVO); } @@ -872,4 +791,33 @@ public class UserPerformanceSummaryController { } + /** + * 小程序端仪表盘 + * @return 用户绩效汇总 + */ + @PostMapping("mini/query/dashboard") + @Operation(summary = "小程序端仪表盘", description = "参数:无,权限:管理员,方法名:miniQueryDashboard") + @RequiresPermission(mustRole = UserConstant.MANAGER_ROLE) + public BaseResponse miniQueryDashboard(HttpServletRequest request) { + Long userId = (Long) request.getAttribute("userId"); + UserInfo userInfo = userInfoService.getById(userId); + String userRole = userInfo.getUserRole(); + UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole); + WebQueryDashboardVO webQueryDashboardVO; + if (UserRoleEnum.MANAGER.equals(userRoleEnum)) { + webQueryDashboardVO = userPerformanceSummaryService.queryManagerDashboard(); + } else { + webQueryDashboardVO = userPerformanceSummaryService.querySupervisorOrStaffDashboard(userRoleEnum, userId); + } + return ResultUtils.success(webQueryDashboardVO); + } + + + + + + + + + } \ No newline at end of file diff --git a/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java b/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java index 0652edc..26994ae 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java @@ -9,6 +9,8 @@ import com.greenorange.promotion.model.dto.userPerformanceSummary.*; import com.greenorange.promotion.model.entity.CourseOrder; import com.greenorange.promotion.model.entity.UserPerformanceSummary; import com.baomidou.mybatisplus.extension.service.IService; +import com.greenorange.promotion.model.enums.UserRoleEnum; +import com.greenorange.promotion.model.vo.dashboard.WebQueryDashboardVO; import com.greenorange.promotion.model.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; import java.math.BigDecimal; @@ -61,5 +63,18 @@ public interface UserPerformanceSummaryService extends IService getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay); + Map getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay, UserRoleEnum userRoleEnum, Long userId); + + + /** + * 经理查看仪表盘 + */ + WebQueryDashboardVO queryManagerDashboard(); + + + /** + * 主管或员工查看仪表盘 + */ + WebQueryDashboardVO querySupervisorOrStaffDashboard(UserRoleEnum userRoleEnum, Long userId); + } diff --git a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserPerformanceSummaryServiceImpl.java b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserPerformanceSummaryServiceImpl.java index c0fe5a8..585c5ae 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserPerformanceSummaryServiceImpl.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserPerformanceSummaryServiceImpl.java @@ -2,20 +2,22 @@ package com.greenorange.promotion.service.userInfo.impl; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.greenorange.promotion.common.PageRequest; import com.greenorange.promotion.constant.CommonConstant; import com.greenorange.promotion.constant.SystemConstant; +import com.greenorange.promotion.constant.UserConstant; import com.greenorange.promotion.model.dto.CommonStringRequest; import com.greenorange.promotion.model.dto.userPerformanceSummary.*; -import com.greenorange.promotion.model.entity.CourseOrder; -import com.greenorange.promotion.model.entity.CoursePromotionCommissionPending; -import com.greenorange.promotion.model.entity.EmployeePromotionRecords; -import com.greenorange.promotion.model.entity.UserPerformanceSummary; +import com.greenorange.promotion.model.entity.*; import com.greenorange.promotion.model.enums.CommissionStatusEnum; +import com.greenorange.promotion.model.enums.UserRoleEnum; +import com.greenorange.promotion.model.vo.dashboard.WebQueryDashboardVO; import com.greenorange.promotion.model.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; +import com.greenorange.promotion.service.common.CommonService; import com.greenorange.promotion.service.course.CoursePromotionCommissionPendingService; import com.greenorange.promotion.service.userInfo.EmployeePromotionRecordsService; import com.greenorange.promotion.service.userInfo.UserInfoService; @@ -62,6 +64,14 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay) { + public Map getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay, UserRoleEnum userRoleEnum, Long userId) { Map performanceSummaryMap = new HashMap<>(); Integer orderCount; BigDecimal orderAmount = BigDecimal.ZERO; @@ -205,6 +215,11 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl coursePromotionQueryWrapper = new QueryWrapper<>(); coursePromotionQueryWrapper.ge("orderCreateTime", beginOfDay); coursePromotionQueryWrapper.le("orderCreateTime", endOfDay); + if (UserRoleEnum.SUPERVISOR.equals(userRoleEnum)) { + coursePromotionQueryWrapper.eq("firstUserId", userId); + } else if (UserRoleEnum.STAFF.equals(userRoleEnum)) { + coursePromotionQueryWrapper.eq("secondUserId", userId); + } List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); orderCount = coursePromotionCommissionPendingList.size(); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { @@ -220,6 +235,11 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl empQueryWrapper = new QueryWrapper<>(); empQueryWrapper.ge("createTime", beginOfDay); empQueryWrapper.le("createTime", endOfDay); + if (UserRoleEnum.SUPERVISOR.equals(userRoleEnum)) { + coursePromotionQueryWrapper.eq("firstUserId", userId); + } else if (UserRoleEnum.STAFF.equals(userRoleEnum)) { + coursePromotionQueryWrapper.eq("secondUserId", userId); + } List employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper); promotionCount = employeePromotionRecordsList.size(); @@ -231,6 +251,187 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE, userInfoService); + List userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, this, UserInfo::getId, UserPerformanceSummary::getUserId); + superCount = userPerformanceSummaryList.size(); + for (UserPerformanceSummary userPerformanceSummary : userPerformanceSummaryList) { + totalAmount = totalAmount.add(userPerformanceSummary.getTotalAmount()); + netAmount = netAmount.add(userPerformanceSummary.getNetAmount()); + promoCount += userPerformanceSummary.getPromoCount(); + empCount += userPerformanceSummary.getEmpCount(); + orderCount += userPerformanceSummary.getOrderCount(); + toRelease = toRelease.add(userPerformanceSummary.getToRelease()); + toSettle = toSettle.add(userPerformanceSummary.getToSettle()); + settled = settled.add(userPerformanceSummary.getSettled()); + refunded = refunded.add(userPerformanceSummary.getRefunded()); + } + + + DateTime now = DateUtil.date(); + + // 查看今天的绩效 + DateTime beginOfDay = DateUtil.beginOfDay(now); + DateTime endOfDay = DateUtil.endOfDay(now); + Map todayPerformanceSummary = this.getPerformanceSummaryByStartAndEndTime(beginOfDay, endOfDay, UserRoleEnum.MANAGER, null); + todayOrderCount = (Integer) todayPerformanceSummary.get("orderCount"); + todayOrderAmount = (BigDecimal) todayPerformanceSummary.get("orderAmount"); + todayRefundCount = (Integer) todayPerformanceSummary.get("refundCount"); + todayRefundAmount = (BigDecimal) todayPerformanceSummary.get("refundAmount"); + todayPromotionCount = (Integer) todayPerformanceSummary.get("promotionCount"); + + // 查看本月的绩效 + DateTime beginOfMonth = DateUtil.beginOfMonth(now); + DateTime endOfMonth = DateUtil.beginOfMonth(now); + Map monthPerformanceSummary = this.getPerformanceSummaryByStartAndEndTime(beginOfMonth, endOfMonth, UserRoleEnum.MANAGER, null); + monthOrderCount = (Integer) monthPerformanceSummary.get("orderCount"); + monthOrderAmount = (BigDecimal) monthPerformanceSummary.get("orderAmount"); + monthRefundCount = (Integer) monthPerformanceSummary.get("refundCount"); + monthRefundAmount = (BigDecimal) monthPerformanceSummary.get("refundAmount"); + monthPromotionCount = (Integer) monthPerformanceSummary.get("promotionCount"); + + WebQueryDashboardVO webQueryDashboardVO = WebQueryDashboardVO.builder() + .totalAmount(totalAmount) + .netAmount(netAmount) + .promoCount(promoCount) + .superCount(superCount) + .empCount(empCount) + .orderCount(orderCount) + .toRelease(toRelease) + .toSettle(toSettle) + .settled(settled) + .refunded(refunded) + .todayOrderCount(todayOrderCount) + .todayOrderAmount(todayOrderAmount) + .todayRefundCount(todayRefundCount) + .todayRefundAmount(todayRefundAmount) + .todayPromotionCount(todayPromotionCount) + .monthOrderCount(monthOrderCount) + .monthOrderAmount(monthOrderAmount) + .monthRefundCount(monthRefundCount) + .monthRefundAmount(monthRefundAmount) + .monthPromotionCount(monthPromotionCount) + .build(); + return webQueryDashboardVO; + } + + + /** + * 主管查看仪表盘 + */ + @Override + public WebQueryDashboardVO querySupervisorOrStaffDashboard(UserRoleEnum userRoleEnum, Long userId) { + BigDecimal totalAmount; + BigDecimal netAmount; + Integer promoCount; + Integer superCount = 0; + Integer empCount; + Integer orderCount; + BigDecimal toRelease; + BigDecimal toSettle; + BigDecimal settled; + BigDecimal refunded; + + Integer todayOrderCount; + BigDecimal todayOrderAmount; + Integer todayRefundCount; + BigDecimal todayRefundAmount; + Integer todayPromotionCount; + + Integer monthOrderCount; + BigDecimal monthOrderAmount; + Integer monthRefundCount; + BigDecimal monthRefundAmount; + Integer monthPromotionCount; + LambdaQueryWrapper userPerformanceSummaryLambdaQueryWrapper = commonService.buildQueryWrapperByField(UserPerformanceSummary::getUserId, userId, this); + UserPerformanceSummary userPerformanceSummary = this.getOne(userPerformanceSummaryLambdaQueryWrapper); + totalAmount = userPerformanceSummary.getTotalAmount(); + netAmount = userPerformanceSummary.getNetAmount(); + promoCount = userPerformanceSummary.getPromoCount(); + empCount = userPerformanceSummary.getEmpCount(); + orderCount = userPerformanceSummary.getOrderCount(); + toRelease = userPerformanceSummary.getToRelease(); + toSettle = userPerformanceSummary.getToSettle(); + settled = userPerformanceSummary.getSettled(); + refunded = userPerformanceSummary.getRefunded(); + + + DateTime now = DateUtil.date(); + + // 查看今天的绩效 + DateTime beginOfDay = DateUtil.beginOfDay(now); + DateTime endOfDay = DateUtil.endOfDay(now); + Map todayPerformanceSummary = this.getPerformanceSummaryByStartAndEndTime(beginOfDay, endOfDay, userRoleEnum, userId); + todayOrderCount = (Integer) todayPerformanceSummary.get("orderCount"); + todayOrderAmount = (BigDecimal) todayPerformanceSummary.get("orderAmount"); + todayRefundCount = (Integer) todayPerformanceSummary.get("refundCount"); + todayRefundAmount = (BigDecimal) todayPerformanceSummary.get("refundAmount"); + todayPromotionCount = (Integer) todayPerformanceSummary.get("promotionCount"); + + // 查看本月的绩效 + DateTime beginOfMonth = DateUtil.beginOfMonth(now); + DateTime endOfMonth = DateUtil.beginOfMonth(now); + Map monthPerformanceSummary = this.getPerformanceSummaryByStartAndEndTime(beginOfMonth, endOfMonth, userRoleEnum, userId); + monthOrderCount = (Integer) monthPerformanceSummary.get("orderCount"); + monthOrderAmount = (BigDecimal) monthPerformanceSummary.get("orderAmount"); + monthRefundCount = (Integer) monthPerformanceSummary.get("refundCount"); + monthRefundAmount = (BigDecimal) monthPerformanceSummary.get("refundAmount"); + monthPromotionCount = (Integer) monthPerformanceSummary.get("promotionCount"); + + WebQueryDashboardVO webQueryDashboardVO = WebQueryDashboardVO.builder() + .totalAmount(totalAmount) + .netAmount(netAmount) + .promoCount(promoCount) + .superCount(superCount) + .empCount(empCount) + .orderCount(orderCount) + .toRelease(toRelease) + .toSettle(toSettle) + .settled(settled) + .refunded(refunded) + .todayOrderCount(todayOrderCount) + .todayOrderAmount(todayOrderAmount) + .todayRefundCount(todayRefundCount) + .todayRefundAmount(todayRefundAmount) + .todayPromotionCount(todayPromotionCount) + .monthOrderCount(monthOrderCount) + .monthOrderAmount(monthOrderAmount) + .monthRefundCount(monthRefundCount) + .monthRefundAmount(monthRefundAmount) + .monthPromotionCount(monthPromotionCount) + .build(); + return webQueryDashboardVO; + } + + }