Bläddra i källkod

fix 模块章关联

he2802 4 år sedan
förälder
incheckning
3f3a4bef2e

+ 112 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/course/CourseModuleChapterController.java

@@ -0,0 +1,112 @@
+package com.zhongzheng.controller.course;
+
+import java.util.List;
+import java.util.Arrays;
+
+import com.zhongzheng.modules.course.bo.CourseModuleChapterAddBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterEditBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterQueryBo;
+import com.zhongzheng.modules.course.service.ICourseModuleChapterService;
+import com.zhongzheng.modules.course.vo.CourseModuleChapterVo;
+import lombok.RequiredArgsConstructor;
+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.zhongzheng.common.annotation.Log;
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.enums.BusinessType;
+import com.zhongzheng.common.utils.poi.ExcelUtil;
+import com.zhongzheng.common.core.page.TableDataInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 模块与章关系Controller
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Api(value = "模块与章关系控制器", tags = {"模块与章关系管理"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/course/module/chapter")
+public class CourseModuleChapterController extends BaseController {
+
+    private final ICourseModuleChapterService iCourseModuleChapterService;
+
+    /**
+     * 查询模块与章关系列表
+     */
+    @ApiOperation("查询模块与章关系列表")
+    @PreAuthorize("@ss.hasPermi('system:chapter:list')")
+    @GetMapping("/list")
+    public TableDataInfo<CourseModuleChapterVo> list(CourseModuleChapterQueryBo bo) {
+        startPage();
+        List<CourseModuleChapterVo> list = iCourseModuleChapterService.queryList(bo);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出模块与章关系列表
+     */
+   /* @ApiOperation("导出模块与章关系列表")
+    @PreAuthorize("@ss.hasPermi('system:chapter:export')")
+    @Log(title = "模块与章关系", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult<CourseModuleChapterVo> export(CourseModuleChapterQueryBo bo) {
+        List<CourseModuleChapterVo> list = iCourseModuleChapterService.queryList(bo);
+        ExcelUtil<CourseModuleChapterVo> util = new ExcelUtil<CourseModuleChapterVo>(CourseModuleChapterVo.class);
+        return util.exportExcel(list, "模块与章关系");
+    }*/
+
+    /**
+     * 获取模块与章关系详细信息
+     */
+    @ApiOperation("获取模块与章关系详细信息")
+    @PreAuthorize("@ss.hasPermi('system:chapter:query')")
+    @GetMapping("/{id}")
+    public AjaxResult<CourseModuleChapterVo> getInfo(@PathVariable("id" ) Long id) {
+        return AjaxResult.success(iCourseModuleChapterService.queryById(id));
+    }
+
+    /**
+     * 新增模块与章关系
+     */
+    @ApiOperation("新增模块与章关系")
+    @PreAuthorize("@ss.hasPermi('system:chapter:add')")
+    @Log(title = "模块与章关系", businessType = BusinessType.INSERT)
+    @PostMapping()
+    public AjaxResult<Void> add(@RequestBody CourseModuleChapterAddBo bo) {
+        return toAjax(iCourseModuleChapterService.insertByAddBo(bo) ? 1 : 0);
+    }
+
+    /**
+     * 修改模块与章关系
+     */
+    @ApiOperation("修改模块与章关系")
+    @PreAuthorize("@ss.hasPermi('system:chapter:edit')")
+    @Log(title = "模块与章关系", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    public AjaxResult<Void> edit(@RequestBody CourseModuleChapterEditBo bo) {
+        return toAjax(iCourseModuleChapterService.updateByEditBo(bo) ? 1 : 0);
+    }
+
+    /**
+     * 删除模块与章关系
+     */
+    @ApiOperation("删除模块与章关系")
+    @PreAuthorize("@ss.hasPermi('system:chapter:remove')")
+    @Log(title = "模块与章关系" , businessType = BusinessType.DELETE)
+    @PostMapping("/del/{ids}")
+    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
+        return toAjax(iCourseModuleChapterService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
+    }
+}

+ 27 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/bo/CourseModuleChapterAddBo.java

@@ -0,0 +1,27 @@
+package com.zhongzheng.modules.course.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+
+/**
+ * 模块与章关系添加对象 course_module_chapter
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Data
+@ApiModel("模块与章关系添加对象")
+public class CourseModuleChapterAddBo {
+
+    /** 模块id */
+    @ApiModelProperty("模块id")
+    private Long moduleId;
+    /** 章ID */
+    @ApiModelProperty("章ID")
+    private Long chapterId;
+}

+ 32 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/bo/CourseModuleChapterEditBo.java

@@ -0,0 +1,32 @@
+package com.zhongzheng.modules.course.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+/**
+ * 模块与章关系编辑对象 course_module_chapter
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Data
+@ApiModel("模块与章关系编辑对象")
+public class CourseModuleChapterEditBo {
+
+    /** $column.columnComment */
+    @ApiModelProperty("$column.columnComment")
+    private Long id;
+
+    /** 模块id */
+    @ApiModelProperty("模块id")
+    private Long moduleId;
+
+    /** 章ID */
+    @ApiModelProperty("章ID")
+    private Long chapterId;
+
+}

+ 45 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/bo/CourseModuleChapterQueryBo.java

@@ -0,0 +1,45 @@
+package com.zhongzheng.modules.course.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
+
+import com.zhongzheng.common.core.domain.BaseEntity;
+
+/**
+ * 模块与章关系分页查询对象 course_module_chapter
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("模块与章关系分页查询对象")
+public class CourseModuleChapterQueryBo extends BaseEntity {
+
+	/** 分页大小 */
+	@ApiModelProperty("分页大小")
+	private Integer pageSize;
+	/** 当前页数 */
+	@ApiModelProperty("当前页数")
+	private Integer pageNum;
+	/** 排序列 */
+	@ApiModelProperty("排序列")
+	private String orderByColumn;
+	/** 排序的方向desc或者asc */
+	@ApiModelProperty(value = "排序的方向", example = "asc,desc")
+	private String isAsc;
+
+
+	/** 模块id */
+	@ApiModelProperty("模块id")
+	private Long moduleId;
+	/** 章ID */
+	@ApiModelProperty("章ID")
+	private Long chapterId;
+}

+ 33 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/domain/CourseModuleChapter.java

@@ -0,0 +1,33 @@
+package com.zhongzheng.modules.course.domain;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import java.io.Serializable;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.zhongzheng.common.annotation.Excel;
+
+/**
+ * 模块与章关系对象 course_module_chapter
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("course_module_chapter")
+public class CourseModuleChapter implements Serializable {
+
+private static final long serialVersionUID=1L;
+
+    /** $column.columnComment */
+    @TableId(value = "id")
+    private Long id;
+    /** 模块id */
+    private Long moduleId;
+    /** 章ID */
+    private Long chapterId;
+}

+ 14 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/mapper/CourseModuleChapterMapper.java

@@ -0,0 +1,14 @@
+package com.zhongzheng.modules.course.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zhongzheng.modules.course.domain.CourseModuleChapter;
+
+/**
+ * 模块与章关系Mapper接口
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+public interface CourseModuleChapterMapper extends BaseMapper<CourseModuleChapter> {
+
+}

+ 52 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/ICourseModuleChapterService.java

@@ -0,0 +1,52 @@
+package com.zhongzheng.modules.course.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterAddBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterEditBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterQueryBo;
+import com.zhongzheng.modules.course.domain.CourseModuleChapter;
+import com.zhongzheng.modules.course.vo.CourseModuleChapterVo;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 模块与章关系Service接口
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+public interface ICourseModuleChapterService extends IService<CourseModuleChapter> {
+	/**
+	 * 查询单个
+	 * @return
+	 */
+	CourseModuleChapterVo queryById(Long id);
+
+	/**
+	 * 查询列表
+	 */
+	List<CourseModuleChapterVo> queryList(CourseModuleChapterQueryBo bo);
+
+	/**
+	 * 根据新增业务对象插入模块与章关系
+	 * @param bo 模块与章关系新增业务对象
+	 * @return
+	 */
+	Boolean insertByAddBo(CourseModuleChapterAddBo bo);
+
+	/**
+	 * 根据编辑业务对象修改模块与章关系
+	 * @param bo 模块与章关系编辑业务对象
+	 * @return
+	 */
+	Boolean updateByEditBo(CourseModuleChapterEditBo bo);
+
+	/**
+	 * 校验并删除数据
+	 * @param ids 主键集合
+	 * @param isValid 是否校验,true-删除前校验,false-不校验
+	 * @return
+	 */
+	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+}

+ 97 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseModuleChapterServiceImpl.java

@@ -0,0 +1,97 @@
+package com.zhongzheng.modules.course.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterAddBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterEditBo;
+import com.zhongzheng.modules.course.bo.CourseModuleChapterQueryBo;
+import com.zhongzheng.modules.course.domain.CourseModuleChapter;
+import com.zhongzheng.modules.course.mapper.CourseModuleChapterMapper;
+import com.zhongzheng.modules.course.service.ICourseModuleChapterService;
+import com.zhongzheng.modules.course.vo.CourseModuleChapterVo;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.Page;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 模块与章关系Service业务层处理
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Service
+public class CourseModuleChapterServiceImpl extends ServiceImpl<CourseModuleChapterMapper, CourseModuleChapter> implements ICourseModuleChapterService {
+
+    @Override
+    public CourseModuleChapterVo queryById(Long id){
+        CourseModuleChapter db = this.baseMapper.selectById(id);
+        return BeanUtil.toBean(db, CourseModuleChapterVo.class);
+    }
+
+    @Override
+    public List<CourseModuleChapterVo> queryList(CourseModuleChapterQueryBo bo) {
+        LambdaQueryWrapper<CourseModuleChapter> lqw = Wrappers.lambdaQuery();
+        lqw.eq(bo.getModuleId() != null, CourseModuleChapter::getModuleId, bo.getModuleId());
+        lqw.eq(bo.getChapterId() != null, CourseModuleChapter::getChapterId, bo.getChapterId());
+        return entity2Vo(this.list(lqw));
+    }
+
+    /**
+    * 实体类转化成视图对象
+    *
+    * @param collection 实体类集合
+    * @return
+    */
+    private List<CourseModuleChapterVo> entity2Vo(Collection<CourseModuleChapter> collection) {
+        List<CourseModuleChapterVo> voList = collection.stream()
+                .map(any -> BeanUtil.toBean(any, CourseModuleChapterVo.class))
+                .collect(Collectors.toList());
+        if (collection instanceof Page) {
+            Page<CourseModuleChapter> page = (Page<CourseModuleChapter>)collection;
+            Page<CourseModuleChapterVo> pageVo = new Page<>();
+            BeanUtil.copyProperties(page,pageVo);
+            pageVo.addAll(voList);
+            voList = pageVo;
+        }
+        return voList;
+    }
+
+    @Override
+    public Boolean insertByAddBo(CourseModuleChapterAddBo bo) {
+        CourseModuleChapter add = BeanUtil.toBean(bo, CourseModuleChapter.class);
+        validEntityBeforeSave(add);
+        return this.save(add);
+    }
+
+    @Override
+    public Boolean updateByEditBo(CourseModuleChapterEditBo bo) {
+        CourseModuleChapter update = BeanUtil.toBean(bo, CourseModuleChapter.class);
+        validEntityBeforeSave(update);
+        return this.updateById(update);
+    }
+
+    /**
+     * 保存前的数据校验
+     *
+     * @param entity 实体类数据
+     */
+    private void validEntityBeforeSave(CourseModuleChapter entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return this.removeByIds(ids);
+    }
+}

+ 35 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/vo/CourseModuleChapterVo.java

@@ -0,0 +1,35 @@
+package com.zhongzheng.modules.course.vo;
+
+import com.zhongzheng.common.annotation.Excel;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+
+
+
+/**
+ * 模块与章关系视图对象 mall_package
+ *
+ * @author hjl
+ * @date 2021-10-11
+ */
+@Data
+@ApiModel("模块与章关系视图对象")
+public class CourseModuleChapterVo {
+	private static final long serialVersionUID = 1L;
+
+	/** $pkColumn.columnComment */
+	@ApiModelProperty("$pkColumn.columnComment")
+	private Long id;
+
+	/** 模块id */
+	@Excel(name = "模块id")
+	@ApiModelProperty("模块id")
+	private Long moduleId;
+	/** 章ID */
+	@Excel(name = "章ID")
+	@ApiModelProperty("章ID")
+	private Long chapterId;
+}

+ 14 - 0
zhongzheng-system/src/main/resources/mapper/modules/course/CourseModuleChapterMapper.xml

@@ -0,0 +1,14 @@
+<?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.zhongzheng.modules.course.mapper.CourseModuleChapterMapper">
+
+    <resultMap type="com.zhongzheng.modules.course.domain.CourseModuleChapter" id="CourseModuleChapterResult">
+        <result property="id" column="id"/>
+        <result property="moduleId" column="module_id"/>
+        <result property="chapterId" column="chapter_id"/>
+    </resultMap>
+
+
+</mapper>