添加了查询员工,主管业绩功能

This commit is contained in:
2025-07-13 13:45:59 +08:00
parent d13bd60a84
commit c2972e7d9f
5 changed files with 186 additions and 43 deletions

View File

@ -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<Page<CourseOrderBaseInfoVO>> listUserPerformanceSummaryRankingsByPage(@Valid @RequestBody UserPerformanceSummaryRankQueryRequest userPerformanceSummaryRankQueryRequest) {
public BaseResponse<Page<SupervisorPerformanceSummaryVO>> 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<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合主管id, 值:推广数量)
Map<Long, Integer> supervisorCntMap = new HashMap<>();
// 封装Map集合员工id, 值:推广数量)
Map<Long, Integer> 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<Long, Integer> supervisorOrderCntMap = new HashMap<>();
// 封装Map集合员工id, 值:下单数量
Map<Long, Integer> staffOrderCntMap = new HashMap<>();
// 主管id, 值:下单金额)
// 封装Map集合主管id, 值:下单金额
Map<Long, BigDecimal> supervisorOrderAmountMap = new HashMap<>();
// (键:员工id, 值:下单金额)
Map<Long, BigDecimal> staffOrderAmountMap = new HashMap<>();
// 主管id, 值:净成交金额)
// 封装Map集合(键:主管id, 值:净成交金额)
Map<Long, BigDecimal> supervisorNetSalesAmountMap = new HashMap<>();
// 员工id, 值:净成交金额)
Map<Long, BigDecimal> staffNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
List<CoursePromotionCommissionPending> 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<Long, Integer> supervisorStaffCntMap = new HashMap<>();
List<UserInfo> userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserRoleEnum.SUPERVISOR, userInfoService);
List<UserPerformanceSummary> 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<SupervisorPerformanceSummaryVO> 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<Page<SupervisorPerformanceSummaryVO>> 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<EmployeePromotionRecords> empQueryWrapper = new QueryWrapper<>();
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
List<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合员工id, 值:推广数量)
Map<Long, Integer> staffCntMap = new HashMap<>();
for (EmployeePromotionRecords employeePromotionRecords : employeePromotionRecordsList) {
Long secondUserId = employeePromotionRecords.getSecondUserId();
staffCntMap.merge(secondUserId, 1, Integer::sum);
}
// 封装Map集合员工id, 值:下单数量)
Map<Long, Integer> staffOrderCntMap = new HashMap<>();
// 封装Map集合员工id, 值:下单金额)
Map<Long, BigDecimal> staffOrderAmountMap = new HashMap<>();
// 封装Map集合员工id, 值:净成交金额)
Map<Long, BigDecimal> staffNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
List<CoursePromotionCommissionPending> 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<UserInfo> userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserRoleEnum.STAFF, userInfoService);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId);
// 封装Map集合主管id, 用户信息)
Map<Long, UserInfo> userInfoMap = new HashMap<>();
for (UserInfo userInfo : userInfoList) {
userInfoMap.put(userInfo.getId(), userInfo);
}
// 封装主管绩效排名列表
List<SupervisorPerformanceSummaryVO> 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<SupervisorPerformanceSummaryVO> 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<Boolean> updateRakeRewardsRate(@Valid @RequestBody RakeRewardsUpdateRequest rakeRewardsUpdateRequest) {
// userPerformanceSummaryService.updateRakeRewards(rakeRewardsUpdateRequest);
// return ResultUtils.success(true);
// }
/**
* Web端管理员修改一、二级抽成比例
* @param rakeRewardsUpdateRequest 抽成比例更新请求体

View File

@ -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 {
/**

View File

@ -63,7 +63,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo>
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, "文件类型错误");
}

View File

@ -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<UserPerformanceS
* Web端管理员根据级别查询抽佣比例
*/
BigDecimal queryRakeRewardsRateByLevel(RakeRewardsQueryRequest rakeRewardsQueryRequest);
/**
* 在内存 List 上模拟 MyBatis-Plus 的分页
*/
Page<SupervisorPerformanceSummaryVO> queryPage(UserPerformanceSummaryRankQueryRequest req, List<SupervisorPerformanceSummaryVO> allVos);
}

View File

@ -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<UserPerforman
String level = rakeRewardsQueryRequest.getLevel();
return new BigDecimal(redisTemplate.opsForHash().get(KEY, level).toString());
}
/**
* 在内存 List 上模拟 MyBatis-Plus 的分页
*/
public Page<SupervisorPerformanceSummaryVO> queryPage(UserPerformanceSummaryRankQueryRequest req, List<SupervisorPerformanceSummaryVO> allVos) {
long current = req.getCurrent(); // 页码
long pageSize = req.getPageSize(); // 每页大小
// 1. 过滤
List<SupervisorPerformanceSummaryVO> 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<SupervisorPerformanceSummaryVO> 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<SupervisorPerformanceSummaryVO> pageList = filtered.subList(start, end);
// 4. 封装到 MyBatis-Plus 的 Page 对象
Page<SupervisorPerformanceSummaryVO> page = new Page<>(current, pageSize);
page.setTotal(total);
page.setRecords(pageList);
return page;
}
}