From d1f4c3539f4ae9ccd274bfe38c8a416a1e4e287a Mon Sep 17 00:00:00 2001 From: nagocoler Date: Thu, 7 Nov 2024 17:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 + ruoyi-admin/pom.xml | 5 + ruoyi-core/pom.xml | 26 +++ .../system/controller/CourseController.java | 103 ++++++++++++ .../java/com/ruoyi/system/domain/Course.java | 149 ++++++++++++++++++ .../com/ruoyi/system/mapper/CourseMapper.java | 61 +++++++ .../ruoyi/system/service/ICourseService.java | 61 +++++++ .../service/impl/CourseServiceImpl.java | 93 +++++++++++ .../resources/mapper/system/CourseMapper.xml | 91 +++++++++++ .../framework/config/SecurityConfig.java | 12 +- 10 files changed, 602 insertions(+), 6 deletions(-) create mode 100644 ruoyi-core/pom.xml create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/controller/CourseController.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/domain/Course.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/mapper/CourseMapper.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/service/ICourseService.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/service/impl/CourseServiceImpl.java create mode 100644 ruoyi-core/src/main/resources/mapper/system/CourseMapper.xml diff --git a/pom.xml b/pom.xml index 956a61b..5985760 100644 --- a/pom.xml +++ b/pom.xml @@ -185,6 +185,12 @@ ${ruoyi.version} + + com.ruoyi + ruoyi-core + ${ruoyi.version} + + @@ -195,6 +201,7 @@ ruoyi-quartz ruoyi-generator ruoyi-common + ruoyi-core pom diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 5454253..c366907 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -54,6 +54,11 @@ ruoyi-generator + + com.ruoyi + ruoyi-core + + diff --git a/ruoyi-core/pom.xml b/ruoyi-core/pom.xml new file mode 100644 index 0000000..e7462e7 --- /dev/null +++ b/ruoyi-core/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.ruoyi + ruoyi + 3.8.8 + + + ruoyi-core + + + 17 + 17 + UTF-8 + + + + + com.ruoyi + ruoyi-common + + + \ No newline at end of file diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/controller/CourseController.java b/ruoyi-core/src/main/java/com/ruoyi/system/controller/CourseController.java new file mode 100644 index 0000000..5aea9e5 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/controller/CourseController.java @@ -0,0 +1,103 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.Course; +import com.ruoyi.system.service.ICourseService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 课程Controller + * + * @author ruoyi + * @date 2024-11-07 + */ +@RestController +@RequestMapping("/system/course") +public class CourseController extends BaseController +{ + @Autowired + private ICourseService courseService; + + /** + * 查询课程列表 + */ + @GetMapping("/list") + public TableDataInfo list(Course course) + { + startPage(); + List list = courseService.selectCourseList(course); + return getDataTable(list); + } + + /** + * 导出课程列表 + */ + @PreAuthorize("@ss.hasPermi('system:course:export')") + @Log(title = "课程", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, Course course) + { + List list = courseService.selectCourseList(course); + ExcelUtil util = new ExcelUtil(Course.class); + util.exportExcel(response, list, "课程数据"); + } + + /** + * 获取课程详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:course:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Integer id) + { + return success(courseService.selectCourseById(id)); + } + + /** + * 新增课程 + */ + @PreAuthorize("@ss.hasPermi('system:course:add')") + @Log(title = "课程", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody Course course) + { + return toAjax(courseService.insertCourse(course)); + } + + /** + * 修改课程 + */ + @PreAuthorize("@ss.hasPermi('system:course:edit')") + @Log(title = "课程", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody Course course) + { + return toAjax(courseService.updateCourse(course)); + } + + /** + * 删除课程 + */ + @PreAuthorize("@ss.hasPermi('system:course:remove')") + @Log(title = "课程", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Integer[] ids) + { + return toAjax(courseService.deleteCourseByIds(ids)); + } +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/domain/Course.java b/ruoyi-core/src/main/java/com/ruoyi/system/domain/Course.java new file mode 100644 index 0000000..4c2a561 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/domain/Course.java @@ -0,0 +1,149 @@ +package com.ruoyi.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 课程对象 db_course + * + * @author ruoyi + * @date 2024-11-07 + */ +public class Course extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 课程ID */ + private Integer id; + + /** 主讲老师 */ + @Excel(name = "主讲老师") + private String teacher; + + /** 课程标题 */ + @Excel(name = "课程标题") + private String title; + + /** 课程简介 */ + @Excel(name = "课程简介") + private String about; + + /** 课程详细 */ + @Excel(name = "课程详细") + private String description; + + /** 课程数量 */ + @Excel(name = "课程数量") + private Long lessone; + + /** 课程价格 */ + @Excel(name = "课程价格") + private Long price; + + /** 课程时长 */ + @Excel(name = "课程时长") + private Long duration; + + /** 最大学生 */ + @Excel(name = "最大学生") + private Long maxStudents; + + public void setId(Integer id) + { + this.id = id; + } + + public Integer getId() + { + return id; + } + public void setTeacher(String teacher) + { + this.teacher = teacher; + } + + public String getTeacher() + { + return teacher; + } + public void setTitle(String title) + { + this.title = title; + } + + public String getTitle() + { + return title; + } + public void setAbout(String about) + { + this.about = about; + } + + public String getAbout() + { + return about; + } + public void setDescription(String description) + { + this.description = description; + } + + public String getDescription() + { + return description; + } + public void setLessone(Long lessone) + { + this.lessone = lessone; + } + + public Long getLessone() + { + return lessone; + } + public void setPrice(Long price) + { + this.price = price; + } + + public Long getPrice() + { + return price; + } + public void setDuration(Long duration) + { + this.duration = duration; + } + + public Long getDuration() + { + return duration; + } + public void setMaxStudents(Long maxStudents) + { + this.maxStudents = maxStudents; + } + + public Long getMaxStudents() + { + return maxStudents; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("teacher", getTeacher()) + .append("title", getTitle()) + .append("about", getAbout()) + .append("description", getDescription()) + .append("lessone", getLessone()) + .append("price", getPrice()) + .append("duration", getDuration()) + .append("maxStudents", getMaxStudents()) + .toString(); + } +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/mapper/CourseMapper.java b/ruoyi-core/src/main/java/com/ruoyi/system/mapper/CourseMapper.java new file mode 100644 index 0000000..c971935 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/mapper/CourseMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.Course; + +/** + * 课程Mapper接口 + * + * @author ruoyi + * @date 2024-11-07 + */ +public interface CourseMapper +{ + /** + * 查询课程 + * + * @param id 课程主键 + * @return 课程 + */ + public Course selectCourseById(Integer id); + + /** + * 查询课程列表 + * + * @param course 课程 + * @return 课程集合 + */ + public List selectCourseList(Course course); + + /** + * 新增课程 + * + * @param course 课程 + * @return 结果 + */ + public int insertCourse(Course course); + + /** + * 修改课程 + * + * @param course 课程 + * @return 结果 + */ + public int updateCourse(Course course); + + /** + * 删除课程 + * + * @param id 课程主键 + * @return 结果 + */ + public int deleteCourseById(Integer id); + + /** + * 批量删除课程 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteCourseByIds(Integer[] ids); +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/service/ICourseService.java b/ruoyi-core/src/main/java/com/ruoyi/system/service/ICourseService.java new file mode 100644 index 0000000..4f031c8 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/service/ICourseService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.Course; + +/** + * 课程Service接口 + * + * @author ruoyi + * @date 2024-11-07 + */ +public interface ICourseService +{ + /** + * 查询课程 + * + * @param id 课程主键 + * @return 课程 + */ + public Course selectCourseById(Integer id); + + /** + * 查询课程列表 + * + * @param course 课程 + * @return 课程集合 + */ + public List selectCourseList(Course course); + + /** + * 新增课程 + * + * @param course 课程 + * @return 结果 + */ + public int insertCourse(Course course); + + /** + * 修改课程 + * + * @param course 课程 + * @return 结果 + */ + public int updateCourse(Course course); + + /** + * 批量删除课程 + * + * @param ids 需要删除的课程主键集合 + * @return 结果 + */ + public int deleteCourseByIds(Integer[] ids); + + /** + * 删除课程信息 + * + * @param id 课程主键 + * @return 结果 + */ + public int deleteCourseById(Integer id); +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/CourseServiceImpl.java b/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/CourseServiceImpl.java new file mode 100644 index 0000000..3c2544b --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/CourseServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.CourseMapper; +import com.ruoyi.system.domain.Course; +import com.ruoyi.system.service.ICourseService; + +/** + * 课程Service业务层处理 + * + * @author ruoyi + * @date 2024-11-07 + */ +@Service +public class CourseServiceImpl implements ICourseService +{ + @Autowired + private CourseMapper courseMapper; + + /** + * 查询课程 + * + * @param id 课程主键 + * @return 课程 + */ + @Override + public Course selectCourseById(Integer id) + { + return courseMapper.selectCourseById(id); + } + + /** + * 查询课程列表 + * + * @param course 课程 + * @return 课程 + */ + @Override + public List selectCourseList(Course course) + { + return courseMapper.selectCourseList(course); + } + + /** + * 新增课程 + * + * @param course 课程 + * @return 结果 + */ + @Override + public int insertCourse(Course course) + { + return courseMapper.insertCourse(course); + } + + /** + * 修改课程 + * + * @param course 课程 + * @return 结果 + */ + @Override + public int updateCourse(Course course) + { + return courseMapper.updateCourse(course); + } + + /** + * 批量删除课程 + * + * @param ids 需要删除的课程主键 + * @return 结果 + */ + @Override + public int deleteCourseByIds(Integer[] ids) + { + return courseMapper.deleteCourseByIds(ids); + } + + /** + * 删除课程信息 + * + * @param id 课程主键 + * @return 结果 + */ + @Override + public int deleteCourseById(Integer id) + { + return courseMapper.deleteCourseById(id); + } +} diff --git a/ruoyi-core/src/main/resources/mapper/system/CourseMapper.xml b/ruoyi-core/src/main/resources/mapper/system/CourseMapper.xml new file mode 100644 index 0000000..3223a22 --- /dev/null +++ b/ruoyi-core/src/main/resources/mapper/system/CourseMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + select id, teacher, title, about, description, lessone, price, duration, max_students from db_course + + + + + + + + insert into db_course + + teacher, + title, + about, + description, + lessone, + price, + duration, + max_students, + + + #{teacher}, + #{title}, + #{about}, + #{description}, + #{lessone}, + #{price}, + #{duration}, + #{maxStudents}, + + + + + update db_course + + teacher = #{teacher}, + title = #{title}, + about = #{about}, + description = #{description}, + lessone = #{lessone}, + price = #{price}, + duration = #{duration}, + max_students = #{maxStudents}, + + where id = #{id} + + + + delete from db_course where id = #{id} + + + + delete from db_course where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 18ac155..3ca9229 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -111,12 +111,12 @@ public class SecurityConfig .authorizeHttpRequests((requests) -> { permitAllUrl.getUrls().forEach(url -> requests.requestMatchers(url).permitAll()); // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - requests.requestMatchers("/login", "/register", "/captchaImage").permitAll() - // 静态资源,可匿名访问 - .requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll() - .requestMatchers("/swagger-ui.html", "/v3/api-docs/**", "/swagger-ui/**", "/druid/**").permitAll() - // 除上面外的所有请求全部需要鉴权认证 - .anyRequest().authenticated(); + requests + .requestMatchers("/login", "/register", "/captchaImage").permitAll() + .requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll() + .requestMatchers("/swagger-ui.html", "/v3/api-docs/**", "/swagger-ui/**", "/druid/**").permitAll() + .requestMatchers("/system/course/**").permitAll() + .anyRequest().authenticated(); }) // 添加Logout filter .logout(logout -> logout.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler))