提交 6819755c 编写于 作者: F fengyw

用户工程调整

上级 9fa5373b
......@@ -18,8 +18,8 @@ import java.util.Date;
@Data
@Accessors(chain = true)
public class EsCourse implements Serializable {
public static final String COURSE = "edu_course";
private static final long serialVersionUID = 1L;
public static final String COURSE = "rc_course";
/**
* 主键
......@@ -35,46 +35,32 @@ public class EsCourse implements Serializable {
*/
private Date gmtModified;
/**
* 排序
*/
private Integer sort;
/**
* 讲师名称
*/
private String lecturerName;
/**
* 课程编号
* 课程名称
*/
private Long courseNo;
private String courseName;
/**
* 课程封面
*/
private String courseLogo;
/**
* 课程名称
* 分类
*/
private String courseName;
private Long categoryId;
/**
* 课程排序
* 是否免费(1:免费,0:收费)
*/
private Integer courseSort;
private Integer isFree;
/**
* 原价
*/
private BigDecimal courseOriginal;
private BigDecimal rulingPrice;
/**
* 优惠价
*/
private BigDecimal courseDiscount;
private BigDecimal coursePrice;
/**
* 是否免费(1:免费,0:收费)
* 课程排序
*/
private Integer isFree;
@Override
public String toString() {
return "EsCourse [id=" + id + ", gmtCreate=" + gmtCreate + ", gmtModified=" + gmtModified + ", sort=" + sort + ", lecturerName=" + lecturerName + ", courseNo=" + courseNo + ", courseLogo=" + courseLogo + ", courseName=" + courseName + ", courseSort=" + courseSort + ", courseOriginal="
+ courseOriginal + ", courseDiscount=" + courseDiscount + ", isFree=" + isFree + "]";
}
private Integer courseSort;
}
......@@ -59,7 +59,7 @@ public interface CourseChapterDao {
/**
* 章节信息--条件列出
*
* @param example 查询条件
* @param example 查询条件
* @return 章节信息列表
*/
List<CourseChapter> listByExample(CourseChapterExample example);
......@@ -67,8 +67,12 @@ public interface CourseChapterDao {
/**
* 章节信息--条件统计
*
* @param example 统计条件
* @param example 统计条件
* @return 章节信息数量
*/
int countByExample(CourseChapterExample example);
List<CourseChapter> listByCourseId(Long courseId);
List<CourseChapter> listByCourseIdAndStatusId(Long id, Integer statusId);
}
......@@ -59,7 +59,7 @@ public interface CourseChapterPeriodDao {
/**
* 课时信息--条件列出
*
* @param example 查询条件
* @param example 查询条件
* @return 课时信息列表
*/
List<CourseChapterPeriod> listByExample(CourseChapterPeriodExample example);
......@@ -67,8 +67,10 @@ public interface CourseChapterPeriodDao {
/**
* 课时信息--条件统计
*
* @param example 统计条件
* @param example 统计条件
* @return 课时信息数量
*/
int countByExample(CourseChapterPeriodExample example);
List<CourseChapterPeriod> listByCourseIdAndStatusId(Long courseId, Integer statusId);
}
......@@ -68,7 +68,23 @@ public class CourseChapterDaoImpl implements CourseChapterDao {
}
@Override
public int countByExample(CourseChapterExample example){
public int countByExample(CourseChapterExample example) {
return this.mapper.countByExample(example);
}
@Override
public List<CourseChapter> listByCourseId(Long courseId) {
CourseChapterExample example = new CourseChapterExample();
example.createCriteria().andCourseIdEqualTo(courseId);
example.setOrderByClause(" sort asc, id desc ");
return this.mapper.selectByExample(example);
}
@Override
public List<CourseChapter> listByCourseIdAndStatusId(Long courseId, Integer statusId) {
CourseChapterExample example = new CourseChapterExample();
example.createCriteria().andCourseIdEqualTo(courseId).andStatusIdEqualTo(statusId);
example.setOrderByClause(" sort asc, id desc ");
return this.mapper.selectByExample(example);
}
}
......@@ -68,7 +68,19 @@ public class CourseChapterPeriodDaoImpl implements CourseChapterPeriodDao {
}
@Override
public int countByExample(CourseChapterPeriodExample example){
public int countByExample(CourseChapterPeriodExample example) {
return this.mapper.countByExample(example);
}
@Override
public List<CourseChapterPeriod> listByCourseIdAndStatusId(Long courseId, Integer statusId) {
CourseChapterPeriodExample example = new CourseChapterPeriodExample();
CourseChapterPeriodExample.Criteria c = example.createCriteria();
c.andCourseIdEqualTo(courseId);
if (null != statusId) {
c.andStatusIdEqualTo(statusId);
}
example.setOrderByClause("sort asc, id desc");
return this.mapper.selectByExample(example);
}
}
package com.roncoo.education.course.service.api;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.course.service.api.biz.ApiCourseBiz;
import com.roncoo.education.course.service.api.req.ApiCoursePageReq;
import com.roncoo.education.course.service.api.req.ApiCourseReq;
import com.roncoo.education.course.service.api.resp.ApiCoursePageResp;
import com.roncoo.education.course.service.api.resp.ApiCourseResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
......@@ -23,4 +32,23 @@ public class ApiCourseController {
@NotNull
private final ApiCourseBiz biz;
/**
* 课程信息列表接口
*
* @author fengyw
*/
@ApiOperation(value = "列表和搜索接口", notes = "根据条件进行课程列出")
@RequestMapping(value = "/search", method = RequestMethod.POST)
public Result<Page<ApiCoursePageResp>> searchForPage(@RequestBody ApiCoursePageReq req) {
return biz.searchForPage(req);
}
/**
* 课程详情接口
*/
@ApiOperation(value = "课程详情接口", notes = "根据课程ID获取课程信息")
@RequestMapping(value = "/view", method = RequestMethod.POST)
public Result<ApiCourseResp> view(@RequestBody ApiCourseReq req) {
return biz.view(req);
}
}
package com.roncoo.education.course.service.api.biz;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.common.core.enums.PutawayEnum;
import com.roncoo.education.common.core.enums.StatusIdEnum;
import com.roncoo.education.common.core.tools.BeanUtil;
import com.roncoo.education.common.es.EsCourse;
import com.roncoo.education.common.es.EsPageUtil;
import com.roncoo.education.common.service.BaseBiz;
import com.roncoo.education.course.dao.CourseChapterDao;
import com.roncoo.education.course.dao.CourseChapterPeriodDao;
import com.roncoo.education.course.dao.CourseDao;
import com.roncoo.education.course.dao.impl.mapper.entity.Course;
import com.roncoo.education.course.dao.impl.mapper.entity.CourseChapter;
import com.roncoo.education.course.dao.impl.mapper.entity.CourseChapterPeriod;
import com.roncoo.education.course.service.api.req.ApiCoursePageReq;
import com.roncoo.education.course.service.api.req.ApiCourseReq;
import com.roncoo.education.course.service.api.resp.*;
import com.roncoo.education.user.feign.interfaces.IFeignLecturer;
import com.roncoo.education.user.feign.interfaces.vo.LecturerViewVO;
import lombok.RequiredArgsConstructor;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* API-课程信息
......@@ -13,10 +49,83 @@ import javax.validation.constraints.NotNull;
* @author wujing
*/
@Component
@CacheConfig(cacheNames = {"course"})
@RequiredArgsConstructor
public class ApiCourseBiz extends BaseBiz {
@NotNull
private final CourseDao dao;
@NotNull
private final CourseChapterDao chapterDao;
@NotNull
private final CourseChapterPeriodDao periodDao;
@NotNull
private final IFeignLecturer feignLecturer;
@NotNull
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
public Result<Page<ApiCoursePageResp>> searchForPage(ApiCoursePageReq req) {
NativeSearchQueryBuilder nsb = new NativeSearchQueryBuilder();
// 高亮字段
nsb.withHighlightFields(new HighlightBuilder.Field("courseName").preTags("<mark>").postTags("</mark>"));
// 课程排序(courseSort)
nsb.withSort(new FieldSortBuilder("courseSort").order(SortOrder.DESC));
// 分页
nsb.withPageable(PageRequest.of(req.getPageCurrent() - 1, req.getPageSize()));
BoolQueryBuilder qb = QueryBuilders.boolQuery();
if (ObjectUtil.isNotEmpty(req.getCategoryId())) {
qb.must(QueryBuilders.termQuery(req.getCategoryId().toString(), "categoryId"));
}
if (ObjectUtil.isNotEmpty(req.getIsFree())) {
qb.must(QueryBuilders.termQuery(req.getIsFree().toString(), "isFree"));
}
if (StringUtils.hasText(req.getCourseName())) {
// 模糊查询multiMatchQuery,最佳字段best_fields
qb.must(QueryBuilders.multiMatchQuery(req.getCourseName(), "courseName").type(MultiMatchQueryBuilder.Type.BEST_FIELDS));
}
nsb.withQuery(qb);
SearchHits<EsCourse> searchHits = elasticsearchRestTemplate.search(nsb.build(), EsCourse.class, IndexCoordinates.of(EsCourse.COURSE));
return Result.success(EsPageUtil.transform(searchHits, req.getPageCurrent(), req.getPageSize(), ApiCoursePageResp.class));
}
@Cacheable
public Result<ApiCourseResp> view(ApiCourseReq req) {
Course course = dao.getById(req.getCourseId());
if (course == null) {
return Result.error("找不到该课程信息");
}
if (!course.getStatusId().equals(StatusIdEnum.YES.getCode())) {
return Result.error("该课程已被禁用");
}
if (course.getIsPutaway().equals(PutawayEnum.DOWN.getCode())) {
return Result.error("该课程已下架");
}
ApiCourseResp courseResp = BeanUtil.copyProperties(course, ApiCourseResp.class);
// 获取讲师信息
LecturerViewVO lecturerViewVO = feignLecturer.getById(course.getLecturerId());
if (ObjectUtil.isNotEmpty(lecturerViewVO)) {
courseResp.setLecturerResp(BeanUtil.copyProperties(lecturerViewVO, ApiCourseLecturerResp.class));
}
// 章节信息
List<CourseChapter> chapterList = chapterDao.listByCourseIdAndStatusId(course.getId(), StatusIdEnum.YES.getCode());
if (CollUtil.isNotEmpty(chapterList)) {
courseResp.setChapterRespList(BeanUtil.copyProperties(chapterList, ApiCourseChapterResp.class));
// 课时信息
List<CourseChapterPeriod> periodList = periodDao.listByCourseIdAndStatusId(course.getId(), StatusIdEnum.YES.getCode());
if (CollUtil.isNotEmpty(periodList)) {
Map<Long, List<CourseChapterPeriod>> map = periodList.stream().collect(Collectors.groupingBy(CourseChapterPeriod::getChapterId, Collectors.toList()));
for (ApiCourseChapterResp chapterResp : courseResp.getChapterRespList()) {
chapterResp.setPeriodRespList(BeanUtil.copyProperties(map.get(chapterResp.getId()), ApiCourseChapterPeriodResp.class));
}
}
}
return Result.success(courseResp);
}
}
package com.roncoo.education.course.service.api.req;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
* API-课程信息
* </p>
*
* @author wujing
* @date 2022-08-25
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "ApiCourseReq", description = "API-课程信息")
public class ApiCoursePageReq implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "分类ID")
private Long categoryId;
@ApiModelProperty(value = "课程名称")
private String courseName;
@ApiModelProperty(value = "是否免费(1:免费,0:收费)")
private Integer isFree;
@ApiModelProperty(value = "购买人数")
private Integer countBuy;
@ApiModelProperty(value = "学习人数")
private Integer countStudy;
/**
* 当前页
*/
@ApiModelProperty(value = "当前页")
private Integer pageCurrent = 1;
/**
* 每页条数
*/
@ApiModelProperty(value = "每页条数")
private Integer pageSize = 20;
}
package com.roncoo.education.course.service.api.req;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
* API-课程信息
......@@ -24,56 +22,7 @@ public class ApiCourseReq implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private LocalDateTime gmtCreate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "状态(1:正常,0:禁用)")
private Integer statusId;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "讲师ID")
private Long lecturerId;
@ApiModelProperty(value = "分类ID")
private Long categoryId;
@ApiModelProperty(value = "课程名称")
private String courseName;
@ApiModelProperty(value = "课程封面")
private String courseLogo;
@ApiModelProperty(value = "课程简介")
private String introduce;
@ApiModelProperty(value = "是否免费(1:免费,0:收费)")
private Integer isFree;
@ApiModelProperty(value = "原价")
private BigDecimal courseOriginal;
@ApiModelProperty(value = "优惠价")
private BigDecimal courseDiscount;
@ApiModelProperty(value = "是否上架(1:上架,0:下架)")
private Integer isPutaway;
@ApiModelProperty(value = "课程排序(前端显示使用)")
private Integer courseSort;
@ApiModelProperty(value = "购买人数")
private Integer countBuy;
@ApiModelProperty(value = "课程ID")
private Long courseId;
@ApiModelProperty(value = "学习人数")
private Integer countStudy;
}
package com.roncoo.education.course.service.api.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* API-课时信息
......@@ -34,12 +35,6 @@ public class ApiCourseChapterPeriodResp implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "状态(1:正常,0:禁用)")
private Integer statusId;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "课程ID")
private Long courseId;
......
package com.roncoo.education.course.service.api.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
* API-章节信息
......@@ -34,12 +36,6 @@ public class ApiCourseChapterResp implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "状态(1:正常,0:禁用)")
private Integer statusId;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "课程ID")
private Long courseId;
......@@ -51,4 +47,7 @@ public class ApiCourseChapterResp implements Serializable {
@ApiModelProperty(value = "是否免费(1免费,0收费)")
private Integer isFree;
@ApiModelProperty(value = "课时信息")
private List<ApiCourseChapterPeriodResp> periodRespList;
}
package com.roncoo.education.course.service.api.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
* ADMIN-讲师信息
* </p>
*
* @author wujing
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "ApiLecturerResp", description = "ADMIN-讲师信息查看")
public class ApiCourseLecturerResp implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@ApiModelProperty(value = "讲师名称")
private String lecturerName;
@ApiModelProperty(value = "讲师手机")
private String lecturerMobile;
@ApiModelProperty(value = "讲师职位")
private String lecturerPosition;
@ApiModelProperty(value = "讲师头像")
private String lecturerHead;
@ApiModelProperty(value = "简介")
private String introduce;
}
package com.roncoo.education.course.service.api.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* <p>
* API-课程信息
* </p>
*
* @author wujing
* @date 2022-08-25
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "ApiCourseResp", description = "API-课程信息")
public class ApiCoursePageResp implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private LocalDateTime gmtCreate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "讲师ID")
private Long lecturerId;
@ApiModelProperty(value = "分类ID")
private Long categoryId;
@ApiModelProperty(value = "课程名称")
private String courseName;
@ApiModelProperty(value = "课程封面")
private String courseLogo;
@ApiModelProperty(value = "课程简介")
private String introduce;
@ApiModelProperty(value = "是否免费(1:免费,0:收费)")
private Integer isFree;
@ApiModelProperty(value = "原价")
private BigDecimal rulingPrice;
@ApiModelProperty(value = "优惠价")
private BigDecimal coursePrice;
@ApiModelProperty(value = "课程排序(前端显示使用)")
private Integer courseSort;
// @ApiModelProperty(value = "购买人数")
// private Integer countBuy;
//
// @ApiModelProperty(value = "学习人数")
// private Integer countStudy;
}
......@@ -9,6 +9,7 @@ import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
......@@ -36,18 +37,6 @@ public class ApiCourseResp implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "状态(1:正常,0:禁用)")
private Integer statusId;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "讲师ID")
private Long lecturerId;
@ApiModelProperty(value = "分类ID")
private Long categoryId;
@ApiModelProperty(value = "课程名称")
private String courseName;
......@@ -66,15 +55,21 @@ public class ApiCourseResp implements Serializable {
@ApiModelProperty(value = "优惠价")
private BigDecimal courseDiscount;
@ApiModelProperty(value = "是否上架(1:上架,0:下架)")
private Integer isPutaway;
@ApiModelProperty(value = "课程排序(前端显示使用)")
private Integer courseSort;
@ApiModelProperty(value = "购买人数")
private Integer countBuy;
@ApiModelProperty(value = "学习人数")
private Integer countStudy;
@ApiModelProperty(value = "分类ID")
private Long categoryId;
@ApiModelProperty(value = "讲师ID")
private Long lecturerId;
@ApiModelProperty(value = "讲师信息")
private ApiCourseLecturerResp lecturerResp;
@ApiModelProperty(value = "章节信息")
private List<ApiCourseChapterResp> chapterRespList;
}
package com.roncoo.education.course.test;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.course.service.api.biz.ApiCourseBiz;
import com.roncoo.education.course.service.api.req.ApiCourseReq;
import com.roncoo.education.course.service.api.resp.ApiCourseResp;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class CourseTest extends BaseTest {
@Autowired
private ApiCourseBiz courseBiz;
@Test
public void view() {
ApiCourseReq req = new ApiCourseReq();
req.setCourseId(1080759557655564289L);
Result<ApiCourseResp> result = courseBiz.view(req);
log.info("course={}", result.getData());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册