ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Java的新项目学成在线笔记-day19(十三)

2019-08-08 10:36:50  阅读:291  来源: 互联网

标签:学成 Java String 选课 userId xcLearningCourse 添加 xcTask day19


4 自动添加选课开发 
  4.1 学习服务添加选课 
4.1.1需求分析 
学习服务接收MQ发送添加选课消息,执行添加 选 课操作。 添加选课成功向学生选课表插入记录、向历史任务表插入记录、并向MQ发送“完成选课”消息。
  4.1.2 RabbitMQ配置 
学习服务监听MQ的添加选课队列,并且声明完成选课队列,配置代码同订单服务中RabbitMQ配置   4.1.3 Dao 
学生选课Dao:

[AppleScript] 纯文本查看 复制代码

?

1

public interface XcLearningCourseRepository extends JpaRepository<XcLearningCourse, String> {     //根据用户和课程查询选课记录,用于判断是否添加选课     XcLearningCourse findXcLearningCourseByUserIdAndCourseId(String userId, String courseId); }


历史任务Dao:
 

[AppleScript] 纯文本查看 复制代码

?

1

public interface XcTaskHisRepository extends JpaRepository<XcTaskHis,String> {   }


4.1.4 Service 
1、添加选课方法 向xc_learning_course添加记录,为保证不重复添加选课,先查询历史任务表,如果从历史任务表查询不到任务说 明此任务还没有处理,此时则添加选课并添加历史任务。
在学习服务中编码如下代码:
 

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

//完成选课  

  @Transactional  

  public ResponseResult addcourse(String userId, String courseId,String valid,Date  startTime,Date endTime,XcTask xcTask){         if (StringUtils.isEmpty(courseId)) {   

         ExceptionCast.cast(LearningCode.LEARNING_GETMEDIA_ERROR);   

     }       

 if (StringUtils.isEmpty(userId)) {  

          ExceptionCast.cast(LearningCode.CHOOSECOURSE_USERISNULL);  

      }   

     if(xcTask == null || StringUtils.isEmpty(xcTask.getId())){  

          ExceptionCast.cast(LearningCode.CHOOSECOURSE_TASKISNULL);   

     }          //查询历史任务      

  Optional<XcTaskHis> optional = xcTaskHisRepository.findById(xcTask.getId());  

      if(optional.isPresent()){        

    return new ResponseResult(CommonCode.SUCCESS);    

    }     

   XcLearningCourse xcLearningCourse =  xcLearningCourseRepository.findXcLearningCourseByUserIdAndCourseId(userId, courseId);         if (xcLearningCourse == null) {//没有选课记录则添加     

       xcLearningCourse = new XcLearningCourse();      

      xcLearningCourse.setUserId(userId);     

       xcLearningCourse.setCourseId(courseId);      

      xcLearningCourse.setValid(valid);       

     xcLearningCourse.setStartTime(startTime);    

        xcLearningCourse.setEndTime(endTime);   

         xcLearningCourse.setStatus("501001");   

         xcLearningCourseRepository.save(xcLearningCourse);  

      } else {//有选课记录则更新日期     

       xcLearningCourse.setValid(valid);    

        xcLearningCourse.setStartTime(startTime);    

        xcLearningCourse.setEndTime(endTime);     

       xcLearningCourse.setStatus("501001");     

       xcLearningCourseRepository.save(xcLearningCourse);     

   }  

     //向历史任务表播入记录

        Optional<XcTaskHis> optional = xcTaskHisRepository.findById(xcTask.getId());   

     if(!optional.isPresent()){      

     //添加历史任务    

        XcTaskHis xcTaskHis = new XcTaskHis();     

       BeanUtils.copyProperties(xcTask,xcTaskHis);    

        xcTaskHisRepository.save(xcTaskHis);

        }

 

[AppleScript] 纯文本查看 复制代码

?

1

return new ResponseResult(CommonCode.SUCCESS);     }

标签:学成,Java,String,选课,userId,xcLearningCourse,添加,xcTask,day19
来源: https://blog.csdn.net/czbkzmj/article/details/98849032

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有