mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
学习课程ES增加了按id删除
This commit is contained in:
@@ -71,4 +71,11 @@ public interface ICourseStudySearch {
|
||||
* @throws Exception
|
||||
*/
|
||||
void removeByDocId(String id) throws Exception;
|
||||
|
||||
/**
|
||||
* 根据学习id删除
|
||||
* @param id
|
||||
* @throws Exception
|
||||
*/
|
||||
void removeByStudyId(String id);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
@@ -242,9 +245,38 @@ public class CourseStudyElasticsearchImpl implements ICourseStudySearch{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatusAndProcessByDocId(String docId, int status, int process) throws Exception {
|
||||
public void updateStatusAndProcessByDocId(String docId, int status, int progress) throws Exception {
|
||||
//更新状态和进度
|
||||
|
||||
UpdateRequest updateRequest = new UpdateRequest(IndexName, docId);
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
Map<String,Object> map=new HashMap<String,Object>();
|
||||
map.put("status",status);
|
||||
map.put("progress",progress);
|
||||
String textJson =mapper.writeValueAsString(map);
|
||||
updateRequest.doc(textJson, XContentType.JSON);
|
||||
UpdateResponse updateResponse = restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
|
||||
if (updateResponse.getResult() == DocWriteResponse.Result.UPDATED) {
|
||||
log.info("更新课程学习状态进度成功!");
|
||||
} else {
|
||||
log.error("更新课程学习状态进度失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByStudyId(String id) {
|
||||
//根据学习id删除
|
||||
try {
|
||||
DeleteByQueryRequest deleteRequest=new DeleteByQueryRequest(IndexName);
|
||||
deleteRequest.setQuery(new TermQueryBuilder("id",id));
|
||||
BulkByScrollResponse response = restHighLevelClient.deleteByQuery(deleteRequest, RequestOptions.DEFAULT);
|
||||
long n=response.getStatus().getTotal();
|
||||
if(n==0) {
|
||||
log.error("按id删除失败",response);
|
||||
}
|
||||
}catch(Exception e){
|
||||
log.error("按id【"+id+"】删除失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,23 +37,18 @@
|
||||
<artifactId>xboe-module-course</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.xboe</groupId>
|
||||
<artifactId>xboe-module-event</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>com.xboe</groupId>
|
||||
<artifactId>xboe-module-idconfig</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xboe</groupId>
|
||||
<artifactId>xboe-module-es</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>it.sauronsoftware</groupId>
|
||||
<artifactId>jave</artifactId>
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.xboe.core.utils.ConvertUtil;
|
||||
import com.xboe.module.course.dao.CourseContentDao;
|
||||
import com.xboe.module.course.dao.CourseDao;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.service.ICourseStudySearch;
|
||||
import com.xboe.school.study.dao.StudyAssessDao;
|
||||
import com.xboe.school.study.dao.StudyCourseDao;
|
||||
import com.xboe.school.study.dao.StudyCourseItemDao;
|
||||
@@ -84,6 +85,8 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
@Autowired
|
||||
CourseDao courseDao;
|
||||
|
||||
@Autowired(required = false)
|
||||
ICourseStudySearch search;//对ES的处理
|
||||
|
||||
@Override
|
||||
public StudyCourse findByCourseIdAndAid(String courseId, String aid) {
|
||||
@@ -277,6 +280,11 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
studySignupDao.deleteByFilter(FieldFilters.and(FieldFilters.eq("courseId",courseId),FieldFilters.eq("aid",aid)));
|
||||
//修改课程学习人数
|
||||
courseDao.updateMultiFieldById(courseId, UpdateBuilder.create("studys", "studys-1", FieldUpdateType.EXPRESSION));
|
||||
//同步删除ES的处理
|
||||
if(search!=null) {
|
||||
//search.removeByStudyId(id);
|
||||
log.info("删除,同步操作ES的删除未启用,如果确认已配置ES,请启用");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -601,7 +609,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
|
||||
@Override
|
||||
public List<Object[]> progress(String aid, List<String> courseIds) {
|
||||
List<Object> floats = new ArrayList<>();
|
||||
//List<Object> floats = new ArrayList<>();
|
||||
QueryBuilder builder = QueryBuilder.from(StudyCourse.class);
|
||||
builder.addFilter(FieldFilters.eq("aid",aid));
|
||||
builder.addFilter(FieldFilters.in("courseId",courseIds));
|
||||
|
||||
Reference in New Issue
Block a user