HereWhiteController.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.ym.controller;
  2. import com.ym.mec.common.controller.BaseController;
  3. import com.ym.pojo.HereWhite;
  4. import com.ym.service.HereWhiteService;
  5. import freemarker.cache.StringTemplateLoader;
  6. import org.apache.commons.lang3.RandomStringUtils;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.data.redis.core.RedisTemplate;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.Objects;
  14. import java.util.concurrent.TimeUnit;
  15. @RestController
  16. @RequestMapping("/hereWhite")
  17. public class HereWhiteController extends BaseController {
  18. @Autowired
  19. private HereWhiteService hereWhiteService;
  20. @Autowired
  21. private RedisTemplate<String,String> redisTemplate;
  22. /**
  23. * 创建白板,默认全部采用零时白板
  24. * @param name 白板名称
  25. * @param userNum 白板人数上限,0不限制
  26. * @param courseScheduleId 课程编号
  27. * @return
  28. * @throws Exception
  29. */
  30. @RequestMapping(value = "create", method = RequestMethod.POST)
  31. public Object userAdd(String name,Integer userNum,Integer courseScheduleId) throws Exception {
  32. if(StringUtils.isEmpty(name) || userNum == null || courseScheduleId == null){
  33. return failed("参数校验失败");
  34. }
  35. HereWhite hereWhite = hereWhiteService.create(name, userNum, courseScheduleId);
  36. String joinSuccessKey = "createHereWhite:" + courseScheduleId;
  37. String randomNumeric = RandomStringUtils.randomNumeric(22);
  38. redisTemplate.opsForValue().set(joinSuccessKey,randomNumeric,2, TimeUnit.HOURS);
  39. hereWhite.setRandomNumeric(randomNumeric);
  40. return succeed(hereWhite);
  41. }
  42. /**
  43. * 获取特定白板详情
  44. * @param courseScheduleId 课程编号
  45. * @return
  46. * @throws Exception
  47. */
  48. @RequestMapping(value = "get", method = RequestMethod.GET)
  49. public Object join(Integer courseScheduleId){
  50. HereWhite hereWhite = hereWhiteService.getByClassId(courseScheduleId);
  51. if(Objects.nonNull(hereWhite)){
  52. String joinSuccessKey = "createHereWhite:" + courseScheduleId;
  53. hereWhite.setRandomNumeric(redisTemplate.opsForValue().get(joinSuccessKey));
  54. }
  55. return succeed(hereWhite);
  56. }
  57. }