A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 谷粒姐姐 于 2019-5-6 15:20 编辑

3.2.3修改课程发布
在课程管理服务定义dao:
1)创建course_pub表的dao
[AppleScript] 纯文本查看 复制代码
public interface CoursePubRepository extends JpaRepository<CoursePub, String> { }

2) 修改课程发布service

[AppleScript] 纯文本查看 复制代码
 //保存CoursePub    
 public CoursePub saveCoursePub(String id, CoursePub coursePub){ 
        if(StringUtils.isNotEmpty(id)){   
          ExceptionCast.cast(CourseCode.COURSE_PUBLISH_COURSEIDISNULL);   
      }     
    CoursePub coursePubNew = null;       
  Optional<CoursePub> coursePubOptional = coursePubRepository.findById(id); 
        if(coursePubOptional.isPresent()){          
   coursePubNew = coursePubOptional.get();       
  }   
      if(coursePubNew == null){    
         coursePubNew = new CoursePub();  
       }     
      BeanUtils.copyProperties(coursePub,coursePubNew);   
      //设置主键    
     coursePubNew.setId(id);      
   //更新时间戳为最新时间   
      coursePub.setTimestamp(new Date());
        //发布时间

[AppleScript] 纯文本查看 复制代码
 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY‐MM‐dd HH:mm:ss");         String date = simpleDateFormat.format(new Date());     
    coursePub.setPubTime(date);     
    coursePubRepository.save(coursePub);    
     return coursePub; 
      }   
  //创建coursePub对象   
  private CoursePub createCoursePub(String id){    
     CoursePub coursePub = new CoursePub();    
     coursePub.setId(id);     
      //基础信息    
     Optional<CourseBase> courseBaseOptional = courseBaseRepository.findById(id);    
     if(courseBaseOptional == null){ 
            CourseBase courseBase = courseBaseOptional.get();     
        BeanUtils.copyProperties(courseBase, coursePub);       
  }     
    //查询课程图片   
      Optional<CoursePic> picOptional = coursePicRepository.findById(id);   
      if(picOptional.isPresent()){         
    CoursePic coursePic = picOptional.get();     
        BeanUtils.copyProperties(coursePic, coursePub);  
       }      
     //课程营销信息     
    Optional<CourseMarket> marketOptional = courseMarketRepository.findById(id);     
    if(marketOptional.isPresent()){    
         CourseMarket courseMarket = marketOptional.get();        
     BeanUtils.copyProperties(courseMarket, coursePub);     
    }        
   //课程计划     
    TeachplanNode teachplanNode = teachplanMapper.selectList(id);   
      //将课程计划转成json       
  String teachplanString = JSON.toJSONString(teachplanNode);      
   coursePub.setTeachplan(teachplanString);    
     return coursePub;  
   }
修改课程发布方法,添加调用saveCoursePub方法的代码,添加部分的代码如下:
[AppleScript] 纯文本查看 复制代码
//课程发布    
 @Transactional   
  public CoursePublishResult publish(String courseId){   
      ....       
  //创建课程索引     
    //创建课程索引信息      
   CoursePub coursePub = createCoursePub(courseId);    
     //向数据库保存课程索引信息
        CoursePub newCoursePub = saveCoursePub(courseId, coursePub);
if(newCoursePub==null){       
      //创建课程索引信息失败       
      ExceptionCast.cast(CourseCode.COURSE_PUBLISH_CREATE_INDEX_ERROR);    
     }   
     ....    
   }




0 个回复

您需要登录后才可以回帖 登录 | 加入黑马