diff --git a/src/main/java/com/greenorange/promotion/aop/OperateLogAspect.java b/src/main/java/com/greenorange/promotion/aop/OperateLogAspect.java index b310565..d11a4a3 100644 --- a/src/main/java/com/greenorange/promotion/aop/OperateLogAspect.java +++ b/src/main/java/com/greenorange/promotion/aop/OperateLogAspect.java @@ -170,6 +170,10 @@ public class OperateLogAspect { for (Object o : paramsArray) { if (o != null) { try { + // 排除掉 RequestFacade 类型的对象 + if (o instanceof org.apache.catalina.connector.RequestFacade) { + continue; // 跳过该对象 + } Object jsonObj = JSON.toJSON(o); params += jsonObj.toString() + " "; } catch (Exception e) { diff --git a/src/main/java/com/greenorange/promotion/controller/project/ProjectController.java b/src/main/java/com/greenorange/promotion/controller/project/ProjectController.java new file mode 100644 index 0000000..4f1f3ec --- /dev/null +++ b/src/main/java/com/greenorange/promotion/controller/project/ProjectController.java @@ -0,0 +1,146 @@ +package com.greenorange.promotion.controller.project; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.greenorange.promotion.annotation.RequiresPermission; +import com.greenorange.promotion.annotation.SysLog; +import com.greenorange.promotion.common.BaseResponse; +import com.greenorange.promotion.common.ErrorCode; +import com.greenorange.promotion.common.ResultUtils; +import com.greenorange.promotion.constant.UserConstant; +import com.greenorange.promotion.exception.ThrowUtils; +import com.greenorange.promotion.model.dto.CommonBatchRequest; +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.entity.Project; +import com.greenorange.promotion.model.vo.project.ProjectVO; +import com.greenorange.promotion.service.common.CommonService; +import com.greenorange.promotion.service.project.ProjectService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.greenorange.promotion.model.dto.CommonRequest; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + + +/** + * 项目 控制器 + */ +@RestController +@RequestMapping("project") +@Slf4j +@Tag(name = "项目管理") +public class ProjectController { + + @Resource + private ProjectService projectService; + + @Resource + private CommonService commonService; + + /** + * web端管理员添加项目 + * @param projectAddRequest 项目添加请求体 + * @return 是否添加成功 + */ + @PostMapping("add") + @Operation(summary = "web端管理员添加项目", description = "参数:项目添加请求体,权限:管理员,方法名:addProject") + public BaseResponse addProject(@Valid @RequestBody ProjectAddRequest projectAddRequest) { + Project project = commonService.copyProperties(projectAddRequest, Project.class); + projectService.save(project); + return ResultUtils.success(true); + } + + /** + * web端管理员根据id修改项目信息 + * @param projectUpdateRequest 项目更新请求体 + * @return 是否更新成功 + */ + @PostMapping("update") + @Operation(summary = "web端管理员更新项目", description = "参数:项目更新请求体,权限:管理员,方法名:updateProject") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "项目管理", content = "web端管理员根据id修改项目信息") + public BaseResponse updateProject(@Valid @RequestBody ProjectUpdateRequest projectUpdateRequest) { + Project project = commonService.copyProperties(projectUpdateRequest, Project.class); + projectService.updateById(project); + return ResultUtils.success(true); + } + + /** + * web端管理员根据id删除项目 + * @param commonRequest 项目删除请求体 + * @return 是否删除成功 + */ + @PostMapping("delete") + @Operation(summary = "web端管理员根据id删除项目", description = "参数:项目删除请求体,权限:管理员,方法名:delProject") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "项目管理", content = "web端管理员根据id删除项目") + public BaseResponse delProject(@Valid @RequestBody CommonRequest commonRequest) { + Long id = commonRequest.getId(); + projectService.removeById(id); + return ResultUtils.success(true); + } + + /** + * web端管理员批量删除项目 + * @param commonBatchRequest 项目批量删除请求体 + * @return 是否删除成功 + */ + @PostMapping("delBatch") + @Operation(summary = "web端管理员批量删除项目", description = "参数:项目批量删除请求体,权限:管理员,方法名:delBatchProject") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "项目管理", content = "web端管理员批量删除项目") + public BaseResponse delBatchProject(@Valid @RequestBody CommonBatchRequest commonBatchRequest) { + List ids = commonBatchRequest.getIds(); + projectService.removeByIds(ids); + return ResultUtils.success(true); + } + + /** + * web端管理员根据id查询项目 + * @param commonRequest 项目查询请求体 + * @return 项目信息 + */ + @PostMapping("queryById") + @Operation(summary = "web端管理员根据id查询项目", description = "参数:项目查询请求体,权限:管理员,方法名:queryProjectById") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "项目管理", content = "web端管理员根据id查询项目") + public BaseResponse queryProjectById(@Valid @RequestBody CommonRequest commonRequest) { + Long id = commonRequest.getId(); + Project project = projectService.getById(id); + ThrowUtils.throwIf(project == null, ErrorCode.OPERATION_ERROR, "当前项目不存在"); + ProjectVO projectVO = commonService.copyProperties(project, ProjectVO.class); + return ResultUtils.success(projectVO); + } + + /** + * Web端管理员分页查询项目 + * @param projectQueryRequest 项目查询请求体 + * @return 项目列表 + */ + @PostMapping("page") + @Operation(summary = "Web端管理员分页查询项目", description = "参数:项目查询请求体,权限:管理员,方法名:listProjectByPage") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "项目管理", content = "Web端管理员分页查询项目") + public BaseResponse> listProjectByPage(@Valid @RequestBody ProjectQueryRequest projectQueryRequest) { + long current = projectQueryRequest.getCurrent(); + long pageSize = projectQueryRequest.getPageSize(); + QueryWrapper queryWrapper = projectService.getQueryWrapper(projectQueryRequest); + Page page = projectService.page(new Page<>(current, pageSize), queryWrapper); + List projectList = page.getRecords(); + List projectVOList = commonService.convertList(projectList, ProjectVO.class); + Page voPage = new Page<>(current, pageSize); + voPage.setRecords(projectVOList); + voPage.setPages(page.getPages()); + voPage.setTotal(page.getTotal()); + return ResultUtils.success(voPage); + } +} \ No newline at end of file diff --git a/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java b/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java index 5db55af..95d1f43 100644 --- a/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java +++ b/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java @@ -68,6 +68,7 @@ public class UserInfoController { */ @PostMapping("login") @Operation(summary = "web端管理员登录", description = "参数:用户登录请求体,权限:管理员(boss, admin),方法名:userInfoLogin") + @SysLog(title = "用户管理", content = "web端管理员登录") public BaseResponse userInfoLogin(@Valid @RequestBody UserInfoLoginRequest userInfoLoginRequest, HttpServletRequest request) { String userAccount = userInfoLoginRequest.getUserAccount(); String userPassword = userInfoLoginRequest.getUserPassword(); @@ -84,6 +85,7 @@ public class UserInfoController { @PostMapping("logout") @Operation(summary = "web端管理员退出登录", description = "参数:JWT,权限:管理员(boss, admin),方法名:userInfoLogout") @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "用户管理", content = "web端管理员退出登录") public BaseResponse userInfoLogout(@RequestHeader("Authorization") String token) { // 获取token的过期时间 DecodedJWT decodedJWT = jwtUtils.verify(token); @@ -112,12 +114,14 @@ public class UserInfoController { /** - * web端管理员更新用户表 + * web端管理员根据id修改用户信息 * @param userInfoUpdateRequest 用户表更新请求体 * @return 是否更新成功 */ @PostMapping("update") @Operation(summary = "web端管理员更新用户", description = "参数:用户表更新请求体,权限:管理员(boss, admin),方法名:updateUserInfo") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "用户管理", content = "web端管理员根据id修改用户信息") public BaseResponse updateUserInfo(@Valid @RequestBody UserInfoUpdateRequest userInfoUpdateRequest) { UserInfo userInfo = commonService.copyProperties(userInfoUpdateRequest, UserInfo.class); userInfoService.updateById(userInfo); @@ -126,12 +130,14 @@ public class UserInfoController { /** - * web端管理员删除用户表 + * web端管理员根据id删除用户 * @param commonRequest 用户表删除请求体 * @return 是否删除成功 */ @PostMapping("delete") - @Operation(summary = "web端管理员删除用户", description = "参数:用户表删除请求体,权限:管理员(boss, admin),方法名:delUserInfo") + @Operation(summary = "web端管理员根据id删除用户", description = "参数:用户表删除请求体,权限:管理员(boss, admin),方法名:delUserInfo") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "用户管理", content = "web端管理员根据id删除用户表") public BaseResponse delUserInfo(@Valid @RequestBody CommonRequest commonRequest) { Long id = commonRequest.getId(); userInfoService.removeById(id); @@ -139,30 +145,27 @@ public class UserInfoController { } + /** - * Web端管理员分页查看用户表 - * @param userInfoQueryRequest 用户表查询请求体 - * @return 用户表列表 + * web端管理员批量删除用户 + * @param commonBatchRequest 用户表批量删除请求体 + * @return 是否删除成功 */ - @PostMapping("page") - @Operation(summary = "Web端管理员分页查看用户", description = "参数:用户表查询请求体,权限:管理员(boss, admin),方法名:listUserInfoByPage") - public BaseResponse> listUserInfoByPage(@Valid @RequestBody UserInfoQueryRequest userInfoQueryRequest) { - long current = userInfoQueryRequest.getCurrent(); - long pageSize = userInfoQueryRequest.getPageSize(); - QueryWrapper queryWrapper = userInfoService.getQueryWrapper(userInfoQueryRequest); - Page page = userInfoService.page(new Page<>(current, pageSize), queryWrapper); - List userInfoList = page.getRecords(); - List userInfoVOList = commonService.convertList(userInfoList, UserInfoVO.class); - Page voPage = new Page<>(current, pageSize); - voPage.setRecords(userInfoVOList); - voPage.setPages(page.getPages()); - voPage.setTotal(page.getTotal()); - return ResultUtils.success(voPage); + @PostMapping("delBatch") + @Operation(summary = "web端管理员批量删除用户", description = "参数:用户表批量删除请求体,权限:管理员(boss, admin),方法名:delBatchUserInfo") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "用户管理", content = "web端管理员批量删除用户表") + public BaseResponse delBatchUserInfo(@Valid @RequestBody CommonBatchRequest commonBatchRequest) { + List ids = commonBatchRequest.getIds(); + userInfoService.removeByIds(ids); + return ResultUtils.success(true); } + + /** - * web端管理员根据id查询用户表 + * web端管理员根据id查询用户 * @param commonRequest 用户表查询请求体 * @return 用户表信息 */ @@ -181,18 +184,28 @@ public class UserInfoController { - - /** - * web端管理员批量删除用户表 - * @param commonBatchRequest 用户表批量删除请求体 - * @return 是否删除成功 + * Web端管理员分页查询用户 + * @param userInfoQueryRequest 用户表查询请求体 + * @return 用户表列表 */ - @PostMapping("delBatch") - @Operation(summary = "web端管理员批量删除用户", description = "参数:用户表批量删除请求体,权限:管理员(boss, admin),方法名:delBatchUserInfo") - public BaseResponse delBatchUserInfo(@Valid @RequestBody CommonBatchRequest commonBatchRequest) { - List ids = commonBatchRequest.getIds(); - userInfoService.removeByIds(ids); - return ResultUtils.success(true); + @PostMapping("page") + @Operation(summary = "Web端管理员分页查询用户", description = "参数:用户表查询请求体,权限:管理员(boss, admin),方法名:listUserInfoByPage") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "用户管理", content = "Web端管理员分页查看用户") + public BaseResponse> listUserInfoByPage(@Valid @RequestBody UserInfoQueryRequest userInfoQueryRequest) { + long current = userInfoQueryRequest.getCurrent(); + long pageSize = userInfoQueryRequest.getPageSize(); + QueryWrapper queryWrapper = userInfoService.getQueryWrapper(userInfoQueryRequest); + Page page = userInfoService.page(new Page<>(current, pageSize), queryWrapper); + List userInfoList = page.getRecords(); + List userInfoVOList = commonService.convertList(userInfoList, UserInfoVO.class); + Page voPage = new Page<>(current, pageSize); + voPage.setRecords(userInfoVOList); + voPage.setPages(page.getPages()); + voPage.setTotal(page.getTotal()); + return ResultUtils.success(voPage); } + + } diff --git a/src/main/java/com/greenorange/promotion/generator/Generator.java b/src/main/java/com/greenorange/promotion/generator/Generator.java index 11ef511..70bb36b 100644 --- a/src/main/java/com/greenorange/promotion/generator/Generator.java +++ b/src/main/java/com/greenorange/promotion/generator/Generator.java @@ -24,12 +24,15 @@ public class Generator { // 根路径 private static final String ROOT_PATH = "/src/main/java"; + // 实体类属性名 + private static final String ENTITY_NAME_LOWER = "project"; + // 父包名 private static final String PARENT_PATH = "com.greenorange.promotion"; // 子包名 - private static final String CONTROLLER_PACKAGE = "controller.user"; - private static final String DTO_PACKAGE = "model.dto.user"; - private static final String VO_PACKAGE = "model.vo.user"; + private static final String CONTROLLER_PACKAGE = "controller." + ENTITY_NAME_LOWER; + private static final String DTO_PACKAGE = "model.dto." + ENTITY_NAME_LOWER; + private static final String VO_PACKAGE = "model.vo." + ENTITY_NAME_LOWER; // 生成的文件后缀名 private static final String DTO_ADD_REQUEST = "AddRequest.java"; @@ -48,11 +51,12 @@ public class Generator { // 作者 private static final String AUTHOR = "chenxinzhi"; // 表注释 - private static final String TABLE_COMMENT = "用户表"; + private static final String TABLE_COMMENT = "项目"; // 实体类名 - private static final String ENTITY_NAME = "UserInfo"; + private static final String ENTITY_NAME = "Project"; // 表名 - private static final String TABLE_NAME = "user_info"; + private static final String TABLE_NAME = "project"; + @@ -91,6 +95,7 @@ public class Generator { .injectionConfig(consumer -> { Map customMap = new HashMap<>(); customMap.put("entityName", ENTITY_NAME); // 示例值 + customMap.put("entityNameLower", ENTITY_NAME_LOWER); customMap.put("entityComment", TABLE_COMMENT); // 示例值 customMap.put("parentPackage", PARENT_PATH); customMap.put("controllerPackage", CONTROLLER_PACKAGE); diff --git a/src/main/java/com/greenorange/promotion/mapper/ProjectMapper.java b/src/main/java/com/greenorange/promotion/mapper/ProjectMapper.java new file mode 100644 index 0000000..ae653ae --- /dev/null +++ b/src/main/java/com/greenorange/promotion/mapper/ProjectMapper.java @@ -0,0 +1,18 @@ +package com.greenorange.promotion.mapper; + +import com.greenorange.promotion.model.entity.Project; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author 35880 +* @description 针对表【project(项目表)】的数据库操作Mapper +* @createDate 2025-05-06 14:19:08 +* @Entity com.greenorange.promotion.model.entity.Project +*/ +public interface ProjectMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/greenorange/promotion/model/dto/project/ProjectAddRequest.java b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectAddRequest.java new file mode 100644 index 0000000..8590fdf --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectAddRequest.java @@ -0,0 +1,138 @@ +package com.greenorange.promotion.model.dto.project; + +import com.greenorange.promotion.annotation.EnumValue; +import com.greenorange.promotion.model.enums.ProjectStatusEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 项目添加请求体 + */ +@Data +@Schema(description = "项目添加请求体", requiredProperties = { + "projectName", + "projectImage", + "maxProjectPrice", + "minProjectPrice", + "projectDescription", + "settlementDesc", + "projectDesc", + "projectFlow", + "applyPromoCodeDesc", + "projectSettlementCycle", + "currentPromotionCount", + "maxPromoterCount", + "projectStatus", + "isShelves", +}) +public class ProjectAddRequest implements Serializable { + + /** + * 项目名称 + */ + @NotBlank(message = "项目名称不能为空") + @Schema(description = "项目名称", example = "美团省钱包") + private String projectName; + + /** + * 项目图片URL + */ + @NotBlank(message = "项目图片URL不能为空") + @Schema(description = "项目图片URL", example = "http://xxx.png") + private String projectImage; + + /** + * 项目最高价格 + */ + @DecimalMin(value = "0", message = "项目最低价格不能小于0") + @Schema(description = "项目最高价格", example = "30") + private BigDecimal maxProjectPrice; + + /** + * 项目最低价格 + */ + @DecimalMin(value = "0", message = "项目最低价格不能小于0") + @Schema(description = "项目最低价格", example = "10") + private BigDecimal minProjectPrice; + + /** + * 项目简介 + */ + @NotBlank(message = "项目简介不能为空") + @Schema(description = "项目简介", example = "不限制推广方式,禁止/恶意/夸大虚假宣传") + private String projectDescription; + + /** + * 结算说明(富文本) + */ + @NotBlank(message = "结算说明(富文本)不能为空") + @Schema(description = "结算说明(富文本)", example = "富文本") + private String settlementDesc; + + /** + * 项目说明(富文本) + */ + @NotBlank(message = "项目说明(富文本)不能为空") + @Schema(description = "项目说明(富文本)", example = "富文本") + private String projectDesc; + + /** + * 项目流程(富文本) + */ + @NotBlank(message = "项目流程(富文本)不能为空") + @Schema(description = "项目流程(富文本)", example = "富文本") + private String projectFlow; + + /** + * 申请推广码说明(富文本) + */ + @NotBlank(message = "申请推广码说明(富文本)不能为空") + @Schema(description = "申请推广码说明(富文本)", example = "富文本") + private String applyPromoCodeDesc; + + /** + * 项目结算周期 + */ + @Min(value = 1, message = "项目结算周期不能小于1") + @Schema(description = "项目结算周期", example = "2") + private Integer projectSettlementCycle; + + /** + * 当前推广人数 + */ + @Min(value = 1, message = "当前推广人数不能小于1") + @Schema(description = "当前推广人数", example = "150") + private Integer currentPromotionCount; + + /** + * 最大推广人数 + */ + @Min(value = 1, message = "当前推广人数不能小于1") + @Schema(description = "最大推广人数", example = "200") + private Integer maxPromoterCount; + + /** + * 项目状态(项目运行|人数已满|项目暂停) + */ + @EnumValue(enumClass = ProjectStatusEnum.class) + @Schema(description = "项目状态", example = "项目运行") + private String projectStatus; + + /** + * 是否上架 + */ + @Schema(description = "是否上架", example = "true") + private Boolean isShelves; + + + @Serial + private static final long serialVersionUID = 1L; +} + diff --git a/src/main/java/com/greenorange/promotion/model/dto/project/ProjectQueryRequest.java b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectQueryRequest.java new file mode 100644 index 0000000..aefb45b --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectQueryRequest.java @@ -0,0 +1,39 @@ +package com.greenorange.promotion.model.dto.project; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +import com.greenorange.promotion.common.PageRequest; + +/** + * 项目查询请求体,继承自分页请求 PageRequest + */ +@Data +@Schema(description = "项目查询请求体", requiredProperties = {"current", "pageSize"}) +public class ProjectQueryRequest extends PageRequest implements Serializable { + + /** + * 项目 ID + */ + @Schema(description = "项目 ID", example = "1") + @Min(value = 1L, message = "项目 ID不能小于1") + private Long id; + + /** + * 项目名称 + */ + @NotBlank(message = "项目名称不能为空") + @Schema(description = "项目名称", example = "美团省钱包") + private String projectName; + + + @Serial + private static final long serialVersionUID = 1L; +} + diff --git a/src/main/java/com/greenorange/promotion/model/dto/project/ProjectUpdateRequest.java b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectUpdateRequest.java new file mode 100644 index 0000000..f851088 --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/dto/project/ProjectUpdateRequest.java @@ -0,0 +1,143 @@ +package com.greenorange.promotion.model.dto.project; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 项目更新请求体 + */ +@Data +@Schema(description = "项目更新请求体", requiredProperties = { + "id", + "projectName", + "projectImage", + "maxProjectPrice", + "minProjectPrice", + "projectDescription", + "settlementDesc", + "projectDesc", + "projectFlow", + "applyPromoCodeDesc", + "projectSettlementCycle", + "currentPromotionCount", + "maxPromoterCount", + "projectStatus", + "isShelves", +}) +public class ProjectUpdateRequest implements Serializable { + + /** + * 项目ID + */ + @Min(value = 1L, message = "项目 ID不能小于1") + @TableId(type = IdType.AUTO) + @Schema(description = "项目ID", example = "美团省钱包") + private Long id; + + /** + * 项目名称 + */ + @NotBlank(message = "项目名称不能为空") + @Schema(description = "项目名称", example = "美团省钱包") + private String projectName; + + /** + * 项目图片URL + */ + @NotBlank(message = "项目图片URL不能为空") + @Schema(description = "项目图片URL", example = "http://xxx.png") + private String projectImage; + + /** + * 项目最高价格 + */ + @DecimalMin(value = "0", message = "项目最低价格不能小于0") + @Schema(description = "项目最高价格", example = "30") + private BigDecimal maxProjectPrice; + + /** + * 项目最低价格 + */ + @DecimalMin(value = "0", message = "项目最低价格不能小于0") + @Schema(description = "项目最低价格", example = "10") + private BigDecimal minProjectPrice; + + /** + * 项目简介 + */ + @NotBlank(message = "项目简介不能为空") + @Schema(description = "项目简介", example = "不限制推广方式,禁止/恶意/夸大虚假宣传") + private String projectDescription; + + /** + * 结算说明(富文本) + */ + @NotBlank(message = "结算说明(富文本)不能为空") + @Schema(description = "结算说明(富文本)", example = "富文本") + private String settlementDesc; + + /** + * 项目说明(富文本) + */ + @NotBlank(message = "项目说明(富文本)不能为空") + @Schema(description = "项目说明(富文本)", example = "富文本") + private String projectDesc; + + /** + * 项目流程(富文本) + */ + @NotBlank(message = "项目流程(富文本)不能为空") + @Schema(description = "项目流程(富文本)", example = "富文本") + private String projectFlow; + + /** + * 申请推广码说明(富文本) + */ + @NotBlank(message = "申请推广码说明(富文本)不能为空") + @Schema(description = "申请推广码说明(富文本)", example = "富文本") + private String applyPromoCodeDesc; + + /** + * 项目结算周期 + */ + @Schema(description = "项目结算周期", example = "2") + private Integer projectSettlementCycle; + + /** + * 当前推广人数 + */ + @Schema(description = "当前推广人数", example = "150") + private Integer currentPromotionCount; + + /** + * 最大推广人数 + */ + @Schema(description = "最大推广人数", example = "200") + private Integer maxPromoterCount; + + /** + * 项目状态(项目运行|人数已满|项目暂停) + */ + @NotBlank(message = "项目状态不能为空") + @Schema(description = "项目状态", example = "项目运行") + private String projectStatus; + + /** + * 是否上架 + */ + @Schema(description = "是否上架", example = "true") + private Boolean isShelves; + + + @Serial + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java b/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java index f951a38..14bb896 100644 --- a/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java +++ b/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java @@ -66,7 +66,7 @@ public class UserInfoAddRequest implements Serializable { * 用户角色 */ @EnumValue(enumClass = UserRoleEnum.class) - @Schema(description = "用户角色", example = "USER") + @Schema(description = "用户角色", example = "user") private String userRole; /** diff --git a/src/main/java/com/greenorange/promotion/model/entity/Project.java b/src/main/java/com/greenorange/promotion/model/entity/Project.java new file mode 100644 index 0000000..613221d --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/entity/Project.java @@ -0,0 +1,112 @@ +package com.greenorange.promotion.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Data; + +/** + * 项目表 + * @TableName project + */ +@TableName(value ="project") +@Data +public class Project implements Serializable { + /** + * 项目ID + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 项目名称 + */ + private String projectName; + + /** + * 项目图片URL + */ + private String projectImage; + + /** + * 项目最高价格 + */ + private BigDecimal maxProjectPrice; + + /** + * 项目最低价格 + */ + private BigDecimal minProjectPrice; + + /** + * 项目简介 + */ + private String projectDescription; + + /** + * 结算说明(富文本) + */ + private String settlementDesc; + + /** + * 项目说明(富文本) + */ + private String projectDesc; + + /** + * 项目流程(富文本) + */ + private String projectFlow; + + /** + * 申请推广码说明(富文本) + */ + private String applyPromoCodeDesc; + + /** + * 项目结算周期 + */ + private Integer projectSettlementCycle; + + /** + * 当前推广人数 + */ + private Integer currentPromotionCount; + + /** + * 最大推广人数 + */ + private Integer maxPromoterCount; + + /** + * 项目状态(项目运行|人数已满|项目暂停) + */ + private String projectStatus; + + /** + * 是否上架 + */ + private Integer isShelves; + + /** + * 是否删除 + */ + private Integer isDelete; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/greenorange/promotion/model/enums/ProjectStatusEnum.java b/src/main/java/com/greenorange/promotion/model/enums/ProjectStatusEnum.java new file mode 100644 index 0000000..2a01da3 --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/enums/ProjectStatusEnum.java @@ -0,0 +1,48 @@ +package com.greenorange.promotion.model.enums; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@Getter +public enum ProjectStatusEnum { + + RUNNING("项目运行", "running"), + FULL("人数已满", "full"), + PAUSED("项目暂停", "paused"); + + private final String text; + private final String value; + + ProjectStatusEnum(String text, String value) { + this.text = text; + this.value = value; + } + + /** + * 获取值列表 + */ + public static List getValues() { + return Arrays.stream(values()) + .map(item -> item.value) + .collect(Collectors.toList()); + } + + /** + * 根据值获取枚举 + */ + public static ProjectStatusEnum getEnumByValue(String value) { + if (StringUtils.isBlank(value)) { + return null; + } + for (ProjectStatusEnum status : ProjectStatusEnum.values()) { + if (status.value.equals(value)) { + return status; + } + } + return null; + } +} diff --git a/src/main/java/com/greenorange/promotion/model/enums/UserRoleEnum.java b/src/main/java/com/greenorange/promotion/model/enums/UserRoleEnum.java index e5e01ee..b505dd0 100644 --- a/src/main/java/com/greenorange/promotion/model/enums/UserRoleEnum.java +++ b/src/main/java/com/greenorange/promotion/model/enums/UserRoleEnum.java @@ -2,7 +2,7 @@ package com.greenorange.promotion.model.enums; import lombok.Getter; import org.apache.commons.lang3.StringUtils; -import org.springframework.util.ObjectUtils; + import java.util.Arrays; import java.util.List; diff --git a/src/main/java/com/greenorange/promotion/model/vo/project/ProjectVO.java b/src/main/java/com/greenorange/promotion/model/vo/project/ProjectVO.java new file mode 100644 index 0000000..5dfeefc --- /dev/null +++ b/src/main/java/com/greenorange/promotion/model/vo/project/ProjectVO.java @@ -0,0 +1,110 @@ +package com.greenorange.promotion.model.vo.project; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 项目 视图对象 + */ +@Data +@Schema(description = "项目 视图对象") +public class ProjectVO implements Serializable { + + /** + * 项目 ID + */ + @Schema(description = "项目 ID", example = "1") + private Long id; + + /** + * 项目名称 + */ + @Schema(description = "项目名称", example = "美团省钱包") + private String projectName; + + /** + * 项目图片URL + */ + @Schema(description = "项目图片URL", example = "http://xxx.png") + private String projectImage; + + /** + * 项目最高价格 + */ + @Schema(description = "项目最高价格", example = "30") + private BigDecimal maxProjectPrice; + + /** + * 项目最低价格 + */ + @Schema(description = "项目最低价格", example = "10") + private BigDecimal minProjectPrice; + + /** + * 项目简介 + */ + @Schema(description = "项目简介", example = "不限制推广方式,禁止/恶意/夸大虚假宣传") + private String projectDescription; + + /** + * 结算说明(富文本) + */ + @Schema(description = "结算说明(富文本)", example = "富文本") + private String settlementDesc; + + /** + * 项目说明(富文本) + */ + @Schema(description = "项目说明(富文本)", example = "富文本") + private String projectDesc; + + /** + * 项目流程(富文本) + */ + @Schema(description = "项目流程(富文本)", example = "富文本") + private String projectFlow; + + /** + * 申请推广码说明(富文本) + */ + @Schema(description = "申请推广码说明(富文本)", example = "富文本") + private String applyPromoCodeDesc; + + /** + * 项目结算周期 + */ + @Schema(description = "项目结算周期", example = "2") + private Integer projectSettlementCycle; + + /** + * 当前推广人数 + */ + @Schema(description = "当前推广人数", example = "150") + private Integer currentPromotionCount; + + /** + * 最大推广人数 + */ + @Schema(description = "最大推广人数", example = "200") + private Integer maxPromoterCount; + + /** + * 项目状态(项目运行|人数已满|项目暂停) + */ + @Schema(description = "项目状态", example = "项目运行") + private String projectStatus; + + /** + * 是否上架 + */ + @Schema(description = "是否上架", example = "true") + private Boolean isShelves; + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/greenorange/promotion/service/project/ProjectService.java b/src/main/java/com/greenorange/promotion/service/project/ProjectService.java new file mode 100644 index 0000000..c59a491 --- /dev/null +++ b/src/main/java/com/greenorange/promotion/service/project/ProjectService.java @@ -0,0 +1,20 @@ +package com.greenorange.promotion.service.project; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.greenorange.promotion.model.dto.project.ProjectQueryRequest; +import com.greenorange.promotion.model.entity.Project; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author 35880 +* @description 针对表【project(项目表)】的数据库操作Service +* @createDate 2025-05-06 14:19:08 +*/ +public interface ProjectService extends IService { + + + /** + * 获取查询条件 + */ + QueryWrapper getQueryWrapper(ProjectQueryRequest projectQueryRequest); +} diff --git a/src/main/java/com/greenorange/promotion/service/project/impl/ProjectServiceImpl.java b/src/main/java/com/greenorange/promotion/service/project/impl/ProjectServiceImpl.java new file mode 100644 index 0000000..4689965 --- /dev/null +++ b/src/main/java/com/greenorange/promotion/service/project/impl/ProjectServiceImpl.java @@ -0,0 +1,43 @@ +package com.greenorange.promotion.service.project.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.greenorange.promotion.constant.CommonConstant; +import com.greenorange.promotion.model.dto.project.ProjectQueryRequest; +import com.greenorange.promotion.model.entity.Project; +import com.greenorange.promotion.model.entity.UserInfo; +import com.greenorange.promotion.service.project.ProjectService; +import com.greenorange.promotion.mapper.ProjectMapper; +import com.greenorange.promotion.utils.SqlUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +/** +* @author 35880 +* @description 针对表【project(项目表)】的数据库操作Service实现 +* @createDate 2025-05-06 14:19:08 +*/ +@Service +public class ProjectServiceImpl extends ServiceImpl + implements ProjectService{ + + /** + * 获取查询条件 + */ + @Override + public QueryWrapper getQueryWrapper(ProjectQueryRequest projectQueryRequest) { + Long id = projectQueryRequest.getId(); + String projectName = projectQueryRequest.getProjectName(); + String sortField = projectQueryRequest.getSortField(); + String sortOrder = projectQueryRequest.getSortOrder(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq(id != null, "id", id); + queryWrapper.eq(StringUtils.isNotBlank(projectName), "projectName", projectName); + queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField); + return queryWrapper; + } +} + + + + diff --git a/src/main/resources/mapper/ProjectMapper.xml b/src/main/resources/mapper/ProjectMapper.xml new file mode 100644 index 0000000..bf10e21 --- /dev/null +++ b/src/main/resources/mapper/ProjectMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + id,projectName,projectImage, + maxProjectPrice,minProjectPrice,projectDescription, + settlementDesc,projectDesc,projectFlow, + applyPromoCodeDesc,projectSettlementCycle,currentPromotionCount, + maxPromoterCount,projectStatus,isShelves, + isDelete,createTime,updateTime + + diff --git a/src/main/resources/templates/controller.java.vm b/src/main/resources/templates/controller.java.vm index 6d17f5a..ed8e28a 100644 --- a/src/main/resources/templates/controller.java.vm +++ b/src/main/resources/templates/controller.java.vm @@ -1,100 +1,82 @@ package ${parentPackage}.${controllerPackage}; -import java.util.List; +import org.springframework.web.bind.annotation.RequestBody; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.greenorange.promotion.model.dto.CommonRequest; +import jakarta.validation.Valid; + /** * ${entityComment} 控制器 */ @RestController -@RequestMapping("${entityName}") +@RequestMapping("${tableName}") @Slf4j @Tag(name = "${entityComment}管理") public class ${entityName}Controller { @Resource - private ${entityName}Service ${entityName}Service; + private ${entityName}Service ${entityNameLower}Service; @Resource private CommonService commonService; /** * web端管理员添加${entityComment} - * @param ${entityName}AddRequest ${entityComment}添加请求体 + * @param ${entityNameLower}AddRequest ${entityComment}添加请求体 * @return 是否添加成功 */ @PostMapping("add") - @Operation(summary = "web端管理员添加${entityComment}", description = "参数:${entityComment}添加请求体,权限:管理员(boss, admin),方法名:add${entityName}") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse add${entityName}(@RequestBody ${entityName}AddRequest ${entityName}AddRequest) { - if (${entityName}AddRequest == null) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } - ${entityName} ${entityName} = new ${entityName}(); - BeanUtils.copyProperties(${entityName}AddRequest, ${entityName}); - boolean result = ${entityName}Service.save(${entityName}); - ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}添加失败"); + @Operation(summary = "web端管理员添加${entityComment}", description = "参数:${entityComment}添加请求体,权限:管理员,方法名:add${entityName}") + public BaseResponse add${entityName}(@Valid @RequestBody ${entityName}AddRequest ${entityNameLower}AddRequest) { + ${entityName} ${entityNameLower} = commonService.copyProperties(${entityNameLower}AddRequest, ${entityName}.class); + ${entityNameLower}Service.save(${entityNameLower}); return ResultUtils.success(true); } /** - * web端管理员更新${entityComment} - * @param ${entityName}UpdateRequest ${entityComment}更新请求体 + * web端管理员根据id修改${entityComment}信息 + * @param ${entityNameLower}UpdateRequest ${entityComment}更新请求体 * @return 是否更新成功 */ @PostMapping("update") - @Operation(summary = "web端管理员更新${entityComment}", description = "参数:${entityComment}更新请求体,权限:管理员(boss, admin),方法名:update${entityName}") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse update${entityName}(@RequestBody ${entityName}UpdateRequest ${entityName}UpdateRequest) { - if (${entityName}UpdateRequest == null || ${entityName}UpdateRequest.getId() <= 0) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } - ${entityName} ${entityName} = new ${entityName}(); - BeanUtils.copyProperties(${entityName}UpdateRequest, ${entityName}); - boolean result = ${entityName}Service.updateById(${entityName}); - ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}更新失败"); + @Operation(summary = "web端管理员更新${entityComment}", description = "参数:${entityComment}更新请求体,权限:管理员,方法名:update${entityName}") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "${entityComment}管理", content = "web端管理员根据id修改${entityComment}信息") + public BaseResponse update${entityName}(@Valid @RequestBody ${entityName}UpdateRequest ${entityNameLower}UpdateRequest) { + ${entityName} ${entityNameLower} = commonService.copyProperties(${entityNameLower}UpdateRequest, ${entityName}.class); + ${entityNameLower}Service.updateById(${entityNameLower}); return ResultUtils.success(true); } /** - * web端管理员删除${entityComment} + * web端管理员根据id删除${entityComment} * @param commonRequest ${entityComment}删除请求体 * @return 是否删除成功 */ @PostMapping("delete") - @Operation(summary = "web端管理员删除${entityComment}", description = "参数:${entityComment}删除请求体,权限:管理员(boss, admin),方法名:del${entityName}") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse del${entityName}(@RequestBody CommonRequest commonRequest) { - if (commonRequest == null || commonRequest.getId() <= 0) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } + @Operation(summary = "web端管理员根据id删除${entityComment}", description = "参数:${entityComment}删除请求体,权限:管理员,方法名:del${entityName}") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "${entityComment}管理", content = "web端管理员根据id删除${entityComment}") + public BaseResponse del${entityName}(@Valid @RequestBody CommonRequest commonRequest) { Long id = commonRequest.getId(); - boolean result = ${entityName}Service.removeById(id); - ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}删除失败"); + ${entityNameLower}Service.removeById(id); return ResultUtils.success(true); } /** - * Web端管理员分页查看${entityComment} - * @param ${entityName}QueryRequest ${entityComment}查询请求体 - * @return ${entityComment}列表 + * web端管理员批量删除${entityComment} + * @param commonBatchRequest ${entityComment}批量删除请求体 + * @return 是否删除成功 */ - @PostMapping("page") - @Operation(summary = "Web端管理员分页查看${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员(boss, admin),方法名:list${entityName}ByPage") - public BaseResponse> list${entityName}ByPage(@RequestBody ${entityName}QueryRequest ${entityName}QueryRequest) { - if (${entityName}QueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR); - long current = ${entityName}QueryRequest.getCurrent(); - long pageSize = ${entityName}QueryRequest.getPageSize(); - QueryWrapper<${entityName}> queryWrapper = ${entityName}Service.getQueryWrapper(${entityName}QueryRequest); - Page<${entityName}> page = ${entityName}Service.page(new Page<>(current, pageSize), queryWrapper); - List<${entityName}> ${entityName}List = page.getRecords(); - List<${entityName}VO> ${entityName}VOList = commonService.convertList(${entityName}List, ${entityName}VO.class); - Page<${entityName}VO> voPage = new Page<>(); - voPage.setRecords(${entityName}VOList); - voPage.setPages(page.getPages()); - voPage.setCurrent(page.getCurrent()); - voPage.setTotal(page.getTotal()); - voPage.setSize(page.getSize()); - return ResultUtils.success(voPage); + @PostMapping("delBatch") + @Operation(summary = "web端管理员批量删除${entityComment}", description = "参数:${entityComment}批量删除请求体,权限:管理员,方法名:delBatch${entityName}") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "${entityComment}管理", content = "web端管理员批量删除${entityComment}") + public BaseResponse delBatch${entityName}(@Valid @RequestBody CommonBatchRequest commonBatchRequest) { + List ids = commonBatchRequest.getIds(); + ${entityNameLower}Service.removeByIds(ids); + return ResultUtils.success(true); } /** @@ -103,32 +85,37 @@ public class ${entityName}Controller { * @return ${entityComment}信息 */ @PostMapping("queryById") - @Operation(summary = "web端管理员根据id查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员(boss, admin),方法名:query${entityName}ById") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse<${entityName}VO> query${entityName}ById(@RequestBody CommonRequest commonRequest) { - if (commonRequest == null || commonRequest.getId() <= 0) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } - ${entityName} ${entityName} = ${entityName}Service.getById(commonRequest.getId()); - ThrowUtils.throwIf(${entityName} == null, ErrorCode.NOT_FOUND, "${entityComment}未找到"); - ${entityName}VO ${entityName}VO = commonService.convert(${entityName}, ${entityName}VO.class); - return ResultUtils.success(${entityName}VO); + @Operation(summary = "web端管理员根据id查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员,方法名:query${entityName}ById") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "${entityComment}管理", content = "web端管理员根据id查询${entityComment}") + public BaseResponse<${entityName}VO> query${entityName}ById(@Valid @RequestBody CommonRequest commonRequest) { + Long id = commonRequest.getId(); + ${entityName} ${entityNameLower} = ${entityNameLower}Service.getById(id); + ThrowUtils.throwIf(${entityNameLower} == null, ErrorCode.OPERATION_ERROR, "当前${entityComment}不存在"); + ${entityName}VO ${entityNameLower}VO = commonService.copyProperties(${entityNameLower}, ${entityName}VO.class); + return ResultUtils.success(${entityNameLower}VO); } /** - * web端管理员批量删除${entityComment} - * @param commonRequest ${entityComment}批量删除请求体 - * @return 是否删除成功 + * Web端管理员分页查询${entityComment} + * @param ${entityNameLower}QueryRequest ${entityComment}查询请求体 + * @return ${entityComment}列表 */ - @PostMapping("delBatch") - @Operation(summary = "web端管理员批量删除${entityComment}", description = "参数:${entityComment}批量删除请求体,权限:管理员(boss, admin),方法名:delBatch${entityName}") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse delBatch${entityName}(@RequestBody CommonRequest commonRequest) { - if (commonRequest == null || commonRequest.getIds() == null || commonRequest.getIds().isEmpty()) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } - boolean result = ${entityName}Service.removeByIds(commonRequest.getIds()); - ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}批量删除失败"); - return ResultUtils.success(true); + @PostMapping("page") + @Operation(summary = "Web端管理员分页查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员,方法名:list${entityName}ByPage") + @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE) + @SysLog(title = "${entityComment}管理", content = "Web端管理员分页查询${entityComment}") + public BaseResponse> list${entityName}ByPage(@Valid @RequestBody ${entityName}QueryRequest ${entityNameLower}QueryRequest) { + long current = ${entityNameLower}QueryRequest.getCurrent(); + long pageSize = ${entityNameLower}QueryRequest.getPageSize(); + QueryWrapper<${entityName}> queryWrapper = ${entityNameLower}Service.getQueryWrapper(${entityNameLower}QueryRequest); + Page<${entityName}> page = ${entityNameLower}Service.page(new Page<>(current, pageSize), queryWrapper); + List<${entityName}> ${entityNameLower}List = page.getRecords(); + List<${entityName}VO> ${entityNameLower}VOList = commonService.convertList(${entityNameLower}List, ${entityName}VO.class); + Page<${entityName}VO> voPage = new Page<>(current, pageSize); + voPage.setRecords(${entityNameLower}VOList); + voPage.setPages(page.getPages()); + voPage.setTotal(page.getTotal()); + return ResultUtils.success(voPage); } -} +} \ No newline at end of file diff --git a/src/main/resources/templates/dto/Addrequest.java.vm b/src/main/resources/templates/dto/Addrequest.java.vm index 5258036..442e330 100644 --- a/src/main/resources/templates/dto/Addrequest.java.vm +++ b/src/main/resources/templates/dto/Addrequest.java.vm @@ -1,6 +1,8 @@ package ${parentPackage}.${dtoPackage}; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; import lombok.Data; import java.io.Serial; @@ -10,7 +12,13 @@ import java.io.Serializable; * ${entityComment}添加请求体 */ @Data -@Schema(description = "${entityComment}添加请求体", requiredProperties = {"name", "categoryId", "price", "image", "period", "isShelves"}) +@Schema(description = "${entityComment}添加请求体", requiredProperties = { + #foreach($field in ${table.fields}) + #if(!$field.keyFlag && $field.propertyName != "id" && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete") + "${field.propertyName}", + #end + #end +}) public class ${entityName}AddRequest implements Serializable { #foreach($field in ${table.fields}) @@ -18,7 +26,13 @@ public class ${entityName}AddRequest implements Serializable { /** * ${field.comment} */ - @Schema(description = "${field.comment}", example = "${field.example}") + #if($field.propertyType == "String") + @NotBlank(message = "${field.comment}不能为空") + #end + #if($field.propertyType == "Long") + @Min(value = 1L, message = "${field.comment} ID不能小于1") + #end + @Schema(description = "${field.comment}", example = "") private ${field.propertyType} ${field.propertyName}; #end @@ -27,3 +41,4 @@ public class ${entityName}AddRequest implements Serializable { @Serial private static final long serialVersionUID = 1L; } + diff --git a/src/main/resources/templates/dto/QueryRequest.java.vm b/src/main/resources/templates/dto/QueryRequest.java.vm index 3ed2210..1f47253 100644 --- a/src/main/resources/templates/dto/QueryRequest.java.vm +++ b/src/main/resources/templates/dto/QueryRequest.java.vm @@ -1,10 +1,13 @@ package ${parentPackage}.${dtoPackage}; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; import lombok.Data; + import java.io.Serial; import java.io.Serializable; -import ${parentPackage}.common.PageRequest; +import com.greenorange.promotion.common.PageRequest; /** * ${entityComment}查询请求体,继承自分页请求 PageRequest @@ -17,6 +20,7 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab * ${entityComment} ID */ @Schema(description = "${entityComment} ID", example = "1") + @Min(value = 1L, message = "${entityComment} ID不能小于1") private Long id; #foreach($field in ${table.fields}) @@ -24,7 +28,10 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab /** * ${field.comment} */ - @Schema(description = "${field.comment}", example = "${field.example}") + #if($field.propertyType == "String") + @NotBlank(message = "${field.comment}不能为空") + #end + @Schema(description = "${field.comment}", example = "") private ${field.propertyType} ${field.propertyName}; #end @@ -33,3 +40,4 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab @Serial private static final long serialVersionUID = 1L; } + diff --git a/src/main/resources/templates/dto/UpdateRequest.java.vm b/src/main/resources/templates/dto/UpdateRequest.java.vm index 1054c53..883cdc6 100644 --- a/src/main/resources/templates/dto/UpdateRequest.java.vm +++ b/src/main/resources/templates/dto/UpdateRequest.java.vm @@ -1,6 +1,8 @@ package ${parentPackage}.${dtoPackage}; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Min; import lombok.Data; import java.io.Serial; @@ -10,21 +12,27 @@ import java.io.Serializable; * ${entityComment}更新请求体 */ @Data -@Schema(description = "${entityComment}更新请求体", requiredProperties = {"id", "name", "categoryId", "price", "image", "period", "isShelves"}) +@Schema(description = "${entityComment}更新请求体", requiredProperties = { + #foreach($field in ${table.fields}) + #if(!$field.keyFlag && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete") + "${field.propertyName}", + #end + #end +}) public class ${entityName}UpdateRequest implements Serializable { - /** - * ${entityComment} ID - */ - @Schema(description = "${entityComment} ID", example = "1") - private Long id; - #foreach($field in ${table.fields}) #if(!$field.keyFlag && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete") /** * ${field.comment} */ - @Schema(description = "${field.comment}", example = "${field.example}") + #if($field.propertyType == "String") + @NotBlank(message = "${field.comment}不能为空") + #end + #if($field.propertyType == "Long") + @Min(value = 1L, message = "${field.comment} ID不能小于1") + #end + @Schema(description = "${field.comment}", example = "") private ${field.propertyType} ${field.propertyName}; #end @@ -32,4 +40,4 @@ public class ${entityName}UpdateRequest implements Serializable { @Serial private static final long serialVersionUID = 1L; -} +} \ No newline at end of file diff --git a/src/main/resources/templates/vo/VO.java.vm b/src/main/resources/templates/vo/VO.java.vm index 6a0c64c..6eb5d9f 100644 --- a/src/main/resources/templates/vo/VO.java.vm +++ b/src/main/resources/templates/vo/VO.java.vm @@ -5,6 +5,7 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.math.BigDecimal; /** * ${entityComment} 视图对象