Merge remote-tracking branch 'origin/在线访问lhj' into 在线访问lhj

在线访问lhj
李宏杰 8 months ago
commit 46c38e66d3

@ -2,45 +2,40 @@ package com.tamguo.modules.tiku.model;
import java.io.Serializable;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.tamguo.config.dao.SuperEntity;
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum;
import lombok.Data;
import java.util.List;
import com.alibaba.fastjson.annotation.JSONField; // 用于 JSON 序列化时的注解
import com.alibaba.fastjson.serializer.SerializerFeature; // JSON 序列化特性
import com.baomidou.mybatisplus.annotations.TableField; // 与数据库表字段相关的注解
import com.baomidou.mybatisplus.annotations.TableName; // 表名注解
import com.tamguo.config.dao.SuperEntity; // 父类实体
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; // 章节状态枚举
import lombok.Data; // Lombok 的数据注解
/**
* The persistent class for the t_chapter database table.
*
* t_chapter
*/
@TableName(value="t_chapter")
@Data
public class ChapterEntity extends SuperEntity<ChapterEntity> implements Serializable {
private static final long serialVersionUID = 1L;
private String courseId;
private String bookId;
private String name;
private String parentCode;
private String parentCodes;
private Integer questionNum;
private Integer pointNum;
private Integer orders;
private Boolean treeLeaf;
private Integer treeLevel;
private String seoTitle;
private String seoKeywords;
private String seoDescription;
@TableField(exist=false)
private List<ChapterEntity> childChapterList;
@JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString)
private ChapterStatusEnum status;
@TableName(value = "t_chapter") // 指定表名为 t_chapter
@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法
public class ChapterEntity extends SuperEntity<ChapterEntity> implements Serializable { // 继承父类实体,实现序列化接口
private static final long serialVersionUID = 1L; // 序列化版本号
private String courseId; // 课程 ID
private String bookId; // 书籍 ID
private String name; // 章节名称
private String parentCode; // 父章节代码
private String parentCodes; // 父章节代码列表
private Integer questionNum; // 问题数量
private Integer pointNum; // 知识点数量
private Integer orders; // 排序序号
private Boolean treeLeaf; // 是否为叶子节点
private Integer treeLevel; // 树的层级
private String seoTitle; // SEO 标题
private String seoKeywords; // SEO 关键字
private String seoDescription; // SEO 描述
@TableField(exist = false) // 表示该字段在数据库中不存在
private List<ChapterEntity> childChapterList; // 子章节列表
@JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) // 指定 JSON 序列化枚举时的特性
private ChapterStatusEnum status; // 章节状态枚举
}

@ -1,43 +1,42 @@
package com.tamguo.modules.tiku.model;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum;
import lombok.Data;
import java.util.Date; // 日期类
@Data
@TableName(value="t_course")
public class CourseEntity {
@TableId
private String id;
private String subjectId;
private String name;
private Integer sort;
private Integer questionNum;
private Integer pointNum;
private String remarks;
private String icon;
import com.alibaba.fastjson.annotation.JSONField; // 用于 JSON 序列化时的注解
import com.alibaba.fastjson.serializer.SerializerFeature; // JSON 序列化特性
import com.baomidou.mybatisplus.annotations.TableField; // 与数据库表字段相关的注解
import com.baomidou.mybatisplus.annotations.TableId; // 表主键注解
import com.baomidou.mybatisplus.annotations.TableName; // 表名注解
import com.baomidou.mybatisplus.enums.FieldFill; // 字段填充策略枚举
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 课程状态枚举
import lombok.Data; // Lombok 的数据注解
private String seoTitle;
private String seoKeywords;
private String seoDescription;
@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法
@TableName(value = "t_course") // 指定表名为 t_course
public class CourseEntity {
@TableId // 标识为主键
private String id; // 课程 ID
private String subjectId; // 科目 ID
private String name; // 课程名称
private Integer sort; // 排序号
private Integer questionNum; // 问题数量
private Integer pointNum; // 知识点数量
private String remarks; // 备注
private String icon; // 图标
@TableField(fill = FieldFill.INSERT_UPDATE)
private String createBy;
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date createDate;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
private String seoTitle; // SEO 标题
private String seoKeywords; // SEO 关键字
private String seoDescription; // SEO 描述
@JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString)
private CourseStatusEnum status;
@TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充
private String createBy; // 创建人
@TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充
private String updateBy; // 更新人
@TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充
private Date createDate; // 创建日期
@TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充
private Date updateDate; // 更新日期
@JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) // 指定 JSON 序列化枚举时的特性
private CourseStatusEnum status; // 课程状态枚举
}

@ -1,28 +1,66 @@
package com.tamguo.modules.tiku.model.enums;
import java.io.Serializable;
/**
* (1.2.; 3.)
*
* (1. 2. 3. 4. 5. )
*
* @author tamguo
*
*/
public enum QuestionTypeEnum {
/**
*
* @param value
* @param desc
*/
DANXUANTI("1", "单选题"),
/**
*
* @param value
* @param desc
*/
DUOXUANTI("2", "多选题"),
/**
*
* @param value
* @param desc
*/
TIANKONGTI("3", "填空题"),
/**
*
* @param value
* @param desc
*/
PANDUANTI("4", "判断题"),
/**
*
* @param value
* @param desc
*/
WENDATI("5", "问答题");
private String value;
private String desc;
private String value; // 枚举值
private String desc; // 描述
/**
*
* @param value
* @param desc
*/
QuestionTypeEnum(final String value, final String desc) {
this.value = value;
this.desc = desc;
}
/**
* value
* @param value value
* @return WENDATI
*/
public static QuestionTypeEnum getQuestionType(String value) {
if ("1".equals(value)) {
return DANXUANTI;
@ -38,17 +76,28 @@ public enum QuestionTypeEnum {
return WENDATI;
}
/**
*
* @return
*/
public Serializable getValue() {
return this.value;
}
/**
*
* @return
*/
public String getDesc() {
return this.desc;
}
/**
*
* @return
*/
@Override
public String toString() {
return this.value;
}
}

@ -1,45 +1,54 @@
package com.tamguo.modules.tiku.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.tiku.dao.KnowPointMapper;
import com.tamguo.modules.tiku.dao.ChapterMapper;
import com.tamguo.modules.tiku.dao.CourseMapper;
import com.tamguo.modules.tiku.model.KnowPointEntity;
import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.condition.ChapterCondition;
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum;
import com.tamguo.modules.tiku.service.IChapterService;
@Service
import java.util.ArrayList; // 导入 ArrayList 类,用于存储章节列表
import java.util.List; // 导入 List 接口,用于存储章节实体列表
import org.apache.commons.lang3.StringUtils; // 导入StringUtils 类,用于字符串操作
import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入
import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类
import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理
import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组
import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象
import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件
import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询
import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类
import com.tamguo.common.utils.SystemConstant; // 导入 SystemConstant 类,用于定义系统常量
import com.tamguo.modules.tiku.dao.KnowPointMapper; // 导入 KnowPointMapper 接口,用于知识关键点的数据访问
import com.tamguo.modules.tiku.dao.ChapterMapper; // 导入 ChapterMapper 接口,用于章节的数据访问
import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问
import com.tamguo.modules.tiku.model.KnowPointEntity; // 导入 KnowPointEntity 类,代表知识关键点实体
import com.tamguo.modules.tiku.model.ChapterEntity; // 导入 ChapterEntity 类,代表章节实体
import com.tamguo.modules.tiku.model.condition.ChapterCondition; // 导入 ChapterCondition 类,代表章节查询条件
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; // 导入 ChapterStatusEnum 枚举,代表章节状态
import com.tamguo.modules.tiku.service.IChapterService; // 导入 IChapterService 接口,定义章节服务的接口
@Service // 标识为服务层实现类
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity> implements IChapterService {
@Autowired
ChapterMapper chapterMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
KnowPointMapper bookMapper;
@Autowired // 自动注入 ChapterMapper 实例
private ChapterMapper chapterMapper;
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@Autowired // 自动注入 KnowPointMapper 实例
private KnowPointMapper bookMapper;
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
/**
*
*
* @param bookId ID
* @return
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@SuppressWarnings("unchecked") // 抑制unchecked 警告
@Override
public List<ChapterEntity> findChapterTree(String bookId) {
// 根据书籍 ID 查询章节列表
List<ChapterEntity> chapterList = baseMapper.selectList(Condition.create().eq("book_id", bookId));
// 获取根chapter UID
// 获取根章节 UID
String rootUid = StringUtils.EMPTY;
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity chapter = chapterList.get(i);
@ -47,6 +56,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
rootUid = chapter.getId();
}
}
// 获取第一层结构
List<ChapterEntity> entitys = new ArrayList<>();
for (int i = 0; i < chapterList.size(); i++) {
@ -55,8 +65,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
entitys.add(chapter);
}
}
for (int i = 0; i < entitys.size(); i++) {
ChapterEntity entity = entitys.get(i);
// 获取子章节列表
List<ChapterEntity> childs = new ArrayList<>();
for (int k = 0; k < chapterList.size(); k++) {
ChapterEntity chapter = chapterList.get(k);
@ -66,10 +78,12 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
}
entity.setChildChapterList(childs);
}
for (int i = 0; i < entitys.size(); i++) {
List<ChapterEntity> childs = entitys.get(i).getChildChapterList();
for (int k = 0; k < childs.size(); k++) {
ChapterEntity child = childs.get(k);
// 获取子子章节列表
List<ChapterEntity> tmpChilds = new ArrayList<>();
for (int n = 0; n < chapterList.size(); n++) {
ChapterEntity chapter = chapterList.get(n);
@ -83,83 +97,98 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
return entitys;
}
@SuppressWarnings("unchecked")
/**
*
*
* @param condition
* @return
*/
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public List<ChapterEntity> listData(ChapterCondition condition) {
Condition query = Condition.create();
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getParentCode())) {
query.eq("parent_code", condition.getParentCode());
query.eq("parent_code", condition.getParentCode()); // 添加父章节代码条件
} else {
query.eq("tree_level", "0");
query.eq("tree_level", "0"); // 添加树级别为 0 的条件(即根章节)
}
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
query.eq("id", condition.getId()); // 添加章节 ID 条件
}
if (!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName());
query.like("name", condition.getName()); // 添加章节名称模糊匹配条件
}
if (!StringUtils.isEmpty(condition.getBookId())) {
query.andNew().eq("course_id", condition.getBookId()).or().eq("book_id", condition.getBookId()).or().eq("subject_id", condition.getBookId());;
query.andNew().eq("course_id", condition.getBookId()).or().eq("book_id", condition.getBookId()).or().eq("subject_id", condition.getBookId()); // 添加课程 ID、书籍 ID 或科目 ID 条件
}
return chapterMapper.selectList(query);
}
@SuppressWarnings("unchecked")
@Override
public JSONArray treeData(String courseId, String excludeId) {
List<ChapterEntity> chapterList = null;
if(StringUtils.isEmpty(excludeId)) {
chapterList = chapterMapper.selectList(Condition.EMPTY);
} else {
chapterList = chapterMapper.selectList(Condition.create().notLike("parent_codes", excludeId).eq("id", excludeId));
}
return turnZTreeData(chapterList);
return chapterMapper.selectList(query); // 执行查询并返回结果
}
/**
* ZTree JSON
*
* @param chapterList
* @return ZTree JSON
*/
private JSONArray turnZTreeData(List<ChapterEntity> chapterList) {
if (chapterList!= null) {
JSONArray nodes = new JSONArray();
JSONArray nodes = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < chapterList.size(); i++) {
JSONObject node = new JSONObject();
JSONObject node = new JSONObject(); // 创建 JSON 对象
ChapterEntity office = chapterList.get(i);
node.put("name", office.getName());
node.put("id", office.getId());
node.put("pId", office.getParentCode());
node.put("title", office.getName());
nodes.add(node);
ChapterEntity office = chapterList.get(i); // 获取章节实体
node.put("name", office.getName()); // 设置节点名称
node.put("id", office.getId()); // 设置节点 ID
node.put("pId", office.getParentCode()); // 设置父节点 ID
node.put("title", office.getName()); // 设置节点标题
nodes.add(node); // 将节点添加到 JSON 数组中
}
return nodes;
return nodes; // 返回 JSON 数组
}
return null;
return null; // 如果章节列表为空,则返回 null
}
@Transactional(readOnly=false)
/**
*
*
* @param chapter
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void save(ChapterEntity chapter) {
// 更新父章节的叶子节点状态为 false
ChapterEntity parentChapter = chapterMapper.selectById(chapter.getParentCode());
parentChapter.setTreeLeaf(false);
chapterMapper.updateById(parentChapter);
chapter.setStatus(ChapterStatusEnum.NORMAL);
chapter.setTreeLeaf(true);
chapter.setTreeLevel(parentChapter.getTreeLevel() + 1);
chapter.setBookId(parentChapter.getBookId());
chapterMapper.insert(chapter);
chapter.setStatus(ChapterStatusEnum.NORMAL); // 设置章节状态为正常
chapter.setTreeLeaf(true); // 设置章节为叶子节点
chapter.setTreeLevel(parentChapter.getTreeLevel() + 1); // 设置章节树级别
chapter.setBookId(parentChapter.getBookId()); // 设置章节所属书籍 ID
chapterMapper.insert(chapter); // 插入章节记录
// 更新章节的父章节代码列表
chapter.setParentCodes(parentChapter.getParentCodes() + chapter.getId() + ",");
chapterMapper.updateById(chapter);
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=false)
/**
*
*
* @param chapter
*/
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void update(ChapterEntity chapter) {
ChapterEntity entity = chapterMapper.selectById(chapter.getId());
// 更新父章节的叶子节点状态为 false
ChapterEntity parentChapter = chapterMapper.selectById(chapter.getParentCode());
parentChapter.setTreeLeaf(false);
chapterMapper.updateById(parentChapter);
// 更新章节信息
ChapterEntity entity = chapterMapper.selectById(chapter.getId());
entity.setName(chapter.getName());
entity.setParentCode(chapter.getParentCode());
entity.setParentCodes(parentChapter.getParentCodes() + entity.getId() + ",");
@ -168,7 +197,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
entity.setOrders(chapter.getOrders());
entity.setTreeLevel(entity.getParentCodes().split(",").length - 1);
// 更新子集章节
// 更新子集章节的父章节代码列表和树级别
List<ChapterEntity> chapterList = chapterMapper.selectList(Condition.create().like("parent_codes", entity.getId()));
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity child = chapterList.get(i);
@ -181,13 +210,20 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
chapterMapper.updateById(entity);
}
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
/**
*
*
* @param id ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public void delete(String id) {
// 更新章节状态为已删除
ChapterEntity chapter = chapterMapper.selectById(id);
chapter.setStatus(ChapterStatusEnum.DELETE);
chapterMapper.updateById(chapter);
// 删除子章节
List<ChapterEntity> childs = chapterMapper.selectList(Condition.create().like("parent_codes", id));
for (int i = 0; i < childs.size(); i++) {
@ -197,24 +233,41 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
}
}
@Transactional(readOnly=true)
@SuppressWarnings("unchecked")
/**
* ID
*
* @param courseId ID
* @return
*/
@Transactional(readOnly = true) // 开启事务,设置只读为 true
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public List<ChapterEntity> findCourseChapter(String courseId) {
// 根据课程 ID 查询知识关键点列表
List<KnowPointEntity> bookList = bookMapper.selectList(Condition.create().eq("course_id", courseId));
if (bookList.size() == 0) {
return null;
return null; // 如果没有找到知识关键点,则返回 null
}
Condition condition = Condition.create();
condition.eq("tree_level", 1);
condition.eq("book_id", bookList.get(0).getId());
Condition condition = Condition.create(); // 创建查询条件对象
condition.eq("tree_level", 1); // 设置树级别为 1
condition.eq("book_id", bookList.get(0).getId()); // 设置书籍 ID
// 根据条件查询章节列表
List<ChapterEntity> list = chapterMapper.selectPage(new Page<>(1, 5), condition);
return list;
return list; // 返回章节列表
}
@Transactional(readOnly=true)
/**
* ID
*
* @param parentCode
* @param id ID
* @return
*/
@Transactional(readOnly = true) // 开启事务,设置只读为 true
@Override
public ChapterEntity selectNextChapter(String parentCode, String id) {
return chapterMapper.selectNextChapter(parentCode , id);
return chapterMapper.selectNextChapter(parentCode, id); // 查询下一个章节
}
}

