优化了效率

This commit is contained in:
2025-08-04 20:08:46 +08:00
parent 104a2b573e
commit 1e1a031f64
6 changed files with 266 additions and 206 deletions

View File

@ -70,7 +70,7 @@ public class PermissionCheck {
lambdaQueryWrapper.eq(StringUtils.isNotBlank(userRole), UserInfo::getUserRole, userRole);
UserInfo userInfo = userInfoService.getOne(lambdaQueryWrapper);
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "用户不存在");
// 将用户id存入request于记录日志
// 将用户id存入request方便后续在接口中使
request.setAttribute("userId", userInfo.getId());
// 获取用户权限的枚举类

View File

@ -251,7 +251,6 @@ public class UserInfoController {
@GetMapping("mini/logout")
@Operation(summary = "小程序端用户退出登录", description = "参数JWT权限管理员boss, admin)方法名userInfoMiniLogout")
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
// @SysLog(title = "用户管理", content = "小程序端用户退出登录")
public BaseResponse<Boolean> userInfoMiniLogout(@RequestHeader("Authorization") String token) {
// 获取token的过期时间
DecodedJWT decodedJWT = jwtUtils.verify(token);

View File

@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit;
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.core.toolkit.support.SFunction;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ResultUtils;
@ -32,6 +33,8 @@ 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.catalina.User;
import org.apache.commons.collections.map.LazyMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
@ -111,10 +114,11 @@ public class UserPerformanceSummaryController {
long pageSize = userPerformanceSummarySupervisorQueryRequest.getPageSize();
String nickName = userPerformanceSummarySupervisorQueryRequest.getNickName();
String phoneNumber = userPerformanceSummarySupervisorQueryRequest.getPhoneNumber();
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), "nickName", nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), "phoneNumber", phoneNumber);
queryWrapper.eq("userRole", UserConstant.SUPERVISOR_ROLE);
LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber);
queryWrapper.eq(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE);
queryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
List<Long> ids = userInfoList.stream().map(UserInfo::getId).collect(Collectors.toList());
if (ids.isEmpty()) ids.add(-10L);
@ -164,10 +168,11 @@ public class UserPerformanceSummaryController {
String phoneNumber = userPerformanceSummaryQueryRequest.getPhoneNumber();
Long supervisorUserId = userPerformanceSummaryQueryRequest.getSupervisorUserId();
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), "nickName", nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), "phoneNumber", phoneNumber);
queryWrapper.eq("parentUserId", supervisorUserId);
LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber);
queryWrapper.eq(UserInfo::getParentUserId, supervisorUserId);
queryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
List<Long> ids = userInfoList.stream().map(UserInfo::getId).collect(Collectors.toList());
if (ids.isEmpty()) ids.add(-10L);
@ -218,9 +223,11 @@ public class UserPerformanceSummaryController {
courseOrderQueryWrapper.in("orderStatus", OrderStatusConstant.SUCCESS, OrderStatusConstant.REFUNDED);
List<Long> ids = userInfoService.findAllSubUser(staffUserId);
List<UserInfo> userInfoList = commonService.findByFieldInTargetField(ids, userInfoService, Function.identity(), UserInfo::getId);
courseOrderQueryWrapper.in("userId", ids);
List<UserInfo> userInfoList = commonService.findByFieldInTargetFieldWithSpecificFields(ids, userInfoService, Function.identity(), UserInfo::getId,
List.of(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber));
courseOrderQueryWrapper.in("userId", ids);
Page<CourseOrder> page = courseOrderService.page(new Page<>(current, pageSize), courseOrderQueryWrapper);
List<CourseOrder> courseOrderList = page.getRecords();
List<CourseOrderDetailInfoVO> courseOrderDetailInfoVOS = commonService.convertList(courseOrderList, CourseOrderDetailInfoVO.class);
@ -234,7 +241,11 @@ public class UserPerformanceSummaryController {
courseOrderBaseInfoVOS.setPhoneNumber(userInfo.getPhoneNumber());
}
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = commonService.findByFieldInTargetField(courseOrderList, coursePromotionCommissionPendingService, CourseOrder::getId, CoursePromotionCommissionPending::getOrderId);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = commonService.findByFieldInTargetFieldWithSpecificFields(
courseOrderList, coursePromotionCommissionPendingService, CourseOrder::getId, CoursePromotionCommissionPending::getOrderId,
List.of(CoursePromotionCommissionPending::getFirstRate, CoursePromotionCommissionPending::getSecondRate, CoursePromotionCommissionPending::getFirstReward,
CoursePromotionCommissionPending::getSecondReward, CoursePromotionCommissionPending::getCommissionStatus, CoursePromotionCommissionPending::getOrderId));
// 封装Map集合用户id, 值:课程推广待提成记录)
Map<Long, CoursePromotionCommissionPending> coursePromotionCommissionPendingMap = new HashMap<>();
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) coursePromotionCommissionPendingMap.put(coursePromotionCommissionPending.getOrderId(), coursePromotionCommissionPending);
@ -280,11 +291,12 @@ public class UserPerformanceSummaryController {
isAddDate = false;
}
QueryWrapper<EmployeePromotionRecords> empQueryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<EmployeePromotionRecords> empQueryWrapper = new LambdaQueryWrapper<>();
if (isAddDate) {
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), EmployeePromotionRecords::getCreateTime, startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), EmployeePromotionRecords::getCreateTime, endDate);
}
empQueryWrapper.select(EmployeePromotionRecords::getFirstUserId);
List<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合主管id, 值:推广数量)
Map<Long, Integer> supervisorCntMap = new HashMap<>();
@ -299,9 +311,11 @@ public class UserPerformanceSummaryController {
Map<Long, BigDecimal> supervisorOrderAmountMap = new HashMap<>();
// 封装Map集合主管id, 值:净成交金额)
Map<Long, BigDecimal> supervisorNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate);
LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, endDate);
coursePromotionQueryWrapper.select(CoursePromotionCommissionPending::getFirstUserId, CoursePromotionCommissionPending::getTotalAmount,
CoursePromotionCommissionPending::getUpdateTime, CoursePromotionCommissionPending::getCommissionStatus);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper);
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) {
Long firstUserId = coursePromotionCommissionPending.getFirstUserId();
@ -331,8 +345,11 @@ public class UserPerformanceSummaryController {
userInfoQueryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName)
.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber)
.eq(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE);
userInfoQueryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(userInfoQueryWrapper);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetFieldWithSpecificFields(
userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId,
List.of(UserPerformanceSummary::getUserId, UserPerformanceSummary::getEmpCount));
// 封装Map集合主管id, 用户信息)
Map<Long, UserInfo> userInfoMap = new HashMap<>();
@ -384,11 +401,12 @@ public class UserPerformanceSummaryController {
} catch (Exception e) {
isAddDate = false;
}
QueryWrapper<EmployeePromotionRecords> empQueryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<EmployeePromotionRecords> empQueryWrapper = new LambdaQueryWrapper<>();
if (isAddDate) {
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), EmployeePromotionRecords::getCreateTime, startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), EmployeePromotionRecords::getCreateTime, endDate);
}
empQueryWrapper.select(EmployeePromotionRecords::getSecondUserId);
List<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合员工id, 值:推广数量)
Map<Long, Integer> staffCntMap = new HashMap<>();
@ -403,9 +421,11 @@ public class UserPerformanceSummaryController {
Map<Long, BigDecimal> staffOrderAmountMap = new HashMap<>();
// 封装Map集合员工id, 值:净成交金额)
Map<Long, BigDecimal> staffNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate);
LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), CoursePromotionCommissionPending::getCreateTime, endDate);
coursePromotionQueryWrapper.select(CoursePromotionCommissionPending::getSecondUserId, CoursePromotionCommissionPending::getTotalAmount,
CoursePromotionCommissionPending::getUpdateTime, CoursePromotionCommissionPending::getCommissionStatus);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper);
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) {
Long secondUserId = coursePromotionCommissionPending.getSecondUserId();
@ -435,9 +455,11 @@ public class UserPerformanceSummaryController {
userInfoQueryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName)
.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber)
.eq(UserInfo::getUserRole, UserConstant.STAFF_ROLE);
userInfoQueryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(userInfoQueryWrapper);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetFieldWithSpecificFields(
userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId,
List.of(UserPerformanceSummary::getUserId, UserPerformanceSummary::getEmpCount));
// 封装Map集合主管id, 用户信息)
Map<Long, UserInfo> userInfoMap = new HashMap<>();
for (UserInfo userInfo : userInfoList) {
@ -593,16 +615,17 @@ public class UserPerformanceSummaryController {
String nickName = miniUserPerformanceSummaryQueryRequest.getNickName();
String phoneNumber = miniUserPerformanceSummaryQueryRequest.getPhoneNumber();
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), "nickName", nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), "phoneNumber", phoneNumber);
queryWrapper.eq("userRole", UserConstant.SUPERVISOR_ROLE);
LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber);
queryWrapper.eq(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE);
queryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
List<Long> ids = userInfoList.stream().map(UserInfo::getId).collect(Collectors.toList());
if (ids.isEmpty()) ids.add(-10L);
QueryWrapper<UserPerformanceSummary> userPerformanceSummaryQueryWrapper = new QueryWrapper<>();
userPerformanceSummaryQueryWrapper.in("userId", ids);
LambdaQueryWrapper<UserPerformanceSummary> userPerformanceSummaryQueryWrapper = new LambdaQueryWrapper<>();
userPerformanceSummaryQueryWrapper.in(UserPerformanceSummary::getUserId, ids);
List<UserPerformanceSummary> userPerformanceSummaryList = userPerformanceSummaryService.list(userPerformanceSummaryQueryWrapper);
List<UserPerformanceSummaryDetailVO> userPerformanceSummaryDetailVOS = commonService.convertList(userPerformanceSummaryList, UserPerformanceSummaryDetailVO.class);
@ -637,16 +660,17 @@ public class UserPerformanceSummaryController {
String phoneNumber = miniUserPerformanceSummaryStaffQueryRequest.getPhoneNumber();
Long supervisorUserId = miniUserPerformanceSummaryStaffQueryRequest.getSupervisorUserId();
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), "nickName", nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), "phoneNumber", phoneNumber);
queryWrapper.eq("parentUserId", supervisorUserId);
LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName);
queryWrapper.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber);
queryWrapper.eq(UserInfo::getParentUserId, supervisorUserId);
queryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
List<Long> ids = userInfoList.stream().map(UserInfo::getId).collect(Collectors.toList());
if (ids.isEmpty()) ids.add(-10L);
QueryWrapper<UserPerformanceSummary> userPerformanceSummaryQueryWrapper = new QueryWrapper<>();
userPerformanceSummaryQueryWrapper.in("userId", ids);
LambdaQueryWrapper<UserPerformanceSummary> userPerformanceSummaryQueryWrapper = new LambdaQueryWrapper<>();
userPerformanceSummaryQueryWrapper.in(UserPerformanceSummary::getUserId, ids);
List<UserPerformanceSummary> userPerformanceSummaryList = userPerformanceSummaryService.list(userPerformanceSummaryQueryWrapper);
List<UserPerformanceSummaryDetailVO> userPerformanceSummaryDetailVOS = commonService.convertList(userPerformanceSummaryList, UserPerformanceSummaryDetailVO.class);
@ -679,14 +703,16 @@ public class UserPerformanceSummaryController {
public BaseResponse<List<CourseOrderDetailInfoVO>> miniListUserPerformanceSummary(@Valid @RequestBody MiniUserCourseOrderQueryRequest miniUserCourseOrderQueryRequest) {
String orderNumber = miniUserCourseOrderQueryRequest.getOrderNumber();
Long staffUserId = miniUserCourseOrderQueryRequest.getStaffUserId();
QueryWrapper<CourseOrder> courseOrderQueryWrapper = new QueryWrapper<>();
courseOrderQueryWrapper.eq(StringUtils.isNotBlank(orderNumber), "orderNumber", orderNumber);
courseOrderQueryWrapper.in("orderStatus", OrderStatusConstant.SUCCESS, OrderStatusConstant.REFUNDED);
LambdaQueryWrapper<CourseOrder> courseOrderQueryWrapper = new LambdaQueryWrapper<>();
courseOrderQueryWrapper.eq(StringUtils.isNotBlank(orderNumber), CourseOrder::getOrderNumber, orderNumber);
courseOrderQueryWrapper.in(CourseOrder::getOrderStatus, OrderStatusConstant.SUCCESS, OrderStatusConstant.REFUNDED);
List<Long> ids = userInfoService.findAllSubUser(staffUserId);
List<UserInfo> userInfoList = commonService.findByFieldInTargetField(ids, userInfoService, Function.identity(), UserInfo::getId);
courseOrderQueryWrapper.in("userId", ids);
List<UserInfo> userInfoList = commonService.findByFieldInTargetFieldWithSpecificFields(ids, userInfoService, Function.identity(), UserInfo::getId,
List.of(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber));
courseOrderQueryWrapper.in(CourseOrder::getUserId, ids);
courseOrderQueryWrapper.select(CourseOrder::getId, CourseOrder::getUserId, CourseOrder::getOrderNumber, CourseOrder::getTotalAmount, CourseOrder::getOrderStatus, CourseOrder::getCreateTime);
List<CourseOrder> courseOrderList = courseOrderService.list(courseOrderQueryWrapper);
List<CourseOrderDetailInfoVO> courseOrderDetailInfoVOS = commonService.convertList(courseOrderList, CourseOrderDetailInfoVO.class);
@ -699,7 +725,10 @@ public class UserPerformanceSummaryController {
courseOrderBaseInfoVOS.setPhoneNumber(userInfo.getPhoneNumber());
}
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = commonService.findByFieldInTargetField(courseOrderList, coursePromotionCommissionPendingService, CourseOrder::getId, CoursePromotionCommissionPending::getOrderId);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = commonService.findByFieldInTargetFieldWithSpecificFields(
courseOrderList, coursePromotionCommissionPendingService, CourseOrder::getId, CoursePromotionCommissionPending::getOrderId,
List.of(CoursePromotionCommissionPending::getFirstRate, CoursePromotionCommissionPending::getSecondRate, CoursePromotionCommissionPending::getFirstReward,
CoursePromotionCommissionPending::getSecondReward, CoursePromotionCommissionPending::getCommissionStatus, CoursePromotionCommissionPending::getOrderId));
// 封装Map集合用户id, 值:课程推广待提成记录)
Map<Long, CoursePromotionCommissionPending> coursePromotionCommissionPendingMap = new HashMap<>();
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) coursePromotionCommissionPendingMap.put(coursePromotionCommissionPending.getOrderId(), coursePromotionCommissionPending);
@ -743,11 +772,12 @@ public class UserPerformanceSummaryController {
isAddDate = false;
}
QueryWrapper<EmployeePromotionRecords> empQueryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<EmployeePromotionRecords> empQueryWrapper = new LambdaQueryWrapper<>();
if (isAddDate) {
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), EmployeePromotionRecords::getCreateTime, startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), EmployeePromotionRecords::getCreateTime, endDate);
}
empQueryWrapper.select(EmployeePromotionRecords::getFirstUserId);
List<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合主管id, 值:推广数量)
Map<Long, Integer> supervisorCntMap = new HashMap<>();
@ -762,9 +792,11 @@ public class UserPerformanceSummaryController {
Map<Long, BigDecimal> supervisorOrderAmountMap = new HashMap<>();
// 封装Map集合主管id, 值:净成交金额)
Map<Long, BigDecimal> supervisorNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate);
LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, endDate);
coursePromotionQueryWrapper.select(CoursePromotionCommissionPending::getFirstUserId, CoursePromotionCommissionPending::getTotalAmount,
CoursePromotionCommissionPending::getUpdateTime, CoursePromotionCommissionPending::getCommissionStatus);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper);
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) {
Long firstUserId = coursePromotionCommissionPending.getFirstUserId();
@ -794,8 +826,11 @@ public class UserPerformanceSummaryController {
userInfoLambdaQueryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName)
.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber)
.eq(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE);
userInfoLambdaQueryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(userInfoLambdaQueryWrapper);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetFieldWithSpecificFields(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId,
List.of(UserPerformanceSummary::getUserId, UserPerformanceSummary::getEmpCount));
// 封装Map集合主管id, 用户信息)
Map<Long, UserInfo> userInfoMap = new HashMap<>();
@ -849,11 +884,12 @@ public class UserPerformanceSummaryController {
isAddDate = false;
}
QueryWrapper<EmployeePromotionRecords> empQueryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<EmployeePromotionRecords> empQueryWrapper = new LambdaQueryWrapper<>();
if (isAddDate) {
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "createTime", startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "createTime", endDate);
empQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), EmployeePromotionRecords::getCreateTime, startDate);
empQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), EmployeePromotionRecords::getCreateTime, endDate);
}
empQueryWrapper.select(EmployeePromotionRecords::getSecondUserId);
List<EmployeePromotionRecords> employeePromotionRecordsList = employeePromotionRecordsService.list(empQueryWrapper);
// 封装Map集合员工id, 值:推广数量)
Map<Long, Integer> staffCntMap = new HashMap<>();
@ -868,9 +904,11 @@ public class UserPerformanceSummaryController {
Map<Long, BigDecimal> staffOrderAmountMap = new HashMap<>();
// 封装Map集合员工id, 值:净成交金额)
Map<Long, BigDecimal> staffNetSalesAmountMap = new HashMap<>();
QueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new QueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), "orderCreateTime", startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), "orderCreateTime", endDate);
LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
coursePromotionQueryWrapper.ge(StringUtils.isNotBlank(startTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, startDate);
coursePromotionQueryWrapper.le(StringUtils.isNotBlank(endTimeStr), CoursePromotionCommissionPending::getOrderCreateTime, endDate);
coursePromotionQueryWrapper.select(CoursePromotionCommissionPending::getSecondUserId, CoursePromotionCommissionPending::getTotalAmount,
CoursePromotionCommissionPending::getUpdateTime, CoursePromotionCommissionPending::getCommissionStatus);
List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(coursePromotionQueryWrapper);
for (CoursePromotionCommissionPending coursePromotionCommissionPending : coursePromotionCommissionPendingList) {
Long secondUserId = coursePromotionCommissionPending.getSecondUserId();
@ -900,6 +938,7 @@ public class UserPerformanceSummaryController {
userInfoLambdaQueryWrapper.eq(StringUtils.isNotBlank(nickName), UserInfo::getNickName, nickName)
.eq(StringUtils.isNotBlank(phoneNumber), UserInfo::getPhoneNumber, phoneNumber)
.eq(UserInfo::getUserRole, UserConstant.STAFF_ROLE);
userInfoLambdaQueryWrapper.select(UserInfo::getId, UserInfo::getNickName, UserInfo::getPhoneNumber);
List<UserInfo> userInfoList = userInfoService.list(userInfoLambdaQueryWrapper);
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(userInfoList, userPerformanceSummaryService, UserInfo::getId, UserPerformanceSummary::getUserId);

View File

@ -12,19 +12,6 @@ import java.util.function.Function;
public interface CommonService {
// /**
// * 从源集合中提取指定属性并作为查询条件查询目标集合
// * @param sourceList 源集合List<T>),包含需要提取属性的元素
// * @param service 执行查询的 Service
// * @param getField 提取源集合中每个元素的属性值的函数
// * @param targetField 目标集合中查询字段的字段名
// * @param <T> 源集合元素类型
// * @param <R> 目标集合中元素类型
// * @return 查询结果集合
// */
// <T, R> List<R> findByFieldInTargetField(List<T> sourceList, IService<R> service, Function<T, Object> getField, String targetField);
/**
* 从源集合中提取指定属性并作为查询条件查询目标集合
*
@ -45,19 +32,6 @@ public interface CommonService {
// /**
// * 根据指定字段名和值,使用给定的服务对象构建查询条件。
// * @param <T> 实体类类型
// * @param fieldName 查询字段的名称
// * @param fieldValue 查询字段的值
// * @param service 用于执行查询的服务层对象
// *
// * @return 返回构建的 QueryWrapper 对象,用于进一步查询或修改
// */
// <T> QueryWrapper<T> buildQueryWrapperByField(String fieldName, Object fieldValue, IService<T> service);
/**
* 根据指定字段和值,使用给定的服务对象构建查询条件。
*
@ -74,16 +48,6 @@ public interface CommonService {
);
// /**
// * 根据指定字段名和值,使用给定的服务对象查询对应的实体类列表。
// * @param <T> 实体类类型
// * @param fieldName 查询字段的名称
// * @param fieldValue 查询字段的值
// * @param service 用于执行查询的服务层对象
// * @return 返回符合条件的实体类列表(`List<T>`)。如果没有符合条件的记录,返回空列表。
// */
// <T> List<T> findByFieldEqTargetField(String fieldName, Object fieldValue, IService<T> service);
/**
* 根据指定字段和值,使用给定的服务对象查询对应的实体类列表。
*
@ -100,19 +64,6 @@ public interface CommonService {
);
// /**
// * 根据多个字段和对应的值进行查询。
// * 该方法可以动态构建查询条件并执行查询。
// *
// * @param fieldConditions 查询条件的字段和值使用Map存储
// * @param service 执行查询操作的服务对象通常是MyBatis-Plus的 IService
// * @return 返回查询结果的列表
// */
// <T> List<T> findByFieldEqTargetFields(Map<String, Object> fieldConditions, IService<T> service);
/**
* 根据多个字段和对应的值进行查询。
* 该方法可以动态构建查询条件并执行查询。
@ -143,8 +94,6 @@ public interface CommonService {
/**
* 复制属性并返回新的目标对象
*
@ -157,4 +106,63 @@ public interface CommonService {
<S, T> T copyProperties(S source, Class<T> targetClass);
/**
* 从源集合中提取指定属性并作为查询条件查询目标集合,同时只返回指定的属性。
* 通过 MyBatis-Plus 的 `select` 方法,限制查询时返回的字段,避免查询不必要的字段,从而提高性能。
*
* @param sourceList 源集合List<T>),包含需要提取属性的元素
* @param service 执行查询的 MyBatis-Plus IService<R> 实例,用于调用数据库查询方法
* @param sourceField 提取源集合中每个元素的属性值的函数(如 T::getId用于获取源集合中元素的属性值
* @param targetField 目标集合中查询字段的函数引用(如 R::getForeignId用于指定查询条件
* @param targetFields 需要返回的目标字段列表,包含希望从目标集合中查询的字段(如 R::getId, R::getName
* @param <T> 源集合元素类型
* @param <R> 目标集合中元素类型
* @return 查询结果集合,包含指定字段的数据,其他字段为 null
*/
<T, R> List<R> findByFieldInTargetFieldWithSpecificFields(
List<T> sourceList,
IService<R> service,
Function<T, ?> sourceField,
SFunction<R, ?> targetField,
List<SFunction<R, ?>> targetFields
);
/**
* 根据指定字段和值,使用给定的服务对象查询对应的实体类列表,并且只返回指定的字段。
*
* @param <T> 实体类类型
* @param field 目标查询字段的函数引用(如 User::getUsername
* @param fieldValue 查询字段的值
* @param service 用于执行查询的服务层对象
* @param targetFields 需要返回的目标字段列表
* @return 返回符合条件的实体类列表List<T>)。如果没有符合条件的记录,返回空列表。
*/
<T> List<T> findByFieldEqTargetFieldWithSpecificFields(
SFunction<T, ?> field,
Object fieldValue,
IService<T> service,
List<SFunction<T, ?>> targetFields
);
/**
* 根据多个字段和对应的值进行查询,同时只返回指定的字段。
* 该方法可以动态构建查询条件并执行查询。
*
* @param <T> 实体类类型
* @param fieldConditions 查询条件的字段引用和值,使用 Map 存储
* keyR::getXxxvalue对应的查询值
* @param service 执行查询操作的服务对象MyBatis-Plus 的 IService
* @param targetFields 需要返回的目标字段列表
* @return 返回查询结果的列表,只包含指定的字段
*/
<T> List<T> findByFieldEqTargetFieldsWithSpecificColumns(
Map<SFunction<T, ?>, Object> fieldConditions,
IService<T> service,
List<SFunction<T, ?>> targetFields
);
}

View File

@ -18,37 +18,6 @@ public class CommonServiceImpl implements CommonService {
//
// /**
// * 从源集合中提取指定属性并作为查询条件查询目标集合
// * @param sourceList 源集合List<T>),包含需要提取属性的元素
// * @param service 执行查询的 Service
// * @param getField 提取源集合中每个元素的属性值的函数
// * @param targetField 目标集合中查询字段的字段名
// * @param <T> 源集合元素类型
// * @param <R> 目标集合中元素类型
// * @return 查询结果集合
// */
// public <T, R> List<R> findByFieldInTargetField(List<T> sourceList, IService<R> service, Function<T, Object> getField, String targetField) {
// // 提取源集合中每个元素的字段值
// List<Object> fieldValues = sourceList.stream()
// .map(getField) // 提取每个元素的字段值
// .collect(Collectors.toList());
//
// // 如果 fieldValues 为空,直接返回空集合
// if (fieldValues.isEmpty()) {
// return List.of(); // 返回空集合
// }
//
// // 创建查询条件
// QueryWrapper<R> queryWrapper = new QueryWrapper<>();
// queryWrapper.in(targetField, fieldValues); // 根据字段值进行查询
//
// // 执行查询并返回结果
// return service.list(queryWrapper);
// }
/**
* 从源集合中提取指定属性并作为查询条件查询目标集合
*
@ -86,26 +55,6 @@ public class CommonServiceImpl implements CommonService {
}
// /**
// * 根据指定字段名和值,使用给定的服务对象构建查询条件。
// * @param <T> 实体类类型
// * @param fieldName 查询字段的名称
// * @param fieldValue 查询字段的值
// * @param service 用于执行查询的服务层对象
// *
// * @return 返回构建的 QueryWrapper 对象,用于进一步查询或修改
// */
// @Override
// public <T> QueryWrapper<T> buildQueryWrapperByField(String fieldName, Object fieldValue, IService<T> service) {
// // 创建 QueryWrapper动态构建查询条件
// QueryWrapper<T> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq(fieldName, fieldValue); // 设置等值查询条件
//
// // 返回 QueryWrapper供外部使用
// return queryWrapper;
// }
/**
* 根据指定字段和值,使用给定的服务对象构建查询条件。
*
@ -132,26 +81,6 @@ public class CommonServiceImpl implements CommonService {
// /**
// * 根据指定字段名和值,使用给定的服务对象查询对应的实体类列表。
// * @param <T> 实体类类型
// * @param fieldName 查询字段的名称
// * @param fieldValue 查询字段的值
// * @param service 用于执行查询的服务层对象
// *
// * @return 返回符合条件的实体类列表(`List<T>`)。如果没有符合条件的记录,返回空列表。
// */
// @Override
// public <T> List<T> findByFieldEqTargetField(String fieldName, Object fieldValue, IService<T> service) {
// // 创建 QueryWrapper动态构建查询条件
// QueryWrapper<T> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq(fieldName, fieldValue); // 设置等值查询条件
//
// // 执行查询
// return service.list(queryWrapper);
// }
/**
* 根据指定字段和值,使用给定的服务对象查询对应的实体类列表。
*
@ -177,30 +106,6 @@ public class CommonServiceImpl implements CommonService {
// /**
// * 根据多个字段和对应的值进行查询。
// * 该方法根据输入的查询条件,动态构建查询,并执行数据库查询。
// * @param fieldConditions 查询条件的字段和值使用Map存储
// * @param service 执行查询操作的服务对象通常是MyBatis-Plus的 IService
// * @return 返回查询结果的列表
// */
// @Override
// public <T> List<T> findByFieldEqTargetFields(Map<String, Object> fieldConditions, IService<T> service) {
// // 创建 QueryWrapper动态构建查询条件
// QueryWrapper<T> queryWrapper = new QueryWrapper<>();
//
// // 遍历传入的条件Map逐个设置查询条件
// for (Map.Entry<String, Object> entry : fieldConditions.entrySet()) {
// // 设置等值查询条件
// queryWrapper.eq(entry.getKey(), entry.getValue());
// }
//
// // 执行查询,并返回结果
// return service.list(queryWrapper);
// }
/**
* 根据多个字段和对应的值进行查询。
* 该方法可以动态构建查询条件并执行查询。
@ -286,4 +191,114 @@ public class CommonServiceImpl implements CommonService {
}
/**
* 从源集合中提取指定属性并作为查询条件查询目标集合,同时只返回指定的属性。
* 通过 MyBatis-Plus 的 `select` 方法,限制查询时返回的字段,避免查询不必要的字段,从而提高性能。
*
* @param sourceList 源集合List<T>),包含需要提取属性的元素
* @param service 执行查询的 MyBatis-Plus IService<R> 实例,用于调用数据库查询方法
* @param sourceField 提取源集合中每个元素的属性值的函数(如 T::getId用于获取源集合中元素的属性值
* @param targetField 目标集合中查询字段的函数引用(如 R::getForeignId用于指定查询条件
* @param targetFields 需要返回的目标字段列表,包含希望从目标集合中查询的字段(如 R::getId, R::getName
* @param <T> 源集合元素类型
* @param <R> 目标集合中元素类型
* @return 查询结果集合,包含指定字段的数据,其他字段为 null
*/
@Override
public <T, R> List<R> findByFieldInTargetFieldWithSpecificFields(
List<T> sourceList,
IService<R> service,
Function<T, ?> sourceField,
SFunction<R, ?> targetField,
List<SFunction<R, ?>> targetFields
) {
// 提取源集合中每个元素的字段值,获取源集合中每个元素的属性值
List<Object> fieldValues = sourceList.stream()
.map(sourceField) // 使用传入的 sourceField 函数获取每个元素的属性值
.collect(Collectors.toList()); // 收集到 List 中
// 如果源集合为空,直接返回空集合
if (fieldValues.isEmpty()) {
return List.of(); // 返回一个空集合
}
// 使用 LambdaQueryWrapper 构造 in 查询条件,确保查询时根据源集合中提取的字段值进行筛选
LambdaQueryWrapper<R> query = new LambdaQueryWrapper<>();
query.in(targetField, fieldValues); // 设置查询条件targetField 在 fieldValues 中
// 动态选择需要返回的字段,传入指定的 targetFields 列表
query.select(targetFields.toArray(new SFunction[0])); // 将 targetFields 列表转换为数组传递给 select 方法
// 执行查询并返回结果
return service.list(query); // 执行查询并返回查询结果
}
/**
* 根据指定字段和值,使用给定的服务对象查询对应的实体类列表,并且只返回指定的字段。
*
* @param <T> 实体类类型
* @param field 目标查询字段的函数引用(如 User::getUsername
* @param fieldValue 查询字段的值
* @param service 用于执行查询的服务层对象
* @param targetFields 需要返回的目标字段列表
* @return 返回符合条件的实体类列表List<T>)。如果没有符合条件的记录,返回空列表。
*/
@Override
public <T> List<T> findByFieldEqTargetFieldWithSpecificFields(
SFunction<T, ?> field,
Object fieldValue,
IService<T> service,
List<SFunction<T, ?>> targetFields
) {
// 构建 LambdaQueryWrapper并设置等值查询条件
LambdaQueryWrapper<T> query = new LambdaQueryWrapper<>();
query.eq(field, fieldValue); // 设置查询条件:等于指定字段和值
// 动态选择需要返回的字段
query.select(targetFields.toArray(new SFunction[0])); // 只返回指定的字段
// 执行查询并返回结果
return service.list(query);
}
/**
* 根据多个字段和对应的值进行查询,同时只返回指定的字段。
* 该方法可以动态构建查询条件并执行查询。
*
* @param <T> 实体类类型
* @param fieldConditions 查询条件的字段引用和值,使用 Map 存储
* keyR::getXxxvalue对应的查询值
* @param service 执行查询操作的服务对象MyBatis-Plus 的 IService
* @param targetFields 需要返回的目标字段列表
* @return 返回查询结果的列表,只包含指定的字段
*/
@Override
public <T> List<T> findByFieldEqTargetFieldsWithSpecificColumns(
Map<SFunction<T, ?>, Object> fieldConditions,
IService<T> service,
List<SFunction<T, ?>> targetFields
) {
// 构建 LambdaQueryWrapper添加查询条件
LambdaQueryWrapper<T> query = new LambdaQueryWrapper<>();
// 动态添加 EQ 条件
fieldConditions.forEach(query::eq);
// 选择只返回指定的字段
query.select(targetFields.toArray(new SFunction[0])); // 将 targetFields 转换为数组,传入 select 方法
// 执行查询并返回结果
return service.list(query);
}
}

View File

@ -7,7 +7,6 @@ import com.auth0.jwt.interfaces.DecodedJWT;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.exception.ThrowUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;