diff --git a/src/main/java/com/gxwebsoft/booking/controller/CategoryController.java b/src/main/java/com/gxwebsoft/booking/controller/CategoryController.java new file mode 100644 index 0000000..7d8a614 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/controller/CategoryController.java @@ -0,0 +1,115 @@ +package com.gxwebsoft.booking.controller; + +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.booking.service.CategoryService; +import com.gxwebsoft.booking.entity.Category; +import com.gxwebsoft.booking.param.CategoryParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.system.entity.User; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 课程分类控制器 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Api(tags = "课程分类管理") +@RestController +@RequestMapping("/api/booking/category") +public class CategoryController extends BaseController { + @Resource + private CategoryService categoryService; + + @ApiOperation("分页查询课程分类") + @GetMapping("/page") + public ApiResult> page(CategoryParam param) { + // 使用关联查询 + return success(categoryService.pageRel(param)); + } + + @ApiOperation("查询全部课程分类") + @GetMapping() + public ApiResult> list(CategoryParam param) { + // 使用关联查询 + return success(categoryService.listRel(param)); + } + + @PreAuthorize("hasAuthority('booking:category:list')") + @ApiOperation("根据id查询课程分类") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(categoryService.getByIdRel(id)); + } + + @ApiOperation("添加课程分类") + @PostMapping() + public ApiResult save(@RequestBody Category category) { + // 记录当前登录用户id + // User loginUser = getLoginUser(); + // if (loginUser != null) { + // category.setUserId(loginUser.getUserId()); + // } + if (categoryService.save(category)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改课程分类") + @PutMapping() + public ApiResult update(@RequestBody Category category) { + if (categoryService.updateById(category)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除课程分类") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (categoryService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加课程分类") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (categoryService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改课程分类") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(categoryService, "category_id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除课程分类") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (categoryService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/booking/controller/LessonController.java b/src/main/java/com/gxwebsoft/booking/controller/LessonController.java new file mode 100644 index 0000000..04b6220 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/controller/LessonController.java @@ -0,0 +1,115 @@ +package com.gxwebsoft.booking.controller; + +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.booking.service.LessonService; +import com.gxwebsoft.booking.entity.Lesson; +import com.gxwebsoft.booking.param.LessonParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.system.entity.User; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 课程管理控制器 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Api(tags = "课程管理管理") +@RestController +@RequestMapping("/api/booking/lesson") +public class LessonController extends BaseController { + @Resource + private LessonService lessonService; + + @ApiOperation("分页查询课程管理") + @GetMapping("/page") + public ApiResult> page(LessonParam param) { + // 使用关联查询 + return success(lessonService.pageRel(param)); + } + + @ApiOperation("查询全部课程管理") + @GetMapping() + public ApiResult> list(LessonParam param) { + // 使用关联查询 + return success(lessonService.listRel(param)); + } + + @PreAuthorize("hasAuthority('booking:lesson:list')") + @ApiOperation("根据id查询课程管理") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(lessonService.getByIdRel(id)); + } + + @ApiOperation("添加课程管理") + @PostMapping() + public ApiResult save(@RequestBody Lesson lesson) { + // 记录当前登录用户id + // User loginUser = getLoginUser(); + // if (loginUser != null) { + // lesson.setUserId(loginUser.getUserId()); + // } + if (lessonService.save(lesson)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改课程管理") + @PutMapping() + public ApiResult update(@RequestBody Lesson lesson) { + if (lessonService.updateById(lesson)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除课程管理") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (lessonService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加课程管理") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (lessonService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改课程管理") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(lessonService, "lesson_id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除课程管理") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (lessonService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/booking/controller/TeacherController.java b/src/main/java/com/gxwebsoft/booking/controller/TeacherController.java new file mode 100644 index 0000000..c9ec93d --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/controller/TeacherController.java @@ -0,0 +1,115 @@ +package com.gxwebsoft.booking.controller; + +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.booking.service.TeacherService; +import com.gxwebsoft.booking.entity.Teacher; +import com.gxwebsoft.booking.param.TeacherParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.system.entity.User; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 老师管理控制器 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Api(tags = "老师管理管理") +@RestController +@RequestMapping("/api/booking/teacher") +public class TeacherController extends BaseController { + @Resource + private TeacherService teacherService; + + @ApiOperation("分页查询老师管理") + @GetMapping("/page") + public ApiResult> page(TeacherParam param) { + // 使用关联查询 + return success(teacherService.pageRel(param)); + } + + @ApiOperation("查询全部老师管理") + @GetMapping() + public ApiResult> list(TeacherParam param) { + // 使用关联查询 + return success(teacherService.listRel(param)); + } + + @PreAuthorize("hasAuthority('booking:teacher:list')") + @ApiOperation("根据id查询老师管理") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(teacherService.getByIdRel(id)); + } + + @ApiOperation("添加老师管理") + @PostMapping() + public ApiResult save(@RequestBody Teacher teacher) { + // 记录当前登录用户id + // User loginUser = getLoginUser(); + // if (loginUser != null) { + // teacher.setUserId(loginUser.getUserId()); + // } + if (teacherService.save(teacher)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改老师管理") + @PutMapping() + public ApiResult update(@RequestBody Teacher teacher) { + if (teacherService.updateById(teacher)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除老师管理") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (teacherService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加老师管理") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (teacherService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改老师管理") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(teacherService, "teacher_id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除老师管理") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (teacherService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/booking/entity/Category.java b/src/main/java/com/gxwebsoft/booking/entity/Category.java new file mode 100644 index 0000000..7332469 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/entity/Category.java @@ -0,0 +1,92 @@ +package com.gxwebsoft.booking.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableLogic; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 课程分类 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Category对象", description = "课程分类") +@TableName("booking_category") +public class Category implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "商品分类ID") + @TableId(value = "category_id", type = IdType.AUTO) + private Integer categoryId; + + @ApiModelProperty(value = "分类标识") + private String categoryCode; + + @ApiModelProperty(value = "分类名称") + private String title; + + @ApiModelProperty(value = "类型 0列表 1单页 2外链") + private Integer type; + + @ApiModelProperty(value = "分类图片") + private String image; + + @ApiModelProperty(value = "上级分类ID") + private Integer parentId; + + @ApiModelProperty(value = "路由/链接地址") + private String path; + + @ApiModelProperty(value = "组件路径") + private String component; + + @ApiModelProperty(value = "绑定的页面") + private Integer pageId; + + @ApiModelProperty(value = "用户ID") + private Integer userId; + + @ApiModelProperty(value = "商品数量") + private Integer count; + + @ApiModelProperty(value = "排序(数字越小越靠前)") + private Integer sortNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单)") + private Integer hide; + + @ApiModelProperty(value = "是否推荐") + private Integer recommend; + + @ApiModelProperty(value = "是否显示在首页") + private Integer showIndex; + + @ApiModelProperty(value = "状态, 0正常, 1禁用") + private Integer status; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "注册时间") + private LocalDateTime createTime; + + @ApiModelProperty(value = "修改时间") + private LocalDateTime updateTime; + +} diff --git a/src/main/java/com/gxwebsoft/booking/entity/Lesson.java b/src/main/java/com/gxwebsoft/booking/entity/Lesson.java new file mode 100644 index 0000000..77d7085 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/entity/Lesson.java @@ -0,0 +1,69 @@ +package com.gxwebsoft.booking.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 课程管理 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Lesson对象", description = "课程管理") +@TableName("booking_lesson") +public class Lesson implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @TableId(value = "lesson_id", type = IdType.AUTO) + private Integer lessonId; + + @ApiModelProperty(value = "课程名称") + private String lessonName; + + @ApiModelProperty(value = "图标") + private String image; + + @ApiModelProperty(value = "分类ID") + private Integer categoryId; + + @ApiModelProperty(value = "老师ID") + private Integer teacherId; + + @ApiModelProperty(value = "商户ID") + private Integer merchantId; + + @ApiModelProperty(value = "上课时间") + private LocalDateTime startTime; + + @ApiModelProperty(value = "报名人数上限") + private Integer maxNumber; + + @ApiModelProperty(value = "上课地点") + private String address; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "状态") + private Integer status; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "创建时间") + private LocalDateTime createTime; + +} diff --git a/src/main/java/com/gxwebsoft/booking/entity/Teacher.java b/src/main/java/com/gxwebsoft/booking/entity/Teacher.java new file mode 100644 index 0000000..210a3dd --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/entity/Teacher.java @@ -0,0 +1,57 @@ +package com.gxwebsoft.booking.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 老师管理 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Teacher对象", description = "老师管理") +@TableName("booking_teacher") +public class Teacher implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @TableId(value = "teacher_id", type = IdType.AUTO) + private Integer teacherId; + + @ApiModelProperty(value = "老师姓名") + private String teacherName; + + @ApiModelProperty(value = "老师照片") + private String image; + + @ApiModelProperty(value = "老师介绍") + private String content; + + @ApiModelProperty(value = "商户ID") + private Integer merchantId; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "状态") + private Integer status; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "创建时间") + private LocalDateTime createTime; + +} diff --git a/src/main/java/com/gxwebsoft/booking/mapper/CategoryMapper.java b/src/main/java/com/gxwebsoft/booking/mapper/CategoryMapper.java new file mode 100644 index 0000000..f763d0a --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/CategoryMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.booking.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.booking.entity.Category; +import com.gxwebsoft.booking.param.CategoryParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 课程分类Mapper + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface CategoryMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") CategoryParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") CategoryParam param); + +} diff --git a/src/main/java/com/gxwebsoft/booking/mapper/LessonMapper.java b/src/main/java/com/gxwebsoft/booking/mapper/LessonMapper.java new file mode 100644 index 0000000..cff4a03 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/LessonMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.booking.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.booking.entity.Lesson; +import com.gxwebsoft.booking.param.LessonParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 课程管理Mapper + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface LessonMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") LessonParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") LessonParam param); + +} diff --git a/src/main/java/com/gxwebsoft/booking/mapper/TeacherMapper.java b/src/main/java/com/gxwebsoft/booking/mapper/TeacherMapper.java new file mode 100644 index 0000000..fd89c97 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/TeacherMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.booking.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.booking.entity.Teacher; +import com.gxwebsoft.booking.param.TeacherParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 老师管理Mapper + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface TeacherMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") TeacherParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") TeacherParam param); + +} diff --git a/src/main/java/com/gxwebsoft/booking/mapper/xml/CategoryMapper.xml b/src/main/java/com/gxwebsoft/booking/mapper/xml/CategoryMapper.xml new file mode 100644 index 0000000..a26648e --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/xml/CategoryMapper.xml @@ -0,0 +1,90 @@ + + + + + + + SELECT a.* + FROM booking_category a + + + AND a.category_id = #{param.categoryId} + + + AND a.category_code LIKE CONCAT('%', #{param.categoryCode}, '%') + + + AND a.title LIKE CONCAT('%', #{param.title}, '%') + + + AND a.type = #{param.type} + + + AND a.image LIKE CONCAT('%', #{param.image}, '%') + + + AND a.parent_id = #{param.parentId} + + + AND a.path LIKE CONCAT('%', #{param.path}, '%') + + + AND a.component LIKE CONCAT('%', #{param.component}, '%') + + + AND a.page_id = #{param.pageId} + + + AND a.user_id = #{param.userId} + + + AND a.count = #{param.count} + + + AND a.sort_number = #{param.sortNumber} + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.hide = #{param.hide} + + + AND a.recommend = #{param.recommend} + + + AND a.show_index = #{param.showIndex} + + + AND a.status = #{param.status} + + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/booking/mapper/xml/LessonMapper.xml b/src/main/java/com/gxwebsoft/booking/mapper/xml/LessonMapper.xml new file mode 100644 index 0000000..ca5bb0d --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/xml/LessonMapper.xml @@ -0,0 +1,69 @@ + + + + + + + SELECT a.* + FROM booking_lesson a + + + AND a.lesson_id = #{param.lessonId} + + + AND a.lesson_name LIKE CONCAT('%', #{param.lessonName}, '%') + + + AND a.image LIKE CONCAT('%', #{param.image}, '%') + + + AND a.category_id = #{param.categoryId} + + + AND a.teacher_id = #{param.teacherId} + + + AND a.merchant_id = #{param.merchantId} + + + AND a.start_time LIKE CONCAT('%', #{param.startTime}, '%') + + + AND a.max_number = #{param.maxNumber} + + + AND a.address LIKE CONCAT('%', #{param.address}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.status = #{param.status} + + + AND a.sort_number = #{param.sortNumber} + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/booking/mapper/xml/TeacherMapper.xml b/src/main/java/com/gxwebsoft/booking/mapper/xml/TeacherMapper.xml new file mode 100644 index 0000000..7aa0b98 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/mapper/xml/TeacherMapper.xml @@ -0,0 +1,57 @@ + + + + + + + SELECT a.* + FROM booking_teacher a + + + AND a.teacher_id = #{param.teacherId} + + + AND a.teacher_name LIKE CONCAT('%', #{param.teacherName}, '%') + + + AND a.merchant_id = #{param.merchantId} + + + AND a.image LIKE CONCAT('%', #{param.image}, '%') + + + AND a.content LIKE CONCAT('%', #{param.content}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.status = #{param.status} + + + AND a.sort_number = #{param.sortNumber} + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/booking/param/CategoryParam.java b/src/main/java/com/gxwebsoft/booking/param/CategoryParam.java new file mode 100644 index 0000000..ff6c805 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/param/CategoryParam.java @@ -0,0 +1,92 @@ +package com.gxwebsoft.booking.param; + +import java.math.BigDecimal; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 课程分类查询参数 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "CategoryParam对象", description = "课程分类查询参数") +public class CategoryParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "商品分类ID") + @QueryField(type = QueryType.EQ) + private Integer categoryId; + + @ApiModelProperty(value = "分类标识") + private String categoryCode; + + @ApiModelProperty(value = "分类名称") + private String title; + + @ApiModelProperty(value = "类型 0列表 1单页 2外链") + @QueryField(type = QueryType.EQ) + private Integer type; + + @ApiModelProperty(value = "分类图片") + private String image; + + @ApiModelProperty(value = "上级分类ID") + @QueryField(type = QueryType.EQ) + private Integer parentId; + + @ApiModelProperty(value = "路由/链接地址") + private String path; + + @ApiModelProperty(value = "组件路径") + private String component; + + @ApiModelProperty(value = "绑定的页面") + @QueryField(type = QueryType.EQ) + private Integer pageId; + + @ApiModelProperty(value = "用户ID") + @QueryField(type = QueryType.EQ) + private Integer userId; + + @ApiModelProperty(value = "商品数量") + @QueryField(type = QueryType.EQ) + private Integer count; + + @ApiModelProperty(value = "排序(数字越小越靠前)") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单)") + @QueryField(type = QueryType.EQ) + private Integer hide; + + @ApiModelProperty(value = "是否推荐") + @QueryField(type = QueryType.EQ) + private Integer recommend; + + @ApiModelProperty(value = "是否显示在首页") + @QueryField(type = QueryType.EQ) + private Integer showIndex; + + @ApiModelProperty(value = "状态, 0正常, 1禁用") + @QueryField(type = QueryType.EQ) + private Integer status; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @QueryField(type = QueryType.EQ) + private Integer deleted; + +} diff --git a/src/main/java/com/gxwebsoft/booking/param/LessonParam.java b/src/main/java/com/gxwebsoft/booking/param/LessonParam.java new file mode 100644 index 0000000..c8f25f4 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/param/LessonParam.java @@ -0,0 +1,69 @@ +package com.gxwebsoft.booking.param; + +import java.math.BigDecimal; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 课程管理查询参数 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "LessonParam对象", description = "课程管理查询参数") +public class LessonParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @QueryField(type = QueryType.EQ) + private Integer lessonId; + + @ApiModelProperty(value = "课程名称") + private String lessonName; + + @ApiModelProperty(value = "图标") + private String image; + + @ApiModelProperty(value = "分类ID") + @QueryField(type = QueryType.EQ) + private Integer categoryId; + + @ApiModelProperty(value = "老师ID") + @QueryField(type = QueryType.EQ) + private Integer teacherId; + + @ApiModelProperty(value = "商户ID") + @QueryField(type = QueryType.EQ) + private Integer merchantId; + + @ApiModelProperty(value = "上课时间") + private String startTime; + + @ApiModelProperty(value = "报名人数上限") + @QueryField(type = QueryType.EQ) + private Integer maxNumber; + + @ApiModelProperty(value = "上课地点") + private String address; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "状态") + @QueryField(type = QueryType.EQ) + private Integer status; + + @ApiModelProperty(value = "排序号") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + +} diff --git a/src/main/java/com/gxwebsoft/booking/param/TeacherParam.java b/src/main/java/com/gxwebsoft/booking/param/TeacherParam.java new file mode 100644 index 0000000..bafa109 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/param/TeacherParam.java @@ -0,0 +1,50 @@ +package com.gxwebsoft.booking.param; + +import java.math.BigDecimal; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 老师管理查询参数 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "TeacherParam对象", description = "老师管理查询参数") +public class TeacherParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @QueryField(type = QueryType.EQ) + private Integer teacherId; + + @ApiModelProperty(value = "老师姓名") + private String teacherName; + + @ApiModelProperty(value = "老师照片") + private String image; + + @ApiModelProperty(value = "老师介绍") + private String content; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "状态") + @QueryField(type = QueryType.EQ) + private Integer status; + + @ApiModelProperty(value = "排序号") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/CategoryService.java b/src/main/java/com/gxwebsoft/booking/service/CategoryService.java new file mode 100644 index 0000000..e901660 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/CategoryService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.booking.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.booking.entity.Category; +import com.gxwebsoft.booking.param.CategoryParam; + +import java.util.List; + +/** + * 课程分类Service + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface CategoryService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(CategoryParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(CategoryParam param); + + /** + * 根据id查询 + * + * @param categoryId 商品分类ID + * @return Category + */ + Category getByIdRel(Integer categoryId); + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/LessonService.java b/src/main/java/com/gxwebsoft/booking/service/LessonService.java new file mode 100644 index 0000000..c3dd27a --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/LessonService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.booking.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.booking.entity.Lesson; +import com.gxwebsoft.booking.param.LessonParam; + +import java.util.List; + +/** + * 课程管理Service + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface LessonService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(LessonParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(LessonParam param); + + /** + * 根据id查询 + * + * @param lessonId ID + * @return Lesson + */ + Lesson getByIdRel(Integer lessonId); + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/TeacherService.java b/src/main/java/com/gxwebsoft/booking/service/TeacherService.java new file mode 100644 index 0000000..a58525d --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/TeacherService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.booking.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.booking.entity.Teacher; +import com.gxwebsoft.booking.param.TeacherParam; + +import java.util.List; + +/** + * 老师管理Service + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +public interface TeacherService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(TeacherParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(TeacherParam param); + + /** + * 根据id查询 + * + * @param teacherId ID + * @return Teacher + */ + Teacher getByIdRel(Integer teacherId); + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/impl/CategoryServiceImpl.java b/src/main/java/com/gxwebsoft/booking/service/impl/CategoryServiceImpl.java new file mode 100644 index 0000000..19632ae --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/impl/CategoryServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.booking.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.booking.mapper.CategoryMapper; +import com.gxwebsoft.booking.service.CategoryService; +import com.gxwebsoft.booking.entity.Category; +import com.gxwebsoft.booking.param.CategoryParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 课程分类Service实现 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Service +public class CategoryServiceImpl extends ServiceImpl implements CategoryService { + + @Override + public PageResult pageRel(CategoryParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number asc, create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(CategoryParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + page.setDefaultOrder("sort_number asc, create_time desc"); + return page.sortRecords(list); + } + + @Override + public Category getByIdRel(Integer categoryId) { + CategoryParam param = new CategoryParam(); + param.setCategoryId(categoryId); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/impl/LessonServiceImpl.java b/src/main/java/com/gxwebsoft/booking/service/impl/LessonServiceImpl.java new file mode 100644 index 0000000..cb29815 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/impl/LessonServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.booking.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.booking.mapper.LessonMapper; +import com.gxwebsoft.booking.service.LessonService; +import com.gxwebsoft.booking.entity.Lesson; +import com.gxwebsoft.booking.param.LessonParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 课程管理Service实现 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Service +public class LessonServiceImpl extends ServiceImpl implements LessonService { + + @Override + public PageResult pageRel(LessonParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number asc, create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(LessonParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + page.setDefaultOrder("sort_number asc, create_time desc"); + return page.sortRecords(list); + } + + @Override + public Lesson getByIdRel(Integer lessonId) { + LessonParam param = new LessonParam(); + param.setLessonId(lessonId); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/gxwebsoft/booking/service/impl/TeacherServiceImpl.java b/src/main/java/com/gxwebsoft/booking/service/impl/TeacherServiceImpl.java new file mode 100644 index 0000000..f2d7d77 --- /dev/null +++ b/src/main/java/com/gxwebsoft/booking/service/impl/TeacherServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.booking.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.booking.mapper.TeacherMapper; +import com.gxwebsoft.booking.service.TeacherService; +import com.gxwebsoft.booking.entity.Teacher; +import com.gxwebsoft.booking.param.TeacherParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 老师管理Service实现 + * + * @author 科技小王子 + * @since 2024-04-21 14:31:15 + */ +@Service +public class TeacherServiceImpl extends ServiceImpl implements TeacherService { + + @Override + public PageResult pageRel(TeacherParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number asc, create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(TeacherParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + page.setDefaultOrder("sort_number asc, create_time desc"); + return page.sortRecords(list); + } + + @Override + public Teacher getByIdRel(Integer teacherId) { + TeacherParam param = new TeacherParam(); + param.setTeacherId(teacherId); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/gxwebsoft/common/core/config/MybatisPlusConfig.java b/src/main/java/com/gxwebsoft/common/core/config/MybatisPlusConfig.java index f9d893a..6dc0ce3 100644 --- a/src/main/java/com/gxwebsoft/common/core/config/MybatisPlusConfig.java +++ b/src/main/java/com/gxwebsoft/common/core/config/MybatisPlusConfig.java @@ -63,7 +63,8 @@ public class MybatisPlusConfig { "sys_tenant", "sys_dictionary", "sys_dictionary_data", - "apps_test_data" + "apps_test_data", + "shop_merchant_account" ).contains(tableName); } }; diff --git a/src/main/java/com/gxwebsoft/shop/controller/GoodsController.java b/src/main/java/com/gxwebsoft/shop/controller/GoodsController.java index f5ba63c..6606396 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/GoodsController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/GoodsController.java @@ -59,7 +59,6 @@ public class GoodsController extends BaseController { return success(goodsService.listRel(param)); } - @Transactional(rollbackFor = {Exception.class}) @ApiOperation("根据id查询商品记录表") @GetMapping("/{id}") @@ -77,6 +76,7 @@ public class GoodsController extends BaseController { return success(goods); } + @PreAuthorize("hasAuthority('shop:goods:save')") @ApiOperation("添加商品记录表") @PostMapping() public ApiResult save(@RequestBody Goods goods) { @@ -93,6 +93,7 @@ public class GoodsController extends BaseController { return fail("添加失败"); } + @PreAuthorize("hasAuthority('shop:goods:update')") @ApiOperation("修改商品记录表") @PutMapping() public ApiResult update(@RequestBody Goods goods) { @@ -107,6 +108,7 @@ public class GoodsController extends BaseController { return fail("修改失败"); } + @PreAuthorize("hasAuthority('shop:goods:remove')") @ApiOperation("删除商品记录表") @DeleteMapping("/{id}") public ApiResult remove(@PathVariable("id") Integer id) { @@ -116,6 +118,7 @@ public class GoodsController extends BaseController { return fail("删除失败"); } + @PreAuthorize("hasAuthority('shop:goods:save')") @ApiOperation("批量添加商品记录表") @PostMapping("/batch") public ApiResult saveBatch(@RequestBody List list) { @@ -125,6 +128,7 @@ public class GoodsController extends BaseController { return fail("添加失败"); } + @PreAuthorize("hasAuthority('shop:goods:update')") @ApiOperation("批量修改商品记录表") @PutMapping("/batch") public ApiResult removeBatch(@RequestBody BatchParam batchParam) { @@ -134,6 +138,7 @@ public class GoodsController extends BaseController { return fail("修改失败"); } + @PreAuthorize("hasAuthority('shop:goods:remove')") @ApiOperation("批量删除商品记录表") @DeleteMapping("/batch") public ApiResult removeBatch(@RequestBody List ids) { diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantAccountMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantAccountMapper.xml index 11cffc0..3d1939c 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantAccountMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantAccountMapper.xml @@ -12,7 +12,7 @@ AND a.id = #{param.id} - AND a.phone LIKE CONCAT('%', #{param.phone}, '%') + AND a.phone = #{param.phone} AND a.real_name LIKE CONCAT('%', #{param.realName}, '%') diff --git a/src/main/java/com/gxwebsoft/shop/param/MerchantAccountParam.java b/src/main/java/com/gxwebsoft/shop/param/MerchantAccountParam.java index bc05702..9b0c29b 100644 --- a/src/main/java/com/gxwebsoft/shop/param/MerchantAccountParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/MerchantAccountParam.java @@ -28,6 +28,7 @@ public class MerchantAccountParam extends BaseParam { private Integer id; @ApiModelProperty(value = "商户手机号") + @QueryField(type = QueryType.EQ) private String phone; @ApiModelProperty(value = "真实姓名") diff --git a/src/test/java/com/gxwebsoft/generator.zip b/src/test/java/com/gxwebsoft/generator.zip new file mode 100644 index 0000000..b19e3d1 Binary files /dev/null and b/src/test/java/com/gxwebsoft/generator.zip differ diff --git a/src/test/java/com/gxwebsoft/generator/BookingGenerator.java b/src/test/java/com/gxwebsoft/generator/BookingGenerator.java new file mode 100644 index 0000000..eb4230a --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/BookingGenerator.java @@ -0,0 +1,229 @@ +package com.gxwebsoft.generator; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 代码生成工具 + * + * @author WebSoft + * @since 2021-09-05 00:31:14 + */ +public class BookingGenerator { + // 输出位置 + private static final String OUTPUT_LOCATION = System.getProperty("user.dir"); + //private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径 + // 输出目录 + private static final String OUTPUT_DIR = "/src/main/java"; + // Vue文件输出位置 + private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/com.gxwebsoft.core-web"; + // Vue文件输出目录 + private static final String OUTPUT_DIR_VUE = "/src"; + // 作者名称 + private static final String AUTHOR = "科技小王子"; + // 是否在xml中添加二级缓存配置 + private static final boolean ENABLE_CACHE = false; + // 数据库连接配置 + private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"; + private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; + private static final String DB_USERNAME = "modules"; + private static final String DB_PASSWORD = "FYJGx7s8yt7K8xDH"; + // 包名 + private static final String PACKAGE_NAME = "com.gxwebsoft"; + // 模块名 + private static final String MODULE_NAME = "booking"; + // 需要生成的表 + private static final String[] TABLE_NAMES = new String[]{ + "booking_lesson", + "booking_teacher", + "booking_category" + }; + // 需要去除的表前缀 + private static final String[] TABLE_PREFIX = new String[]{ + "booking_", + "tb_" + }; + // 不需要作为查询参数的字段 + private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{ + "tenant_id", + "create_time", + "update_time" + }; + // 查询参数使用String的类型 + private static final String[] PARAM_TO_STRING_TYPE = new String[]{ + "Date", + "LocalDate", + "LocalTime", + "LocalDateTime" + }; + // 查询参数使用EQ的类型 + private static final String[] PARAM_EQ_TYPE = new String[]{ + "Integer", + "Boolean", + "BigDecimal" + }; + // 是否添加权限注解 + private static final boolean AUTH_ANNOTATION = false; + // 是否添加日志注解 + private static final boolean LOG_ANNOTATION = false; + // controller的mapping前缀 + private static final String CONTROLLER_MAPPING_PREFIX = "/api"; + // 模板所在位置 + private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates"; + + public static void main(String[] args) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR); + gc.setAuthor(AUTHOR); + gc.setOpen(false); + gc.setFileOverride(true); + gc.setEnableCache(ENABLE_CACHE); + gc.setSwagger2(true); + gc.setIdType(IdType.AUTO); + gc.setServiceName("%sService"); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setUrl(DB_URL); + // dsc.setSchemaName("public"); + dsc.setDriverName(DB_DRIVER); + dsc.setUsername(DB_USERNAME); + dsc.setPassword(DB_PASSWORD); + mpg.setDataSource(dsc); + + // 包配置 + PackageConfig pc = new PackageConfig(); + pc.setModuleName(MODULE_NAME); + pc.setParent(PACKAGE_NAME); + mpg.setPackageInfo(pc); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + strategy.setInclude(TABLE_NAMES); + strategy.setTablePrefix(TABLE_PREFIX); + strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController"); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + strategy.setControllerMappingHyphenStyle(true); + strategy.setLogicDeleteFieldName("deleted"); + mpg.setStrategy(strategy); + + // 模板配置 + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setController(TEMPLATES_DIR + "/controller.java"); + templateConfig.setEntity(TEMPLATES_DIR + "/entity.java"); + templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java"); + templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml"); + templateConfig.setService(TEMPLATES_DIR + "/service.java"); + templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java"); + mpg.setTemplate(templateConfig); + mpg.setTemplateEngine(new BeetlTemplateEnginePlus()); + + // 自定义模板配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + Map map = new HashMap<>(); + map.put("packageName", PACKAGE_NAME); + map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS); + map.put("paramToStringType", PARAM_TO_STRING_TYPE); + map.put("paramEqType", PARAM_EQ_TYPE); + map.put("authAnnotation", AUTH_ANNOTATION); + map.put("logAnnotation", LOG_ANNOTATION); + map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX); + this.setMap(map); + } + }; + String templatePath = TEMPLATES_DIR + "/param.java.btl"; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION + OUTPUT_DIR + "/" + + PACKAGE_NAME.replace(".", "/") + + "/" + pc.getModuleName() + "/param/" + + tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA; + } + }); + /** + * 以下是生成VUE项目代码 + * 生成文件的路径 /api/shop/goods/index.ts + */ + templatePath = TEMPLATES_DIR + "/index.ts.btl"; + + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/api/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/" + "index.ts"; + } + }); + // 生成TS文件 (/api/shop/goods/model/index.ts) + templatePath = TEMPLATES_DIR + "/model.ts.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/api/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/model/" + "index.ts"; + } + }); + // 生成Vue文件(/views/shop/goods/index.vue) + templatePath = TEMPLATES_DIR + "/index.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/" + "index.vue"; + } + }); + + // 生成components文件(/views/shop/goods/components/edit.vue) + templatePath = TEMPLATES_DIR + "/components.edit.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue"; + } + }); + + // 生成components文件(/views/shop/goods/components/search.vue) + templatePath = TEMPLATES_DIR + "/components.search.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/components/" + "search.vue"; + } + }); + + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + + mpg.execute(); + } + +} diff --git a/src/test/java/com/gxwebsoft/generator/templates/controller.java.btl b/src/test/java/com/gxwebsoft/generator/templates/controller.java.btl index 4de4d52..4a68f75 100644 --- a/src/test/java/com/gxwebsoft/generator/templates/controller.java.btl +++ b/src/test/java/com/gxwebsoft/generator/templates/controller.java.btl @@ -64,6 +64,9 @@ public class ${table.controllerName} { * 分页查询${table.comment!} */ <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:list')") + <% } %> <% if(swagger2) { %> @ApiOperation("分页查询${table.comment!}") <% } %> @@ -81,6 +84,9 @@ public class ${table.controllerName} { * 查询全部${table.comment!} */ <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:list')") + <% } %> <% if(swagger2) { %> @ApiOperation("查询全部${table.comment!}") <% } %> @@ -98,6 +104,7 @@ public class ${table.controllerName} { * 根据id查询${table.comment!} */ <% } %> + @PreAuthorize("hasAuthority('${authPre}:list')") @ApiOperation("根据id查询${table.comment!}") @GetMapping("/{id}") public ApiResult<${entity}> get(@PathVariable("id") Integer id) { diff --git a/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl b/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl index 9d0b5e9..9cd968d 100644 --- a/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl +++ b/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl @@ -8,7 +8,7 @@ import { MODULES_API_URL } from '@/config/setting'; */ export async function page${entity}(params: ${entity}Param) { const res = await request.get>>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}/page', + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/page', { params } @@ -24,7 +24,7 @@ export async function page${entity}(params: ${entity}Param) { */ export async function list${entity}(params?: ${entity}Param) { const res = await request.get>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}', + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', { params } @@ -40,7 +40,7 @@ export async function list${entity}(params?: ${entity}Param) { */ export async function add${entity}(data: ${entity}) { const res = await request.post>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}', + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', data ); if (res.data.code === 0) { @@ -54,7 +54,7 @@ export async function add${entity}(data: ${entity}) { */ export async function update${entity}(data: ${entity}) { const res = await request.put>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}', + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', data ); if (res.data.code === 0) { @@ -68,7 +68,7 @@ export async function update${entity}(data: ${entity}) { */ export async function remove${entity}(id?: number) { const res = await request.delete>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}/' + id + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id ); if (res.data.code === 0) { return res.data.message; @@ -81,7 +81,7 @@ export async function remove${entity}(id?: number) { */ export async function removeBatch${entity}(data: (number | undefined)[]) { const res = await request.delete>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}/batch', + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/batch', { data } @@ -97,7 +97,7 @@ export async function removeBatch${entity}(data: (number | undefined)[]) { */ export async function get${entity}(id: number) { const res = await request.get>( - MODULES_API_URL + '/shop/${controllerMappingHyphen}/' + id + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id ); if (res.data.code === 0 && res.data.data) { return res.data.data;