【郑州校区】学成在线-第10天-讲义-课程发布 二
1.3 课程发布接口
1.3.1 Api接口
此Api接口由课程管理提供,由课程管理前端调用此Api接口,实现课程发布。
在api工程下课程管理包下定义接口:
[AppleScript] 纯文本查看 复制代码 @ApiOperation(
"
发布课程
"
)
public CoursePublishResult publish(@PathVariable String id);
1.3.2 创建Feign Client
在课程管理工程创建CMS服务页面发布的Feign Client
[AppleScript] 纯文本查看 复制代码 @FeignClient(value
= XcServiceList.XC_SERVICE_MANAGE_CMS)
public interface CmsPageClient {
//
一
键发布页面
@PostMapping(
"
/cms/page/postPageQuick
"
)
public CmsPostPageResult postPageQuick(CmsPage cmsPage);
}
1.3.3 Service
1、配置课程发布页面参数
在application.yml中配置
[AppleScript] 纯文本查看 复制代码 course
‐
publish:
siteId: 5b30cba5f58b4411fc6cb1e5
templateId: 5ad9a24d68db5239b8fef199
previewUrl: [url]http://www.xuecheng[/url]
.com/cms/preview/
pageWebPath: /course/detail/
pagePhysicalPath: /course/detail/
dataUrlPre: http://localhost:31200/course/courseview/
siteId:站点id
templateId:模板id
dataurlPre:数据url的前缀
pageWebPath: 页面的web访问路径
pagePhysicalPath:页面的物理存储路径。
2、Service方法如下
[AppleScript] 纯文本查看 复制代码 @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);
}
//更新课程状态
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;
}
1.3.4 Controller
[AppleScript] 纯文本查看 复制代码 @Override
@PostMapping(
"
/publish/{id}
"
)
public CoursePublishResult publish(@PathVariable String id) {
return courseService.
publish(id);
}
|