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,54 +1,103 @@
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;
QuestionTypeEnum(final String value, final String desc) {
this.value = value;
this.desc = desc;
}
public static QuestionTypeEnum getQuestionType(String value) {
if("1".equals(value)) {
return DANXUANTI;
}else if("2".equals(value)) {
return DUOXUANTI;
}else if("3".equals(value)) {
return TIANKONGTI;
}else if("4".equals(value)) {
return PANDUANTI;
}else if("5".equals(value)) {
return WENDATI;
}
return WENDATI;
}
public Serializable getValue() {
return this.value;
}
public String getDesc(){
return this.desc;
}
@Override
public String toString() {
return this.value;
}
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;
} else if ("2".equals(value)) {
return DUOXUANTI;
} else if ("3".equals(value)) {
return TIANKONGTI;
} else if ("4".equals(value)) {
return PANDUANTI;
} else if ("5".equals(value)) {
return WENDATI;
}
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,79 +1,93 @@
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
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity> implements IChapterService{
@Autowired
ChapterMapper chapterMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
KnowPointMapper bookMapper;
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
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 实例
private ChapterMapper chapterMapper;
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@Autowired // 自动注入 KnowPointMapper 实例
private KnowPointMapper bookMapper;
/**
*
*
* @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++){
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity chapter = chapterList.get(i);
if(chapter.getParentCode().equals(SystemConstant.CHAPTER_DEFAULT_ROOT_UID)){
if (chapter.getParentCode().equals(SystemConstant.CHAPTER_DEFAULT_ROOT_UID)) {
rootUid = chapter.getId();
}
}
// 获取第一层结构
List<ChapterEntity> entitys = new ArrayList<>();
for(int i=0 ; i<chapterList.size() ; i++){
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity chapter = chapterList.get(i);
if(rootUid.equals(chapter.getParentCode())){
if (rootUid.equals(chapter.getParentCode())) {
entitys.add(chapter);
}
}
for(int i=0 ; i<entitys.size() ; i++){
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++){
for (int k = 0; k < chapterList.size(); k++) {
ChapterEntity chapter = chapterList.get(k);
if(entity.getId().equals(chapter.getParentCode())){
if (entity.getId().equals(chapter.getParentCode())) {
childs.add(chapter);
}
}
entity.setChildChapterList(childs);
}
for(int i=0 ; i<entitys.size() ; i++){
for (int i = 0; i < entitys.size(); i++) {
List<ChapterEntity> childs = entitys.get(i).getChildChapterList();
for(int k=0 ; k<childs.size() ; k++){
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++){
for (int n = 0; n < chapterList.size(); n++) {
ChapterEntity chapter = chapterList.get(n);
if(child.getId().equals(chapter.getParentCode())){
if (child.getId().equals(chapter.getParentCode())) {
tmpChilds.add(chapter);
}
}
@ -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();
if(!StringUtils.isEmpty(condition.getParentCode())) {
query.eq("parent_code", condition.getParentCode());
}else {
query.eq("tree_level", "0");
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getParentCode())) {
query.eq("parent_code", condition.getParentCode()); // 添加父章节代码条件
} else {
query.eq("tree_level", "0"); // 添加树级别为 0 的条件(即根章节)
}
if(!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId()); // 添加章节 ID 条件
}
if(!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName());
if (!StringUtils.isEmpty(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());;
if (!StringUtils.isEmpty(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();
for(int i=0 ; i<chapterList.size() ; i++) {
JSONObject node = new JSONObject();
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);
if (chapterList!= null) {
JSONArray nodes = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < chapterList.size(); i++) {
JSONObject node = new JSONObject(); // 创建 JSON 对象
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,9 +197,9 @@ 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++) {
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity child = chapterList.get(i);
String subParentCodes = child.getParentCodes().substring(child.getParentCodes().indexOf(entity.getId()) + entity.getId().length() + 1);
@ -181,40 +210,64 @@ 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++) {
for (int i = 0; i < childs.size(); i++) {
ChapterEntity child = childs.get(i);
child.setStatus(ChapterStatusEnum.DELETE);
chapterMapper.updateById(child);
}
}
@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;
if (bookList.size() == 0) {
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);
public ChapterEntity selectNextChapter(String parentCode, String 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
public class CourseServiceImpl extends ServiceImpl<CourseMapper, CourseEntity> implements ICourseService{
@Autowired
public CourseMapper courseMapper;
@Autowired
public SubjectMapper subjectMapper;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true)
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 // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@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();
if(!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
Page<CourseEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId()); // 添加课程 ID 条件
}
if(!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName());
if (!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName()); // 添加课程名称模糊匹配条件
}
if(!StringUtils.isEmpty(condition.getSubjectId())) {
query.eq("subject_id", condition.getSubjectId());
if (!StringUtils.isEmpty(condition.getSubjectId())) {
query.eq("subject_id", condition.getSubjectId()); // 添加科目 ID 条件
}
if(!StringUtils.isEmpty(condition.getStatus())) {
query.eq("status", condition.getStatus());
if (!StringUtils.isEmpty(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 数组
}
private JSONArray transform(List<SubjectEntity> subjectList , List<CourseEntity> courseList) {
JSONArray entitys = new JSONArray();
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);
}
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);
/**
* ZTree JSON
*
* @param subjectList
* @param courseList
* @return ZTree JSON
*/
private JSONArray transform(List<SubjectEntity> subjectList, List<CourseEntity> courseList) {
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
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 数组中
}
return entitys;
}
for (int i = 0; i < courseList.size(); i++) {
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
public class KnowPointServiceImpl extends ServiceImpl<KnowPointMapper, KnowPointEntity> implements IKnowPointService{
@Autowired
KnowPointMapper knowPointMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
SubjectMapper subjectMapper;
@Transactional(readOnly=false)
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 实例
private KnowPointMapper knowPointMapper;
@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 数组
}
private JSONArray transform(List<SubjectEntity> subjectList , List<CourseEntity> courseList , List<KnowPointEntity> bookList) {
JSONArray entitys = new JSONArray();
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);
/**
* 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(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
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);
for (int i = 0; i < courseList.size(); i++) {
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);
for (int i = 0; i < bookList.size(); i++) {
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,100 +14,136 @@ 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{
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() {
List<MenuEntity> menuList = ((List<MenuEntity>) cacheService.getObject(SystemConstant.INDEX_MENU));
if (menuList == null) {
menuList = menuMapper.selectList(Condition.create().eq("parent_id", 1).eq("is_show", 1).orderDesc(Arrays.asList("orders")));
for(MenuEntity menu : menuList){
for (MenuEntity menu : menuList) {
List<MenuEntity> childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders")));
menu.setChildSubjects(childSubjects);
}
cacheService.setObject(SystemConstant.INDEX_MENU, menuList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.INDEX_MENU, menuList, 2 * 60 * 60);
}
return menuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findAllMenus() {
List<MenuEntity> allMenuList = ((List<MenuEntity>) cacheService.getObject(SystemConstant.ALL_INDEX_MENU));
if(allMenuList == null){
if (allMenuList == null) {
allMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 1).orderDesc(Arrays.asList("orders")));
for(MenuEntity menu : allMenuList){
for (MenuEntity menu : allMenuList) {
List<MenuEntity> childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders")));
menu.setChildSubjects(childSubjects);
}
cacheService.setObject(SystemConstant.ALL_INDEX_MENU, allMenuList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.ALL_INDEX_MENU, allMenuList, 2 * 60 * 60);
}
return allMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findLeftMenus() {
List<MenuEntity> leftMenuList = ((List<MenuEntity>) cacheService.getObject(SystemConstant.LEFT_INDEX_MENU));
if(leftMenuList == null){
if (leftMenuList == null) {
leftMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 2).orderDesc(Arrays.asList("orders")));
for(MenuEntity menu : leftMenuList){
for (MenuEntity menu : leftMenuList) {
List<MenuEntity> childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders")));
menu.setChildSubjects(childSubjects);
}
cacheService.setObject(SystemConstant.LEFT_INDEX_MENU, leftMenuList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.LEFT_INDEX_MENU, leftMenuList, 2 * 60 * 60);
}
return leftMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findChapterMenus() {
List<MenuEntity> chapterMenuList = ((List<MenuEntity>) cacheService.getObject(SystemConstant.CHAPTER_INDEX_MENU));
if(chapterMenuList == null){
if (chapterMenuList == null) {
chapterMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 4).orderAsc(Arrays.asList("orders")));
for(MenuEntity menu : chapterMenuList){
for (MenuEntity menu : chapterMenuList) {
List<MenuEntity> childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders")));
menu.setChildSubjects(childSubjects);
}
cacheService.setObject(SystemConstant.CHAPTER_INDEX_MENU, chapterMenuList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.CHAPTER_INDEX_MENU, chapterMenuList, 2 * 60 * 60);
}
return chapterMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findFooterMenus() {
List<MenuEntity> footerMenuList = ((List<MenuEntity>) cacheService.getObject(SystemConstant.FOOTER_INDEX_MENU));
if(footerMenuList == null){
if (footerMenuList == null) {
footerMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 3).orderDesc(Arrays.asList("orders")));
for(MenuEntity menu : footerMenuList){
for (MenuEntity menu : footerMenuList) {
List<MenuEntity> childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders")));
menu.setChildSubjects(childSubjects);
}
cacheService.setObject(SystemConstant.FOOTER_INDEX_MENU, footerMenuList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.FOOTER_INDEX_MENU, footerMenuList, 2 * 60 * 60);
}
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,79 +27,129 @@ 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{
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() {
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(SystemConstant.HISTORY_PAPER);
if(paperList == null){
Page<PaperEntity> page = new Page<>(1 , 6);
if (paperList == null) {
Page<PaperEntity> page = new Page<>(1, 6);
paperList = paperMapper.selectPage(page, Condition.create().eq("type", SystemConstant.ZHENGTI_PAPER_ID).orderDesc(Arrays.asList("id")));
for(int i=0 ; i<paperList.size() ; i++) {
for (int i = 0; i < paperList.size(); i++) {
PaperEntity paper = paperList.get(i);
paper.setSubjectName(iSubjectService.selectById(paper.getSubjectId()).getName());
paper.setCourseName(iCourseService.selectById(paper.getCourseId()).getName());
paper.setAreaName(iSysAreaService.selectById(paper.getAreaId()).getAreaName());
}
cacheService.setObject(SystemConstant.HISTORY_PAPER, paperList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.HISTORY_PAPER, paperList, 2 * 60 * 60);
}
return paperList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findSimulationPaper() {
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(SystemConstant.SIMULATION_PAPER);
if(paperList == null){
Page<PaperEntity> page = new Page<>(1 , 6);
if (paperList == null) {
Page<PaperEntity> page = new Page<>(1, 6);
paperList = paperMapper.selectPage(page, Condition.create().eq("type", SystemConstant.MONI_PAPER_ID).orderDesc(Arrays.asList("id")));
for(int i=0 ; i<paperList.size() ; i++) {
for (int i = 0; i < paperList.size(); i++) {
PaperEntity paper = paperList.get(i);
paper.setSubjectName(iSubjectService.selectById(paper.getSubjectId()).getName());
paper.setCourseName(iCourseService.selectById(paper.getCourseId()).getName());
paper.setAreaName(iSysAreaService.selectById(paper.getAreaId()).getAreaName());
}
cacheService.setObject(SystemConstant.SIMULATION_PAPER, paperList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.SIMULATION_PAPER, paperList, 2 * 60 * 60);
}
return paperList;
}
/**
*
* @param areaId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findHotPaper(String areaId) {
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(SystemConstant.HOT_PAPER);
if(paperList == null){
Page<PaperEntity> page = new Page<>(1 , 10);
if (paperList == null) {
Page<PaperEntity> page = new Page<>(1, 10);
paperList = paperMapper.selectPage(page, Condition.create().orderDesc(Arrays.asList("id")));
for(int i=0 ; i<paperList.size() ; i++) {
for (int i = 0; i < paperList.size(); i++) {
PaperEntity paper = paperList.get(i);
paper.setSubjectName(iSubjectService.selectById(paper.getSubjectId()).getName());
paper.setCourseName(iCourseService.selectById(paper.getCourseId()).getName());
paper.setAreaName(iSysAreaService.selectById(paper.getAreaId()).getAreaName());
}
cacheService.setObject(SystemConstant.HOT_PAPER, paperList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.HOT_PAPER, paperList, 2 * 60 * 60);
}
return paperList;
}
@Transactional(readOnly=false)
/**
*
* @param paperId ID
* @param title
* @param name
* @param type
*/
@Transactional(readOnly = false)
@Override
public void addPaperQuestionInfo(String paperId, String title, String name, String type) {
PaperEntity paper = paperMapper.selectById(paperId);
@ -117,14 +167,22 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.updateById(paper);
}
@Transactional(readOnly=false)
/**
*
* @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) {
PaperEntity paper = paperMapper.selectById(paperId);
JSONArray qList = JSONArray.parseArray(paper.getQuestionInfo());
for(int i =0 ; i<qList.size() ; i++){
for (int i = 0; i < qList.size(); i++) {
JSONObject q = qList.getJSONObject(i);
if(q.getString("id").equals(uid)){
if (q.getString("id").equals(uid)) {
q.put("name", name);
q.put("title", title);
q.put("type", type);
@ -135,30 +193,43 @@ 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 , "不能删除其他人的试卷!");
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "不能删除其他人的试卷!");
}
paperMapper.deleteById(paperId);
// 删除试题
questionMapper.delete(Condition.create().eq("paper_id", paperId));
return Result.result(Result.SUCCESS_CODE, null , "删除成功!");
return Result.result(Result.SUCCESS_CODE, null, "删除成功!");
}
@Transactional(readOnly=false)
/**
*
* @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)) {
if (!paper.getCreaterId().equals(currMemberId)) {
return Result.failResult("试卷属于当前用户,不能修改!");
}
JSONArray qList = JSONArray.parseArray(paper.getQuestionInfo());
for(int i =0 ; i<qList.size() ; i++){
for (int i = 0; i < qList.size(); i++) {
JSONObject q = qList.getJSONObject(i);
if(q.getString("uid").equals(cuid)){
if (q.getString("uid").equals(cuid)) {
qList.remove(i);
}
}
@ -167,24 +238,34 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, null, "删除子卷成功");
}
@Transactional(readOnly=false)
/**
*
* @param paper
*/
@Transactional(readOnly = false)
@Override
public void addPaper(PaperEntity paper) {
paper.setDownHits(0);
paper.setOpenHits(0);
paper.setQuestionInfo("[]");
// 写入seo信息
// 写入 seo 信息
paper.setSeoTitle(paper.getName());
paper.setSeoKeywords(paper.getName());
paper.setSeoDescription(paper.getName());
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)) {
if (!entity.getCreaterId().equals(currMemberId)) {
return Result.failResult("试卷属于当前用户,不能修改!");
}
paper.setCreaterId(currMemberId);
@ -192,15 +273,19 @@ 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) {
// 查询选项信息
List<QuestionEntity> questionList = questionMapper.selectList(Condition.create().eq("paper_id", paperId));
questionList.forEach(question -> {
List<QuestionOptionsEntity> questionOptions = questionOptionsMapper.selectList(Condition.create().eq("question_id" , question.getId()));
List<QuestionOptionsEntity> questionOptions = questionOptionsMapper.selectList(Condition.create().eq("question_id", question.getId()));
question.setQuestionOptions(questionOptions);
});
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{
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) {
public Result addQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
if(!currMemberId.equals(paper.getCreaterId())) {
// 判断当前登录会员的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) {
if(!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) {
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();
if(!StringUtils.isEmpty(questionType)) {
// 判断题目类型是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定题目类型的题目与数据库题目表中的题目类型字段进行精确匹配查询。
if (!StringUtils.isEmpty(questionType)) {
condition.eq("question_type", questionType);
}
if(!StringUtils.isEmpty(id)) {
// 判断题目ID是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定ID的题目与数据库题目表中的题目ID字段进行精确匹配查询用于精确查找特定题目。
if (!StringUtils.isEmpty(id)) {
condition.eq("id", id);
}
if(!StringUtils.isEmpty(content)) {
// 判断题目内容是否不为空字符串如果不为空则添加一个模糊匹配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));
}
@Transactional(readOnly=false)
/**
*
* ID
* QuestionMapperID
* 使
*
* @param question ID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result updateQuestion(QuestionEntity question , String currMemberId) {
public Result updateQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
if(!currMemberId.equals(paper.getCreaterId())) {
// 判断当前登录会员的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, "修改成功!");
}
@Transactional(readOnly=false)
/**
*
* IDID
* QuestionMapperID
* 使
*
* @param uid IDID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result delete(String uid , String currMemberId) {
public Result delete(String uid, String currMemberId) {
// 根据传入的题目ID通过QuestionMapper从数据库中查询对应的题目实体信息用于获取该题目所属试卷的ID以便后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
QuestionEntity question = questionMapper.selectById(uid);
// 根据题目所属试卷的ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
if(!currMemberId.equals(paper.getCreaterId())) {
// 判断当前登录会员的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,51 +19,78 @@ 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) {
List<SchoolEntity> schoolList = (List<SchoolEntity>) cacheService.getObject(SystemConstant.ELITE_SCHOOL_PAPER);
// 获取名校试卷
if(schoolList == null){
Page<SchoolEntity> page = new Page<>(1 , 3);
if (schoolList == null) {
Page<SchoolEntity> page = new Page<>(1, 3);
schoolList = schoolMapper.selectPage(page, Condition.create().eq("id", shcoolId));
for(SchoolEntity school : schoolList){
Page<PaperEntity> p = new Page<>(1 , 3);
for (SchoolEntity school : schoolList) {
Page<PaperEntity> p = new Page<>(1, 3);
List<PaperEntity> paperList = paperMapper.selectPage(p, Condition.create().eq("school_id", school.getId()));
school.setPaperList(paperList);
}
cacheService.setObject(SystemConstant.ELITE_SCHOOL_PAPER, schoolList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.ELITE_SCHOOL_PAPER, schoolList, 2 * 60 * 60);
}
return schoolList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findEliteSchool() {
List<SchoolEntity> schoolList = (List<SchoolEntity>) cacheService.getObject(SystemConstant.ELITE_PAPER);
if(schoolList == null){
RowBounds row = new RowBounds(1 , 6);
if (schoolList == null) {
RowBounds row = new RowBounds(1, 6);
schoolList = schoolMapper.selectPage(row, Condition.EMPTY);
cacheService.setObject(SystemConstant.ELITE_PAPER, schoolList , 2 * 60 * 60);
cacheService.setObject(SystemConstant.ELITE_PAPER, schoolList, 2 * 60 * 60);
}
return schoolList;
}
@Transactional(readOnly=true)
/**
* 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,39 +19,62 @@ 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{
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity> implements ISubjectService {
/**
* SubjectMapper
*/
@Autowired
private SubjectMapper subjectMapper;
/**
* CourseMapper
*/
@Autowired
private CourseMapper courseMapper;
@Transactional(readOnly=false)
/**
*
* @param condition
* @return
*/
@Transactional(readOnly = false)
@SuppressWarnings("unchecked")
@Override
public Page<SubjectEntity> listData(SubjectCondition condition) {
Page<SubjectEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize());
Condition query = Condition.create();
if(!StringUtils.isEmpty(condition.getUid())) {
if (!StringUtils.isEmpty(condition.getUid())) {
query.eq("uid", condition.getUid());
}else if(!StringUtils.isEmpty(condition.getName())) {
} else if (!StringUtils.isEmpty(condition.getName())) {
query.eq("name", condition.getName());
}else if(!StringUtils.isEmpty(condition.getStatus())) {
} else if (!StringUtils.isEmpty(condition.getStatus())) {
query.eq("status", condition.getStatus());
}
query.ne("status", SubjectStatusEnum.DELETE.getValue());
return page.setRecords(subjectMapper.selectPage(page, query));
}
@Transactional(readOnly=false)
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void save(SubjectEntity subject) {
subject.setStatus(SubjectStatusEnum.NORMAL);
subjectMapper.insert(subject);
}
@Transactional(readOnly=false)
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void update(SubjectEntity subject) {
SubjectEntity entity = subjectMapper.selectById(subject.getId());
@ -64,7 +87,11 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
@Transactional(readOnly=false)
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void enable(String uid) {
SubjectEntity entity = subjectMapper.selectById(uid);
@ -72,7 +99,11 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
@Transactional(readOnly=false)
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void disabled(String uid) {
SubjectEntity entity = subjectMapper.selectById(uid);
@ -80,7 +111,11 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
@Transactional(readOnly=false)
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void delete(String uid) {
SubjectEntity entity = subjectMapper.selectById(uid);
@ -88,12 +123,16 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @return JSON
*/
@SuppressWarnings("unchecked")
@Override
public JSONArray getCourseCascaderTree() {
JSONArray courseTree = new JSONArray();
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.EMPTY);
for(int i=0 ; i<subjectList.size() ; i++){
for (int i = 0; i < subjectList.size(); i++) {
SubjectEntity subject = subjectList.get(i);
JSONObject node = new JSONObject();
node.put("value", subject.getId());
@ -101,7 +140,7 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
JSONArray children = new JSONArray();
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("subject_id", subject.getId()));
for(int k=0 ; k<courseList.size() ; k++){
for (int k = 0; k < courseList.size(); k++) {
CourseEntity course = courseList.get(k);
JSONObject no = new JSONObject();
@ -115,13 +154,17 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
return courseTree;
}
@Transactional(readOnly=true)
/**
*
* @return JSON
*/
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public JSONArray getSubjectTree() {
JSONArray courseTree = new JSONArray();
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.EMPTY);
for(int i=0 ; i<subjectList.size() ; i++){
for (int i = 0; i < subjectList.size(); i++) {
SubjectEntity subject = subjectList.get(i);
JSONObject node = new JSONObject();
node.put("value", subject.getId());
@ -130,5 +173,4 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
}
return courseTree;
}
}
Loading…
Cancel
Save