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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

1 课程发布 1.1 需求分析
课程发布后将生成正式的课程详情页面,课程发布后用户即可浏览课程详情页面,并开始课程的学习。
课程发布生成课程详情页面的流程与课程预览业务流程相同,如下:
1、用户进入教学管理中心,进入某个课程的管理界面
2、点击课程发布,前端请求到课程管理服务
3、课程管理服务远程调用CMS生成课程发布页面,CMS将课程详情页面发布到服务器
4、课程管理服务修改课程发布状态为 “已发布”,并向前端返回发布成功
5、用户在教学管理中心点击“课程详情页面”链接,查看课程详情页面内容

1.2 CMS一键发布接口
1.2.1 需求分析
根据需求分析内容,需要在cms服务增加页面发布接口供课程管理服务调用,此接口的功能如下: 1、接收课程管理服务发布的页面信息
2、将页面信息添加到 数据库(mongodb) 3、对页面信息进行静态化
4、将页面信息发布到服务器   1.2.3 接口定义
1、创建响应结果类型 页面发布成功cms返回页面的url
页面Url= cmsSite.siteDomain+cmsSite.siteWebPath+ cmsPage.pageWebPath + cmsPage.pageName
[AppleScript] 纯文本查看 复制代码
@Data
 @NoArgsConstructor//无参构造器注解 public class CmsPostPageResult extends ResponseResult  {   
  String pageUrl;   
  public CmsPostPageResult(ResultCode resultCode,String pageUrl) {  
       super(resultCode);      
   this.pageUrl = pageUrl;  
   } } 

2、在api工程定义页面发布接口

[AppleScript] 纯文本查看 复制代码
@ApiOperation("一键发布页面") 
public CmsPostPageResult postPageQuick(CmsPage cmsPage); 

2.2.4 Dao
1、站点dao
接口中需要获取站点的信息(站点域名、站点访问路径等)

[AppleScript] 纯文本查看 复制代码
public interface CmsSiteRepository extends MongoRepository<CmsSite,String> {
 }

2.2.5 Service
1、添加页面,如果已存在则更新页面

[AppleScript] 纯文本查看 复制代码
//添加页面,如果已存在则更新页面 
public CmsPageResult save(CmsPage cmsPage){ 
    //校验页面是否存在,根据页面名称、站点Id、页面webpath查询   
  CmsPage cmsPage1 =  cmsPageRepository.findByPageNameAndSiteIdAndPageWebPath(cmsPage.getPageName(),  cmsPage.getSiteId(), cmsPage.getPageWebPath());  
   if(cmsPage1 !=null){   
      //更新      
   return this.update(cmsPage1.getPageId(),cmsPage);  
   }else{      
   //添加     
    return this.add(cmsPage);  
   } }

2、页面发布方法

[AppleScript] 纯文本查看 复制代码
//一键发布页面    
 public CmsPostPageResult postPageQuick(CmsPage cmsPage){    
     //添加页面     
    CmsPageResult save = this.save(cmsPage);  
       if(!save.isSuccess()){    
         return new CmsPostPageResult(CommonCode.FAIL,null);    
     }        
 CmsPage cmsPage1 = save.getCmsPage();   
      //要布的页面id       
  String pageId = cmsPage1.getPageId();  
       //发布页面     
    ResponseResult responseResult = this.postPage(pageId);  
       if(!responseResult.isSuccess()){     
        return new CmsPostPageResult(CommonCode.FAIL,null);    
     }       
  //得到页面的url   
      //页面url=站点域名+站点webpath+页面webpath+页面名称   
      //站点id     
    String siteId = cmsPage1.getSiteId();     
    //查询站点信息     
    CmsSite cmsSite = findCmsSiteById(siteId);    
     //站点域名       
  String siteDomain = cmsSite.getSiteDomain();    
     //站点web路径      
   String siteWebPath = cmsSite.getSiteWebPath();   
      //页面web路径      
   String pageWebPath = cmsPage1.getPageWebPath(); 
        //页面名称      
   String pageName = cmsPage1.getPageName();     
    //页面的web访问地址    
     String pageUrl = siteDomain+siteWebPath+pageWebPath+pageName;     
    return new CmsPostPageResult(CommonCode.SUCCESS,pageUrl);  
   }

[AppleScript] 纯文本查看 复制代码
//根据id查询站点信息  
   public CmsSite findCmsSiteById(String siteId){     
    Optional<CmsSite> optional = cmsSiteRepository.findById(siteId);  
       if(optional.isPresent()){     
        return optional.get();       
  }       
  return null;  
   } 

2.2.6 Controller
[AppleScript] 纯文本查看 复制代码
@Override
 @PostMapping("/postPageQuick") 
public CmsPostPageResult postPageQuick(@RequestBody CmsPage cmsPage) {   
  return pageService.postPageQuick(cmsPage); }



0 个回复

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