@ -1,125 +1,185 @@
package com.tamguo.modules.tiku.service.impl;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.modules.tiku.dao.CourseMapper;
import com.tamguo.modules.tiku.dao.SubjectMapper;
import com.tamguo.modules.tiku.model.CourseEntity;
import com.tamguo.modules.tiku.model.SubjectEntity;
import com.tamguo.modules.tiku.model.condition.CourseCondition;
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum;
import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum;
import com.tamguo.modules.tiku.service.ICourseService;
@Service
import java.util.Arrays; // 导入 Arrays 类,用于操作数组
import java.util.List; // 导入 List 接口,用于存储科目和课程实体列表
import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入
import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类
import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理
import org.springframework.util.StringUtils; // 导入 StringUtils 类,用于字符串操作
import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组
import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象
import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件
import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询
import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类
import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问
import com.tamguo.modules.tiku.dao.SubjectMapper; // 导入 SubjectMapper 接口,用于科目的数据访问
import com.tamguo.modules.tiku.model.CourseEntity; // 导入 CourseEntity 类,代表课程实体
import com.tamguo.modules.tiku.model.SubjectEntity; // 导入 SubjectEntity 类,代表科目实体
import com.tamguo.modules.tiku.model.condition.CourseCondition; // 导入 CourseCondition 类,代表课程查询条件
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 导入 CourseStatusEnum 枚举,代表课程状态
import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; // 导入 SubjectStatusEnum 枚举,代表科目状态
import com.tamguo.modules.tiku.service.ICourseService; // 导入 ICourseService 接口,定义课程服务的接口
@Service // 标识为服务层实现类
public class CourseServiceImpl extends ServiceImpl<CourseMapper, CourseEntity> implements ICourseService {
@Autowired
public CourseMapper courseMapper;
@Autowired
public SubjectMapper subjectMapper;
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true)
@Autowired // 自动注入 SubjectMapper 实例
private SubjectMapper subjectMapper;
/**
*
*
* @param condition
* @return
*/
@SuppressWarnings("unchecked") // 抑制unchecked 警告
@Transactional(readOnly = true) // 开启事务,设置只读为 true
@Override
public Page<CourseEntity> listData(CourseCondition condition) {
Page<CourseEntity> page = new Page<>(condition.getPageNo() , condition.getPageSize());
Condition query = Condition.create();
Page<CourseEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
query.eq("id", condition.getId()); // 添加课程 ID 条件
}
if (!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName());
query.like("name", condition.getName()); // 添加课程名称模糊匹配条件
}
if (!StringUtils.isEmpty(condition.getSubjectId())) {
query.eq("subject_id", condition.getSubjectId());
query.eq("subject_id", condition.getSubjectId()); // 添加科目 ID 条件
}
if (!StringUtils.isEmpty(condition.getStatus())) {
query.eq("status", condition.getStatus());
query.eq("status", condition.getStatus()); // 添加课程状态条件
}
query.orderAsc(Arrays.asList("sort"));
return page.setRecords(courseMapper.selectPage(page , query));
query.orderAsc(Arrays.asList("sort")); // 根据排序字段升序排序
return page.setRecords(courseMapper.selectPage(page, query)); // 执行查询并设置分页结果
}
@Transactional(readOnly=false)
/**
*
*
* @param course
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void save(CourseEntity course) {
course.setStatus(CourseStatusEnum.NORMAL);
courseMapper.insert(course);
course.setStatus(CourseStatusEnum.NORMAL); // 设置课程状态为正常
courseMapper.insert(course); // 插入课程记录
}
@Transactional(readOnly=false)
/**
*
*
* @param course
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void update(CourseEntity course) {
CourseEntity entity = courseMapper.selectById(course.getId());
entity.setName(course.getName());
entity.setSubjectId(course.getSubjectId());
entity.setSort(course.getSort());
entity.setRemarks(course.getRemarks());
courseMapper.updateById(entity);
CourseEntity entity = courseMapper.selectById(course.getId()); // 获取要更新的课程实体
entity.setName(course.getName()); // 更新课程名称
entity.setSubjectId(course.getSubjectId()); // 更新科目 ID
entity.setSort(course.getSort()); // 更新排序号
entity.setRemarks(course.getRemarks()); // 更新备注
courseMapper.updateById(entity); // 更新课程记录
}
@Transactional(readOnly=false)
/**
*
*
* @param uid ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void delete(String uid) {
CourseEntity entity = courseMapper.selectById(uid);
entity.setStatus(CourseStatusEnum.DELETE);
courseMapper.updateById(entity);
CourseEntity entity = courseMapper.selectById(uid); // 获取要删除的课程实体
entity.setStatus(CourseStatusEnum.DELETE); // 设置课程状态为已删除
courseMapper.updateById(entity); // 更新课程记录
}
@Transactional(readOnly=false)
/**
*
*
* @param uid ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void enable(String uid) {
CourseEntity entity = courseMapper.selectById(uid);
entity.setStatus(CourseStatusEnum.NORMAL);
courseMapper.updateById(entity);
CourseEntity entity = courseMapper.selectById(uid); // 获取要启用的课程实体
entity.setStatus(CourseStatusEnum.NORMAL); // 设置课程状态为正常
courseMapper.updateById(entity); // 更新课程记录
}
@Transactional(readOnly=false)
/**
*
*
* @param uid ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void disabled(String uid) {
CourseEntity entity = courseMapper.selectById(uid);
entity.setStatus(CourseStatusEnum.DISABLED);
courseMapper.updateById(entity);
CourseEntity entity = courseMapper.selectById(uid); // 获取要禁用的课程实体
entity.setStatus(CourseStatusEnum.DISABLED); // 设置课程状态为禁用
courseMapper.updateById(entity); // 更新课程记录
}
@SuppressWarnings("unchecked")
/**
* ZTree JSON
*
* @return ZTree JSON
*/
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public JSONArray treeData() {
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue()));
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue()));
return transform(subjectList, courseList);
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表
return transform(subjectList, courseList); // 转换科目和课程数据为 JSON 数组
}
/**
* ZTree JSON
*
* @param subjectList
* @param courseList
* @return ZTree JSON
*/
private JSONArray transform(List<SubjectEntity> subjectList, List<CourseEntity> courseList) {
JSONArray entitys = new JSONArray();
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", subjectList.get(i).getId());
entity.put("name", subjectList.get(i).getName());
entity.put("pId", "0");
entitys.add(entity);
JSONObject entity = new JSONObject(); // 创建 JSON 对象
SubjectEntity subject = subjectList.get(i); // 获取科目实体
entity.put("id", subject.getId()); // 设置科目 ID
entity.put("name", subject.getName()); // 设置科目名称
entity.put("pId", "0"); // 设置父节点 ID 为 0
entitys.add(entity); // 将科目对象添加到 JSON 数组中
}
for (int i = 0; i < courseList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", courseList.get(i).getId());
entity.put("name", courseList.get(i).getName());
entity.put("pId", courseList.get(i).getSubjectId());
entitys.add(entity);
}
return entitys;
}
JSONObject entity = new JSONObject(); // 创建 JSON 对象
CourseEntity course = courseList.get(i); // 获取课程实体
entity.put("id", course.getId()); // 设置课程 ID
entity.put("name", course.getName()); // 设置课程名称
entity.put("pId", course.getSubjectId()); // 设置父节点 ID 为课程所属科目 ID
entitys.add(entity); // 将课程对象添加到 JSON 数组中
}
return entitys; // 返回转换后的 JSON 数组
}
}

