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 526de45..46c6787 100644 --- a/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java +++ b/src/main/java/com/greenorange/promotion/controller/userInfo/UserPerformanceSummaryController.java @@ -216,13 +216,13 @@ public class UserPerformanceSummaryController { /** * Web端管理员分页查询主管绩效排名 - * @param userPerformanceSummaryRankQueryRequest 主管绩效排名查询请求体 + * @param userPerformanceSummaryRankQueryRequest 绩效排名查询请求体 * @return 用户绩效汇总列表 */ - @PostMapping("rank/user/page") - @Operation(summary = "Web端管理员分页查询主管绩效排名", description = "参数:主管绩效排名查询请求体,权限:管理员,方法名:listUserPerformanceSummaryRankingsByPage") + @PostMapping("rank/supervisor/page") + @Operation(summary = "Web端管理员分页查询主管绩效排名", description = "参数:绩效排名查询请求体,权限:管理员,方法名:listSupervisorPerformanceSummaryRankingsByPage") @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse> listUserPerformanceSummaryRankingsByPage(@Valid @RequestBody UserPerformanceSummaryRankQueryRequest userPerformanceSummaryRankQueryRequest) { + public BaseResponse> listSupervisorPerformanceSummaryRankingsByPage(@Valid @RequestBody UserPerformanceSummaryRankQueryRequest userPerformanceSummaryRankQueryRequest) { String startTimeStr = userPerformanceSummaryRankQueryRequest.getStartDate(); String endTimeStr = userPerformanceSummaryRankQueryRequest.getEndDate(); DateTime startDate = DateUtil.parse(startTimeStr, "yyyy-MM-dd HH:mm:ss"); @@ -234,51 +234,35 @@ public class UserPerformanceSummaryController { List employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper); // 封装Map集合(键:主管id, 值:推广数量) Map supervisorCntMap = new HashMap<>(); - // 封装Map集合(键:员工id, 值:推广数量) - Map staffCntMap = new HashMap<>(); for (EmployeePromotionRecords employeePromotionRecords : employeePromotionRecordsList) { Long firstUserId = employeePromotionRecords.getFirstUserId(); - Long secondUserId = employeePromotionRecords.getSecondUserId(); supervisorCntMap.merge(firstUserId, 1, Integer::sum); - staffCntMap.merge(secondUserId, 1, Integer::sum); } // 封装Map集合(键:主管id, 值:下单数量) Map supervisorOrderCntMap = new HashMap<>(); - // 封装Map集合(键:员工id, 值:下单数量) - Map staffOrderCntMap = new HashMap<>(); - // (键:主管id, 值:下单金额) + // 封装Map集合(键:主管id, 值:下单金额) Map supervisorOrderAmountMap = new HashMap<>(); - // (键:员工id, 值:下单金额) - Map staffOrderAmountMap = new HashMap<>(); - // (键:主管id, 值:净成交金额) + // 封装Map集合(键:主管id, 值:净成交金额) Map supervisorNetSalesAmountMap = new HashMap<>(); - // (键:员工id, 值:净成交金额) - Map staffNetSalesAmountMap = new HashMap<>(); QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { Long firstUserId = coursePromotionCommissionPending.getFirstUserId(); - Long secondUserId = coursePromotionCommissionPending.getSecondUserId(); BigDecimal totalAmount = coursePromotionCommissionPending.getTotalAmount(); DateTime updateDate = DateUtil.date(coursePromotionCommissionPending.getUpdateTime()); String commissionStatus = coursePromotionCommissionPending.getCommissionStatus(); CommissionStatusEnum commissionStatusEnum = CommissionStatusEnum.getEnumByValue(commissionStatus); supervisorOrderCntMap.merge(firstUserId, 1, Integer::sum); - staffOrderCntMap.merge(secondUserId, 1, Integer::sum); supervisorOrderAmountMap.merge(firstUserId, totalAmount, BigDecimal::add); - staffOrderAmountMap.merge(secondUserId, totalAmount, BigDecimal::add); if (!(CommissionStatusEnum.COMPLETED.equals(commissionStatusEnum) && updateDate.isAfterOrEquals(startDate) && updateDate.isBeforeOrEquals(endDate))) { totalAmount = totalAmount.multiply(SystemConstant.FEE_RATE); } supervisorNetSalesAmountMap.merge(firstUserId, totalAmount, BigDecimal::add); - staffNetSalesAmountMap.merge(secondUserId, totalAmount, BigDecimal::add); } - // 封装Map集合(键:主管id, 值:员工数量) - Map supervisorStaffCntMap = new HashMap<>(); List userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserRoleEnum.SUPERVISOR, userInfoService); List userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId); @@ -304,19 +288,110 @@ public class UserPerformanceSummaryController { .build(); supervisorPerformanceSummaryVOS.add(supervisorPerformanceSummaryVO); } - long current = userPerformanceSummaryRankQueryRequest.getCurrent(); - long pageSize = userPerformanceSummaryRankQueryRequest.getPageSize(); - String nickName = userPerformanceSummaryRankQueryRequest.getNickName(); - String phoneNumber = userPerformanceSummaryRankQueryRequest.getPhoneNumber(); - String sortField = userPerformanceSummaryRankQueryRequest.getSortField(); - String sortOrder = userPerformanceSummaryRankQueryRequest.getSortOrder(); - - - return null; - + Page supervisorPerformanceSummaryVOPage = userPerformanceSummaryService.queryPage(userPerformanceSummaryRankQueryRequest, supervisorPerformanceSummaryVOS); + return ResultUtils.success(supervisorPerformanceSummaryVOPage); } + + /** + * Web端管理员分页查询员工绩效排名 + * @param userPerformanceSummaryRankQueryRequest 绩效排名查询请求体 + * @return 用户绩效汇总列表 + */ + @PostMapping("rank/staff/page") + @Operation(summary = "Web端管理员分页查询员工绩效排名", description = "参数:绩效排名查询请求体,权限:管理员,方法名:listStaffUserPerformanceSummaryRankingsByPage") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse> listStaffUserPerformanceSummaryRankingsByPage(@Valid @RequestBody UserPerformanceSummaryRankQueryRequest userPerformanceSummaryRankQueryRequest) { + String startTimeStr = userPerformanceSummaryRankQueryRequest.getStartDate(); + String endTimeStr = userPerformanceSummaryRankQueryRequest.getEndDate(); + DateTime startDate = DateUtil.parse(startTimeStr, "yyyy-MM-dd HH:mm:ss"); + DateTime endDate = DateUtil.parse(endTimeStr, "yyyy-MM-dd HH:mm:ss"); + + QueryWrapper empQueryWrapper = new QueryWrapper<>(); + empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); + empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + List employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper); + // 封装Map集合(键:员工id, 值:推广数量) + Map staffCntMap = new HashMap<>(); + for (EmployeePromotionRecords employeePromotionRecords : employeePromotionRecordsList) { + Long secondUserId = employeePromotionRecords.getSecondUserId(); + staffCntMap.merge(secondUserId, 1, Integer::sum); + } + + // 封装Map集合(键:员工id, 值:下单数量) + Map staffOrderCntMap = new HashMap<>(); + // 封装Map集合(键:员工id, 值:下单金额) + Map staffOrderAmountMap = new HashMap<>(); + // 封装Map集合(键:员工id, 值:净成交金额) + Map staffNetSalesAmountMap = new HashMap<>(); + QueryWrapper coursePromotionQueryWrapper = new QueryWrapper<>(); + coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate); + coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate); + List coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper); + for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) { + Long secondUserId = coursePromotionCommissionPending.getSecondUserId(); + BigDecimal totalAmount = coursePromotionCommissionPending.getTotalAmount(); + DateTime updateDate = DateUtil.date(coursePromotionCommissionPending.getUpdateTime()); + String commissionStatus = coursePromotionCommissionPending.getCommissionStatus(); + CommissionStatusEnum commissionStatusEnum = CommissionStatusEnum.getEnumByValue(commissionStatus); + staffOrderCntMap.merge(secondUserId, 1, Integer::sum); + staffOrderAmountMap.merge(secondUserId, totalAmount, BigDecimal::add); + + if (!(CommissionStatusEnum.COMPLETED.equals(commissionStatusEnum) && updateDate.isAfterOrEquals(startDate) && updateDate.isBeforeOrEquals(endDate))) { + totalAmount = totalAmount.multiply(SystemConstant.FEE_RATE); + } + staffNetSalesAmountMap.merge(secondUserId, totalAmount, BigDecimal::add); + } + List userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserRoleEnum.STAFF, userInfoService); + List userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId); + + // 封装Map集合(键:主管id, 用户信息) + Map userInfoMap = new HashMap<>(); + for (UserInfo userInfo : userInfoList) { + userInfoMap.put(userInfo.getId(), userInfo); + } + + // 封装主管绩效排名列表 + List supervisorPerformanceSummaryVOS = new ArrayList<>(); + for (UserPerformanceSummary userPerformanceSummary : userPerformanceSummaryList) { + Long userId = userPerformanceSummary.getUserId(); + UserInfo userInfo = userInfoMap.get(userId); + SupervisorPerformanceSummaryVO supervisorPerformanceSummaryVO = SupervisorPerformanceSummaryVO.builder() + .nickName(userInfo.getNickName()) + .phoneNumber(userInfo.getPhoneNumber()) + .empCount(userPerformanceSummary.getEmpCount()) + .orderCount(staffOrderCntMap.get(userId)) + .totalAmount(staffOrderAmountMap.get(userId)) + .netAmount(staffNetSalesAmountMap.get(userId)) + .promoCount(staffCntMap.get(userId)) + .build(); + supervisorPerformanceSummaryVOS.add(supervisorPerformanceSummaryVO); + } + Page supervisorPerformanceSummaryVOPage = userPerformanceSummaryService.queryPage(userPerformanceSummaryRankQueryRequest, supervisorPerformanceSummaryVOS); + return ResultUtils.success(supervisorPerformanceSummaryVOPage); + } + + + +// /** +// * Web端管理员一键结算 +// * @param rakeRewardsUpdateRequest 抽成比例更新请求体 +// * @return 是否更新成功 +// */ +// @PostMapping("update/rate") +// @Operation(summary = "Web端管理员修改一、二级抽成比例", description = "参数:抽成比例更新请求体,权限:管理员,方法名:updateRakeRewardsRate") +// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) +// public BaseResponse updateRakeRewardsRate(@Valid @RequestBody RakeRewardsUpdateRequest rakeRewardsUpdateRequest) { +// userPerformanceSummaryService.updateRakeRewards(rakeRewardsUpdateRequest); +// return ResultUtils.success(true); +// } + + + + + + /** * Web端管理员修改一、二级抽成比例 * @param rakeRewardsUpdateRequest 抽成比例更新请求体 diff --git a/src/main/java/com/greenorange/promotion/model/dto/userPerformanceSummary/UserPerformanceSummaryRankQueryRequest.java b/src/main/java/com/greenorange/promotion/model/dto/userPerformanceSummary/UserPerformanceSummaryRankQueryRequest.java index 71da306..e930553 100644 --- a/src/main/java/com/greenorange/promotion/model/dto/userPerformanceSummary/UserPerformanceSummaryRankQueryRequest.java +++ b/src/main/java/com/greenorange/promotion/model/dto/userPerformanceSummary/UserPerformanceSummaryRankQueryRequest.java @@ -8,10 +8,10 @@ import java.io.Serial; import java.io.Serializable; /** - * 主管绩效排名查询请求体,继承自分页请求 PageRequest + * 绩效排名查询请求体,继承自分页请求 PageRequest */ @Data -@Schema(description = "主管绩效排名查询请求体", requiredProperties = {"current", "pageSize"}) +@Schema(description = "绩效排名查询请求体", requiredProperties = {"current", "pageSize"}) public class UserPerformanceSummaryRankQueryRequest extends PageRequest implements Serializable { /** diff --git a/src/main/java/com/greenorange/promotion/service/file/impl/FileInfoServiceImpl.java b/src/main/java/com/greenorange/promotion/service/file/impl/FileInfoServiceImpl.java index 5e4ae40..ad58865 100644 --- a/src/main/java/com/greenorange/promotion/service/file/impl/FileInfoServiceImpl.java +++ b/src/main/java/com/greenorange/promotion/service/file/impl/FileInfoServiceImpl.java @@ -63,7 +63,7 @@ public class FileInfoServiceImpl extends ServiceImpl String fileSuffix = FileUtil.getSuffix(multipartFile.getOriginalFilename()); final long LIMIT = 20 * 1024 * 1024L; ThrowUtils.throwIf(fileSize > LIMIT, ErrorCode.PARAMS_ERROR, "文件大小不能超过20MB"); - ThrowUtils.throwIf(!Arrays.asList("jpeg", "jpg", "svg", "png", "webp", "JPG").contains(fileSuffix),ErrorCode.PARAMS_ERROR, "文件类型错误"); + ThrowUtils.throwIf(!Arrays.asList("jpeg", "jpg", "svg", "png", "webp", "JPG", "pdf", "PDF").contains(fileSuffix),ErrorCode.PARAMS_ERROR, "文件类型错误"); } 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 3d58cf5..d614ef4 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/UserPerformanceSummaryService.java @@ -1,17 +1,17 @@ package com.greenorange.promotion.service.userInfo; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.greenorange.promotion.common.PageRequest; import com.greenorange.promotion.model.dto.CommonStringRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.MiniUserCourseOrderQueryRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.RakeRewardsQueryRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.RakeRewardsUpdateRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.UserCourseOrderQueryRequest; +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.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; import java.math.BigDecimal; +import java.util.List; import java.util.Map; /** @@ -49,4 +49,10 @@ public interface UserPerformanceSummaryService extends IService queryPage(UserPerformanceSummaryRankQueryRequest req, List allVos); } 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 d957398..aceaae7 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 @@ -3,16 +3,15 @@ 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.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.model.dto.CommonStringRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.MiniUserCourseOrderQueryRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.RakeRewardsQueryRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.RakeRewardsUpdateRequest; -import com.greenorange.promotion.model.dto.userPerformanceSummary.UserCourseOrderQueryRequest; +import com.greenorange.promotion.model.dto.userPerformanceSummary.*; import com.greenorange.promotion.model.entity.CourseOrder; import com.greenorange.promotion.model.entity.UserPerformanceSummary; +import com.greenorange.promotion.model.vo.userPerformanceSummary.SupervisorPerformanceSummaryVO; import com.greenorange.promotion.service.userInfo.UserInfoService; import com.greenorange.promotion.service.userInfo.UserPerformanceSummaryService; import com.greenorange.promotion.mapper.UserPerformanceSummaryMapper; @@ -25,7 +24,10 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.security.Key; +import java.util.Comparator; +import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -108,6 +110,66 @@ public class UserPerformanceSummaryServiceImpl extends ServiceImpl queryPage(UserPerformanceSummaryRankQueryRequest req, List allVos) { + long current = req.getCurrent(); // 页码 + long pageSize = req.getPageSize(); // 每页大小 + + // 1. 过滤 + List filtered = allVos.stream() + .filter(vo -> { + if (StringUtils.isNotBlank(req.getNickName())) { + return vo.getNickName() != null + && vo.getNickName().toLowerCase() + .contains(req.getNickName().toLowerCase()); + } + return true; + }) + .filter(vo -> { + if (StringUtils.isNotBlank(req.getPhoneNumber())) { + return vo.getPhoneNumber() != null + && vo.getPhoneNumber().contains(req.getPhoneNumber()); + } + return true; + }) + .collect(Collectors.toList()); + + // 2. 排序 + if (StringUtils.isNotBlank(req.getSortField())) { + Comparator cmp = Comparator.comparing(vo -> switch (req.getSortField()) { + case "totalAmount" -> vo.getTotalAmount(); + case "netAmount" -> vo.getNetAmount(); + case "promoCount" -> BigDecimal.valueOf(vo.getPromoCount()); + case "empCount" -> BigDecimal.valueOf(vo.getEmpCount()); + case "orderCount" -> BigDecimal.valueOf(vo.getOrderCount()); + default -> null; + }, Comparator.nullsLast(Comparator.naturalOrder())); + + if ("desc".equalsIgnoreCase(req.getSortOrder())) { + cmp = cmp.reversed(); + } + filtered.sort(cmp); + } + + // 3. 计算分页 + long total = filtered.size(); + long offset = (current - 1) * pageSize; + int start = (int)Math.min(offset, total); + int end = (int)Math.min(offset + pageSize, total); + List pageList = filtered.subList(start, end); + + // 4. 封装到 MyBatis-Plus 的 Page 对象 + Page page = new Page<>(current, pageSize); + page.setTotal(total); + page.setRecords(pageList); + + return page; + } + }