Skip to content

Commit

Permalink
返回老师信息时根据用户id返回是否对某个课程已经进行了评价
Browse files Browse the repository at this point in the history
  • Loading branch information
txcjhaz committed Mar 16, 2019
1 parent 8baf897 commit f23ddcd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public List<Comment> getCommentInfo(String teacherId, String courseId){
if(courseId == null || courseId.equals("")){
return commentMapper.getCommentInfoByTeacherId(teacherId);
}
else
else {
return commentMapper.getCommentInfoByCourseId(courseId);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.nju171250.njuTeacher.controller;

import com.alibaba.fastjson.JSONObject;
import com.nju171250.njuTeacher.mapper.CommentMapper;
import com.nju171250.njuTeacher.mapper.CourseMapper;
import com.nju171250.njuTeacher.mapper.TeacherMapper;
import com.nju171250.njuTeacher.model.CommentExample;
import com.nju171250.njuTeacher.model.Course;
import com.nju171250.njuTeacher.model.CourseExample;
import com.nju171250.njuTeacher.model.Teacher;
Expand All @@ -18,16 +20,32 @@ public class TeacherController {
TeacherMapper teacherMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
CommentMapper commentMapper;

@GetMapping(value = "/getTeacherInfo")
public JSONObject getTeacherInfo(String teacherId){
public JSONObject getTeacherInfo(String teacherId, String openid){
Teacher teacher = teacherMapper.selectByPrimaryKey(teacherId);

CourseExample example = new CourseExample();
CourseExample.Criteria criteria = example.createCriteria();
criteria.andTeacherIdEqualTo(teacherId);
List<Course> list = courseMapper.selectByExample(example);

if(openid != null) {
for (Course course : list) {// 设置用户是否已对该课程进行评价
CommentExample commentExample = new CommentExample();
CommentExample.Criteria criteria1 = commentExample.createCriteria();
criteria1.andUserIdEqualTo(openid);
criteria1.andCourseIdEqualTo(course.getCourseId());
if(commentMapper.countByExample(commentExample) == 0){// 若返回0,则说明用户对该课程未评价,否则已评价
course.setCommented(false);
}
else
course.setCommented(true);
}
}

JSONObject jsonObject = new JSONObject();
jsonObject.put("teacher", teacher);
jsonObject.put("courses", list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Comment(String commentId, String courseId, String userId, String commentC
this.likeNum = likeNum;
}


/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table comment
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/nju171250/njuTeacher/model/Course.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.nju171250.njuTeacher.model;

public class Course {
private boolean isCommented;

/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column course.course_id
Expand Down Expand Up @@ -91,6 +93,14 @@ public Course(String courseId, String courseIdSchool, String teacherId, String c
this.courseTeacher = courseTeacher;
}

public boolean isCommented() {
return isCommented;
}

public void setCommented(boolean commented) {
isCommented = commented;
}

/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table course
Expand Down

0 comments on commit f23ddcd

Please sign in to comment.