123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.nuliji.tools.mybatis.Example;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.dao.UserCourseAppointmentMapper;
- import com.qxgmat.data.dao.entity.CourseNo;
- import com.qxgmat.data.dao.entity.UserCourseAppointment;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.*;
- @Service
- public class UserCourseAppointmentService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(UserCourseAppointmentService.class);
- @Resource
- private UserCourseAppointmentMapper userCourseAppointmentMapper;
- public Page<UserCourseAppointment> listAdmin(int page, int size, Integer recordId, Integer userId, Integer courseId, String startTime, String endTime, String order, DirectionStatus direction){
- Example example = new Example(UserCourseAppointment.class);
- if(recordId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("recordId", recordId)
- );
- }
- if (userId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- );
- }
- if (courseId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("courseId", courseId)
- );
- }
- // 在课程结束前完成预习作业逻辑
- if (startTime != null){
- example.and(
- example.createCriteria()
- .andGreaterThanOrEqualTo("endTime", startTime)
- );
- }
- if (endTime != null){
- example.and(
- example.createCriteria()
- .andLessThanOrEqualTo("endTime", endTime)
- );
- }
- if(order == null || order.isEmpty()) order = "id";
- switch(direction){
- case ASC:
- example.orderBy(order).asc();
- break;
- case DESC:
- default:
- example.orderBy(order).desc();
- }
- return select(userCourseAppointmentMapper, example, page, size);
- }
- /**
- * 获取课程课时分组列表
- * @param recordIds
- * @return
- */
- public Map<Object, Collection<UserCourseAppointment>> groupByRecordId(Collection recordIds){
- Map<Object, Collection<UserCourseAppointment>> relationMap = new HashMap<>();
- Example example = new Example(UserCourseAppointment.class);
- example.and(
- example.createCriteria()
- .andIn("recordId", recordIds)
- );
- example.setOrderByClause("recordId asc, no asc");
- List<UserCourseAppointment> nos = select(userCourseAppointmentMapper, example);
- Collection<UserCourseAppointment> list;
- for(UserCourseAppointment no : nos){
- if (!relationMap.containsKey(no.getRecordId())){
- list = new ArrayList<>();
- relationMap.put(no.getRecordId(), list);
- }else{
- list = relationMap.get(no.getRecordId());
- }
- list.add(no);
- }
- return relationMap;
- }
- public List<UserCourseAppointment> listByRecord(Integer recordId){
- Example example = new Example(UserCourseAppointment.class);
- example.and(
- example.createCriteria()
- .andEqualTo("recordId", recordId)
- );
- return select(userCourseAppointmentMapper, example);
- }
- public UserCourseAppointment addAppointment(UserCourseAppointment appointment){
- List<UserCourseAppointment> list = listByRecord(appointment.getRecordId());
- Integer max = 0;
- for(UserCourseAppointment no:list){
- if (max < no.getNo()) max = no.getNo();
- }
- appointment.setNo(max + 1);
- return add(appointment);
- }
- public Boolean deleteAppointment(Number id){
- UserCourseAppointment in = get(id);
- List<UserCourseAppointment> nos = listByRecord(in.getRecordId());
- for(UserCourseAppointment no : nos){
- if (no.getNo() < in.getNo()){
- continue;
- }
- edit(UserCourseAppointment.builder().id(no.getId()).no(no.getNo() - 1).build());
- }
- return delete(id);
- }
- public UserCourseAppointment add(UserCourseAppointment appointment){
- int result = insert(userCourseAppointmentMapper, appointment);
- appointment = one(userCourseAppointmentMapper, appointment.getId());
- if(appointment == null){
- throw new SystemException("预约添加失败");
- }
- return appointment;
- }
- public UserCourseAppointment edit(UserCourseAppointment appointment){
- UserCourseAppointment in = one(userCourseAppointmentMapper, appointment.getId());
- if(in == null){
- throw new ParameterException("预约不存在");
- }
- int result = update(userCourseAppointmentMapper, appointment);
- return appointment;
- }
- public boolean delete(Number id){
- UserCourseAppointment in = one(userCourseAppointmentMapper, id);
- if(in == null){
- throw new ParameterException("预约不存在");
- }
- int result = delete(userCourseAppointmentMapper, id);
- return result > 0;
- }
- public UserCourseAppointment get(Number id){
- UserCourseAppointment in = one(userCourseAppointmentMapper, id);
- if(in == null){
- throw new ParameterException("预约不存在");
- }
- return in;
- }
- public Page<UserCourseAppointment> select(int page, int pageSize){
- return select(userCourseAppointmentMapper, page, pageSize);
- }
- public Page<UserCourseAppointment> select(Integer[] ids){
- return page(()->select(userCourseAppointmentMapper, ids), 1, ids.length);
- }
- public List<UserCourseAppointment> select(Collection ids){
- return select(userCourseAppointmentMapper, ids);
- }
- }
|