提交 44200a0b 编写于 作者: K keyh

课程增加一键导入ES功能

上级 8730e89e
......@@ -50,4 +50,13 @@ public interface CourseDao {
* @return
*/
List<Course> listBycategoryId2AndStatusId(Long categoryId2, Integer statusId);
/**
* 根据状态获取课程信息
*
* @param isPutaway
* @param statusId
* @return
*/
List<Course> listByIsPutawayAndStatusId(Integer isPutaway, Integer statusId);
}
......@@ -87,4 +87,13 @@ public class CourseDaoImpl implements CourseDao {
example.setOrderByClause("sort desc,id desc");
return this.courseMapper.selectByExample(example);
}
@Override
public List<Course> listByIsPutawayAndStatusId(Integer isPutaway, Integer statusId) {
CourseExample example = new CourseExample();
CourseExample.Criteria c = example.createCriteria();
c.andIsPutawayEqualTo(isPutaway);
c.andStatusIdEqualTo(statusId);
return this.courseMapper.selectByExample(example);
}
}
......@@ -13,10 +13,7 @@ import com.roncoo.education.course.service.pc.resq.CoursePageRESQ;
import com.roncoo.education.course.service.pc.resq.CourseViewRESQ;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.*;
/**
* 课程信息
......@@ -76,4 +73,10 @@ public class PcApiCourseController extends BaseController {
return biz.view(courseViewREQ);
}
@ApiOperation(value = "一键导入ES", notes = "一键导入ES")
@PostMapping(value = "/es/add")
public Result<String> addEs() {
return biz.addEs();
}
}
......@@ -18,6 +18,7 @@ import com.roncoo.education.course.service.pc.req.CourseUpdateREQ;
import com.roncoo.education.course.service.pc.req.CourseViewREQ;
import com.roncoo.education.course.service.pc.resq.*;
import com.roncoo.education.user.feign.interfaces.IFeignLecturer;
import com.roncoo.education.user.feign.interfaces.qo.LecturerQO;
import com.roncoo.education.user.feign.interfaces.vo.LecturerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
......@@ -29,7 +30,11 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 课程信息
......@@ -58,6 +63,7 @@ public class PcApiCourseBiz extends BaseBiz {
private CourseChapterPeriodDao courseChapterPeriodDao;
@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;
/**
* 分页列出
*
......@@ -298,4 +304,38 @@ public class PcApiCourseBiz extends BaseBiz {
return Result.success(resq);
}
public Result<String> addEs() {
// 查询全部,删除全部索引重建
List<Course> courseList = dao.listByIsPutawayAndStatusId(IsPutawayEnum.YES.getCode(), StatusIdEnum.YES.getCode());
if (CollectionUtil.isEmpty(courseList)) {
return Result.error("暂无导入课程");
}
List<Long> lecturerUserNos = courseList.stream().map(Course::getLecturerUserNo).collect(Collectors.toList());
Map<Long, LecturerVO> lecturerNameMap = new HashMap<>();
LecturerQO lecturerQO = new LecturerQO();
lecturerQO.setLecturerUserNos(lecturerUserNos);
List<LecturerVO> lecturerVOList = bossLecturer.listByLecturerUserNos(lecturerQO);
if (CollectionUtil.isNotEmpty(lecturerVOList)) {
lecturerNameMap = lecturerVOList.stream().collect(Collectors.toMap(LecturerVO::getLecturerUserNo, item -> item));
}
List<IndexQuery> queries = new ArrayList<>();
try {
// 查询讲师名称并插入es
for (Course course : courseList) {
EsCourse esCourse = BeanUtil.copyProperties(course, EsCourse.class);
LecturerVO lecturerVO = lecturerNameMap.get(course.getLecturerUserNo());
if (ObjectUtil.isNotNull(lecturerVO) && !StringUtils.isEmpty(lecturerVO.getLecturerName())) {
esCourse.setLecturerName(lecturerVO.getLecturerName());
}
IndexQuery query = new IndexQueryBuilder().withObject(esCourse).build();
queries.add(query);
}
elasticsearchRestTemplate.indexOps(EsCourse.class).delete();
elasticsearchRestTemplate.bulkIndex(queries, IndexCoordinates.of(EsCourse.COURSE));
} catch (Exception e) {
logger.warn("elasticsearch更新数据失败", e);
return Result.error("导入失败");
}
return Result.success("导入成功");
}
}
......@@ -47,5 +47,13 @@ public interface IFeignLecturer {
*/
@RequestMapping(value = "/feign/user/lecturer/listAllForLecturer", method = RequestMethod.POST)
List<LecturerVO> listAllForLecturer();
/**
* 根据讲师编号集合获取讲师信息
*
* @param lecturerQO
* @return
*/
@RequestMapping(value = "/lecturer/listByLecturerUserNos", method = RequestMethod.POST)
List<LecturerVO> listByLecturerUserNos(@RequestBody LecturerQO lecturerQO);
}
......@@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 讲师信息
......@@ -78,4 +79,8 @@ public class LecturerQO implements Serializable {
* 讲师分成比例
*/
private BigDecimal lecturerProportion;
/**
* 讲师编号集合
*/
private List<Long> lecturerUserNos;
}
......@@ -46,4 +46,12 @@ public interface LecturerDao {
* @author WY
*/
Lecturer getByLecturerUserNoAndStatusId(Long lecturerUserNo, Integer statusId);
/**
* 根据讲师编号集合获取讲师信息
*
* @param lecturerUserNos
* @return
*/
List<Lecturer> listByLecturerUserNos(List<Long> lecturerUserNos);
}
......@@ -93,4 +93,12 @@ public class LecturerDaoImpl implements LecturerDao {
}
return resultList.get(0);
}
@Override
public List<Lecturer> listByLecturerUserNos(List<Long> lecturerUserNos) {
LecturerExample example = new LecturerExample();
LecturerExample.Criteria criteria = example.createCriteria();
criteria.andLecturerUserNoIn(lecturerUserNos);
return this.lecturerMapper.selectByExample(example);
}
}
......@@ -57,6 +57,11 @@ public class FeignLecturerController extends BaseController implements IFeignLec
return biz.listAllForLecturer();
}
@Override
public List<LecturerVO> listByLecturerUserNos(LecturerQO lecturerQO) {
return biz.listByLecturerUserNos(lecturerQO);
}
/***
* 根据讲师用户编号查找讲师信息
*/
......
......@@ -106,4 +106,9 @@ public class FeignLecturerBiz {
List<Lecturer> lecturerList = dao.listByStatusId(StatusIdEnum.YES.getCode());
return PageUtil.copyList(lecturerList, LecturerVO.class);
}
public List<LecturerVO> listByLecturerUserNos(LecturerQO lecturerQO) {
List<Lecturer> lecturerList = dao.listByLecturerUserNos(lecturerQO.getLecturerUserNos());
return PageUtil.copyList(lecturerList, LecturerVO.class);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册