diff --git a/src/main/java/com/msdw/tms/api/ClassTeachingApi.java b/src/main/java/com/msdw/tms/api/ClassTeachingApi.java index d93409b..ab705f2 100644 --- a/src/main/java/com/msdw/tms/api/ClassTeachingApi.java +++ b/src/main/java/com/msdw/tms/api/ClassTeachingApi.java @@ -19,4 +19,7 @@ public interface ClassTeachingApi { @ApiOperation(value = "查看虚拟仿真课程列表",notes = "查看虚拟仿真课程列表") R querySimulationPlayList(Integer page,Integer size); + + @ApiOperation(value = "校验是否需要邀请码",notes = "校验是否需要邀请码") + R check(Integer userId,Integer projectId); } diff --git a/src/main/java/com/msdw/tms/controller/ClassTeachingController.java b/src/main/java/com/msdw/tms/controller/ClassTeachingController.java index e696b86..6970b6e 100644 --- a/src/main/java/com/msdw/tms/controller/ClassTeachingController.java +++ b/src/main/java/com/msdw/tms/controller/ClassTeachingController.java @@ -4,10 +4,13 @@ import com.msdw.tms.api.ClassTeachingApi; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.BroadcastEntity; +import com.msdw.tms.entity.ExperimentalStudentEntity; import com.msdw.tms.entity.ExperimentalTeachingEntity; import com.msdw.tms.entity.vo.ProjectRecordVo; import com.msdw.tms.service.ClassTeachingService; +import com.msdw.tms.service.ExperimentalStudentService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -19,6 +22,8 @@ public class ClassTeachingController implements ClassTeachingApi { @Autowired private ClassTeachingService classTeachingService; + @Autowired + private ExperimentalStudentService experimentalStudentService; /** * 用户端查看班级实验列表 @@ -58,27 +63,49 @@ public class ClassTeachingController implements ClassTeachingApi { return R.ok().put("page", page1); } + /** + * 校验是否需要输入邀请码 + * @param userId + * @param projectId + * @return + */ + @Override + @GetMapping("/checkInvitationCode") + public R check(@RequestParam Integer userId,@RequestParam Integer projectId){ + List o = experimentalStudentService.queryIsCode(userId,projectId); + if (o.size()>0){ + return R.ok(); + }else{ + return R.error(200,"false"); + } + } + /** * 通过邀请码进入实验 * @param * @return */ @Override + @Transactional @PostMapping("/joinPractice") public R joinPractice(@RequestBody ExperimentalTeachingEntity entity1){ //获取参数 - Integer isCode = entity1.getIsCode(); Integer projectId = entity1.getProjectId(); Integer invitationCode = entity1.getInvitationCode(); - + Integer userId = entity1.getUserId(); //用于接受参数 + ExperimentalStudentEntity studentEntity = new ExperimentalStudentEntity(); ExperimentalTeachingEntity entity = new ExperimentalTeachingEntity(); - if (isCode==0){ +// Integer ICode = experimentalStudentService.queryIsCode(userId);//获取iscode信息, + + //if (isCode==0) if (invitationCode!=null){ - entity.setIsCode(isCode).setProjectId(projectId); + entity.setProjectId(projectId); ExperimentalTeachingEntity result= classTeachingService.queryInvitationcode(entity);//邀请码唯一 Integer code = result.getInvitationCode(); if (invitationCode.equals(code)==true){ + ExperimentalStudentEntity student = studentEntity.setUserId(userId).setProjectId(projectId); + experimentalStudentService.saveCode(student); return R.ok(); }else{ return R.error("邀请码错误,验证失败!!!"); @@ -86,10 +113,11 @@ public class ClassTeachingController implements ClassTeachingApi { }else{ return R.error(400,"邀请码格式错误!!!"); } - }else{ - return R.error("输入有误,无需邀请码"); } - } +// else{ +// return R.error("输入有误,无需邀请码"); +// } +// } //查看成绩 @Override diff --git a/src/main/java/com/msdw/tms/dao/ExperimentalStudentDao.java b/src/main/java/com/msdw/tms/dao/ExperimentalStudentDao.java new file mode 100644 index 0000000..b5561d8 --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/ExperimentalStudentDao.java @@ -0,0 +1,15 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.ExperimentalStudentEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ExperimentalStudentDao extends BaseMapper { + + List queryIsCode(Integer userId, Integer projectId); + + void saveCode(ExperimentalStudentEntity student); +} diff --git a/src/main/java/com/msdw/tms/entity/ExperimentalStudentEntity.java b/src/main/java/com/msdw/tms/entity/ExperimentalStudentEntity.java new file mode 100644 index 0000000..16a6c4c --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/ExperimentalStudentEntity.java @@ -0,0 +1,21 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@TableName("tms_experimental_student") +public class ExperimentalStudentEntity { + + @TableId(type = IdType.AUTO) + private Integer id; + //绑定用户id + private Integer userId; + //绑定项目id + private Integer projectId; + +} diff --git a/src/main/java/com/msdw/tms/service/ExperimentalStudentService.java b/src/main/java/com/msdw/tms/service/ExperimentalStudentService.java new file mode 100644 index 0000000..42d9610 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/ExperimentalStudentService.java @@ -0,0 +1,12 @@ +package com.msdw.tms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.msdw.tms.entity.ExperimentalStudentEntity; + +import java.util.List; + +public interface ExperimentalStudentService extends IService { + List queryIsCode(Integer userId, Integer projectId); + + void saveCode(ExperimentalStudentEntity student); +} diff --git a/src/main/java/com/msdw/tms/service/impl/ExperimentalStudentServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/ExperimentalStudentServiceImpl.java new file mode 100644 index 0000000..dbe379d --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/ExperimentalStudentServiceImpl.java @@ -0,0 +1,28 @@ +package com.msdw.tms.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.dao.ExperimentalStudentDao; +import com.msdw.tms.entity.ExperimentalStudentEntity; +import com.msdw.tms.service.ExperimentalStudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service("tms_experimental_student") +public class ExperimentalStudentServiceImpl extends ServiceImpl implements ExperimentalStudentService { + + @Autowired + private ExperimentalStudentDao experimentalStudentDao; + + @Override + public List queryIsCode(Integer userId, Integer projectId) { + List o = experimentalStudentDao.queryIsCode(userId,projectId); + return o; + } + + @Override + public void saveCode(ExperimentalStudentEntity student){ + experimentalStudentDao.saveCode(student); + } +} diff --git a/src/main/resources/mapper/tms/ClassTeachingDao.xml b/src/main/resources/mapper/tms/ClassTeachingDao.xml index 85675eb..b88ddf8 100644 --- a/src/main/resources/mapper/tms/ClassTeachingDao.xml +++ b/src/main/resources/mapper/tms/ClassTeachingDao.xml @@ -3,7 +3,7 @@ diff --git a/src/main/resources/mapper/tms/ExperimentalStudentDao.xml b/src/main/resources/mapper/tms/ExperimentalStudentDao.xml new file mode 100644 index 0000000..b5fd886 --- /dev/null +++ b/src/main/resources/mapper/tms/ExperimentalStudentDao.xml @@ -0,0 +1,12 @@ + + + + + + + + INSERT INTO tms_experimental_student(projectId,userId) VALUES (#{projectId},#{userId}) + + \ No newline at end of file diff --git a/src/main/resources/mapper/tms/UserDao.xml b/src/main/resources/mapper/tms/UserDao.xml index 45e9c2a..e2d078d 100644 --- a/src/main/resources/mapper/tms/UserDao.xml +++ b/src/main/resources/mapper/tms/UserDao.xml @@ -111,9 +111,6 @@ per.userId = #{userId} AND per.personalFileId = #{personalFileId} - AND - per.schoolId = s.schoolId -