| | |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.Meet; |
| | | import com.ycl.jxkg.enums.MeetStatusEnum; |
| | | import com.ycl.jxkg.mapper.ClassesUserMapper; |
| | | import com.ycl.jxkg.mapper.MeetMapper; |
| | | import com.ycl.jxkg.service.MeetService; |
| | | import com.ycl.jxkg.base.Result; |
| | |
| | | import com.ycl.jxkg.domain.vo.MeetVO; |
| | | import com.ycl.jxkg.domain.query.MeetQuery; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.core.userdetails.User; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.ycl.jxkg.utils.PageUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | private final MeetMapper meetMapper; |
| | | |
| | | @Autowired |
| | | protected WebContext webContext; |
| | | private WebContext webContext; |
| | | @Autowired |
| | | private ClassesUserMapper classesUserMapper; |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | |
| | | @Override |
| | | public Result add(MeetForm form) { |
| | | Meet entity = MeetForm.getEntityByForm(form, null); |
| | | entity.setStudentIds(JSONArray.toJSONString(form.getStudentIds())); |
| | | entity.setStatus(MeetStatusEnum.Wait.getCode()); |
| | | entity.setCreateUser(webContext.getCurrentUser().getId()); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | entity.setStudentIds(JSONArray.toJSONString(form.getStudentIds())); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * 教师分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result page(MeetQuery query) { |
| | | |
| | | IPage<Meet> page = PageUtil.getPage(query, Meet.class); |
| | | Integer id = webContext.getCurrentUser().getId(); |
| | | //查自己创建的房间 |
| | | query.setTeacherId(id); |
| | | IPage<MeetVO> page = PageUtil.getPage(query, MeetVO.class); |
| | | baseMapper.getPage(page, query); |
| | | List<Meet> records = page.getRecords(); |
| | | List<MeetVO> vos = new ArrayList<>(); |
| | | for (Meet record : records) { |
| | | MeetVO meetVO = new MeetVO(); |
| | | BeanUtils.copyProperties(record,meetVO); |
| | | meetVO.setStudentIds(JSONArray.parseArray(record.getStudentIds(),Integer.class)); |
| | | vos.add(meetVO); |
| | | |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 学生分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result studentPage(MeetQuery query) { |
| | | Integer userId = webContext.getCurrentUser().getId(); |
| | | //查出学生所在班级 |
| | | List<Integer> classes = classesUserMapper.getClassesByUserId(userId); |
| | | if(CollectionUtils.isEmpty(classes)){ |
| | | return Result.ok("您暂未加入班级"); |
| | | } |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | query.setClassesIds(classes); |
| | | IPage<MeetVO> page = PageUtil.getPage(query, MeetVO.class); |
| | | baseMapper.getPage(page, query); |
| | | |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | |
| | | public Result detail(Integer id) { |
| | | MeetVO vo = baseMapper.getById(id); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | return Result.ok().data(vo); |
| | | if(vo.getStatus().equals(MeetStatusEnum.Starting.getCode())){ |
| | | return Result.ok(); |
| | | }else { |
| | | return Result.fail(SystemCode.InnerError.getCode(),"房间尚未开始或已结束"); |
| | | } |
| | | } |
| | | |
| | | /** |