Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roncoo
roncoo-education
提交
4b09fd31
R
roncoo-education
项目概览
roncoo
/
roncoo-education
大约 1 年 前同步成功
通知
146
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roncoo-education
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b09fd31
编写于
6月 02, 2023
作者:
F
fengyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化功能,不强制依赖es
上级
8ec9f2c1
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
67 addition
and
39 deletion
+67
-39
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/job/CourseJob.java
.../main/java/com/roncoo/education/course/job/CourseJob.java
+16
-13
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/job/UserStudyJob.java
...in/java/com/roncoo/education/course/job/UserStudyJob.java
+2
-2
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/service/admin/biz/AdminCourseBiz.java
...oo/education/course/service/admin/biz/AdminCourseBiz.java
+23
-17
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/service/api/biz/ApiCourseBiz.java
...roncoo/education/course/service/api/biz/ApiCourseBiz.java
+26
-7
未找到文件。
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/job/CourseJob.java
浏览文件 @
4b09fd31
package
com.roncoo.education.course.job
;
package
com.roncoo.education.course.job
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.roncoo.education.common.core.enums.PutawayEnum
;
import
com.roncoo.education.common.core.enums.PutawayEnum
;
import
com.roncoo.education.common.core.enums.StatusIdEnum
;
import
com.roncoo.education.common.core.enums.StatusIdEnum
;
import
com.roncoo.education.common.core.tools.BeanUtil
;
import
com.roncoo.education.common.core.tools.BeanUtil
;
...
@@ -30,16 +31,17 @@ import java.util.List;
...
@@ -30,16 +31,17 @@ import java.util.List;
@Component
@Component
public
class
CourseJob
{
public
class
CourseJob
{
@Autowired
(
required
=
false
)
private
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
@Autowired
@Autowired
private
CourseDao
courseDao
;
private
CourseDao
courseDao
;
@Autowired
private
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
/**
/**
* 每天凌晨5点执行一次
* 每天凌晨5点执行一次
*/
*/
@XxlJob
(
"courseJobHandler"
)
@XxlJob
(
"courseJobHandler"
)
public
void
course
()
{
public
void
course
()
{
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
CourseExample
example
=
new
CourseExample
();
CourseExample
example
=
new
CourseExample
();
example
.
createCriteria
().
andStatusIdEqualTo
(
StatusIdEnum
.
YES
.
getCode
()).
andIsPutawayEqualTo
(
PutawayEnum
.
UP
.
getCode
());
example
.
createCriteria
().
andStatusIdEqualTo
(
StatusIdEnum
.
YES
.
getCode
()).
andIsPutawayEqualTo
(
PutawayEnum
.
UP
.
getCode
());
List
<
Course
>
courseList
=
courseDao
.
listByExample
(
example
);
List
<
Course
>
courseList
=
courseDao
.
listByExample
(
example
);
...
@@ -53,6 +55,7 @@ public class CourseJob {
...
@@ -53,6 +55,7 @@ public class CourseJob {
elasticsearchRestTemplate
.
indexOps
(
EsCourse
.
class
).
delete
();
elasticsearchRestTemplate
.
indexOps
(
EsCourse
.
class
).
delete
();
elasticsearchRestTemplate
.
bulkIndex
(
queries
,
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
elasticsearchRestTemplate
.
bulkIndex
(
queries
,
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
}
}
}
XxlJobHelper
.
handleSuccess
(
"完成"
);
XxlJobHelper
.
handleSuccess
(
"完成"
);
}
}
...
...
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/job/UserStudyJob.java
浏览文件 @
4b09fd31
...
@@ -23,11 +23,11 @@ import java.util.concurrent.TimeUnit;
...
@@ -23,11 +23,11 @@ import java.util.concurrent.TimeUnit;
@Slf4j
@Slf4j
@Component
@Component
public
class
UserStudyJob
{
public
class
UserStudyJob
{
@Autowired
private
UserStudyDao
userStudyDao
;
@Autowired
@Autowired
private
CacheRedis
cacheRedis
;
private
CacheRedis
cacheRedis
;
@Autowired
private
UserStudyDao
userStudyDao
;
/**
/**
* 每10秒执行一次
* 每10秒执行一次
...
...
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/service/admin/biz/AdminCourseBiz.java
浏览文件 @
4b09fd31
...
@@ -24,7 +24,6 @@ import com.roncoo.education.course.service.admin.resp.AdminCoursePageResp;
...
@@ -24,7 +24,6 @@ import com.roncoo.education.course.service.admin.resp.AdminCoursePageResp;
import
com.roncoo.education.course.service.admin.resp.AdminCourseViewResp
;
import
com.roncoo.education.course.service.admin.resp.AdminCourseViewResp
;
import
com.roncoo.education.user.feign.interfaces.IFeignLecturer
;
import
com.roncoo.education.user.feign.interfaces.IFeignLecturer
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
;
import
org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
;
import
org.springframework.data.elasticsearch.core.query.IndexQuery
;
import
org.springframework.data.elasticsearch.core.query.IndexQuery
;
...
@@ -48,16 +47,15 @@ import java.util.stream.Collectors;
...
@@ -48,16 +47,15 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
AdminCourseBiz
extends
BaseBiz
{
public
class
AdminCourseBiz
extends
BaseBiz
{
@NotNull
private
final
IFeignLecturer
feignLecturer
;
@NotNull
@NotNull
private
final
CourseDao
dao
;
private
final
CourseDao
dao
;
@NotNull
@NotNull
private
final
CategoryDao
categoryDao
;
private
final
CategoryDao
categoryDao
;
@NotNull
private
final
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
private
final
IFeignLecturer
feignLecturer
;
@Autowired
private
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
/**
/**
* 课程信息分页
* 课程信息分页
...
@@ -106,8 +104,10 @@ public class AdminCourseBiz extends BaseBiz {
...
@@ -106,8 +104,10 @@ public class AdminCourseBiz extends BaseBiz {
}
}
Course
record
=
BeanUtil
.
copyProperties
(
req
,
Course
.
class
);
Course
record
=
BeanUtil
.
copyProperties
(
req
,
Course
.
class
);
if
(
dao
.
save
(
record
)
>
0
)
{
if
(
dao
.
save
(
record
)
>
0
)
{
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
record
,
EsCourse
.
class
);
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
record
,
EsCourse
.
class
);
elasticsearchRestTemplate
.
index
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
(),
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
elasticsearchRestTemplate
.
index
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
(),
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
}
return
Result
.
success
(
"操作成功"
);
return
Result
.
success
(
"操作成功"
);
}
}
return
Result
.
error
(
"操作失败"
);
return
Result
.
error
(
"操作失败"
);
...
@@ -140,8 +140,10 @@ public class AdminCourseBiz extends BaseBiz {
...
@@ -140,8 +140,10 @@ public class AdminCourseBiz extends BaseBiz {
}
}
Course
record
=
BeanUtil
.
copyProperties
(
req
,
Course
.
class
);
Course
record
=
BeanUtil
.
copyProperties
(
req
,
Course
.
class
);
if
(
dao
.
updateById
(
record
)
>
0
)
{
if
(
dao
.
updateById
(
record
)
>
0
)
{
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
record
,
EsCourse
.
class
);
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
record
,
EsCourse
.
class
);
elasticsearchRestTemplate
.
index
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
(),
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
elasticsearchRestTemplate
.
index
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
(),
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
}
return
Result
.
success
(
"操作成功"
);
return
Result
.
success
(
"操作成功"
);
}
}
return
Result
.
error
(
"操作失败"
);
return
Result
.
error
(
"操作失败"
);
...
@@ -155,7 +157,9 @@ public class AdminCourseBiz extends BaseBiz {
...
@@ -155,7 +157,9 @@ public class AdminCourseBiz extends BaseBiz {
*/
*/
public
Result
<
String
>
delete
(
Long
id
)
{
public
Result
<
String
>
delete
(
Long
id
)
{
if
(
dao
.
deleteById
(
id
)
>
0
)
{
if
(
dao
.
deleteById
(
id
)
>
0
)
{
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
elasticsearchRestTemplate
.
delete
(
id
.
toString
(),
EsCourse
.
class
);
elasticsearchRestTemplate
.
delete
(
id
.
toString
(),
EsCourse
.
class
);
}
return
Result
.
success
(
"操作成功"
);
return
Result
.
success
(
"操作成功"
);
}
}
return
Result
.
error
(
"操作失败"
);
return
Result
.
error
(
"操作失败"
);
...
@@ -168,6 +172,7 @@ public class AdminCourseBiz extends BaseBiz {
...
@@ -168,6 +172,7 @@ public class AdminCourseBiz extends BaseBiz {
List
<
Course
>
courseList
=
dao
.
listByExample
(
example
);
List
<
Course
>
courseList
=
dao
.
listByExample
(
example
);
if
(
CollUtil
.
isNotEmpty
(
courseList
))
{
if
(
CollUtil
.
isNotEmpty
(
courseList
))
{
List
<
IndexQuery
>
queries
=
new
ArrayList
<>();
List
<
IndexQuery
>
queries
=
new
ArrayList
<>();
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
for
(
Course
course
:
courseList
)
{
for
(
Course
course
:
courseList
)
{
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
course
,
EsCourse
.
class
);
EsCourse
esCourse
=
BeanUtil
.
copyProperties
(
course
,
EsCourse
.
class
);
queries
.
add
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
());
queries
.
add
(
new
IndexQueryBuilder
().
withObject
(
esCourse
).
build
());
...
@@ -176,6 +181,7 @@ public class AdminCourseBiz extends BaseBiz {
...
@@ -176,6 +181,7 @@ public class AdminCourseBiz extends BaseBiz {
elasticsearchRestTemplate
.
indexOps
(
EsCourse
.
class
).
delete
();
elasticsearchRestTemplate
.
indexOps
(
EsCourse
.
class
).
delete
();
elasticsearchRestTemplate
.
bulkIndex
(
queries
,
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
elasticsearchRestTemplate
.
bulkIndex
(
queries
,
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
}
}
}
return
Result
.
success
(
"操作成功"
);
return
Result
.
success
(
"操作成功"
);
}
}
}
}
roncoo-education-course/roncoo-education-course-service/src/main/java/com/roncoo/education/course/service/api/biz/ApiCourseBiz.java
浏览文件 @
4b09fd31
...
@@ -3,6 +3,7 @@ package com.roncoo.education.course.service.api.biz;
...
@@ -3,6 +3,7 @@ package com.roncoo.education.course.service.api.biz;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.roncoo.education.common.core.base.Page
;
import
com.roncoo.education.common.core.base.Page
;
import
com.roncoo.education.common.core.base.PageUtil
;
import
com.roncoo.education.common.core.base.Result
;
import
com.roncoo.education.common.core.base.Result
;
import
com.roncoo.education.common.core.enums.PutawayEnum
;
import
com.roncoo.education.common.core.enums.PutawayEnum
;
import
com.roncoo.education.common.core.enums.StatusIdEnum
;
import
com.roncoo.education.common.core.enums.StatusIdEnum
;
...
@@ -58,6 +59,9 @@ import java.util.stream.Collectors;
...
@@ -58,6 +59,9 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
ApiCourseBiz
extends
BaseBiz
{
public
class
ApiCourseBiz
extends
BaseBiz
{
@NotNull
private
final
IFeignLecturer
feignLecturer
;
@NotNull
@NotNull
private
final
CourseDao
dao
;
private
final
CourseDao
dao
;
@NotNull
@NotNull
...
@@ -67,20 +71,36 @@ public class ApiCourseBiz extends BaseBiz {
...
@@ -67,20 +71,36 @@ public class ApiCourseBiz extends BaseBiz {
@NotNull
@NotNull
private
final
CategoryDao
categoryDao
;
private
final
CategoryDao
categoryDao
;
@NotNull
private
final
IFeignLecturer
feignLecturer
;
@NotNull
private
final
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
private
final
ElasticsearchRestTemplate
elasticsearchRestTemplate
;
public
Result
<
Page
<
ApiCoursePageResp
>>
searchForPage
(
ApiCoursePageReq
req
)
{
public
Result
<
Page
<
ApiCoursePageResp
>>
searchForPage
(
ApiCoursePageReq
req
)
{
if
(
ObjectUtil
.
isNotNull
(
elasticsearchRestTemplate
))
{
// elasticsearch
return
getPageResultForElasticsearch
(
req
);
}
// mysql
CourseExample
example
=
new
CourseExample
();
CourseExample
.
Criteria
criteria
=
example
.
createCriteria
();
if
(
ObjectUtil
.
isNotEmpty
(
req
.
getCategoryId
()))
{
criteria
.
andCategoryIdEqualTo
(
req
.
getCategoryId
());
}
if
(
ObjectUtil
.
isNotEmpty
(
req
.
getIsFree
()))
{
criteria
.
andIsFreeEqualTo
(
req
.
getIsFree
());
}
if
(
StringUtils
.
hasText
(
req
.
getCourseName
()))
{
criteria
.
andCourseNameLike
(
PageUtil
.
like
(
req
.
getCourseName
()));
}
example
.
setOrderByClause
(
"course_sort asc, id desc"
);
Page
<
Course
>
page
=
dao
.
page
(
req
.
getPageCurrent
(),
req
.
getPageSize
(),
example
);
return
Result
.
success
(
PageUtil
.
transform
(
page
,
ApiCoursePageResp
.
class
));
}
private
Result
<
Page
<
ApiCoursePageResp
>>
getPageResultForElasticsearch
(
ApiCoursePageReq
req
)
{
NativeSearchQueryBuilder
nsb
=
new
NativeSearchQueryBuilder
();
NativeSearchQueryBuilder
nsb
=
new
NativeSearchQueryBuilder
();
// 高亮字段
// 高亮字段
nsb
.
withHighlightFields
(
new
HighlightBuilder
.
Field
(
"courseName"
).
preTags
(
"<mark>"
).
postTags
(
"</mark>"
));
nsb
.
withHighlightFields
(
new
HighlightBuilder
.
Field
(
"courseName"
).
preTags
(
"<mark>"
).
postTags
(
"</mark>"
));
// 分页
// 分页
nsb
.
withPageable
(
PageRequest
.
of
(
req
.
getPageCurrent
()
-
1
,
req
.
getPageSize
()));
nsb
.
withPageable
(
PageRequest
.
of
(
req
.
getPageCurrent
()
-
1
,
req
.
getPageSize
()));
BoolQueryBuilder
qb
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
qb
=
QueryBuilders
.
boolQuery
();
if
(
ObjectUtil
.
isNotEmpty
(
req
.
getCategoryId
()))
{
if
(
ObjectUtil
.
isNotEmpty
(
req
.
getCategoryId
()))
{
List
<
Long
>
categoryIdList
=
listCategoryId
(
req
.
getCategoryId
());
List
<
Long
>
categoryIdList
=
listCategoryId
(
req
.
getCategoryId
());
...
@@ -98,7 +118,6 @@ public class ApiCourseBiz extends BaseBiz {
...
@@ -98,7 +118,6 @@ public class ApiCourseBiz extends BaseBiz {
nsb
.
withSort
(
new
FieldSortBuilder
(
"id"
).
order
(
SortOrder
.
DESC
));
nsb
.
withSort
(
new
FieldSortBuilder
(
"id"
).
order
(
SortOrder
.
DESC
));
}
}
nsb
.
withQuery
(
qb
);
nsb
.
withQuery
(
qb
);
SearchHits
<
EsCourse
>
searchHits
=
elasticsearchRestTemplate
.
search
(
nsb
.
build
(),
EsCourse
.
class
,
IndexCoordinates
.
of
(
EsCourse
.
COURSE
));
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
));
return
Result
.
success
(
EsPageUtil
.
transform
(
searchHits
,
req
.
getPageCurrent
(),
req
.
getPageSize
(),
ApiCoursePageResp
.
class
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录