12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.ym.controller;
- import com.ym.mec.common.controller.BaseController;
- import com.ym.pojo.HereWhite;
- import com.ym.service.HereWhiteService;
- import freemarker.cache.StringTemplateLoader;
- import org.apache.commons.lang3.RandomStringUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.Objects;
- import java.util.concurrent.TimeUnit;
- @RestController
- @RequestMapping("/hereWhite")
- public class HereWhiteController extends BaseController {
- @Autowired
- private HereWhiteService hereWhiteService;
- @Autowired
- private RedisTemplate<String,String> redisTemplate;
- /**
- * 创建白板,默认全部采用零时白板
- * @param name 白板名称
- * @param userNum 白板人数上限,0不限制
- * @param courseScheduleId 课程编号
- * @return
- * @throws Exception
- */
- @RequestMapping(value = "create", method = RequestMethod.POST)
- public Object userAdd(String name,Integer userNum,Integer courseScheduleId) throws Exception {
- if(StringUtils.isEmpty(name) || userNum == null || courseScheduleId == null){
- return failed("参数校验失败");
- }
- HereWhite hereWhite = hereWhiteService.create(name, userNum, courseScheduleId);
- String joinSuccessKey = "createHereWhite:" + courseScheduleId;
- String randomNumeric = RandomStringUtils.randomNumeric(22);
- redisTemplate.opsForValue().set(joinSuccessKey,randomNumeric,2, TimeUnit.HOURS);
- hereWhite.setRandomNumeric(randomNumeric);
- return succeed(hereWhite);
- }
- /**
- * 获取特定白板详情
- * @param courseScheduleId 课程编号
- * @return
- * @throws Exception
- */
- @RequestMapping(value = "get", method = RequestMethod.GET)
- public Object join(Integer courseScheduleId){
- HereWhite hereWhite = hereWhiteService.getByClassId(courseScheduleId);
- if(Objects.nonNull(hereWhite)){
- String joinSuccessKey = "createHereWhite:" + courseScheduleId;
- hereWhite.setRandomNumeric(redisTemplate.opsForValue().get(joinSuccessKey));
- }
- return succeed(hereWhite);
- }
- }
|