package com.qmth.exam.reserve.service.impl; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qmth.boot.core.collection.PageResult; import com.qmth.boot.core.exception.StatusException; import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO; import com.qmth.exam.reserve.bean.login.LoginUser; import com.qmth.exam.reserve.bean.stdapply.CategoryVO; import com.qmth.exam.reserve.bean.task.ApplyTaskReq; import com.qmth.exam.reserve.bean.task.ApplyTaskRuleVO; import com.qmth.exam.reserve.bean.task.ApplyTaskVO; import com.qmth.exam.reserve.dao.ApplyTaskDao; import com.qmth.exam.reserve.entity.ApplyTaskEntity; import com.qmth.exam.reserve.service.ApplyTaskService; import com.qmth.exam.reserve.util.PageUtil; @Service public class ApplyTaskServiceImpl extends ServiceImpl implements ApplyTaskService { @Override public PageResult page(ApplyTaskReq req) { IPage iPage = this.baseMapper.page(new Page(req.getPageNumber(), req.getPageSize()), req); return PageUtil.of(iPage); } @Override public ApplyTaskRuleVO find(Long id) { ApplyTaskRuleVO task = this.baseMapper.find(id); if (StringUtils.isEmpty(task)) { throw new StatusException("预约任务不存在!"); } task.setTimeList(this.baseMapper.getTimePeriodList(id)); return task; } @Override public void ruleSave(ApplyTaskReq req, LoginUser user) { checkRule(req); ApplyTaskEntity task = new ApplyTaskEntity(); task.setId(req.getId()); task.setName(req.getName()); task.setAllowApplyDays(req.getAllowApplyDays()); task.setAllowApplyCancelDays(req.getAllowApplyCancelDays()); task.setSelfApplyStartTime(req.getSelfApplyStartTime()); task.setSelfApplyEndTime(req.getSelfApplyEndTime()); task.setOpenApplyStartTime(req.getOpenApplyStartTime()); task.setOpenApplyEndTime(req.getOpenApplyEndTime()); task.setEnable(Boolean.FALSE); task.setOrgId(user.getOrgId()); this.saveOrUpdate(task); } private void checkRule(ApplyTaskReq req) { if (StringUtils.isEmpty(req.getName())) throw new StatusException("请填写任务名称"); if (StringUtils.isEmpty(req.getAllowApplyDays())) throw new StatusException("请填写禁止考生预约的天数"); if (StringUtils.isEmpty(req.getAllowApplyCancelDays())) throw new StatusException("请填写禁止考生取消预约的天数"); if (StringUtils.isEmpty(req.getSelfApplyStartTime())) throw new StatusException("请填写自主预约起始时间"); if (StringUtils.isEmpty(req.getSelfApplyEndTime())) throw new StatusException("请填写自主预约截止时间"); if (StringUtils.isEmpty(req.getOpenApplyStartTime())) throw new StatusException("请填写开放式预约起始时间"); if (StringUtils.isEmpty(req.getOpenApplyEndTime())) throw new StatusException("请填写开放式预约截止时间"); } @Override public List listTask() { List categoryList = new ArrayList(); QueryWrapper wrapper = new QueryWrapper<>(); LambdaQueryWrapper lw = wrapper.lambda(); lw.eq(ApplyTaskEntity::getEnable, Boolean.TRUE); List taskList = this.getBaseMapper().selectList(wrapper); for (ApplyTaskEntity task : taskList) { CategoryVO category = new CategoryVO(); category.setId(task.getId()); category.setName(task.getName()); categoryList.add(category); } return categoryList; } /** * 获取当前启用的预约任务 */ @Override public CurrentApplyTaskVO currentApplyTask() { return baseMapper.currentApplyTask(); } @Override public ApplyTaskEntity findApplyTask() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(ApplyTaskEntity::getEnable, Boolean.TRUE); return baseMapper.selectOne(wrapper); } }