初步完成小程序模块

This commit is contained in:
chen-xin-zhi 2025-05-12 21:05:52 +08:00
parent eab0a0f2a3
commit a2b2888e86
6 changed files with 118 additions and 52 deletions

View File

@ -46,37 +46,37 @@ public class PermissionCheck {
**/
@Around("@annotation(requiresPermission)")
public Object check(ProceedingJoinPoint joinPoint, RequiresPermission requiresPermission) throws Throwable {
// // 获取请求对象
// HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
// // 接口的权限
// String mustRole = requiresPermission.mustRole();
// // 获取接口权限的枚举类
// UserRoleEnum interfaceRoleEnum = UserRoleEnum.getEnumByValue(mustRole);
// ThrowUtils.throwIf(interfaceRoleEnum == null, ErrorCode.NO_AUTH_ERROR);
// // 获取用户权限
// String token = request.getHeader("Authorization");
// ThrowUtils.throwIf(StringUtils.isBlank(token), ErrorCode.NO_AUTH_ERROR, "JWT为空");
// // 解析token
// DecodedJWT decodedJWT = jwtUtils.verify(token);
// String userAccount = decodedJWT.getClaim("userAccount").asString();
// String userPassword = decodedJWT.getClaim("userPassword").asString();
// // 查询用户信息
// LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// lambdaQueryWrapper.eq(UserInfo::getUserAccount, userAccount).eq(UserInfo::getUserPassword, userPassword);
// UserInfo userInfo = userInfoService.getOne(lambdaQueryWrapper);
// ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "用户不存在");
// // 将用户id存入request用于记录日志
// request.setAttribute("userId", userInfo.getId());
//
// // 获取用户权限的枚举类
// String userRole = userInfo.getUserRole();
// UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
//
// // 接口权限只能是 USERADMINBOSS用户权限是 ADMINBOSSUSERBAN
// // 校验角色
// ThrowUtils.throwIf(UserRoleEnum.USER.equals(userRoleEnum) && !UserRoleEnum.USER.equals(interfaceRoleEnum), ErrorCode.NO_AUTH_ERROR);
// ThrowUtils.throwIf(UserRoleEnum.BAN.equals(userRoleEnum), ErrorCode.NO_AUTH_ERROR, "用户已被封禁");
// ThrowUtils.throwIf(UserRoleEnum.ADMIN.equals(userRoleEnum) && UserRoleEnum.BOSS.equals(interfaceRoleEnum), ErrorCode.NO_AUTH_ERROR);
// 获取请求对象
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
// 接口的权限
String mustRole = requiresPermission.mustRole();
// 获取接口权限的枚举类
UserRoleEnum interfaceRoleEnum = UserRoleEnum.getEnumByValue(mustRole);
ThrowUtils.throwIf(interfaceRoleEnum == null, ErrorCode.NO_AUTH_ERROR);
// 获取用户权限
String token = request.getHeader("Authorization");
ThrowUtils.throwIf(StringUtils.isBlank(token), ErrorCode.NO_AUTH_ERROR, "JWT为空");
// 解析token
DecodedJWT decodedJWT = jwtUtils.verify(token);
String userAccount = decodedJWT.getClaim("userAccount").asString();
String userPassword = decodedJWT.getClaim("userPassword").asString();
// 查询用户信息
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserInfo::getUserAccount, userAccount).eq(UserInfo::getUserPassword, userPassword);
UserInfo userInfo = userInfoService.getOne(lambdaQueryWrapper);
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "用户不存在");
// 将用户id存入request用于记录日志
request.setAttribute("userId", userInfo.getId());
// 获取用户权限的枚举类
String userRole = userInfo.getUserRole();
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
// 接口权限只能是 USERADMINBOSS用户权限是 ADMINBOSSUSERBAN
// 校验角色
ThrowUtils.throwIf(UserRoleEnum.USER.equals(userRoleEnum) && !UserRoleEnum.USER.equals(interfaceRoleEnum), ErrorCode.NO_AUTH_ERROR);
ThrowUtils.throwIf(UserRoleEnum.BAN.equals(userRoleEnum), ErrorCode.NO_AUTH_ERROR, "用户已被封禁");
ThrowUtils.throwIf(UserRoleEnum.ADMIN.equals(userRoleEnum) && UserRoleEnum.BOSS.equals(interfaceRoleEnum), ErrorCode.NO_AUTH_ERROR);
return joinPoint.proceed();
}

View File

