1. Course release
1.1 demand analysis
After the course is published, a formal course details page will be generated. After the course is published, users can browse the course details page and start the course learning.
The process of generating course details page by course publishing is the same as that of course preview, as follows:
1. Users enter the teaching management center and enter the management interface of a course
2. Click course release, and the front end requests to course management service
3. The course management service remotely calls CMS to generate the course publishing page, and CMS publishes the course details page to the server
4. The course management service modifies the course publishing status to released, and returns to the front end that the course is published successfully
5. Users click the "course details page" link in the teaching management center to view the content of the course details page
1.2 CMS one key publishing interface
1.2.1 demand analysis
According to the content of demand analysis, the cms service needs to add a page publishing interface for the course management service to call. The functions of this interface are as follows:
1. Receive the page information published by the course management service
2. Add page information to the database (mongodb)
3. Static page information
4. Publish page information to the server
1.2.3 interface definition
1. Create response result type
The page is published successfully. The URL page of cms return page Url=cmsSite.siteDomain+cmsSite.siteWebPath+ cmsPage.pageWebPath + cmsPage.pageName
@Data @NoArgsConstructor//Parameterless constructor annotation public class CmsPostPageResult extends ResponseResult { String pageUrl; public CmsPostPageResult(ResultCode resultCode,String pageUrl) { super(resultCode); this. pageUrl = pageUrl; } }
2. Publish interface in api project definition page
@ApiOperation( "One Key publishing page " ) public CmsPostPageResult postPageQuick(CmsPage cmsPage);
2.2.4 Dao
1. Site dao
Need to obtain site information (site domain name, site access path, etc.) in the interface
public interface CmsSiteRepository extends MongoRepository<CmsSite,String> { }
2.2.5 Service
1. Add page, update page if it already exists
//Add page, update page if it already exists public CmsPageResult save(CmsPage cmsPage){ //Check whether the page exists. Query according to the page name, site Id and page web path CmsPage cmsPage1 = cmsPageRepository .findByPageNameAndSiteIdAndPageWebPath(cmsPage. getPageName(), cmsPage. getSiteId(), cmsPage. getPageWebPath()); if(cmsPage1 ! =null){ //To update return this.update(cmsPage1. getPageId(),cmsPage); }else{ //Add to return this.add(cmsPage); } }
2. Page publishing method
// //One //Key publishing page public CmsPostPageResult postPageQuick(CmsPage cmsPage){ //Add page CmsPageResult save = this.save(cmsPage); if(!save.isSuccess()){ return new CmsPostPageResult(CommonCode.FAIL,null); } CmsPage cmsPage1 = save. getCmsPage(); //Page id to be distributed String pageId = cmsPage1. getPageId(); //Publish page ResponseResult responseResult = this. postPage(pageId); if(!responseResult.isSuccess()){ return new CmsPostPageResult(CommonCode.FAIL,null); } //Get the url of the page //Page url= //Site domain name + site web path + page web path + page name //Site id String siteId = cmsPage1. getSiteId(); //Query site information CmsSite cmsSite = findCmsSiteById(siteId); //Site domain name String siteDomain = cmsSite. getSiteDomain(); //Site web path String siteWebPath = cmsSite. getSiteWebPath(); //Page web path String pageWebPath = cmsPage1. getPageWebPath(); //page name String pageName = cmsPage1. getPageName(); //web access address of the page String pageUrl = siteDomain+siteWebPath+pageWebPath+pageName; return new CmsPostPageResult(CommonCode.SUCCESS,pageUrl); } //Query site information according to id public CmsSite findCmsSiteById(String siteId){ Optional<CmsSite> optional = cmsSiteRepository .findById(siteId); if(optional.isPresent()){ return optional. get(); } return null; }
2.2.6 Controller
@Override @PostMapping( " /postPageQuick " ) public CmsPostPageResult postPageQuick(@RequestBody CmsPage cmsPage) { return pageService. postPageQuick(cmsPage); }