ApplyTaskServiceImpl.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.qmth.exam.reserve.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.util.StringUtils;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.baomidou.mybatisplus.core.metadata.IPage;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.qmth.boot.core.collection.PageResult;
  12. import com.qmth.boot.core.exception.StatusException;
  13. import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
  14. import com.qmth.exam.reserve.bean.login.LoginUser;
  15. import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
  16. import com.qmth.exam.reserve.bean.task.ApplyTaskReq;
  17. import com.qmth.exam.reserve.bean.task.ApplyTaskRuleVO;
  18. import com.qmth.exam.reserve.bean.task.ApplyTaskVO;
  19. import com.qmth.exam.reserve.dao.ApplyTaskDao;
  20. import com.qmth.exam.reserve.entity.ApplyTaskEntity;
  21. import com.qmth.exam.reserve.service.ApplyTaskService;
  22. import com.qmth.exam.reserve.util.PageUtil;
  23. @Service
  24. public class ApplyTaskServiceImpl extends ServiceImpl<ApplyTaskDao, ApplyTaskEntity> implements ApplyTaskService {
  25. @Override
  26. public PageResult<ApplyTaskVO> page(ApplyTaskReq req) {
  27. IPage<ApplyTaskVO> iPage = this.baseMapper.page(new Page<ApplyTaskVO>(req.getPageNumber(), req.getPageSize()),
  28. req);
  29. return PageUtil.of(iPage);
  30. }
  31. @Override
  32. public ApplyTaskRuleVO find(Long id) {
  33. ApplyTaskRuleVO task = this.baseMapper.find(id);
  34. if (StringUtils.isEmpty(task)) {
  35. throw new StatusException("预约任务不存在!");
  36. }
  37. task.setTimeList(this.baseMapper.getTimePeriodList(id));
  38. return task;
  39. }
  40. @Override
  41. public void ruleSave(ApplyTaskReq req, LoginUser user) {
  42. checkRule(req);
  43. ApplyTaskEntity task = new ApplyTaskEntity();
  44. task.setId(req.getId());
  45. task.setName(req.getName());
  46. task.setAllowApplyDays(req.getAllowApplyDays());
  47. task.setAllowApplyCancelDays(req.getAllowApplyCancelDays());
  48. task.setSelfApplyStartTime(req.getSelfApplyStartTime());
  49. task.setSelfApplyEndTime(req.getSelfApplyEndTime());
  50. task.setOpenApplyStartTime(req.getOpenApplyStartTime());
  51. task.setOpenApplyEndTime(req.getOpenApplyEndTime());
  52. task.setEnable(Boolean.FALSE);
  53. task.setOrgId(user.getOrgId());
  54. this.saveOrUpdate(task);
  55. }
  56. private void checkRule(ApplyTaskReq req) {
  57. if (StringUtils.isEmpty(req.getName()))
  58. throw new StatusException("请填写任务名称");
  59. if (StringUtils.isEmpty(req.getAllowApplyDays()))
  60. throw new StatusException("请填写禁止考生预约的天数");
  61. if (StringUtils.isEmpty(req.getAllowApplyCancelDays()))
  62. throw new StatusException("请填写禁止考生取消预约的天数");
  63. if (StringUtils.isEmpty(req.getSelfApplyStartTime()))
  64. throw new StatusException("请填写自主预约起始时间");
  65. if (StringUtils.isEmpty(req.getSelfApplyEndTime()))
  66. throw new StatusException("请填写自主预约截止时间");
  67. if (StringUtils.isEmpty(req.getOpenApplyStartTime()))
  68. throw new StatusException("请填写开放式预约起始时间");
  69. if (StringUtils.isEmpty(req.getOpenApplyEndTime()))
  70. throw new StatusException("请填写开放式预约截止时间");
  71. }
  72. @Override
  73. public List<CategoryVO> listTask() {
  74. List<CategoryVO> categoryList = new ArrayList<CategoryVO>();
  75. QueryWrapper<ApplyTaskEntity> wrapper = new QueryWrapper<>();
  76. LambdaQueryWrapper<ApplyTaskEntity> lw = wrapper.lambda();
  77. lw.eq(ApplyTaskEntity::getEnable, Boolean.TRUE);
  78. List<ApplyTaskEntity> taskList = this.getBaseMapper().selectList(wrapper);
  79. for (ApplyTaskEntity task : taskList) {
  80. CategoryVO category = new CategoryVO();
  81. category.setId(task.getId());
  82. category.setName(task.getName());
  83. categoryList.add(category);
  84. }
  85. return categoryList;
  86. }
  87. /**
  88. * 获取当前启用的预约任务
  89. */
  90. @Override
  91. public CurrentApplyTaskVO currentApplyTask() {
  92. return baseMapper.currentApplyTask();
  93. }
  94. @Override
  95. public ApplyTaskEntity findApplyTask() {
  96. LambdaQueryWrapper<ApplyTaskEntity> wrapper = new LambdaQueryWrapper<>();
  97. wrapper.eq(ApplyTaskEntity::getEnable, Boolean.TRUE);
  98. return baseMapper.selectOne(wrapper);
  99. }
  100. }