@ -1,129 +1,192 @@
package com.tamguo.modules.tiku.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.modules.tiku.dao.KnowPointMapper;
import com.tamguo.modules.tiku.dao.CourseMapper;
import com.tamguo.modules.tiku.dao.SubjectMapper;
import com.tamguo.modules.tiku.model.KnowPointEntity;
import com.tamguo.modules.tiku.model.CourseEntity;
import com.tamguo.modules.tiku.model.SubjectEntity;
import com.tamguo.modules.tiku.model.condition.BookCondition;
import com.tamguo.modules.tiku.model.enums.BookStatusEnum;
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum;
import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum;
import com.tamguo.modules.tiku.service.IKnowPointService;
@Service
import java.util.List; // 导入 List 接口,用于存储科目、课程和知识点实体列表
import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入
import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类
import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理
import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组
import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象
import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件
import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询
import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类
import com.tamguo.modules.tiku.dao.KnowPointMapper; // 导入 KnowPointMapper 接口,用于知识点的数据访问
import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问
import com.tamguo.modules.tiku.dao.SubjectMapper; // 导入 SubjectMapper 接口,用于科目的数据访问
import com.tamguo.modules.tiku.model.KnowPointEntity; // 导入 KnowPointEntity 类,代表知识点实体
import com.tamguo.modules.tiku.model.CourseEntity; // 导入 CourseEntity 类,代表课程实体
import com.tamguo.modules.tiku.model.SubjectEntity; // 导入 SubjectEntity 类,代表科目实体
import com.tamguo.modules.tiku.model.condition.BookCondition; // 导入 BookCondition 类,代表知识点查询条件
import com.tamguo.modules.tiku.model.enums.BookStatusEnum; // 导入 BookStatusEnum 枚举,代表知识点状态
import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 导入 CourseStatusEnum 枚举,代表课程状态
import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; // 导入 SubjectStatusEnum 枚举,代表科目状态
import com.tamguo.modules.tiku.service.IKnowPointService; // 导入 IKnowPointService 接口,定义知识点服务的接口
@Service // 标识为服务层实现类
public class KnowPointServiceImpl extends ServiceImpl<KnowPointMapper, KnowPointEntity> implements IKnowPointService {
@Autowired
KnowPointMapper knowPointMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
SubjectMapper subjectMapper;
@Autowired // 自动注入 KnowPointMapper 实例
private KnowPointMapper knowPointMapper;
@Transactional(readOnly=false)
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@Autowired // 自动注入 SubjectMapper 实例
private SubjectMapper subjectMapper;
/**
*
*
* @param condition
* @return
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public Page<KnowPointEntity> listData(BookCondition condition) {
Page<KnowPointEntity> page = new Page<>(condition.getPageNo() , condition.getPageSize());
return page.setRecords(knowPointMapper.listData(page, condition));
Page<KnowPointEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象
return page.setRecords(knowPointMapper.listData(page, condition)); // 执行查询并设置分页结果
}
@Transactional(readOnly=false)
/**
*
*
* @param book
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void save(KnowPointEntity book) {
CourseEntity course = courseMapper.selectById(book.getCourseId());
CourseEntity course = courseMapper.selectById(book.getCourseId()); // 获取课程实体
book.setStatus(BookStatusEnum.NORMAL);
book.setSubjectId(course.getSubjectId());
knowPointMapper.insert(book);
book.setStatus(BookStatusEnum.NORMAL); // 设置知识点状态为正常
book.setSubjectId(course.getSubjectId()); // 设置知识点所属科目 ID
knowPointMapper.insert(book); // 插入知识点记录
}
@Transactional(readOnly=false)
/**
*
*
* @param book
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void update(KnowPointEntity book) {
CourseEntity course = courseMapper.selectById(book.getCourseId());
KnowPointEntity entity = knowPointMapper.selectById(book.getId());
entity.setName(book.getName());
entity.setPointNum(book.getPointNum());
entity.setQuestionNum(book.getQuestionNum());
entity.setRemarks(book.getRemarks());
entity.setPublishingHouse(book.getPublishingHouse());
entity.setSort(book.getSort());
entity.setCourseId(course.getId());
knowPointMapper.updateById(entity);
CourseEntity course = courseMapper.selectById(book.getCourseId()); // 获取课程实体
KnowPointEntity entity = knowPointMapper.selectById(book.getId()); // 获取要更新的知识点实体
entity.setName(book.getName()); // 更新知识点名称
entity.setPointNum(book.getPointNum()); // 更新知识点数量
entity.setQuestionNum(book.getQuestionNum()); // 更新问题数量
entity.setRemarks(book.getRemarks()); // 更新备注
entity.setPublishingHouse(book.getPublishingHouse()); // 更新出版社
entity.setSort(book.getSort()); // 更新排序号
entity.setCourseId(course.getId()); // 更新课程 ID
knowPointMapper.updateById(entity); // 更新知识点记录
}
@Transactional(readOnly=false)
/**
*
*
* @param id ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void delete(String id) {
KnowPointEntity book = knowPointMapper.selectById(id);
book.setStatus(BookStatusEnum.DELETE);
knowPointMapper.updateById(book);
KnowPointEntity book = knowPointMapper.selectById(id); // 获取要删除的知识点实体
book.setStatus(BookStatusEnum.DELETE); // 设置知识点状态为已删除
knowPointMapper.updateById(book); // 更新知识点记录
}
@Transactional(readOnly=false)
/**
*
*
* @param id ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void enable(String id) {
KnowPointEntity book = knowPointMapper.selectById(id);
book.setStatus(BookStatusEnum.NORMAL);
knowPointMapper.updateById(book);
KnowPointEntity book = knowPointMapper.selectById(id); // 获取要启用的知识点实体
book.setStatus(BookStatusEnum.NORMAL); // 设置知识点状态为正常
knowPointMapper.updateById(book); // 更新知识点记录
}
@Transactional(readOnly=false)
/**
*
*
* @param id ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void disabled(String id) {
KnowPointEntity book = knowPointMapper.selectById(id);
book.setStatus(BookStatusEnum.DISABLED);
knowPointMapper.updateById(book);
KnowPointEntity book = knowPointMapper.selectById(id); // 获取要禁用的知识点实体
book.setStatus(BookStatusEnum.DISABLED); // 设置知识点状态为禁用
knowPointMapper.updateById(book); // 更新知识点记录
}
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
/**
* ZTree JSON
*
* @return ZTree JSON
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public JSONArray treeData() {
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue()));
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue()));
List<KnowPointEntity> bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue()));
return transform(subjectList, courseList , bookList);
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表
List<KnowPointEntity> bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue())); // 查询正常状态的知识点列表
return transform(subjectList, courseList, bookList); // 转换科目、课程和知识点数据为 JSON 数组
}
/**
* ZTree JSON
*
* @param subjectList
* @param courseList
* @param bookList
* @return ZTree JSON
*/
private JSONArray transform(List<SubjectEntity> subjectList, List<CourseEntity> courseList, List<KnowPointEntity> bookList) {
JSONArray entitys = new JSONArray();
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", subjectList.get(i).getId());
entity.put("name", subjectList.get(i).getName());
entity.put("pId", "0");
entitys.add(entity);
JSONObject entity = new JSONObject(); // 创建 JSON 对象
SubjectEntity subject = subjectList.get(i); // 获取科目实体
entity.put("id", subject.getId()); // 设置科目 ID
entity.put("name", subject.getName()); // 设置科目名称
entity.put("pId", "0"); // 设置父节点 ID 为 0
entitys.add(entity); // 将科目对象添加到 JSON 数组中
}
for (int i = 0; i < courseList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", courseList.get(i).getId());
entity.put("name", courseList.get(i).getName());
entity.put("pId", courseList.get(i).getSubjectId());
entitys.add(entity);
JSONObject entity = new JSONObject(); // 创建 JSON 对象
CourseEntity course = courseList.get(i); // 获取课程实体
entity.put("id", course.getId()); // 设置课程 ID
entity.put("name", course.getName()); // 设置课程名称
entity.put("pId", course.getSubjectId()); // 设置父节点 ID 为课程所属科目 ID
entitys.add(entity); // 将课程对象添加到 JSON 数组中
}
for (int i = 0; i < bookList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", bookList.get(i).getId());
entity.put("name", bookList.get(i).getName());
entity.put("pId", bookList.get(i).getCourseId());
entitys.add(entity);
JSONObject entity = new JSONObject(); // 创建 JSON 对象
KnowPointEntity book = bookList.get(i); // 获取知识点实体
entity.put("id", book.getId()); // 设置知识点 ID
entity.put("name", book.getName()); // 设置知识点名称
entity.put("pId", book.getCourseId()); // 设置父节点 ID 为知识点所属课程 ID
entitys.add(entity); // 将知识点对象添加到 JSON 数组中
}
return entitys;
return entitys; // 返回转换后的 JSON 数组
}
}

