Merge remote-tracking branch 'origin/master'
commit
c3c3eccdb1
@ -0,0 +1,25 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.config;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MyWebMvcConfig extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/**").addResourceLocations(
|
||||||
|
"classpath:/static/");
|
||||||
|
|
||||||
|
// swagger静态资源相关
|
||||||
|
registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
|
||||||
|
"classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations(
|
||||||
|
"classpath:/META-INF/resources/webjars/");
|
||||||
|
// 针对swagger自带的静态资源
|
||||||
|
registry.addResourceHandler("/swagger-ui/**").addResourceLocations(
|
||||||
|
"classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
||||||
|
super.addResourceHandlers(registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.zhiyun.zhiyun03.course.entity.Course;
|
||||||
|
|
||||||
|
import com.zhiyun.zhiyun03.course.service.CourseService;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.CourseVo;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.PageVO;
|
||||||
|
|
||||||
|
import com.zhiyun.zhiyun03.utils.common.JsonResult;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api("课程")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/course")
|
||||||
|
public class CourseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("查询课程")
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public JsonResult<CourseVo> queryCourse(){
|
||||||
|
|
||||||
|
List<CourseVo> lists = courseService.queryCourse();
|
||||||
|
|
||||||
|
return JsonResult.success(lists);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("课程添加")
|
||||||
|
@PostMapping("/add")
|
||||||
|
public JsonResult addCourse(Course course){
|
||||||
|
courseService.addCourse(course);
|
||||||
|
return JsonResult.success();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//// @ApiOperation("查询目录")
|
||||||
|
//// @PostMapping("/select")
|
||||||
|
//// public JsonResult selectDir(Directory directory){
|
||||||
|
//// courseService.se(course);
|
||||||
|
//// return JsonResult.ok();
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
@ApiOperation("删除课程")
|
||||||
|
@DeleteMapping("delById")
|
||||||
|
public JsonResult delCourseById(Integer id){
|
||||||
|
courseService.delCourseById(id);
|
||||||
|
return JsonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("更新课程")
|
||||||
|
@PostMapping("update")
|
||||||
|
public JsonResult updateById(Course course){
|
||||||
|
courseService.update(course);
|
||||||
|
return JsonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.zhiyun.zhiyun03.course.entity.Course;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CourseMapper extends BaseMapper<Course> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.param;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageParam {
|
||||||
|
private Integer currentPage;
|
||||||
|
private Integer pageSize;
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.zhiyun.zhiyun03.course.entity.Course;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.CourseVo;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.PageVO;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CourseService extends IService<Course> {
|
||||||
|
// public void addCourse(Course course);
|
||||||
|
//
|
||||||
|
// void delCourseById(Integer id);
|
||||||
|
//
|
||||||
|
// void updateById(Course course);
|
||||||
|
|
||||||
|
|
||||||
|
List<CourseVo> queryCourse();
|
||||||
|
|
||||||
|
void addCourse(Course course);
|
||||||
|
|
||||||
|
void delCourseById(Integer id);
|
||||||
|
|
||||||
|
void update(Course course);
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fasterxml.jackson.databind.util.BeanUtil;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.zhiyun.zhiyun03.application.entity.Directory;
|
||||||
|
import com.zhiyun.zhiyun03.application.mapper.DirectoryMapper;
|
||||||
|
import com.zhiyun.zhiyun03.application.util.ConvertUtil;
|
||||||
|
import com.zhiyun.zhiyun03.course.entity.Course;
|
||||||
|
import com.zhiyun.zhiyun03.course.service.CourseService;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.CourseVo;
|
||||||
|
import com.zhiyun.zhiyun03.course.mapper.CourseMapper;
|
||||||
|
import com.zhiyun.zhiyun03.course.vo.PageVO;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CourseServiceImpl extends ServiceImpl<CourseMapper,Course> implements CourseService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CourseMapper courseMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DirectoryMapper directoryMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用中心查询
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CourseVo> queryCourse() {
|
||||||
|
|
||||||
|
QueryWrapper<Course> qwa=new QueryWrapper<>();
|
||||||
|
List<Course> courses = courseMapper.selectList(qwa);
|
||||||
|
QueryWrapper<Directory> qwd=new QueryWrapper<>();
|
||||||
|
List<Directory> directories = directoryMapper.selectList(qwd);
|
||||||
|
ConvertUtil convertUtil=new ConvertUtil();
|
||||||
|
List<CourseVo> applicationVos = convertUtil.entityToVoList(courses, CourseVo.class);
|
||||||
|
|
||||||
|
for (int i = 0; i < courses.size(); i++) {
|
||||||
|
for (int j = 0; j <directories.size() ; j++) {
|
||||||
|
//判断目录id是否相等
|
||||||
|
if(courses.get(i).getDirId()==directories.get(j).getId()){
|
||||||
|
//将目录名称添加到vo类中
|
||||||
|
applicationVos.get(i).setDirName(directories.get(j).getDirName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return applicationVos;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加课程
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCourse(Course course) {
|
||||||
|
|
||||||
|
courseMapper.insert(course);
|
||||||
|
// UpdateWrapper<Directory> updateWrapper = new UpdateWrapper<>();
|
||||||
|
// updateWrapper.set("id",course.getDirId());
|
||||||
|
// directoryMapper.update(null,updateWrapper);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除课程
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delCourseById(Integer id) {
|
||||||
|
courseMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程更新
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void update(Course course) {
|
||||||
|
//变更数据进行更新
|
||||||
|
UpdateWrapper<Course> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.set("course_name",course.getCourseName());
|
||||||
|
updateWrapper.set("course_brief",course.getCourseBrief());
|
||||||
|
updateWrapper.set("course_url",course.getCourseUrl());
|
||||||
|
updateWrapper.set("dir_id",course.getDirId());
|
||||||
|
updateWrapper.set("course_icon",course.getCourseIcon());
|
||||||
|
updateWrapper.eq("id",course.getId());
|
||||||
|
courseMapper.update(null,updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.zhiyun.zhiyun03.course.param.PageParam;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CourseVo {
|
||||||
|
@TableId
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String courseName;
|
||||||
|
|
||||||
|
private String courseBrief;
|
||||||
|
|
||||||
|
private String courseUrl;
|
||||||
|
|
||||||
|
private String dirName;
|
||||||
|
|
||||||
|
private String courseIcon;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.zhiyun.zhiyun03.course.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageVO<T> {
|
||||||
|
|
||||||
|
private Integer currentPage;
|
||||||
|
private Long total;
|
||||||
|
private List<T> list;
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.zhiyun.zhiyun03.utils.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class JsonResult<T> {
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
|
||||||
|
public static JsonResult success() {
|
||||||
|
|
||||||
|
JsonResult jsonResult = new JsonResult();
|
||||||
|
jsonResult.setCode("200");//code值是自行定义
|
||||||
|
jsonResult.setMsg("success");
|
||||||
|
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> JsonResult success(T data) {
|
||||||
|
|
||||||
|
JsonResult jsonResult = new JsonResult();
|
||||||
|
jsonResult.setCode("200");//code值是自行定义
|
||||||
|
jsonResult.setMsg("success");
|
||||||
|
jsonResult.setData(data);
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonResult error() {
|
||||||
|
|
||||||
|
JsonResult jsonResult = new JsonResult();
|
||||||
|
jsonResult.setCode("500");
|
||||||
|
jsonResult.setMsg("fail");
|
||||||
|
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonResult error(String code, String msg) {
|
||||||
|
|
||||||
|
JsonResult jsonResult = new JsonResult();
|
||||||
|
jsonResult.setCode(code);
|
||||||
|
jsonResult.setMsg(msg);
|
||||||
|
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.zhiyun.zhiyun03.utils.common;
|
||||||
|
|
||||||
|
public enum ResultCode {
|
||||||
|
SUCCESS("0", "成功"),
|
||||||
|
ERROR("-1", "系统异常"),
|
||||||
|
PARAM_ERROR("1001", "参数异常"),
|
||||||
|
USER_EXIST_ERROR("2001", "用户已存在"),
|
||||||
|
USER_ACCOUNT_ERROR("2002", "账号或密码错误"),
|
||||||
|
USER_NOT_EXIST_ERROR("2003", "未找到用户"),
|
||||||
|
ORDER_PAY_ERROR("3001", "库存不足,下单失败"),
|
||||||
|
PARAM_LOST_ERROR("2004", "参数缺失"),
|
||||||
|
PARAM_PASSWORD_ERROR("2005", "原密码输入错误"),
|
||||||
|
;
|
||||||
|
|
||||||
|
public String code;
|
||||||
|
public String msg;
|
||||||
|
|
||||||
|
ResultCode(String code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.zhiyun.zhiyun03.utils.exception;
|
||||||
|
|
||||||
|
import com.zhiyun.zhiyun03.utils.common.JsonResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
// @RestController + @ResponseBody
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(ServiceException.class)
|
||||||
|
public JsonResult serviceExceptionHandler(ServiceException e) {
|
||||||
|
log.error("异常信息", e);
|
||||||
|
|
||||||
|
return JsonResult.error(e.getCode(), e.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public JsonResult exceptionHandler(Exception e) {
|
||||||
|
log.error("未知异常", e);
|
||||||
|
|
||||||
|
return JsonResult.error("500", "未知异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.zhiyun.zhiyun03.utils.exception;
|
||||||
|
|
||||||
|
public class ServiceException extends RuntimeException {
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
public ServiceException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceException(String code, String msg) {
|
||||||
|
super(msg);
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.zhiyun.zhiyun03.application.mapper.DirectoryMapper">
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue