Java的新项目学成在线笔记-day10(二)

1.3 课程发布接口 
1.3.1 Api接口 
此Api接口由课程管理提供,由课程管理前端调用此Api接口,实现课程发布。 在api工程下课程管理包下定义接口:
[mw_shl_code=applescript,true]@ApiOperation("发布课程") 
public CoursePublishResult publish(@PathVariable String id); [/mw_shl_code]
1.3.2 创建Feign Client 
在课程管理工程创建CMS服务页面发布的Feign Client

[mw_shl_code=applescript,true]@FeignClient(value = XcServiceList.XC_SERVICE_MANAGE_CMS) public interface CmsPageClient {  
  //一键发布页面  
   @PostMapping("/cms/page/postPageQuick")   
  public CmsPostPageResult postPageQuick(CmsPage cmsPage); }[/mw_shl_code]
1.3.3 Service 
1、配置课程发布页面参数 在application.yml中配置

[mw_shl_code=applescript,true]course‐publish:
   siteId: 5b30cba5f58b4411fc6cb1e5 
  templateId: 5ad9a24d68db5239b8fef199 
  previewUrl: http://www.xuecheng.com/cms/preview/  
pageWebPath: /course/detail/  
pagePhysicalPath: /course/detail/  
dataUrlPre: http://localhost:31200/course/courseview/ [/mw_shl_code]
siteId:站点id templateId:模板id dataurlPre:数据url的前缀
pageWebPath: 页面的web访问路径 pagePhysicalPath:页面的物理存储路径。
  2、Service方法如下

[mw_shl_code=applescript,true] 
course‐publish:   siteId: 5b30cba5f58b4411fc6cb1e5 
  templateId: 5ad9a24d68db5239b8fef199 
  previewUrl: http://www.xuecheng.com/cms/preview/ 
  pageWebPath: /course/detail/ 
  pagePhysicalPath: /course/detail/  
dataUrlPre: http://localhost:31200/course/courseview/  
@Value("${course‐publish.dataUrlPre}") private String publish_dataUrlPre; @Value("${course‐publish.pagePhysicalPath}") private String publish_page_physicalpath; @Value("${course‐publish.pageWebPath}") private String publish_page_webpath; @Value("${course‐publish.siteId}") private String publish_siteId; 
@Value("${course‐publish.templateId}") private String publish_templateId; 
@Value("${course‐publish.previewUrl}") private String previewUrl; 
@Autowired CmsPageClient cmsPageClient;   
//课程发布   
  @Transactional  
   public CoursePublishResult publish(String courseId){   
      //课程信息      
   CourseBase one = this.findCourseBaseById(courseId);  
       //发布课程详情页面     
    CmsPostPageResult cmsPostPageResult = publish_page(courseId);    
     if(!cmsPostPageResult.isSuccess()){
            ExceptionCast.cast(CommonCode.FAIL);
[/mw_shl_code]
[mw_shl_code=applescript,true] }     
    //更新课程状态     
    CourseBase courseBase = saveCoursePubState(courseId);     
    //课程索引...     
    //课程缓存...      
     //页面url  
       String pageUrl = cmsPostPageResult.getPageUrl();    
     return new CoursePublishResult(CommonCode.SUCCESS,pageUrl);   
    }   
  //更新课程发布状态  
   private CourseBase saveCoursePubState(String courseId){    
     CourseBase courseBase = this.findCourseBaseById(courseId);    
     //更新发布状态     
    courseBase.setStatus("202002");    
     CourseBase save = courseBaseRepository.save(courseBase);  
      return save;  
  }   
  //发布课程正式页面 
    public CmsPostPageResult publish_page(String courseId){    
     CourseBase one = this.findCourseBaseById(courseId);      
   //发布课程预览页面      
   CmsPage cmsPage = new CmsPage();   
      //站点       
  cmsPage.setSiteId(publish_siteId);//课程预览站点    
     //模板      
   cmsPage.setTemplateId(publish_templateId);   
      //页面名称    
    cmsPage.setPageName(courseId+".html");    
     //页面别名        
cmsPage.setPageAliase(one.getName());    
     //页面访问路径    
     cmsPage.setPageWebPath(publish_page_webpath);  
       //页面存储路径     
    cmsPage.setPagePhysicalPath(publish_page_physicalpath);    
     //数据url       
  cmsPage.setDataUrl(publish_dataUrlPre+courseId);      
   //发布页面   
      CmsPostPageResult cmsPostPageResult = cmsPageClient.postPageQuick(cmsPage);    
     return cmsPostPageResult;   
  } [/mw_shl_code]
1.3.4 Controller 
[mw_shl_code=applescript,true]@Override  
   @PostMapping("/publish/{id}")   
  public CoursePublishResult publish(@PathVariable String id) {    
     return courseService.publish(id);     }
[/mw_shl_code]
 

你可能感兴趣的:(JAVA)