项目实训——第二周第一次日志

确定需求后,学生端后端准备从“培养方案和培养计划“功能开始实现,经过简单讨论,我主要负责对培养计划中选课的后端实现,简单来说,需要完成必修课、选修课和公共课三类课程的查询、选课和删除选课三个功能。
1)学生查看未选的的课程,包括了必修、选修和公共三类,这里以公共课为例:
controller层

/**
     * 学生查看未选的公共课
     * @param request
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/findPublicCourse")
    @ResponseBody
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public  Map<String, Object> findPublicCourse(HttpServletRequest request) {
    
        int stu_id=Integer.parseInt(request.getParameter("stu_id"));
        List<StudyProject> list1 =StuService.selectStudyProject(stu_id);
        int pid=list1.get(0).getStudyProjectId();

        List<ProjectCourse> list2= StuService.selectCanChooseCourse(stu_id,pid);
        Map<String, Object> allproperty = new HashMap<String, Object>();//存放总信息
        StudyProject project0 = list1.get(0);//取出培养计划
        List<Object> pub = new ArrayList<Object>();
        int pub_num=1;
        //取出培养计划对应的课程信息
        for (int i = 0; i < list2.size(); i++) {
            ProjectCourse courseInfo = list2.get(i);

            if(courseInfo.getCourseType().equals("公共课")) {
                Map<String, Object> course = new HashMap<String, Object>();

                course.put( "course_id", courseInfo.getCourseId());
                course.put( "course_attr", courseInfo.getCourseAttr());
                course.put("course_name", courseInfo.getCourseName());
                course.put( "began_time", courseInfo.getBeganTime());
                course.put("total_period", courseInfo.getTotalPeriod());
                course.put( "credit", courseInfo.getCredit());
                course.put("exm_method", courseInfo.getExmMethod());
                pub.add(course);
                ++pub_num;
            }

        }
        allproperty.put("pub_course",pub);
        return  allproperty;
    }

service层:

  //学生查询未选过的所有课
    public List<ProjectCourse> selectCanChooseCourse(int stu_id,int pid) {return projectCourseDao.selectCanChooseCourse(stu_id,pid);  }

Dao层:

List<ProjectCourse> selectCanChooseCourse(int stu_id,int pid);

Mapper:

 <select id="selectCanChooseCourse" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  select * from project_course where study_project_id=#{pid} and
  course_id not in(
  select course_id from study_plan where study_plan_id =
  (select study_plan_id from student where stu_id=#{stu_id})
  )
  </select>

postman进行测试:
查询学号为201656777的学生的未选的公共课,正确结果{科技英语},查询结果{科技英语}。
在这里插入图片描述
2)学生查看已选的课程:同样包括三类,这里以必修课为例:
controller层:

 /**
     * 学生已选的非公共必修课
     * @param request
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/findChosenNessCourse")
    @ResponseBody
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public  Map<String, Object> findChosenNessCourse(HttpServletRequest request) {

        int stu_id=Integer.parseInt(request.getParameter("stu_id"));
        List<StudyProject> list1 =StuService.selectStudyProject(stu_id);
        int pid=list1.get(0).getStudyProjectId();

        List<ProjectCourse> list2= StuService.selectChosenCourse(stu_id,pid);
        Map<String, Object> allproperty = new HashMap<String, Object>();//存放总信息
        StudyProject project0 = list1.get(0);//取出培养计划
        List<Object> ness = new ArrayList<Object>();
        int ness_num=1;
        //取出培养计划对应的课程信息
        for (int i = 0; i < list2.size(); i++) {

            ProjectCourse courseInfo = list2.get(i);
            if(courseInfo.getCourseType().equals("公共课")) {}
            else {
                if (courseInfo.getCourseAttr().equals("必修课")) {
                    Map<String, Object> course = new HashMap<String, Object>();

                    course.put("course_id", courseInfo.getCourseId());
                    course.put("course_attr", courseInfo.getCourseAttr());
                    course.put("course_name", courseInfo.getCourseName());
                    course.put("began_time", courseInfo.getBeganTime());
                    course.put("total_period", courseInfo.getTotalPeriod());
                    course.put("credit", courseInfo.getCredit());
                    course.put("exm_method", courseInfo.getExmMethod());
                    ness.add(course);
                    ++pub_num;
                }
            }
        }
        allproperty.put("ness_course",ness);
        return  allproperty;
    }

service层:

  //学生查询选了的所有课
    public List<ProjectCourse> selectChosenCourse(int stu_id,int pid) {return projectCourseDao.selectChosenCourse(stu_id,pid);  }

dao层:

 List<ProjectCourse> selectChosenCourse(int stu_id,int pid);

Mapper:

 <select id="selectChosenCourse" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  select * from project_course where study_project_id=#{pid} and
  course_id  in(
  select course_id from study_plan where study_plan_id =
  (select study_plan_id from student where stu_id=#{stu_id})
  )
  </select>

postman测试:
查询学号为201656777学生的必修课,正确结果集{“高级软件工程”,“数据科学”},查询结果{“高级软件工程”,“数据科学”}
在这里插入图片描述3)选课:
controller层:

/**
     * 新增培养计划
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/insertStudyPlanInfo")
    @ResponseBody
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Result insertStudyPlanInfo(HttpServletRequest request) {
        StudyPlan sp = new StudyPlan();
        sp.setState("未提交");
        sp.setCourseId(Integer.parseInt(request.getParameter("course_id")));
        sp.setStuId(Integer.parseInt(request.getParameter("stu_id")));
        int re = StuService.insertStuPlanInfo(sp);
        return Result.succ(200, "成功", re);

    }

service层:

//新增、撤销、提交培养计划
    public  int insertStuPlanInfo(StudyPlan sp) {
        return studyPlanDao.insertStuplanInfo(sp);
    }

dao层:

int insertStuplanInfo(StudyPlan record);

mapper:

  <insert id="insertStuplanInfo" parameterType="com.sdu.postgraduate.entity.StudyPlan"  >
    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer">
      select id from study_plan order by id desc limit 1
    </selectKey>
    insert into study_plan (id, study_plan_id, segment, 
      course_id, course_type, course_attr, 
      course_name, began_time, total_period, 
      credit, exm_method, state
      )
    values (#{id,jdbcType=INTEGER}+1, (select study_plan_id from student where student.stu_id=#{stuId,jdbcType=INTEGER}), (select segment from study_project where study_project_id= (select study_project_id from student where student.stu_id=#{stuId,jdbcType=INTEGER})),
      #{courseId,jdbcType=INTEGER}, (select course_type from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}),  (select course_attr from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}),
    (select course_name from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}),  (select began_time from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}),  (select total_period from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}),
    (select credit from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}), (select exm_method from project_course where project_course.course_id=#{courseId,jdbcType=INTEGER}), #{state,jdbcType=VARCHAR}
      )
  </insert>

postman测试:
学号为201656777的学生选了488004课程号的“电子商务”课程。
原数据库:该学生的study_plan_id为2,他的课程中无电子商务
在这里插入图片描述在这里插入图片描述在这里插入图片描述经过postman模拟选课请求后,数据库内增加了他的选课数据,测试成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值