|
|
|
@ -22,97 +22,192 @@ import com.tamguo.util.Result;
|
|
|
|
|
import com.tamguo.util.ShiroUtils;
|
|
|
|
|
import com.tamguo.util.TamguoConstant;
|
|
|
|
|
|
|
|
|
|
// 使用 @Service 注解将这个类标记为Spring中的服务层组件,表明它主要负责处理与试卷(Paper)相关的业务逻辑,
|
|
|
|
|
// Spring会自动扫描并将其纳入到Spring容器管理中,方便在其他地方进行依赖注入等操作,遵循Spring的分层架构设计。
|
|
|
|
|
@Service
|
|
|
|
|
public class PaperService extends ServiceImpl<PaperMapper, PaperEntity> implements IPaperService{
|
|
|
|
|
public class PaperService extends ServiceImpl<PaperMapper, PaperEntity> implements IPaperService {
|
|
|
|
|
|
|
|
|
|
// 通过Spring的依赖注入机制,自动注入 PaperMapper 接口的实现类实例,
|
|
|
|
|
// PaperMapper 是用于定义与试卷实体(PaperEntity)相关的数据库操作方法的接口,比如查询、插入、更新、删除等操作,
|
|
|
|
|
// 在本服务类中会调用它的方法来与数据库进行交互,获取试卷相关的数据信息。
|
|
|
|
|
@Autowired
|
|
|
|
|
private PaperMapper paperMapper;
|
|
|
|
|
|
|
|
|
|
// 同样通过依赖注入注入 CacheService 实例,CacheService 大概率是用于处理缓存相关操作的服务类,
|
|
|
|
|
// 例如从缓存中获取数据、将数据存入缓存以及判断缓存是否存在等功能,在试卷相关业务中用于缓存不同类型的试卷列表数据,
|
|
|
|
|
// 以减少频繁访问数据库获取试卷信息的开销,提高系统性能,优化试卷相关业务操作的响应速度。
|
|
|
|
|
@Autowired
|
|
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
// 通过依赖注入注入 QuestionMapper 接口的实现类实例,QuestionMapper 应该是用于定义与试题相关的数据库操作方法的接口,
|
|
|
|
|
// 在涉及试卷中试题相关的操作(如添加、删除、更新试题信息等)时会调用它的方法来与数据库进行交互。
|
|
|
|
|
@Autowired
|
|
|
|
|
private QuestionMapper questionMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findHistoryPaper 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 findHistoryPaper 方法,用于获取历史试卷信息列表,并结合了缓存机制来优化数据获取性能,避免重复查询数据库。
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findHistoryPaper() {
|
|
|
|
|
// 首先尝试从缓存中获取名为 TamguoConstant.HISTORY_PAPER 的缓存对象,并将其强制转换为 List<PaperEntity> 类型,
|
|
|
|
|
// 期望从缓存中获取到之前存储的历史试卷信息列表,如果缓存命中,就可以直接返回这个缓存中的试卷列表数据,减少数据库查询操作。
|
|
|
|
|
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(TamguoConstant.HISTORY_PAPER);
|
|
|
|
|
if(paperList == null || paperList.isEmpty()){
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1 , 6);
|
|
|
|
|
paperList = paperMapper.findByTypeAndAreaId(TamguoConstant.ZHENGTI_PAPER_ID , TamguoConstant.BEIJING_AREA_ID , page);
|
|
|
|
|
cacheService.setObject(TamguoConstant.ZHENGTI_PAPER_ID, paperList , 2 * 60 * 60);
|
|
|
|
|
// 判断从缓存中获取到的试卷列表是否为 null 或者为空列表(即没有缓存数据或者缓存数据不存在有效的试卷信息),
|
|
|
|
|
// 如果满足这个条件,就需要从数据库中重新获取历史试卷信息列表,并将其存入缓存中供后续使用。
|
|
|
|
|
if (paperList == null || paperList.isEmpty()) {
|
|
|
|
|
// 创建一个 Page 对象,用于分页查询,设置当前页码为 1,每页显示的记录数为 6(这里的分页参数可以根据实际业务需求调整),
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1, 6);
|
|
|
|
|
// 通过注入的 PaperMapper 的 findByTypeAndAreaId 方法,传入特定的试卷类型标识符(TamguoConstant.ZHENGTI_PAPER_ID)和地区标识符(TamguoConstant.BEIJING_AREA_ID)以及分页对象(page),
|
|
|
|
|
// 从数据库中获取符合条件的历史试卷信息列表,这里的具体查询逻辑由 PaperMapper 中对应的方法实现来确定,返回查询到的历史试卷列表赋值给 paperList 变量。
|
|
|
|
|
paperList = paperMapper.findByTypeAndAreaId(TamguoConstant.ZHENGTI_PAPER_ID, TamguoConstant.BEIJING_AREA_ID, page);
|
|
|
|
|
// 将获取到的历史试卷列表存入缓存中,缓存的键名为 TamguoConstant.ZHENGTI_PAPER_ID,同时设置了缓存的有效时间为 2 * 60 * 60 秒(即 2 小时),
|
|
|
|
|
// 这样在接下来的 2 小时内,如果再次调用 findHistoryPaper 方法,就可以直接从缓存中获取历史试卷数据,而不用再次查询数据库了。
|
|
|
|
|
cacheService.setObject(TamguoConstant.ZHENGTI_PAPER_ID, paperList, 2 * 60 * 60);
|
|
|
|
|
}
|
|
|
|
|
// 最后返回获取到的历史试卷信息列表,这个列表可能是从缓存中直接获取的,也可能是从数据库中查询后存入缓存再返回的,
|
|
|
|
|
// 取决于缓存中是否存在有效数据以及之前的逻辑执行情况。
|
|
|
|
|
return paperList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findSimulationPaper 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 findSimulationPaper 方法,用于获取模拟试卷信息列表,同样运用了缓存机制来提升数据获取效率,减少数据库访问次数。
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findSimulationPaper() {
|
|
|
|
|
// 先从缓存中获取名为 TamguoConstant.SIMULATION_PAPER 的缓存对象,并强制转换为 List<PaperEntity> 类型,尝试获取之前缓存的模拟试卷信息列表,
|
|
|
|
|
// 如果缓存中有数据,就直接返回该缓存中的试卷列表数据,避免再次查询数据库。
|
|
|
|
|
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(TamguoConstant.SIMULATION_PAPER);
|
|
|
|
|
if(paperList == null || paperList.isEmpty()){
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1 , 6);
|
|
|
|
|
paperList = paperMapper.findByTypeAndAreaId(TamguoConstant.MONI_PAPER_ID , TamguoConstant.BEIJING_AREA_ID , page);
|
|
|
|
|
cacheService.setObject(TamguoConstant.SIMULATION_PAPER, paperList , 2 * 60 * 60);
|
|
|
|
|
// 判断从缓存中获取到的模拟试卷列表是否为 null 或者为空,如果是这种情况,就需要从数据库中重新获取模拟试卷信息列表并缓存起来供后续使用。
|
|
|
|
|
if (paperList == null || paperList.isEmpty()) {
|
|
|
|
|
// 创建一个 Page 对象用于分页查询,设置当前页码为 1,每页显示记录数为 6,可根据实际情况调整分页参数。
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1, 6);
|
|
|
|
|
// 通过 PaperMapper 的 findByTypeAndAreaId 方法,传入模拟试卷类型标识符(TamguoConstant.MONI_PAPER_ID)和地区标识符(TamguoConstant.BEIJING_AREA_ID)以及分页对象(page),
|
|
|
|
|
// 从数据库中获取符合条件的模拟试卷信息列表,具体查询逻辑由 PaperMapper 中对应方法实现来确定,将查询到的模拟试卷列表赋值给 paperList 变量。
|
|
|
|
|
paperList = paperMapper.findByTypeAndAreaId(TamguoConstant.MONI_PAPER_ID, TamguoConstant.BEIJING_AREA_ID, page);
|
|
|
|
|
// 将获取到的模拟试卷列表存入缓存中,缓存键名为 TamguoConstant.SIMULATION_PAPER,缓存有效时间设置为 2 * 60 * 60 秒(2 小时),
|
|
|
|
|
// 以便后续在有效期内再次调用 findSimulationPaper 方法时,能直接从缓存获取模拟试卷数据,提高获取数据的效率。
|
|
|
|
|
cacheService.setObject(TamguoConstant.SIMULATION_PAPER, paperList, 2 * 60 * 60);
|
|
|
|
|
}
|
|
|
|
|
// 最后返回获取到的模拟试卷信息列表,其来源取决于缓存是否命中以及之前的逻辑执行情况,可能是缓存数据也可能是新从数据库获取后存入缓存再返回的数据。
|
|
|
|
|
return paperList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findHotPaper 方法(第一个重载方法,接收一个 String 类型的 areaId 参数)
|
|
|
|
|
* 实现了 IPaperService 接口中的 findHotPaper 方法(这个方法有多个重载形式,此处是其中之一),用于获取热门试卷信息列表,同样结合了缓存逻辑来优化性能。
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findHotPaper(String areaId) {
|
|
|
|
|
// 首先从缓存中获取名为 TamguoConstant.HOT_PAPER 的缓存对象,并强制转换为 List<PaperEntity> 类型,尝试获取之前缓存的热门试卷信息列表,
|
|
|
|
|
// 这里有个特殊处理,先将获取到的列表赋值为 null,不过通常来说这样的操作不太符合常规逻辑,可能需要确认此处的真实意图是否合理,
|
|
|
|
|
// 暂时按照现有代码逻辑继续分析,后续可能需要优化此处代码。
|
|
|
|
|
List<PaperEntity> paperList = (List<PaperEntity>) cacheService.getObject(TamguoConstant.HOT_PAPER);
|
|
|
|
|
paperList = null;
|
|
|
|
|
if(paperList == null || paperList.isEmpty()){
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1 , 10);
|
|
|
|
|
paperList = paperMapper.findByAreaId(areaId ,page);
|
|
|
|
|
cacheService.setObject(TamguoConstant.HOT_PAPER, paperList , 2 * 60 * 60);
|
|
|
|
|
// 判断热门试卷列表是否为 null 或者为空,如果是这种情况,就需要从数据库中重新获取热门试卷信息列表并缓存起来供后续调用使用。
|
|
|
|
|
if (paperList == null || paperList.isEmpty()) {
|
|
|
|
|
// 创建一个 Page 对象用于分页查询,设置当前页码为 1,每页显示记录数为 10(可根据业务实际情况调整分页参数),
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1, 10);
|
|
|
|
|
// 通过 PaperMapper 的 findByAreaId 方法,传入地区标识符(areaId)和分页对象(page),从数据库中获取该地区的热门试卷信息列表,
|
|
|
|
|
// 具体的热门试卷判定以及查询逻辑由 PaperMapper 中对应的方法实现来确定,将查询到的热门试卷列表赋值给 paperList 变量。
|
|
|
|
|
paperList = paperMapper.findByAreaId(areaId, page);
|
|
|
|
|
// 将构建好的热门试卷列表存入缓存中,缓存键名为 TamguoConstant.HOT_PAPER,缓存有效时间设置为 2 * 60 * 60 秒(2 小时),
|
|
|
|
|
// 这样在后续的 2 小时内,再次调用 findHotPaper 方法时,就可以直接从缓存获取热门试卷数据,提高获取数据的效率,减少数据库查询操作。
|
|
|
|
|
cacheService.setObject(TamguoConstant.HOT_PAPER, paperList, 2 * 60 * 60);
|
|
|
|
|
}
|
|
|
|
|
// 最后返回获取到的热门试卷信息列表,其来源取决于缓存情况以及之前的逻辑执行结果,可能是缓存中的数据,也可能是新从数据库获取后存入缓存再返回的数据。
|
|
|
|
|
return paperList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findList 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 findList 方法,用于根据多个条件(学科 ID、课程 ID、试卷类型、年份、地区以及页码等)查询试卷信息列表,并进行分页处理,
|
|
|
|
|
* 返回包含查询结果的 Page 对象,方便前端进行分页展示等操作。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Page<PaperEntity> findList(String subjectId , String courseId,
|
|
|
|
|
String paperType, String year, String area , Integer pageNum) {
|
|
|
|
|
Page<PaperEntity> page = new Page<>(pageNum , TamguoConstant.DEFAULT_PAGE_SIZE);
|
|
|
|
|
if("0".equals(courseId)) {
|
|
|
|
|
public Page<PaperEntity> findList(String subjectId, String courseId,
|
|
|
|
|
String paperType, String year, String area, Integer pageNum) {
|
|
|
|
|
// 创建一个 Page 对象用于分页查询,设置当前页码为传入的 pageNum 参数值,每页显示的记录数为 TamguoConstant.DEFAULT_PAGE_SIZE(这应该是预定义的每页默认显示记录数常量),
|
|
|
|
|
Page<PaperEntity> page = new Page<>(pageNum, TamguoConstant.DEFAULT_PAGE_SIZE);
|
|
|
|
|
// 判断课程 ID 是否为 "0",如果是,将其设置为空字符串,可能是表示不根据课程 ID 进行筛选的情况,具体业务含义取决于项目设计。
|
|
|
|
|
if ("0".equals(courseId)) {
|
|
|
|
|
courseId = "";
|
|
|
|
|
}
|
|
|
|
|
if("0".equals(paperType)) {
|
|
|
|
|
// 类似地,判断试卷类型是否为 "0",如果是,将其设置为空字符串,意味着不依据试卷类型进行筛选,具体根据业务逻辑来确定这样处理的意义。
|
|
|
|
|
if ("0".equals(paperType)) {
|
|
|
|
|
paperType = "";
|
|
|
|
|
}
|
|
|
|
|
if("0".equals(year)) {
|
|
|
|
|
// 判断年份是否为 "0",若是则设置为空字符串,可能表示不按照年份来筛选试卷,同样取决于业务中对年份筛选的具体规则。
|
|
|
|
|
if ("0".equals(year)) {
|
|
|
|
|
year = "";
|
|
|
|
|
}
|
|
|
|
|
if("0".equals(area)) {
|
|
|
|
|
// 判断地区是否为 "0",若是则设置为空字符串,即不通过地区来筛选试卷,这与业务中地区作为筛选条件的具体定义相关。
|
|
|
|
|
if ("0".equals(area)) {
|
|
|
|
|
area = "";
|
|
|
|
|
}
|
|
|
|
|
return page.setRecords(paperMapper.findList(subjectId , courseId , paperType , year , area , page));
|
|
|
|
|
// 通过 PaperMapper 的 findList 方法,传入学科 ID、处理后的课程 ID、试卷类型、年份、地区以及分页对象(page)这些参数,
|
|
|
|
|
// 从数据库中获取符合条件的试卷信息列表,并将结果设置到 Page 对象中(通过 page.setRecords 方法),最后返回这个包含查询结果的 Page 对象,
|
|
|
|
|
// 方便后续进行分页相关的业务操作,如在前端展示分页后的试卷列表等。
|
|
|
|
|
return page.setRecords(paperMapper.findList(subjectId, courseId, paperType, year, area, page));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* find 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 find 方法,用于根据试卷的唯一标识符(paperId)从数据库中查询并获取对应的试卷实体信息,
|
|
|
|
|
// 直接调用了 PaperMapper 的 selectById 方法,传入试卷 UID 参数(paperId),由 PaperMapper 具体实现与数据库的交互查询操作,返回查询到的试卷实体对象。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public PaperEntity find(String paperId) {
|
|
|
|
|
return paperMapper.selectById(paperId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findPaperByAreaId 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 findPaperByAreaId 方法,用于根据地区 ID 和试卷类型获取相应的试卷信息列表,
|
|
|
|
|
// 根据传入的 type 参数值判断不同的情况,如果 type 参数值为 "n",则调用本类中的 findHotPaper 方法(传入 areaId 参数)获取热门试卷信息列表并返回;
|
|
|
|
|
// 如果不是 "n",则创建一个 Page 对象用于分页查询(设置当前页码为 1,每页显示记录数为 8),然后通过 PaperMapper 的 findPaperByAreaId 方法,传入地区 ID、试卷类型以及分页对象,
|
|
|
|
|
// 从数据库中获取符合条件的试卷信息列表并返回,具体的查询逻辑由 PaperMapper 中对应的方法实现来确定。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findPaperByAreaId(String areaId , String type) {
|
|
|
|
|
if("n".equals(type)){
|
|
|
|
|
public List<PaperEntity> findPaperByAreaId(String areaId, String type) {
|
|
|
|
|
if ("n".equals(type)) {
|
|
|
|
|
return this.findHotPaper(areaId);
|
|
|
|
|
}
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1 , 8);
|
|
|
|
|
return paperMapper.findPaperByAreaId(areaId , type , page);
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1, 8);
|
|
|
|
|
return paperMapper.findPaperByAreaId(areaId, type, page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getPaperTotal 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 getPaperTotal 方法,用于获取试卷的总数量,
|
|
|
|
|
// 直接调用了 PaperMapper 的 getPaperTotal 方法,由 PaperMapper 具体实现查询数据库中试卷总记录数的逻辑,返回查询到的试卷总数量(类型为 Long)。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Long getPaperTotal() {
|
|
|
|
|
return paperMapper.getPaperTotal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* findByCreaterId 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 findByCreaterId 方法,用于根据创建者的唯一标识符(createrId)从数据库中查询并获取该创建者创建的试卷信息列表,
|
|
|
|
|
// 直接调用了 PaperMapper 的 findByCreaterId 方法,传入创建者 ID 参数(createrId),由 PaperMapper 具体实现与数据库的交互查询操作,返回查询到的试卷列表。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findByCreaterId(String createrId) {
|
|
|
|
|
return paperMapper.findByCreaterId(createrId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
/**
|
|
|
|
|
* updatePaperName 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 updatePaperName 方法,用于更新试卷的名称,
|
|
|
|
|
// 首先通过 PaperMapper 的 selectById 方法根据传入的试卷 ID(paperId)从数据库中查询获取对应的试卷实体,
|
|
|
|
|
// 然后将试卷实体的名称属性(name)设置为传入的新名称(name),最后通过 PaperMapper 的 updateById 方法将更新后的试卷实体信息更新到数据库中,完成试卷名称的修改操作。
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
|
|
@Override
|
|
|
|
|
public void updatePaperName(String paperId, String name) {
|
|
|
|
|
PaperEntity paper = paperMapper.selectById(paperId);
|
|
|
|
@ -120,122 +215,15 @@ public class PaperService extends ServiceImpl<PaperMapper, PaperEntity> implemen
|
|
|
|
|
paperMapper.updateById(paper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* deletePaper 方法
|
|
|
|
|
* 实现了 IPaperService 接口中的 deletePaper 方法,用于删除试卷以及与之相关的试题信息,被标记为可读写事务(通过 @Transactional(readOnly = false) 注解指定),
|
|
|
|
|
// 因为涉及到对数据库中试卷和试题数据的删除操作,需要保证事务的完整性,要么全部操作成功,要么全部回滚。
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public Result deletePaper(String paperId) {
|
|
|
|
|
// 首先通过 PaperMapper 的 selectById 方法根据传入的试卷 ID(paperId)从数据库中查询获取对应的试卷实体,
|
|
|
|
|
PaperEntity paper = paperMapper.selectById(paperId);
|
|
|
|
|
if(!ShiroUtils.getUserId().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 , "删除成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
@Override
|
|
|
|
|
public void addPaperQuestionInfo(String paperId, String title,
|
|
|
|
|
String name, String type) {
|
|
|
|
|
PaperEntity paper = paperMapper.selectById(paperId);
|
|
|
|
|
String questionInfo = paper.getQuestionInfo();
|
|
|
|
|
|
|
|
|
|
JSONArray qList = JSONArray.parseArray(questionInfo);
|
|
|
|
|
JSONObject entity = new JSONObject();
|
|
|
|
|
entity.put("name", name);
|
|
|
|
|
entity.put("title", title);
|
|
|
|
|
entity.put("type", type);
|
|
|
|
|
entity.put("uid", UUID.randomUUID().toString());
|
|
|
|
|
qList.add(entity);
|
|
|
|
|
|
|
|
|
|
paper.setQuestionInfo(qList.toString());
|
|
|
|
|
paperMapper.updateById(paper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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++){
|
|
|
|
|
JSONObject q = qList.getJSONObject(i);
|
|
|
|
|
if(q.getString("uid").equals(uid)){
|
|
|
|
|
q.put("name", name);
|
|
|
|
|
q.put("title", title);
|
|
|
|
|
q.put("type", type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paper.setQuestionInfo(qList.toString());
|
|
|
|
|
paperMapper.updateById(paper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Result deletePaperQuestionInfoBtn(String paperId, String uid) {
|
|
|
|
|
PaperEntity paper = paperMapper.selectById(paperId);
|
|
|
|
|
if(!paper.getCreaterId().equals(ShiroUtils.getMember().getUid())) {
|
|
|
|
|
return Result.failResult("试卷属于当前用户,不能修改!");
|
|
|
|
|
}
|
|
|
|
|
JSONArray qList = JSONArray.parseArray(paper.getQuestionInfo());
|
|
|
|
|
for(int i =0 ; i<qList.size() ; i++){
|
|
|
|
|
JSONObject q = qList.getJSONObject(i);
|
|
|
|
|
if(q.getString("uid").equals(uid)){
|
|
|
|
|
qList.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
paper.setQuestionInfo(qList.toString());
|
|
|
|
|
paperMapper.updateById(paper);
|
|
|
|
|
return Result.result(Result.SUCCESS_CODE, null, "删除子卷成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Page<PaperEntity> memberPaperList(String name , String memberId , Page<PaperEntity> page) {
|
|
|
|
|
if(!StringUtils.isEmpty(name)){
|
|
|
|
|
name = "%" + name + "%";
|
|
|
|
|
}
|
|
|
|
|
return page.setRecords(paperMapper.queryPageByNameAndCreatorId(name , memberId , page));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
@Override
|
|
|
|
|
public void addPaper(PaperEntity paper) {
|
|
|
|
|
paper.setDownHits(0);
|
|
|
|
|
paper.setOpenHits(0);
|
|
|
|
|
paper.setQuestionInfo("[]");
|
|
|
|
|
|
|
|
|
|
// 写入seo信息
|
|
|
|
|
paper.setSeoTitle(paper.getName());
|
|
|
|
|
paper.setSeoKeywords(paper.getName());
|
|
|
|
|
paper.setSeoDescription(paper.getName());
|
|
|
|
|
paperMapper.insert(paper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=true)
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> featuredPaper(String type, String subjectId) {
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1,8);
|
|
|
|
|
return paperMapper.featuredPaper(type , subjectId , page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=true)
|
|
|
|
|
@Override
|
|
|
|
|
public List<PaperEntity> findHotPaper(String subjectId, String courseId) {
|
|
|
|
|
Page<PaperEntity> page = new Page<>(1,5);
|
|
|
|
|
return paperMapper.findHotPaper(subjectId , courseId , page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
@Override
|
|
|
|
|
public Result updatePaper(PaperEntity paper) {
|
|
|
|
|
PaperEntity entity = paperMapper.selectById(paper.getUid());
|
|
|
|
|
if(!entity.getCreaterId().equals(ShiroUtils.getMember().getUid())) {
|
|
|
|
|
return Result.failResult("试卷属于当前用户,不能修改!");
|
|
|
|
|
}
|
|
|
|
|
paper.setCreaterId(ShiroUtils.getUserId());
|
|
|
|
|
paperMapper.updateById(paper);
|
|
|
|
|
return Result.result(Result.SUCCESS_CODE, paper, "修改成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 通过 ShiroUtils 获取当前用户的 ID,并与试卷的创建者 ID 进行比对,如果当前用户不是试卷的创建者,
|
|
|
|
|
//
|