添加了小程序端查询主管和员工业绩排名的功能

This commit is contained in:
2025-07-13 17:58:13 +08:00
parent e8a3317c70
commit 455802ee9f

View File

@ -624,4 +624,163 @@ public class UserPerformanceSummaryController {
}
/**
* 小程序端经理查询主管绩效排名
* @param userPerformanceSummaryRankQueryRequest 绩效排名查询请求体
* @return 用户绩效汇总列表
*/
@PostMapping("rank/supervisor")
@Operation(summary = "小程序端经理查询主管绩效排名", description = "参数绩效排名查询请求体权限管理员方法名miniListSupervisorPerformanceSummaryRankingsByPage")
@RequiresPermission(mustRole = UserConstant.MANAGER_ROLE)
public BaseResponse<List<SupervisorPerformanceSummaryVO>> miniListSupervisorPerformanceSummaryRankingsByPage(@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> supervisorCntMap = new HashMap<>();
for (EmployeePromotionRecords employeePromotionRecords : employeePromotionRecordsList) {
Long firstUserId = employeePromotionRecords.getFirstUserId();
supervisorCntMap.merge(firstUserId, 1, Integer::sum);
}
// 封装Map集合主管id, 值:下单数量)
Map<Long, Integer> supervisorOrderCntMap = new HashMap<>();
// 封装Map集合主管id, 值:下单金额)
Map<Long, BigDecimal> supervisorOrderAmountMap = new HashMap<>();
// 封装Map集合主管id, 值:净成交金额)
Map<Long, BigDecimal> supervisorNetSalesAmountMap = 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();
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);
supervisorOrderAmountMap.merge(firstUserId, 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);
}
List<UserInfo> userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserRoleEnum.SUPERVISOR, 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(supervisorOrderCntMap.get(userId))
.totalAmount(supervisorOrderAmountMap.get(userId))
.netAmount(supervisorNetSalesAmountMap.get(userId))
.promoCount(supervisorCntMap.get(userId))
.build();
supervisorPerformanceSummaryVOS.add(supervisorPerformanceSummaryVO);
}
return ResultUtils.success(supervisorPerformanceSummaryVOS);
}
/**
* 小程序端主管查询员工绩效排名
* @param userPerformanceSummaryRankQueryRequest 绩效排名查询请求体
* @return 用户绩效汇总列表
*/
@PostMapping("rank/staff")
@Operation(summary = "小程序端主管查询员工绩效排名", description = "参数绩效排名查询请求体权限管理员方法名miniListStaffUserPerformanceSummaryRankingsByPage")
@RequiresPermission(mustRole = UserConstant.SUPERVISOR_ROLE)
public BaseResponse<List<SupervisorPerformanceSummaryVO>> miniListStaffUserPerformanceSummaryRankingsByPage(@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);
}
return ResultUtils.success(supervisorPerformanceSummaryVOS);
}
}