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 3b6a60d..1ed7038 100644 --- a/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java +++ b/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java @@ -1,11 +1,8 @@ package com.greenorange.promotion.controller.userInfo; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.lang.hash.Hash; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.greenorange.promotion.annotation.RequiresPermission; import com.greenorange.promotion.common.BaseResponse; @@ -13,13 +10,12 @@ import com.greenorange.promotion.common.ResultUtils; import com.greenorange.promotion.constant.OrderStatusConstant; 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.*; import com.greenorange.promotion.model.enums.CommissionStatusEnum; import com.greenorange.promotion.model.enums.UserRoleEnum; -import com.greenorange.promotion.model.vo.courseOrder.CourseOrderBaseInfoVO; import com.greenorange.promotion.model.vo.courseOrder.CourseOrderDetailInfoVO; +import com.greenorange.promotion.model.vo.dashboard.WebQueryDashboardVO; import com.greenorange.promotion.model.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; import com.greenorange.promotion.model.vo.userPerformanceSummary.UserPerformanceSummaryDetailVO; import com.greenorange.promotion.service.common.CommonService; @@ -33,8 +29,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -82,6 +76,101 @@ public class UserPerformanceSummaryController { + /** + * Web端仪表盘 + * @return 用户绩效汇总 + */ + @PostMapping("query/dashboard") + @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(); + return ResultUtils.success(webQueryDashboardVO); + } + + /** @@ -263,8 +352,8 @@ public class UserPerformanceSummaryController { // 封装Map集合(键:主管id, 值:净成交金额) Map supervisorNetSalesAmountMap = new HashMap<>(); QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); - coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); - coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate); + coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate); List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { Long firstUserId = coursePromotionCommissionPending.getFirstUserId(); @@ -343,8 +432,8 @@ public class UserPerformanceSummaryController { // 封装Map集合(键:员工id, 值:净成交金额) Map staffNetSalesAmountMap = new HashMap<>(); QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); - coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); - coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate); + coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate); List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { Long secondUserId = coursePromotionCommissionPending.getSecondUserId(); @@ -658,8 +747,8 @@ public class UserPerformanceSummaryController { // 封装Map集合(键:主管id, 值:净成交金额) Map supervisorNetSalesAmountMap = new HashMap<>(); QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); - coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); - coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate); + coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate); List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { Long firstUserId = coursePromotionCommissionPending.getFirstUserId(); @@ -737,8 +826,8 @@ public class UserPerformanceSummaryController { // 封装Map集合(键:员工id, 值:净成交金额) Map staffNetSalesAmountMap = new HashMap<>(); QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); - coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); - coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate); + coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate); List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { Long secondUserId = coursePromotionCommissionPending.getSecondUserId(); diff --git a/src/main/java/com/greenorange/promotion/model/entity/UserPerformanceSummary.java b/src/main/java/com/greenorange/promotion/model/entity/UserPerformanceSummary.java index bc86d77..b315727 100644 --- a/src/main/java/com/greenorange/promotion/model/entity/UserPerformanceSummary.java +++ b/src/main/java/com/greenorange/promotion/model/entity/UserPerformanceSummary.java @@ -46,11 +46,6 @@ public class UserPerformanceSummary implements Serializable { */ private Integer promoCount; - /** - * 主管数量 - */ - private Integer superCount; - /** * 员工数量 */ diff --git a/src/main/java/com/greenorange/promotion/model/vo/dashboard/WebQueryDashboardVO.java b/src/main/java/com/greenorange/promotion/model/vo/dashboard/WebQueryDashboardVO.java new file mode 100644 index 0000000..df9f3ca --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/vo/dashboard/WebQueryDashboardVO.java @@ -0,0 +1,142 @@ +package com.greenorange.promotion.model.vo.dashboard; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class WebQueryDashboardVO implements Serializable { + + /** + * 订单总金额 + */ + @Schema(description = "订单总金额", example = "1000.00") + private BigDecimal totalAmount; + + /** + * 净成交 + */ + @Schema(description = "净成交", example = "800.00") + private BigDecimal netAmount; + + /** + * 客户数量 + */ + @Schema(description = "客户数量", example = "10") + private Integer promoCount; + + /** + * 主管数量 + */ + @Schema(description = "主管数量", example = "15") + private Integer superCount; + + /** + * 员工数量 + */ + @Schema(description = "员工数量", example = "15") + private Integer empCount; + + /** + * 下单数量 + */ + @Schema(description = "下单数量", example = "25") + private Integer orderCount; + + /** + * 待释放 + */ + @Schema(description = "待释放", example = "1000.00") + private BigDecimal toRelease; + + /** + * 可结算 + */ + @Schema(description = "可结算", example = "600.00") + private BigDecimal toSettle; + + /** + * 已结算 + */ + @Schema(description = "已结算", example = "200.00") + private BigDecimal settled; + + /** + * 已回退 + */ + @Schema(description = "已回退", example = "100.00") + private BigDecimal refunded; + + /** + * 今日下单数量 + */ + @Schema(description = "今日下单数量", example = "10") + private Integer todayOrderCount; + + /** + * 今日下单总金额 + */ + @Schema(description = "今日下单总金额", example = "100.00") + private BigDecimal todayOrderAmount; + + /** + * 今日退款数量 + */ + @Schema(description = "今日退款数量", example = "10") + private Integer todayRefundCount; + + /** + * 今日下单退款金额 + */ + @Schema(description = "今日下单退款金额", example = "90.00") + private BigDecimal todayRefundAmount; + + /** + * 今日推广数量 + */ + @Schema(description = "今日推广数量", example = "10") + private Integer todayPromotionCount; + + /** + * 本月下单数量 + */ + @Schema(description = "本月下单数量", example = "100") + private Integer monthOrderCount; + + /** + * 本月下单金额 + */ + @Schema(description = "本月下单金额", example = "1000.00") + private BigDecimal monthOrderAmount; + + /** + * 本月退款数量 + */ + @Schema(description = "本月退款数量", example = "10") + private Integer monthRefundCount; + + /** + * 本月退款金额 + */ + @Schema(description = "本月退款金额", example = "1000.00") + private BigDecimal monthRefundAmount; + + /** + * 本月推广数量 + */ + @Schema(description = "本月推广数量", example = "10") + private Integer monthPromotionCount; + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryDetailVO.java b/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryDetailVO.java index 81fe6c1..c4ba402 100644 --- a/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryDetailVO.java +++ b/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryDetailVO.java @@ -50,12 +50,6 @@ public class UserPerformanceSummaryDetailVO implements Serializable { @Schema(description = "推广人数", example = "300") private Integer promoCount; - /** - * 主管数量 - */ - @Schema(description = "主管数量", example = "5") - private Integer superCount; - /** * 员工数量 */ diff --git a/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryVO.java b/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryVO.java index 51de2cf..0b82ad2 100644 --- a/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryVO.java +++ b/src/main/java/com/greenorange/promotion/model/vo/userPerformanceSummary/UserPerformanceSummaryVO.java @@ -38,12 +38,6 @@ public class UserPerformanceSummaryVO implements Serializable { @Schema(description = "推广人数", example = "") private Integer promoCount; - /** - * 主管数量 - */ - @Schema(description = "主管数量", example = "") - private Integer superCount; - /** * 员工数量 */ 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 d614ef4..0652edc 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java @@ -1,5 +1,6 @@ package com.greenorange.promotion.service.userInfo; +import cn.hutool.core.date.DateTime; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.greenorange.promotion.common.PageRequest; @@ -55,4 +56,10 @@ public interface UserPerformanceSummaryService extends IService queryPage(UserPerformanceSummaryRankQueryRequest req, List allVos); + + + /** + * 查看某个时间段的绩效 + */ + Map getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay); } diff --git a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java index 5ccdc6c..96bb630 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java @@ -412,8 +412,6 @@ public class UserInfoServiceImpl extends ServiceImpl userPerformanceSummary.setPromoCount(userPerformanceSummary.getPromoCount() + 1); } else if (userRoleEnum.equals(UserRoleEnum.STAFF)) { userPerformanceSummary.setEmpCount(userPerformanceSummary.getEmpCount() + 1); - } else if (userRoleEnum.equals(UserRoleEnum.SUPERVISOR)) { - userPerformanceSummary.setSuperCount(userPerformanceSummary.getSuperCount() + 1); } } userPerformanceSummaryService.updateBatchById(userPerformanceSummaryList); 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 aceaae7..c0fe5a8 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 @@ -7,11 +7,17 @@ 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.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.enums.CommissionStatusEnum; import com.greenorange.promotion.model.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; +import com.greenorange.promotion.service.course.CoursePromotionCommissionPendingService; +import com.greenorange.promotion.service.userInfo.EmployeePromotionRecordsService; import com.greenorange.promotion.service.userInfo.UserInfoService; import com.greenorange.promotion.service.userInfo.UserPerformanceSummaryService; import com.greenorange.promotion.mapper.UserPerformanceSummaryMapper; @@ -25,6 +31,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.security.Key; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -39,11 +46,22 @@ import java.util.stream.Collectors; public class UserPerformanceSummaryServiceImpl extends ServiceImpl implements UserPerformanceSummaryService{ + private static final String KEY = "rakeRate"; + @Resource private RedisTemplate redisTemplate; + + @Resource + private CoursePromotionCommissionPendingService coursePromotionCommissionPendingService; + + + @Resource + private EmployeePromotionRecordsService employeePromotionRecordsService; + + /** * 获取查询条件 */ @@ -170,6 +188,49 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl getPerformanceSummaryByStartAndEndTime(DateTime beginOfDay, DateTime endOfDay) { + Map performanceSummaryMap = new HashMap<>(); + Integer orderCount; + BigDecimal orderAmount = BigDecimal.ZERO; + Integer refundedCount = 0; + BigDecimal refundedAmount = BigDecimal.ZERO; + Integer promotionCount; + + + QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); + coursePromotionQueryWrapper.ge("orderCreateTime", beginOfDay); + coursePromotionQueryWrapper.le("orderCreateTime", endOfDay); + List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); + orderCount = coursePromotionCommissionPendingList.size(); + for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { + String commissionStatus = coursePromotionCommissionPending.getCommissionStatus(); + CommissionStatusEnum commissionStatusEnum = CommissionStatusEnum.getEnumByValue(commissionStatus); + orderAmount = orderAmount.add(coursePromotionCommissionPending.getTotalAmount()); + if (CommissionStatusEnum.EXPIRED.equals(commissionStatusEnum)) { + refundedCount ++; + refundedAmount = refundedAmount.add(coursePromotionCommissionPending.getTotalAmount().multiply(SystemConstant.REFUND_RATE)); + } + } + + QueryWrapper empQueryWrapper = new QueryWrapper<>(); + empQueryWrapper.ge("createTime", beginOfDay); + empQueryWrapper.le("createTime", endOfDay); + List employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper); + promotionCount = employeePromotionRecordsList.size(); + + performanceSummaryMap.put("orderCount", orderCount); + performanceSummaryMap.put("orderAmount", orderAmount); + performanceSummaryMap.put("refundCount", refundedCount); + performanceSummaryMap.put("refundAmount", refundedAmount); + performanceSummaryMap.put("promotionCount", promotionCount); + return performanceSummaryMap; + } + }