@ -3,6 +3,7 @@ package com.greenorange.promotion.controller.project;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
@ -15,13 +16,14 @@ import com.greenorange.promotion.model.dto.CommonRequest;
import com.greenorange.promotion.model.dto.project.ProjectAddRequest;
import com.greenorange.promotion.model.dto.project.ProjectQueryRequest;
import com.greenorange.promotion.model.dto.project.ProjectUpdateRequest;
import com.greenorange.promotion.model.dto.promoCodeApply.PromoCodeApplyRequest;
import com.greenorange.promotion.model.entity.*;
import com.greenorange.promotion.model.vo.project.ProjectCardVO;
import com.greenorange.promotion.model.vo.project.ProjectDetailVO;
import com.greenorange.promotion.model.vo.project.ProjectAllDetailVO;
import com.greenorange.promotion.model.vo.project.ProjectPageVO;
import com.greenorange.promotion.model.vo.project.ProjectVO;
import com.greenorange.promotion.model.vo.projectDetail.ProjectDetailVO;
import com.greenorange.promotion.model.vo.projectNotification.ProjectNotificationVO;
import com.greenorange.promotion.model.vo.promoCodeApply.PromoCodeApplyVO;
import com.greenorange.promotion.model.vo.userProject.UserProjectVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.project.*;
@ -36,7 +38,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -72,6 +77,9 @@ public class ProjectController {
@Resource
private UserProjectService userProjectService;
@Resource
private PromoCodeApplyService promoCodeApplyService;
/**
@ -82,8 +90,27 @@ public class ProjectController {
@Operation(summary = "小程序用户查看项目列表", description = "参数权限管理员方法名queryProjectCardList")
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
@SysLog(title = "项目管理", content = "小程序用户查看项目列表")
public BaseResponse<List<ProjectCardVO>> queryProjectCardList() {
public BaseResponse<List<ProjectCardVO>> queryProjectCardList(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
// 获取项目明细抽佣列表
List<ProjectCommission> projectCommissionList = commonService.findByFieldEqTargetField(ProjectCommission::getUserId, userId, projectCommissionService);
// 封装Map集合项目id, 项目总价
Map<Long, BigDecimal> projectPriceMap = new HashMap<>();
for (ProjectCommission projectCommission : projectCommissionList) {
Long projectId = projectCommission.getProjectId();
BigDecimal projectPrice = projectPriceMap.get(projectId);
if (projectPrice == null) {
projectPrice = projectCommission.getMyUnitPrice();
} else {
projectPrice = projectPrice.add(projectCommission.getMyUnitPrice());
}
projectPriceMap.put(projectId, projectPrice);
}
List<Project> projectList = projectService.list();
for (Project project : projectList) {
BigDecimal projectPrice = projectPriceMap.get(project.getId());
project.setProjectPrice(projectPrice);
}
List<ProjectCardVO> projectCardVOS = commonService.convertList(projectList, ProjectCardVO.class);
return ResultUtils.success(projectCardVOS);
}
@ -97,26 +124,46 @@ public class ProjectController {
@Operation(summary = "小程序用户根据id查询项目详情", description = "参数权限管理员方法名queryProjectDetailById")
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
@SysLog(title = "项目管理", content = "小程序用户根据id查询项目详情")
public BaseResponse<ProjectDetailVO> queryProjectDetailById(@Valid @RequestBody CommonRequest commonRequest) {
public BaseResponse<ProjectAllDetailVO> queryProjectDetailById(@Valid @RequestBody CommonRequest commonRequest, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
Long id = commonRequest.getId();
Project project = projectService.getById(id);
ProjectDetailVO projectDetailVO = commonService.copyProperties(project, ProjectDetailVO.class);
ProjectAllDetailVO projectAllDetailVO = commonService.copyProperties(project, ProjectAllDetailVO.class);
// 获取项目通知列表
LambdaQueryWrapper<ProjectNotification> notificationLambdaQueryWrapper = new LambdaQueryWrapper<>();
notificationLambdaQueryWrapper.eq(ProjectNotification::getProjectId, id);
List<ProjectNotification> projectNotificationList = projectNotificationService.list(notificationLambdaQueryWrapper);
List<ProjectNotification> projectNotificationList = commonService.findByFieldEqTargetField(ProjectNotification::getProjectId, id, projectNotificationService);
List<ProjectNotificationVO> projectNotificationVOS = commonService.convertList(projectNotificationList, ProjectNotificationVO.class);
// 获取项目明细列表
LambdaQueryWrapper<ProjectDetail> projectDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
projectDetailLambdaQueryWrapper.eq(ProjectDetail::getProjectId, id);
List<ProjectDetail> projectDetailList = projectDetailService.list(projectDetailLambdaQueryWrapper);
List<ProjectDetail> projectDetailList = commonService.findByFieldEqTargetField(ProjectDetail::getProjectId, id, projectDetailService);
List<ProjectDetailVO> projectDetailVOS = commonService.convertList(projectDetailList, ProjectDetailVO.class);
// 将项目明细的价格修改为当前用户的单价
Map<SFunction<ProjectCommission, ?>, Object> fieldConditions = Map.of(ProjectCommission::getUserId, userId, ProjectCommission::getProjectId, id);
List<ProjectCommission> projectCommissionList = commonService.findByFieldEqTargetFields(fieldConditions, projectCommissionService);
// 封装Map集合项目明细id, 项目结算价格
Map<Long, BigDecimal> projectCommissionMap = new HashMap<>();
for (ProjectCommission projectCommission : projectCommissionList) {
Long projectDetailId = projectCommission.getProjectDetailId();
BigDecimal projectSettlementPrice = projectCommission.getMyUnitPrice();
projectCommissionMap.put(projectDetailId, projectSettlementPrice);
}
// 修改项目明细的结算价格
BigDecimal projectPrice = BigDecimal.ZERO;
for (ProjectDetailVO projectDetailVO : projectDetailVOS) {
BigDecimal projectSettlementPrice = projectCommissionMap.get(projectDetailVO.getId());
ThrowUtils.throwIf(projectSettlementPrice == null, ErrorCode.PARAMS_ERROR, "项目明细不存在");
projectDetailVO.setProjectSettlementPrice(projectSettlementPrice);
projectPrice = projectPrice.add(projectSettlementPrice);
}
// 更新项目价格
projectAllDetailVO.setProjectPrice(projectPrice);
// 获取用户申请的推广码列表
List<PromoCodeApply> promoCodeApplyList = commonService.findByFieldEqTargetField(PromoCodeApply::getUserId, userId, promoCodeApplyService);
List<PromoCodeApplyVO> promoCodeApplyVOList = commonService.convertList(promoCodeApplyList, PromoCodeApplyVO.class);
// 填充项目详情VO
projectAllDetailVO.setProjectNotificationVOList(projectNotificationVOS);
projectAllDetailVO.setProjectAllDetailVOList(projectDetailVOS);
projectAllDetailVO.setPromoCodeApplyVOList(promoCodeApplyVOList);
// 更新项目明细价格
projectDetailVO.setProjectNotificationVOList(projectNotificationVOS);
projectDetailVO.setProjectDetailVOList(projectDetailVOS);
return ResultUtils.success(projectDetailVO);
return ResultUtils.success(projectAllDetailVO);
}

View File

@ -1,6 +1,7 @@
package com.greenorange.promotion.controller.project;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
@ -17,6 +18,7 @@ import com.greenorange.promotion.model.vo.projectDetail.ProjectDetailVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.project.ProjectCommissionService;
import com.greenorange.promotion.service.project.ProjectDetailService;
import com.greenorange.promotion.service.project.ProjectService;
import com.greenorange.promotion.service.project.SubUserProjectCommissionService;
import com.greenorange.promotion.service.userInfo.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
@ -59,6 +61,9 @@ public class ProjectDetailController {
@Resource
private UserInfoService userInfoService;
@Resource
private ProjectService projectService;
/**
* web端管理员添加项目明细
* @param projectDetailAddRequest 项目明细添加请求体
@ -72,6 +77,12 @@ public class ProjectDetailController {
ProjectDetail projectDetail = commonService.copyProperties(projectDetailAddRequest, ProjectDetail.class);
projectDetailService.save(projectDetail);
// 修改项目价格
Long pId = projectDetail.getProjectId();
Project project = projectService.getById(pId);
project.setProjectPrice(project.getProjectPrice().add(projectDetail.getProjectSettlementPrice()));
projectService.updateById(project);
// 获取所有的小程序用户
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserInfo::getUserRole, UserConstant.DEFAULT_ROLE);

View File

@ -1,6 +1,8 @@
package com.greenorange.promotion.model.dto.promoCode;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertFalse;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Min;
import lombok.Data;
@ -44,7 +46,6 @@ public class PromoCodeAddRequest implements Serializable {
/**
* 推广码状态(true:占用false:空闲)
*/
@NotBlank(message = "推广码状态不能为空")
@Schema(description = "推广码状态(true:占用false:空闲)", example = "false")
private Boolean promoCodeStatus;

View File

@ -1,7 +1,8 @@
package com.greenorange.promotion.model.vo.project;
import com.greenorange.promotion.model.entity.ProjectNotification;
import com.greenorange.promotion.model.vo.projectDetail.ProjectDetailVO;
import com.greenorange.promotion.model.vo.projectNotification.ProjectNotificationVO;
import com.greenorange.promotion.model.vo.promoCodeApply.PromoCodeApplyVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -11,7 +12,7 @@ import java.math.BigDecimal;
import java.util.List;
@Data
public class ProjectDetailVO implements Serializable {
public class ProjectAllDetailVO implements Serializable {
/**
* 项目 ID
@ -79,7 +80,13 @@ public class ProjectDetailVO implements Serializable {
* 项目明细列表
*/
@Schema(description = "项目明细列表")
private List<ProjectDetailVO> projectDetailVOList;
private List<ProjectDetailVO> projectAllDetailVOList;
/**
* 申请的推广码列表
*/
@Schema(description = "申请的推广码列表")
private List<PromoCodeApplyVO> promoCodeApplyVOList;
@Serial

View File

@ -12,7 +12,7 @@ import jakarta.validation.Valid;
@RestController
@RequestMapping("${entityNameLower}")
@Slf4j
@Tag(name = "${entityComment}管理")
@Tag(name = "${entityComment}模块")
public class ${entityName}Controller {
@Resource