@ -2,6 +2,7 @@ package com.tamguo.modules.tiku.service.impl;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -13,14 +14,28 @@ import com.tamguo.modules.tiku.dao.MenuMapper;
import com.tamguo.modules.tiku.model.MenuEntity;
import com.tamguo.modules.tiku.service.IMenuService;
/**
* MenuServiceImpl IMenuService
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> implements IMenuService {
/**
* MenuMapper
*/
@Autowired
private MenuMapper menuMapper;
/**
*
*/
@Autowired
private CacheService cacheService;
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findMenus() {
@ -36,6 +51,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return menuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findAllMenus() {
@ -51,6 +70,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return allMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findLeftMenus() {
@ -66,7 +89,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return leftMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findChapterMenus() {
@ -82,7 +108,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return chapterMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findFooterMenus() {
@ -98,15 +127,23 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return footerMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> getMenuTree() {
return menuMapper.selectList(Condition.EMPTY);
}
/**
* ID
* @param uid ID
* @return
*/
@Override
public MenuEntity findById(String uid) {
return menuMapper.selectById(uid);
}
}

@ -27,24 +27,58 @@ import com.tamguo.modules.tiku.service.ICourseService;
import com.tamguo.modules.tiku.service.IPaperService;
import com.tamguo.modules.tiku.service.ISubjectService;
/**
* PaperServiceImpl IPaperService
*/
@Service
public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> implements IPaperService {
/**
* ISubjectService
*/
@Autowired
private ISubjectService iSubjectService;
/**
* ICourseService
*/
@Autowired
private ICourseService iCourseService;
/**
* ISysAreaService
*/
@Autowired
private ISysAreaService iSysAreaService;
/**
* PaperMapper
*/
@Autowired
private PaperMapper paperMapper;
/**
* CacheService
*/
@Autowired
private CacheService cacheService;
/**
* QuestionMapper
*/
@Autowired
private QuestionMapper questionMapper;
/**
* QuestionOptionsMapper
*/
@Autowired
private QuestionOptionsMapper questionOptionsMapper;
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findHistoryPaper() {
@ -63,6 +97,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findSimulationPaper() {
@ -81,6 +119,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @param areaId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findHotPaper(String areaId) {
@ -99,6 +142,13 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @param paperId ID
* @param title
* @param name
* @param type
*/
@Transactional(readOnly = false)
@Override
public void addPaperQuestionInfo(String paperId, String title, String name, String type) {
@ -117,6 +167,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.updateById(paper);
}
/**
*
* @param paperId ID
* @param title
* @param name
* @param type
* @param uid ID
*/
@Transactional(readOnly = false)
@Override
public void updatePaperQuestionInfo(String paperId, String title, String name, String type, String uid) {
@ -135,9 +193,15 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.updateById(paper);
}
/**
*
* @param currMemberId ID
* @param paperId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public Result deletePaper(String currMemberId , String paperId) {
public Result deletePaper(String CurrMemberId, String paperId) {
PaperEntity paper = paperMapper.selectById(paperId);
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "不能删除其他人的试卷!");
@ -148,9 +212,16 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, null, "删除成功!");
}
/**
*
* @param CurrMemberId ID
* @param paperId ID
* @param cuid ID
* @return
*/
@Transactional(readOnly = false)
@Override
public Result deletePaperQuestionInfoBtn(String currMemberId , String paperId, String cuid) {
public Result deletePaperQuestionInfoBtn(String CurrMemberId, String paperId, String cuid) {
PaperEntity paper = paperMapper.selectById(paperId);
if (!paper.getCreaterId().equals(currMemberId)) {
return Result.failResult("试卷属于当前用户,不能修改!");
@ -167,6 +238,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, null, "删除子卷成功");
}
/**
*
* @param paper
*/
@Transactional(readOnly = false)
@Override
public void addPaper(PaperEntity paper) {
@ -181,8 +256,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.insert(paper);
}
/**
*
* @param paper
* @param currMemberId ID
* @return
*/
@Override
public Result updatePaper(PaperEntity paper ,String currMemberId) {
public Result updatePaper(PaperEntity paper, String CurrMemberId) {
PaperEntity entity = paperMapper.selectById(paper.getId());
if (!entity.getCreaterId().equals(currMemberId)) {
return Result.failResult("试卷属于当前用户,不能修改!");
@ -192,6 +273,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, paper, "修改成功");
}
/**
*
* @param paperId ID
* @return
*/
@Override
public List<QuestionEntity> findQuestionList(String paperId) {
// 查询选项信息
@ -202,5 +288,4 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
});
return questionList;
}
}

@ -15,66 +15,135 @@ import com.tamguo.modules.tiku.model.PaperEntity;
import com.tamguo.modules.tiku.model.QuestionEntity;
import com.tamguo.modules.tiku.service.IQuestionService;
// 标识这是一个Spring的服务层组件类用于实现IQuestionService接口中定义的与题目Question相关的业务逻辑方法
// 它继承自ServicePlus框架提供的ServiceImpl类借助其提供的通用数据库操作能力结合自身的业务逻辑实现对题目数据的添加、查询、更新和删除等操作并且通过依赖注入获取相关的Mapper对象来与数据库进行交互。
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEntity> implements IQuestionService {
// 自动注入PaperMapper用于操作试卷Paper相关的数据比如通过试卷ID查询试卷信息等操作在题目相关业务逻辑中可能需要获取试卷的创建者等信息来进行权限判断等操作依赖该Mapper与数据库的试卷表进行交互。
@Autowired
private PaperMapper paperMapper;
// 自动注入QuestionMapper用于操作题目Question相关的数据比如插入题目、根据条件查询题目、更新题目以及删除题目等数据库操作是实现题目业务逻辑中与数据库进行交互的核心依赖对象直接对应数据库中的题目表。
@Autowired
private QuestionMapper questionMapper;
/**
*
* ID
* ID
*
* @param question ID
* @param currMemberId IDID
* @return Result0501
*/
@Override
public Result addQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等如果不相等表示当前用户无权操作该试卷下的题目返回包含相应错误提示信息和状态码501的Result对象给调用者。
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "改试卷不属于您!");
}
// 如果当前用户有权限添加题目将从试卷实体对象中获取的课程ID设置到题目实体对象中保证题目与试卷在课程维度上的关联关系正确便于后续按课程等维度进行题目相关的查询、统计等业务操作。
question.setCourseId(paper.getCourseId());
// 通过QuestionMapper将题目实体对象插入到数据库的题目表中完成题目添加的数据库操作若插入成功则数据库中会新增一条对应的题目记录。
questionMapper.insert(question);
// 返回包含添加成功提示信息和状态码0表示成功的Result对象给调用者告知题目添加操作已成功完成。
return Result.result(0, null, "添加成功!");
}
/**
*
* IDIDID
* IDID
* MyBatis Plus
*
* @param questionType
* @param id IDIDID便ID
* @param content LIKE
* @param paperId IDIDIDID
* @param currMemberId IDID访
* @param p 便
* @return Page<QuestionEntity>p.setRecords(null)
*/
@SuppressWarnings("unchecked")
@Override
public Page<QuestionEntity> queryQuestionList(String questionType, String id, String content, String paperId, String currMemberId,
Page<QuestionEntity> p) {
// 根据传入的试卷ID从数据库中查询对应的试卷实体信息然后判断当前登录会员的ID与查询到的试卷创建者的ID是否相等如果不相等表示当前用户无权查询该试卷下的题目直接返回传入的分页对象并将其记录列表设置为空表示无权获取题目数据。
if (!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) {
return p.setRecords(null);
}
// 创建一个MyBatis Plus的查询条件对象用于构建后续查询题目时的各种条件通过该对象可以方便地添加等于、大于、小于、模糊匹配等各种条件来精确筛选题目数据符合MyBatis Plus的条件查询规范。
Condition condition = new Condition();
// 判断题目类型是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定题目类型的题目与数据库题目表中的题目类型字段进行精确匹配查询。
if (!StringUtils.isEmpty(questionType)) {
condition.eq("question_type", questionType);
}
// 判断题目ID是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定ID的题目与数据库题目表中的题目ID字段进行精确匹配查询用于精确查找特定题目。
if (!StringUtils.isEmpty(id)) {
condition.eq("id", id);
}
// 判断题目内容是否不为空字符串如果不为空则添加一个模糊匹配like条件到查询条件对象中使得查询时会获取题目内容包含指定关键字的题目通过数据库的模糊查询LIKE操作符与题目表中的题目内容字段进行匹配查询用于根据部分内容查找相关题目。
if (!StringUtils.isEmpty(content)) {
condition.like("content", content);
}
// 添加一个等于eq条件到查询条件对象中指定要查询的题目所属的试卷ID与数据库题目表中的所属试卷ID字段进行精确匹配查询确保获取的题目都是属于指定试卷的。
condition.eq("paper_id", paperId);
// 通过QuestionMapper结合分页对象和构建好的查询条件对象进行分页查询从数据库中获取符合条件的题目列表数据并将查询结果设置到传入的分页对象的记录列表中最后返回该分页对象供前端进行分页展示等操作。
return p.setRecords(questionMapper.selectPage(p, condition));
}
/**
*
* ID
* QuestionMapperID
* 使
*
* @param question ID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result updateQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等如果不相等表示当前用户无权操作该试卷下的题目返回包含相应错误提示信息和状态码501的Result对象给调用者。
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "改试卷不属于您!");
}
// 如果当前用户有权限更新题目通过QuestionMapper根据题目实体对象的ID更新数据库中对应的题目记录将传入的题目实体对象中的属性值覆盖原有记录中的相应属性值完成题目信息的更新操作。
questionMapper.updateById(question);
// 返回包含更新成功提示信息和状态码0表示成功的Result对象给调用者告知题目更新操作已成功完成。
return Result.result(0, null, "修改成功!");
}
/**
*
* IDID
* QuestionMapperID
* 使
*
* @param uid IDID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result delete(String uid, String currMemberId) {
// 根据传入的题目ID通过QuestionMapper从数据库中查询对应的题目实体信息用于获取该题目所属试卷的ID以便后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
QuestionEntity question = questionMapper.selectById(uid);
// 根据题目所属试卷的ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等如果不相等表示当前用户无权操作该试卷下的题目返回包含相应错误提示信息和状态码501的Result对象给调用者。
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "改试卷不属于您!");
}
// 如果当前用户有权限删除题目通过QuestionMapper根据题目ID删除数据库中对应的题目记录完成题目删除的数据库操作从数据库表中移除该题目对应的行数据。
questionMapper.deleteById(uid);
// 返回包含删除成功提示信息和状态码0表示成功的Result对象给调用者告知题目删除操作已成功完成。
return Result.result(0, null, "删除成功!");
}

@ -19,16 +19,35 @@ import com.tamguo.modules.tiku.model.PaperEntity;
import com.tamguo.modules.tiku.model.SchoolEntity;
import com.tamguo.modules.tiku.service.ISchoolService;
/**
* SchoolServiceImpl ISchoolService
*/
@Service
public class SchoolService extends ServiceImpl<SchoolMapper, SchoolEntity> implements ISchoolService {
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, SchoolEntity> implements ISchoolService {
/**
* SchoolMapper
*/
@Autowired
private SchoolMapper schoolMapper;
/**
* PaperMapper
*/
@Autowired
private PaperMapper paperMapper;
/**
* CacheService
*/
@Autowired
private CacheService cacheService;
/**
*
* @param shcoolId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findEliteSchoolPaper(String shcoolId) {
@ -47,6 +66,10 @@ public class SchoolService extends ServiceImpl<SchoolMapper, SchoolEntity> imple
return schoolList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findEliteSchool() {
@ -59,11 +82,15 @@ public class SchoolService extends ServiceImpl<SchoolMapper, SchoolEntity> imple
return schoolList;
}
/**
* ID
* @param areaId ID
* @return
*/
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findSchoolByAreaId(String areaId) {
return schoolMapper.selectList(Condition.create().in("area_id", Arrays.asList(areaId.split(","))));
}
}

@ -19,14 +19,29 @@ import com.tamguo.modules.tiku.model.condition.SubjectCondition;
import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum;
import com.tamguo.modules.tiku.service.ISubjectService;
/**
* SubjectServiceImpl ISubjectService
*/
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity> implements ISubjectService {
/**
* SubjectMapper
*/
@Autowired
private SubjectMapper subjectMapper;
/**
* CourseMapper
*/
@Autowired
private CourseMapper courseMapper;
/**
*
* @param condition
* @return
*/
@Transactional(readOnly = false)
@SuppressWarnings("unchecked")
@Override
@ -44,6 +59,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
return page.setRecords(subjectMapper.selectPage(page, query));
}
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void save(SubjectEntity subject) {
@ -51,6 +70,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.insert(subject);
}
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void update(SubjectEntity subject) {
@ -64,6 +87,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void enable(String uid) {
@ -72,6 +99,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void disabled(String uid) {
@ -80,6 +111,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void delete(String uid) {
@ -88,6 +123,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @return JSON
*/
@SuppressWarnings("unchecked")
@Override
public JSONArray getCourseCascaderTree() {
@ -115,6 +154,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
return courseTree;
}
/**
*
* @return JSON
*/
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
@ -130,5 +173,4 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
}
return courseTree;
}
}
Loading…
Cancel
Save